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 <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
deokjinkim authored and RafaelGSS committed Jan 20, 2023
1 parent 4ac5c71 commit 5bdfaae
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 @@ -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
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 5bdfaae

Please sign in to comment.