v8::Local<v8::FunctionTemplate> V8TestInterfaceNamedConstructor2Constructor::domTemplate(v8::Isolate* isolate) { static int domTemplateKey; // This address is used for a key to look up the dom template. V8PerIsolateData* data = V8PerIsolateData::from(isolate); v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey); if (!result.IsEmpty()) return result; TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); result = v8::FunctionTemplate::New(isolate, V8TestInterfaceNamedConstructor2ConstructorCallback); v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); instanceTemplate->SetInternalFieldCount(V8TestInterfaceNamedConstructor2::internalFieldCount); result->SetClassName(v8AtomicString(isolate, "TestInterfaceNamedConstructor2")); result->Inherit(V8TestInterfaceNamedConstructor2::domTemplate(isolate)); data->setDOMTemplate(&domTemplateKey, result); return result; }
static void installV8TestInterfaceNamedConstructor2Template(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestInterfaceNamedConstructor2", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceNamedConstructor2::internalFieldCount, 0, 0, 0, 0, 0, 0); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void configureV8TestInterface3Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterface3", v8::Local<v8::FunctionTemplate>(), V8TestInterface3::internalFieldCount, 0, 0, 0, 0, 0, 0, isolate); v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestInterface3V8Internal::indexedPropertyGetterCallback, TestInterface3V8Internal::indexedPropertySetterCallback, 0, TestInterface3V8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestInterface3>); functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestInterface3V8Internal::namedPropertyGetterCallback, TestInterface3V8Internal::namedPropertySetterCallback, TestInterface3V8Internal::namedPropertyQueryCallback, TestInterface3V8Internal::namedPropertyDeleterCallback, TestInterface3V8Internal::namedPropertyEnumeratorCallback); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void configureV8TestTypedefsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestTypedefs", v8::Local<v8::FunctionTemplate>(), V8TestTypedefs::internalFieldCount, V8TestTypedefsAttributes, WTF_ARRAY_LENGTH(V8TestTypedefsAttributes), 0, 0, V8TestTypedefsMethods, WTF_ARRAY_LENGTH(V8TestTypedefsMethods), isolate); functionTemplate->SetCallHandler(V8TestTypedefs::constructorCallback); functionTemplate->SetLength(1); v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void configureV8TestInterfaceConstructor3Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor3", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor3::internalFieldCount, 0, 0, 0, 0, 0, 0, isolate); functionTemplate->SetCallHandler(V8TestInterfaceConstructor3::constructorCallback); functionTemplate->SetLength(1); v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate(); v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate(); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void configureV8TestSpecialOperationsCustomTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestSpecialOperationsCustom", v8::Local<v8::FunctionTemplate>(), V8TestSpecialOperationsCustom::internalFieldCount, 0, 0, 0, 0, 0, 0, isolate, currentWorldType); v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate(); v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate(); functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestSpecialOperationsCustomV8Internal::indexedPropertyGetterCallback, TestSpecialOperationsCustomV8Internal::indexedPropertySetterCallback, 0, TestSpecialOperationsCustomV8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestSpecialOperationsCustom>); functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestSpecialOperationsCustomV8Internal::namedPropertyGetterCallback, TestSpecialOperationsCustomV8Internal::namedPropertySetterCallback, TestSpecialOperationsCustomV8Internal::namedPropertyQueryCallback, TestSpecialOperationsCustomV8Internal::namedPropertyDeleterCallback, TestSpecialOperationsCustomV8Internal::namedPropertyEnumeratorCallback); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate()); }
static void installV8SVGTestInterfaceTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "SVGTestInterface", v8::Local<v8::FunctionTemplate>(), V8SVGTestInterface::internalFieldCount, V8SVGTestInterfaceAttributes, WTF_ARRAY_LENGTH(V8SVGTestInterfaceAttributes), 0, 0, 0, 0, isolate); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context) : m_wrapperBoilerplates(context->GetIsolate()) , m_constructorMap(context->GetIsolate()) , m_isolate(context->GetIsolate()) , m_contextHolder(adoptPtr(new gin::ContextHolder(context->GetIsolate()))) , m_context(m_isolate, context) , m_customElementBindings(adoptPtr(new CustomElementBindingMap())) { m_contextHolder->SetContext(context); v8::Context::Scope contextScope(context); ASSERT(m_errorPrototype.isEmpty()); v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(v8AtomicString(m_isolate, "Error"))); ASSERT(!object.IsEmpty()); v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate, "prototype")); ASSERT(!prototypeValue.IsEmpty()); m_errorPrototype.set(m_isolate, prototypeValue); }
void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) { if (!m_resolver) return; ScriptState* scriptState = m_resolver->getScriptState(); ScriptState::Scope scope(scriptState); v8::Local<v8::String> jsonString = v8AtomicString(scriptState->isolate(), utf8Data, length); v8::TryCatch exceptionCatcher(scriptState->isolate()); v8::Local<v8::Value> jsonDictionary; if (v8Call(v8::JSON::Parse(scriptState->isolate(), jsonString), jsonDictionary, exceptionCatcher)) m_resolver->resolve(jsonDictionary); else m_resolver->reject(exceptionCatcher.Exception()); clearResolver(); }
V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context) : m_isolate(context->GetIsolate()) , m_wrapperBoilerplates(m_isolate) , m_constructorMap(m_isolate) , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate))) , m_context(m_isolate, context) , m_activityLogger(0) , m_compiledPrivateScript(m_isolate) { m_contextHolder->SetContext(context); v8::Context::Scope contextScope(context); ASSERT(m_errorPrototype.isEmpty()); v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(v8AtomicString(m_isolate, "Error"))); ASSERT(!object.IsEmpty()); v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate, "prototype")); ASSERT(!prototypeValue.IsEmpty()); m_errorPrototype.set(m_isolate, prototypeValue); }
static void installV8TestNodeTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestNode", V8Node::domTemplate(isolate), V8TestNode::internalFieldCount, 0, 0, V8TestNodeAccessors, WTF_ARRAY_LENGTH(V8TestNodeAccessors), 0, 0); functionTemplate->SetCallHandler(V8TestNode::constructorCallback); functionTemplate->SetLength(0); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void constructorOfToString(const v8::FunctionCallbackInfo<v8::Value>& info) { // The DOM constructors' toString functions grab the current toString // for Functions by taking the toString function of itself and then // calling it with the constructor as its receiver. This means that // changes to the Function prototype chain or toString function are // reflected when printing DOM constructors. The only wart is that // changes to a DOM constructor's toString's toString will cause the // toString of the DOM constructor itself to change. This is extremely // obscure and unlikely to be a problem. v8::Handle<v8::Value> value = info.Callee()->Get(v8AtomicString(info.GetIsolate(), "toString")); if (!value->IsFunction()) { v8SetReturnValue(info, v8::String::Empty(info.GetIsolate())); return; } v8::Local<v8::Value> result; if (V8ScriptRunner::callInternalFunction(v8::Handle<v8::Function>::Cast(value), info.This(), 0, 0, info.GetIsolate()).ToLocal(&result)) v8SetReturnValue(info, result); }
static void installV8TestInterfaceWillBeGarbageCollectedTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestInterfaceWillBeGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceWillBeGarbageCollected::internalFieldCount, V8TestInterfaceWillBeGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedAttributes), 0, 0, V8TestInterfaceWillBeGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedMethods)); functionTemplate->SetCallHandler(V8TestInterfaceWillBeGarbageCollected::constructorCallback); functionTemplate->SetLength(1); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
short V8NodeFilterCondition::acceptNode(Node* node, ExceptionState& exceptionState) const { v8::Isolate* isolate = m_scriptState->isolate(); ASSERT(!m_scriptState->context().IsEmpty()); v8::HandleScope handleScope(isolate); v8::Local<v8::Value> filter = m_filter.newLocal(isolate); ASSERT(filter.IsEmpty() || filter->IsObject()); if (filter.IsEmpty()) return NodeFilter::FILTER_ACCEPT; v8::TryCatch exceptionCatcher; v8::Local<v8::Function> callback; v8::Local<v8::Value> receiver; if (filter->IsFunction()) { callback = v8::Local<v8::Function>::Cast(filter); receiver = v8::Undefined(isolate); } else { v8::Local<v8::Value> value = filter->ToObject(isolate)->Get(v8AtomicString(isolate, "acceptNode")); if (value.IsEmpty() || !value->IsFunction()) { exceptionState.throwTypeError("NodeFilter object does not have an acceptNode function"); return NodeFilter::FILTER_REJECT; } callback = v8::Local<v8::Function>::Cast(value); receiver = filter; } OwnPtr<v8::Local<v8::Value>[]> info = adoptArrayPtr(new v8::Local<v8::Value>[1]); info[0] = toV8(node, m_scriptState->context()->Global(), isolate); v8::Local<v8::Value> result = ScriptController::callFunction(m_scriptState->executionContext(), callback, receiver, 1, info.get(), isolate); if (exceptionCatcher.HasCaught()) { exceptionState.rethrowV8Exception(exceptionCatcher.Exception()); return NodeFilter::FILTER_REJECT; } ASSERT(!result.IsEmpty()); return result->Int32Value(); }
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; }
v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const WrapperTypeInfo* type) { ASSERT(!m_errorPrototype.isEmpty()); v8::Local<v8::Context> currentContext = context(); v8::Context::Scope scope(currentContext); const DOMWrapperWorld& world = DOMWrapperWorld::world(currentContext); // We shouldn't reach this point for the types that are implemented in v8 such as typed arrays and // hence don't have domTemplateFunction. ASSERT(type->domTemplateFunction); v8::Local<v8::FunctionTemplate> interfaceTemplate = type->domTemplate(m_isolate, world); // Getting the function might fail if we're running out of stack or memory. v8::Local<v8::Function> interfaceObject; if (!interfaceTemplate->GetFunction(currentContext).ToLocal(&interfaceObject)) return v8::Local<v8::Function>(); if (type->parentClass) { v8::Local<v8::Object> prototypeTemplate = constructorForType(type->parentClass); if (prototypeTemplate.IsEmpty()) return v8::Local<v8::Function>(); if (!v8CallBoolean(interfaceObject->SetPrototype(currentContext, prototypeTemplate))) return v8::Local<v8::Function>(); } v8::Local<v8::Value> prototypeValue; if (!interfaceObject->Get(currentContext, v8AtomicString(m_isolate, "prototype")).ToLocal(&prototypeValue) || !prototypeValue->IsObject()) return v8::Local<v8::Function>(); v8::Local<v8::Object> prototypeObject = prototypeValue.As<v8::Object>(); if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectPrototype) prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type)); type->preparePrototypeAndInterfaceObject(currentContext, world, prototypeObject, interfaceObject, interfaceTemplate); if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionPrototype) { if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_errorPrototype.newLocal(m_isolate)))) return v8::Local<v8::Function>(); } m_constructorMap.Set(type, interfaceObject); return interfaceObject; }
static void installV8TestInterfaceGarbageCollectedTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestInterfaceGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceGarbageCollected::internalFieldCount, 0, 0, V8TestInterfaceGarbageCollectedAccessors, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedAccessors), V8TestInterfaceGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedMethods)); functionTemplate->SetCallHandler(V8TestInterfaceGarbageCollected::constructorCallback); functionTemplate->SetLength(1); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); const V8DOMConfiguration::SymbolKeyedMethodConfiguration symbolKeyedIteratorConfiguration = { v8::Symbol::GetIterator, TestInterfaceGarbageCollectedV8Internal::iteratorMethodCallback, 0, v8::DontDelete, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype }; V8DOMConfiguration::installMethod(isolate, prototypeTemplate, defaultSignature, symbolKeyedIteratorConfiguration); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void configureV8TestInterfaceDoNotCheckConstantsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceDoNotCheckConstants", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceDoNotCheckConstants::internalFieldCount, 0, 0, 0, 0, 0, 0, isolate, currentWorldType); v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate(); v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate(); static const V8DOMConfiguration::ConstantConfiguration V8TestInterfaceDoNotCheckConstantsConstants[] = { {"CONST_VALUE_0", 0}, {"CONST_JAVASCRIPT", 1}, }; V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, V8TestInterfaceDoNotCheckConstantsConstants, WTF_ARRAY_LENGTH(V8TestInterfaceDoNotCheckConstantsConstants), isolate); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate()); }
v8::Local<v8::Function> V8EventListener::getListenerFunction(ExecutionContext*) { v8::Local<v8::Object> listener = getListenerObject(scriptState()->executionContext()); // Has the listener been disposed? if (listener.IsEmpty()) return v8::Local<v8::Function>(); if (listener->IsFunction()) return v8::Local<v8::Function>::Cast(listener); if (listener->IsObject()) { v8::Local<v8::Value> property = listener->Get(v8AtomicString(isolate(), "handleEvent")); // Check that no exceptions were thrown when getting the // handleEvent property and that the value is a function. if (!property.IsEmpty() && property->IsFunction()) return v8::Local<v8::Function>::Cast(property); } return v8::Local<v8::Function>(); }
v8::Local<v8::Function> V8EventListener::getListenerFunction( ScriptState* scriptState) { v8::Local<v8::Object> listener = getListenerObject(scriptState->getExecutionContext()); // Has the listener been disposed? if (listener.IsEmpty()) return v8::Local<v8::Function>(); if (listener->IsFunction()) return v8::Local<v8::Function>::Cast(listener); // The EventHandler callback function type (used for event handler // attributes in HTML) has [TreatNonObjectAsNull], which implies that // non-function objects should be treated as no-op functions that return // undefined. if (isAttribute()) return v8::Local<v8::Function>(); // Getting the handleEvent property can runs script in the getter. if (ScriptForbiddenScope::isScriptForbidden()) { V8ThrowException::throwError(isolate(), "Script execution is forbidden."); return v8::Local<v8::Function>(); } if (listener->IsObject()) { // Check that no exceptions were thrown when getting the // handleEvent property and that the value is a function. v8::Local<v8::Value> property; if (listener ->Get(scriptState->context(), v8AtomicString(isolate(), "handleEvent")) .ToLocal(&property) && property->IsFunction()) return v8::Local<v8::Function>::Cast(property); } return v8::Local<v8::Function>(); }
void V8HTMLDocument::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder()); if (info.Length() > 2) { if (RefPtr<LocalFrame> frame = htmlDocument->frame()) { // Fetch the global object for the frame. v8::Local<v8::Context> context = toV8Context(info.GetIsolate(), frame.get(), DOMWrapperWorld::current(info.GetIsolate())); // Bail out if we cannot get the context. if (context.IsEmpty()) return; v8::Local<v8::Object> global = context->Global(); // Get the open property of the global object. v8::Local<v8::Value> function = global->Get(v8AtomicString(info.GetIsolate(), "open")); // Failed; return without throwing (new) exception. if (function.IsEmpty()) return; // If the open property is not a function throw a type error. if (!function->IsFunction()) { throwTypeError("open is not a function", info.GetIsolate()); return; } // Wrap up the arguments and call the function. OwnPtr<v8::Local<v8::Value>[]> params = adoptArrayPtr(new v8::Local<v8::Value>[info.Length()]); for (int i = 0; i < info.Length(); i++) params[i] = info[i]; v8SetReturnValue(info, frame->script().callFunction(v8::Local<v8::Function>::Cast(function), global, info.Length(), params.get())); return; } } ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Document", info.Holder(), info.GetIsolate()); htmlDocument->open(callingDOMWindow(info.GetIsolate())->document(), exceptionState); if (exceptionState.throwIfNeeded()) return; v8SetReturnValue(info, info.Holder()); }
v8::Local<v8::Function> V8EventListener::getListenerFunction(ScriptState* scriptState) { v8::Local<v8::Object> listener = getListenerObject(scriptState->executionContext()); // Has the listener been disposed? if (listener.IsEmpty()) return v8::Local<v8::Function>(); if (listener->IsFunction()) return v8::Local<v8::Function>::Cast(listener); if (listener->IsObject()) { ASSERT_WITH_MESSAGE(!isAttribute(), "EventHandler attributes should only accept JS Functions as input."); v8::Local<v8::Value> property = listener->Get(v8AtomicString(isolate(), "handleEvent")); // Check that no exceptions were thrown when getting the // handleEvent property and that the value is a function. if (!property.IsEmpty() && property->IsFunction()) return v8::Local<v8::Function>::Cast(property); } return v8::Local<v8::Function>(); }
ScriptPromise PushRegistrationManager::hasPermissionPush(ExecutionContext* executionContext) { ScriptPromise promise = ScriptPromise::createPending(executionContext); RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promise, executionContext); if (m_pushPermission != PushPermission::Default) { DOMRequestState requestState(executionContext); v8::Isolate* isolate = requestState.isolate(); PushPermission::PermissionType permission = (permission == PushPermission::InProgress) ? PushPermission::Default : m_pushPermission; resolver->resolve(ScriptValue(v8AtomicString(isolate, PushPermission::permissionString(m_pushPermission).utf8().data()), isolate)); return promise; } m_pushController->client()->hasPermissionPush( blink::WebSecurityOrigin(executionContext->securityOrigin()), new CallbackPromiseAdapterContext<PushPermission, PushError>(resolver, executionContext)); return promise; }
bool WorkerScriptController::initializeContextIfNeeded() { v8::HandleScope handleScope(m_isolate); if (isContextInitialized()) return true; v8::Handle<v8::Context> context = v8::Context::New(m_isolate); if (context.IsEmpty()) return false; m_scriptState = ScriptState::create(context, m_world); ScriptState::Scope scope(m_scriptState.get()); // Set DebugId for the new context. context->SetEmbedderData(0, v8AtomicString(m_isolate, "worker")); // Create a new JS object and use it as the prototype for the shadow global object. const WrapperTypeInfo* contextType = &V8DedicatedWorkerGlobalScope::wrapperTypeInfo; if (m_workerGlobalScope.isServiceWorkerGlobalScope()) contextType = &V8ServiceWorkerGlobalScope::wrapperTypeInfo; else if (!m_workerGlobalScope.isDedicatedWorkerGlobalScope()) contextType = &V8SharedWorkerGlobalScope::wrapperTypeInfo; v8::Handle<v8::Function> workerGlobalScopeConstructor = m_scriptState->perContextData()->constructorForType(contextType); v8::Local<v8::Object> jsWorkerGlobalScope = V8ObjectConstructor::newInstance(m_isolate, workerGlobalScopeConstructor); if (jsWorkerGlobalScope.IsEmpty()) { m_scriptState->disposePerContextData(); return false; } V8DOMWrapper::associateObjectWithWrapper<V8WorkerGlobalScope>(PassRefPtrWillBeRawPtr<WorkerGlobalScope>(&m_workerGlobalScope), contextType, jsWorkerGlobalScope, m_isolate, WrapperConfiguration::Dependent); // Insert the object instance as the prototype of the shadow object. v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_scriptState->context()->Global()->GetPrototype()); globalObject->SetPrototype(jsWorkerGlobalScope); return true; }
void WindowProxy::setSecurityToken(SecurityOrigin* origin) { // If two tokens are equal, then the SecurityOrigins canAccess each other. // If two tokens are not equal, then we have to call canAccess. // Note: we can't use the HTTPOrigin if it was set from the DOM. String token; // There are several situations where v8 needs to do a full canAccess check, // so set an empty security token instead: // - document.domain was modified // - the frame is showing the initial empty document // - the frame is remote bool delaySet = m_world->isMainWorld() && (m_frame->isRemoteFrame() || origin->domainWasSetInDOM() || toLocalFrame(m_frame)->loader().stateMachine()->isDisplayingInitialEmptyDocument()); if (origin && !delaySet) token = origin->toString(); // An empty or "null" token means we always have to call // canAccess. The toString method on securityOrigins returns the // string "null" for empty security origins and for security // origins that should only allow access to themselves. In this // case, we use the global object as the security token to avoid // calling canAccess when a script accesses its own objects. v8::HandleScope handleScope(m_isolate); v8::Local<v8::Context> context = m_scriptState->context(); if (token.isEmpty() || token == "null") { context->UseDefaultSecurityToken(); return; } if (m_world->isPrivateScriptIsolatedWorld()) token = "private-script://" + token; CString utf8Token = token.utf8(); // NOTE: V8 does identity comparison in fast path, must use a symbol // as the security token. context->SetSecurityToken(v8AtomicString(m_isolate, utf8Token.data(), utf8Token.length())); }
short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const { v8::Isolate* isolate = state->isolate(); ASSERT(isolate->InContext()); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); ASSERT(!filter.IsEmpty()); if (!filter->IsObject()) return NodeFilter::FILTER_ACCEPT; v8::TryCatch exceptionCatcher; v8::Handle<v8::Function> callback; if (filter->IsFunction()) callback = v8::Handle<v8::Function>::Cast(filter); else { v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isolate, "acceptNode")); if (!value->IsFunction()) { throwTypeError("NodeFilter object does not have an acceptNode function", state->isolate()); return NodeFilter::FILTER_REJECT; } callback = v8::Handle<v8::Function>::Cast(value); } OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Value>[1]); info[0] = toV8(node, v8::Handle<v8::Object>(), state->isolate()); v8::Handle<v8::Object> object = isolate->GetCurrentContext()->Global(); v8::Handle<v8::Value> result = ScriptController::callFunction(state->executionContext(), callback, object, 1, info.get(), isolate); if (exceptionCatcher.HasCaught()) { state->setException(exceptionCatcher.Exception()); return NodeFilter::FILTER_REJECT; } ASSERT(!result.IsEmpty()); return result->Int32Value(); }
void WindowProxy::updateDocumentProperty() { ScriptState::Scope scope(m_scriptState.get()); v8::Handle<v8::Context> context = m_scriptState->context(); v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document(), context->Global(), context->GetIsolate()); ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmpty()); if (m_document.isEmpty()) updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper)); // If instantiation of the document wrapper fails, clear the cache // and let the LocalDOMWindow accessor handle access to the document. if (documentWrapper.IsEmpty()) { clearDocumentProperty(); return; } ASSERT(documentWrapper->IsObject()); context->Global()->ForceSet(v8AtomicString(m_isolate, "document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); // We also stash a reference to the document on the inner global object so that // LocalDOMWindow objects we obtain from JavaScript references are guaranteed to have // live Document objects. V8HiddenValue::setHiddenValue(m_isolate, toInnerGlobalObject(context), V8HiddenValue::document(m_isolate), documentWrapper); }
static void installV8TestIntegerIndexedPrimaryGlobalTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestIntegerIndexedPrimaryGlobal", V8TestIntegerIndexedPrimaryGlobal::domTemplateForNamedPropertiesObject(isolate), V8TestIntegerIndexedPrimaryGlobal::internalFieldCount, 0, 0, V8TestIntegerIndexedPrimaryGlobalAccessors, WTF_ARRAY_LENGTH(V8TestIntegerIndexedPrimaryGlobalAccessors), V8TestIntegerIndexedPrimaryGlobalMethods, WTF_ARRAY_LENGTH(V8TestIntegerIndexedPrimaryGlobalMethods)); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); if (RuntimeEnabledFeatures::iterableCollectionsEnabled()) { instanceTemplate->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate), v8::kArrayProto_values, v8::DontEnum); } v8::IndexedPropertyHandlerConfiguration indexedPropertyHandlerConfig(TestIntegerIndexedPrimaryGlobalV8Internal::indexedPropertyGetterCallback, TestIntegerIndexedPrimaryGlobalV8Internal::indexedPropertySetterCallback, 0, TestIntegerIndexedPrimaryGlobalV8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestIntegerIndexedPrimaryGlobal>, v8::Local<v8::Value>(), v8::PropertyHandlerFlags::kNone); instanceTemplate->SetHandler(indexedPropertyHandlerConfig); functionTemplate->SetHiddenPrototype(true); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
static void installV8TestInterfaceWillBeGarbageCollectedTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestInterfaceWillBeGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceWillBeGarbageCollected::internalFieldCount, V8TestInterfaceWillBeGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedAttributes), 0, 0, 0, 0); functionTemplate->SetCallHandler(V8TestInterfaceWillBeGarbageCollected::constructorCallback); functionTemplate->SetLength(1); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); const V8DOMConfiguration::MethodConfiguration funcMethodConfiguration = { "func", TestInterfaceWillBeGarbageCollectedV8Internal::funcMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts, }; V8DOMConfiguration::installMethod(isolate, instanceTemplate, defaultSignature, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly), funcMethodConfiguration); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); }
void V8WindowShell::setSecurityToken() { ASSERT(m_world->isMainWorld()); Document* document = m_frame->document(); // Ask the document's SecurityOrigin to generate a security token. // If two tokens are equal, then the SecurityOrigins canAccess each other. // If two tokens are not equal, then we have to call canAccess. // Note: we can't use the HTTPOrigin if it was set from the DOM. SecurityOrigin* origin = document->securityOrigin(); String token; // We stick with an empty token if document.domain was modified or if we // are in the initial empty document, so that we can do a full canAccess // check in those cases. if (!origin->domainWasSetInDOM() && !m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()) token = document->securityOrigin()->toString(); // An empty or "null" token means we always have to call // canAccess. The toString method on securityOrigins returns the // string "null" for empty security origins and for security // origins that should only allow access to themselves. In this // case, we use the global object as the security token to avoid // calling canAccess when a script accesses its own objects. v8::HandleScope handleScope(m_isolate); v8::Handle<v8::Context> context = m_contextHolder->context(); if (token.isEmpty() || token == "null") { context->UseDefaultSecurityToken(); return; } CString utf8Token = token.utf8(); // NOTE: V8 does identity comparison in fast path, must use a symbol // as the security token. context->SetSecurityToken(v8AtomicString(m_isolate, utf8Token.data(), utf8Token.length())); }