| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptState.h" | 34 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/V8Binding.h" | 35 #include "bindings/core/v8/V8Binding.h" |
| 36 #include "bindings/core/v8/V8ObjectConstructor.h" | 36 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 37 #include "wtf/StringExtras.h" | 37 #include "wtf/StringExtras.h" |
| 38 | 38 |
| 39 #include <stdlib.h> | 39 #include <stdlib.h> |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context) | 43 V8PerContextData::V8PerContextData(v8::Local<v8::Context> context) |
| 44 : m_isolate(context->GetIsolate()) | 44 : m_isolate(context->GetIsolate()) |
| 45 , m_wrapperBoilerplates(m_isolate) | 45 , m_wrapperBoilerplates(m_isolate) |
| 46 , m_constructorMap(m_isolate) | 46 , m_constructorMap(m_isolate) |
| 47 , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate))) | 47 , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate))) |
| 48 , m_context(m_isolate, context) | 48 , m_context(m_isolate, context) |
| 49 , m_activityLogger(0) | 49 , m_activityLogger(0) |
| 50 , m_compiledPrivateScript(m_isolate) | 50 , m_compiledPrivateScript(m_isolate) |
| 51 { | 51 { |
| 52 m_contextHolder->SetContext(context); | 52 m_contextHolder->SetContext(context); |
| 53 | 53 |
| 54 v8::Context::Scope contextScope(context); | 54 v8::Context::Scope contextScope(context); |
| 55 ASSERT(m_errorPrototype.isEmpty()); | 55 ASSERT(m_errorPrototype.isEmpty()); |
| 56 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global
()->Get(v8AtomicString(m_isolate, "Error"))); | 56 v8::Local<v8::Value> objectValue = context->Global()->Get(context, v8AtomicS
tring(m_isolate, "Error")).ToLocalChecked(); |
| 57 ASSERT(!object.IsEmpty()); | 57 v8::Local<v8::Value> prototypeValue = objectValue.As<v8::Object>()->Get(cont
ext, v8AtomicString(m_isolate, "prototype")).ToLocalChecked(); |
| 58 v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate,
"prototype")); | |
| 59 ASSERT(!prototypeValue.IsEmpty()); | |
| 60 m_errorPrototype.set(m_isolate, prototypeValue); | 58 m_errorPrototype.set(m_isolate, prototypeValue); |
| 61 } | 59 } |
| 62 | 60 |
| 63 V8PerContextData::~V8PerContextData() | 61 V8PerContextData::~V8PerContextData() |
| 64 { | 62 { |
| 65 } | 63 } |
| 66 | 64 |
| 67 PassOwnPtr<V8PerContextData> V8PerContextData::create(v8::Handle<v8::Context> co
ntext) | 65 PassOwnPtr<V8PerContextData> V8PerContextData::create(v8::Local<v8::Context> con
text) |
| 68 { | 66 { |
| 69 return adoptPtr(new V8PerContextData(context)); | 67 return adoptPtr(new V8PerContextData(context)); |
| 70 } | 68 } |
| 71 | 69 |
| 72 V8PerContextData* V8PerContextData::from(v8::Handle<v8::Context> context) | 70 V8PerContextData* V8PerContextData::from(v8::Local<v8::Context> context) |
| 73 { | 71 { |
| 74 return ScriptState::from(context)->perContextData(); | 72 return ScriptState::from(context)->perContextData(); |
| 75 } | 73 } |
| 76 | 74 |
| 77 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) | 75 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) |
| 78 { | 76 { |
| 79 ASSERT(!m_errorPrototype.isEmpty()); | 77 ASSERT(!m_errorPrototype.isEmpty()); |
| 80 | 78 |
| 81 v8::Context::Scope scope(context()); | 79 v8::Context::Scope scope(context()); |
| 82 v8::Local<v8::Function> function = constructorForType(type); | 80 v8::Local<v8::Function> function = constructorForType(type); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 104 return v8::Local<v8::Function>(); | 102 return v8::Local<v8::Function>(); |
| 105 | 103 |
| 106 if (type->parentClass) { | 104 if (type->parentClass) { |
| 107 v8::Local<v8::Object> prototypeTemplate = constructorForType(type->paren
tClass); | 105 v8::Local<v8::Object> prototypeTemplate = constructorForType(type->paren
tClass); |
| 108 if (prototypeTemplate.IsEmpty()) | 106 if (prototypeTemplate.IsEmpty()) |
| 109 return v8::Local<v8::Function>(); | 107 return v8::Local<v8::Function>(); |
| 110 if (!v8CallBoolean(function->SetPrototype(currentContext, prototypeTempl
ate))) | 108 if (!v8CallBoolean(function->SetPrototype(currentContext, prototypeTempl
ate))) |
| 111 return v8::Local<v8::Function>(); | 109 return v8::Local<v8::Function>(); |
| 112 } | 110 } |
| 113 | 111 |
| 114 v8::Local<v8::Value> prototypeValue = function->Get(v8AtomicString(m_isolate
, "prototype")); | 112 v8::Local<v8::Object> prototypeObject = function->Get(currentContext, v8Atom
icString(m_isolate, "prototype")).ToLocalChecked().As<v8::Object>(); |
| 115 if (!prototypeValue.IsEmpty() && prototypeValue->IsObject()) { | 113 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount |
| 116 v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(prot
otypeValue); | 114 && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectProto
type) |
| 117 if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcou
nt | 115 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex,
const_cast<WrapperTypeInfo*>(type)); |
| 118 && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectP
rototype) | 116 type->installConditionallyEnabledMethods(prototypeObject, m_isolate); |
| 119 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd
ex, const_cast<WrapperTypeInfo*>(type)); | 117 if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionProto
type) { |
| 120 type->installConditionallyEnabledMethods(prototypeObject, m_isolate); | 118 if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_error
Prototype.newLocal(m_isolate)))) |
| 121 if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionP
rototype) { | 119 return v8::Local<v8::Function>(); |
| 122 if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_e
rrorPrototype.newLocal(m_isolate)))) | |
| 123 return v8::Local<v8::Function>(); | |
| 124 } | |
| 125 } | 120 } |
| 126 | 121 |
| 127 m_constructorMap.Set(type, function); | 122 m_constructorMap.Set(type, function); |
| 128 | 123 |
| 129 return function; | 124 return function; |
| 130 } | 125 } |
| 131 | 126 |
| 132 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo*
type) | 127 v8::Local<v8::Object> V8PerContextData::prototypeForType(const WrapperTypeInfo*
type) |
| 133 { | 128 { |
| 134 v8::Local<v8::Object> constructor = constructorForType(type); | 129 v8::Local<v8::Object> constructor = constructorForType(type); |
| 135 if (constructor.IsEmpty()) | 130 if (constructor.IsEmpty()) |
| 136 return v8::Local<v8::Object>(); | 131 return v8::Local<v8::Object>(); |
| 137 return constructor->Get(v8String(m_isolate, "prototype")).As<v8::Object>(); | 132 v8::Local<v8::Value> prototypeValue; |
| 133 if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(&
prototypeValue) || !prototypeValue->IsObject()) |
| 134 return v8::Local<v8::Object>(); |
| 135 return prototypeValue.As<v8::Object>(); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti
on, PassOwnPtr<CustomElementBinding> binding) | 138 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definiti
on, PassOwnPtr<CustomElementBinding> binding) |
| 141 { | 139 { |
| 142 m_customElementBindings.append(binding); | 140 m_customElementBindings.append(binding); |
| 143 } | 141 } |
| 144 | 142 |
| 145 v8::Handle<v8::Value> V8PerContextData::compiledPrivateScript(String className) | 143 v8::Handle<v8::Value> V8PerContextData::compiledPrivateScript(String className) |
| 146 { | 144 { |
| 147 return m_compiledPrivateScript.Get(className); | 145 return m_compiledPrivateScript.Get(className); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void V8PerContextData::setCompiledPrivateScript(String className, v8::Handle<v8:
:Value> compiledObject) | 148 void V8PerContextData::setCompiledPrivateScript(String className, v8::Handle<v8:
:Value> compiledObject) |
| 151 { | 149 { |
| 152 m_compiledPrivateScript.Set(className, compiledObject); | 150 m_compiledPrivateScript.Set(className, compiledObject); |
| 153 } | 151 } |
| 154 | 152 |
| 155 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |