| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb7b89c commit ea0668a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,16 +63,7 @@ const kTrustEvent = Symbol('kTrustEvent'); | |||
| 63 | 63 | ||
| 64 | 64 | const { now } = require('internal/perf/utils'); | |
| 65 | 65 | ||
| 66 | - // TODO(joyeecheung): V8 snapshot does not support instance member | ||
| 67 | - // initializers for now: | ||
| 68 | - // https://bugs.chromium.org/p/v8/issues/detail?id=10704 | ||
| 69 | 66 | const kType = Symbol('type'); | |
| 70 | - const kDefaultPrevented = Symbol('defaultPrevented'); | ||
| 71 | - const kCancelable = Symbol('cancelable'); | ||
| 72 | - const kTimestamp = Symbol('timestamp'); | ||
| 73 | - const kBubbles = Symbol('bubbles'); | ||
| 74 | - const kComposed = Symbol('composed'); | ||
| 75 | - const kPropagationStopped = Symbol('propagationStopped'); | ||
| 76 | 67 | ||
| 77 | 68 | const isTrustedSet = new SafeWeakSet(); | |
| 78 | 69 | const isTrusted = ObjectGetOwnPropertyDescriptor({ | |
@@ -86,6 +77,13 @@ function isEvent(value) { | |||
| 86 | 77 | } | |
| 87 | 78 | ||
| 88 | 79 | class Event { | |
| 80 | + #cancelable = false; | ||
| 81 | + #bubbles = false; | ||
| 82 | + #composed = false; | ||
| 83 | + #defaultPrevented = false; | ||
| 84 | + #timestamp = now(); | ||
| 85 | + #propagationStopped = false; | ||
| 86 | + | ||
| 89 | 87 | /** | |
| 90 | 88 | * @param {string} type | |
| 91 | 89 | * @param {{ | |
@@ -101,13 +99,11 @@ class Event { | |||
| 101 | 99 | allowArray: true, allowFunction: true, nullable: true, | |
| 102 | 100 | }); | |
| 103 | 101 | const { cancelable, bubbles, composed } = { ...options }; | |
| 104 | - this[kCancelable] = !!cancelable; | ||
| 105 | - this[kBubbles] = !!bubbles; | ||
| 106 | - this[kComposed] = !!composed; | ||
| 102 | + this.#cancelable = !!cancelable; | ||
| 103 | + this.#bubbles = !!bubbles; | ||
| 104 | + this.#composed = !!composed; | ||
| 105 | + | ||
| 107 | 106 | this[kType] = `${type}`; | |
| 108 | - this[kDefaultPrevented] = false; | ||
| 109 | - this[kTimestamp] = now(); | ||
| 110 | - this[kPropagationStopped] = false; | ||
| 111 | 107 | if (options?.[kTrustEvent]) { | |
| 112 | 108 | isTrustedSet.add(this); | |
| 113 | 109 | } | |
@@ -135,9 +131,9 @@ class Event { | |||
| 135 | 131 | ||
| 136 | 132 | return `${name} ${inspect({ | |
| 137 | 133 | type: this[kType], | |
| 138 | - defaultPrevented: this[kDefaultPrevented], | ||
| 139 | - cancelable: this[kCancelable], | ||
| 140 | - timeStamp: this[kTimestamp], | ||
| 134 | + defaultPrevented: this.#defaultPrevented, | ||
| 135 | + cancelable: this.#cancelable, | ||
| 136 | + timeStamp: this.#timestamp, | ||
| 141 | 137 | }, opts)}`; | |
| 142 | 138 | } | |
| 143 | 139 | ||
@@ -150,7 +146,7 @@ class Event { | |||
| 150 | 146 | preventDefault() { | |
| 151 | 147 | if (!isEvent(this)) | |
| 152 | 148 | throw new ERR_INVALID_THIS('Event'); | |
| 153 | - this[kDefaultPrevented] = true; | ||
| 149 | + this.#defaultPrevented = true; | ||
| 154 | 150 | } | |
| 155 | 151 | ||
| 156 | 152 | /** | |
@@ -195,7 +191,7 @@ class Event { | |||
| 195 | 191 | get cancelable() { | |
| 196 | 192 | if (!isEvent(this)) | |
| 197 | 193 | throw new ERR_INVALID_THIS('Event'); | |
| 198 | - return this[kCancelable]; | ||
| 194 | + return this.#cancelable; | ||
| 199 | 195 | } | |
| 200 | 196 | ||
| 201 | 197 | /** | |
@@ -204,7 +200,7 @@ class Event { | |||
| 204 | 200 | get defaultPrevented() { | |
| 205 | 201 | if (!isEvent(this)) | |
| 206 | 202 | throw new ERR_INVALID_THIS('Event'); | |
| 207 | - return this[kCancelable] && this[kDefaultPrevented]; | ||
| 203 | + return this.#cancelable && this.#defaultPrevented; | ||
| 208 | 204 | } | |
| 209 | 205 | ||
| 210 | 206 | /** | |
@@ -213,7 +209,7 @@ class Event { | |||
| 213 | 209 | get timeStamp() { | |
| 214 | 210 | if (!isEvent(this)) | |
| 215 | 211 | throw new ERR_INVALID_THIS('Event'); | |
| 216 | - return this[kTimestamp]; | ||
| 212 | + return this.#timestamp; | ||
| 217 | 213 | } | |
| 218 | 214 | ||
| 219 | 215 | ||
@@ -244,7 +240,7 @@ class Event { | |||
| 244 | 240 | get bubbles() { | |
| 245 | 241 | if (!isEvent(this)) | |
| 246 | 242 | throw new ERR_INVALID_THIS('Event'); | |
| 247 | - return this[kBubbles]; | ||
| 243 | + return this.#bubbles; | ||
| 248 | 244 | } | |
| 249 | 245 | ||
| 250 | 246 | /** | |
@@ -253,7 +249,7 @@ class Event { | |||
| 253 | 249 | get composed() { | |
| 254 | 250 | if (!isEvent(this)) | |
| 255 | 251 | throw new ERR_INVALID_THIS('Event'); | |
| 256 | - return this[kComposed]; | ||
| 252 | + return this.#composed; | ||
| 257 | 253 | } | |
| 258 | 254 | ||
| 259 | 255 | /** | |
@@ -271,7 +267,7 @@ class Event { | |||
| 271 | 267 | get cancelBubble() { | |
| 272 | 268 | if (!isEvent(this)) | |
| 273 | 269 | throw new ERR_INVALID_THIS('Event'); | |
| 274 | - return this[kPropagationStopped]; | ||
| 270 | + return this.#propagationStopped; | ||
| 275 | 271 | } | |
| 276 | 272 | ||
| 277 | 273 | /** | |
@@ -288,7 +284,7 @@ class Event { | |||
| 288 | 284 | stopPropagation() { | |
| 289 | 285 | if (!isEvent(this)) | |
| 290 | 286 | throw new ERR_INVALID_THIS('Event'); | |
| 291 | - this[kPropagationStopped] = true; | ||
| 287 | + this.#propagationStopped = true; | ||
| 292 | 288 | } | |
| 293 | 289 | ||
| 294 | 290 | static NONE = 0; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments