OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" | 5 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" |
6 | 6 |
7 #include "bindings/core/v8/DOMWrapperWorld.h" | 7 #include "bindings/core/v8/DOMWrapperWorld.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" | 9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 m_constructor)) { | 52 m_constructor)) { |
53 | 53 |
54 // Constructor is already registered. | 54 // Constructor is already registered. |
55 m_exceptionState.throwDOMException( | 55 m_exceptionState.throwDOMException( |
56 NotSupportedError, | 56 NotSupportedError, |
57 "this constructor has already been used with this registry"); | 57 "this constructor has already been used with this registry"); |
58 return false; | 58 return false; |
59 } | 59 } |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
haraken
2016/06/06 01:39:15
I'd change 'char*' in this file with 'String'.
kojii
2016/06/06 11:12:35
Done.
| |
63 bool ScriptCustomElementDefinitionBuilder::valueForName( | |
64 const v8::Local<v8::Object>& object, const char* name, | |
65 v8::Local<v8::Value>& value) const | |
66 { | |
67 v8::Isolate* isolate = m_scriptState->isolate(); | |
68 v8::Local<v8::Context> context = m_scriptState->context(); | |
69 v8::Local<v8::String> nameString = v8AtomicString(isolate, name); | |
70 return v8Call(object->Get(context, nameString), value); | |
71 } | |
72 | |
63 bool ScriptCustomElementDefinitionBuilder::checkPrototype() | 73 bool ScriptCustomElementDefinitionBuilder::checkPrototype() |
64 { | 74 { |
65 v8::Isolate* isolate = m_scriptState->isolate(); | |
66 v8::Local<v8::Context> context = m_scriptState->context(); | |
67 v8::Local<v8::String> prototypeString = | |
68 v8AtomicString(isolate, "prototype"); | |
69 v8::Local<v8::Value> prototypeValue; | 75 v8::Local<v8::Value> prototypeValue; |
70 if (!v8Call( | 76 if (!valueForName(m_constructor, "prototype", prototypeValue)) |
71 m_constructor->Get(context, prototypeString), prototypeValue)) { | |
72 return false; | 77 return false; |
73 } | |
74 if (!prototypeValue->IsObject()) { | 78 if (!prototypeValue->IsObject()) { |
75 m_exceptionState.throwTypeError( | 79 m_exceptionState.throwTypeError( |
76 "constructor prototype is not an object"); | 80 "constructor prototype is not an object"); |
77 return false; | 81 return false; |
78 } | 82 } |
79 m_prototype = prototypeValue.As<v8::Object>(); | 83 m_prototype = prototypeValue.As<v8::Object>(); |
80 // If retrieving the prototype destroyed the context, indicate that | 84 // If retrieving the prototype destroyed the context, indicate that |
81 // defining the element should not proceed. | 85 // defining the element should not proceed. |
82 return true; | 86 return true; |
83 } | 87 } |
84 | 88 |
89 bool ScriptCustomElementDefinitionBuilder::callableForName(const char* name, | |
90 v8::Local<v8::Object>& callback) const | |
91 { | |
92 v8::Local<v8::Value> value; | |
93 if (!valueForName(m_prototype, name, value)) | |
94 return false; | |
95 if (value->IsUndefined()) | |
96 return true; | |
haraken
2016/06/06 01:39:15
Just to confirm: You want to return true for undef
kojii
2016/06/06 11:12:34
Yes:
Undefined or IsCallable -> true (success)
Oth
| |
97 if (!value->IsObject()) { | |
98 m_exceptionState.throwTypeError( | |
99 String::format("\"%s\" is not an object", name)); | |
100 return false; | |
101 } | |
102 callback = value.As<v8::Object>(); | |
103 if (!callback->IsCallable()) { | |
104 m_exceptionState.throwTypeError( | |
105 String::format("\"%s\" is not callable", name)); | |
106 return false; | |
107 } | |
108 return true; | |
109 } | |
110 | |
111 bool ScriptCustomElementDefinitionBuilder::cacheObservedAttributes() | |
112 { | |
113 const char* kObservedAttributes = "observedAttributes"; | |
114 v8::Local<v8::Value> observedAttributesValue; | |
115 if (!valueForName(m_constructor, kObservedAttributes, observedAttributesValu e)) | |
116 return false; | |
117 if (observedAttributesValue->IsUndefined()) | |
118 return true; | |
119 Vector<AtomicString> list = toImplArray<Vector<AtomicString>>( | |
120 observedAttributesValue, 0, m_scriptState->isolate(), m_exceptionState); | |
121 if (m_exceptionState.hadException()) | |
122 return false; | |
123 if (list.isEmpty()) | |
124 return true; | |
125 m_observedAttributes.reserveCapacityForSize(list.size()); | |
126 for (const auto& attribute : list) | |
127 m_observedAttributes.add(attribute); | |
128 return true; | |
129 } | |
130 | |
131 bool ScriptCustomElementDefinitionBuilder::cacheProperties() | |
haraken
2016/06/06 01:39:15
I'm a bit confused with the name "cacheProperties"
kojii
2016/06/06 11:12:35
This method retrieves values and keep it in member
haraken
2016/06/06 11:45:52
rememberOriginalProperties ?
Also add a comment a
| |
132 { | |
133 | |
134 const char* kConnectedCallback = "connectedCallback"; | |
135 const char* kDisconnectedCallback = "disconnectedCallback"; | |
136 const char* kAttributeChangedCallback = "attributeChangedCallback"; | |
137 return cacheObservedAttributes() | |
138 && callableForName(kConnectedCallback, m_connectedCallback) | |
139 && callableForName(kDisconnectedCallback, m_disconnectedCallback) | |
140 && callableForName(kAttributeChangedCallback, m_attributeChangedCallback ); | |
141 } | |
142 | |
85 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( | 143 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( |
86 const CustomElementDescriptor& descriptor) | 144 const CustomElementDescriptor& descriptor) |
87 { | 145 { |
88 return ScriptCustomElementDefinition::create( | 146 return ScriptCustomElementDefinition::create( |
89 m_scriptState.get(), | 147 m_scriptState.get(), |
90 m_registry, | 148 m_registry, |
91 descriptor, | 149 descriptor, |
92 m_constructor, | 150 m_constructor, |
93 m_prototype); | 151 m_prototype, |
152 m_connectedCallback, | |
153 m_disconnectedCallback, | |
154 m_attributeChangedCallback, | |
155 m_observedAttributes); | |
94 } | 156 } |
95 | 157 |
96 } // namespace blink | 158 } // namespace blink |
OLD | NEW |