v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo* type) { v8::Local<v8::Object> constructor = constructorForType(type); if (constructor.IsEmpty()) return v8::Local<v8::Object>(); return constructor->Get(v8String(m_isolate, "prototype")).As<v8::Object>(); }
v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const WrapperTypeInfo* type) { ASSERT(!m_errorPrototype.isEmpty()); v8::Context::Scope scope(m_context.newLocal(m_isolate)); v8::Handle<v8::FunctionTemplate> functionTemplate = type->domTemplate(m_isolate, worldType(m_isolate)); // Getting the function might fail if we're running out of stack or memory. v8::TryCatch tryCatch; v8::Local<v8::Function> function = functionTemplate->GetFunction(); if (function.IsEmpty()) return v8::Local<v8::Function>(); if (type->parentClass) { v8::Local<v8::Object> prototypeTemplate = constructorForType(type->parentClass); if (prototypeTemplate.IsEmpty()) return v8::Local<v8::Function>(); function->SetPrototype(prototypeTemplate); } v8::Local<v8::Value> prototypeValue = function->Get(v8AtomicString(m_isolate, "prototype")); if (!prototypeValue.IsEmpty() && prototypeValue->IsObject()) { v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(prototypeValue); if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount && type->wrapperTypePrototype == WrapperTypeObjectPrototype) prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type)); type->installPerContextEnabledMethods(prototypeObject, m_isolate); if (type->wrapperTypePrototype == WrapperTypeExceptionPrototype) prototypeObject->SetPrototype(m_errorPrototype.newLocal(m_isolate)); } m_constructorMap.set(type, UnsafePersistent<v8::Function>(m_isolate, function)); return function; }
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>(); } // Origin Trials installConditionalFeatures(type, ScriptState::from(currentContext), prototypeObject, interfaceObject); m_constructorMap.Set(type, interfaceObject); return interfaceObject; }
v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo* type) { v8::Local<v8::Object> constructor = constructorForType(type); if (constructor.IsEmpty()) return v8::Local<v8::Object>(); v8::Local<v8::Value> prototypeValue; if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(&prototypeValue) || !prototypeValue->IsObject()) return v8::Local<v8::Object>(); return prototypeValue.As<v8::Object>(); }
v8::Local<v8::Object> V8BindingPerContextData::createWrapperFromCacheSlowCase(WrapperTypeInfo* type) { ASSERT(!m_objectPrototype.get().IsEmpty()); v8::Context::Scope scope(m_context); v8::Local<v8::Function> function = constructorForType(type); v8::Local<v8::Object> instance = SafeAllocation::newInstance(function); if (!instance.IsEmpty()) { m_wrapperBoilerplates.set(type, v8::Persistent<v8::Object>::New(instance)); return instance->Clone(); } return v8::Local<v8::Object>(); }
v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const WrapperTypeInfo* type) { ASSERT(!m_errorPrototype.isEmpty()); v8::Context::Scope scope(m_context.newLocal(m_isolate)); v8::Local<v8::Function> function = constructorForType(type); v8::Local<v8::Object> instanceTemplate = V8ObjectConstructor::newInstance(function); if (!instanceTemplate.IsEmpty()) { m_wrapperBoilerplates.set(type, UnsafePersistent<v8::Object>(m_isolate, instanceTemplate)); return instanceTemplate->Clone(); } return v8::Local<v8::Object>(); }
v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const WrapperTypeInfo* type) { ASSERT(!m_errorPrototype.isEmpty()); v8::Context::Scope scope(context()); v8::Local<v8::Function> interfaceObject = constructorForType(type); if (interfaceObject.IsEmpty()) return v8::Local<v8::Object>(); v8::Local<v8::Object> instanceTemplate; if (!V8ObjectConstructor::newInstance(m_isolate, interfaceObject).ToLocal(&instanceTemplate)) return v8::Local<v8::Object>(); m_wrapperBoilerplates.Set(type, instanceTemplate); return instanceTemplate->Clone(); }
v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const WrapperTypeInfo* type) { ASSERT(!m_errorPrototype.isEmpty()); v8::Local<v8::Context> currentContext = context(); v8::Context::Scope scope(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> functionTemplate = type->domTemplate(m_isolate); // Getting the function might fail if we're running out of stack or memory. v8::Local<v8::Function> function; if (!functionTemplate->GetFunction(currentContext).ToLocal(&function)) 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(function->SetPrototype(currentContext, prototypeTemplate))) return v8::Local<v8::Function>(); } v8::Local<v8::Object> prototypeObject = function->Get(currentContext, v8AtomicString(m_isolate, "prototype")).ToLocalChecked().As<v8::Object>(); if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectPrototype) prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type)); type->preparePrototypeObject(m_isolate, prototypeObject, functionTemplate); if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionPrototype) { if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_errorPrototype.newLocal(m_isolate)))) return v8::Local<v8::Function>(); } m_constructorMap.Set(type, function); return function; }