GeezerVison is showing github.com — test_runner: add `__proto__` null · nodejs/node@fa19b0e
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -111,6 +111,14 @@ module.exports = { | 111 | 111 | }, | 112 | 112 | ] }, | 113 | 113 | }, | | 114 | + { | | 115 | + files: [ | | 116 | + 'lib/internal/test_runner/**/*.js', | | 117 | + ], | | 118 | + rules: { | | 119 | + 'node-core/set-proto-to-null-in-object': 'error', | | 120 | + }, | | 121 | + }, | 114 | 122 | ], | 115 | 123 | rules: { | 116 | 124 | // ESLint built-in rules | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/coverage.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -250,7 +250,7 @@ class TestCoverage { | 250 | 250 | let dir; | 251 | 251 |
| 252 | 252 | try { | 253 | | - mkdirSync(this.originalCoverageDirectory, { recursive: true }); | | 253 | + mkdirSync(this.originalCoverageDirectory, { __proto__: null, recursive: true }); | 254 | 254 | dir = opendirSync(this.coverageDirectory); | 255 | 255 |
| 256 | 256 | for (let entry; (entry = dir.readSync()) !== null;) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,6 +116,7 @@ function setup(root) { | 116 | 116 | const globalOptions = parseCommandLine(); | 117 | 117 |
| 118 | 118 | const hook = createHook({ | | 119 | + __proto__: null, | 119 | 120 | init(asyncId, type, triggerAsyncId, resource) { | 120 | 121 | if (resource instanceof Test) { | 121 | 122 | testResources.set(asyncId, resource); | @@ -216,7 +217,7 @@ function runInParentContext(Factory) { | 216 | 217 |
| 217 | 218 | const test = (name, options, fn) => run(name, options, fn); | 218 | 219 | ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => { | 219 | | - test[keyword] = (name, options, fn) => run(name, options, fn, { [keyword]: true }); | | 220 | + test[keyword] = (name, options, fn) => run(name, options, fn, { __proto__: null, [keyword]: true }); | 220 | 221 | }); | 221 | 222 | return test; | 222 | 223 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/mock/mock.js +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -133,7 +133,7 @@ class MockTracker { | 133 | 133 | validateObject(options, 'options'); | 134 | 134 | const { times = Infinity } = options; | 135 | 135 | validateTimes(times, 'options.times'); | 136 | | - const ctx = new MockFunctionContext(implementation, { original }, times); | | 136 | + const ctx = new MockFunctionContext(implementation, { __proto__: null, original }, times); | 137 | 137 | return this.#setupMock(ctx, original); | 138 | 138 | } | 139 | 139 |
| @@ -189,7 +189,7 @@ class MockTracker { | 189 | 189 | ); | 190 | 190 | } | 191 | 191 |
| 192 | | - const restore = { descriptor, object: objectOrFunction, methodName }; | | 192 | + const restore = { __proto__: null, descriptor, object: objectOrFunction, methodName }; | 193 | 193 | const impl = implementation === kDefaultFunction ? | 194 | 194 | original : implementation; | 195 | 195 | const ctx = new MockFunctionContext(impl, restore, times); | @@ -238,6 +238,7 @@ class MockTracker { | 238 | 238 | } | 239 | 239 |
| 240 | 240 | return this.method(object, methodName, implementation, { | | 241 | + __proto__: null, | 241 | 242 | ...options, | 242 | 243 | getter, | 243 | 244 | }); | @@ -265,6 +266,7 @@ class MockTracker { | 265 | 266 | } | 266 | 267 |
| 267 | 268 | return this.method(object, methodName, implementation, { | | 269 | + __proto__: null, | 268 | 270 | ...options, | 269 | 271 | setter, | 270 | 272 | }); | @@ -297,6 +299,7 @@ class MockTracker { | 297 | 299 | throw err; | 298 | 300 | } finally { | 299 | 301 | FunctionPrototypeCall(trackCall, ctx, { | | 302 | + __proto__: null, | 300 | 303 | arguments: argList, | 301 | 304 | error, | 302 | 305 | result, | @@ -321,6 +324,7 @@ class MockTracker { | 321 | 324 | throw err; | 322 | 325 | } finally { | 323 | 326 | FunctionPrototypeCall(trackCall, ctx, { | | 327 | + __proto__: null, | 324 | 328 | arguments: argList, | 325 | 329 | error, | 326 | 330 | result, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/mock/mock_timers.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -45,7 +45,7 @@ function setPosition(node, pos) { | 45 | 45 | } | 46 | 46 |
| 47 | 47 | function abortIt(signal) { | 48 | | - return new AbortError(undefined, { cause: signal.reason }); | | 48 | + return new AbortError(undefined, { __proto__: null, cause: signal.reason }); | 49 | 49 | } | 50 | 50 |
| 51 | 51 | const SUPPORTED_TIMERS = ['setTimeout', 'setInterval']; | @@ -194,7 +194,9 @@ class MockTimers { | 194 | 194 |
| 195 | 195 | #toggleEnableTimers(activate) { | 196 | 196 | const options = { | | 197 | + __proto__: null, | 197 | 198 | toFake: { | | 199 | + __proto__: null, | 198 | 200 | setTimeout: () => { | 199 | 201 | this.#realSetTimeout = globalThis.setTimeout; | 200 | 202 | this.#realClearTimeout = globalThis.clearTimeout; | @@ -233,6 +235,7 @@ class MockTimers { | 233 | 235 | }, | 234 | 236 | }, | 235 | 237 | toReal: { | | 238 | + __proto__: null, | 236 | 239 | setTimeout: () => { | 237 | 240 | globalThis.setTimeout = this.#realSetTimeout; | 238 | 241 | globalThis.clearTimeout = this.#realClearTimeout; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/reporter/spec.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,7 +42,7 @@ class SpecReporter extends Transform { | 42 | 42 | #failedTests = []; | 43 | 43 |
| 44 | 44 | constructor() { | 45 | | - super({ writableObjectMode: true }); | | 45 | + super({ __proto__: null, writableObjectMode: true }); | 46 | 46 | } | 47 | 47 |
| 48 | 48 | #indent(nesting) { | @@ -127,7 +127,7 @@ class SpecReporter extends Transform { | 127 | 127 | } | 128 | 128 | } | 129 | 129 | _transform({ type, data }, encoding, callback) { | 130 | | - callback(null, this.#handleEvent({ type, data })); | | 130 | + callback(null, this.#handleEvent({ __proto__: null, type, data })); | 131 | 131 | } | 132 | 132 | _flush(callback) { | 133 | 133 | if (this.#failedTests.length === 0) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/reporter/tap.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ const kDefaultIndent = ' '; // 4 spaces | 18 | 18 | const kFrameStartRegExp = /^ {4}at /; | 19 | 19 | const kLineBreakRegExp = /\n|\r\n/; | 20 | 20 | const kDefaultTAPVersion = 13; | 21 | | -const inspectOptions = { colors: false, breakLength: Infinity }; | | 21 | +const inspectOptions = { __proto__: null, colors: false, breakLength: Infinity }; | 22 | 22 | let testModule; // Lazy loaded due to circular dependency. | 23 | 23 |
| 24 | 24 | function lazyLoadTest() { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -135,7 +135,7 @@ function createTestFileList() { | 135 | 135 | for (let i = 0; i < testPaths.length; i++) { | 136 | 136 | const absolutePath = resolve(testPaths[i]); | 137 | 137 |
| 138 | | - processPath(absolutePath, testFiles, { userSupplied: true }); | | 138 | + processPath(absolutePath, testFiles, { __proto__: null, userSupplied: true }); | 139 | 139 | } | 140 | 140 | } catch (err) { | 141 | 141 | if (err?.code === 'ENOENT') { | @@ -348,9 +348,9 @@ class FileTest extends Test { | 348 | 348 | function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { | 349 | 349 | const watchMode = filesWatcher != null; | 350 | 350 | const subtest = root.createSubtest(FileTest, path, async (t) => { | 351 | | - const args = getRunArgs({ path, inspectPort, testNamePatterns }); | | 351 | + const args = getRunArgs({ __proto__: null, path, inspectPort, testNamePatterns }); | 352 | 352 | const stdio = ['pipe', 'pipe', 'pipe']; | 353 | | - const env = { ...process.env, NODE_TEST_CONTEXT: 'child-v8' }; | | 353 | + const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' }; | 354 | 354 | if (watchMode) { | 355 | 355 | stdio.push('ipc'); | 356 | 356 | env.WATCH_REPORT_DEPENDENCIES = '1'; | @@ -359,7 +359,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { | 359 | 359 | env.FORCE_COLOR = '1'; | 360 | 360 | } | 361 | 361 |
| 362 | | - const child = spawn(process.execPath, args, { signal: t.signal, encoding: 'utf8', env, stdio }); | | 362 | + const child = spawn(process.execPath, args, { __proto__: null, signal: t.signal, encoding: 'utf8', env, stdio }); | 363 | 363 | if (watchMode) { | 364 | 364 | filesWatcher.runningProcesses.set(path, child); | 365 | 365 | filesWatcher.watcher.watchChildProcessModules(child, path); | @@ -376,7 +376,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { | 376 | 376 | subtest.parseMessage(data); | 377 | 377 | }); | 378 | 378 |
| 379 | | - const rl = createInterface({ input: child.stderr }); | | 379 | + const rl = createInterface({ __proto__: null, input: child.stderr }); | 380 | 380 | rl.on('line', (line) => { | 381 | 381 | if (isInspectorMessage(line)) { | 382 | 382 | process.stderr.write(line + '\n'); | @@ -394,8 +394,8 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { | 394 | 394 | }); | 395 | 395 |
| 396 | 396 | const { 0: { 0: code, 1: signal } } = await SafePromiseAll([ | 397 | | - once(child, 'exit', { signal: t.signal }), | 398 | | - finished(child.stdout, { signal: t.signal }), | | 397 | + once(child, 'exit', { __proto__: null, signal: t.signal }), | | 398 | + finished(child.stdout, { __proto__: null, signal: t.signal }), | 399 | 399 | ]); | 400 | 400 |
| 401 | 401 | if (watchMode) { | @@ -428,7 +428,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { | 428 | 428 | function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) { | 429 | 429 | const runningProcesses = new SafeMap(); | 430 | 430 | const runningSubtests = new SafeMap(); | 431 | | - const watcher = new FilesWatcher({ debounce: 200, mode: 'filter', signal }); | | 431 | + const watcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: 'filter', signal }); | 432 | 432 | const filesWatcher = { __proto__: null, watcher, runningProcesses, runningSubtests }; | 433 | 433 |
| 434 | 434 | watcher.on('changed', ({ owners }) => { | @@ -513,7 +513,7 @@ function run(options) { | 513 | 513 | }); | 514 | 514 | } | 515 | 515 |
| 516 | | - const root = createTestTree({ concurrency, timeout, signal }); | | 516 | + const root = createTestTree({ __proto__: null, concurrency, timeout, signal }); | 517 | 517 | let testFiles = files ?? createTestFileList(); | 518 | 518 |
| 519 | 519 | if (shard) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,7 +79,7 @@ function stopTest(timeout, signal) { | 79 | 79 | if (timeout === kDefaultTimeout) { | 80 | 80 | return once(signal, 'abort'); | 81 | 81 | } | 82 | | - return PromisePrototypeThen(setTimeout(timeout, null, { ref: false, signal }), () => { | | 82 | + return PromisePrototypeThen(setTimeout(timeout, null, { __proto__: null, ref: false, signal }), () => { | 83 | 83 | throw new ERR_TEST_FAILURE( | 84 | 84 | `test timed out after ${timeout}ms`, | 85 | 85 | kTestTimeoutFailure, | @@ -506,7 +506,7 @@ class Test extends AsyncResource { | 506 | 506 |
| 507 | 507 | getRunArgs() { | 508 | 508 | const ctx = new TestContext(this); | 509 | | - return { ctx, args: [ctx] }; | | 509 | + return { __proto__: null, ctx, args: [ctx] }; | 510 | 510 | } | 511 | 511 |
| 512 | 512 | async runHook(hook, args) { | @@ -540,12 +540,12 @@ class Test extends AsyncResource { | 540 | 540 | const { args, ctx } = this.getRunArgs(); | 541 | 541 | const after = async () => { | 542 | 542 | if (this.hooks.after.length > 0) { | 543 | | - await this.runHook('after', { args, ctx }); | | 543 | + await this.runHook('after', { __proto__: null, args, ctx }); | 544 | 544 | } | 545 | 545 | }; | 546 | 546 | const afterEach = runOnce(async () => { | 547 | 547 | if (this.parent?.hooks.afterEach.length > 0) { | 548 | | - await this.parent.runHook('afterEach', { args, ctx }); | | 548 | + await this.parent.runHook('afterEach', { __proto__: null, args, ctx }); | 549 | 549 | } | 550 | 550 | }); | 551 | 551 |
| @@ -554,7 +554,7 @@ class Test extends AsyncResource { | 554 | 554 | await this.parent.runHook('before', this.parent.getRunArgs()); | 555 | 555 | } | 556 | 556 | if (this.parent?.hooks.beforeEach.length > 0) { | 557 | | - await this.parent.runHook('beforeEach', { args, ctx }); | | 557 | + await this.parent.runHook('beforeEach', { __proto__: null, args, ctx }); | 558 | 558 | } | 559 | 559 | const stopPromise = stopTest(this.timeout, this.signal); | 560 | 560 | const runArgs = ArrayPrototypeSlice(args); | @@ -811,7 +811,7 @@ class Suite extends Test { | 811 | 811 |
| 812 | 812 | getRunArgs() { | 813 | 813 | const ctx = new SuiteContext(this); | 814 | | - return { ctx, args: [ctx] }; | | 814 | + return { __proto__: null, ctx, args: [ctx] }; | 815 | 815 | } | 816 | 816 |
| 817 | 817 | async run() { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/tests_stream.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ class TestsStream extends Readable { | 12 | 12 | #canPush; | 13 | 13 |
| 14 | 14 | constructor() { | 15 | | - super({ objectMode: true }); | | 15 | + super({ __proto__: null, objectMode: true }); | 16 | 16 | this.#buffer = []; | 17 | 17 | this.#canPush = true; | 18 | 18 | } | @@ -83,6 +83,8 @@ class TestsStream extends Readable { | 83 | 83 |
| 84 | 84 | [kEmitMessage](type, data) { | 85 | 85 | this.emit(type, data); | | 86 | + // Disabling as this going to the user-land | | 87 | + // eslint-disable-next-line node-core/set-proto-to-null-in-object | 86 | 88 | this.#tryPush({ type, data }); | 87 | 89 | } | 88 | 90 |
| |
|