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, V8DOMConfigu ration::PrivatePropertyCallback, v8::Local<v8::Value> data, v8::Local<v8::Signat ure>, int length); |
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, V8DOMConfiguration::PrivatePropertyCal lback surrogateProperty, v8::Local<v8::Value> data, v8::Local<v8::Signature> sig nature, 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 (surrogateProperty) { |
109 functionTemplate = v8::FunctionTemplate::NewSurrogate(isolate, c allback, | |
110 surrogateProperty(isolate), data, signature, length); | |
111 } else { | |
112 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, signature, length); | |
113 } | |
108 } | 114 } |
109 | 115 |
110 if (!functionTemplate.IsEmpty()) { | 116 if (!functionTemplate.IsEmpty()) { |
111 functionTemplate->RemovePrototype(); | 117 functionTemplate->RemovePrototype(); |
112 functionTemplate->SetAcceptAnyReceiver(false); | 118 functionTemplate->SetAcceptAnyReceiver(false); |
113 } | 119 } |
114 } | 120 } |
115 return functionTemplate; | 121 return functionTemplate; |
116 } | 122 } |
117 | 123 |
118 template <> | 124 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) | 125 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(v8::Isola te* isolate, v8::FunctionCallback callback, V8DOMConfiguration::FastAccessorBuil derCallback, V8DOMConfiguration::PrivatePropertyCallback, v8::Local<v8::Value> d ata, v8::Local<v8::Signature> signature, int length) |
120 { | 126 { |
121 if (!callback) | 127 if (!callback) |
122 return v8::Local<v8::Function>(); | 128 return v8::Local<v8::Function>(); |
123 | 129 |
124 v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrT emplate<v8::FunctionTemplate>(isolate, callback, nullptr, data, signature, lengt h); | 130 v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrT emplate<v8::FunctionTemplate>(isolate, callback, nullptr, nullptr, data, signatu re, length); |
125 if (functionTemplate.IsEmpty()) | 131 if (functionTemplate.IsEmpty()) |
126 return v8::Local<v8::Function>(); | 132 return v8::Local<v8::Function>(); |
127 | 133 |
128 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 134 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
129 v8::Local<v8::Function> function; | 135 v8::Local<v8::Function> function; |
130 if (!functionTemplate->GetFunction(context).ToLocal(&function)) | 136 if (!functionTemplate->GetFunction(context).ToLocal(&function)) |
131 return v8::Local<v8::Function>(); | 137 return v8::Local<v8::Function>(); |
132 return function; | 138 return function; |
133 } | 139 } |
134 | 140 |
(...skipping 20 matching lines...) Expand all Loading... | |
155 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) | 161 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) |
156 signature = v8::Local<v8::Signature>(); | 162 signature = v8::Local<v8::Signature>(); |
157 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data)); | 163 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data)); |
158 | 164 |
159 DCHECK(accessor.propertyLocationConfiguration); | 165 DCHECK(accessor.propertyLocationConfiguration); |
160 | 166 |
161 V8DOMConfiguration::FastAccessorBuilderCallback fastGetterCallback = accesso r.fastGetter; | 167 V8DOMConfiguration::FastAccessorBuilderCallback fastGetterCallback = accesso r.fastGetter; |
162 | 168 |
163 if (accessor.propertyLocationConfiguration & | 169 if (accessor.propertyLocationConfiguration & |
164 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { | 170 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { |
165 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, data, signature , 0); | 171 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, accessor.surrog atePropertyCallback, data, signature, 0); |
166 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, nullptr, data, signature, 1); | 172 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, nullptr, 0, data, signature, 1); |
jochen (gone - plz use gerrit)
2016/09/19 14:54:19
you still have some 0 in your CL that should be nu
haraken
2016/09/20 05:53:25
You don't need to worry about 0 or nullptr in this
| |
167 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce) | 173 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce) |
168 instanceOrTemplate->SetAccessorProperty(name, getter, setter, static _cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl> (accessor.settings)); | 174 instanceOrTemplate->SetAccessorProperty(name, getter, setter, static _cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl> (accessor.settings)); |
169 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnProto type) | 175 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)); | 176 prototypeOrTemplate->SetAccessorProperty(name, getter, setter, stati c_cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl >(accessor.settings)); |
171 } | 177 } |
172 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { | 178 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { |
173 // Attributes installed on the interface object must be static | 179 // Attributes installed on the interface object must be static |
174 // attributes, so no need to specify a signature, i.e. no need to do | 180 // attributes, so no need to specify a signature, i.e. no need to do |
175 // type check against a holder. | 181 // type check against a holder. |
176 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, fastGetterCallback, data, v8::Local <v8::Signature>(), 0); | 182 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); | 183 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)); | 184 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings)); |
179 } | 185 } |
180 } | 186 } |
181 | 187 |
182 v8::Local<v8::Primitive> valueForConstant(v8::Isolate* isolate, const V8DOMConfi guration::ConstantConfiguration& constant) | 188 v8::Local<v8::Primitive> valueForConstant(v8::Isolate* isolate, const V8DOMConfi guration::ConstantConfiguration& constant) |
183 { | 189 { |
184 v8::Local<v8::Primitive> value; | 190 v8::Local<v8::Primitive> value; |
185 switch (constant.type) { | 191 switch (constant.type) { |
186 case V8DOMConfiguration::ConstantTypeShort: | 192 case V8DOMConfiguration::ConstantTypeShort: |
187 case V8DOMConfiguration::ConstantTypeLong: | 193 case V8DOMConfiguration::ConstantTypeLong: |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 data->setInterfaceTemplate(world, wrapperTypeInfo, result); | 404 data->setInterfaceTemplate(world, wrapperTypeInfo, result); |
399 return result; | 405 return result; |
400 } | 406 } |
401 | 407 |
402 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) | 408 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) |
403 { | 409 { |
404 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); | 410 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); |
405 } | 411 } |
406 | 412 |
407 } // namespace blink | 413 } // namespace blink |
OLD | NEW |