Search in sources :

Example 36 with Callable

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;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 37 with Callable

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;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 38 with Callable

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);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Reference(com.github.anba.es6draft.runtime.types.Reference) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) CheckCallable(com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 39 with Callable

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);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PromiseObject(com.github.anba.es6draft.runtime.objects.promise.PromiseObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 40 with Callable

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));
}
Also used : ArrayList(java.util.ArrayList) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

Callable (com.github.anba.es6draft.runtime.types.Callable)59 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)49 Property (com.github.anba.es6draft.runtime.types.Property)26 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)10 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)7 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)7 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)6 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 ArrayList (java.util.ArrayList)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)2 Realm (com.github.anba.es6draft.runtime.Realm)2 PromiseObject (com.github.anba.es6draft.runtime.objects.promise.PromiseObject)2 com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 Abrupt (com.github.anba.es6draft.ast.AbruptNode.Abrupt)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 ModuleScope (com.github.anba.es6draft.ast.scope.ModuleScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 ScriptScope (com.github.anba.es6draft.ast.scope.ScriptScope)1