Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
events: fix depth in customInspectSymbol and clean up
  • Loading branch information
lundibundi committed Jun 19, 2020
commit 8713e07bcaa59fdbd26c110a91ce06cf1f0cffec
19 changes: 8 additions & 11 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

const {
ArrayFrom,
Boolean,
Error,
Map,
NumberIsInteger,
Object,
Set,
Symbol,
Expand Down Expand Up @@ -78,7 +80,7 @@ class Event {
return name;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, @BridgeAR shouldn't this return this? (as well as the other one)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be ideal. this will just let inspect() to properly know what to do.


const opts = Object.assign({}, options, {
dept: options.depth === null ? null : options.depth - 1
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd assume this was a bug (dept instead of depth) but wanted to point out since I'm not sure how this interaction works (inspecting circular events I assume?).
Also, use NumberIsInteger instead of just null check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is both correct. The user should only ever pass through null or and integer but it would be possible to pass through other types as well.

});

return `${name} ${inspect({
Expand Down Expand Up @@ -294,7 +296,7 @@ class EventTarget {
this.#emitting.delete(event.type);
event[kTarget] = undefined;

return event.defaultPrevented === true ? false : true;
return event.defaultPrevented !== true;
}

[customInspectSymbol](depth, options) {
Expand All @@ -303,7 +305,7 @@ class EventTarget {
return name;

const opts = Object.assign({}, options, {
dept: options.depth === null ? null : options.depth - 1
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
});

return `${name} ${inspect({}, opts)}`;
Expand Down Expand Up @@ -429,15 +431,10 @@ function validateEventListenerOptions(options) {
if (typeof options === 'boolean')
return { capture: options };
validateObject(options, 'options');
const {
once = false,
capture = false,
passive = false,
} = options;
return {
once: !!once,
capture: !!capture,
passive: !!passive,
once: Boolean(options.once),
capture: Boolean(options.capture),
passive: Boolean(options.passive),
};
}

Expand Down