556 public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException {
557 final ScriptObject oldGlobal = getGlobalTrusted();
558 final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() {
559 @Override
560 public ScriptObject run() {
561 try {
562 return newGlobal();
563 } catch (final RuntimeException e) {
564 if (Context.DEBUG) {
565 e.printStackTrace();
566 }
567 throw e;
568 }
569 }
570 }, CREATE_GLOBAL_ACC_CTXT);
571 // initialize newly created Global instance
572 initGlobal(newGlobal);
573 setGlobalTrusted(newGlobal);
574
575 final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal);
576 newGlobal.put("arguments", ((GlobalObject)newGlobal).wrapAsObject(wrapped));
577
578 try {
579 // wrap objects from newGlobal's world as mirrors - but if result
580 // is from oldGlobal's world, unwrap it!
581 return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal);
582 } finally {
583 setGlobalTrusted(oldGlobal);
584 }
585 }
586
587 /**
588 * Load or get a structure class. Structure class names are based on the number of parameter fields
589 * and {@link AccessorProperty} fields in them. Structure classes are used to represent ScriptObjects
590 *
591 * @see ObjectClassGenerator
592 * @see AccessorProperty
593 * @see ScriptObject
594 *
595 * @param fullName full name of class, e.g. jdk.nashorn.internal.objects.JO2P1 contains 2 fields and 1 parameter.
596 *
|
556 public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException {
557 final ScriptObject oldGlobal = getGlobalTrusted();
558 final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() {
559 @Override
560 public ScriptObject run() {
561 try {
562 return newGlobal();
563 } catch (final RuntimeException e) {
564 if (Context.DEBUG) {
565 e.printStackTrace();
566 }
567 throw e;
568 }
569 }
570 }, CREATE_GLOBAL_ACC_CTXT);
571 // initialize newly created Global instance
572 initGlobal(newGlobal);
573 setGlobalTrusted(newGlobal);
574
575 final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal);
576 newGlobal.put("arguments", ((GlobalObject)newGlobal).wrapAsObject(wrapped), env._strict);
577
578 try {
579 // wrap objects from newGlobal's world as mirrors - but if result
580 // is from oldGlobal's world, unwrap it!
581 return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal);
582 } finally {
583 setGlobalTrusted(oldGlobal);
584 }
585 }
586
587 /**
588 * Load or get a structure class. Structure class names are based on the number of parameter fields
589 * and {@link AccessorProperty} fields in them. Structure classes are used to represent ScriptObjects
590 *
591 * @see ObjectClassGenerator
592 * @see AccessorProperty
593 * @see ScriptObject
594 *
595 * @param fullName full name of class, e.g. jdk.nashorn.internal.objects.JO2P1 contains 2 fields and 1 parameter.
596 *
|