icestark icon indicating copy to clipboard operation
icestark copied to clipboard

A way to reduce the count of proxy's `get` trap in sandbox

Open maoxiaoke opened this issue 3 years ago • 0 comments

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.

  1. has handler to determine wether Math.random() should fall into get handler
  2. Then, Symbol.unscopables was trapped in the get handler
  3. Finally, Math was trapped in the get handler

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.

maoxiaoke avatar Apr 06 '22 07:04 maoxiaoke