Commit 282a05f9 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Stop dispatching a error event for an event listener in a foreign world

In addition to error handler (i.e., self.onerror), stop dispatching a
error event for an event listener in a foreign world.

Bur: 225513
Change-Id: I757dcfbefdd6b31711c29fe4f91ce7d7e764e992
Reviewed-on: https://chromium-review.googlesource.com/1187844Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585746}
parent 0168a172
CONSOLE ERROR: line 11: Uncaught Error: Error in isolated world inline script.
CONSOLE ERROR: line 8: Uncaught Error: Error in isolated world load handler.
CONSOLE ERROR: line 6: Uncaught Error: Error in isolated world setTimeout callback.
Test that window.onerror and "error" event listeners from main world are not invoked for uncaught exceptions in scripts running in isolate worlds, but only for exceptions in the main world. Test that window.onerror and "error" event listeners from main world are not invoked for uncaught exceptions in scripts running in isolate worlds, but only for exceptions in the main world.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Handling 'error' event (phase 2): "Uncaught Error: Error in isolated world inline script." at window-onerror-isolatedworld-01.html:11 window.onerror: "Uncaught Error: Error in main world inline script." at window-onerror-isolatedworld-01.html (Line: 49, Column: 13)
No stack trace.
PASS eventPassedToTheErrorListener is window.event
PASS eventCurrentTarget is window
Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.
window.onerror: "Uncaught Error: Error in main world inline script." at window-onerror-isolatedworld-01.html (Line: 52, Column: 13)
Stack Trace: Stack Trace:
Error: Error in main world inline script. Error: Error in main world inline script.
at exceptions window-onerror-isolatedworld-01.html:52:19 at exceptions window-onerror-isolatedworld-01.html:49:19
at window-onerror-isolatedworld-01.html:58:9 at window-onerror-isolatedworld-01.html:55:9
Returning 'true': the error should not be reported in the console as an unhandled exception. Returning 'true': the error should not be reported in the console as an unhandled exception.
Handling 'error' event (phase 2): "Uncaught Error: Error in main world inline script." at window-onerror-isolatedworld-01.html:52 Handling 'error' event (phase 2): "Uncaught Error: Error in main world inline script." at window-onerror-isolatedworld-01.html:49
Stack Trace: Stack Trace:
Error: Error in main world inline script. Error: Error in main world inline script.
at exceptions window-onerror-isolatedworld-01.html:52:19 at exceptions window-onerror-isolatedworld-01.html:49:19
at window-onerror-isolatedworld-01.html:58:9 at window-onerror-isolatedworld-01.html:55:9
PASS eventPassedToTheErrorListener is window.event
PASS eventCurrentTarget is window
Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.
Handling 'error' event (phase 2): "Uncaught Error: Error in isolated world load handler." at window-onerror-isolatedworld-01.html:8
No stack trace.
PASS eventPassedToTheErrorListener is window.event PASS eventPassedToTheErrorListener is window.event
PASS eventCurrentTarget is window PASS eventCurrentTarget is window
Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception. Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.
window.onerror: "Uncaught Error: Error in main world load handler." at window-onerror-isolatedworld-01.html (Line: 49, Column: 17) window.onerror: "Uncaught Error: Error in main world load handler." at window-onerror-isolatedworld-01.html (Line: 46, Column: 17)
Stack Trace: Stack Trace:
Error: Error in main world load handler. Error: Error in main world load handler.
at window-onerror-isolatedworld-01.html:49:23 at window-onerror-isolatedworld-01.html:46:23
Returning 'true': the error should not be reported in the console as an unhandled exception. Returning 'true': the error should not be reported in the console as an unhandled exception.
Handling 'error' event (phase 2): "Uncaught Error: Error in main world load handler." at window-onerror-isolatedworld-01.html:49 Handling 'error' event (phase 2): "Uncaught Error: Error in main world load handler." at window-onerror-isolatedworld-01.html:46
Stack Trace: Stack Trace:
Error: Error in main world load handler. Error: Error in main world load handler.
at window-onerror-isolatedworld-01.html:49:23 at window-onerror-isolatedworld-01.html:46:23
PASS eventPassedToTheErrorListener is window.event
PASS eventCurrentTarget is window
Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.
FAIL Only main-world exceptions should be caught by ErrorEvent listeners.
Handling 'error' event (phase 2): "Uncaught Error: Error in isolated world setTimeout callback." at window-onerror-isolatedworld-01.html:6
No stack trace.
PASS eventPassedToTheErrorListener is window.event PASS eventPassedToTheErrorListener is window.event
PASS eventCurrentTarget is window PASS eventCurrentTarget is window
Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception. Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.
FAIL Only main-world exceptions should be caught by ErrorEvent listeners. window.onerror: "Uncaught Error: Error in main world setTimeout callback." at window-onerror-isolatedworld-01.html (Line: 44, Column: 21)
window.onerror: "Uncaught Error: Error in main world setTimeout callback." at window-onerror-isolatedworld-01.html (Line: 47, Column: 21)
Stack Trace: Stack Trace:
Error: Error in main world setTimeout callback. Error: Error in main world setTimeout callback.
at window-onerror-isolatedworld-01.html:47:27 at window-onerror-isolatedworld-01.html:44:27
Returning 'true': the error should not be reported in the console as an unhandled exception. Returning 'true': the error should not be reported in the console as an unhandled exception.
Handling 'error' event (phase 2): "Uncaught Error: Error in main world setTimeout callback." at window-onerror-isolatedworld-01.html:47 Handling 'error' event (phase 2): "Uncaught Error: Error in main world setTimeout callback." at window-onerror-isolatedworld-01.html:44
Stack Trace: Stack Trace:
Error: Error in main world setTimeout callback. Error: Error in main world setTimeout callback.
at window-onerror-isolatedworld-01.html:47:27 at window-onerror-isolatedworld-01.html:44:27
PASS eventPassedToTheErrorListener is window.event PASS eventPassedToTheErrorListener is window.event
PASS eventCurrentTarget is window PASS eventCurrentTarget is window
...@@ -91,7 +68,6 @@ Calling e.preventDefault(): the error should not be reported in the console as a ...@@ -91,7 +68,6 @@ Calling e.preventDefault(): the error should not be reported in the console as a
FAIL Only main-world exceptions should be caught by ErrorEvent listeners.
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
if (onerrorsHandled > 3) if (onerrorsHandled > 3)
testFailed("Only main-world exceptions should be caught by onerror handlers."); testFailed("Only main-world exceptions should be caught by onerror handlers.");
// FIXME: This should be 6 once we correctly handle 'error' event dispatch for worlds: crbug.com/225513 if (errorsHandled === 6)
if (errorsHandled === 9)
finishJSTest(); finishJSTest();
} }
...@@ -27,12 +26,10 @@ ...@@ -27,12 +26,10 @@
function errorEventCallback(errorsHandled) { function errorEventCallback(errorsHandled) {
errorEventsHandled++; errorEventsHandled++;
if (errorEventsHandled > 3) { if (errorEventsHandled > 3) {
// FIXME: This currently fails. We need to correctly handle 'error' event dispatch for worlds: crbug.com/225513
testFailed("Only main-world exceptions should be caught by ErrorEvent listeners."); testFailed("Only main-world exceptions should be caught by ErrorEvent listeners.");
} }
// FIXME: This should be 6 once we correctly handle 'error' event dispatch for worlds: crbug.com/225513 if (errorsHandled === 6)
if (errorsHandled === 9)
finishJSTest(); finishJSTest();
} }
......
CONSOLE ERROR: line 30: Uncaught Error: Error in main world inline script.
CONSOLE ERROR: line 27: Uncaught Error: Error in main world load handler.
Test that window.onerror and "error" event listeners from isolated world are invoked for uncaught exceptions in scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519. Test that window.onerror and "error" event listeners from isolated world are invoked for uncaught exceptions in scripts running in isolate worlds as well as for exceptions in the main world.Bug 8519.
isolated world window.onerror: Uncaught Error: Error in isolated world inline script. at window-onerror-isolatedworld-02.html, Line: 41, Column: 13 isolated world window.onerror: Uncaught Error: Error in isolated world inline script. at window-onerror-isolatedworld-02.html, Line: 41, Column: 13
Error object present! Error object present!
isolated world error event listener: Uncaught Error: Error in isolated world inline script. at window-onerror-isolatedworld-02.html:, Line: 41 isolated world error event listener: Uncaught Error: Error in isolated world inline script. at window-onerror-isolatedworld-02.html:, Line: 41
Error object present! Error object present!
isolated world error event listener: Uncaught Error: Error in main world inline script. at window-onerror-isolatedworld-02.html:, Line: 30
No error object present!
isolated world window.onerror: Uncaught Error: Error in isolated world load handler. at window-onerror-isolatedworld-02.html, Line: 38, Column: 17 isolated world window.onerror: Uncaught Error: Error in isolated world load handler. at window-onerror-isolatedworld-02.html, Line: 38, Column: 17
Error object present! Error object present!
isolated world error event listener: Uncaught Error: Error in isolated world load handler. at window-onerror-isolatedworld-02.html:, Line: 38 isolated world error event listener: Uncaught Error: Error in isolated world load handler. at window-onerror-isolatedworld-02.html:, Line: 38
Error object present! Error object present!
isolated world error event listener: Uncaught Error: Error in main world load handler. at window-onerror-isolatedworld-02.html:, Line: 27 isolated world window.onerror: Uncaught Error: Error in isolated world setTimeout callback. at window-onerror-isolatedworld-02.html, Line: 36, Column: 21
No error object present! Error object present!
...@@ -53,9 +53,6 @@ v8::Local<v8::Value> V8ErrorHandler::CallListenerFunction( ...@@ -53,9 +53,6 @@ v8::Local<v8::Value> V8ErrorHandler::CallListenerFunction(
} }
ErrorEvent* error_event = static_cast<ErrorEvent*>(event); ErrorEvent* error_event = static_cast<ErrorEvent*>(event);
if (error_event->World() && error_event->World() != &World())
return v8::Null(GetIsolate());
v8::Local<v8::Context> context = script_state->GetContext(); v8::Local<v8::Context> context = script_state->GetContext();
ExecutionContext* execution_context = ToExecutionContext(context); ExecutionContext* execution_context = ToExecutionContext(context);
v8::Local<v8::Object> listener = GetListenerObjectInternal(execution_context); v8::Local<v8::Object> listener = GetListenerObjectInternal(execution_context);
......
...@@ -82,6 +82,10 @@ const AtomicString& ErrorEvent::InterfaceName() const { ...@@ -82,6 +82,10 @@ const AtomicString& ErrorEvent::InterfaceName() const {
return EventNames::ErrorEvent; return EventNames::ErrorEvent;
} }
bool ErrorEvent::CanBeDispatchedInWorld(const DOMWrapperWorld& world) const {
return !world_ || world_ == &world;
}
ScriptValue ErrorEvent::error(ScriptState* script_state) const { ScriptValue ErrorEvent::error(ScriptState* script_state) const {
// Don't return |m_error| when we are in the different worlds to avoid // Don't return |m_error| when we are in the different worlds to avoid
// leaking a V8 value. // leaking a V8 value.
......
...@@ -88,6 +88,7 @@ class ErrorEvent final : public Event { ...@@ -88,6 +88,7 @@ class ErrorEvent final : public Event {
SourceLocation* Location() const { return location_.get(); } SourceLocation* Location() const { return location_.get(); }
const AtomicString& InterfaceName() const override; const AtomicString& InterfaceName() const override;
bool CanBeDispatchedInWorld(const DOMWrapperWorld&) const override;
DOMWrapperWorld* World() const { return world_.get(); } DOMWrapperWorld* World() const { return world_.get(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment