| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ee58b2d commit f1753d4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,21 +6,27 @@ | |||
| 6 | 6 | ||
| 7 | 7 | const { | |
| 8 | 8 | ArrayPrototypeEvery, | |
| 9 | + ArrayPrototypeForEach, | ||
| 10 | + ArrayPrototypeIncludes, | ||
| 9 | 11 | ArrayPrototypeMap, | |
| 10 | 12 | ArrayPrototypePush, | |
| 11 | 13 | ArrayPrototypeSplice, | |
| 12 | 14 | BigUint64Array, | |
| 13 | 15 | Float64Array, | |
| 14 | 16 | NumberMAX_SAFE_INTEGER, | |
| 15 | - ObjectDefineProperty, | ||
| 16 | 17 | ObjectFreeze, | |
| 17 | 18 | ReflectApply, | |
| 18 | 19 | RegExpPrototypeTest, | |
| 19 | - SafeSet, | ||
| 20 | + SafeArrayIterator, | ||
| 21 | + Set, | ||
| 22 | + SetPrototypeEntries, | ||
| 23 | + SetPrototypeValues, | ||
| 20 | 24 | StringPrototypeEndsWith, | |
| 21 | 25 | StringPrototypeReplace, | |
| 22 | 26 | StringPrototypeSlice, | |
| 23 | 27 | StringPrototypeStartsWith, | |
| 28 | + Symbol, | ||
| 29 | + SymbolIterator, | ||
| 24 | 30 | Uint32Array, | |
| 25 | 31 | } = primordials; | |
| 26 | 32 | ||
@@ -41,6 +47,8 @@ const { | |||
| 41 | 47 | } = require('internal/validators'); | |
| 42 | 48 | const constants = internalBinding('constants').os.signals; | |
| 43 | 49 | ||
| 50 | + const kInternal = Symbol('internal properties'); | ||
| 51 | + | ||
| 44 | 52 | function assert(x, msg) { | |
| 45 | 53 | if (!x) throw new ERR_ASSERTION(msg || 'assertion error'); | |
| 46 | 54 | } | |
@@ -293,18 +301,18 @@ function buildAllowedFlags() { | |||
| 293 | 301 | ||
| 294 | 302 | // Save these for comparison against flags provided to | |
| 295 | 303 | // process.allowedNodeEnvironmentFlags.has() which lack leading dashes. | |
| 296 | - const nodeFlags = new SafeSet(ArrayPrototypeMap(allowedNodeEnvironmentFlags, | ||
| 297 | - trimLeadingDashes)); | ||
| 298 | - | ||
| 299 | - class NodeEnvironmentFlagsSet extends SafeSet { | ||
| 300 | - constructor(...args) { | ||
| 301 | - super(...args); | ||
| 302 | - | ||
| 303 | - // The super constructor consumes `add`, but | ||
| 304 | - // disallow any future adds. | ||
| 305 | - ObjectDefineProperty(this, 'add', { | ||
| 306 | - value: () => this | ||
| 307 | - }); | ||
| 304 | + const nodeFlags = ArrayPrototypeMap(allowedNodeEnvironmentFlags, | ||
| 305 | + trimLeadingDashes); | ||
| 306 | + | ||
| 307 | + class NodeEnvironmentFlagsSet extends Set { | ||
| 308 | + constructor(array) { | ||
| 309 | + super(); | ||
| 310 | + this[kInternal] = { array }; | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + add() { | ||
| 314 | + // No-op, `Set` API compatible | ||
| 315 | + return this; | ||
| 308 | 316 | } | |
| 309 | 317 | ||
| 310 | 318 | delete() { | |
@@ -313,7 +321,7 @@ function buildAllowedFlags() { | |||
| 313 | 321 | } | |
| 314 | 322 | ||
| 315 | 323 | clear() { | |
| 316 | - // No-op | ||
| 324 | + // No-op, `Set` API compatible | ||
| 317 | 325 | } | |
| 318 | 326 | ||
| 319 | 327 | has(key) { | |
@@ -328,13 +336,39 @@ function buildAllowedFlags() { | |||
| 328 | 336 | key = StringPrototypeReplace(key, replaceUnderscoresRegex, '-'); | |
| 329 | 337 | if (RegExpPrototypeTest(leadingDashesRegex, key)) { | |
| 330 | 338 | key = StringPrototypeReplace(key, trailingValuesRegex, ''); | |
| 331 | - return super.has(key); | ||
| 339 | + return ArrayPrototypeIncludes(this[kInternal].array, key); | ||
| 332 | 340 | } | |
| 333 | - return nodeFlags.has(key); | ||
| 341 | + return ArrayPrototypeIncludes(nodeFlags, key); | ||
| 334 | 342 | } | |
| 335 | 343 | return false; | |
| 336 | 344 | } | |
| 345 | + | ||
| 346 | + entries() { | ||
| 347 | + this[kInternal].set ??= | ||
| 348 | + new Set(new SafeArrayIterator(this[kInternal].array)); | ||
| 349 | + return SetPrototypeEntries(this[kInternal].set); | ||
| 350 | + } | ||
| 351 | + | ||
| 352 | + forEach(callback, thisArg = undefined) { | ||
| 353 | + ArrayPrototypeForEach( | ||
| 354 | + this[kInternal].array, | ||
| 355 | + (v) => ReflectApply(callback, thisArg, [v, v, this]) | ||
| 356 | + ); | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + get size() { | ||
| 360 | + return this[kInternal].array.length; | ||
| 361 | + } | ||
| 362 | + | ||
| 363 | + values() { | ||
| 364 | + this[kInternal].set ??= | ||
| 365 | + new Set(new SafeArrayIterator(this[kInternal].array)); | ||
| 366 | + return SetPrototypeValues(this[kInternal].set); | ||
| 367 | + } | ||
| 337 | 368 | } | |
| 369 | + NodeEnvironmentFlagsSet.prototype.keys = | ||
| 370 | + NodeEnvironmentFlagsSet.prototype[SymbolIterator] = | ||
| 371 | + NodeEnvironmentFlagsSet.prototype.values; | ||
| 338 | 372 | ||
| 339 | 373 | ObjectFreeze(NodeEnvironmentFlagsSet.prototype.constructor); | |
| 340 | 374 | ObjectFreeze(NodeEnvironmentFlagsSet.prototype); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | ||
| 6 | 6 | // Assert legit flags are allowed, and bogus flags are disallowed | |
@@ -63,14 +63,41 @@ const assert = require('assert'); | |||
| 63 | 63 | ||
| 64 | 64 | process.allowedNodeEnvironmentFlags.add('foo'); | |
| 65 | 65 | assert.strictEqual(process.allowedNodeEnvironmentFlags.has('foo'), false); | |
| 66 | - process.allowedNodeEnvironmentFlags.forEach((flag) => { | ||
| 67 | - assert.strictEqual(flag === 'foo', false); | ||
| 68 | - }); | ||
| 66 | + Set.prototype.add.call(process.allowedNodeEnvironmentFlags, 'foo'); | ||
| 67 | + assert.strictEqual(process.allowedNodeEnvironmentFlags.has('foo'), false); | ||
| 69 | 68 | ||
| 70 | - process.allowedNodeEnvironmentFlags.clear(); | ||
| 71 | - assert.strictEqual(process.allowedNodeEnvironmentFlags.size > 0, true); | ||
| 69 | + const thisArg = {}; | ||
| 70 | + process.allowedNodeEnvironmentFlags.forEach( | ||
| 71 | + common.mustCallAtLeast(function(flag, _, set) { | ||
| 72 | + assert.notStrictEqual(flag, 'foo'); | ||
| 73 | + assert.strictEqual(this, thisArg); | ||
| 74 | + assert.strictEqual(set, process.allowedNodeEnvironmentFlags); | ||
| 75 | + }), | ||
| 76 | + thisArg | ||
| 77 | + ); | ||
| 78 | + | ||
| 79 | + for (const flag of process.allowedNodeEnvironmentFlags.keys()) { | ||
| 80 | + assert.notStrictEqual(flag, 'foo'); | ||
| 81 | + } | ||
| 82 | + for (const flag of process.allowedNodeEnvironmentFlags.values()) { | ||
| 83 | + assert.notStrictEqual(flag, 'foo'); | ||
| 84 | + } | ||
| 85 | + for (const flag of process.allowedNodeEnvironmentFlags) { | ||
| 86 | + assert.notStrictEqual(flag, 'foo'); | ||
| 87 | + } | ||
| 88 | + for (const [flag] of process.allowedNodeEnvironmentFlags.entries()) { | ||
| 89 | + assert.notStrictEqual(flag, 'foo'); | ||
| 90 | + } | ||
| 72 | 91 | ||
| 73 | 92 | const size = process.allowedNodeEnvironmentFlags.size; | |
| 93 | + | ||
| 94 | + process.allowedNodeEnvironmentFlags.clear(); | ||
| 95 | + assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size); | ||
| 96 | + Set.prototype.clear.call(process.allowedNodeEnvironmentFlags); | ||
| 97 | + assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size); | ||
| 98 | + | ||
| 74 | 99 | process.allowedNodeEnvironmentFlags.delete('-r'); | |
| 75 | 100 | assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size); | |
| 101 | + Set.prototype.delete.call(process.allowedNodeEnvironmentFlags, '-r'); | ||
| 102 | + assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size); | ||
| 76 | 103 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments