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

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

Issue 2244203002: Fix "report the exception" in Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: yukishiino review 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
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
index 6c7b1e3de4e39b0513efb14349dddf12a81ff0b4..58c6c6c10c2943f9f8b90482441f83ea1b7e159d 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
@@ -189,6 +189,69 @@ HTMLElement* ScriptCustomElementDefinition::createElementSync(
return toHTMLElement(element);
}
+static AccessControlStatus accessControlStatusFromScriptOriginOptions(
+ const v8::ScriptOriginOptions& scriptOriginOptions)
+{
+ if (scriptOriginOptions.IsOpaque())
+ return OpaqueResource;
+ if (scriptOriginOptions.IsSharedCrossOrigin())
+ return SharableCrossOrigin;
+ return NotSharableCrossOrigin;
haraken 2016/08/18 09:03:02 Can you create a helper function and share the cod
+}
+
+static void reportException(ScriptState* scriptState,
haraken 2016/08/18 09:03:03 Would you move this function to V8ThrowException?
Yuki 2016/08/18 09:34:26 I opposed putting this function in V8ThrowExceptio
+ 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));
+}
+
+static void reportException(ScriptState* scriptState,
+ v8::Local<v8::Value> exception,
+ const String& message,
+ v8::Local<v8::Function> function)
+{
+ reportException(scriptState, exception, message,
+ SourceLocation::fromFunction(function),
+ function->GetScriptOrigin().Options());
+}
+
+static void reportException(ScriptState* scriptState,
+ ExceptionState& exceptionState,
+ v8::Local<v8::Function> function)
+{
+ DCHECK(exceptionState.hadException());
+ v8::Local<v8::Value> exception = exceptionState.getException();
+ const String& message = exceptionState.message();
+ if (!message.isEmpty()) {
haraken 2016/08/18 09:03:02 It looks nasty to have this branch. Wouldn't it b
kojii 2016/08/18 10:15:14 There's no place to report, this is similar to unh
+ // 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, message, function);
+ } else {
+ // The exception was thrown in JavaScript, caught, and set by
+ // rethrowV8Exception(). It has SourceLocation and ScriptOrigin.
+ 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());
+ }
+ exceptionState.clearException();
+}
+
HTMLElement* ScriptCustomElementDefinition::createElementSync(
Document& document, const QualifiedName& tagName)
{
@@ -202,16 +265,14 @@ HTMLElement* ScriptCustomElementDefinition::createElementSync(
"CustomElement", constructor(), isolate);
HTMLElement* element = createElementSync(document, tagName, exceptionState);
- if (exceptionState.hadException() || !element) {
+ if (exceptionState.hadException()) {
+ DCHECK(!element);
// 7. If this step throws an exception, then report the exception, ...
- {
- v8::TryCatch tryCatch(isolate);
- tryCatch.SetVerbose(true);
- exceptionState.throwIfNeeded();
- }
-
+ reportException(m_scriptState.get(), exceptionState,
+ constructor().As<v8::Function>());
haraken 2016/08/18 09:03:02 Why do you pass in constructor()? Here you're hand
kojii 2016/08/18 10:15:14 This code path comes from the document parser, whe
return CustomElement::createFailedElement(document, tagName);
}
+ DCHECK(element);
return element;
}
@@ -238,12 +299,12 @@ bool ScriptCustomElementDefinition::runConstructor(Element* element)
if (result != element) {
const String& message = "custom element constructors must call super() first and must "
"not return a different object";
- std::unique_ptr<SourceLocation> location = SourceLocation::fromFunction(constructor().As<v8::Function>());
v8::Local<v8::Value> exception = V8ThrowException::createDOMException(
m_scriptState->isolate(),
InvalidStateError,
message);
- fireErrorEvent(m_scriptState.get(), message, exception, std::move(location));
+ reportException(m_scriptState.get(), exception, message,
+ constructor().As<v8::Function>());
return false;
}
@@ -268,14 +329,6 @@ Element* ScriptCustomElementDefinition::runConstructor()
return V8Element::toImplWithTypeCheck(isolate, result);
}
-void ScriptCustomElementDefinition::fireErrorEvent(ScriptState* scriptState, const String& message, v8::Local<v8::Value> exception, std::unique_ptr<SourceLocation> location)
-{
- ErrorEvent* event = ErrorEvent::create(message, std::move(location), &scriptState->world());
- V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, exception, scriptState->context()->Global());
- ExecutionContext* executionContext = scriptState->getExecutionContext();
- executionContext->reportException(event, NotSharableCrossOrigin);
-}
-
v8::Local<v8::Object> ScriptCustomElementDefinition::constructor() const
{
DCHECK(!m_constructor.isEmpty());
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698