Skip to content

Commit

Permalink
events: change status of event.returnvalue to legacy
Browse files Browse the repository at this point in the history
`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: #46175
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
deokjinkim authored and juanarbol committed Jan 31, 2023
1 parent a3056f4 commit 297773c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 297773c

Please sign in to comment.