Skip to content

Commit

Permalink
util: extract uncurryThis function for reuse
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ZYSzys authored and targos committed Mar 30, 2019
1 parent 169f3f7 commit 21486e5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
12 changes: 12 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ function once(callback) {
};
}

const ReflectApply = Reflect.apply;

// This function is borrowed from the function with the same name on V8 Extras'
// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
// with the spread syntax, such that no additional special case is needed for
// function calls w/o arguments.
// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}

module.exports = {
assertCrypto,
cachedResult,
Expand All @@ -405,6 +416,7 @@ module.exports = {
promisify,
spliceOne,
removeColors,
uncurryThis,

// Symbol used to customize promisify conversion
customPromisifyArgs: kCustomPromisifyArgsSymbol,
Expand Down
7 changes: 1 addition & 6 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ const {
ONLY_ENUMERABLE
}
} = internalBinding('util');

const ReflectApply = Reflect.apply;

function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}
const { uncurryThis } = require('internal/util');

const kStrict = true;
const kLoose = false;
Expand Down
14 changes: 2 additions & 12 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {
customInspectSymbol,
isError,
join,
removeColors
removeColors,
uncurryThis
} = require('internal/util');

const {
Expand Down Expand Up @@ -63,17 +64,6 @@ const {
isBigUint64Array
} = require('internal/util/types');

const ReflectApply = Reflect.apply;

// This function is borrowed from the function with the same name on V8 Extras'
// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
// with the spread syntax, such that no additional special case is needed for
// function calls w/o arguments.
// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}

const propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable);
const regExpToString = uncurryThis(RegExp.prototype.toString);
const dateToISOString = uncurryThis(Date.prototype.toISOString);
Expand Down
11 changes: 1 addition & 10 deletions lib/internal/util/types.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
'use strict';

const ReflectApply = Reflect.apply;

// This function is borrowed from the function with the same name on V8 Extras'
// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
// with the spread syntax, such that no additional special case is needed for
// function calls w/o arguments.
// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}
const { uncurryThis } = require('internal/util');

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

Expand Down
6 changes: 1 addition & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ const {
deprecate,
getSystemErrorName: internalErrorName,
promisify,
uncurryThis
} = require('internal/util');

const ReflectApply = Reflect.apply;

function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}
const objectToString = uncurryThis(Object.prototype.toString);

let internalDeepEqual;
Expand Down

0 comments on commit 21486e5

Please sign in to comment.