| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ const { | |||
| 15 | 15 | ERR_INVALID_ARG_TYPE, | |
| 16 | 16 | ERR_EVENT_RECURSION, | |
| 17 | 17 | ERR_OUT_OF_RANGE, | |
| 18 | + ERR_MISSING_ARGS | ||
| 18 | 19 | } | |
| 19 | 20 | } = require('internal/errors'); | |
| 20 | 21 | ||
@@ -45,6 +46,9 @@ class Event { | |||
| 45 | 46 | ||
| 46 | 47 | ||
| 47 | 48 | constructor(type, options) { | |
| 49 | + if (arguments.length === 0) { | ||
| 50 | + throw new ERR_MISSING_ARGS('type'); | ||
| 51 | + } | ||
| 48 | 52 | if (options != null && typeof options !== 'object') | |
| 49 | 53 | throw new ERR_INVALID_ARG_TYPE('options', 'object', options); | |
| 50 | 54 | const { cancelable, bubbles, composed } = { ...options }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ ok(EventTarget); | |||
| 29 | 29 | strictEqual(ev.defaultPrevented, false); | |
| 30 | 30 | strictEqual(typeof ev.timeStamp, 'number'); | |
| 31 | 31 | ||
| 32 | + // Compatibility properties with the DOM | ||
| 32 | 33 | deepStrictEqual(ev.composedPath(), []); | |
| 33 | 34 | strictEqual(ev.returnValue, true); | |
| 34 | 35 | strictEqual(ev.bubbles, false); | |
@@ -59,7 +60,15 @@ ok(EventTarget); | |||
| 59 | 60 | ev.cancelBubble = 'some-truthy-value'; | |
| 60 | 61 | strictEqual(ev.cancelBubble, true); | |
| 61 | 62 | } | |
| 62 | - | ||
| 63 | + { | ||
| 64 | + // No argument behavior - throw TypeError | ||
| 65 | + throws(() => { | ||
| 66 | + new Event(); | ||
| 67 | + }, TypeError); | ||
| 68 | + // Too many arguments passed behavior - ignore additional arguments | ||
| 69 | + const ev = new Event('foo', {}, {}); | ||
| 70 | + strictEqual(ev.type, 'foo'); | ||
| 71 | + } | ||
| 63 | 72 | { | |
| 64 | 73 | const ev = new Event('foo', { cancelable: true }); | |
| 65 | 74 | strictEqual(ev.type, 'foo'); | |
@@ -419,6 +428,6 @@ ok(EventTarget); | |||
| 419 | 428 | { | |
| 420 | 429 | const target = new EventTarget(); | |
| 421 | 430 | strictEqual(target.toString(), '[object EventTarget]'); | |
| 422 | - const event = new Event(); | ||
| 431 | + const event = new Event(''); | ||
| 423 | 432 | strictEqual(event.toString(), '[object Event]'); | |
| 424 | 433 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments