osmium::osm_entity_bits::type object_to_entity_bits(v8::Local<v8::Object> options) { osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::nothing; v8::Local<v8::Value> want_nodes = options->Get(symbol_node); if (want_nodes->IsBoolean() && want_nodes->BooleanValue()) { entities |= osmium::osm_entity_bits::node; } v8::Local<v8::Value> want_ways = options->Get(symbol_way); if (want_ways->IsBoolean() && want_ways->BooleanValue()) { entities |= osmium::osm_entity_bits::way; } v8::Local<v8::Value> want_relations = options->Get(symbol_relation); if (want_relations->IsBoolean() && want_relations->BooleanValue()) { entities |= osmium::osm_entity_bits::relation; } v8::Local<v8::Value> want_changesets = options->Get(symbol_changeset); if (want_changesets->IsBoolean() && want_changesets->BooleanValue()) { entities |= osmium::osm_entity_bits::changeset; } return entities; }
result_t Stats_base::_new(v8::Local<v8::Array> staticKeys, v8::Local<v8::Array> keys, obj_ptr<Stats_base> &retVal, v8::Local<v8::Object> This) { obj_ptr<Stats> pStats = new Stats(); int sn = staticKeys->Length(); int n = keys->Length(); int i; result_t hr; pStats->init(sn, n + sn); for (i = 0; i < sn; i++) { hr = pStats->set_key(i, staticKeys->Get(i)); if (hr < 0) return hr; } for (i = 0; i < n; i++) { hr = pStats->set_key(sn + i, keys->Get(i)); if (hr < 0) return hr; } retVal = pStats; return 0; }
result_t MongoCollection::update(v8::Local<v8::Object> query, v8::Local<v8::Object> document, v8::Local<v8::Object> options) { Isolate* isolate = holder(); return update(query, document, options->Get(isolate->NewString("upsert", 6))->BooleanValue(), options->Get(isolate->NewString("multi", 5))->BooleanValue()); }
result_t Image::affine(v8::Local<v8::Array> affine, int32_t x, int32_t y, int32_t width, int32_t height, obj_ptr<Image_base>& retVal) { if (!m_image) return CHECK_ERROR(CALL_E_INVALID_CALL); if (x == -1 && y == -1 && width == -1 && height == -1) { width = gdImageSX(m_image); height = gdImageSY(m_image); } else if (x < 0 || y < 0 || width < 0 || height < 0 || affine->Length() != 6 ) return CHECK_ERROR(CALL_E_INVALIDARG); obj_ptr<Image> dst = new Image(); gdRect rect; rect.x = x; rect.y = y; rect.width = width; rect.height = height; double affineMatrix[6]; for ( int32_t i = 0; i <= 5; i++) affineMatrix[i] = affine->Get(i)->NumberValue(); gdTransformAffineGetImage(&dst->m_image, m_image, &rect, affineMatrix); dst->setExtMemory(); retVal = dst; return 0; }
result_t Routing::append(v8::Local<v8::Object> map) { v8::Local<v8::Array> ks = map->GetPropertyNames(); int32_t len = ks->Length(); int32_t i; result_t hr; for (i = len - 1; i >= 0; i--) { v8::Local<v8::Value> k = ks->Get(i); v8::Local<v8::Value> v = map->Get(k); obj_ptr<Handler_base> hdlr = Handler_base::getInstance(v); if (hdlr) { append(*v8::String::Utf8Value(k), hdlr); continue; } hr = append(*v8::String::Utf8Value(k), v); if (hr < 0) return hr; } return 0; }
void JsVlcPlayer::initLibvlc( const v8::Local<v8::Array>& vlcOpts ) { using namespace v8; if( _libvlc ) { assert( false ); libvlc_release( _libvlc ); _libvlc = nullptr; } if( vlcOpts.IsEmpty() || vlcOpts->Length() == 0 ) { _libvlc = libvlc_new( 0, nullptr ); } else { std::deque<std::string> opts; std::vector<const char*> libvlcOpts; for( unsigned i = 0 ; i < vlcOpts->Length(); ++i ) { String::Utf8Value opt( vlcOpts->Get(i)->ToString() ); if( opt.length() ) { auto it = opts.emplace( opts.end(), *opt ); libvlcOpts.push_back( it->c_str() ); } } _libvlc = libvlc_new( libvlcOpts.size(), libvlcOpts.data() ); } }
void ExecuteBaton::SetOptionsInBaton(ExecuteBaton* baton, v8::Local<v8::Object> options) { baton->getColumnMetaData = !options.IsEmpty() ? options->Get(Nan::New<String>("getColumnMetaData").ToLocalChecked())->BooleanValue() : false; }
static void messageHandlerInWorker(v8::Local<v8::Message> message, v8::Local<v8::Value> data) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); V8PerIsolateData* perIsolateData = V8PerIsolateData::from(isolate); // During the frame teardown, there may not be a valid context. ScriptState* scriptState = ScriptState::current(isolate); if (!scriptState->contextIsValid()) return; // Exceptions that occur in error handler should be ignored since in that case // WorkerGlobalScope::reportException will send the exception to the worker object. if (perIsolateData->isReportingException()) return; perIsolateData->setReportingException(true); ExecutionContext* context = scriptState->getExecutionContext(); std::unique_ptr<SourceLocation> location = SourceLocation::fromMessage(isolate, message, context); ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), std::move(location), &scriptState->world()); AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin; // If execution termination has been triggered as part of constructing // the error event from the v8::Message, quietly leave. if (!isolate->IsExecutionTerminating()) { V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, data, scriptState->context()->Global()); scriptState->getExecutionContext()->reportException(event, corsStatus); } perIsolateData->setReportingException(false); }
static bool populateContextMenuItems(v8::Isolate* isolate, const v8::Local<v8::Array>& itemArray, ContextMenu& menu) { v8::Local<v8::Context> context = isolate->GetCurrentContext(); for (size_t i = 0; i < itemArray->Length(); ++i) { v8::Local<v8::Object> item = itemArray->Get(context, i).ToLocalChecked().As<v8::Object>(); v8::Local<v8::Value> type; v8::Local<v8::Value> id; v8::Local<v8::Value> label; v8::Local<v8::Value> enabled; v8::Local<v8::Value> checked; v8::Local<v8::Value> subItems; if (!item->Get(context, v8AtomicString(isolate, "type")).ToLocal(&type) || !item->Get(context, v8AtomicString(isolate, "id")).ToLocal(&id) || !item->Get(context, v8AtomicString(isolate, "label")).ToLocal(&label) || !item->Get(context, v8AtomicString(isolate, "enabled")) .ToLocal(&enabled) || !item->Get(context, v8AtomicString(isolate, "checked")) .ToLocal(&checked) || !item->Get(context, v8AtomicString(isolate, "subItems")) .ToLocal(&subItems)) return false; if (!type->IsString()) continue; String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); if (typeString == "separator") { ContextMenuItem item(ContextMenuItem( SeparatorType, ContextMenuItemCustomTagNoAction, String(), String())); menu.appendItem(item); } else if (typeString == "subMenu" && subItems->IsArray()) { ContextMenu subMenu; v8::Local<v8::Array> subItemsArray = v8::Local<v8::Array>::Cast(subItems); if (!populateContextMenuItems(isolate, subItemsArray, subMenu)) return false; TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelString, label, false); ContextMenuItem item(SubmenuType, ContextMenuItemCustomTagNoAction, labelString, String(), &subMenu); menu.appendItem(item); } else { int32_t int32Id; if (!v8Call(id->Int32Value(context), int32Id)) return false; ContextMenuAction typedId = static_cast<ContextMenuAction>( ContextMenuItemBaseCustomTag + int32Id); TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelString, label, false); ContextMenuItem menuItem( (typeString == "checkbox" ? CheckableActionType : ActionType), typedId, labelString, String()); if (checked->IsBoolean()) menuItem.setChecked(checked.As<v8::Boolean>()->Value()); if (enabled->IsBoolean()) menuItem.setEnabled(enabled.As<v8::Boolean>()->Value()); menu.appendItem(menuItem); } } return true; }
static inline bool propertyKey(v8::Local<v8::Context> v8Context, v8::Local<v8::Array> properties, uint32_t index, v8::Local<v8::String>& key) { v8::Local<v8::Value> property; if (!properties->Get(v8Context, index).ToLocal(&property)) return false; return property->ToString(v8Context).ToLocal(&key); }
jobject v8ToJava_javaLong(JNIEnv* env, v8::Local<v8::Object> obj) { jobject longValue = v8ToJava(env, obj->Get(v8::String::New("longValue"))); jclass longClazz = env->FindClass("java/lang/Long"); jmethodID long_constructor = env->GetMethodID(longClazz, "<init>", "(Ljava/lang/String;)V"); jobject jobj = env->NewObject(longClazz, long_constructor, longValue); return jobj; }
result_t coroutine_base::parallel(v8::Local<v8::Array> func, v8::Local<v8::Array> &retVal) { int l = func->Length(); int i; if (l == 0) { retVal = v8::Array::New(isolate); return 0; } std::vector<v8::Local<v8::Function> > funs; funs.resize(l); for (i = 0; i < l; i++) { v8::Local<v8::Value> v = func->Get(i); if (!v.IsEmpty() && v->IsFunction()) funs[i] = v8::Local<v8::Function>::Cast(v); else return CHECK_ERROR(CALL_E_INVALIDARG); } return _parallel(funs, retVal); }
result_t Buffer::write(v8::Local<v8::Array> datas) { int32_t sz = datas->Length(); if (sz) { int32_t i; result_t hr; std::string str; str.resize(sz); for (i = 0; i < sz; i ++) { v8::Local<v8::Value> v = datas->Get(i); int32_t num; hr = GetArgumentValue(v, num); if (hr < 0) return hr; if (num < 0 || num > 256) return CHECK_ERROR(CALL_E_OUTRANGE); str[i] = num; } extMemory((int) sz); m_data.append(str); } return 0; }
result_t coroutine_base::parallel(v8::Local<v8::Array> data, v8::Local<v8::Function> func, v8::Local<v8::Array> &retVal) { std::vector<obj_ptr<JSFiber> > fibers; int i; int len = data->Length(); if (len == 0) { retVal = v8::Array::New(isolate); return 0; } fibers.resize(len); for (i = 1; i < (int) len; i++) { v8::Local<v8::Value> v = data->Get(i); JSFiber::New(func, &v, 1, fibers[i]); } v8::Local<v8::Value> r; v8::Local<v8::Value> v = data->Get(0); JSFiber::call(func, &v, 1, r); bool bError = r.IsEmpty(); if (!bError) { retVal = v8::Array::New(isolate, len); retVal->Set(0, r); } for (i = 1; i < len; i++) { JSFiber *fb = fibers[i]; fb->join(); if (fb->isError()) bError = true; else if (!bError && fb->get_result(r) != CALL_RETURN_NULL) retVal->Set(i, r); } if (bError) return CHECK_ERROR(CALL_E_INTERNAL); return 0; }
result_t querystring_base::stringify(v8::Local<v8::Object> obj, exlib::string sep, exlib::string eq, v8::Local<v8::Object> opt, exlib::string& retVal) { StringBuffer bufs; v8::Local<v8::Array> ks = obj->GetPropertyNames(); int32_t len = ks->Length(); int32_t i; result_t hr; for (i = 0; i < len; i++) { exlib::string strKey, strValue, str; v8::Local<v8::Array> vs; v8::Local<v8::Value> k = ks->Get(i); v8::Local<v8::Value> v = obj->Get(k); GetArgumentValue(k, strKey); encoding_base::encodeURIComponent(strKey, strKey); hr = GetArgumentValue(v, vs, true); if (hr >= 0) { int32_t len1 = vs->Length(); int32_t i1; for (i1 = 0; i1 < len1; i1++) { hr = GetArgumentValue(vs->Get(i1), strValue); if (hr < 0) return hr; encoding_base::encodeURIComponent(strValue, strValue); if (bufs.size() > 0) bufs.append(sep); bufs.append(strKey); bufs.append(eq); bufs.append(strValue); } } else { hr = GetArgumentValue(v, strValue); if (hr < 0) return hr; encoding_base::encodeURIComponent(strValue, strValue); if (bufs.size() > 0) bufs.append(sep); bufs.append(strKey); bufs.append(eq); bufs.append(strValue); } } retVal = bufs.str(); return 0; }
bool hasProperty(v8::Local<v8::Object> obj, std::string property) { //v8::HandleScope scope; //Check field: id v8::Local<v8::Value> id = obj->Get(ToV8<std::string>(property)); bool res = ( id.IsEmpty() ) ? false : true; //return scope.Close(ToV8<bool>(res)); return res; }
static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local<v8::Value> data) { ASSERT(isMainThread()); v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (isolate->GetEnteredContext().IsEmpty()) return; // If called during context initialization, there will be no entered context. ScriptState* scriptState = ScriptState::current(isolate); if (!scriptState->contextIsValid()) return; ExecutionContext* context = scriptState->getExecutionContext(); std::unique_ptr<SourceLocation> location = SourceLocation::fromMessage(isolate, message, context); AccessControlStatus accessControlStatus = NotSharableCrossOrigin; if (message->IsOpaque()) accessControlStatus = OpaqueResource; else if (message->IsSharedCrossOrigin()) accessControlStatus = SharableCrossOrigin; ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), std::move(location), &scriptState->world()); String messageForConsole = extractMessageForConsole(isolate, data); if (!messageForConsole.isEmpty()) event->setUnsanitizedMessage("Uncaught " + messageForConsole); // 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? if (context->isDocument()) { LocalFrame* frame = toDocument(context)->frame(); if (frame && frame->script().existingWindowProxy(scriptState->world())) { V8ErrorHandler::storeExceptionOnErrorEventWrapper( scriptState, event, data, scriptState->context()->Global()); } } if (scriptState->world().isPrivateScriptIsolatedWorld()) { // We allow a private script to dispatch error events even in a // EventDispatchForbiddenScope scope. Without having this ability, it's // hard to debug the private script because syntax errors in the private // script are not reported to console (the private script just crashes // silently). Allowing error events in private scripts is safe because // error events don't propagate to other isolated worlds (which means that // the error events won't fire any event listeners in user's scripts). EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; context->dispatchErrorEvent(event, accessControlStatus); } else { context->dispatchErrorEvent(event, accessControlStatus); } }
v8::Local<v8::Value> CFX_V8::GetArrayElement(v8::Local<v8::Array> pArray, unsigned index) { if (pArray.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; if (!pArray->Get(m_pIsolate->GetCurrentContext(), index).ToLocal(&val)) return v8::Local<v8::Value>(); return val; }
double TNodeJsUtil::GetFldFlt(v8::Local<v8::Object> Obj, const TStr& FldNm) { v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); EAssertR(IsFldFlt(Obj, FldNm), "The field is not an integer!"); v8::Local<v8::Value> FldVal = Obj->Get(v8::String::NewFromUtf8(Isolate, FldNm.CStr())); return FldVal->NumberValue(); }
WARN_UNUSED_RESULT static v8::MaybeLocal<v8::String> getStringValueInArray( v8::Local<v8::Context> context, v8::Local<v8::Array> array, uint32_t index) { v8::Local<v8::Value> value; if (!array->Get(context, index).ToLocal(&value)) return v8::MaybeLocal<v8::String>(); return value->ToString(context); }
result_t Url::format(v8::Local<v8::Object> args) { clear(); Isolate* isolate = holder(); exlib::string str; v8::Local<v8::Value> v; if (getString(isolate, args, "protocol", str)) set_protocol(str); if (getString(isolate, args, "username", str)) set_username(str); if (getString(isolate, args, "password", str)) set_password(str); if (getString(isolate, args, "host", str)) set_host(str); if (getString(isolate, args, "port", str)) set_port(str); if (getString(isolate, args, "hostname", str)) set_hostname(str); if (getString(isolate, args, "pathname", str)) set_pathname(str); v = args->Get(holder()->NewString("query")); if (!IsEmpty(v)) set_query(v); if (getString(isolate, args, "hash", str)) set_hash(str); if (m_slashes && m_protocol.compare("file:") && m_hostname.length() == 0) m_slashes = false; v = args->Get(holder()->NewString("slashes")); if (!IsEmpty(v)) set_slashes(v->BooleanValue()); return 0; }
bool TNodeJsUtil::IsFldFlt(v8::Local<v8::Object> Obj, const TStr& FldNm) { if (!IsObjFld(Obj, FldNm)) { return false; } v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); v8::Local<v8::Value> FldVal = Obj->Get(v8::String::NewFromUtf8(Isolate, FldNm.CStr())); return FldVal->IsNumber() || FldVal->IsNumberObject(); }
bool TNodeJsUtil::IsFldNull(v8::Local<v8::Object> Obj, const TStr& FldNm) { if (!IsObjFld(Obj, FldNm)) { return true; } // the field exists, check if it is null v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); v8::Local<v8::Value> FldVal = Obj->Get(v8::String::NewFromUtf8(Isolate, FldNm.CStr())); return FldVal->IsNull() || FldVal->IsUndefined(); }
v8::Local<v8::Value> CFXJS_Engine::GetObjectProperty( v8::Local<v8::Object> pObj, const CFX_WideString& wsPropertyName) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; if (!pObj->Get(m_isolate->GetCurrentContext(), WSToJSString(wsPropertyName)) .ToLocal(&val)) return v8::Local<v8::Value>(); return val; }
v8::Local<v8::Value> CFX_V8::GetObjectProperty( v8::Local<v8::Object> pObj, ByteStringView bsUTF8PropertyName) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; if (!pObj->Get(m_pIsolate->GetCurrentContext(), NewString(bsUTF8PropertyName)) .ToLocal(&val)) return v8::Local<v8::Value>(); return val; }
v8::Local<v8::Function> TNodeJsUtil::GetFldFun(v8::Local<v8::Object> Obj, const TStr& FldNm) { v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); EAssertR(IsFldFun(Obj, FldNm), "The field is not a function!"); v8::Local<v8::Value> FldVal = Obj->Get(v8::String::NewFromUtf8(Isolate, FldNm.CStr())); v8::Local<v8::Function> RetFun = v8::Handle<v8::Function>::Cast(FldVal); return RetFun; }
v8::Local<v8::Object> TNodeJsUtil::GetFldObj(v8::Local<v8::Object> Obj, const TStr& FldNm) { v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); EAssertR(IsObjFld(Obj, FldNm), "TNodeJsUtil::GetUnwrapFld: Key " + FldNm + " is missing!"); v8::Handle<v8::Value> FldVal = Obj->Get(v8::String::NewFromUtf8(Isolate, FldNm.CStr())); EAssertR(FldVal->IsObject(), "TNodeJsUtil::GetUnwrapFld: Key " + FldNm + " is not an object"); v8::Handle<v8::Object> FldObj = v8::Handle<v8::Object>::Cast(FldVal); return FldObj; }
v8::Local<v8::Value> FXJS_GetObjectElement(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; if (!pObj->Get(pIsolate->GetCurrentContext(), FXJS_WSToJSString(pIsolate, PropertyName)).ToLocal(&val)) return v8::Local<v8::Value>(); return val; }
bool getString(Isolate* isolate, v8::Local<v8::Object>& args, const char* key, exlib::string& retVal) { v8::Local<v8::Value> v = args->Get(isolate->NewString(key)); if (!v.IsEmpty() && (v->IsString() || v->IsStringObject())) { retVal = *v8::String::Utf8Value(v); return true; } return false; }
bool TNodeJsUtil::IsFldClass(v8::Local<v8::Object> Obj, const TStr& FldNm, const TStr& ClassId) { if (!IsObjFld(Obj, FldNm)) { return false; } v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); v8::Local<v8::Value> FldVal = Obj->Get(v8::String::NewFromUtf8(Isolate, FldNm.CStr())); v8::Handle<v8::Object> FldObj = v8::Handle<v8::Object>::Cast(FldVal); TStr ClassStr = GetClass(FldObj); return ClassStr.EqI(ClassId); }