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/ScriptCustomElementDefinition.h" | 5 #include "bindings/core/v8/ScriptCustomElementDefinition.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
9 #include "bindings/core/v8/V8BindingMacros.h" | 9 #include "bindings/core/v8/V8BindingMacros.h" |
10 #include "bindings/core/v8/V8CustomElementsRegistry.h" | 10 #include "bindings/core/v8/V8CustomElementsRegistry.h" |
11 #include "bindings/core/v8/V8Element.h" | 11 #include "bindings/core/v8/V8Element.h" |
12 #include "bindings/core/v8/V8ErrorHandler.h" | |
12 #include "bindings/core/v8/V8HiddenValue.h" | 13 #include "bindings/core/v8/V8HiddenValue.h" |
13 #include "bindings/core/v8/V8ScriptRunner.h" | 14 #include "bindings/core/v8/V8ScriptRunner.h" |
14 #include "bindings/core/v8/V8ThrowException.h" | 15 #include "bindings/core/v8/V8ThrowException.h" |
15 #include "core/dom/ExceptionCode.h" | 16 #include "core/dom/ExceptionCode.h" |
17 #include "core/events/ErrorEvent.h" | |
16 #include "core/html/HTMLElement.h" | 18 #include "core/html/HTMLElement.h" |
17 #include "core/html/HTMLUnknownElement.h" | 19 #include "core/html/HTMLUnknownElement.h" |
18 #include "v8.h" | 20 #include "v8.h" |
19 #include "wtf/Allocator.h" | 21 #include "wtf/Allocator.h" |
20 | 22 |
21 namespace blink { | 23 namespace blink { |
22 | 24 |
23 // Retrieves the custom elements constructor -> name map, creating it | 25 // Retrieves the custom elements constructor -> name map, creating it |
24 // if necessary. The same map is used to keep prototypes alive. | 26 // if necessary. The same map is used to keep prototypes alive. |
25 static v8::Local<v8::Map> ensureCustomElementsRegistryMap( | 27 static v8::Local<v8::Map> ensureCustomElementsRegistryMap( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 return false; | 224 return false; |
223 ScriptState::Scope scope(m_scriptState.get()); | 225 ScriptState::Scope scope(m_scriptState.get()); |
224 v8::Isolate* isolate = m_scriptState->isolate(); | 226 v8::Isolate* isolate = m_scriptState->isolate(); |
225 | 227 |
226 // Step 5 says to rethrow the exception; but there is no one to | 228 // Step 5 says to rethrow the exception; but there is no one to |
227 // catch it. The side effect is to report the error. | 229 // catch it. The side effect is to report the error. |
228 v8::TryCatch tryCatch(isolate); | 230 v8::TryCatch tryCatch(isolate); |
229 tryCatch.SetVerbose(true); | 231 tryCatch.SetVerbose(true); |
230 | 232 |
231 Element* result = runConstructor(); | 233 Element* result = runConstructor(); |
232 if (!result) | 234 if (tryCatch.HasCaught()) |
233 return false; | 235 return false; |
234 | 236 |
235 if (result != element) { | 237 if (result != element) { |
238 const String& message = "custom element constructors must call super() f irst and must " | |
haraken
2016/07/26 11:25:16
I want to create a helper method that runs line 23
| |
239 "not return a different object"; | |
236 V8ThrowException::throwException( | 240 V8ThrowException::throwException( |
237 V8ThrowException::createDOMException( | 241 V8ThrowException::createDOMException( |
238 m_scriptState->isolate(), | 242 m_scriptState->isolate(), |
239 InvalidStateError, | 243 InvalidStateError, |
240 "custom element constructors must call super() first and must " | 244 message, |
241 "not return a different object", | |
242 constructor()), | 245 constructor()), |
243 m_scriptState->isolate()); | 246 m_scriptState->isolate()); |
247 | |
248 v8::Local<v8::Function> function = constructor().As<v8::Function>(); | |
249 ErrorEvent* event = ErrorEvent::create( | |
250 message, | |
251 SourceLocation::fromFunction(function), | |
252 &m_scriptState->world()); | |
253 V8ErrorHandler::storeExceptionOnErrorEventWrapper(m_scriptState.get(), e vent, tryCatch.Exception(), m_scriptState->context()->Global()); | |
haraken
2016/07/26 11:46:16
BTW, is this line needed?
e.g., Lazy event listen
| |
254 ExecutionContext* executionContext = m_scriptState->getExecutionContext( ); | |
255 executionContext->reportException(event, NotSharableCrossOrigin); | |
haraken
2016/07/22 09:31:53
Do we really need to report the exception synchron
| |
256 | |
244 return false; | 257 return false; |
245 } | 258 } |
246 | 259 |
247 return true; | 260 return true; |
248 } | 261 } |
249 | 262 |
250 Element* ScriptCustomElementDefinition::runConstructor() | 263 Element* ScriptCustomElementDefinition::runConstructor() |
251 { | 264 { |
252 v8::Isolate* isolate = m_scriptState->isolate(); | 265 v8::Isolate* isolate = m_scriptState->isolate(); |
253 DCHECK(ScriptState::current(isolate) == m_scriptState); | 266 DCHECK(ScriptState::current(isolate) == m_scriptState); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 v8String(isolate, name.localName()), | 360 v8String(isolate, name.localName()), |
348 v8StringOrNull(isolate, oldValue), | 361 v8StringOrNull(isolate, oldValue), |
349 v8StringOrNull(isolate, newValue), | 362 v8StringOrNull(isolate, newValue), |
350 v8String(isolate, name.namespaceURI()), | 363 v8String(isolate, name.namespaceURI()), |
351 }; | 364 }; |
352 runCallback(m_attributeChangedCallback.newLocal(isolate), element, | 365 runCallback(m_attributeChangedCallback.newLocal(isolate), element, |
353 argc, argv); | 366 argc, argv); |
354 } | 367 } |
355 | 368 |
356 } // namespace blink | 369 } // namespace blink |
OLD | NEW |