Main entry point. Set up the shared scope and then spawn new threads that execute relative to that shared scope. Try to run functions with and without dynamic scope to see the effect. The expected output is sharedScope nested:sharedScope sharedScope nested:sharedScope sharedScope nest
(String[] args)
| 56 | * @param args the array of arguments |
| 57 | */ |
| 58 | public static void main(String[] args) { |
| 59 | Context cx = Context.enter(); |
| 60 | try { |
| 61 | // Precompile source only once |
| 62 | String source = |
| 63 | "" |
| 64 | + "var x = 'sharedScope';\n" |
| 65 | + "function f() { return x; }\n" |
| 66 | // Dynamic scope works with nested function too |
| 67 | + "function initClosure(prefix) {\n" |
| 68 | + " return function test() { return prefix+x; }\n" |
| 69 | + "}\n" |
| 70 | + "var closure = initClosure('nested:');\n" |
| 71 | + ""; |
| 72 | Script script = cx.compileString(source, "sharedScript", 1, null); |
| 73 | |
| 74 | useDynamicScope = false; |
| 75 | runScripts(cx, script); |
| 76 | useDynamicScope = true; |
| 77 | runScripts(cx, script); |
| 78 | } finally { |
| 79 | Context.exit(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static void runScripts(Context cx, Script script) { |
| 84 | // Initialize the standard objects (Object, Function, etc.) |
nothing calls this directly
no test coverage detected