Skip to content

Commit 21486e5

Browse files
ZYSzystargos
authored andcommittedMar 30, 2019
util: extract uncurryThis function for reuse
PR-URL: #23081 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 169f3f7 commit 21486e5

File tree

5 files changed

+17
-33
lines changed

5 files changed

+17
-33
lines changed
 

‎lib/internal/util.js

+12
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ function once(callback) {
385385
};
386386
}
387387

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+
388399
module.exports = {
389400
assertCrypto,
390401
cachedResult,
@@ -405,6 +416,7 @@ module.exports = {
405416
promisify,
406417
spliceOne,
407418
removeColors,
419+
uncurryThis,
408420

409421
// Symbol used to customize promisify conversion
410422
customPromisifyArgs: kCustomPromisifyArgsSymbol,

‎lib/internal/util/comparisons.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ const {
2222
ONLY_ENUMERABLE
2323
}
2424
} = 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');
3126

3227
const kStrict = true;
3328
const kLoose = false;

‎lib/internal/util/inspect.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const {
1717
customInspectSymbol,
1818
isError,
1919
join,
20-
removeColors
20+
removeColors,
21+
uncurryThis
2122
} = require('internal/util');
2223

2324
const {
@@ -63,17 +64,6 @@ const {
6364
isBigUint64Array
6465
} = require('internal/util/types');
6566

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-
7767
const propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable);
7868
const regExpToString = uncurryThis(RegExp.prototype.toString);
7969
const dateToISOString = uncurryThis(Date.prototype.toISOString);

‎lib/internal/util/types.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
'use strict';
22

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');
134

145
const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
156

‎lib/util.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ const {
4242
deprecate,
4343
getSystemErrorName: internalErrorName,
4444
promisify,
45+
uncurryThis
4546
} = require('internal/util');
4647

47-
const ReflectApply = Reflect.apply;
48-
49-
function uncurryThis(func) {
50-
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
51-
}
5248
const objectToString = uncurryThis(Object.prototype.toString);
5349

5450
let internalDeepEqual;

0 commit comments

Comments
 (0)
Please sign in to comment.