use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class WrapperProxy method CreateWrapProxy.
/**
* (extension): CreateWrapProxy
*
* @param cx
* the execution context
* @param target
* the proxy target object
* @param proto
* the proxy protoype object
* @return the new wrapper proxy
*/
public static WrapperProxy CreateWrapProxy(ExecutionContext cx, Object target, Object proto) {
if (!Type.isObject(target)) {
throw newTypeError(cx, Messages.Key.NotObjectType);
}
if (!Type.isObjectOrNull(proto)) {
throw newTypeError(cx, Messages.Key.NotObjectOrNull);
}
ScriptObject proxyTarget = Type.objectValue(target);
ScriptObject prototype = Type.objectValueOrNull(proto);
WrapperProxy proxy;
if (IsCallable(proxyTarget)) {
proxy = new CallableWrapperProxy((Callable) proxyTarget, prototype);
} else {
proxy = new WrapperProxy(proxyTarget, prototype);
}
return proxy;
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, long propertyKey, Object value, Object receiver) {
/* modified 9.1.9 [[Set] (P, V, Receiver) */
Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
if (ownDesc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent != null) {
return parent.set(cx, propertyKey, value, receiver);
} else {
ownDesc = new Property(UNDEFINED, true, true, true);
}
}
if (ownDesc.isDataDescriptor()) {
if (!ownDesc.isWritable()) {
return false;
}
if (!Type.isObject(receiver)) {
return false;
}
ScriptObject _receiver = Type.objectValue(receiver);
Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
if (existingDescriptor != null) {
PropertyDescriptor valueDesc = new PropertyDescriptor(value);
return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
} else {
return CreateDataProperty(cx, _receiver, propertyKey, value);
}
}
assert ownDesc.isAccessorDescriptor();
Callable setter = ownDesc.getSetter();
if (setter == null) {
return false;
}
setter.call(cx, receiver, value);
return true;
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class Interpreter method EvaluateCall.
/**
* 12.3.4.2 Runtime Semantics: EvaluateCall( ref, arguments, tailPosition )<br>
* 12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
*
* @param ref
* the call base reference
* @param arguments
* the function call arguments
* @param directEval
* the direct eval flag
* @param cx
* the execution context
* @return the return value after applying the call operation
*/
private Object EvaluateCall(Object ref, List<Expression> arguments, boolean directEval, ExecutionContext cx) {
/* steps 1-2 (EvaluateCall) */
Object func = GetValue(ref, cx);
/* steps 3-4 (EvaluateCall) */
Object thisValue = UNDEFINED;
if (ref instanceof Reference) {
Reference<?, ?> rref = (Reference<?, ?>) ref;
if (rref.isPropertyReference()) {
thisValue = rref.getThisValue();
} else if (!(rref instanceof Reference.BindingReference)) {
assert rref instanceof Reference.IdentifierReference;
Reference.IdentifierReference<?> idref = (Reference.IdentifierReference<?>) rref;
ScriptObject newThisValue = idref.getBase().withBaseObject();
if (newThisValue != null) {
thisValue = newThisValue;
}
}
}
/* steps 1-2 (EvaluateDirectCall) */
Object[] argList = ArgumentListEvaluation(arguments, cx);
/* steps 3-4 (EvaluateDirectCall) */
Callable f = CheckCallable(func, cx);
/* [12.3.4.1 Runtime Semantics: Evaluation - step 3] */
if (directEval && IsBuiltinEval(ref, f, cx)) {
int evalFlags = EvalFlags.Direct.getValue();
if (strict) {
evalFlags |= EvalFlags.Strict.getValue();
}
evalFlags |= EvalFlags.toFlags(parserOptions);
return Eval.directEval(argList, cx, evalFlags);
}
if (directEval && ScriptRuntime.directEvalFallbackHook(cx) != null) {
argList = ScriptRuntime.directEvalFallbackArguments(f, cx, thisValue, argList);
thisValue = ScriptRuntime.directEvalFallbackThisArgument(cx);
f = ScriptRuntime.directEvalFallbackHook(cx);
}
/* steps 6, 9 (EvaluateDirectCall) */
return f.call(cx, thisValue, argList);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class AsyncGeneratorAbstractOperations method GetAsyncIterator.
/**
* GetIterator ( obj [ , hint ] )
*
* @param cx
* the execution context
* @param obj
* the script object
* @return the script iterator object
*/
public static ScriptObject GetAsyncIterator(ExecutionContext cx, Object obj) {
/* steps 1-2 (not applicable) */
/* step 3 */
Callable method = GetMethod(cx, obj, BuiltinSymbol.asyncIterator.get());
/* step 5 (inlined Call operation) */
if (method == null) {
throw newTypeError(cx, Messages.Key.PropertyNotCallable, BuiltinSymbol.asyncIterator.toString());
}
Object iterator = method.call(cx, obj);
/* step 6 */
if (!Type.isObject(iterator)) {
throw newTypeError(cx, Messages.Key.NotObjectTypeReturned, "[Symbol.asyncIterator]");
}
/* step 7 */
return Type.objectValue(iterator);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class TypedArrayConstructorPrototype method IterableToArrayLike.
/**
* 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items )
*
* @param cx
* the execution context
* @param items
* the items object
* @return the items list
*/
public static List<Object> IterableToArrayLike(ExecutionContext cx, Object items) {
/* step 1 */
Callable usingIterator = GetMethod(cx, items, BuiltinSymbol.iterator.get());
/* step 2 */
if (usingIterator != null) {
/* step 2.a */
ScriptIterator<?> iterator = GetScriptIterator(cx, items, usingIterator);
/* step 2.b */
ArrayList<Object> values = new ArrayList<>();
/* steps 2.c-d */
while (iterator.hasNext()) {
Object nextValue = iterator.next();
values.add(nextValue);
}
/* step 2.e */
return values;
}
/* step 4 */
return new ScriptArrayList(cx, ToObject(cx, items));
}
Aggregations