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) { |
236 V8ThrowException::throwException( | 238 V8ThrowException::throwException( |
237 V8ThrowException::createDOMException( | 239 V8ThrowException::createDOMException( |
238 m_scriptState->isolate(), | 240 m_scriptState->isolate(), |
239 InvalidStateError, | 241 InvalidStateError, |
240 "custom element constructors must call super() first and must " | 242 "custom element constructors must call super() first and must " |
241 "not return a different object", | 243 "not return a different object", |
242 constructor()), | 244 constructor()), |
243 m_scriptState->isolate()); | 245 m_scriptState->isolate()); |
246 | |
247 ExecutionContext* executionContext = m_scriptState->getExecutionContext( ); | |
dominicc (has gone to gerrit)
2016/07/22 07:34:08
Could you move this line closer to where it is use
| |
248 v8::Local<v8::Function> function = constructor().As<v8::Function>(); | |
249 ErrorEvent* event = ErrorEvent::create( | |
250 "custom element constructors must call super() first and must" | |
251 "not return a different object", | |
252 SourceLocation::fromFunction(function), | |
253 &m_scriptState->world()); | |
254 v8::Local<v8::Value> data = tryCatch.Exception(); | |
dominicc (has gone to gerrit)
2016/07/22 07:34:08
I don't think "data" is a very descriptive name. M
| |
255 | |
256 V8ErrorHandler::storeExceptionOnErrorEventWrapper(m_scriptState.get(), e vent, data, m_scriptState->context()->Global()); | |
257 executionContext->reportException(event, NotSharableCrossOrigin); | |
258 | |
244 return false; | 259 return false; |
245 } | 260 } |
246 | 261 |
247 return true; | 262 return true; |
248 } | 263 } |
249 | 264 |
250 Element* ScriptCustomElementDefinition::runConstructor() | 265 Element* ScriptCustomElementDefinition::runConstructor() |
251 { | 266 { |
252 v8::Isolate* isolate = m_scriptState->isolate(); | 267 v8::Isolate* isolate = m_scriptState->isolate(); |
253 DCHECK(ScriptState::current(isolate) == m_scriptState); | 268 DCHECK(ScriptState::current(isolate) == m_scriptState); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 v8String(isolate, name.localName()), | 362 v8String(isolate, name.localName()), |
348 v8StringOrNull(isolate, oldValue), | 363 v8StringOrNull(isolate, oldValue), |
349 v8StringOrNull(isolate, newValue), | 364 v8StringOrNull(isolate, newValue), |
350 v8String(isolate, name.namespaceURI()), | 365 v8String(isolate, name.namespaceURI()), |
351 }; | 366 }; |
352 runCallback(m_attributeChangedCallback.newLocal(isolate), element, | 367 runCallback(m_attributeChangedCallback.newLocal(isolate), element, |
353 argc, argv); | 368 argc, argv); |
354 } | 369 } |
355 | 370 |
356 } // namespace blink | 371 } // namespace blink |
OLD | NEW |