Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions 25 lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const { now } = require('internal/perf/utils');

const kType = Symbol('type');
const kDetail = Symbol('detail');
const kInPassiveListener = Symbol('kInPassiveListener');

const isTrustedSet = new SafeWeakSet();
const isTrusted = ObjectGetOwnPropertyDescriptor({
Expand Down Expand Up @@ -127,6 +128,7 @@ class Event {

this[kTarget] = null;
this[kIsBeingDispatched] = false;
this[kInPassiveListener] = false;
}

/**
Expand Down Expand Up @@ -178,6 +180,7 @@ class Event {
preventDefault() {
if (!isEvent(this))
throw new ERR_INVALID_THIS('Event');
if (!this.#cancelable || this[kInPassiveListener]) return;
this.#defaultPrevented = true;
}

Expand Down Expand Up @@ -266,6 +269,19 @@ class Event {
return !this.#cancelable || !this.#defaultPrevented;
}

/**
* @type {boolean}
*/
set returnValue(value) {
if (!isEvent(this))
throw new ERR_INVALID_THIS('Event');

if (!value) {
if (!this.#cancelable || this[kInPassiveListener]) return;
this.#defaultPrevented = true;
}
}

/**
* @type {boolean}
*/
Expand Down Expand Up @@ -760,7 +776,6 @@ class EventTarget {
throw new ERR_EVENT_RECURSION(event.type);

this[kHybridDispatch](event, event.type, event);

return event.defaultPrevented !== true;
}

Expand Down Expand Up @@ -813,8 +828,8 @@ class EventTarget {
this[kRemoveListener](root.size, type, listener, capture);
}

let arg;
try {
let arg;
if (handler.isNodeStyleListener) {
arg = nodeValue;
} else {
Expand All @@ -824,6 +839,9 @@ class EventTarget {
handler.callback.deref() : handler.callback;
let result;
if (callback) {
if (handler.passive && !handler.isNodeStyleListener) {
arg[kInPassiveListener] = true;
}
result = FunctionPrototypeCall(callback, this, arg);
if (!handler.isNodeStyleListener) {
arg[kIsBeingDispatched] = false;
Expand All @@ -833,6 +851,9 @@ class EventTarget {
addCatch(result);
} catch (err) {
emitUncaughtException(err);
} finally {
if (arg?.[kInPassiveListener])
arg[kInPassiveListener] = false;
}

handler = next;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const common = require('../common');
require('../common');

// Manually converted from https://github.com/web-platform-tests/wpt/blob/master/dom/events/AddEventListenerOptions-passive.html
// in order to define the `document` ourselves
Expand Down Expand Up @@ -58,7 +58,6 @@ const {
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);
Expand Down
9 changes: 0 additions & 9 deletions 9 test/wpt/status/dom/events.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
{
"AddEventListenerOptions-passive.any.js": {
"fail": {
"expected": [
"preventDefault should be ignored if-and-only-if the passive option is true",
"returnValue should be ignored if-and-only-if the passive option is true",
"passive behavior of one listener should be unaffected by the presence of other listeners"
]
}
},
"Event-dispatch-listener-order.window.js": {
"skip": "document is not defined"
},
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.