From 4f35a2407681717d1848a7764eaa02f772f7e65a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 10 Jul 2019 09:50:32 -0700 Subject: [PATCH] Use more allKeys(). --- src/safe/vm.js | 4 ++-- src/util/prepare-context.js | 4 ++-- src/util/safe-assign-properties.js | 29 ----------------------------- src/util/safe.js | 10 +++++----- 4 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 src/util/safe-assign-properties.js diff --git a/src/safe/vm.js b/src/safe/vm.js index 727bb8397..5d1162de0 100644 --- a/src/safe/vm.js +++ b/src/safe/vm.js @@ -1,7 +1,7 @@ +import allKeys from "../util/all-keys.js" import copyProperty from "../util/copy-property.js" import getPrototypeOf from "../util/get-prototype-of.js" import has from "../util/has.js" -import ownKeys from "../util/own-keys.js" import realVM from "../real/vm.js" import safe from "../util/safe.js" import setProperty from "../util/set-property.js" @@ -15,7 +15,7 @@ function init() { const SafeProto = SafeScript.prototype const contextifyProto = getPrototypeOf(Script.prototype) - const names = ownKeys(contextifyProto) + const names = allKeys(contextifyProto) for (const name of names) { if (! has(SafeProto, name)) { diff --git a/src/util/prepare-context.js b/src/util/prepare-context.js index f8bb4d455..bd26e2dc2 100644 --- a/src/util/prepare-context.js +++ b/src/util/prepare-context.js @@ -1,11 +1,11 @@ import { Script } from "../safe/vm.js" +import allKeys from "./all-keys.js" import { deprecate } from "../safe/util.js" import getPrototypeOf from "./get-prototype-of.js" import has from "./has.js" import instanceOf from "./instance-of.js" import isObjectLike from "./is-object-like.js" -import ownKeys from "./own-keys.js" import setPrototypeOf from "./set-prototype-of.js" import shared from "../shared.js" @@ -42,7 +42,7 @@ function init() { return context } - const names = ownKeys(defaultGlobal) + const names = allKeys(defaultGlobal) for (const name of names) { let descriptor diff --git a/src/util/safe-assign-properties.js b/src/util/safe-assign-properties.js deleted file mode 100644 index c022b1b53..000000000 --- a/src/util/safe-assign-properties.js +++ /dev/null @@ -1,29 +0,0 @@ -import ownKeys from "./own-keys.js" -import safeCopyProperty from "./safe-copy-property.js" -import shared from "../shared.js" - -function init() { - function safeAssignProperties(object) { - const { length } = arguments - - let i = 0 - - while (++i < length) { - const source = arguments[i] - const names = ownKeys(source) - - for (const name of names) { - safeCopyProperty(object, source, name) - } - } - - return object - } - - return safeAssignProperties -} - -export default shared.inited - ? shared.module.utilSafeAssignProperties - : shared.module.utilSafeAssignProperties = init() - diff --git a/src/util/safe.js b/src/util/safe.js index 4b09f3c0b..c6910f546 100644 --- a/src/util/safe.js +++ b/src/util/safe.js @@ -1,6 +1,6 @@ +import allKeys from "./all-keys.js" import isObject from "./is-object.js" -import ownKeys from "./own-keys.js" -import safeAssignProperties from "./safe-assign-properties.js" +import safeAssignPropertiesIn from "./safe-assign-properties-in.js" import safeCopyProperty from "./safe-copy-property.js" import setPrototypeOf from "./set-prototype-of.js" import shared from "../shared.js" @@ -13,7 +13,7 @@ function init() { } return isObject(value) - ? safeAssignProperties({}, value) + ? safeAssignPropertiesIn({}, value) : value } @@ -27,7 +27,7 @@ function init() { return result } - const SuperNames = ownKeys(Super) + const SuperNames = allKeys(Super) for (const name of SuperNames) { if (name !== "prototype") { @@ -38,7 +38,7 @@ function init() { const SafeProto = Safe.prototype setPrototypeOf(SafeProto, null) - safeAssignProperties(SafeProto, Super.prototype) + safeAssignPropertiesIn(SafeProto, Super.prototype) return Safe }