Java Code Examples for jdk.nashorn.internal.objects.Global#put()
The following examples show how to use
jdk.nashorn.internal.objects.Global#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Context.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }
Example 2
Source File: Context.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }
Example 3
Source File: Context.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }
Example 4
Source File: Context.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }
Example 5
Source File: Context.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }
Example 6
Source File: Context.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }
Example 7
Source File: Context.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
/** * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source * expression, after creating a new global scope. * * @param from source expression for script * @param args (optional) arguments to be passed to the loaded script * * @return return value for load call (undefined) * * @throws IOException if source cannot be found or loaded */ public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { final Global oldGlobal = getGlobal(); final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { try { return newGlobal(); } catch (final RuntimeException e) { if (Context.DEBUG) { e.printStackTrace(); } throw e; } } }, CREATE_GLOBAL_ACC_CTXT); // initialize newly created Global instance initGlobal(newGlobal); setGlobal(newGlobal); final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); try { // wrap objects from newGlobal's world as mirrors - but if result // is from oldGlobal's world, unwrap it! return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); } finally { setGlobal(oldGlobal); } }