window.onerror should pass the ErrorEvent's 'error' property as the 5th argument...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jun 2016 03:28:10 +0000 (03:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jun 2016 03:28:10 +0000 (03:28 +0000)
commit5727db252acaccfbeda72a81c5ad6029114535c3
tree9b845973a8c381b13f8fe264f5be023a5e7aa383
parent15479a430e58d68bff1e13b177ceefb0021f8293
window.onerror should pass the ErrorEvent's 'error' property as the 5th argument to the event handler
https://bugs.webkit.org/show_bug.cgi?id=55092
<rdar://problem/25731279>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-06-13
Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

* web-platform-tests/html/dom/interfaces-expected.txt:

Source/WebCore:

This includes the actual Error in window.error / ErrorEvent:
https://html.spec.whatwg.org/multipage/webappapis.html#the-errorevent-interface

This is useful for scripts to be able to get an error stack
from uncaught exceptions, by checking the error itself.

Tests: fast/events/window-onerror17.html
       http/tests/security/cross-origin-script-error-event-redirected.html
       http/tests/security/cross-origin-script-error-event.html
       http/tests/security/script-crossorigin-error-event-information.html
       http/tests/security/script-no-crossorigin-error-event-should-be-sanitized.html
       userscripts/window-onerror-for-isolated-world-3.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
Add new custom error event file.

* bindings/js/JSDOMBinding.cpp:
(WebCore::reportException):
Include the JSC::Exception when reporting exceptions, so the error value is available.

* bindings/js/JSErrorEventCustom.cpp:
(WebCore::JSErrorEvent::error):
Sanitized access to the ErrorEvent's error property to prevent leaking objects
across isolated world boundaries. This is like CustomEvent's data property.

* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/js/JSErrorHandler.h:
Include the error object as the 4th argument to the window.onerror event handler.

* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::sanitizeScriptError):
(WebCore::ScriptExecutionContext::reportException):
(WebCore::ScriptExecutionContext::dispatchErrorEvent):
* dom/ScriptExecutionContext.h:
Include the error object in the ErrorEvent constructed when dispatching error events.

* dom/ErrorEvent.cpp:
(WebCore::ErrorEvent::ErrorEvent):
(WebCore::ErrorEvent::sanitizedErrorValue):
(WebCore::ErrorEvent::trySerializeError):
* dom/ErrorEvent.h:
* dom/ErrorEvent.idl:
Include an any "error" property on the ErrorEvent, and allow it in initialization.

* bindings/js/WorkerScriptController.cpp:
(WebCore::WorkerScriptController::evaluate):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):
Within the Worker world, the error is included in the event.
When re-dispatching the error on the world object in the world that spawned the
Worker the event does not include an error object. This matches other browsers
right now, but could be improved to have the same cross world serialization
as isolated worlds have with the error data.

* dom/CustomEvent.h:
Remove unimplemented stale method.

LayoutTests:

* platform/wk2/TestExpectations:
Skip new userscript test on WebKit2 like others.

* fast/events/constructors/error-event-constructor-expected.txt:
* fast/events/constructors/error-event-constructor.html:
Test for the new any "error" initialization property.

* fast/events/event-leak-objects-expected.txt:
* fast/events/event-leak-objects.html:
* fast/events/event-properties-gc-expected.txt:
* fast/events/event-properties-gc.html:
Like CustomEvent.details, ErrorEvent.error should not leak
objects across isolated worlds.

* fast/events/window-onerror-exception-in-attr-expected.txt:
* fast/events/window-onerror-exception-in-attr.html:
* fast/events/window-onerror-syntax-error-in-attr-expected.txt:
* fast/events/window-onerror-syntax-error-in-attr.html:
* fast/events/window-onerror1-expected.txt:
* fast/events/window-onerror1.html:
* fast/events/window-onerror10-expected.txt:
* fast/events/window-onerror10.html:
* fast/events/window-onerror11-expected.txt:
* fast/events/window-onerror11.html:
* fast/events/window-onerror12-expected.txt:
* fast/events/window-onerror12.html:
* fast/events/window-onerror13.html:
* fast/events/window-onerror14.html:
* fast/events/window-onerror16.html:
* fast/events/window-onerror17-expected.txt: Added.
* fast/events/window-onerror17.html: Copied from LayoutTests/fast/events/window-onerror12.html.
* fast/events/window-onerror2-expected.txt:
* fast/events/window-onerror2.html:
* fast/events/window-onerror3-expected.txt:
* fast/events/window-onerror3.html:
* fast/events/window-onerror4-expected.txt:
* fast/events/window-onerror4.html:
* fast/events/window-onerror5-expected.txt:
* fast/events/window-onerror5.html:
* fast/events/window-onerror6-expected.txt:
* fast/events/window-onerror6.html:
* fast/events/window-onerror7-expected.txt:
* fast/events/window-onerror7.html:
* fast/events/window-onerror8-expected.txt:
* fast/events/window-onerror8.html:
* fast/events/window-onerror9-expected.txt:
* fast/events/window-onerror9.html:
Include output for the column number and error object where possible.

