ScriptPromise::ScriptPromise(ScriptState* scriptState, v8::Local<v8::Value> value) : m_scriptState(scriptState) { increaseInstanceCount(); if (value.IsEmpty()) return; if (!value->IsPromise()) { m_promise = ScriptValue(scriptState, v8::Local<v8::Value>()); V8ThrowException::throwTypeError(scriptState->isolate(), "the given value is not a Promise"); return; } m_promise = ScriptValue(scriptState, value); }
bool V8DOMWrapper::isWrapper(v8::Isolate* isolate, v8::Local<v8::Value> value) { if (value.IsEmpty() || !value->IsObject()) return false; v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) return false; const WrapperTypeInfo* untrustedWrapperTypeInfo = toWrapperTypeInfo(object); V8PerIsolateData* perIsolateData = V8PerIsolateData::from(isolate); if (!(untrustedWrapperTypeInfo && perIsolateData)) return false; return perIsolateData->hasInstance(untrustedWrapperTypeInfo, object); }
bool OptionsObject::getKey(const String& key, v8::Local<v8::Value>& value) const { if (isUndefinedOrNull()) return false; v8::Local<v8::Object> options = m_options->ToObject(); ASSERT(!options.IsEmpty()); v8::Handle<v8::String> v8Key = v8String(key); if (!options->Has(v8Key)) return false; value = options->Get(v8Key); if (value.IsEmpty()) return false; return true; }
bool V8DOMWrapper::hasInternalFieldsSet(v8::Local<v8::Value> value) { if (value.IsEmpty() || !value->IsObject()) return false; v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) return false; const ScriptWrappable* untrustedScriptWrappable = toScriptWrappable(object); const WrapperTypeInfo* untrustedWrapperTypeInfo = toWrapperTypeInfo(object); return untrustedScriptWrappable && untrustedWrapperTypeInfo && untrustedWrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink; }
void resetInternalsObject(v8::Local<v8::Context> context) { // This can happen if JavaScript is disabled in the main frame. if (context.IsEmpty()) return; v8::Context::Scope contextScope(context); v8::HandleScope scope; ScriptExecutionContext* scriptContext = getScriptExecutionContext(); ASSERT(scriptContext->isDocument()); Page* page = static_cast<Document*>(scriptContext)->frame()->page(); Internals::resetToConsistentState(page); InternalSettings::from(page)->resetToConsistentState(); }
std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const { v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "wrapTable"); function.appendArgument(table); if (columns.IsEmpty()) function.appendArgument(false); else function.appendArgument(columns); bool hadException = false; v8::Local<v8::Value> r = function.call(hadException); if (hadException) return nullptr; protocol::ErrorSupport errors; return protocol::Runtime::RemoteObject::parse(toProtocolValue(m_context->context(), r).get(), &errors); }
result_t SandBox::require(const char *id, v8::Local<v8::Value> &retVal) { std::string fname = resolvePath(id); std::map<std::string, VariantEx >::iterator it; // remove .js ext name if exists if (fname.length() > 3 && !qstrcmp(&fname[fname.length() - 3], ".js")) fname.resize(fname.length() - 3); it = m_mods.find(fname); if (it != m_mods.end()) { retVal = it->second; return 1; } if (!m_require.IsEmpty()) { v8::Local<v8::Value> arg = v8::String::NewFromUtf8(isolate, fname.c_str()); retVal = v8::Local<v8::Function>::New(isolate, m_require)->Call(wrap(), 1, &arg); if (retVal.IsEmpty()) return CALL_E_JAVASCRIPT; if (!IsEmpty(retVal)) { if (retVal->IsObject() && !object_base::getInstance(retVal)) retVal = retVal->ToObject()->Clone(); InstallModule(fname, retVal); return 0; } } // append .js ext name fname += ".js"; result_t hr; const char *pname = fname.c_str(); std::string buf; hr = fs_base::ac_readFile(pname, buf); if (hr < 0) return hr; return addScript(pname, buf.c_str(), retVal); }
std::vector<WideString> CFX_V8::GetObjectPropertyNames( v8::Local<v8::Object> pObj) { if (pObj.IsEmpty()) return std::vector<WideString>(); v8::Local<v8::Array> val; v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); if (!pObj->GetPropertyNames(context).ToLocal(&val)) return std::vector<WideString>(); std::vector<WideString> result; for (uint32_t i = 0; i < val->Length(); ++i) { result.push_back(ToWideString(val->Get(context, i).ToLocalChecked())); } return result; }
void V8BooleanOrString::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, BooleanOrString& impl, ExceptionState& exceptionState) { if (v8Value.IsEmpty()) return; if (v8Value->IsBoolean()) { impl.setBoolean(v8Value->ToBoolean()->Value()); return; } { TOSTRING_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, v8Value, exceptionState); impl.setString(cppValue); return; } }
bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const { if (isUndefinedOrNull()) return false; v8::Local<v8::Object> options = m_options->ToObject(); ASSERT(!options.IsEmpty()); ASSERT(m_isolate); ASSERT(m_isolate == v8::Isolate::GetCurrent()); v8::Handle<v8::String> v8Key = v8String(m_isolate, key); if (!options->Has(v8Key)) return false; value = options->Get(v8Key); if (value.IsEmpty()) return false; return true; }
result_t util_base::flatten(v8::Local<v8::Value> list, bool shallow, v8::Local<v8::Array> &retVal) { if (!list->IsObject()) return CHECK_ERROR(CALL_E_TYPEMISMATCH); bool bNext = true; Isolate* isolate = Isolate::current(); if (retVal.IsEmpty()) retVal = v8::Array::New(isolate->m_isolate); else if (shallow) bNext = false; v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast(list); v8::Local<v8::Value> v = o->Get(isolate->NewFromUtf8("length")); if (IsEmpty(v)) return CHECK_ERROR(CALL_E_TYPEMISMATCH); int32_t len = v->Int32Value(); int32_t cnt = retVal->Length(); int32_t i; for (i = 0; i < len; i ++) { v = o->Get(i); if (bNext && v->IsObject()) { v8::Local<v8::Object> o1 = v8::Local<v8::Object>::Cast(v); v = o->Get(isolate->NewFromUtf8("length")); if (IsEmpty(v)) retVal->Set(cnt ++, o->Get(i)); else { flatten(o1, shallow, retVal); cnt = retVal->Length(); } } else retVal->Set(cnt ++, o->Get(i)); } return 0; }
v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(ScriptState* scriptState, v8::Local<v8::Value> jsEvent, Event* event) { ASSERT(!jsEvent.IsEmpty()); v8::Local<v8::Function> handlerFunction = getListenerFunction(scriptState); v8::Local<v8::Object> receiver = getReceiverObject(scriptState, event); if (handlerFunction.IsEmpty() || receiver.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> parameters[1] = { jsEvent }; v8::MaybeLocal<v8::Value> maybeResult = V8ScriptRunner::callFunction(handlerFunction, scriptState->executionContext(), receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate()); TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data()); v8::Local<v8::Value> result; if (!maybeResult.ToLocal(&result)) return v8::Local<v8::Value>(); return result; }
// static CJS_Value::Type CJS_Value::GetValueType(v8::Local<v8::Value> value) { if (value.IsEmpty()) return VT_unknown; if (value->IsString()) return VT_string; if (value->IsNumber()) return VT_number; if (value->IsBoolean()) return VT_boolean; if (value->IsDate()) return VT_date; if (value->IsObject()) return VT_object; if (value->IsNull()) return VT_null; if (value->IsUndefined()) return VT_undefined; return VT_unknown; }
inline result_t GetArray(v8::Local<v8::Value> v, QuickArray<T> &n) { if (v.IsEmpty() || !v->IsArray()) return CALL_E_INVALIDARG; v8::Local<v8::Array> a = v8::Local<v8::Array>::Cast(v); result_t hr; for (int32_t i = 0; i < (int32_t)a->Length(); i ++) { T vr; hr = GetArgumentValue(a->Get(i), vr, true); if (hr < 0) return hr; n.append(vr); } return 0; }
result_t Url::set_query(v8::Local<v8::Value> newVal) { if (!newVal.IsEmpty()) { if (newVal->IsString() || newVal->IsStringObject()) { m_query = *v8::String::Utf8Value(newVal); if (m_queryParsed) { m_queryParsed = new HttpCollection(); m_queryParsed->parse(m_query); } } else { obj_ptr<HttpCollection> queryParsed = (HttpCollection*)HttpCollection_base::getInstance(newVal); if (!queryParsed) return CHECK_ERROR(CALL_E_INVALIDARG); m_queryParsed = queryParsed; } } return 0; }
v8::Local<v8::Object> ImageData::associateWithWrapper( v8::Isolate* isolate, const WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) { wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper); if (!wrapper.IsEmpty() && m_data.get()) { // Create a V8 Uint8ClampedArray object and set the "data" property // of the ImageData object to the created v8 object, eliminating the // C++ callback when accessing the "data" property. v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty( isolate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::ReadOnly))) return v8::Local<v8::Object>(); } return wrapper; }
void V8TestInterfaceGarbageCollectedOrString::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, TestInterfaceGarbageCollectedOrString& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState) { if (v8Value.IsEmpty()) return; if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull(v8Value)) return; if (V8TestInterfaceGarbageCollected::hasInstance(v8Value, isolate)) { TestInterfaceGarbageCollected* cppValue = V8TestInterfaceGarbageCollected::toImpl(v8::Local<v8::Object>::Cast(v8Value)); impl.setTestInterfaceGarbageCollected(cppValue); return; } { V8StringResource<> cppValue = v8Value; if (!cppValue.prepare(exceptionState)) return; impl.setString(cppValue); return; } }
void V8NodeOrNodeList::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, NodeOrNodeList& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState) { if (v8Value.IsEmpty()) return; if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull(v8Value)) return; if (V8Node::hasInstance(v8Value, isolate)) { Node* cppValue = V8Node::toImpl(v8::Local<v8::Object>::Cast(v8Value)); impl.setNode(cppValue); return; } if (V8NodeList::hasInstance(v8Value, isolate)) { NodeList* cppValue = V8NodeList::toImpl(v8::Local<v8::Object>::Cast(v8Value)); impl.setNodeList(cppValue); return; } exceptionState.throwTypeError("The provided value is not of type '(Node or NodeList)'"); }
ExecuteBaton::ExecuteBaton(oracle::occi::Environment* m_environment, oracle::occi::StatelessConnectionPool* m_connectionPool, oracle::occi::Connection* m_connection, bool m_autoCommit, int m_prefetchRowCount, const char* sql, v8::Local<v8::Array> values, v8::Local<v8::Object> options, v8::Local<v8::Function> callback) { this->m_environment = m_environment; this->m_connectionPool = m_connectionPool; this->m_connection = m_connection; this->m_autoCommit = m_autoCommit; this->m_prefetchRowCount = m_prefetchRowCount; this->sql = sql; this->outputs = new vector<output_t*>(); this->error = NULL; this->callback = callback.IsEmpty() ? NULL : new Nan::Callback(callback); CopyValuesToBaton(this, values); SetOptionsInBaton(this, options); }
v8::Local<v8::Value> V8ErrorHandler::callListenerFunction(ScriptState* scriptState, v8::Local<v8::Value> jsEvent, Event* event) { ASSERT(!jsEvent.IsEmpty()); if (!event->hasInterface(EventNames::ErrorEvent)) return V8EventListener::callListenerFunction(scriptState, jsEvent, event); ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event); if (errorEvent->world() && errorEvent->world() != &world()) return v8::Null(isolate()); v8::Local<v8::Object> listener = getListenerObject(scriptState->executionContext()); if (listener.IsEmpty() || !listener->IsFunction()) return v8::Null(isolate()); v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener); v8::Local<v8::Object> thisValue = scriptState->context()->Global(); v8::Local<v8::Object> eventObject; if (!jsEvent->ToObject(scriptState->context()).ToLocal(&eventObject)) return v8::Null(isolate()); v8::Local<v8::Value> error = V8HiddenValue::getHiddenValue(isolate(), eventObject, V8HiddenValue::error(isolate())); if (error.IsEmpty()) error = v8::Null(isolate()); v8::Local<v8::Value> parameters[5] = { v8String(isolate(), errorEvent->message()), v8String(isolate(), errorEvent->filename()), v8::Integer::New(isolate(), errorEvent->lineno()), v8::Integer::New(isolate(), errorEvent->colno()), error }; v8::TryCatch tryCatch; tryCatch.SetVerbose(true); v8::MaybeLocal<v8::Value> result; if (scriptState->executionContext()->isWorkerGlobalScope()) { result = V8ScriptRunner::callFunction(callFunction, scriptState->executionContext(), thisValue, WTF_ARRAY_LENGTH(parameters), parameters, isolate()); } else { result = ScriptController::callFunction(scriptState->executionContext(), callFunction, thisValue, WTF_ARRAY_LENGTH(parameters), parameters, isolate()); } v8::Local<v8::Value> returnValue; if (!result.ToLocal(&returnValue)) return v8::Null(isolate()); return returnValue; }
void V8TestInterfaceOrTestInterfaceEmpty::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, TestInterfaceOrTestInterfaceEmpty& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState) { if (v8Value.IsEmpty()) return; if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull(v8Value)) return; if (V8TestInterface::hasInstance(v8Value, isolate)) { TestInterfaceImplementation* cppValue = V8TestInterface::toImpl(v8::Local<v8::Object>::Cast(v8Value)); impl.setTestInterface(cppValue); return; } if (V8TestInterfaceEmpty::hasInstance(v8Value, isolate)) { TestInterfaceEmpty* cppValue = V8TestInterfaceEmpty::toImpl(v8::Local<v8::Object>::Cast(v8Value)); impl.setTestInterfaceEmpty(cppValue); return; } exceptionState.throwTypeError("The provided value is not of type '(TestInterface or TestInterfaceEmpty)'"); }
void V8StringOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, StringOrDouble& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState) { if (v8Value.IsEmpty()) return; if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull(v8Value)) return; if (v8Value->IsNumber()) { double cppValue = toRestrictedDouble(isolate, v8Value, exceptionState); if (exceptionState.hadException()) return; impl.setDouble(cppValue); return; } { V8StringResource<> cppValue = v8Value; if (!cppValue.prepare(exceptionState)) return; impl.setString(cppValue); return; } }
double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0.0; v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return pValue->ToNumber(context).ToLocalChecked()->Value(); }
jobject v8ToJava(JNIEnv* env, v8::Local<v8::Value> arg) { if(arg.IsEmpty() || arg->IsNull() || arg->IsUndefined()) { return NULL; } if(arg->IsArray()) { v8::Local<v8::Array> array = v8::Array::Cast(*arg); uint32_t arraySize = array->Length(); jclass objectClazz = env->FindClass("java/lang/Object"); jobjectArray result = env->NewObjectArray(arraySize, objectClazz, NULL); for(uint32_t i=0; i<arraySize; i++) { jobject val = v8ToJava(env, array->Get(i)); env->SetObjectArrayElement(result, i, val); } return result; } if(arg->IsString()) { v8::String::Utf8Value val(arg->ToString()); return env->NewStringUTF(*val); } if(arg->IsInt32() || arg->IsUint32()) { jint val = arg->ToInt32()->Value(); jclass clazz = env->FindClass("java/lang/Integer"); jmethodID constructor = env->GetMethodID(clazz, "<init>", "(I)V"); return env->NewObject(clazz, constructor, val); } if(arg->IsNumber()) { jdouble val = arg->ToNumber()->Value(); jclass clazz = env->FindClass("java/lang/Double"); jmethodID constructor = env->GetMethodID(clazz, "<init>", "(D)V"); return env->NewObject(clazz, constructor, val); } if(arg->IsBoolean()) { jboolean val = arg->ToBoolean()->Value(); jclass clazz = env->FindClass("java/lang/Boolean"); jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Z)V"); return env->NewObject(clazz, constructor, val); } if(arg->IsObject()) { v8::Local<v8::Object> obj = v8::Object::Cast(*arg); v8::Local<v8::Value> isJavaObject = obj->GetHiddenValue(v8::String::New(V8_HIDDEN_MARKER_JAVA_OBJECT)); if(!isJavaObject.IsEmpty() && isJavaObject->IsBoolean()) { return v8ToJava_javaObject(env, obj); } v8::Local<v8::Value> isJavaLong = obj->GetHiddenValue(v8::String::New(V8_HIDDEN_MARKER_JAVA_LONG)); if(!isJavaLong.IsEmpty() && isJavaLong->IsBoolean()) { return v8ToJava_javaLong(env, obj); } } // TODO: handle other arg types v8::String::AsciiValue typeStr(arg); printf("v8ToJava: Unhandled type: %s\n", *typeStr); return NULL; }
void FXJS_FreePrivate(v8::Local<v8::Object> pObj) { if (pObj.IsEmpty() || !pObj->InternalFieldCount()) return; FXJS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); pObj->SetAlignedPointerInInternalField(0, NULL); }
v8::Local<v8::Value> FXJS_NewObject2(v8::Isolate* pIsolate, v8::Local<v8::Array> pObj) { if (pObj.IsEmpty()) return v8::Local<v8::Value>(); return pObj->Clone(); }
unsigned CFX_V8::GetArrayLength(v8::Local<v8::Array> pArray) { if (pArray.IsEmpty()) return 0; return pArray->Length(); }
bool FXJS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return false; v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); return pValue->ToBoolean(context).ToLocalChecked()->Value(); }
v8::Local<v8::Array> CFX_V8::ToArray(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty() || !pValue->IsArray()) return v8::Local<v8::Array>(); v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); }
bool CFX_V8::ToBoolean(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return false; return pValue->BooleanValue(m_pIsolate.Get()); }