v8::Handle<v8::Object> CustomElementWrapper<ElementType, WrapperType>::wrap(PassRefPtrWillBeRawPtr<ElementType> element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationContext, v8::Isolate*)) { ASSERT(DOMDataStore::getWrapper<V8Element>(element.get(), isolate).IsEmpty()); // FIXME: creationContext.IsEmpty() should never happen. Remove // this when callers (like InspectorController::inspect) are fixed // to never pass an empty creation context. v8::Handle<v8::Context> context = creationContext.IsEmpty() ? isolate->GetCurrentContext() : creationContext->CreationContext(); if (!element->isUpgradedCustomElement() || DOMWrapperWorld::world(context).isIsolatedWorld()) return createUpgradeCandidateWrapper(element.get(), creationContext, isolate, createSpecificWrapper); V8PerContextData* perContextData = V8PerContextData::from(context); if (!perContextData) return v8::Handle<v8::Object>(); CustomElementBinding* binding = perContextData->customElementBinding(element->customElementDefinition()); v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, binding->wrapperType(), element.get(), isolate); if (wrapper.IsEmpty()) return v8::Handle<v8::Object>(); wrapper->SetPrototype(binding->prototype()); V8DOMWrapper::associateObjectWithWrapper<WrapperType>(element, binding->wrapperType(), wrapper, isolate, WrapperConfiguration::Dependent); return wrapper; }
v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Isolate* isolate, v8::Local<v8::Object> creationContext, const WrapperTypeInfo* type, ScriptWrappable* scriptWrappable) { ASSERT(!type->equals(&V8Window::wrapperTypeInfo)); // According to https://html.spec.whatwg.org/multipage/browsers.html#security-location, // cross-origin script access to a few properties of Location is allowed. // Location already implements the necessary security checks. bool withSecurityCheck = !type->equals(&V8Location::wrapperTypeInfo); V8WrapperInstantiationScope scope(creationContext, isolate, withSecurityCheck); V8PerContextData* perContextData = V8PerContextData::from(scope.context()); v8::Local<v8::Object> wrapper; if (perContextData) { wrapper = perContextData->createWrapperFromCache(type); } else { v8::Local<v8::Function> function; if (!type->domTemplate(isolate)->GetFunction(isolate->GetCurrentContext()).ToLocal(&function)) return v8::Local<v8::Object>(); if (!V8ObjectConstructor::newInstance(isolate, function).ToLocal(&wrapper)) return v8::Local<v8::Object>(); } if (type == &V8HTMLDocument::wrapperTypeInfo && !wrapper.IsEmpty()) wrapper = wrapInShadowTemplate(wrapper, scriptWrappable, isolate); return wrapper; }
v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(Document* deprecatedDocument, WrapperTypeInfo* type, void* impl) { V8PerContextData* perContextData = 0; // Please don't add any more uses of deprecatedDocument. We want to remove it. // If we have a pointer to the frame, we cna get the V8PerContextData // directly, which is faster than going through V8. if (deprecatedDocument && deprecatedDocument->frame()) perContextData = perContextDataForCurrentWorld(deprecatedDocument->frame()); else perContextData = V8PerContextData::from(v8::Context::GetCurrent()); v8::Local<v8::Object> instance = perContextData ? perContextData->createWrapperFromCache(type) : V8ObjectConstructor::newInstance(type->getTemplate()->GetFunction()); // Avoid setting the DOM wrapper for failed allocations. if (instance.IsEmpty()) return instance; setDOMWrapper(instance, type, impl); if (type == &V8HTMLDocument::info) instance = V8HTMLDocument::wrapInShadowObject(instance, static_cast<Node*>(impl)); return instance; }
static void TestInterfaceNamedConstructorConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) { v8::Handle<v8::Value> data = info.Data(); ASSERT(data->IsExternal()); V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext()); if (!perContextData) return; v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data))); }
v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Handle<v8::Object> creationContext, WrapperTypeInfo* type, void* impl, v8::Isolate* isolate) { V8WrapperInstantiationScope scope(creationContext); V8PerContextData* perContextData = V8PerContextData::from(scope.context()); v8::Local<v8::Object> wrapper = perContextData ? perContextData->createWrapperFromCache(type) : V8ObjectConstructor::newInstance(type->getTemplate(isolate, worldTypeInMainThread(isolate))->GetFunction()); if (type == &V8HTMLDocument::info && !wrapper.IsEmpty()) wrapper = wrapInShadowTemplate(wrapper, static_cast<Node*>(impl), isolate); return wrapper; }
V8DOMActivityLogger* V8DOMActivityLogger::currentActivityLogger() { v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (!isolate->InContext()) return 0; V8PerContextData* contextData = ScriptState::current(isolate)->perContextData(); if (!contextData) return 0; return contextData->activityLogger(); }
bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owner, PassOwnPtr<CustomElementBinding> binding) { V8PerContextData* perContextData = creationContextData(); if (!perContextData) return false; // The context is responsible for keeping the prototype // alive. This in turn keeps callbacks alive through hidden // references; see CALLBACK_LIST(SET_HIDDEN_VALUE). perContextData->addCustomElementBinding(owner, binding); return true; }
v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(v8::Handle<v8::Object> creationContext, WrapperTypeInfo* type, void* impl) { V8WrapperInstantiationScope scope(creationContext); V8PerContextData* perContextData = V8PerContextData::from(scope.context()); v8::Local<v8::Object> instance = perContextData ? perContextData->createWrapperFromCache(type) : V8ObjectConstructor::newInstance(type->getTemplate()->GetFunction()); // Avoid setting the DOM wrapper for failed allocations. if (instance.IsEmpty()) return instance; if (type == &V8HTMLDocument::info) instance = V8HTMLDocument::wrapInShadowObject(instance, static_cast<Node*>(impl)); return instance; }
bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owner, PassOwnPtr<CustomElementBinding> binding) { ASSERT(!m_owner); V8PerContextData* perContextData = creationContextData(); if (!perContextData) return false; m_owner = owner; // Bindings retrieve the prototype when needed from per-context data. perContextData->addCustomElementBinding(owner, binding); return true; }
V8DOMActivityLogger* V8DOMActivityLogger::currentActivityLogger() { v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (!isolate->InContext()) return 0; v8::HandleScope handleScope(isolate); v8::Local<v8::Context> context = isolate->GetCurrentContext(); if (context.IsEmpty() || !toDOMWindow(context)) return 0; V8PerContextData* contextData = ScriptState::from(context)->perContextData(); if (!contextData) return 0; return contextData->activityLogger(); }
v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Isolate* isolate, v8::Local<v8::Object> creationContext, const WrapperTypeInfo* type, ScriptWrappable* scriptWrappable) { V8WrapperInstantiationScope scope(creationContext, isolate); V8PerContextData* perContextData = V8PerContextData::from(scope.context()); v8::Local<v8::Object> wrapper; if (perContextData) { wrapper = perContextData->createWrapperFromCache(type); } else { v8::Local<v8::Function> function; if (!type->domTemplate(isolate)->GetFunction(isolate->GetCurrentContext()).ToLocal(&function)) return v8::Local<v8::Object>(); if (!V8ObjectConstructor::newInstance(isolate, function).ToLocal(&wrapper)) return v8::Local<v8::Object>(); } if (type == &V8HTMLDocument::wrapperTypeInfo && !wrapper.IsEmpty()) wrapper = wrapInShadowTemplate(wrapper, scriptWrappable, isolate); return wrapper; }