* fast/files/resources/setup-for-read-common.js:
* fast/files/workers/worker-apply-blob-url-to-xhr.html:
* fast/workers/resources/worker-error-in-handling-script-error.js:
* fast/workers/resources/worker-script-error-bubbled.js:
* fast/workers/resources/worker-script-error-handled.js:
* fast/workers/resources/worker-script-error.js:
* fast/workers/worker-script-error-expected.txt:
Test "onerror" within Workers, and the "error" event on
the Worker from the spawning context.

* http/tests/security/cross-origin-script-error-event-expected.txt: Added.
* http/tests/security/cross-origin-script-error-event-redirected-expected.txt: Added.
* http/tests/security/cross-origin-script-error-event-redirected.html: Added.
* http/tests/security/cross-origin-script-error-event.html: Added.
* http/tests/security/cross-origin-script-window-onerror-expected.txt:
* http/tests/security/cross-origin-script-window-onerror-redirected-expected.txt:
* http/tests/security/cross-origin-script-window-onerror-redirected.html:
* http/tests/security/cross-origin-script-window-onerror.html:
* http/tests/security/script-crossorigin-error-event-information-expected.txt: Added.
* http/tests/security/script-crossorigin-error-event-information.html: Added.
* http/tests/security/script-crossorigin-onerror-information-expected.txt:
* http/tests/security/script-crossorigin-onerror-information.html:
* http/tests/security/script-no-crossorigin-error-event-should-be-sanitized-expected.txt: Added.
* http/tests/security/script-no-crossorigin-error-event-should-be-sanitized.html: Copied from LayoutTests/http/tests/security/script-no-crossorigin-onerror-should-be-sanitized.html.
* http/tests/security/script-no-crossorigin-onerror-should-be-sanitized-expected.txt:
* http/tests/security/script-no-crossorigin-onerror-should-be-sanitized.html:
* http/tests/security/window-onerror-exception-in-iframe-expected.txt:
* http/tests/security/window-onerror-exception-in-iframe.html:
* http/tests/workers/worker-importScriptsOnError-expected.txt:
* js/dom/exception-line-number-expected.txt:
* js/dom/script-tests/exception-line-number.js:
(window.onerror):

