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 11 matching lines...) Expand all Loading... |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
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/ScriptState.h" |
32 #include "bindings/core/v8/V8ObjectConstructor.h" | 33 #include "bindings/core/v8/V8ObjectConstructor.h" |
33 #include "bindings/core/v8/V8PerContextData.h" | 34 #include "bindings/core/v8/V8PerContextData.h" |
34 #include "platform/tracing/TraceEvent.h" | 35 #include "platform/tracing/TraceEvent.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 void installAttributeInternal( | 41 void installAttributeInternal( |
41 v8::Isolate* isolate, | 42 v8::Isolate* isolate, |
(...skipping 29 matching lines...) Expand all Loading... |
71 prototypeTemplate->SetNativeDataProperty( | 72 prototypeTemplate->SetNativeDataProperty( |
72 name, getter, setter, data, | 73 name, getter, setter, data, |
73 static_cast<v8::PropertyAttribute>(attribute.attribute), | 74 static_cast<v8::PropertyAttribute>(attribute.attribute), |
74 v8::Local<v8::AccessorSignature>(), | 75 v8::Local<v8::AccessorSignature>(), |
75 static_cast<v8::AccessControl>(attribute.settings)); | 76 static_cast<v8::AccessControl>(attribute.settings)); |
76 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) | 77 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) |
77 NOTREACHED(); | 78 NOTREACHED(); |
78 } | 79 } |
79 | 80 |
80 void installAttributeInternal( | 81 void installAttributeInternal( |
81 v8::Isolate* isolate, | 82 const ScriptState* scriptState, |
82 v8::Local<v8::Object> instance, | 83 v8::Local<v8::Object> instance, |
83 v8::Local<v8::Object> prototype, | 84 v8::Local<v8::Object> prototype, |
84 const V8DOMConfiguration::AttributeConfiguration& attribute, | 85 const V8DOMConfiguration::AttributeConfiguration& attribute) { |
85 const DOMWrapperWorld& world) { | 86 v8::Isolate* isolate = scriptState->isolate(); |
| 87 const DOMWrapperWorld& world = scriptState->world(); |
| 88 |
86 if (attribute.exposeConfiguration == | 89 if (attribute.exposeConfiguration == |
87 V8DOMConfiguration::OnlyExposedToPrivateScript && | 90 V8DOMConfiguration::OnlyExposedToPrivateScript && |
88 !world.isPrivateScriptIsolatedWorld()) | 91 !world.isPrivateScriptIsolatedWorld()) |
89 return; | 92 return; |
90 | 93 |
91 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); | 94 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); |
92 | 95 |
93 // This method is only being used for installing interfaces which are | 96 // This method is only being used for installing interfaces which are |
94 // enabled through origin trials. Assert here that it is being called with | 97 // enabled through origin trials. Assert here that it is being called with |
95 // an attribute configuration for a constructor. | 98 // an attribute configuration for a constructor. |
96 // TODO(iclelland): Relax this constraint and allow arbitrary data-type | 99 // TODO(iclelland): Relax this constraint and allow arbitrary data-type |
97 // properties to be added here. | 100 // properties to be added here. |
98 DCHECK_EQ(&v8ConstructorAttributeGetter, attribute.getter); | 101 DCHECK_EQ(&v8ConstructorAttributeGetter, attribute.getter); |
99 | 102 |
100 V8PerContextData* perContextData = | 103 V8PerContextData* perContextData = |
101 V8PerContextData::from(isolate->GetCurrentContext()); | 104 V8PerContextData::from(scriptState->context()); |
102 v8::Local<v8::Function> data = | 105 v8::Local<v8::Function> value = |
103 perContextData->constructorForType(attribute.data); | 106 perContextData->constructorForType(attribute.data); |
104 | 107 |
105 DCHECK(attribute.propertyLocationConfiguration); | 108 DCHECK(attribute.propertyLocationConfiguration); |
106 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) | 109 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) |
107 instance | 110 instance |
108 ->DefineOwnProperty( | 111 ->DefineOwnProperty( |
109 isolate->GetCurrentContext(), name, data, | 112 isolate->GetCurrentContext(), name, value, |
110 static_cast<v8::PropertyAttribute>(attribute.attribute)) | 113 static_cast<v8::PropertyAttribute>(attribute.attribute)) |
111 .ToChecked(); | 114 .ToChecked(); |
112 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype) | 115 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype) |
113 prototype | 116 prototype |
114 ->DefineOwnProperty( | 117 ->DefineOwnProperty( |
115 isolate->GetCurrentContext(), name, data, | 118 isolate->GetCurrentContext(), name, value, |
116 static_cast<v8::PropertyAttribute>(attribute.attribute)) | 119 static_cast<v8::PropertyAttribute>(attribute.attribute)) |
117 .ToChecked(); | 120 .ToChecked(); |
118 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) | 121 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) |
119 NOTREACHED(); | 122 NOTREACHED(); |
120 } | 123 } |
121 | 124 |
122 template <class FunctionOrTemplate> | 125 template <class FunctionOrTemplate> |
123 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate( | 126 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate( |
124 v8::Isolate*, | 127 v8::Isolate*, |
125 v8::FunctionCallback, | 128 v8::FunctionCallback, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 v8::Isolate* isolate, | 411 v8::Isolate* isolate, |
409 const DOMWrapperWorld& world, | 412 const DOMWrapperWorld& world, |
410 v8::Local<v8::ObjectTemplate> instanceTemplate, | 413 v8::Local<v8::ObjectTemplate> instanceTemplate, |
411 v8::Local<v8::ObjectTemplate> prototypeTemplate, | 414 v8::Local<v8::ObjectTemplate> prototypeTemplate, |
412 const AttributeConfiguration& attribute) { | 415 const AttributeConfiguration& attribute) { |
413 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, | 416 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, |
414 attribute, world); | 417 attribute, world); |
415 } | 418 } |
416 | 419 |
417 void V8DOMConfiguration::installAttribute( | 420 void V8DOMConfiguration::installAttribute( |
418 v8::Isolate* isolate, | 421 const ScriptState* scriptState, |
419 const DOMWrapperWorld& world, | |
420 v8::Local<v8::Object> instance, | 422 v8::Local<v8::Object> instance, |
421 v8::Local<v8::Object> prototype, | 423 v8::Local<v8::Object> prototype, |
422 const AttributeConfiguration& attribute) { | 424 const AttributeConfiguration& attribute) { |
423 installAttributeInternal(isolate, instance, prototype, attribute, world); | 425 installAttributeInternal(scriptState, instance, prototype, attribute); |
424 } | 426 } |
425 | 427 |
426 void V8DOMConfiguration::installAccessors( | 428 void V8DOMConfiguration::installAccessors( |
427 v8::Isolate* isolate, | 429 v8::Isolate* isolate, |
428 const DOMWrapperWorld& world, | 430 const DOMWrapperWorld& world, |
429 v8::Local<v8::ObjectTemplate> instanceTemplate, | 431 v8::Local<v8::ObjectTemplate> instanceTemplate, |
430 v8::Local<v8::ObjectTemplate> prototypeTemplate, | 432 v8::Local<v8::ObjectTemplate> prototypeTemplate, |
431 v8::Local<v8::FunctionTemplate> interfaceTemplate, | 433 v8::Local<v8::FunctionTemplate> interfaceTemplate, |
432 v8::Local<v8::Signature> signature, | 434 v8::Local<v8::Signature> signature, |
433 const AccessorConfiguration* accessors, | 435 const AccessorConfiguration* accessors, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 void V8DOMConfiguration::setClassString( | 604 void V8DOMConfiguration::setClassString( |
603 v8::Isolate* isolate, | 605 v8::Isolate* isolate, |
604 v8::Local<v8::ObjectTemplate> objectTemplate, | 606 v8::Local<v8::ObjectTemplate> objectTemplate, |
605 const char* classString) { | 607 const char* classString) { |
606 objectTemplate->Set( | 608 objectTemplate->Set( |
607 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), | 609 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), |
608 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 610 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
609 } | 611 } |
610 | 612 |
611 } // namespace blink | 613 } // namespace blink |
OLD | NEW |