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 13 matching lines...) Expand all Loading... | |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #include "bindings/core/v8/V8DOMConfiguration.h" | 29 #include "bindings/core/v8/V8DOMConfiguration.h" |
30 | 30 |
31 #include "bindings/core/v8/GeneratedCodeHelper.h" // just for DCHECK | 31 #include "bindings/core/v8/GeneratedCodeHelper.h" // just for DCHECK |
32 #include "bindings/core/v8/V8ObjectConstructor.h" | 32 #include "bindings/core/v8/V8ObjectConstructor.h" |
33 #include "bindings/core/v8/V8PerContextData.h" | 33 #include "bindings/core/v8/V8PerContextData.h" |
34 #include "bindings/core/v8/WindowProxy.h" | |
34 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 void installAttributeInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate > instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8DOM Configuration::AttributeConfiguration& attribute, const DOMWrapperWorld& world) | 41 void installAttributeInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate > instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8DOM Configuration::AttributeConfiguration& attribute, const DOMWrapperWorld& world) |
41 { | 42 { |
42 if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivat eScript | 43 if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivat eScript |
43 && !world.isPrivateScriptIsolatedWorld()) | 44 && !world.isPrivateScriptIsolatedWorld()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 DCHECK(attribute.propertyLocationConfiguration); | 85 DCHECK(attribute.propertyLocationConfiguration); |
85 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance ) | 86 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance ) |
86 instance->DefineOwnProperty(isolate->GetCurrentContext(), name, data, st atic_cast<v8::PropertyAttribute>(attribute.attribute)).ToChecked(); | 87 instance->DefineOwnProperty(isolate->GetCurrentContext(), name, data, st atic_cast<v8::PropertyAttribute>(attribute.attribute)).ToChecked(); |
87 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp e) | 88 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp e) |
88 prototype->DefineOwnProperty(isolate->GetCurrentContext(), name, data, s tatic_cast<v8::PropertyAttribute>(attribute.attribute)).ToChecked(); | 89 prototype->DefineOwnProperty(isolate->GetCurrentContext(), name, data, s tatic_cast<v8::PropertyAttribute>(attribute.attribute)).ToChecked(); |
89 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac e) | 90 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac e) |
90 NOTREACHED(); | 91 NOTREACHED(); |
91 } | 92 } |
92 | 93 |
93 template <class FunctionOrTemplate> | 94 template <class FunctionOrTemplate> |
94 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8: :FunctionCallback, V8DOMConfiguration::FastAccessorBuilderCallback, v8::Local<v8 ::Value> data, v8::Local<v8::Signature>, int length); | 95 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8: :FunctionCallback, V8DOMConfiguration::FastAccessorBuilderCallback, const char* const surrogateName, v8::Local<v8::Value> data, v8::Local<v8::Signature>, int le ngth); |
95 | 96 |
96 template <> | 97 template <> |
97 v8::Local<v8::FunctionTemplate> createAccessorFunctionOrTemplate<v8::FunctionTem plate>(v8::Isolate* isolate, v8::FunctionCallback callback, V8DOMConfiguration:: FastAccessorBuilderCallback fastCallback, v8::Local<v8::Value> data, v8::Local<v 8::Signature> signature, int length) | 98 v8::Local<v8::FunctionTemplate> createAccessorFunctionOrTemplate<v8::FunctionTem plate>(v8::Isolate* isolate, v8::FunctionCallback callback, V8DOMConfiguration:: FastAccessorBuilderCallback fastCallback, const char* const surrogateName, v8::L ocal<v8::Value> data, v8::Local<v8::Signature> signature, int length) |
98 { | 99 { |
99 v8::Local<v8::FunctionTemplate> functionTemplate; | 100 v8::Local<v8::FunctionTemplate> functionTemplate; |
100 if (callback) { | 101 if (callback) { |
101 // Fast accessors are guarded by the FastDOMAccessors runtime flag. | 102 // Fast accessors are guarded by the FastDOMAccessors runtime flag. |
102 if (RuntimeEnabledFeatures::fastDOMAccessorsEnabled() && fastCallback) { | 103 if (RuntimeEnabledFeatures::fastDOMAccessorsEnabled() && fastCallback) { |
103 v8::experimental::FastAccessorBuilder* fab = fastCallback(isolate, c allback); | 104 v8::experimental::FastAccessorBuilder* fab = fastCallback(isolate, c allback); |
104 DCHECK(fab); | 105 DCHECK(fab); |
105 functionTemplate = v8::FunctionTemplate::NewWithFastHandler(isolate, callback, fab, data, signature, length); | 106 functionTemplate = v8::FunctionTemplate::NewWithFastHandler(isolate, callback, fab, data, signature, length); |
106 } else { | 107 } else { |
107 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data , signature, length); | 108 if (surrogateName) { |
109 v8::Local<v8::String> name = | |
110 v8::String::NewFromUtf8(isolate, surrogateName, v8::NewStrin gType::kNormal).ToLocalChecked(); | |
vogelheim
2016/09/15 15:29:47
nitpick: The line breaking is strange. Since Blink
Alfonso
2016/09/16 14:21:47
Done.
| |
111 | |
112 // Persist the private property in the global map. | |
113 v8::Local<v8::Private> property = v8::Private::New(isolate, name ); | |
114 WindowProxy::cachedAccessors()[surrogateName].Set(isolate, prope rty); | |
115 | |
116 functionTemplate = v8::FunctionTemplate::NewSurrogate(isolate, c allback, property, data, signature, length); | |
117 } else { | |
118 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, signature, length); | |
119 } | |
108 } | 120 } |
109 | 121 |
110 if (!functionTemplate.IsEmpty()) { | 122 if (!functionTemplate.IsEmpty()) { |
111 functionTemplate->RemovePrototype(); | 123 functionTemplate->RemovePrototype(); |
112 functionTemplate->SetAcceptAnyReceiver(false); | 124 functionTemplate->SetAcceptAnyReceiver(false); |
113 } | 125 } |
114 } | 126 } |
115 return functionTemplate; | 127 return functionTemplate; |
116 } | 128 } |
117 | 129 |
118 template <> | 130 template <> |
119 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(v8::Isola te* isolate, v8::FunctionCallback callback, V8DOMConfiguration::FastAccessorBuil derCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length) | 131 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(v8::Isola te* isolate, v8::FunctionCallback callback, V8DOMConfiguration::FastAccessorBuil derCallback, const char* const, v8::Local<v8::Value> data, v8::Local<v8::Signatu re> signature, int length) |
jochen (gone - plz use gerrit)
2016/09/15 08:20:51
why not just const char*?
| |
120 { | 132 { |
121 if (!callback) | 133 if (!callback) |
122 return v8::Local<v8::Function>(); | 134 return v8::Local<v8::Function>(); |
123 | 135 |
124 v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrT emplate<v8::FunctionTemplate>(isolate, callback, nullptr, data, signature, lengt h); | 136 v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrT emplate<v8::FunctionTemplate>(isolate, callback, nullptr, 0, data, signature, le ngth); |
jochen (gone - plz use gerrit)
2016/09/15 08:20:51
nullptr
Alfonso
2016/09/16 14:21:47
I'm confused about when to use 0 vs nullptr, I've
| |
125 if (functionTemplate.IsEmpty()) | 137 if (functionTemplate.IsEmpty()) |
126 return v8::Local<v8::Function>(); | 138 return v8::Local<v8::Function>(); |
127 | 139 |
128 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 140 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
129 v8::Local<v8::Function> function; | 141 v8::Local<v8::Function> function; |
130 if (!functionTemplate->GetFunction(context).ToLocal(&function)) | 142 if (!functionTemplate->GetFunction(context).ToLocal(&function)) |
131 return v8::Local<v8::Function>(); | 143 return v8::Local<v8::Function>(); |
132 return function; | 144 return function; |
133 } | 145 } |
134 | 146 |
(...skipping 20 matching lines...) Expand all Loading... | |
155 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) | 167 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) |
156 signature = v8::Local<v8::Signature>(); | 168 signature = v8::Local<v8::Signature>(); |
157 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data)); | 169 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data)); |
158 | 170 |
159 DCHECK(accessor.propertyLocationConfiguration); | 171 DCHECK(accessor.propertyLocationConfiguration); |
160 | 172 |
161 V8DOMConfiguration::FastAccessorBuilderCallback fastGetterCallback = accesso r.fastGetter; | 173 V8DOMConfiguration::FastAccessorBuilderCallback fastGetterCallback = accesso r.fastGetter; |
162 | 174 |
163 if (accessor.propertyLocationConfiguration & | 175 if (accessor.propertyLocationConfiguration & |
164 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { | 176 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { |
165 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, data, signature , 0); | 177 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, accessor.surrog atePropertyName, data, signature, 0); |
166 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, nullptr, data, signature, 1); | 178 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, nullptr, 0, data, signature, 1); |
167 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce) | 179 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce) { |
168 instanceOrTemplate->SetAccessorProperty(name, getter, setter, static _cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl> (accessor.settings)); | 180 instanceOrTemplate->SetAccessorProperty(name, getter, setter, static _cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl> (accessor.settings)); |
181 | |
182 // TODO(peterssen): Replicate for other 'locations' besides instance (prototype, interface...). | |
183 if (accessor.surrogatePropertyName) { | |
184 v8::Local<v8::Private> property = | |
185 blink::WindowProxy::cachedAccessors().at(accessor.surrogateP ropertyName).Get(isolate); | |
186 | |
187 instanceOrTemplate->Set(v8::Private::AsSymbol(property).As<v8::N ame>(), v8::Undefined(isolate)); | |
jochen (gone - plz use gerrit)
2016/09/15 08:20:51
undefined would be the wrong value here, shouldn't
vogelheim
2016/09/15 15:29:47
Wouldn't this usually be overwritten by WindowProx
Alfonso
2016/09/16 14:21:47
Ack-ed.
haraken@ also suggested to use the normal
Alfonso
2016/09/16 14:21:47
I only have ran V8-side tests, but it will be remo
| |
188 } | |
189 } | |
190 | |
169 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnProto type) | 191 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnProto type) |
170 prototypeOrTemplate->SetAccessorProperty(name, getter, setter, stati c_cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl >(accessor.settings)); | 192 prototypeOrTemplate->SetAccessorProperty(name, getter, setter, stati c_cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl >(accessor.settings)); |
171 } | 193 } |
172 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { | 194 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { |
173 // Attributes installed on the interface object must be static | 195 // Attributes installed on the interface object must be static |
174 // attributes, so no need to specify a signature, i.e. no need to do | 196 // attributes, so no need to specify a signature, i.e. no need to do |
175 // type check against a holder. | 197 // type check against a holder. |
176 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, data, v8::Local <v8::Signature>(), 0); | 198 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, 0, data, v8::Lo cal<v8::Signature>(), 0); |
177 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, nullptr, data, v8::Local<v8::Signat ure>(), 1); | 199 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, nullptr, 0, data, v8::Local<v8::Sig nature>(), 1); |
178 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings)); | 200 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings)); |
179 } | 201 } |
180 } | 202 } |
181 | 203 |
182 v8::Local<v8::Primitive> valueForConstant(v8::Isolate* isolate, const V8DOMConfi guration::ConstantConfiguration& constant) | 204 v8::Local<v8::Primitive> valueForConstant(v8::Isolate* isolate, const V8DOMConfi guration::ConstantConfiguration& constant) |
183 { | 205 { |
184 v8::Local<v8::Primitive> value; | 206 v8::Local<v8::Primitive> value; |
185 switch (constant.type) { | 207 switch (constant.type) { |
186 case V8DOMConfiguration::ConstantTypeShort: | 208 case V8DOMConfiguration::ConstantTypeShort: |
187 case V8DOMConfiguration::ConstantTypeLong: | 209 case V8DOMConfiguration::ConstantTypeLong: |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 data->setInterfaceTemplate(world, wrapperTypeInfo, result); | 420 data->setInterfaceTemplate(world, wrapperTypeInfo, result); |
399 return result; | 421 return result; |
400 } | 422 } |
401 | 423 |
402 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) | 424 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) |
403 { | 425 { |
404 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); | 426 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); |
405 } | 427 } |
406 | 428 |
407 } // namespace blink | 429 } // namespace blink |
OLD | NEW |