use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class ScriptEngineImpl method invoke.
private Object invoke(ScriptObject thisValue, String name, Object... args) throws javax.script.ScriptException, NoSuchMethodException {
Realm realm = getEvalRealm(context);
RuntimeContext runtimeContext = realm.getWorld().getContext();
Console console = runtimeContext.getConsole();
runtimeContext.setConsole(new ScriptingConsole(context));
try {
Object[] arguments = TypeConverter.fromJava(args);
if (thisValue == null) {
thisValue = realm.getGlobalThis();
}
ExecutionContext cx = realm.defaultContext();
Object func = thisValue.get(cx, name, thisValue);
if (!IsCallable(func)) {
throw new NoSuchMethodException(name);
}
Object result = ((Callable) func).call(cx, thisValue, arguments);
realm.getWorld().runEventLoop();
return TypeConverter.toJava(result);
} catch (ScriptException e) {
throw new javax.script.ScriptException(e);
} finally {
runtimeContext.setConsole(console);
}
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class OrdinaryFunction method AddRestrictedFunctionProperties.
/**
* 9.2.7 AddRestrictedFunctionProperties ( F, realm )
*
* @param <FUNCTION>
* the function type
* @param f
* the function object
* @param realm
* the realm object
*/
public static <FUNCTION extends OrdinaryObject & Callable> void AddRestrictedFunctionProperties(FUNCTION f, Realm realm) {
/* steps 1-2 */
Callable thrower = realm.getThrowTypeError();
/* steps 3-4 */
f.infallibleDefineOwnProperty("caller", new Property(thrower, thrower, false, true));
/* steps 5-6 */
f.infallibleDefineOwnProperty("arguments", new Property(thrower, thrower, false, true));
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class BoundFunctionObject method call.
/**
* 9.4.1.1 [[Call]] (thisArgument, argumentsList)
*/
@Override
public final Object call(ExecutionContext callerContext, Object thisValue, Object... argumentsList) {
/* step 1 */
Callable target = getFlattenedTargetFunction();
/* step 2 */
Object boundThis = getBoundThis();
/* step 3 */
Object[] boundArgs = getBoundArguments();
/* step 4 */
Object[] args = concatArguments(callerContext, boundArgs, argumentsList);
/* step 5 */
return target.call(callerContext, boundThis, args);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class BoundFunctionObject method tailCall.
/**
* 9.4.1.1 [[Call]] (thisArgument, argumentsList)
*/
@Override
public final Object tailCall(ExecutionContext callerContext, Object thisValue, Object... argumentsList) throws Throwable {
/* step 1 */
Callable target = getFlattenedTargetFunction();
/* step 2 */
Object boundThis = getBoundThis();
/* step 3 */
Object[] boundArgs = getBoundArguments();
/* step 4 */
Object[] args = concatArguments(callerContext, boundArgs, argumentsList);
/* step 5 */
return target.tailCall(callerContext, boundThis, args);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class OrdinaryObject method getValue.
/**
* 9.1.8 [[Get]] (P, Receiver)
*
* @param cx
* the execution context
* @param propertyKey
* the property key
* @param receiver
* the receiver object
* @return the property value
*/
protected Object getValue(ExecutionContext cx, String propertyKey, Object receiver) {
/* step 1 (implicit) */
/* steps 2-3 */
Property desc = getProperty(cx, propertyKey);
/* step 4 */
if (desc == null) {
ScriptObject parent = getPrototypeOf(cx);
if (parent == null) {
return UNDEFINED;
}
return parent.get(cx, propertyKey, receiver);
}
/* step 5 */
if (desc.isDataDescriptor()) {
return desc.getValue();
}
assert desc.isAccessorDescriptor();
/* step 6 */
Callable getter = desc.getGetter();
/* step 7 */
if (getter == null) {
return UNDEFINED;
}
/* step 8 */
return getter.call(cx, receiver, EMPTY_GETTER_ARGS);
}
Aggregations