| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,27 @@ public static void main(String[] args) throws Exception { | |||
| 21 | 21 | // test4(); | |
| 22 | 22 | // test5(); | |
| 23 | 23 | // test6(); | |
| 24 | - test7(); | ||
| 24 | + // test7(); | ||
| 25 | + test8(); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + private static void test8() throws ScriptException { | ||
| 29 | + NashornScriptEngine engine = createEngine(); | ||
| 30 | + | ||
| 31 | + engine.eval("var obj = { foo: 23 };"); | ||
| 32 | + | ||
| 33 | + ScriptContext defaultContext = engine.getContext(); | ||
| 34 | + Bindings defaultBindings = defaultContext.getBindings(ScriptContext.ENGINE_SCOPE); | ||
| 35 | + | ||
| 36 | + SimpleScriptContext context1 = new SimpleScriptContext(); | ||
| 37 | + context1.setBindings(defaultBindings, ScriptContext.ENGINE_SCOPE); | ||
| 38 | + | ||
| 39 | + SimpleScriptContext context2 = new SimpleScriptContext(); | ||
| 40 | + context2.getBindings(ScriptContext.ENGINE_SCOPE).put("obj", defaultBindings.get("obj")); | ||
| 41 | + | ||
| 42 | + engine.eval("obj.foo = 44;", context1); | ||
| 43 | + engine.eval("print(obj.foo);", context1); | ||
| 44 | + engine.eval("print(obj.foo);", context2); | ||
| 25 | 45 | } | |
| 26 | 46 | ||
| 27 | 47 | private static void test7() throws ScriptException { | |
@@ -118,7 +138,10 @@ private static void test3() throws ScriptException { | |||
| 118 | 138 | private static void test2() throws ScriptException { | |
| 119 | 139 | NashornScriptEngine engine = createEngine(); | |
| 120 | 140 | engine.eval("function foo() { print('bar') };"); | |
| 121 | - engine.eval("foo();", new SimpleScriptContext()); | ||
| 141 | + | ||
| 142 | + SimpleScriptContext context = new SimpleScriptContext(); | ||
| 143 | + engine.eval("print(Function);", context); | ||
| 144 | + engine.eval("foo();", context); | ||
| 122 | 145 | } | |
| 123 | 146 | ||
| 124 | 147 | private static void test1() throws ScriptException { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments