src/jdk/nashorn/internal/runtime/ScriptRuntime.java
Print this page
*** 350,388 ****
global.addBoundProperties(scope);
return global;
}
/**
- * Check that the target function is associated with current Context. And also make sure that 'self', if
- * ScriptObject, is from current context.
- *
- * Call a function given self and args. If the number of the arguments is known in advance, you can likely achieve
- * better performance by {@link Bootstrap#createDynamicInvoker(String, Class, Class...) creating a dynamic invoker}
- * for operation {@code "dyn:call"}, then using its {@link MethodHandle#invokeExact(Object...)} method instead.
- *
- * @param target ScriptFunction object.
- * @param self Receiver in call.
- * @param args Call arguments.
- * @return Call result.
- */
- public static Object checkAndApply(final ScriptFunction target, final Object self, final Object... args) {
- final ScriptObject global = Context.getGlobalTrusted();
- assert (global instanceof GlobalObject): "No current global set";
-
- if (target.getContext() != global.getContext()) {
- throw new IllegalArgumentException("'target' function is not from current Context");
- }
-
- if (self instanceof ScriptObject && ((ScriptObject)self).getContext() != global.getContext()) {
- throw new IllegalArgumentException("'self' object is not from current Context");
- }
-
- // all in order - call real 'apply'
- return apply(target, self, args);
- }
-
- /**
* Call a function given self and args. If the number of the arguments is known in advance, you can likely achieve
* better performance by {@link Bootstrap#createDynamicInvoker(String, Class, Class...) creating a dynamic invoker}
* for operation {@code "dyn:call"}, then using its {@link MethodHandle#invokeExact(Object...)} method instead.
*
* @param target ScriptFunction object.
--- 350,359 ----
*** 399,430 ****
throw new RuntimeException(t);
}
}
/**
- * Check that the target function is associated with current Context.
- * And also make sure that 'self', if ScriptObject, is from current context.
- *
- * Call a function as a constructor given args.
- *
- * @param target ScriptFunction object.
- * @param args Call arguments.
- * @return Constructor call result.
- */
- public static Object checkAndConstruct(final ScriptFunction target, final Object... args) {
- final ScriptObject global = Context.getGlobalTrusted();
- assert (global instanceof GlobalObject): "No current global set";
-
- if (target.getContext() != global.getContext()) {
- throw new IllegalArgumentException("'target' function is not from current Context");
- }
-
- // all in order - call real 'construct'
- return construct(target, args);
- }
-
- /**
* Call a script function as a constructor with given args.
*
* @param target ScriptFunction object.
* @param args Call arguments.
* @return Constructor call result.
--- 370,379 ----
*** 518,530 ****
throw typeError(global, "cant.apply.with.to.undefined");
} else if (expression == null) {
throw typeError(global, "cant.apply.with.to.null");
}
! final ScriptObject withObject = new WithObject(scope, JSType.toScriptObject(global, expression));
! return withObject;
}
/**
* Exiting a {@code with} node requires restoring scope. This is the implementation
*
--- 467,482 ----
throw typeError(global, "cant.apply.with.to.undefined");
} else if (expression == null) {
throw typeError(global, "cant.apply.with.to.null");
}
! final Object wrappedExpr = JSType.toScriptObject(global, expression);
! if (wrappedExpr instanceof ScriptObject) {
! return new WithObject(scope, (ScriptObject)wrappedExpr);
! }
! throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
/**
* Exiting a {@code with} node requires restoring scope. This is the implementation
*
*** 532,542 ****
*
* @return restored scope
*/
public static ScriptObject closeWith(final ScriptObject scope) {
if (scope instanceof WithObject) {
! return scope.getProto();
}
return scope;
}
/**
--- 484,494 ----
*
* @return restored scope
*/
public static ScriptObject closeWith(final ScriptObject scope) {
if (scope instanceof WithObject) {
! return ((WithObject)scope).getParentScope();
}
return scope;
}
/**