OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "bindings/core/v8/ErrorEventDispatcher.h" | |
6 | |
7 #include "bindings/core/v8/ScriptController.h" | |
8 #include "bindings/core/v8/SourceLocation.h" | |
9 #include "bindings/core/v8/V8DOMWrapper.h" | |
10 #include "bindings/core/v8/V8ErrorHandler.h" | |
11 #include "core/events/ErrorEvent.h" | |
12 #include "platform/EventDispatchForbiddenScope.h" | |
13 | |
14 namespace blink { | |
15 | |
16 // static | |
17 AccessControlStatus ErrorEventDispatcher::accessControlStatusFromScriptOriginOpt ions( | |
haraken
2016/08/19 01:51:08
I'd inline this function into dispatchErrorEvent()
| |
18 const v8::ScriptOriginOptions& scriptOriginOptions) | |
19 { | |
20 if (scriptOriginOptions.IsOpaque()) | |
21 return OpaqueResource; | |
22 if (scriptOriginOptions.IsSharedCrossOrigin()) | |
23 return SharableCrossOrigin; | |
24 return NotSharableCrossOrigin; | |
25 } | |
26 | |
27 // Custom elements validates return values from JS and may throw. When it does | |
28 // so in non-JS context such as parser, the exceptions can't be thrown to V8. | |
29 // dispatchErrorEvent() dispatches such errors and report to console. | |
haraken
2016/08/19 01:51:08
I'd remove custom-event specific comments from thi
| |
30 // static | |
31 void ErrorEventDispatcher::dispatchErrorEvent(ScriptState* scriptState, | |
32 v8::Local<v8::Value> exception, | |
33 const String& eventMessage, | |
34 std::unique_ptr<SourceLocation> location, | |
35 const v8::ScriptOriginOptions& scriptOriginOptions) | |
36 { | |
37 // Report an exception: | |
38 // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-excepti on | |
39 ErrorEvent* event = ErrorEvent::create(eventMessage, std::move(location), | |
40 &scriptState->world()); | |
41 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, | |
42 exception, scriptState->context()->Global()); | |
43 scriptState->getExecutionContext()->reportException(event, | |
44 accessControlStatusFromScriptOriginOptions(scriptOriginOptions)); | |
45 } | |
46 | |
47 // static | |
48 void ErrorEventDispatcher::dispatchErrorEvent(ScriptState* scriptState, | |
haraken
2016/08/19 01:51:08
Can we remove this helper function and inline the
| |
49 v8::Local<v8::Value> exception, | |
50 const String& message, | |
51 v8::Local<v8::Function> function) | |
52 { | |
53 // Since it's C++ that validates the return value, and the caller is not JS, | |
54 // use the SourceLocation of the function that returned the invalid value. | |
55 dispatchErrorEvent(scriptState, exception, message, | |
56 SourceLocation::fromFunction(function), | |
57 function->GetScriptOrigin().Options()); | |
58 } | |
59 | |
60 // static | |
61 void ErrorEventDispatcher::dispatchErrorEvent(ScriptState* scriptState, | |
haraken
2016/08/19 01:51:08
Ditto. I'd move this function to ScriptCustomEleme
| |
62 ExceptionState& exceptionState, | |
63 v8::Local<v8::Function> function) | |
64 { | |
65 DCHECK(exceptionState.hadException()); | |
66 v8::Local<v8::Value> exception = exceptionState.getException(); | |
67 const String& message = exceptionState.message(); | |
68 if (!message.isEmpty()) { | |
haraken
2016/08/19 01:51:08
This check still looks very hacky. Is there any be
kojii
2016/08/19 03:20:39
It has an empty SourceLocation and ScritOrigin, wh
haraken
2016/08/19 05:28:56
Isn't it an expected behavior? i.e., it makes sens
dominicc (has gone to gerrit)
2016/08/19 06:41:59
Noooo, I think it is way better if we provide the
| |
69 // The exception was created in C++ after returned from JS. | |
70 // It does not have proper SourceLocation nor ScriptOrigin. | |
71 dispatchErrorEvent(scriptState, exception, message, function); | |
72 } else { | |
73 // The exception was thrown in JavaScript, caught, and set to | |
74 // ExceptionState::rethrowV8Exception(). It can then only be thrown | |
75 // to pending exceptions, that does not go to messageHandler. | |
76 v8::Isolate* isolate = scriptState->isolate(); | |
77 v8::Local<v8::Message> message = v8::Exception::CreateMessage( | |
78 isolate, exception); | |
79 dispatchErrorEvent(scriptState, exception, | |
80 toCoreStringWithNullCheck(message->Get()), | |
81 SourceLocation::fromMessage(isolate, message, | |
82 scriptState->getExecutionContext()), | |
83 message->GetScriptOrigin().Options()); | |
84 } | |
85 exceptionState.clearException(); | |
86 } | |
87 | |
88 } // namespace blink | |
OLD | NEW |