Skip to content

Commit

Permalink
util: extract uncurryThis function for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYSzys committed Mar 19, 2019
1 parent 3e16eba commit 7dcf9bd
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 @@ -24,12 +24,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 @@ -68,17 +69,6 @@ const assert = require('internal/assert');
// Avoid monkey-patched built-ins.
const { Object } = primordials;

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 7dcf9bd

Please sign in to comment.