void JSPlanarVideoFrame::PopulateInstance(v8::Handle<v8::Object> inst) { // We really need to populate the various planes PopulatePlaneInstance(inst->Get(v8::String::New("y"))->ToObject(), PLANAR_Y); PopulatePlaneInstance(inst->Get(v8::String::New("u"))->ToObject(), PLANAR_U); PopulatePlaneInstance(inst->Get(v8::String::New("v"))->ToObject(), PLANAR_V); inst->SetInternalField(0, v8::External::New(this)); }
BSONObj v8ToMongo( v8::Handle<v8::Object> o ){ BSONObjBuilder b; v8::Handle<v8::String> idName = String::New( "_id" ); if ( o->HasRealNamedProperty( idName ) ){ v8ToMongoElement( b , idName , "_id" , o->Get( idName ) ); } Local<v8::Array> names = o->GetPropertyNames(); for ( unsigned int i=0; i<names->Length(); i++ ){ v8::Local<v8::String> name = names->Get(v8::Integer::New(i) )->ToString(); if ( o->GetPrototype()->IsObject() && o->GetPrototype()->ToObject()->HasRealNamedProperty( name ) ) continue; v8::Local<v8::Value> value = o->Get( name ); const string sname = toSTLString( name ); if ( sname == "_id" ) continue; v8ToMongoElement( b , name , sname , value ); } return b.obj(); }
void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> object) { listener->didParseSource( toWebCoreStringWithNullCheck(object->Get(v8::String::New("id"))), toWebCoreStringWithNullCheck(object->Get(v8::String::New("name"))), toWebCoreStringWithNullCheck(object->Get(v8::String::New("source"))), object->Get(v8::String::New("lineOffset"))->ToInteger()->Value()); }
jobjectArray TypeConverter::jsObjectIndexPropsToJavaArray(v8::Handle<v8::Object> jsObject, int start, int length) { JNIEnv *env = JNIScope::getEnv(); if (!env) { return NULL; } HandleScope scope; int arrayLength = length == 0 ? 0 : length - start; jobjectArray javaArray = env->NewObjectArray(arrayLength, JNIUtil::objectClass, NULL); int index = 0; for (int index = start; index < length; ++index) { v8::Local<Value> prop = jsObject->Get(index); bool isNew; jobject javaObject = jsValueToJavaObject(prop, &isNew); env->SetObjectArrayElement(javaArray, index - start, javaObject); if (isNew) { env->DeleteLocalRef(javaObject); } } return javaArray; }
// install a do-nothing "_third_party_main" as a built-in native module to // bypass the normal startup void setupThirdPartyMain(v8::Handle<v8::Object> process_l) { TRACEIN; v8::HandleScope scope; // call process.binding("natives"). We have to call it through Javascript // because the C++ implementation -- Binding() in node.cc -- is declared static. v8::Local<v8::Value> binding_v = process_l->Get(v8::String::New("binding")); assert(binding_v->IsFunction()); v8::Local<v8::Function> binding = v8::Local<v8::Function>::Cast(binding_v); v8::Local<v8::Value> args[] = { v8::String::New("natives") }; v8::TryCatch try_catch; binding->Call(process_l, 1, args); if (try_catch.HasCaught()) { node::FatalException(try_catch); } // add blank source code for _third_party_main to the bindings_cache's "natives" // object, which holds source code for native modules that are included as strings // this tricks Node.js into not calling it's normal node-main v8::Local<v8::Object> nativesObj = node::binding_cache->Get( v8::String::NewSymbol("natives") )->ToObject(); v8::Handle<v8::String> source = BUILTIN_ASCII_ARRAY(pdg_main_native, sizeof(pdg_main_native)-1); nativesObj->Set(v8::String::New("_third_party_main"), source); TRACEOUT; }
Value Interpreter::eval(const String& data, const String& name) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, mData->context); v8::Context::Scope contextScope(context); v8::Handle<v8::String> fileName = v8::String::NewFromUtf8(isolate, name.constData()); v8::Handle<v8::String> source = v8::String::NewFromUtf8(isolate, data.constData()); v8::TryCatch try_catch; v8::Handle<v8::Script> script = v8::Script::Compile(source, fileName); if (script.IsEmpty()) { error() << "script" << name << "didn't compile"; return Value(); } const v8::Handle<v8::Value> result = script->Run(); if (try_catch.HasCaught()) { const v8::Handle<v8::Message> msg = try_catch.Message(); { const v8::String::Utf8Value str(msg->Get()); error() << ToCString(str); } { const v8::String::Utf8Value str(msg->GetScriptResourceName()); error() << String::format<64>("At %s:%d", ToCString(str), msg->GetLineNumber()); } return Value(); } return mData->v8ValueToValue(result); }
void printAllPropertyNames(v8::Handle<v8::Object> objToPrint) { v8::Local<v8::Array> allProps = objToPrint->GetPropertyNames(); std::vector<v8::Local<v8::Object> > propertyNames; for (int s=0; s < (int)allProps->Length(); ++s) { v8::Local<v8::Object>toPrint= v8::Local<v8::Object>::Cast(allProps->Get(s)); String errorMessage = "Error: error decoding first string in debug_checkCurrentContextX. "; String strVal, strVal2; bool stringDecoded = decodeString(toPrint, strVal,errorMessage); if (!stringDecoded) { SILOG(js,error,errorMessage); return; } v8::Local<v8::Value> valueToPrint = objToPrint->Get(v8::String::New(strVal.c_str(), strVal.length())); errorMessage = "Error: error decoding second string in debug_checkCurrentContextX. "; stringDecoded = decodeString(valueToPrint,strVal2,errorMessage); if (!stringDecoded) { SILOG(js,error,errorMessage); return; } std::cout<<" property "<< s <<": "<<strVal <<": "<<strVal2<<"\n"; } }
jarray TypeConverter::jsArrayToJavaArray(v8::Handle<v8::Array> jsArray) { JNIEnv *env = JNIScope::getEnv(); if (env == NULL) { return NULL; } int arrayLength = jsArray->Length(); jobjectArray javaArray = env->NewObjectArray(arrayLength, JNIUtil::objectClass, NULL); if (javaArray == NULL) { LOGE(TAG, "unable to create new jobjectArray"); return NULL; } for (int i = 0; i < arrayLength; i++) { v8::Local<v8::Value> element = jsArray->Get(i); bool isNew; jobject javaObject = jsValueToJavaObject(element, &isNew); env->SetObjectArrayElement(javaArray, i, javaObject); if (isNew) { env->DeleteLocalRef(javaObject); } } return javaArray; }
void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { // Use the frame where JavaScript is called from. Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); if (!frame) return; Page* page = frame->page(); if (!page) return; v8::Handle<v8::String> errorMessageString = message->Get(); ASSERT(!errorMessageString.IsEmpty()); String errorMessage = toWebCoreString(errorMessageString); v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); RefPtr<ScriptCallStack> callStack; // Currently stack trace is only collected when inspector is open. if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture); v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); bool useURL = resourceName.IsEmpty() || !resourceName->IsString(); String resourceNameString = useURL ? frame->document()->url() : toWebCoreString(resourceName); V8ConsoleMessage consoleMessage(errorMessage, resourceNameString, message->GetLineNumber()); consoleMessage.dispatchNow(page, callStack); }
static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { DOMWindow* firstWindow = firstDOMWindow(); if (!firstWindow->isCurrentlyDisplayedInFrame()) return; String errorMessage = toWebCoreString(message->Get()); v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); RefPtr<ScriptCallStack> callStack; // Currently stack trace is only collected when inspector is open. if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture); v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsString(); String resource = shouldUseDocumentURL ? firstWindow->document()->url() : toWebCoreString(resourceName); RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn()); // messageHandlerInMainThread can be called while we're creating a new context. // Since we cannot create a wrapper in the intermediate timing, we need to skip // creating a wrapper for |event|. DOMWrapperWorld* world = DOMWrapperWorld::current(); Frame* frame = firstWindow->document()->frame(); if (world && frame && frame->script()->existingWindowShell(world)) { v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Object>(), v8::Isolate::GetCurrent()); if (!wrappedEvent.IsEmpty()) { ASSERT(wrappedEvent->IsObject()); v8::Local<v8::Object>::Cast(wrappedEvent)->SetHiddenValue(V8HiddenPropertyName::error(), data); } } AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin; firstWindow->document()->reportException(event.release(), callStack, corsStatus); }
static void messageHandlerInWorker(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { static bool isReportingException = false; // Exceptions that occur in error handler should be ignored since in that case // WorkerGlobalScope::reportException will send the exception to the worker object. if (isReportingException) return; isReportingException = true; // During the frame teardown, there may not be a valid context. if (ScriptExecutionContext* context = getScriptExecutionContext()) { String errorMessage = toWebCoreString(message->Get()); String sourceURL = toWebCoreString(message->GetScriptResourceName()); RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, message->GetLineNumber(), message->GetStartColumn()); v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Object>(), v8::Isolate::GetCurrent()); if (!wrappedEvent.IsEmpty()) { ASSERT(wrappedEvent->IsObject()); v8::Local<v8::Object>::Cast(wrappedEvent)->SetHiddenValue(V8HiddenPropertyName::error(), data); } AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin; context->reportException(event.release(), 0, corsStatus); } isReportingException = false; }
static v8::Handle<v8::Function> eventListenerEffectiveFunction(v8::Isolate* isolate, v8::Handle<v8::Object> listenerObject) { v8::Handle<v8::Function> function; if (listenerObject->IsFunction()) { function = v8::Handle<v8::Function>::Cast(listenerObject); } else if (listenerObject->IsObject()) { // Try the "handleEvent" method (EventListener interface). v8::Handle<v8::Value> property = listenerObject->Get(v8AtomicString(isolate, "handleEvent")); if (property.IsEmpty() || !property->IsFunction()) { // Fall back to the "constructor" property. property = listenerObject->Get(v8AtomicString(isolate, "constructor")); } if (!property.IsEmpty() && property->IsFunction()) function = v8::Handle<v8::Function>::Cast(property); } return function; }
static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { ASSERT(isMainThread()); // It's possible that messageHandlerInMainThread() is invoked while we're initializing a window. // In that half-baked situation, we don't have a valid context nor a valid world, // so just return immediately. if (DOMWrapperWorld::windowIsBeingInitialized()) return; v8::Isolate* isolate = v8::Isolate::GetCurrent(); // If called during context initialization, there will be no entered window. LocalDOMWindow* enteredWindow = enteredDOMWindow(isolate); if (!enteredWindow) return; String errorMessage = toCoreString(message->Get()); v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); RefPtr<ScriptCallStack> callStack = nullptr; int scriptId = message->GetScriptOrigin().ScriptID()->Value(); // Currently stack trace is only collected when inspector is open. if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) { callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture, isolate); bool success = false; int topScriptId = callStack->at(0).scriptId().toInt(&success); if (success && topScriptId == scriptId) scriptId = 0; } else { Vector<ScriptCallFrame> callFrames; callStack = ScriptCallStack::create(callFrames); } v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName(); bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsString(); String resource = shouldUseDocumentURL ? enteredWindow->document()->url() : toCoreString(resourceName.As<v8::String>()); ScriptState* scriptState = ScriptState::current(isolate); RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn() + 1, &scriptState->world()); if (V8DOMWrapper::isDOMWrapper(data)) { v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(data); const WrapperTypeInfo* type = toWrapperTypeInfo(obj); if (V8DOMException::wrapperTypeInfo.isSubclass(type)) { DOMException* exception = V8DOMException::toNative(obj); if (exception && !exception->messageForConsole().isEmpty()) event->setUnsanitizedMessage("Uncaught " + exception->toStringForConsole()); } } // This method might be called while we're creating a new context. In this case, we // avoid storing the exception object, as we can't create a wrapper during context creation. // FIXME: Can we even get here during initialization now that we bail out when GetEntered returns an empty handle? LocalFrame* frame = enteredWindow->document()->frame(); if (frame && frame->script().existingWindowProxy(scriptState->world())) { V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, scriptState->context()->Global(), isolate); } enteredWindow->document()->reportException(event.release(), scriptId, callStack); }
static void init(v8::Handle<v8::Object> target) { NodeWxApp::Init(target); wxNode_wxFrame::Init(target); wxNode_wxMenu::Init(target); wxNode_wxMenuBar::Init(target); wxNode_wxPoint::Init(target); wxNode_wxSize::Init(target); wxNode_wxTextCtrl::Init(target); wxNode_wxPanel::Init(target); wxNode_wxListBox::Init(target); wxNode_wxSizerFlags::Init(target); wxNode_wxWindow::Init(target); wxNode_wxNotebook::Init(target); wxNode_wxBoxSizer::Init(target); wxNode_wxButton::Init(target); wxNode_wxStaticText::Init(target); wxNode_wxIcon::Init(target); wxNode_wxDialog::Init(target); NodeWxMessageBox::Init(target); NodeWxLogStatus::Init(target); { v8::Function* newWxSize = v8::Function::Cast(*target->Get(v8::String::New("wxSize"))); v8::Local<v8::Value> argv[0]; v8::Handle<v8::Object> s = newWxSize->CallAsConstructor(0, argv)->ToObject(); v8::Function *initFn = v8::Function::Cast(*s->Get(v8::String::New("init"))); v8::Local<v8::Value> initArgv[2]; initArgv[0] = v8::Number::New(wxDefaultSize.GetWidth()); initArgv[1] = v8::Number::New(wxDefaultSize.GetHeight()); initFn->Call(s, 2, initArgv); target->Set(v8::String::NewSymbol("wxDefaultSize"), s); } { v8::Function* newWxPosition = v8::Function::Cast(*target->Get(v8::String::New("wxPoint"))); v8::Local<v8::Value> argv[0]; v8::Handle<v8::Object> s = newWxPosition->CallAsConstructor(0, argv)->ToObject(); v8::Function *initFn = v8::Function::Cast(*s->Get(v8::String::New("init"))); v8::Local<v8::Value> initArgv[2]; initArgv[0] = v8::Number::New(wxDefaultSize.x); initArgv[1] = v8::Number::New(wxDefaultSize.y); initFn->Call(s, 2, initArgv); target->Set(v8::String::NewSymbol("wxDefaultPosition"), s); } }
void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> object) { String sourceID = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("id"))); ScriptDebugListener::Script script; script.url = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("name"))); script.source = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("source"))); script.sourceMappingURL = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("sourceMappingURL"))); script.startLine = object->Get(v8::String::New("startLine"))->ToInteger()->Value(); script.startColumn = object->Get(v8::String::New("startColumn"))->ToInteger()->Value(); script.endLine = object->Get(v8::String::New("endLine"))->ToInteger()->Value(); script.endColumn = object->Get(v8::String::New("endColumn"))->ToInteger()->Value(); script.isContentScript = object->Get(v8::String::New("isContentScript"))->ToBoolean()->Value(); listener->didParseSource(sourceID, script); }
static Value v8ValueToValue(v8::Handle<v8::Value> v8Value) { v8::HandleScope scope; if (v8Value->IsArray()) { List<Value> value; const v8::Handle<v8::Array> v8Array = v8::Handle<v8::Array>::Cast(v8Value); const uint32_t size = v8Array->Length(); for (uint32_t i = 0; i < size; ++i) { if (v8Array->Has(i)) value.append(v8ValueToValue(v8Array->Get(i))); else value.append(Value()); } return Value(value); } else if (v8Value->IsObject()) { Map<String, Value> value; const v8::Handle<v8::Object> v8Object = v8Value->ToObject(); const v8::Handle<v8::Array> props = v8Object->GetPropertyNames(); const uint32_t size = props->Length(); for (uint32_t i = 0; i < size; ++i) { assert(props->Has(i)); const v8::Handle<v8::Value> name = props->Get(i); value[String(*v8::String::Utf8Value(name))] = v8ValueToValue(v8Object->Get(name)); } return Value(value); } else if (v8Value->IsBoolean()) { return Value(v8Value->BooleanValue()); } else if (v8Value->IsInt32() || v8Value->IsUint32()) { return Value(v8Value->Int32Value()); } else if (v8Value->IsNumber()) { return Value(v8Value->NumberValue()); } else if (v8Value->IsString()) { return Value(String(*v8::String::Utf8Value(v8Value))); } else { error() << "Unexpected v8 value type in JSONParser"; } // undefined or null? return Value(); }
static bool extractBooleanValue(const v8::Handle<v8::Object>& object, const char* name, ExceptionCode& ec) { ec = 0; v8::Local<v8::Value> value = object->Get(v8::String::New(name)); if (!value.IsEmpty() && !isUndefinedOrNull(value)) { v8::TryCatch block; bool nativeValue = value->BooleanValue(); if (block.HasCaught()) { ec = TYPE_MISMATCH_ERR; return false; } return nativeValue; } return false; }
jdoubleArray TypeConverter::jsArrayToJavaDoubleArray(JNIEnv *env, v8::Handle<v8::Array> jsArray) { int arrayLength = jsArray->Length(); jdoubleArray javaDoubleArray = env->NewDoubleArray(arrayLength); if (javaDoubleArray == NULL) { LOGE(TAG, "unable to create new jdoubleArray"); return NULL; } jdouble* doubleBuffer = new jdouble[arrayLength]; for (int i = 0; i < arrayLength; i++) { v8::Local<v8::Value> element = jsArray->Get(i); doubleBuffer[i] = TypeConverter::jsNumberToJavaDouble(element->ToNumber()); } env->SetDoubleArrayRegion(javaDoubleArray, 0, arrayLength, doubleBuffer); return javaDoubleArray; }
jobjectArray TypeConverter::jsArrayToJavaStringArray(JNIEnv *env, v8::Handle<v8::Array> jsArray) { int arrayLength = jsArray->Length(); jobjectArray javaArray = env->NewObjectArray(arrayLength, JNIUtil::stringClass, NULL); if (javaArray == NULL) { LOGE(TAG, "unable to create new jobjectArray"); return NULL; } for (int i = 0; i < arrayLength; i++) { v8::Local<v8::Value> element = jsArray->Get(i); jstring javaObject = jsStringToJavaString(env, element->ToString()); env->SetObjectArrayElement(javaArray, i, javaObject); env->DeleteLocalRef(javaObject); } return javaArray; }
static void reportUncaughtException(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { DOMWindow* firstWindow = firstDOMWindow(BindingState::instance()); if (!firstWindow->isCurrentlyDisplayedInFrame()) return; String errorMessage = toWebCoreString(message->Get()); v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); RefPtr<ScriptCallStack> callStack; // Currently stack trace is only collected when inspector is open. if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture); v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsString(); String resource = shouldUseDocumentURL ? firstWindow->document()->url() : toWebCoreString(resourceName); firstWindow->document()->reportException(errorMessage, message->GetLineNumber(), resource, callStack); }
static void v8MessageHandler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { static bool isReportingException = false; // Exceptions that occur in error handler should be ignored since in that case // WorkerContext::reportException will send the exception to the worker object. if (isReportingException) return; isReportingException = true; // During the frame teardown, there may not be a valid context. if (ScriptExecutionContext* context = getScriptExecutionContext()) { String errorMessage = toWebCoreString(message->Get()); int lineNumber = message->GetLineNumber(); String sourceURL = toWebCoreString(message->GetScriptResourceName()); context->reportException(errorMessage, lineNumber, sourceURL, 0); } isReportingException = false; }
std::vector<BaseIndicator *> IndicatorFactory::CreateFromArray(v8::Handle<v8::Array> array) { unsigned indicatorCount = array->Length(); std::vector<std::string> indicatorNames; for (unsigned i = 0; i < indicatorCount; i++) { indicatorNames.push_back(std::string(*v8::String::Utf8Value(array->Get(i)->ToString()))); } std::vector<BaseIndicator *> indicators; for (unsigned long i = 0; i < indicatorNames.size(); i++) { BaseIndicator* indicator = IndicatorFactory::Create(indicatorNames[i]); indicators.push_back(indicator); } return indicators; }
bool get_option(v8::Isolate* isolate, v8::Handle<v8::Object> options, char const* name, T& value) { char const* dot = strchr(name, '.'); if (dot) { std::string const subname(name, dot); v8::HandleScope scope(isolate); v8::Local<v8::Object> suboptions; return get_option(isolate, options, subname.c_str(), suboptions) && get_option(isolate, suboptions, dot + 1, value); } v8::Local<v8::Value> val = options->Get(v8pp::to_v8(isolate, name)); if (val.IsEmpty() || val == v8::Undefined(isolate)) { return false; } value = from_v8<T>(isolate, val); return true; }
void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { // Use the frame where JavaScript is called from. Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); if (!frame) return; Page* page = frame->page(); if (!page) return; v8::Handle<v8::String> errorMessageString = message->Get(); ASSERT(!errorMessageString.IsEmpty()); String errorMessage = toWebCoreString(errorMessageString); v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); bool useURL = resourceName.IsEmpty() || !resourceName->IsString(); String resourceNameString = useURL ? frame->document()->url() : toWebCoreString(resourceName); V8ConsoleMessage consoleMessage(errorMessage, resourceNameString, message->GetLineNumber()); consoleMessage.dispatchNow(page); }
jintArray TypeConverter::jsArrayToJavaIntArray(v8::Handle<v8::Array> jsArray) { JNIEnv *env = JNIScope::getEnv(); if (env == NULL) { return NULL; } int arrayLength = jsArray->Length(); jintArray javaIntArray = env->NewIntArray(arrayLength); if (javaIntArray == NULL) { LOGE(TAG, "unable to create new jintArray"); return NULL; } jint* intBuffer = new jint[arrayLength]; for (int i = 0; i < arrayLength; i++) { v8::Local<v8::Value> element = jsArray->Get(i); intBuffer[i] = TypeConverter::jsNumberToJavaInt(element->ToNumber()); } env->SetIntArrayRegion(javaIntArray, 0, arrayLength, intBuffer); return javaIntArray; }
void QQmlJavaScriptExpression::exceptionToError(v8::Handle<v8::Message> message, QQmlError &error) { Q_ASSERT(!message.IsEmpty()); v8::Handle<v8::Value> name = message->GetScriptResourceName(); v8::Handle<v8::String> description = message->Get(); int lineNumber = message->GetLineNumber(); v8::Local<v8::String> file = name->IsString()?name->ToString():v8::Local<v8::String>(); if (file.IsEmpty() || file->Length() == 0) error.setUrl(QUrl()); else error.setUrl(QUrl(QV8Engine::toStringStatic(file))); error.setLine(lineNumber); error.setColumn(-1); QString qDescription = QV8Engine::toStringStatic(description); if (qDescription.startsWith(QLatin1String("Uncaught "))) qDescription = qDescription.mid(9 /* strlen("Uncaught ") */); error.setDescription(qDescription); }
static int FillShapeValueArray (v8::Isolate* isolate, VocShaper* shaper, TRI_shape_value_t* dst, v8::Handle<v8::Object> const json, size_t level, set<int>& seenHashes, vector<v8::Handle<v8::Object>>& seenObjects, bool create) { v8::HandleScope scope(isolate); TRI_shape_value_t* values; TRI_shape_value_t* p; TRI_shape_value_t* e; TRI_array_shape_t* a; TRI_shape_sid_t* sids; TRI_shape_aid_t* aids; TRI_shape_size_t* offsetsF; TRI_shape_size_t* offsetsV; TRI_shape_size_t offset; TRI_shape_t const* found; char* ptr; // number of attributes v8::Handle<v8::Array> names = json->GetOwnPropertyNames(); uint32_t n = names->Length(); // convert into TRI_shape_value_t array p = (values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->memoryZone(), n * sizeof(TRI_shape_value_t), true))); if (p == nullptr) { return TRI_ERROR_OUT_OF_MEMORY; } size_t total = 0; size_t f = 0; size_t v = 0; for (uint32_t i = 0; i < n; ++i, ++p) { v8::Handle<v8::Value> key = names->Get(i); // first find an identifier for the name TRI_Utf8ValueNFC keyStr(TRI_UNKNOWN_MEM_ZONE, key); if (*keyStr == 0 || keyStr.length() == 0) { --p; continue; } if ((*keyStr)[0] == '_' && level == 0) { // on top level, strip reserved attributes before shaping char const* k = (*keyStr); if (strcmp(k, "_key") == 0 || strcmp(k, "_rev") == 0 || strcmp(k, "_id") == 0 || strcmp(k, "_from") == 0 || strcmp(k, "_to") == 0) { // found a reserved attribute - discard it --p; continue; } } if (create) { p->_aid = shaper->findOrCreateAttributeByName(*keyStr); } else { p->_aid = shaper->lookupAttributeByName(*keyStr); } int res; // convert value if (p->_aid == 0) { if (create) { res = TRI_ERROR_INTERNAL; } else { res = TRI_RESULT_ELEMENT_NOT_FOUND; } } else { v8::Handle<v8::Value> val = json->Get(key); res = FillShapeValueJson(isolate, shaper, p, val, level + 1, seenHashes, seenObjects, create); } if (res != TRI_ERROR_NO_ERROR) { for (e = p, p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return res; } total += static_cast<size_t>(p->_size); // count fixed and variable sized values if (p->_fixedSized) { ++f; } else { ++v; } } // adjust n n = (uint32_t) (f + v); // add variable offset table size total += (v + 1) * sizeof(TRI_shape_size_t); // now sort the shape entries if (n > 1) { TRI_SortShapeValues(values, (size_t) n); } #ifdef DEBUG_JSON_SHAPER printf("shape values\n------------\ntotal: %u, fixed: %u, variable: %u\n", (unsigned int) n, (unsigned int) f, (unsigned int) v); TRI_PrintShapeValues(values, n); printf("\n"); #endif // generate shape structure size_t const totalSize = sizeof(TRI_array_shape_t) + n * sizeof(TRI_shape_sid_t) + n * sizeof(TRI_shape_aid_t) + (f + 1) * sizeof(TRI_shape_size_t); a = (TRI_array_shape_t*) (ptr = (char*) TRI_Allocate(shaper->memoryZone(), totalSize, true)); if (ptr == nullptr) { e = values + n; for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_OUT_OF_MEMORY; } a->base._type = TRI_SHAPE_ARRAY; a->base._size = (TRI_shape_size_t) totalSize; a->base._dataSize = (v == 0) ? total : TRI_SHAPE_SIZE_VARIABLE; a->_fixedEntries = f; a->_variableEntries = v; ptr += sizeof(TRI_array_shape_t); // array of shape identifiers sids = (TRI_shape_sid_t*) ptr; ptr += n * sizeof(TRI_shape_sid_t); // array of attribute identifiers aids = (TRI_shape_aid_t*) ptr; ptr += n * sizeof(TRI_shape_aid_t); // array of offsets for fixed part (within the shape) offset = (v + 1) * sizeof(TRI_shape_size_t); offsetsF = (TRI_shape_size_t*) ptr; // fill destination (except sid) dst->_type = TRI_SHAPE_ARRAY; dst->_fixedSized = true; dst->_size = total; dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->memoryZone(), dst->_size, true))); if (ptr == nullptr) { e = values + n; for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); TRI_Free(shaper->memoryZone(), a); return TRI_ERROR_OUT_OF_MEMORY; } // array of offsets for variable part (within the value) offsetsV = (TRI_shape_size_t*) ptr; ptr += (v + 1) * sizeof(TRI_shape_size_t); // and fill in attributes e = values + n; for (p = values; p < e; ++p) { *aids++ = p->_aid; *sids++ = p->_sid; if (p->_value != nullptr) { memcpy(ptr, p->_value, static_cast<size_t>(p->_size)); } ptr += p->_size; dst->_fixedSized &= p->_fixedSized; if (p->_fixedSized) { *offsetsF++ = offset; offset += p->_size; *offsetsF = offset; } else { *offsetsV++ = offset; offset += p->_size; *offsetsV = offset; } } // free TRI_shape_value_t array for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); // lookup this shape found = shaper->findShape(&a->base, create); if (found == nullptr) { LOG_TRACE("shaper failed to find shape %d", (int) a->base._type); TRI_Free(shaper->memoryZone(), dst->_value); TRI_Free(shaper->memoryZone(), a); if (! create) { return TRI_RESULT_ELEMENT_NOT_FOUND; } return TRI_ERROR_INTERNAL; } // and finally add the sid dst->_sid = found->_sid; return TRI_ERROR_NO_ERROR; }
v8::Handle<v8::Value> JS_GetArrayElemnet(v8::Handle<v8::Array> pArray,unsigned index) { if(pArray.IsEmpty()) return v8::Handle<v8::Value>(); return pArray->Get(index); }
/////////////////////////////// // QMiner-JavaScript-Stream-Aggr TNodeJsStreamAggr::TNodeJsStreamAggr(TWPt<TQm::TBase> _Base, const TStr& _AggrNm, v8::Handle<v8::Object> TriggerVal) : TStreamAggr(_Base, _AggrNm) { v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); // Every stream aggregate should implement these two QmAssertR(TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "onAdd")), "TNodeJsStreamAggr constructor, name: " + _AggrNm + ", type: javaScript. Missing onAdd callback. Possible reason: type of the aggregate was not specified and it defaulted to javaScript."); QmAssertR(TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "saveJson")), "TNodeJsStreamAggr constructor, name: " + _AggrNm + ", type: javaScript. Missing saveJson callback. Possible reason: type of the aggregate was not specified and it defaulted to javaScript."); v8::Handle<v8::Value> _OnAddFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "onAdd")); QmAssert(_OnAddFun->IsFunction()); OnAddFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_OnAddFun)); if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "onUpdate"))) { v8::Handle<v8::Value> _OnUpdateFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "onUpdate")); QmAssert(_OnUpdateFun->IsFunction()); OnUpdateFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_OnUpdateFun)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "onDelete"))) { v8::Handle<v8::Value> _OnDeleteFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "onDelete")); QmAssert(_OnDeleteFun->IsFunction()); OnDeleteFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_OnDeleteFun)); } v8::Handle<v8::Value> _SaveJsonFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "saveJson")); QmAssert(_SaveJsonFun->IsFunction()); SaveJsonFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_SaveJsonFun)); // StreamAggr::_Save if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "save"))) { v8::Handle<v8::Value> _Save = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "save")); QmAssert(_Save->IsFunction()); SaveFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_Save)); } // StreamAggr::_Load if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "load"))) { v8::Handle<v8::Value> _Load = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "load")); QmAssert(_Load->IsFunction()); LoadFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_Load)); } // IInt if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getInt"))) { v8::Handle<v8::Value> _GetInt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getInt")); QmAssert(_GetInt->IsFunction()); GetIntFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetInt)); } // IFlt if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFlt"))) { v8::Handle<v8::Value> _GetFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFlt")); QmAssert(_GetFlt->IsFunction()); GetFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFlt)); } // ITm if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getTm"))) { v8::Handle<v8::Value> _GetTm = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getTm")); QmAssert(_GetTm->IsFunction()); GetTmMSecsFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetTm)); } // IFltTmIO if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getInFlt"))) { v8::Handle<v8::Value> _GetInFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getInFlt")); QmAssert(_GetInFlt->IsFunction()); GetInFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetInFlt)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getInTm"))) { v8::Handle<v8::Value> _GetInTm = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getInTm")); QmAssert(_GetInTm->IsFunction()); GetInTmMSecsFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetInTm)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getOutFltV"))) { v8::Handle<v8::Value> _GetOutFltV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getOutFltV")); QmAssert(_GetOutFltV->IsFunction()); GetOutFltVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetOutFltV)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getOutTmV"))) { v8::Handle<v8::Value> _GetOutTmV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getOutTmV")); QmAssert(_GetOutTmV->IsFunction()); GetOutTmMSecsVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetOutTmV)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getN"))) { v8::Handle<v8::Value> _GetN = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getN")); QmAssert(_GetN->IsFunction()); GetNFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetN)); } // IFltVec if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFltLen"))) { v8::Handle<v8::Value> _GetFltLen = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFltLen")); QmAssert(_GetFltLen->IsFunction()); GetFltLenFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFltLen)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFltAt"))) { v8::Handle<v8::Value> _GetFltAt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFltAt")); QmAssert(_GetFltAt->IsFunction()); GetFltAtFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFltAt)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFltV"))) { v8::Handle<v8::Value> _GetFltV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFltV")); QmAssert(_GetFltV->IsFunction()); GetFltVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFltV)); } // INmFlt if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "isNmFlt"))) { v8::Handle<v8::Value> _IsNmFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "isNmFlt")); QmAssert(_IsNmFlt->IsFunction()); IsNmFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_IsNmFlt)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmFlt"))) { v8::Handle<v8::Value> _GetNmFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmFlt")); QmAssert(_GetNmFlt->IsFunction()); GetNmFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmFlt)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmFltV"))) { v8::Handle<v8::Value> _GetNmFltV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmFltV")); QmAssert(_GetNmFltV->IsFunction()); GetNmFltVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmFltV)); } // INmInt if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "isNm"))) { v8::Handle<v8::Value> _IsNm = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "isNm")); QmAssert(_IsNm->IsFunction()); IsNmFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_IsNm)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmInt"))) { v8::Handle<v8::Value> _GetNmInt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmInt")); QmAssert(_GetNmInt->IsFunction()); GetNmIntFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmInt)); } if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmIntV"))) { v8::Handle<v8::Value> _GetNmIntV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmIntV")); QmAssert(_GetNmIntV->IsFunction()); GetNmIntVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmIntV)); } }
static int FillShapeValueList (v8::Isolate* isolate, VocShaper* shaper, TRI_shape_value_t* dst, v8::Handle<v8::Array> const json, size_t level, set<int>& seenHashes, vector<v8::Handle<v8::Object>>& seenObjects, bool create) { size_t total; TRI_shape_value_t* values; TRI_shape_value_t* p; TRI_shape_value_t* e; bool hs; bool hl; TRI_shape_sid_t s; TRI_shape_sid_t l; TRI_shape_size_t* offsets; TRI_shape_size_t offset; TRI_shape_t const* found; char* ptr; // check for special case "empty list" uint32_t n = json->Length(); if (n == 0) { dst->_type = TRI_SHAPE_LIST; dst->_sid = BasicShapes::TRI_SHAPE_SID_LIST; dst->_fixedSized = false; dst->_size = sizeof(TRI_shape_length_list_t); dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->memoryZone(), dst->_size, false))); if (dst->_value == nullptr) { return TRI_ERROR_OUT_OF_MEMORY; } * (TRI_shape_length_list_t*) ptr = 0; return TRI_ERROR_NO_ERROR; } // convert into TRI_shape_value_t array p = (values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->memoryZone(), sizeof(TRI_shape_value_t) * n, true))); if (p == nullptr) { return TRI_ERROR_OUT_OF_MEMORY; } total = 0; e = values + n; for (uint32_t i = 0; i < n; ++i, ++p) { v8::Handle<v8::Value> el = json->Get(i); int res = FillShapeValueJson(isolate, shaper, p, el, level + 1, seenHashes, seenObjects, create); if (res != TRI_ERROR_NO_ERROR) { for (e = p, p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return res; } total += static_cast<size_t>(p->_size); } // check if this list is homoegenous hs = true; hl = true; s = values[0]._sid; l = values[0]._size; p = values; for (; p < e; ++p) { if (p->_sid != s) { hs = false; break; } if (p->_size != l) { hl = false; } } // homogeneous sized if (hs && hl) { auto shape = static_cast<TRI_homogeneous_sized_list_shape_t*>(TRI_Allocate(shaper->memoryZone(), sizeof(TRI_homogeneous_sized_list_shape_t), true)); if (shape == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_OUT_OF_MEMORY; } shape->base._size = sizeof(TRI_homogeneous_sized_list_shape_t); shape->base._type = TRI_SHAPE_HOMOGENEOUS_SIZED_LIST; shape->base._dataSize = TRI_SHAPE_SIZE_VARIABLE; shape->_sidEntry = s; shape->_sizeEntry = l; found = shaper->findShape(&shape->base, create); if (found == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); TRI_Free(shaper->memoryZone(), shape); LOG_TRACE("shaper failed to find shape of type %d", (int) shape->base._type); if (! create) { return TRI_RESULT_ELEMENT_NOT_FOUND; } return TRI_ERROR_INTERNAL; } TRI_ASSERT(found != nullptr); dst->_type = found->_type; dst->_sid = found->_sid; dst->_fixedSized = false; dst->_size = sizeof(TRI_shape_length_list_t) + total; dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->memoryZone(), dst->_size, false))); if (dst->_value == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_OUT_OF_MEMORY; } // copy sub-objects into data space * (TRI_shape_length_list_t*) ptr = (TRI_shape_length_list_t) n; ptr += sizeof(TRI_shape_length_list_t); for (p = values; p < e; ++p) { if (p->_value != nullptr) { memcpy(ptr, p->_value, static_cast<size_t>(p->_size)); } ptr += p->_size; } } // homogeneous else if (hs) { auto shape = static_cast<TRI_homogeneous_list_shape_t*>(TRI_Allocate(shaper->memoryZone(), sizeof(TRI_homogeneous_list_shape_t), true)); if (shape == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_OUT_OF_MEMORY; } shape->base._size = sizeof(TRI_homogeneous_list_shape_t); shape->base._type = TRI_SHAPE_HOMOGENEOUS_LIST; shape->base._dataSize = TRI_SHAPE_SIZE_VARIABLE; shape->_sidEntry = s; // if found returns non-NULL, it will free the shape!! found = shaper->findShape(&shape->base, create); if (found == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } LOG_TRACE("shaper failed to find shape %d", (int) shape->base._type); TRI_Free(shaper->memoryZone(), values); TRI_Free(shaper->memoryZone(), shape); if (! create) { return TRI_RESULT_ELEMENT_NOT_FOUND; } return TRI_ERROR_INTERNAL; } TRI_ASSERT(found != nullptr); dst->_type = found->_type; dst->_sid = found->_sid; offset = sizeof(TRI_shape_length_list_t) + (n + 1) * sizeof(TRI_shape_size_t); dst->_fixedSized = false; dst->_size = offset + total; dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->memoryZone(), dst->_size, true))); if (dst->_value == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_OUT_OF_MEMORY; } // copy sub-objects into data space * (TRI_shape_length_list_t*) ptr = (TRI_shape_length_list_t) n; ptr += sizeof(TRI_shape_length_list_t); offsets = (TRI_shape_size_t*) ptr; ptr += (n + 1) * sizeof(TRI_shape_size_t); for (p = values; p < e; ++p) { *offsets++ = offset; offset += p->_size; if (p->_value != nullptr) { memcpy(ptr, p->_value, static_cast<size_t>(p->_size)); } ptr += p->_size; } *offsets = offset; } // in-homogeneous else { dst->_type = TRI_SHAPE_LIST; dst->_sid = BasicShapes::TRI_SHAPE_SID_LIST; offset = sizeof(TRI_shape_length_list_t) + n * sizeof(TRI_shape_sid_t) + (n + 1) * sizeof(TRI_shape_size_t); dst->_fixedSized = false; dst->_size = offset + total; dst->_value = (ptr = (char*) TRI_Allocate(shaper->memoryZone(), dst->_size, true)); if (dst->_value == nullptr) { for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_OUT_OF_MEMORY; } // copy sub-objects into data space * (TRI_shape_length_list_t*) ptr = (TRI_shape_length_list_t) n; ptr += sizeof(TRI_shape_length_list_t); TRI_shape_sid_t* sids = (TRI_shape_sid_t*) ptr; ptr += n * sizeof(TRI_shape_sid_t); offsets = (TRI_shape_size_t*) ptr; ptr += (n + 1) * sizeof(TRI_shape_size_t); for (p = values; p < e; ++p) { *sids++ = p->_sid; *offsets++ = offset; offset += p->_size; if (p->_value != nullptr) { memcpy(ptr, p->_value, static_cast<size_t>(p->_size)); } ptr += p->_size; } *offsets = offset; } // free TRI_shape_value_t array for (p = values; p < e; ++p) { if (p->_value != nullptr) { TRI_Free(shaper->memoryZone(), p->_value); } } TRI_Free(shaper->memoryZone(), values); return TRI_ERROR_NO_ERROR; }