Skip to content

Commit

Permalink
Move decoyProxy into OwnProxy().
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed May 6, 2019
1 parent 04cdca8 commit 82467e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/own/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ function init() {

OwnProxy.instances.set(proxy, [target, maskedHandler])

return proxy
// Wrap `proxy` in a decoy proxy so that `proxy` will be used as the
// unwrapped inspectable value.
const emptyHandler = {}
const decoyProxy = new Proxy(proxy, emptyHandler)

OwnProxy.instances.set(decoyProxy, [proxy, emptyHandler])

return decoyProxy
}
}

Expand Down
17 changes: 5 additions & 12 deletions src/util/proxy-inspectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import OwnProxy from "../own/proxy.js"

import assign from "./assign.js"
import builtinInspect from "../builtin/inspect.js"
import emptyObject from "./empty-object.js"
import getProxyDetails from "./get-proxy-details.js"
import isModuleNamespaceObject from "./is-module-namespace-object.js"
import isObjectLike from "./is-object-like.js"
Expand Down Expand Up @@ -47,8 +46,7 @@ function proxyInspectable(object, options, map) {

const proxy = new OwnProxy(object, {
get(object, name, receiver) {
if (receiver === decoyProxy ||
receiver === proxy) {
if (receiver === proxy) {
receiver = object
}

Expand Down Expand Up @@ -108,7 +106,7 @@ function proxyInspectable(object, options, map) {

contextAsOptions.showProxy = false

return safeInspect(decoyProxy, contextAsOptions)
return safeInspect(proxy, contextAsOptions)
}

return formatProxy(object, contextAsOptions)
Expand Down Expand Up @@ -140,15 +138,10 @@ function proxyInspectable(object, options, map) {
}
})

// Wrap `proxy` in a decoy proxy so that `proxy` will be used as the
// unwrapped value to inspect.
const decoyProxy = new OwnProxy(proxy, emptyObject)
map.set(object, proxy)
map.set(proxy, proxy)

map.set(object, decoyProxy)
map.set(proxy, decoyProxy)
map.set(decoyProxy, decoyProxy)

return decoyProxy
return proxy
}

function formatNamespaceObject(namespace, context) {
Expand Down

0 comments on commit 82467e3

Please sign in to comment.