Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Window and WorkerGlobalScope should inherit EventTarget
https://bugs.webkit.org/show_bug.cgi?id=154170 <rdar://problem/24642377> Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaseline now that a couple of checks are passing. * web-platform-tests/html/dom/interfaces-expected.txt: Source/WebCore: Window and WorkerGlobalScope should inherit EventTarget instead of duplicating the EventTarget API in their IDL. These were the last interfaces that needed fixing. The next step will be to get rid of the [EventTarget] IDL extended attribute and rely entirely on the EventTarget inheritance. Test: - fast/frames/detached-frame-eventListener.html - Covered by existing tests. * WebCore.xcodeproj/project.pbxproj: Add JSEventTargetCustom.h header to the project. * bindings/js/JSDOMWindowCustom.cpp: Drop custom bindings for Window's addEventListener() and removeEventListener(). The only reason these needed custom code was to add a check for frameless windows. The frameless Window checks was moved to the respective methods in the JSEventTarget generated bindings. * bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::setWindow): Set WindowPrototype's prototype to EventTarget's prototype. * bindings/js/JSDOMWindowShell.h: * bindings/js/JSDictionary.cpp: Include "DOMWindow.h" to fix the build. * bindings/js/JSEventTargetCustom.cpp: (WebCore::JSEventTarget::toWrapped): Handle DOMWindow and WorkerGlobalScope explicitely in toWrapped() and get rid of the DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_UNWRAP_WITH_INTERFACE) now that all interfaces inherit EventTarget when they should. The reason DOMWindow and WorkerGlobalScope still need special handling is because their wrappers (JSDOMWindow / JSWorkerGlobalScope) do not subclass JSEventTarget. (WebCore::JSEventTargetOrGlobalScope::create): * bindings/js/JSEventTargetCustom.h: Added. (WebCore::JSEventTargetOrGlobalScope::wrapped): (WebCore::JSEventTargetOrGlobalScope::operator JSC::JSObject&): (WebCore::JSEventTargetOrGlobalScope::JSEventTargetOrGlobalScope): Add a wrapper type for JSEventTarget / JSDOMWindow and JSWorkerGlobalScope for use in the generated bindings. This is needed because JSDOMWindow and JSWorkerGlobalScope do not subclass JSEventTarget. Subclassing JSEventTarget would be complicated for them because they already subclass JSDOMWindowBase / JSWorkerGlobalScopeBase, which subclasses JSDOMGlobalObject. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::initScript): Set WorkerGlobalScopePrototype's prototype to EventTarget's prototype. * bindings/scripts/CodeGeneratorJS.pm: (ShouldGenerateToJSDeclaration): Do not generate to toJS() implementation for interfaces that use the [CustomProxyToJSObject] IDL extended attribute, even if they inherit EventTarget. (GetCastingHelperForThisObject): To initialize castedThis from thisValue JSValue, we now use the JSEventTargetOrGlobalScope wrapper for the EventTarget implementation. This is to work around the fact that JSDOMWindow and JSWorkerGlobalScope do not subclass JSEventTarget. (GenerateFunctionCastedThis): - Drop code handling [WorkerGlobalScope] IDL extended attribute as there is no such attribute. - Use auto instead of auto* type for castedThis because JSEventTargetOrGlobalScope::create() returns a unique_ptr. - Do not check that castedThis inherits JSEventTarget in the EventTarget bindings code as this no longer holds true. (GenerateImplementation): Generate frameless window() and security checks for EventTarget methods when thisValue is a JSDOMWindow. * dom/EventTarget.idl: Add [JSCustomHeader] IDL Extended attribute as we need a header to expose JSEventTargetOrGlobalScope class. * page/DOMWindow.idl: * workers/WorkerGlobalScope.idl: Inherit EventTarget and stop duplicating the EventTarget API. This matches the HTML specification. LayoutTests: * fast/frames/detached-frame-eventListener-expected.txt: Added. * fast/frames/detached-frame-eventListener.html: Added. Add test case to cover the use of the EventListener API on a detached frame. * fast/loader/window-clearing-expected.txt: Rebaseline now that window has one more object in its prototype chain. * http/tests/security/cross-frame-access-call-expected.txt: * http/tests/security/cross-frame-access-call.html: Add test coverage for cross-origin access to window.dispatchEvent() which should not be allowed, in addition to window.addEventListener() and window.removeEventListener() which were already tested. Canonical link: https://commits.webkit.org/172339@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196563 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
32 changed files
with
387 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
LayoutTests/fast/frames/detached-frame-eventListener-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Tests that the EventTarget API is no longer working on detached frames. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
addEventListenerFunction.call(childWindow, 'myevent', function() { callbackCalled = true; }); | ||
PASS dispatchEventFunc.call(childWindow, new Event('myevent')) is undefined. | ||
PASS callbackCalled is false | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script src="../../resources/js-test-pre.js"></script> | ||
<script> | ||
description("Tests that the EventTarget API is no longer working on detached frames."); | ||
jsTestIsAsync = true; | ||
|
||
onload = function() | ||
{ | ||
childWindow = frames[0]; | ||
addEventListenerFunction = childWindow.addEventListener; | ||
dispatchEventFunc = childWindow.dispatchEvent; | ||
document.body.removeChild(document.getElementsByTagName("iframe")[0]); | ||
callbackCalled = false; | ||
evalAndLog("addEventListenerFunction.call(childWindow, 'myevent', function() { callbackCalled = true; });"); | ||
shouldBeUndefined("dispatchEventFunc.call(childWindow, new Event('myevent'))"); | ||
shouldBeFalse("callbackCalled"); | ||
finishJSTest(); | ||
} | ||
</script> | ||
<iframe src="about:blank"></iframe> | ||
<script src="../../resources/js-test-post.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.