| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 V8PerContextData* V8PerContextData::from(v8::Local<v8::Context> context) | 76 V8PerContextData* V8PerContextData::from(v8::Local<v8::Context> context) |
| 77 { | 77 { |
| 78 return ScriptState::from(context)->perContextData(); | 78 return ScriptState::from(context)->perContextData(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) | 81 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) |
| 82 { | 82 { |
| 83 ASSERT(!m_errorPrototype.isEmpty()); | 83 ASSERT(!m_errorPrototype.isEmpty()); |
| 84 | 84 |
| 85 v8::Context::Scope scope(context()); | 85 v8::Context::Scope scope(context()); |
| 86 v8::Local<v8::Function> function = constructorForType(type); | 86 v8::Local<v8::Function> interfaceObject = constructorForType(type); |
| 87 if (function.IsEmpty()) | 87 if (interfaceObject.IsEmpty()) |
| 88 return v8::Local<v8::Object>(); | 88 return v8::Local<v8::Object>(); |
| 89 v8::Local<v8::Object> instanceTemplate; | 89 v8::Local<v8::Object> instanceTemplate; |
| 90 if (!V8ObjectConstructor::newInstance(m_isolate, function).ToLocal(&instance
Template)) | 90 if (!V8ObjectConstructor::newInstance(m_isolate, interfaceObject).ToLocal(&i
nstanceTemplate)) |
| 91 return v8::Local<v8::Object>(); | 91 return v8::Local<v8::Object>(); |
| 92 m_wrapperBoilerplates.Set(type, instanceTemplate); | 92 m_wrapperBoilerplates.Set(type, instanceTemplate); |
| 93 return instanceTemplate->Clone(); | 93 return instanceTemplate->Clone(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const Wrapp
erTypeInfo* type) | 96 v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const Wrapp
erTypeInfo* type) |
| 97 { | 97 { |
| 98 ASSERT(!m_errorPrototype.isEmpty()); | 98 ASSERT(!m_errorPrototype.isEmpty()); |
| 99 | 99 |
| 100 v8::Local<v8::Context> currentContext = context(); | 100 v8::Local<v8::Context> currentContext = context(); |
| 101 v8::Context::Scope scope(currentContext); | 101 v8::Context::Scope scope(currentContext); |
| 102 // We shouldn't reach this point for the types that are implemented in v8 su
ch as typed arrays and | 102 // We shouldn't reach this point for the types that are implemented in v8 su
ch as typed arrays and |
| 103 // hence don't have domTemplateFunction. | 103 // hence don't have domTemplateFunction. |
| 104 ASSERT(type->domTemplateFunction); | 104 ASSERT(type->domTemplateFunction); |
| 105 v8::Local<v8::FunctionTemplate> functionTemplate = type->domTemplate(m_isola
te); | 105 v8::Local<v8::FunctionTemplate> interfaceTemplate = type->domTemplate(m_isol
ate); |
| 106 // Getting the function might fail if we're running out of stack or memory. | 106 // Getting the function might fail if we're running out of stack or memory. |
| 107 v8::Local<v8::Function> function; | 107 v8::Local<v8::Function> interfaceObject; |
| 108 if (!functionTemplate->GetFunction(currentContext).ToLocal(&function)) | 108 if (!interfaceTemplate->GetFunction(currentContext).ToLocal(&interfaceObject
)) |
| 109 return v8::Local<v8::Function>(); | 109 return v8::Local<v8::Function>(); |
| 110 | 110 |
| 111 if (type->parentClass) { | 111 if (type->parentClass) { |
| 112 v8::Local<v8::Object> prototypeTemplate = constructorForType(type->paren
tClass); | 112 v8::Local<v8::Object> prototypeTemplate = constructorForType(type->paren
tClass); |
| 113 if (prototypeTemplate.IsEmpty()) | 113 if (prototypeTemplate.IsEmpty()) |
| 114 return v8::Local<v8::Function>(); | 114 return v8::Local<v8::Function>(); |
| 115 if (!v8CallBoolean(function->SetPrototype(currentContext, prototypeTempl
ate))) | 115 if (!v8CallBoolean(interfaceObject->SetPrototype(currentContext, prototy
peTemplate))) |
| 116 return v8::Local<v8::Function>(); | 116 return v8::Local<v8::Function>(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 v8::Local<v8::Object> prototypeObject = function->Get(currentContext, v8Atom
icString(m_isolate, "prototype")).ToLocalChecked().As<v8::Object>(); | 119 v8::Local<v8::Object> prototypeObject = interfaceObject->Get(currentContext,
v8AtomicString(m_isolate, "prototype")).ToLocalChecked().As<v8::Object>(); |
| 120 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount | 120 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount |
| 121 && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectProto
type) | 121 && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectProto
type) |
| 122 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex,
const_cast<WrapperTypeInfo*>(type)); | 122 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex,
const_cast<WrapperTypeInfo*>(type)); |
| 123 type->preparePrototypeObject(m_isolate, prototypeObject, functionTemplate); | 123 type->preparePrototypeAndInterfaceObject(m_isolate, prototypeObject, interfa
ceObject, interfaceTemplate); |
| 124 if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionProto
type) { | 124 if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionProto
type) { |
| 125 if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_error
Prototype.newLocal(m_isolate)))) | 125 if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_error
Prototype.newLocal(m_isolate)))) |
| 126 return v8::Local<v8::Function>(); | 126 return v8::Local<v8::Function>(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 m_constructorMap.Set(type, function); | 129 m_constructorMap.Set(type, interfaceObject); |
| 130 | 130 |
| 131 return function; | 131 return interfaceObject; |
| 132 } | 132 } |
| 133 | 133 |
| 134 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo*
type) | 134 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo*
type) |
| 135 { | 135 { |
| 136 v8::Local<v8::Object> constructor = constructorForType(type); | 136 v8::Local<v8::Object> constructor = constructorForType(type); |
| 137 if (constructor.IsEmpty()) | 137 if (constructor.IsEmpty()) |
| 138 return v8::Local<v8::Object>(); | 138 return v8::Local<v8::Object>(); |
| 139 v8::Local<v8::Value> prototypeValue; | 139 v8::Local<v8::Value> prototypeValue; |
| 140 if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(&
prototypeValue) || !prototypeValue->IsObject()) | 140 if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(&
prototypeValue) || !prototypeValue->IsObject()) |
| 141 return v8::Local<v8::Object>(); | 141 return v8::Local<v8::Object>(); |
| 142 return prototypeValue.As<v8::Object>(); | 142 return prototypeValue.As<v8::Object>(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti
on, PassOwnPtr<CustomElementBinding> binding) | 145 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti
on, PassOwnPtr<CustomElementBinding> binding) |
| 146 { | 146 { |
| 147 m_customElementBindings.append(binding); | 147 m_customElementBindings.append(binding); |
| 148 } | 148 } |
| 149 | 149 |
| 150 v8::Local<v8::Value> V8PerContextData::compiledPrivateScript(String className) | 150 v8::Local<v8::Value> V8PerContextData::compiledPrivateScript(String className) |
| 151 { | 151 { |
| 152 return m_compiledPrivateScript.Get(className); | 152 return m_compiledPrivateScript.Get(className); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void V8PerContextData::setCompiledPrivateScript(String className, v8::Local<v8::
Value> compiledObject) | 155 void V8PerContextData::setCompiledPrivateScript(String className, v8::Local<v8::
Value> compiledObject) |
| 156 { | 156 { |
| 157 m_compiledPrivateScript.Set(className, compiledObject); | 157 m_compiledPrivateScript.Set(className, compiledObject); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |