From 65f8a2716e6ec129f57090686a781b4ec24b08f9 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 65c7e04fbabfe5..1b984bcde7ff69 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` @@ -2433,6 +2436,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..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; } /**