Global scope insulation POC


| |
In each scope: | |
The SCRIPT type=module (scope 2 here) has proper insulation without the need for recover own context(globals) before running event handler. It also support the 'import' syntax for modules and ability to override window object as local const variable as Proxy trapping the window.XXX assignment and evaluating as variable in local scope.

Scripts and event handlers

In order to reuse the scope, content of script tags and event handlers should be executed in same scope. Which could be achieved either by
* running all code within single SCRIPT tag associated with embed-page.
* wrapping each script with all pre- post- processing
    

Global script handling

  1. Collect all scripts code, extract all variables as keywords with exception of
  • JS keywords
  • "clean" window properties from blank iframe window
  • EPA_ prefixed variables
  • EpaWindow properties
  1. in rendered script declare all collected variables.
  2. clone all EpaWindow properties into variables.
    For each script code
  3. temporary clear container window properties to avoid leaking container globals into embed-page scope
  • preserve "unclean" window properties
  • remove those properties from window
  1. in try{ section insert code }
  2. catch(ex){ console.error(ex)} will permit to run following SCRIPTs
  3. finally{}
  • move added to container window properties into EpaWindow ( detect by comparing with reference iframe )
  • restore container window properties
  1. For each onXXX attribute
  • in try section set event handler
  • in event handler body insert code as in 4-7