summaryrefslogtreecommitdiff
path: root/lib/internal
diff options
context:
space:
mode:
authorZYSzys <zyszys98@gmail.com>2019-03-19 14:00:49 +0800
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-21 23:07:48 +0100
commit5f032a7a269b66d48505869b0ae4fb1db403b118 (patch)
tree31a36eb4930ee6d4893111683b49eb1e2667f9ee /lib/internal
parent20fab5f5d49e952451e47c0d819268364ea5c7c5 (diff)
downloadandroid-node-v8-5f032a7a269b66d48505869b0ae4fb1db403b118.tar.gz
android-node-v8-5f032a7a269b66d48505869b0ae4fb1db403b118.tar.bz2
android-node-v8-5f032a7a269b66d48505869b0ae4fb1db403b118.zip
util: extract uncurryThis function for reuse
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/internal')
-rw-r--r--lib/internal/util.js12
-rw-r--r--lib/internal/util/comparisons.js7
-rw-r--r--lib/internal/util/inspect.js14
-rw-r--r--lib/internal/util/types.js11
4 files changed, 16 insertions, 28 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js
index bb2a101c4e..f5b5fbedd4 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -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,
@@ -405,6 +416,7 @@ module.exports = {
promisify,
spliceOne,
removeColors,
+ uncurryThis,
// Symbol used to customize promisify conversion
customPromisifyArgs: kCustomPromisifyArgsSymbol,
diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js
index 3470f20666..18fb790507 100644
--- a/lib/internal/util/comparisons.js
+++ b/lib/internal/util/comparisons.js
@@ -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;
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index dc97e6dceb..ca78425a52 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -17,7 +17,8 @@ const {
customInspectSymbol,
isError,
join,
- removeColors
+ removeColors,
+ uncurryThis
} = require('internal/util');
const {
@@ -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);
diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js
index 865818c661..f41d11443f 100644
--- a/lib/internal/util/types.js
+++ b/lib/internal/util/types.js
@@ -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);