| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 83d1f41 commit 9023b3f
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -674,8 +674,9 @@ assignFunctionName(EE.captureRejectionSymbol, function(err, event, ...args) { | |||
| 674 | 674 | break; | |
| 675 | 675 | } | |
| 676 | 676 | default: | |
| 677 | - net.Server.prototype[SymbolFor('nodejs.rejection')] | ||
| 678 | - .apply(this, arguments); | ||
| 677 | + ReflectApply( | ||
| 678 | + net.Server.prototype[SymbolFor('nodejs.rejection')], | ||
| 679 | + this, arguments); | ||
| 679 | 680 | } | |
| 680 | 681 | }); | |
| 681 | 682 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,10 @@ const noRestrictedSyntax = [ | |||
| 38 | 38 | selector: "ThrowStatement > NewExpression[callee.name=/^ERR_[A-Z_]+$/] > ObjectExpression:first-child:not(:has([key.name='message']):has([key.name='code']):has([key.name='syscall']))", | |
| 39 | 39 | message: 'The context passed into the SystemError constructor must include .code, .syscall, and .message properties.', | |
| 40 | 40 | }, | |
| 41 | + { | ||
| 42 | + selector: "CallExpression:matches([callee.type='Identifier'][callee.name='FunctionPrototypeApply'], [callee.type='MemberExpression'][callee.property.type='Identifier'][callee.property.name='apply'][arguments.length=2])", | ||
| 43 | + message: 'Use `ReflectApply` instead of %Function.prototype.apply%', | ||
| 44 | + }, | ||
| 41 | 45 | ]; | |
| 42 | 46 | ||
| 43 | 47 | export default [ | |
@@ -57,7 +61,13 @@ export default [ | |||
| 57 | 61 | rules: { | |
| 58 | 62 | 'prefer-object-spread': 'error', | |
| 59 | 63 | 'no-buffer-constructor': 'error', | |
| 60 | - 'no-restricted-syntax': noRestrictedSyntax, | ||
| 64 | + 'no-restricted-syntax': [ | ||
| 65 | + ...noRestrictedSyntax, | ||
| 66 | + { | ||
| 67 | + selector: "CallExpression[callee.type='Identifier'][callee.name='ReflectApply'][arguments.2.type='ArrayExpression']", | ||
| 68 | + message: 'Use `FunctionPrototypeCall` to avoid creating an ad-hoc array', | ||
| 69 | + }, | ||
| 70 | + ], | ||
| 61 | 71 | 'no-restricted-globals': [ | |
| 62 | 72 | 'error', | |
| 63 | 73 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -505,7 +505,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) { | |||
| 505 | 505 | return false; | |
| 506 | 506 | ||
| 507 | 507 | if (typeof handler === 'function') { | |
| 508 | - const result = handler.apply(this, args); | ||
| 508 | + const result = ReflectApply(handler, this, args); | ||
| 509 | 509 | ||
| 510 | 510 | // We check if result is undefined first because that | |
| 511 | 511 | // is the most common case so we do not pay any perf | |
@@ -517,7 +517,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) { | |||
| 517 | 517 | const len = handler.length; | |
| 518 | 518 | const listeners = arrayClone(handler); | |
| 519 | 519 | for (let i = 0; i < len; ++i) { | |
| 520 | - const result = listeners[i].apply(this, args); | ||
| 520 | + const result = ReflectApply(listeners[i], this, args); | ||
| 521 | 521 | ||
| 522 | 522 | // We check if result is undefined first because that | |
| 523 | 523 | // is the most common case so we do not pay any perf | |
@@ -620,7 +620,7 @@ function onceWrapper() { | |||
| 620 | 620 | this.fired = true; | |
| 621 | 621 | if (arguments.length === 0) | |
| 622 | 622 | return this.listener.call(this.target); | |
| 623 | - return this.listener.apply(this.target, arguments); | ||
| 623 | + return ReflectApply(this.listener, this.target, arguments); | ||
| 624 | 624 | } | |
| 625 | 625 | } | |
| 626 | 626 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const { | |||
| 5 | 5 | ErrorCaptureStackTrace, | |
| 6 | 6 | ObjectDefineProperty, | |
| 7 | 7 | ObjectPrototypeHasOwnProperty, | |
| 8 | + ReflectApply, | ||
| 8 | 9 | Symbol, | |
| 9 | 10 | } = primordials; | |
| 10 | 11 | ||
@@ -125,9 +126,9 @@ function callbackTrampoline(asyncId, resource, cb, ...args) { | |||
| 125 | 126 | let result; | |
| 126 | 127 | if (asyncId === 0 && typeof domain_cb === 'function') { | |
| 127 | 128 | args.unshift(cb); | |
| 128 | - result = domain_cb.apply(this, args); | ||
| 129 | + result = ReflectApply(domain_cb, this, args); | ||
| 129 | 130 | } else { | |
| 130 | - result = cb.apply(this, args); | ||
| 131 | + result = ReflectApply(cb, this, args); | ||
| 131 | 132 | } | |
| 132 | 133 | ||
| 133 | 134 | if (asyncId !== 0 && hasHooks(kAfter)) | |
@@ -462,14 +463,14 @@ function clearDefaultTriggerAsyncId() { | |||
| 462 | 463 | */ | |
| 463 | 464 | function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) { | |
| 464 | 465 | if (triggerAsyncId === undefined) | |
| 465 | - return block.apply(null, args); | ||
| 466 | + return ReflectApply(block, null, args); | ||
| 466 | 467 | // CHECK(NumberIsSafeInteger(triggerAsyncId)) | |
| 467 | 468 | // CHECK(triggerAsyncId > 0) | |
| 468 | 469 | const oldDefaultTriggerAsyncId = async_id_fields[kDefaultTriggerAsyncId]; | |
| 469 | 470 | async_id_fields[kDefaultTriggerAsyncId] = triggerAsyncId; | |
| 470 | 471 | ||
| 471 | 472 | try { | |
| 472 | - return block.apply(null, args); | ||
| 473 | + return ReflectApply(block, null, args); | ||
| 473 | 474 | } finally { | |
| 474 | 475 | async_id_fields[kDefaultTriggerAsyncId] = oldDefaultTriggerAsyncId; | |
| 475 | 476 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ const { | |||
| 6 | 6 | JSONParse, | |
| 7 | 7 | ObjectAssign, | |
| 8 | 8 | ObjectPrototypeHasOwnProperty, | |
| 9 | - ReflectApply, | ||
| 10 | 9 | SafeArrayIterator, | |
| 11 | 10 | SafeMap, | |
| 12 | 11 | SafeSet, | |
@@ -193,8 +192,8 @@ function loadCJSModule(module, source, url, filename, isMain) { | |||
| 193 | 192 | }); | |
| 194 | 193 | setOwnProperty(requireFn, 'main', process.mainModule); | |
| 195 | 194 | ||
| 196 | - ReflectApply(compiledWrapper, module.exports, | ||
| 197 | - [module.exports, requireFn, module, filename, __dirname]); | ||
| 195 | + FunctionPrototypeCall(compiledWrapper, module.exports, | ||
| 196 | + module.exports, requireFn, module, filename, __dirname); | ||
| 198 | 197 | setOwnProperty(module, 'loaded', true); | |
| 199 | 198 | } | |
| 200 | 199 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | const { | |
| 7 | 7 | Promise, | |
| 8 | 8 | PromisePrototypeThen, | |
| 9 | + ReflectApply, | ||
| 9 | 10 | SymbolDispose, | |
| 10 | 11 | } = primordials; | |
| 11 | 12 | ||
@@ -272,7 +273,7 @@ function eos(stream, options, callback) { | |||
| 272 | 273 | const originalCallback = callback; | |
| 273 | 274 | callback = once((...args) => { | |
| 274 | 275 | disposable[SymbolDispose](); | |
| 275 | - originalCallback.apply(stream, args); | ||
| 276 | + ReflectApply(originalCallback, stream, args); | ||
| 276 | 277 | }); | |
| 277 | 278 | } | |
| 278 | 279 | } | |
@@ -296,13 +297,13 @@ function eosWeb(stream, options, callback) { | |||
| 296 | 297 | const originalCallback = callback; | |
| 297 | 298 | callback = once((...args) => { | |
| 298 | 299 | disposable[SymbolDispose](); | |
| 299 | - originalCallback.apply(stream, args); | ||
| 300 | + ReflectApply(originalCallback, stream, args); | ||
| 300 | 301 | }); | |
| 301 | 302 | } | |
| 302 | 303 | } | |
| 303 | 304 | const resolverFn = (...args) => { | |
| 304 | 305 | if (!isAborted) { | |
| 305 | - process.nextTick(() => callback.apply(stream, args)); | ||
| 306 | + process.nextTick(() => ReflectApply(callback, stream, args)); | ||
| 306 | 307 | } | |
| 307 | 308 | }; | |
| 308 | 309 | PromisePrototypeThen( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ const { | |||
| 30 | 30 | ObjectKeys, | |
| 31 | 31 | ObjectSetPrototypeOf, | |
| 32 | 32 | Promise, | |
| 33 | + ReflectApply, | ||
| 33 | 34 | SafeSet, | |
| 34 | 35 | Symbol, | |
| 35 | 36 | SymbolAsyncDispose, | |
@@ -1182,8 +1183,7 @@ Readable.prototype.removeListener = function(ev, fn) { | |||
| 1182 | 1183 | Readable.prototype.off = Readable.prototype.removeListener; | |
| 1183 | 1184 | ||
| 1184 | 1185 | Readable.prototype.removeAllListeners = function(ev) { | |
| 1185 | - const res = Stream.prototype.removeAllListeners.apply(this, | ||
| 1186 | - arguments); | ||
| 1186 | + const res = ReflectApply(Stream.prototype.removeAllListeners, this, arguments); | ||
| 1187 | 1187 | ||
| 1188 | 1188 | if (ev === 'readable' || ev === undefined) { | |
| 1189 | 1189 | // We need to check if there is someone still listening to | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ const { | |||
| 5 | 5 | ArrayPrototypeIncludes, | |
| 6 | 6 | DatePrototypeGetTime, | |
| 7 | 7 | DatePrototypeToString, | |
| 8 | - FunctionPrototypeApply, | ||
| 9 | 8 | FunctionPrototypeBind, | |
| 10 | 9 | FunctionPrototypeToString, | |
| 11 | 10 | NumberIsNaN, | |
@@ -14,6 +13,7 @@ const { | |||
| 14 | 13 | ObjectGetOwnPropertyDescriptor, | |
| 15 | 14 | ObjectGetOwnPropertyDescriptors, | |
| 16 | 15 | PromiseWithResolvers, | |
| 16 | + ReflectApply, | ||
| 17 | 17 | Symbol, | |
| 18 | 18 | SymbolDispose, | |
| 19 | 19 | globalThis, | |
@@ -645,7 +645,7 @@ class MockTimers { | |||
| 645 | 645 | let timer = this.#executionQueue.peek(); | |
| 646 | 646 | while (timer) { | |
| 647 | 647 | if (timer.runAt > this.#now) break; | |
| 648 | - FunctionPrototypeApply(timer.callback, undefined, timer.args); | ||
| 648 | + ReflectApply(timer.callback, undefined, timer.args); | ||
| 649 | 649 | ||
| 650 | 650 | // Check if the timeout was cleared by calling clearTimeout inside its own callback | |
| 651 | 651 | const afterCallback = this.#executionQueue.peek(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments