JS Proxy sentinal

2019-09-13

If you ever want to figure out where a value ends up being used, this may come in handy :)

Code:
new Proxy({}, {
getPrototypeOf: () => {throw new Error('poisoned getPrototypeOf')},
setPrototypeOf: () => {throw new Error('poisoned setPrototypeOf')},
isExtensible: () => {throw new Error('poisoned isExtensible')},
preventExtensions: () => {throw new Error('poisoned preventExtensions')},
getOwnPropertyDescriptor: () => {throw new Error('poisoned getOwnPropertyDescriptor')},
defineProperty: () => {throw new Error('poisoned defineProperty')},
has: () => {throw new Error('poisoned has')},
get: () => {throw new Error('poisoned get')},
set: () => {throw new Error('poisoned set')},
deleteProperty: () => {throw new Error('poisoned deleteProperty')},
ownKeys: () => {throw new Error('poisoned ownKeys')},
apply: () => {throw new Error('poisoned apply')},
construct: () => {throw new Error('poisoned construct')},
})

This sets every trap that Proxy supports to a callback that throws. Meaning pretty much any read/write operation on the sentinal will trigger an error which you can investigate.

Happy hunting :)