From c17371199ffb81876a9c8ced03537ba1be03ad13 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Thu, 12 Jan 2023 08:46:33 +0900 Subject: [PATCH 1/3] events: change status of `event.returnvalue` to legacy `event.returnvalue` is described as legacy in spec. Plus, add missed '#'(private member) of defaultPrevented in implementation. Refs: https://dom.spec.whatwg.org/#interface-event Refs: https://developer.mozilla.org/en-US/docs/Web/API/Event/returnValue --- doc/api/events.md | 4 ++++ lib/internal/event_target.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/api/events.md b/doc/api/events.md index 586a37d7cbf526..9d664b0983ce56 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -1846,8 +1846,11 @@ Sets the `defaultPrevented` property to `true` if `cancelable` is `true`. added: v14.5.0 --> +> Stability: 3 - Legacy: Use [`event.defaultPrevented`][] instead. + * Type: {boolean} True if the event has not been canceled. +Returns a value which is opposite of the value returned by `defaultPrevented`. This is not used in Node.js and is provided purely for completeness. #### `event.srcElement` @@ -2168,6 +2171,7 @@ to the `EventTarget`. [`emitter.listenerCount()`]: #emitterlistenercounteventname [`emitter.removeListener()`]: #emitterremovelistenereventname-listener [`emitter.setMaxListeners(n)`]: #emittersetmaxlistenersn +[`event.defaultPrevented`]: #eventdefaultprevented [`event.stopPropagation()`]: #eventstoppropagation [`event.target`]: #eventtarget [`events.defaultMaxListeners`]: #eventsdefaultmaxlisteners diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index dac962e1a3b07e..84abcad4451a18 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -236,7 +236,7 @@ class Event { get returnValue() { if (!isEvent(this)) throw new ERR_INVALID_THIS('Event'); - return !this.defaultPrevented; + return !this.#defaultPrevented; } /** From 4add9b3872d49944eb4ac03a3d0d8ffade20e8f2 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Tue, 17 Jan 2023 12:21:14 +0900 Subject: [PATCH 2/3] use cancelable to determine returnValue Co-authored-by: Antoine du Hamel --- lib/internal/event_target.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 84abcad4451a18..66d7a0db87cdb1 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -236,7 +236,7 @@ class Event { get returnValue() { if (!isEvent(this)) throw new ERR_INVALID_THIS('Event'); - return !this.#defaultPrevented; + return !this.#cancelable || !this.#defaultPrevented; } /** From e8262f69afbd9c61da6c92e7dbb953973d69e719 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Tue, 17 Jan 2023 19:05:36 +0900 Subject: [PATCH 3/3] revise description of `event.returnValue` Co-authored-by: Antoine du Hamel --- doc/api/events.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/events.md b/doc/api/events.md index 9d664b0983ce56..c802db25d73e66 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -1850,7 +1850,7 @@ added: v14.5.0 * Type: {boolean} True if the event has not been canceled. -Returns a value which is opposite of the value returned by `defaultPrevented`. +The value of `event.returnValue` is always the opposite of `event.defaultPrevented`. This is not used in Node.js and is provided purely for completeness. #### `event.srcElement`