-
Notifications
You must be signed in to change notification settings - Fork 5
Diary - JS scope insulation #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How to make the window properties exposed as global( in EPA scope ) objects? The pill is sweater due to the fact that initial window content could be used for populating the scope. Later changes on window and global variables still needed but is not a usual case, so it could be ignored for now. From security stand of point it does not weaken the insulation, except of ability to detect EPA environment. Which is possible in multiple other ways anyway. The |
How to trap global location object assignment? While the window.location="someUrl" could be overridden using setter of window object property, the "global" in the EPA scope 'location' object could not have a setter associated. Unless the name resolution is involving the with operator: |
At this stage the solution chosen for |
While thinking on window management in Frame names are scoped by browser identity session, which is usually either global and incognito. Which is definitely insufficient as multiple identities could be used and better not correlate between each other. To avoid cross-identity session overlap, in The main window will have a collection of top level |
|
All scripts inside of meant to run in same scope, meaning sharing the global
To make the insulated from container windows scope, scripts are executing within In order to share same scope each sub-script or poc/global-scope.html covers that behavior. |
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
1st method will use shared set of global variables, only sync window.xxx assignment with variables is needed.
2nd method
Common:
|
Global script handling
|
Async/defer scripts |
Most popular global variables
A good start to collect js libs with globals is |
Unifying JS under single script allows a single variables list sharing. But concatenation of multiple files conflicts with import module statements which meant to be used ONLY in beginning of JS file, definitely not in try{} scope closure ( What could be done further?
Intermediate (though more complex) solution, matching browser script loading convention :
From MDN formats of static import is limited to:
|
Individual script loading seems to be quite attractive.
CONS: Synchronization of globals across all scripts scopes
With SOLUTION: Sync code exposed as local method and called
The list of variables would be collected by loading all scripts before execution, saved into The scope would register itself in
|
Rather using |
sequential execution of SCRIPT type="module" saved the hassle of hooking into last script execution. 'load' event is emitted on |
Since each SCRIPT has own context with simulated list of global variables, functions would reside in own script closure. When functions used from another module, globals would be visible as local to script scope. Which mean
The top level SCRIPT functions would be trapped by SCRIPT wrapper ( Question of populating scope of caller is open for now. |
Apparently when calling the function from another scope the marshaling of variables needed in both scopes. Otherwise upon return from caller scope the callee scope variables not updated. The call sequence would be:
|
Each top level function( assuming it is not dynamically changed variable ) need to be surrounded by wrapper in each scope only once.
|
embed-page.loadCount |
Scripts inlining
The scoped |
Tricks to implement.
|
Performance issues due to unified variables treatment While in rev 0.0.20 the global variables defined in script and in event attribute level are handled more or less properly, the implementation suffers from quite a bit of overhead:
|
To make global variables sync more efficient:
|
Variables handling sequence
|
Import vars as globals Access to such APIs are valuable in event handlers but there is not much use in duplication the import statement in SCRIPT and within inline event handler. Hence, event handler could have a good use of import declaration when located
To minimize the number of SCRIPT tags, the event handlers could fit into the end of last SCRIPT within |
Globals in event handlers It means the body of event handler should be scanned in same fashion for globals as SCRIPT content. |
EPA /
embed-page
notes on JS scope, window and application security of scope insulation.anonymous
default scope makes complete insulationnone
is a global scope, no insulation. Useful for html includescope="xxx"
named. Variables and API are shared between scope with same nameHow to hide the page scope(global) JS objects and substitute those with own implementation?
eval() with closure-defined global ovverrides appeared to be a way to make embed-page content insulation from host page. Here are the notes on implementation evolution.
The text was updated successfully, but these errors were encountered: