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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 "platform/bindings/V8PerContextData.h" |
32 | 32 |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 #include <memory> | 34 #include <memory> |
35 #include "bindings/core/v8/ConditionalFeatures.h" | |
36 #include "bindings/core/v8/ScriptState.h" | |
37 #include "bindings/core/v8/V8Binding.h" | |
38 #include "bindings/core/v8/V8ObjectConstructor.h" | |
39 #include "platform/InstanceCounters.h" | 35 #include "platform/InstanceCounters.h" |
| 36 #include "platform/bindings/ConditionalFeatures.h" |
| 37 #include "platform/bindings/ScriptState.h" |
| 38 #include "platform/bindings/V8Binding.h" |
| 39 #include "platform/bindings/V8ObjectConstructor.h" |
40 #include "platform/wtf/PtrUtil.h" | 40 #include "platform/wtf/PtrUtil.h" |
41 #include "platform/wtf/StringExtras.h" | 41 #include "platform/wtf/StringExtras.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 V8PerContextData::V8PerContextData(v8::Local<v8::Context> context) | 45 V8PerContextData::V8PerContextData(v8::Local<v8::Context> context) |
46 : isolate_(context->GetIsolate()), | 46 : isolate_(context->GetIsolate()), |
47 wrapper_boilerplates_(isolate_), | 47 wrapper_boilerplates_(isolate_), |
48 constructor_map_(isolate_), | 48 constructor_map_(isolate_), |
49 context_holder_(WTF::MakeUnique<gin::ContextHolder>(isolate_)), | 49 context_holder_(WTF::MakeUnique<gin::ContextHolder>(isolate_)), |
50 context_(isolate_, context), | 50 context_(isolate_, context), |
51 activity_logger_(nullptr) { | 51 activity_logger_(nullptr) { |
52 context_holder_->SetContext(context); | 52 context_holder_->SetContext(context); |
53 | 53 |
54 v8::Context::Scope context_scope(context); | 54 v8::Context::Scope context_scope(context); |
55 DCHECK(error_prototype_.IsEmpty()); | 55 DCHECK(error_prototype_.IsEmpty()); |
56 v8::Local<v8::Value> object_value = | 56 v8::Local<v8::Value> object_value = |
57 context->Global() | 57 context->Global() |
58 ->Get(context, V8AtomicString(isolate_, "Error")) | 58 ->Get(context, V8AtomicString(isolate_, "Error")) |
59 .ToLocalChecked(); | 59 .ToLocalChecked(); |
60 v8::Local<v8::Value> prototype_value = | 60 v8::Local<v8::Value> prototype_value = |
61 object_value.As<v8::Object>() | 61 object_value.As<v8::Object>() |
62 ->Get(context, V8AtomicString(isolate_, "prototype")) | 62 ->Get(context, V8AtomicString(isolate_, "prototype")) |
63 .ToLocalChecked(); | 63 .ToLocalChecked(); |
64 error_prototype_.Set(isolate_, prototype_value); | 64 error_prototype_.Set(isolate_, prototype_value); |
65 | 65 |
66 if (IsMainThread()) | 66 if (IsMainThread()) { |
67 InstanceCounters::IncrementCounter( | 67 InstanceCounters::IncrementCounter( |
68 InstanceCounters::kV8PerContextDataCounter); | 68 InstanceCounters::kV8PerContextDataCounter); |
| 69 } |
69 } | 70 } |
70 | 71 |
71 V8PerContextData::~V8PerContextData() { | 72 V8PerContextData::~V8PerContextData() { |
72 if (IsMainThread()) | 73 if (IsMainThread()) { |
73 InstanceCounters::DecrementCounter( | 74 InstanceCounters::DecrementCounter( |
74 InstanceCounters::kV8PerContextDataCounter); | 75 InstanceCounters::kV8PerContextDataCounter); |
| 76 } |
75 } | 77 } |
76 | 78 |
77 std::unique_ptr<V8PerContextData> V8PerContextData::Create( | 79 std::unique_ptr<V8PerContextData> V8PerContextData::Create( |
78 v8::Local<v8::Context> context) { | 80 v8::Local<v8::Context> context) { |
79 return WTF::WrapUnique(new V8PerContextData(context)); | 81 return WTF::WrapUnique(new V8PerContextData(context)); |
80 } | 82 } |
81 | 83 |
82 V8PerContextData* V8PerContextData::From(v8::Local<v8::Context> context) { | 84 V8PerContextData* V8PerContextData::From(v8::Local<v8::Context> context) { |
83 return ScriptState::From(context)->PerContextData(); | 85 return ScriptState::From(context)->PerContextData(); |
84 } | 86 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 v8::Local<v8::Value> prototype_value; | 132 v8::Local<v8::Value> prototype_value; |
131 if (!interface_object | 133 if (!interface_object |
132 ->Get(current_context, V8AtomicString(isolate_, "prototype")) | 134 ->Get(current_context, V8AtomicString(isolate_, "prototype")) |
133 .ToLocal(&prototype_value) || | 135 .ToLocal(&prototype_value) || |
134 !prototype_value->IsObject()) | 136 !prototype_value->IsObject()) |
135 return v8::Local<v8::Function>(); | 137 return v8::Local<v8::Function>(); |
136 v8::Local<v8::Object> prototype_object = prototype_value.As<v8::Object>(); | 138 v8::Local<v8::Object> prototype_object = prototype_value.As<v8::Object>(); |
137 if (prototype_object->InternalFieldCount() == | 139 if (prototype_object->InternalFieldCount() == |
138 kV8PrototypeInternalFieldcount && | 140 kV8PrototypeInternalFieldcount && |
139 type->wrapper_type_prototype == | 141 type->wrapper_type_prototype == |
140 WrapperTypeInfo::kWrapperTypeObjectPrototype) | 142 WrapperTypeInfo::kWrapperTypeObjectPrototype) { |
141 prototype_object->SetAlignedPointerInInternalField( | 143 prototype_object->SetAlignedPointerInInternalField( |
142 kV8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type)); | 144 kV8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type)); |
| 145 } |
143 type->PreparePrototypeAndInterfaceObject(current_context, world, | 146 type->PreparePrototypeAndInterfaceObject(current_context, world, |
144 prototype_object, interface_object, | 147 prototype_object, interface_object, |
145 interface_template); | 148 interface_template); |
146 if (type->wrapper_type_prototype == | 149 if (type->wrapper_type_prototype == |
147 WrapperTypeInfo::kWrapperTypeExceptionPrototype) { | 150 WrapperTypeInfo::kWrapperTypeExceptionPrototype) { |
148 if (!V8CallBoolean(prototype_object->SetPrototype( | 151 if (!V8CallBoolean(prototype_object->SetPrototype( |
149 current_context, error_prototype_.NewLocal(isolate_)))) | 152 current_context, error_prototype_.NewLocal(isolate_)))) { |
150 return v8::Local<v8::Function>(); | 153 return v8::Local<v8::Function>(); |
| 154 } |
151 } | 155 } |
152 | 156 |
153 // Origin Trials | 157 // Origin Trials |
154 InstallConditionalFeatures(type, ScriptState::From(current_context), | 158 InstallConditionalFeatures(type, ScriptState::From(current_context), |
155 prototype_object, interface_object); | 159 prototype_object, interface_object); |
156 | 160 |
157 constructor_map_.Set(type, interface_object); | 161 constructor_map_.Set(type, interface_object); |
158 | 162 |
159 return interface_object; | 163 return interface_object; |
160 } | 164 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 201 |
198 void V8PerContextData::ClearData(const char* key) { | 202 void V8PerContextData::ClearData(const char* key) { |
199 data_map_.erase(key); | 203 data_map_.erase(key); |
200 } | 204 } |
201 | 205 |
202 V8PerContextData::Data* V8PerContextData::GetData(const char* key) { | 206 V8PerContextData::Data* V8PerContextData::GetData(const char* key) { |
203 return data_map_.at(key); | 207 return data_map_.at(key); |
204 } | 208 } |
205 | 209 |
206 } // namespace blink | 210 } // namespace blink |
OLD | NEW |