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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "bindings/core/v8/V8PerContextData.h" | 31 #include "bindings/core/v8/V8PerContextData.h" |
32 | 32 |
33 #include "bindings/core/v8/ScriptState.h" | 33 #include "bindings/core/v8/ScriptState.h" |
34 #include "bindings/core/v8/V8Binding.h" | 34 #include "bindings/core/v8/V8Binding.h" |
35 #include "bindings/core/v8/V8ObjectConstructor.h" | 35 #include "bindings/core/v8/V8ObjectConstructor.h" |
36 #include "core/inspector/InstanceCounters.h" | 36 #include "core/inspector/InstanceCounters.h" |
| 37 #include "wtf/PtrUtil.h" |
37 #include "wtf/StringExtras.h" | 38 #include "wtf/StringExtras.h" |
38 | 39 #include <memory> |
39 #include <stdlib.h> | 40 #include <stdlib.h> |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
43 V8PerContextData::V8PerContextData(v8::Local<v8::Context> context) | 44 V8PerContextData::V8PerContextData(v8::Local<v8::Context> context) |
44 : m_isolate(context->GetIsolate()) | 45 : m_isolate(context->GetIsolate()) |
45 , m_wrapperBoilerplates(m_isolate) | 46 , m_wrapperBoilerplates(m_isolate) |
46 , m_constructorMap(m_isolate) | 47 , m_constructorMap(m_isolate) |
47 , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate))) | 48 , m_contextHolder(wrapUnique(new gin::ContextHolder(m_isolate))) |
48 , m_context(m_isolate, context) | 49 , m_context(m_isolate, context) |
49 , m_activityLogger(0) | 50 , m_activityLogger(0) |
50 , m_compiledPrivateScript(m_isolate) | 51 , m_compiledPrivateScript(m_isolate) |
51 { | 52 { |
52 m_contextHolder->SetContext(context); | 53 m_contextHolder->SetContext(context); |
53 | 54 |
54 v8::Context::Scope contextScope(context); | 55 v8::Context::Scope contextScope(context); |
55 ASSERT(m_errorPrototype.isEmpty()); | 56 ASSERT(m_errorPrototype.isEmpty()); |
56 v8::Local<v8::Value> objectValue = context->Global()->Get(context, v8AtomicS
tring(m_isolate, "Error")).ToLocalChecked(); | 57 v8::Local<v8::Value> objectValue = context->Global()->Get(context, v8AtomicS
tring(m_isolate, "Error")).ToLocalChecked(); |
57 v8::Local<v8::Value> prototypeValue = objectValue.As<v8::Object>()->Get(cont
ext, v8AtomicString(m_isolate, "prototype")).ToLocalChecked(); | 58 v8::Local<v8::Value> prototypeValue = objectValue.As<v8::Object>()->Get(cont
ext, v8AtomicString(m_isolate, "prototype")).ToLocalChecked(); |
58 m_errorPrototype.set(m_isolate, prototypeValue); | 59 m_errorPrototype.set(m_isolate, prototypeValue); |
59 | 60 |
60 if (isMainThread()) | 61 if (isMainThread()) |
61 InstanceCounters::incrementCounter(InstanceCounters::V8PerContextDataCou
nter); | 62 InstanceCounters::incrementCounter(InstanceCounters::V8PerContextDataCou
nter); |
62 } | 63 } |
63 | 64 |
64 V8PerContextData::~V8PerContextData() | 65 V8PerContextData::~V8PerContextData() |
65 { | 66 { |
66 if (isMainThread()) | 67 if (isMainThread()) |
67 InstanceCounters::decrementCounter(InstanceCounters::V8PerContextDataCou
nter); | 68 InstanceCounters::decrementCounter(InstanceCounters::V8PerContextDataCou
nter); |
68 } | 69 } |
69 | 70 |
70 PassOwnPtr<V8PerContextData> V8PerContextData::create(v8::Local<v8::Context> con
text) | 71 std::unique_ptr<V8PerContextData> V8PerContextData::create(v8::Local<v8::Context
> context) |
71 { | 72 { |
72 return adoptPtr(new V8PerContextData(context)); | 73 return wrapUnique(new V8PerContextData(context)); |
73 } | 74 } |
74 | 75 |
75 V8PerContextData* V8PerContextData::from(v8::Local<v8::Context> context) | 76 V8PerContextData* V8PerContextData::from(v8::Local<v8::Context> context) |
76 { | 77 { |
77 return ScriptState::from(context)->perContextData(); | 78 return ScriptState::from(context)->perContextData(); |
78 } | 79 } |
79 | 80 |
80 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) | 81 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) |
81 { | 82 { |
82 ASSERT(!m_errorPrototype.isEmpty()); | 83 ASSERT(!m_errorPrototype.isEmpty()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 { | 139 { |
139 v8::Local<v8::Object> constructor = constructorForType(type); | 140 v8::Local<v8::Object> constructor = constructorForType(type); |
140 if (constructor.IsEmpty()) | 141 if (constructor.IsEmpty()) |
141 return v8::Local<v8::Object>(); | 142 return v8::Local<v8::Object>(); |
142 v8::Local<v8::Value> prototypeValue; | 143 v8::Local<v8::Value> prototypeValue; |
143 if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(&
prototypeValue) || !prototypeValue->IsObject()) | 144 if (!constructor->Get(context(), v8String(m_isolate, "prototype")).ToLocal(&
prototypeValue) || !prototypeValue->IsObject()) |
144 return v8::Local<v8::Object>(); | 145 return v8::Local<v8::Object>(); |
145 return prototypeValue.As<v8::Object>(); | 146 return prototypeValue.As<v8::Object>(); |
146 } | 147 } |
147 | 148 |
148 void V8PerContextData::addCustomElementBinding(PassOwnPtr<V0CustomElementBinding
> binding) | 149 void V8PerContextData::addCustomElementBinding(std::unique_ptr<V0CustomElementBi
nding> binding) |
149 { | 150 { |
150 m_customElementBindings.append(std::move(binding)); | 151 m_customElementBindings.append(std::move(binding)); |
151 } | 152 } |
152 | 153 |
153 v8::Local<v8::Value> V8PerContextData::compiledPrivateScript(String className) | 154 v8::Local<v8::Value> V8PerContextData::compiledPrivateScript(String className) |
154 { | 155 { |
155 return m_compiledPrivateScript.Get(className); | 156 return m_compiledPrivateScript.Get(className); |
156 } | 157 } |
157 | 158 |
158 void V8PerContextData::setCompiledPrivateScript(String className, v8::Local<v8::
Value> compiledObject) | 159 void V8PerContextData::setCompiledPrivateScript(String className, v8::Local<v8::
Value> compiledObject) |
159 { | 160 { |
160 m_compiledPrivateScript.Set(className, compiledObject); | 161 m_compiledPrivateScript.Set(className, compiledObject); |
161 } | 162 } |
162 | 163 |
163 } // namespace blink | 164 } // namespace blink |
OLD | NEW |