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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "bindings/core/v8/V8DOMConfiguration.h" | 29 #include "bindings/core/v8/V8DOMConfiguration.h" |
30 | 30 |
31 #include "bindings/core/v8/V8ObjectConstructor.h" | 31 #include "bindings/core/v8/V8ObjectConstructor.h" |
32 #include "bindings/core/v8/V8PerContextData.h" | 32 #include "bindings/core/v8/V8PerContextData.h" |
33 #include "platform/instrumentation/tracing/TraceEvent.h" | 33 #include "platform/instrumentation/tracing/TraceEvent.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
| 39 template <class Configuration> |
| 40 bool worldConfigurationApplies(const Configuration& config, |
| 41 const DOMWrapperWorld& world) { |
| 42 const auto currentWorldConfig = world.isMainWorld() |
| 43 ? V8DOMConfiguration::MainWorld |
| 44 : V8DOMConfiguration::NonMainWorlds; |
| 45 return config.worldConfiguration & currentWorldConfig; |
| 46 } |
| 47 |
| 48 template <> |
| 49 bool worldConfigurationApplies( |
| 50 const V8DOMConfiguration::SymbolKeyedMethodConfiguration&, |
| 51 const DOMWrapperWorld&) { |
| 52 return true; |
| 53 } |
| 54 |
39 void installAttributeInternal( | 55 void installAttributeInternal( |
40 v8::Isolate* isolate, | 56 v8::Isolate* isolate, |
41 v8::Local<v8::ObjectTemplate> instanceTemplate, | 57 v8::Local<v8::ObjectTemplate> instanceTemplate, |
42 v8::Local<v8::ObjectTemplate> prototypeTemplate, | 58 v8::Local<v8::ObjectTemplate> prototypeTemplate, |
43 const V8DOMConfiguration::AttributeConfiguration& attribute, | 59 const V8DOMConfiguration::AttributeConfiguration& attribute, |
44 const DOMWrapperWorld& world) { | 60 const DOMWrapperWorld& world) { |
| 61 if (!worldConfigurationApplies(attribute, world)) |
| 62 return; |
| 63 |
45 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); | 64 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); |
46 v8::AccessorNameGetterCallback getter = attribute.getter; | 65 v8::AccessorNameGetterCallback getter = attribute.getter; |
47 v8::AccessorNameSetterCallback setter = attribute.setter; | 66 v8::AccessorNameSetterCallback setter = attribute.setter; |
48 if (world.isMainWorld()) { | |
49 if (attribute.getterForMainWorld) | |
50 getter = attribute.getterForMainWorld; | |
51 if (attribute.setterForMainWorld) | |
52 setter = attribute.setterForMainWorld; | |
53 } | |
54 v8::Local<v8::Value> data = | 67 v8::Local<v8::Value> data = |
55 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)); | 68 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)); |
56 | 69 |
57 DCHECK(attribute.propertyLocationConfiguration); | 70 DCHECK(attribute.propertyLocationConfiguration); |
58 if (attribute.propertyLocationConfiguration & | 71 if (attribute.propertyLocationConfiguration & |
59 V8DOMConfiguration::OnInstance) { | 72 V8DOMConfiguration::OnInstance) { |
60 instanceTemplate->SetNativeDataProperty( | 73 instanceTemplate->SetNativeDataProperty( |
61 name, getter, setter, data, | 74 name, getter, setter, data, |
62 static_cast<v8::PropertyAttribute>(attribute.attribute), | 75 static_cast<v8::PropertyAttribute>(attribute.attribute), |
63 v8::Local<v8::AccessorSignature>(), v8::DEFAULT); | 76 v8::Local<v8::AccessorSignature>(), v8::DEFAULT); |
64 } | 77 } |
65 if (attribute.propertyLocationConfiguration & | 78 if (attribute.propertyLocationConfiguration & |
66 V8DOMConfiguration::OnPrototype) { | 79 V8DOMConfiguration::OnPrototype) { |
67 prototypeTemplate->SetNativeDataProperty( | 80 prototypeTemplate->SetNativeDataProperty( |
68 name, getter, setter, data, | 81 name, getter, setter, data, |
69 static_cast<v8::PropertyAttribute>(attribute.attribute), | 82 static_cast<v8::PropertyAttribute>(attribute.attribute), |
70 v8::Local<v8::AccessorSignature>(), v8::DEFAULT); | 83 v8::Local<v8::AccessorSignature>(), v8::DEFAULT); |
71 } | 84 } |
72 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) | 85 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) |
73 NOTREACHED(); | 86 NOTREACHED(); |
74 } | 87 } |
75 | 88 |
76 void installAttributeInternal( | 89 void installAttributeInternal( |
77 v8::Isolate* isolate, | 90 v8::Isolate* isolate, |
78 v8::Local<v8::Object> instance, | 91 v8::Local<v8::Object> instance, |
79 v8::Local<v8::Object> prototype, | 92 v8::Local<v8::Object> prototype, |
80 const V8DOMConfiguration::AttributeConfiguration& attribute, | 93 const V8DOMConfiguration::AttributeConfiguration& attribute, |
81 const DOMWrapperWorld& world) { | 94 const DOMWrapperWorld& world) { |
| 95 if (!worldConfigurationApplies(attribute, world)) |
| 96 return; |
82 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); | 97 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); |
83 | 98 |
84 // This method is only being used for installing interfaces which are | 99 // This method is only being used for installing interfaces which are |
85 // enabled through origin trials. Assert here that it is being called with | 100 // enabled through origin trials. Assert here that it is being called with |
86 // an attribute configuration for a constructor. | 101 // an attribute configuration for a constructor. |
87 // TODO(iclelland): Relax this constraint and allow arbitrary data-type | 102 // TODO(iclelland): Relax this constraint and allow arbitrary data-type |
88 // properties to be added here. | 103 // properties to be added here. |
89 DCHECK_EQ(&v8ConstructorAttributeGetter, attribute.getter); | 104 DCHECK_EQ(&v8ConstructorAttributeGetter, attribute.getter); |
90 | 105 |
91 V8PerContextData* perContextData = | 106 V8PerContextData* perContextData = |
(...skipping 20 matching lines...) Expand all Loading... |
112 | 127 |
113 void installLazyDataAttributeInternal( | 128 void installLazyDataAttributeInternal( |
114 v8::Isolate* isolate, | 129 v8::Isolate* isolate, |
115 v8::Local<v8::ObjectTemplate> instanceTemplate, | 130 v8::Local<v8::ObjectTemplate> instanceTemplate, |
116 v8::Local<v8::ObjectTemplate> prototypeTemplate, | 131 v8::Local<v8::ObjectTemplate> prototypeTemplate, |
117 const V8DOMConfiguration::AttributeConfiguration& attribute, | 132 const V8DOMConfiguration::AttributeConfiguration& attribute, |
118 const DOMWrapperWorld& world) { | 133 const DOMWrapperWorld& world) { |
119 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); | 134 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); |
120 v8::AccessorNameGetterCallback getter = attribute.getter; | 135 v8::AccessorNameGetterCallback getter = attribute.getter; |
121 DCHECK(!attribute.setter); | 136 DCHECK(!attribute.setter); |
122 DCHECK(!attribute.getterForMainWorld); | 137 DCHECK_EQ(attribute.worldConfiguration, V8DOMConfiguration::AllWorlds); |
123 DCHECK(!attribute.setterForMainWorld); | |
124 v8::Local<v8::Value> data = | 138 v8::Local<v8::Value> data = |
125 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)); | 139 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)); |
126 | 140 |
127 DCHECK(attribute.propertyLocationConfiguration); | 141 DCHECK(attribute.propertyLocationConfiguration); |
128 if (attribute.propertyLocationConfiguration & | 142 if (attribute.propertyLocationConfiguration & |
129 V8DOMConfiguration::OnInstance) { | 143 V8DOMConfiguration::OnInstance) { |
130 instanceTemplate->SetLazyDataProperty( | 144 instanceTemplate->SetLazyDataProperty( |
131 name, getter, data, | 145 name, getter, data, |
132 static_cast<v8::PropertyAttribute>(attribute.attribute)); | 146 static_cast<v8::PropertyAttribute>(attribute.attribute)); |
133 } | 147 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 218 |
205 template <class ObjectOrTemplate, class FunctionOrTemplate> | 219 template <class ObjectOrTemplate, class FunctionOrTemplate> |
206 void installAccessorInternal( | 220 void installAccessorInternal( |
207 v8::Isolate* isolate, | 221 v8::Isolate* isolate, |
208 v8::Local<ObjectOrTemplate> instanceOrTemplate, | 222 v8::Local<ObjectOrTemplate> instanceOrTemplate, |
209 v8::Local<ObjectOrTemplate> prototypeOrTemplate, | 223 v8::Local<ObjectOrTemplate> prototypeOrTemplate, |
210 v8::Local<FunctionOrTemplate> interfaceOrTemplate, | 224 v8::Local<FunctionOrTemplate> interfaceOrTemplate, |
211 v8::Local<v8::Signature> signature, | 225 v8::Local<v8::Signature> signature, |
212 const V8DOMConfiguration::AccessorConfiguration& accessor, | 226 const V8DOMConfiguration::AccessorConfiguration& accessor, |
213 const DOMWrapperWorld& world) { | 227 const DOMWrapperWorld& world) { |
| 228 if (!worldConfigurationApplies(accessor, world)) |
| 229 return; |
214 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); | 230 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); |
215 v8::FunctionCallback getterCallback = accessor.getter; | 231 v8::FunctionCallback getterCallback = accessor.getter; |
216 v8::FunctionCallback setterCallback = accessor.setter; | 232 v8::FunctionCallback setterCallback = accessor.setter; |
217 V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback = nullptr; | 233 V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback = nullptr; |
218 if (world.isMainWorld()) { | 234 if (world.isMainWorld()) { |
219 if (accessor.getterForMainWorld) | |
220 getterCallback = accessor.getterForMainWorld; | |
221 if (accessor.setterForMainWorld) | |
222 setterCallback = accessor.setterForMainWorld; | |
223 cachedAccessorCallback = accessor.cachedAccessorCallback; | 235 cachedAccessorCallback = accessor.cachedAccessorCallback; |
224 } | 236 } |
225 | 237 |
226 // Support [LenientThis] by not specifying the signature. V8 does not do | 238 // Support [LenientThis] by not specifying the signature. V8 does not do |
227 // the type checking against holder if no signature is specified. Note that | 239 // the type checking against holder if no signature is specified. Note that |
228 // info.Holder() passed to callbacks will be *unsafe*. | 240 // info.Holder() passed to callbacks will be *unsafe*. |
229 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) | 241 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) |
230 signature = v8::Local<v8::Signature>(); | 242 signature = v8::Local<v8::Signature>(); |
231 v8::Local<v8::Value> data = | 243 v8::Local<v8::Value> data = |
232 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); | 244 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 329 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
318 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); | 330 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); |
319 v8::PropertyAttribute attributes = | 331 v8::PropertyAttribute attributes = |
320 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 332 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
321 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); | 333 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); |
322 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); | 334 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
323 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); | 335 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
324 } | 336 } |
325 | 337 |
326 template <class Configuration> | 338 template <class Configuration> |
327 bool worldConfigurationApplies(const Configuration& config, | |
328 const DOMWrapperWorld& world) { | |
329 const auto currentWorldConfig = world.isMainWorld() | |
330 ? V8DOMConfiguration::MainWorld | |
331 : V8DOMConfiguration::NonMainWorlds; | |
332 return config.worldConfiguration & currentWorldConfig; | |
333 } | |
334 | |
335 template <> | |
336 bool worldConfigurationApplies( | |
337 const V8DOMConfiguration::SymbolKeyedMethodConfiguration&, | |
338 const DOMWrapperWorld&) { | |
339 return true; | |
340 } | |
341 | |
342 template <class Configuration> | |
343 void installMethodInternal(v8::Isolate* isolate, | 339 void installMethodInternal(v8::Isolate* isolate, |
344 v8::Local<v8::ObjectTemplate> instanceTemplate, | 340 v8::Local<v8::ObjectTemplate> instanceTemplate, |
345 v8::Local<v8::ObjectTemplate> prototypeTemplate, | 341 v8::Local<v8::ObjectTemplate> prototypeTemplate, |
346 v8::Local<v8::FunctionTemplate> interfaceTemplate, | 342 v8::Local<v8::FunctionTemplate> interfaceTemplate, |
347 v8::Local<v8::Signature> signature, | 343 v8::Local<v8::Signature> signature, |
348 const Configuration& method, | 344 const Configuration& method, |
349 const DOMWrapperWorld& world) { | 345 const DOMWrapperWorld& world) { |
350 if (!worldConfigurationApplies(method, world)) | 346 if (!worldConfigurationApplies(method, world)) |
351 return; | 347 return; |
352 | 348 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 void V8DOMConfiguration::setClassString( | 688 void V8DOMConfiguration::setClassString( |
693 v8::Isolate* isolate, | 689 v8::Isolate* isolate, |
694 v8::Local<v8::ObjectTemplate> objectTemplate, | 690 v8::Local<v8::ObjectTemplate> objectTemplate, |
695 const char* classString) { | 691 const char* classString) { |
696 objectTemplate->Set( | 692 objectTemplate->Set( |
697 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), | 693 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), |
698 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 694 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
699 } | 695 } |
700 | 696 |
701 } // namespace blink | 697 } // namespace blink |
OLD | NEW |