-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events: improve argument handling, start passive
Co-authored-by: Benjamin Gruenbaum <[email protected]> PR-URL: #34015 Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
1 parent
ea1a2d7
commit c34f474
Showing
4 changed files
with
319 additions
and
157 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
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,69 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const { | ||
Event, | ||
EventTarget, | ||
} = require('internal/event_target'); | ||
|
||
const { | ||
fail, | ||
ok, | ||
strictEqual | ||
} = require('assert'); | ||
|
||
// Manually ported from WPT AddEventListenerOptions-passive.html | ||
{ | ||
const document = new EventTarget(); | ||
let supportsPassive = false; | ||
const query_options = { | ||
get passive() { | ||
supportsPassive = true; | ||
return false; | ||
}, | ||
get dummy() { | ||
fail('dummy value getter invoked'); | ||
return false; | ||
} | ||
}; | ||
|
||
document.addEventListener('test_event', null, query_options); | ||
ok(supportsPassive); | ||
|
||
supportsPassive = false; | ||
document.removeEventListener('test_event', null, query_options); | ||
strictEqual(supportsPassive, false); | ||
} | ||
{ | ||
function testPassiveValue(optionsValue, expectedDefaultPrevented) { | ||
const document = new EventTarget(); | ||
let defaultPrevented; | ||
function handler(e) { | ||
if (e.defaultPrevented) { | ||
fail('Event prematurely marked defaultPrevented'); | ||
} | ||
e.preventDefault(); | ||
defaultPrevented = e.defaultPrevented; | ||
} | ||
document.addEventListener('test', handler, optionsValue); | ||
// TODO the WHATWG test is more extensive here and tests dispatching on | ||
// document.body, if we ever support getParent we should amend this | ||
const ev = new Event('test', { bubbles: true, cancelable: true }); | ||
const uncanceled = document.dispatchEvent(ev); | ||
|
||
strictEqual(defaultPrevented, expectedDefaultPrevented); | ||
strictEqual(uncanceled, !expectedDefaultPrevented); | ||
|
||
document.removeEventListener('test', handler, optionsValue); | ||
} | ||
testPassiveValue(undefined, true); | ||
testPassiveValue({}, true); | ||
testPassiveValue({ passive: false }, true); | ||
|
||
common.skip('TODO: passive listeners is still broken'); | ||
testPassiveValue({ passive: 1 }, false); | ||
testPassiveValue({ passive: true }, false); | ||
testPassiveValue({ passive: 0 }, true); | ||
} |
Oops, something went wrong.