OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "bindings/core/v8/V8ThrowException.h" | 25 #include "bindings/core/v8/V8ThrowException.h" |
26 | 26 |
27 #include "bindings/core/v8/BindingSecurity.h" | 27 #include "bindings/core/v8/BindingSecurity.h" |
28 #include "bindings/core/v8/V8Binding.h" | 28 #include "bindings/core/v8/V8Binding.h" |
29 #include "bindings/core/v8/V8DOMException.h" | 29 #include "bindings/core/v8/V8DOMException.h" |
| 30 #include "bindings/core/v8/V8ErrorHandler.h" |
30 #include "bindings/core/v8/V8PrivateProperty.h" | 31 #include "bindings/core/v8/V8PrivateProperty.h" |
31 #include "core/dom/DOMException.h" | 32 #include "core/dom/DOMException.h" |
32 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 34 #include "core/events/ErrorEvent.h" |
33 | 35 |
34 namespace blink { | 36 namespace blink { |
35 | 37 |
36 namespace { | 38 namespace { |
37 | 39 |
38 void domExceptionStackGetter(v8::Local<v8::Name> name, const v8::PropertyCallbac
kInfo<v8::Value>& info) | 40 void domExceptionStackGetter(v8::Local<v8::Name> name, const v8::PropertyCallbac
kInfo<v8::Value>& info) |
39 { | 41 { |
40 v8::Isolate* isolate = info.GetIsolate(); | 42 v8::Isolate* isolate = info.GetIsolate(); |
41 v8::Local<v8::Value> value; | 43 v8::Local<v8::Value> value; |
42 if (info.Data().As<v8::Object>()->Get(isolate->GetCurrentContext(), v8Atomic
String(isolate, "stack")).ToLocal(&value)) | 44 if (info.Data().As<v8::Object>()->Get(isolate->GetCurrentContext(), v8Atomic
String(isolate, "stack")).ToLocal(&value)) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 99 } |
98 | 100 |
99 DEFINE_CREATE_AND_THROW_ERROR_FUNC(Error, Error, "Error") | 101 DEFINE_CREATE_AND_THROW_ERROR_FUNC(Error, Error, "Error") |
100 DEFINE_CREATE_AND_THROW_ERROR_FUNC(RangeError, RangeError, "Range error") | 102 DEFINE_CREATE_AND_THROW_ERROR_FUNC(RangeError, RangeError, "Range error") |
101 DEFINE_CREATE_AND_THROW_ERROR_FUNC(ReferenceError, ReferenceError, "Reference er
ror") | 103 DEFINE_CREATE_AND_THROW_ERROR_FUNC(ReferenceError, ReferenceError, "Reference er
ror") |
102 DEFINE_CREATE_AND_THROW_ERROR_FUNC(SyntaxError, SyntaxError, "Syntax error") | 104 DEFINE_CREATE_AND_THROW_ERROR_FUNC(SyntaxError, SyntaxError, "Syntax error") |
103 DEFINE_CREATE_AND_THROW_ERROR_FUNC(TypeError, TypeError, "Type error") | 105 DEFINE_CREATE_AND_THROW_ERROR_FUNC(TypeError, TypeError, "Type error") |
104 | 106 |
105 #undef DEFINE_CREATE_AND_THROW_ERROR_FUNC | 107 #undef DEFINE_CREATE_AND_THROW_ERROR_FUNC |
106 | 108 |
| 109 void V8ThrowException::reportException(ScriptState* scriptState, |
| 110 v8::Local<v8::Value> exception, |
| 111 const String& eventMessage, v8::Local<v8::Function> function) |
| 112 { |
| 113 if (!eventMessage.isEmpty()) { |
| 114 // The exception was created in C++ but was not thrown in JavaScript. |
| 115 // It does not have proper SourceLocation nor ScriptOrigin, so use the |
| 116 // given information. |
| 117 reportException(scriptState, exception, eventMessage, |
| 118 SourceLocation::fromFunction(function), |
| 119 function->GetScriptOrigin().Options()); |
| 120 } else { |
| 121 v8::Isolate* isolate = scriptState->isolate(); |
| 122 v8::Local<v8::Message> message = v8::Exception::CreateMessage(isolate, |
| 123 exception); |
| 124 reportException(scriptState, exception, |
| 125 toCoreStringWithNullCheck(message->Get()), |
| 126 SourceLocation::fromMessage(isolate, message, |
| 127 scriptState->getExecutionContext()), |
| 128 message->GetScriptOrigin().Options()); |
| 129 } |
| 130 } |
| 131 |
| 132 static AccessControlStatus accessControlStatusFromScriptOriginOptions( |
| 133 const v8::ScriptOriginOptions& scriptOriginOptions) |
| 134 { |
| 135 if (scriptOriginOptions.IsOpaque()) |
| 136 return OpaqueResource; |
| 137 if (scriptOriginOptions.IsSharedCrossOrigin()) |
| 138 return SharableCrossOrigin; |
| 139 return NotSharableCrossOrigin; |
| 140 } |
| 141 |
| 142 void V8ThrowException::reportException(ScriptState* scriptState, |
| 143 v8::Local<v8::Value> exception, |
| 144 const String& eventMessage, |
| 145 std::unique_ptr<SourceLocation> location, |
| 146 const v8::ScriptOriginOptions& scriptOriginOptions) |
| 147 { |
| 148 // Report an exception: |
| 149 // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-excepti
on |
| 150 ErrorEvent* event = ErrorEvent::create(eventMessage, std::move(location), |
| 151 &scriptState->world()); |
| 152 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, |
| 153 exception, scriptState->context()->Global()); |
| 154 scriptState->getExecutionContext()->reportException(event, |
| 155 accessControlStatusFromScriptOriginOptions(scriptOriginOptions)); |
| 156 } |
| 157 |
107 } // namespace blink | 158 } // namespace blink |
OLD | NEW |