icestark
icestark copied to clipboard
A way to reduce the count of proxy's `get` trap in sandbox
Background
As we know, Symbol.unscopables can be defined on any object to exclude property names from being exposed as lexical variables in with environment bindings.
As a result, Symbol.unscopables will be also trapped by proxy's get handler.
Just to name an example: what's going on when executing Math.random() in sandbox.
hashandler to determine wetherMath.random()should fall intogethandler- Then,
Symbol.unscopableswas trapped in thegethandler - Finally,
Mathwas trapped in thegethandler
As proxy's traps are expensive, there should be a way to prevent global variables falling into get handler.
A live example should be shown to demonstrate why global variables are worthy of attention.