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.
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
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)
window.onerror: "Uncaught Error: Error in main world inline script." at window-onerror-isolatedworld-01.html (Line: 49, Column: 13)
Stack Trace:
Error: Error in main world inline script.
at exceptions window-onerror-isolatedworld-01.html:52:19
at window-onerror-isolatedworld-01.html:58:9
at exceptions window-onerror-isolatedworld-01.html:49:19
at window-onerror-isolatedworld-01.html:55:9
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:
Error: Error in main world inline script.
at exceptions window-onerror-isolatedworld-01.html:52:19
at window-onerror-isolatedworld-01.html:58: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.
at exceptions window-onerror-isolatedworld-01.html:49:19
at window-onerror-isolatedworld-01.html:55:9
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 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 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:
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.
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:
Error: Error in main world load handler.
at window-onerror-isolatedworld-01.html:49: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.
at window-onerror-isolatedworld-01.html:46:23
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 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.
window.onerror: "Uncaught Error: Error in main world setTimeout callback." at window-onerror-isolatedworld-01.html (Line: 47, Column: 21)
window.onerror: "Uncaught Error: Error in main world setTimeout callback." at window-onerror-isolatedworld-01.html (Line: 44, Column: 21)
Stack Trace:
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.
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:
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 eventCurrentTarget is window
......@@ -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
TEST COMPLETE
......
......@@ -18,8 +18,7 @@
if (onerrorsHandled > 3)
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 === 9)
if (errorsHandled === 6)
finishJSTest();
}
......@@ -27,12 +26,10 @@
function errorEventCallback(errorsHandled) {
errorEventsHandled++;
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.");
}
// FIXME: This should be 6 once we correctly handle 'error' event dispatch for worlds: crbug.com/225513
if (errorsHandled === 9)
if (errorsHandled === 6)
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.
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!
isolated world error event listener: Uncaught Error: Error in isolated world inline script. at window-onerror-isolatedworld-02.html:, Line: 41
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
Error object present!
isolated world error event listener: Uncaught Error: Error in isolated world load handler. at window-onerror-isolatedworld-02.html:, Line: 38
Error object present!
isolated world error event listener: Uncaught Error: Error in main world load handler. at window-onerror-isolatedworld-02.html:, Line: 27
No error object present!
isolated world window.onerror: Uncaught Error: Error in isolated world setTimeout callback. at window-onerror-isolatedworld-02.html, Line: 36, Column: 21
Error object present!
......@@ -53,9 +53,6 @@ v8::Local<v8::Value> V8ErrorHandler::CallListenerFunction(
}
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();
ExecutionContext* execution_context = ToExecutionContext(context);
v8::Local<v8::Object> listener = GetListenerObjectInternal(execution_context);
......
......@@ -82,6 +82,10 @@ const AtomicString& ErrorEvent::InterfaceName() const {
return EventNames::ErrorEvent;
}
bool ErrorEvent::CanBeDispatchedInWorld(const DOMWrapperWorld& world) const {
return !world_ || world_ == &world;
}
ScriptValue ErrorEvent::error(ScriptState* script_state) const {
// Don't return |m_error| when we are in the different worlds to avoid
// leaking a V8 value.
......
......@@ -88,6 +88,7 @@ class ErrorEvent final : public Event {
SourceLocation* Location() const { return location_.get(); }
const AtomicString& InterfaceName() const override;
bool CanBeDispatchedInWorld(const DOMWrapperWorld&) const override;
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