Index: third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp b/third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp |
index 2a5afedeebc50eb0294721cc4537b687f68e0cea..e7e57626e1a7fb7310b05d22c9602ab3739d64bd 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp |
@@ -33,7 +33,9 @@ |
namespace blink { |
-static void domExceptionStackGetter(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
+namespace { |
+ |
+void domExceptionStackGetter(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
v8::Isolate* isolate = info.GetIsolate(); |
v8::Local<v8::Value> value; |
@@ -41,123 +43,65 @@ static void domExceptionStackGetter(v8::Local<v8::Name> name, const v8::Property |
v8SetReturnValue(info, value); |
} |
-static void domExceptionStackSetter(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) |
+void domExceptionStackSetter(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) |
{ |
v8::Maybe<bool> unused = info.Data().As<v8::Object>()->Set(info.GetIsolate()->GetCurrentContext(), v8AtomicString(info.GetIsolate(), "stack"), value); |
ALLOW_UNUSED_LOCAL(unused); |
} |
-v8::Local<v8::Value> V8ThrowException::createDOMException(v8::Isolate* isolate, int ec, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Local<v8::Object>& creationContext) |
-{ |
- if (ec <= 0 || isolate->IsExecutionTerminating()) |
- return v8Undefined(); |
- |
- ASSERT(ec == SecurityError || unsanitizedMessage.isEmpty()); |
- |
- if (ec == V8GeneralError) |
- return V8ThrowException::createGeneralError(isolate, sanitizedMessage); |
- if (ec == V8TypeError) |
- return V8ThrowException::createTypeError(isolate, sanitizedMessage); |
- if (ec == V8RangeError) |
- return V8ThrowException::createRangeError(isolate, sanitizedMessage); |
- if (ec == V8SyntaxError) |
- return V8ThrowException::createSyntaxError(isolate, sanitizedMessage); |
- if (ec == V8ReferenceError) |
- return V8ThrowException::createReferenceError(isolate, sanitizedMessage); |
- |
- v8::Local<v8::Object> sanitizedCreationContext = creationContext; |
- |
- // FIXME: Is the current context always the right choice? |
- ScriptState* scriptState = ScriptState::from(creationContext->CreationContext()); |
- Frame* frame = toFrameIfNotDetached(scriptState->context()); |
- if (!frame || !BindingSecurity::shouldAllowAccessToFrame(isolate, currentDOMWindow(isolate), frame, DoNotReportSecurityError)) { |
- scriptState = ScriptState::current(isolate); |
- sanitizedCreationContext = scriptState->context()->Global(); |
- } |
- |
- v8::TryCatch tryCatch(isolate); |
- |
- DOMException* domException = DOMException::create(ec, sanitizedMessage, unsanitizedMessage); |
- v8::Local<v8::Value> exception = toV8(domException, sanitizedCreationContext, isolate); |
+} // namespace |
- if (tryCatch.HasCaught()) { |
- ASSERT(exception.IsEmpty()); |
- return tryCatch.Exception(); |
+v8::Local<v8::Value> V8ThrowException::createDOMException(v8::Isolate* isolate, ExceptionCode exceptionCode, const String& sanitizedMessage, const String& unsanitizedMessage) |
+{ |
+ DCHECK_GT(exceptionCode, 0); |
+ DCHECK(exceptionCode == SecurityError || unsanitizedMessage.isNull()); |
+ |
+ if (isolate->IsExecutionTerminating()) |
+ return v8::Local<v8::Value>(); |
+ |
+ switch (exceptionCode) { |
+ case V8GeneralError: |
+ return createGeneralError(isolate, sanitizedMessage); |
+ case V8TypeError: |
+ return createTypeError(isolate, sanitizedMessage); |
+ case V8RangeError: |
+ return createRangeError(isolate, sanitizedMessage); |
+ case V8SyntaxError: |
+ return createSyntaxError(isolate, sanitizedMessage); |
+ case V8ReferenceError: |
+ return createReferenceError(isolate, sanitizedMessage); |
} |
- ASSERT(!exception.IsEmpty()); |
- // Attach an Error object to the DOMException. This is then lazily used to get the stack value. |
+ DOMException* domException = DOMException::create(exceptionCode, sanitizedMessage, unsanitizedMessage); |
+ v8::Local<v8::Object> exceptionObj = toV8(domException, isolate->GetCurrentContext()->Global(), isolate).As<v8::Object>(); |
+ // Attach an Error object to the DOMException. This is then lazily used to |
+ // get the stack value. |
v8::Local<v8::Value> error = v8::Exception::Error(v8String(isolate, domException->message())); |
- ASSERT(!error.IsEmpty()); |
- v8::Local<v8::Object> exceptionObject = exception.As<v8::Object>(); |
- exceptionObject->SetAccessor(isolate->GetCurrentContext(), v8AtomicString(isolate, "stack"), domExceptionStackGetter, domExceptionStackSetter, error).ToChecked(); |
+ exceptionObj->SetAccessor(isolate->GetCurrentContext(), v8AtomicString(isolate, "stack"), domExceptionStackGetter, domExceptionStackSetter, error).ToChecked(); |
auto privateError = V8PrivateProperty::getDOMExceptionError(isolate); |
- privateError.set(scriptState->context(), exceptionObject, error); |
- |
- return exception; |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::createGeneralError(v8::Isolate* isolate, const String& message) |
-{ |
- return v8::Exception::Error(v8String(isolate, message.isNull() ? "Error" : message)); |
-} |
+ privateError.set(isolate->GetCurrentContext(), exceptionObj, error); |
-v8::Local<v8::Value> V8ThrowException::throwGeneralError(v8::Isolate* isolate, const String& message) |
-{ |
- v8::Local<v8::Value> exception = V8ThrowException::createGeneralError(isolate, message); |
- return V8ThrowException::throwException(exception, isolate); |
+ return exceptionObj; |
} |
-v8::Local<v8::Value> V8ThrowException::createTypeError(v8::Isolate* isolate, const String& message) |
-{ |
- return v8::Exception::TypeError(v8String(isolate, message.isNull() ? "Type error" : message)); |
+#define DEFINE_CREATE_AND_THROW_ERROR_FUNC(blinkErrorType, v8ErrorType, defaultMessage) \ |
+v8::Local<v8::Value> V8ThrowException::create##blinkErrorType(v8::Isolate* isolate, const String& message) \ |
+{ \ |
+ return v8::Exception::v8ErrorType(v8String(isolate, message.isNull() ? defaultMessage : message)); \ |
+} \ |
+\ |
+void V8ThrowException::throw##blinkErrorType(v8::Isolate* isolate, const String& message) \ |
+{ \ |
+ throwException(isolate, create##blinkErrorType(isolate, message)); \ |
} |
-v8::Local<v8::Value> V8ThrowException::throwTypeError(v8::Isolate* isolate, const String& message) |
-{ |
- v8::Local<v8::Value> exception = V8ThrowException::createTypeError(isolate, message); |
- return V8ThrowException::throwException(exception, isolate); |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::createRangeError(v8::Isolate* isolate, const String& message) |
-{ |
- return v8::Exception::RangeError(v8String(isolate, message.isNull() ? "Range error" : message)); |
-} |
+DEFINE_CREATE_AND_THROW_ERROR_FUNC(GeneralError, Error, "Error") |
+DEFINE_CREATE_AND_THROW_ERROR_FUNC(RangeError, RangeError, "Range error") |
+DEFINE_CREATE_AND_THROW_ERROR_FUNC(ReferenceError, ReferenceError, "Reference error") |
+DEFINE_CREATE_AND_THROW_ERROR_FUNC(SyntaxError, SyntaxError, "Syntax error") |
+DEFINE_CREATE_AND_THROW_ERROR_FUNC(TypeError, TypeError, "Type error") |
-v8::Local<v8::Value> V8ThrowException::throwRangeError(v8::Isolate* isolate, const String& message) |
-{ |
- v8::Local<v8::Value> exception = V8ThrowException::createRangeError(isolate, message); |
- return V8ThrowException::throwException(exception, isolate); |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::createSyntaxError(v8::Isolate* isolate, const String& message) |
-{ |
- return v8::Exception::SyntaxError(v8String(isolate, message.isNull() ? "Syntax error" : message)); |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::throwSyntaxError(v8::Isolate* isolate, const String& message) |
-{ |
- v8::Local<v8::Value> exception = V8ThrowException::createSyntaxError(isolate, message); |
- return V8ThrowException::throwException(exception, isolate); |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::createReferenceError(v8::Isolate* isolate, const String& message) |
-{ |
- return v8::Exception::ReferenceError(v8String(isolate, message.isNull() ? "Reference error" : message)); |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::throwReferenceError(v8::Isolate* isolate, const String& message) |
-{ |
- v8::Local<v8::Value> exception = V8ThrowException::createReferenceError(isolate, message); |
- return V8ThrowException::throwException(exception, isolate); |
-} |
- |
-v8::Local<v8::Value> V8ThrowException::throwException(v8::Local<v8::Value> exception, v8::Isolate* isolate) |
-{ |
- if (!isolate->IsExecutionTerminating()) |
- isolate->ThrowException(exception); |
- return v8::Undefined(isolate); |
-} |
+#undef DEFINE_CREATE_AND_THROW_ERROR_FUNC |
} // namespace blink |