Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp

Issue 2244203002: Fix "report the exception" in Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 36cb08e3bfed8d17a47cc9fdc70fe81e0c556830..7e189482c0fd23f698eb6162a7692f86b6d3bc5e 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp
@@ -27,9 +27,11 @@
#include "bindings/core/v8/BindingSecurity.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMException.h"
+#include "bindings/core/v8/V8ErrorHandler.h"
#include "bindings/core/v8/V8PrivateProperty.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
+#include "core/events/ErrorEvent.h"
namespace blink {
@@ -104,4 +106,53 @@ DEFINE_CREATE_AND_THROW_ERROR_FUNC(TypeError, TypeError, "Type error")
#undef DEFINE_CREATE_AND_THROW_ERROR_FUNC
+void V8ThrowException::reportException(ScriptState* scriptState,
+ v8::Local<v8::Value> exception,
+ const String& eventMessage, v8::Local<v8::Function> function)
+{
+ if (!eventMessage.isEmpty()) {
+ // The exception was created in C++ but was not thrown in JavaScript.
+ // It does not have proper SourceLocation nor ScriptOrigin, so use the
+ // given information.
+ reportException(scriptState, exception, eventMessage,
+ SourceLocation::fromFunction(function),
+ function->GetScriptOrigin().Options());
+ } else {
+ v8::Isolate* isolate = scriptState->isolate();
+ v8::Local<v8::Message> message = v8::Exception::CreateMessage(isolate,
+ exception);
+ reportException(scriptState, exception,
+ toCoreStringWithNullCheck(message->Get()),
+ SourceLocation::fromMessage(isolate, message,
+ scriptState->getExecutionContext()),
+ message->GetScriptOrigin().Options());
+ }
+}
+
+static AccessControlStatus accessControlStatusFromScriptOriginOptions(
+ const v8::ScriptOriginOptions& scriptOriginOptions)
+{
+ if (scriptOriginOptions.IsOpaque())
+ return OpaqueResource;
+ if (scriptOriginOptions.IsSharedCrossOrigin())
+ return SharableCrossOrigin;
+ return NotSharableCrossOrigin;
+}
+
+void V8ThrowException::reportException(ScriptState* scriptState,
+ v8::Local<v8::Value> exception,
+ const String& eventMessage,
+ std::unique_ptr<SourceLocation> location,
+ const v8::ScriptOriginOptions& scriptOriginOptions)
+{
+ // Report an exception:
+ // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception
+ ErrorEvent* event = ErrorEvent::create(eventMessage, std::move(location),
+ &scriptState->world());
+ V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event,
+ exception, scriptState->context()->Global());
+ scriptState->getExecutionContext()->reportException(event,
+ accessControlStatusFromScriptOriginOptions(scriptOriginOptions));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698