From 297773c6d10c091ffb2a980615c21f742babe7f8 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Thu, 19 Jan 2023 16:10:25 +0900 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/46175 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel --- 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 0b61c1add6f20e..104f2e22f2d541 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -2111,8 +2111,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. +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` @@ -2429,6 +2432,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 733636b5d7ae07..e75c09c49a7096 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; } /**