* userscripts/window-onerror-for-isolated-world-1-expected.txt:
* userscripts/window-onerror-for-isolated-world-1.html:
* userscripts/window-onerror-for-isolated-world-2-expected.txt:
* userscripts/window-onerror-for-isolated-world-2.html:
* userscripts/window-onerror-for-isolated-world-3-expected.txt: Added.
* userscripts/window-onerror-for-isolated-world-3.html: Added.
Add an explicit test for error objects crossing isolated world boundaries.
In the Isolated World case, serializable values are cloned, but unserializable
values cause the error object to return to null to avoid leaking across worlds.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202023 268f45cc-cd09-0410-ab3c-d52691b4dbfc
95 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/constructors/error-event-constructor-expected.txt
LayoutTests/fast/events/constructors/error-event-constructor.html
LayoutTests/fast/events/event-leak-objects-expected.txt
LayoutTests/fast/events/event-leak-objects.html
LayoutTests/fast/events/event-properties-gc-expected.txt
LayoutTests/fast/events/event-properties-gc.html
LayoutTests/fast/events/window-onerror-exception-in-attr-expected.txt
LayoutTests/fast/events/window-onerror-exception-in-attr.html
LayoutTests/fast/events/window-onerror-syntax-error-in-attr-expected.txt
LayoutTests/fast/events/window-onerror-syntax-error-in-attr.html
LayoutTests/fast/events/window-onerror1-expected.txt
LayoutTests/fast/events/window-onerror1.html
LayoutTests/fast/events/window-onerror10-expected.txt
LayoutTests/fast/events/window-onerror10.html
LayoutTests/fast/events/window-onerror11-expected.txt
LayoutTests/fast/events/window-onerror11.html
LayoutTests/fast/events/window-onerror12-expected.txt
LayoutTests/fast/events/window-onerror12.html
LayoutTests/fast/events/window-onerror13.html
LayoutTests/fast/events/window-onerror14.html
LayoutTests/fast/events/window-onerror16.html
LayoutTests/fast/events/window-onerror17-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/window-onerror17.html [new file with mode: 0644]
LayoutTests/fast/events/window-onerror2-expected.txt
LayoutTests/fast/events/window-onerror2.html
LayoutTests/fast/events/window-onerror3-expected.txt
LayoutTests/fast/events/window-onerror3.html
LayoutTests/fast/events/window-onerror4-expected.txt
LayoutTests/fast/events/window-onerror4.html
LayoutTests/fast/events/window-onerror5-expected.txt
LayoutTests/fast/events/window-onerror5.html
LayoutTests/fast/events/window-onerror6-expected.txt
LayoutTests/fast/events/window-onerror6.html
LayoutTests/fast/events/window-onerror7-expected.txt
LayoutTests/fast/events/window-onerror7.html
LayoutTests/fast/events/window-onerror8-expected.txt
LayoutTests/fast/events/window-onerror8.html
LayoutTests/fast/events/window-onerror9-expected.txt
LayoutTests/fast/events/window-onerror9.html
LayoutTests/fast/files/resources/setup-for-read-common.js
LayoutTests/fast/files/workers/worker-apply-blob-url-to-xhr.html
LayoutTests/fast/workers/resources/worker-error-in-handling-script-error.js
LayoutTests/fast/workers/resources/worker-script-error-bubbled.js
LayoutTests/fast/workers/resources/worker-script-error-handled.js
LayoutTests/fast/workers/resources/worker-script-error.js [new file with mode: 0644]
LayoutTests/fast/workers/worker-script-error-expected.txt
LayoutTests/fast/workers/worker-script-error.html
LayoutTests/http/tests/security/cross-origin-script-error-event-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/cross-origin-script-error-event-redirected-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/cross-origin-script-error-event-redirected.html [new file with mode: 0644]
LayoutTests/http/tests/security/cross-origin-script-error-event.html [new file with mode: 0644]
LayoutTests/http/tests/security/cross-origin-script-window-onerror-expected.txt
LayoutTests/http/tests/security/cross-origin-script-window-onerror-redirected-expected.txt
LayoutTests/http/tests/security/cross-origin-script-window-onerror-redirected.html
LayoutTests/http/tests/security/cross-origin-script-window-onerror.html
LayoutTests/http/tests/security/script-crossorigin-error-event-information-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/script-crossorigin-error-event-information.html [new file with mode: 0644]
LayoutTests/http/tests/security/script-crossorigin-onerror-information-expected.txt
LayoutTests/http/tests/security/script-crossorigin-onerror-information.html
LayoutTests/http/tests/security/script-no-crossorigin-error-event-should-be-sanitized-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/script-no-crossorigin-error-event-should-be-sanitized.html [new file with mode: 0644]
LayoutTests/http/tests/security/script-no-crossorigin-onerror-should-be-sanitized-expected.txt
LayoutTests/http/tests/security/script-no-crossorigin-onerror-should-be-sanitized.html
LayoutTests/http/tests/security/window-onerror-exception-in-iframe-expected.txt
LayoutTests/http/tests/security/window-onerror-exception-in-iframe.html
LayoutTests/http/tests/workers/worker-importScriptsOnError-expected.txt
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt
LayoutTests/js/dom/exception-line-number-expected.txt
LayoutTests/js/dom/script-tests/exception-line-number.js
LayoutTests/platform/wk2/TestExpectations
LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt
LayoutTests/userscripts/window-onerror-for-isolated-world-1.html
LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt
LayoutTests/userscripts/window-onerror-for-isolated-world-2.html
LayoutTests/userscripts/window-onerror-for-isolated-world-3-expected.txt [new file with mode: 0644]
LayoutTests/userscripts/window-onerror-for-isolated-world-3.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSCustomEventCustom.cpp
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSErrorEventCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSErrorHandler.cpp
Source/WebCore/bindings/js/JSErrorHandler.h
Source/WebCore/bindings/js/WorkerScriptController.cpp
Source/WebCore/dom/CustomEvent.h
Source/WebCore/dom/ErrorEvent.cpp
Source/WebCore/dom/ErrorEvent.h
Source/WebCore/dom/ErrorEvent.idl
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/workers/WorkerMessagingProxy.cpp