util: extract uncurryThis function for reuse · nodejs/node@21486e5 (original) (raw)

5 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -385,6 +385,17 @@ function once(callback) {
385 385 };
386 386 }
387 387
388 +const ReflectApply = Reflect.apply;
389 +
390 +// This function is borrowed from the function with the same name on V8 Extras'
391 +// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
392 +// with the spread syntax, such that no additional special case is needed for
393 +// function calls w/o arguments.
394 +// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
395 +function uncurryThis(func) {
396 +return (thisArg, ...args) => ReflectApply(func, thisArg, args);
397 +}
398 +
388 399 module.exports = {
389 400 assertCrypto,
390 401 cachedResult,
@@ -405,6 +416,7 @@ module.exports = {
405 416 promisify,
406 417 spliceOne,
407 418 removeColors,
419 + uncurryThis,
408 420
409 421 // Symbol used to customize promisify conversion
410 422 customPromisifyArgs: kCustomPromisifyArgsSymbol,
Original file line number Diff line number Diff line change
@@ -22,12 +22,7 @@ const {
22 22 ONLY_ENUMERABLE
23 23 }
24 24 } = internalBinding('util');
25 -
26 -const ReflectApply = Reflect.apply;
27 -
28 -function uncurryThis(func) {
29 -return (thisArg, ...args) => ReflectApply(func, thisArg, args);
30 -}
25 +const { uncurryThis } = require('internal/util');
31 26
32 27 const kStrict = true;
33 28 const kLoose = false;
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@ const {
17 17 customInspectSymbol,
18 18 isError,
19 19 join,
20 - removeColors
20 + removeColors,
21 + uncurryThis
21 22 } = require('internal/util');
22 23
23 24 const {
@@ -63,17 +64,6 @@ const {
63 64 isBigUint64Array
64 65 } = require('internal/util/types');
65 66
66 -const ReflectApply = Reflect.apply;
67 -
68 -// This function is borrowed from the function with the same name on V8 Extras'
69 -// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
70 -// with the spread syntax, such that no additional special case is needed for
71 -// function calls w/o arguments.
72 -// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
73 -function uncurryThis(func) {
74 -return (thisArg, ...args) => ReflectApply(func, thisArg, args);
75 -}
76 -
77 67 const propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable);
78 68 const regExpToString = uncurryThis(RegExp.prototype.toString);
79 69 const dateToISOString = uncurryThis(Date.prototype.toISOString);
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
1 1 'use strict';
2 2
3 -const ReflectApply = Reflect.apply;
4 -
5 -// This function is borrowed from the function with the same name on V8 Extras'
6 -// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
7 -// with the spread syntax, such that no additional special case is needed for
8 -// function calls w/o arguments.
9 -// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
10 -function uncurryThis(func) {
11 -return (thisArg, ...args) => ReflectApply(func, thisArg, args);
12 -}
3 +const { uncurryThis } = require('internal/util');
13 4
14 5 const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
15 6
Original file line number Diff line number Diff line change
@@ -42,13 +42,9 @@ const {
42 42 deprecate,
43 43 getSystemErrorName: internalErrorName,
44 44 promisify,
45 + uncurryThis
45 46 } = require('internal/util');
46 47
47 -const ReflectApply = Reflect.apply;
48 -
49 -function uncurryThis(func) {
50 -return (thisArg, ...args) => ReflectApply(func, thisArg, args);
51 -}
52 48 const objectToString = uncurryThis(Object.prototype.toString);
53 49
54 50 let internalDeepEqual;