Search in sources :

Example 76 with ScriptObject

use of com.github.anba.es6draft.runtime.types.ScriptObject 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 77 with ScriptObject

use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.

the class Realm method SetDefaultGlobalBindings.

/**
     * 8.2.4 SetDefaultGlobalBindings ( realmRec )
     * <p>
     * Initializes {@code [[globalObject]]} with the default properties of the Global Object.
     * 
     * @param cx
     *            the execution context
     * @param realm
     *            the realm instance
     * @return the global object
     */
public static ScriptObject SetDefaultGlobalBindings(ExecutionContext cx, Realm realm) {
    /* step 1 */
    ScriptObject globalObject = realm.getGlobalObject();
    GlobalObject globalTemplate = realm.getGlobalObjectTemplate();
    assert globalObject != null && globalTemplate != null;
    /* step 2 */
    for (Object key : globalTemplate.ownPropertyKeys(cx)) {
        Property prop = globalTemplate.getOwnProperty(cx, key);
        if (prop != null) {
            PropertyDescriptor desc = prop.toPropertyDescriptor();
            DefinePropertyOrThrow(cx, globalObject, key, desc);
        }
    }
    /* step 3 */
    return globalObject;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) SystemObject(com.github.anba.es6draft.runtime.objects.reflect.SystemObject) AtomicsObject(com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject) MathObject(com.github.anba.es6draft.runtime.objects.number.MathObject) ReflectObject(com.github.anba.es6draft.runtime.objects.reflect.ReflectObject) IntlObject(com.github.anba.es6draft.runtime.objects.intl.IntlObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) RealmObject(com.github.anba.es6draft.runtime.objects.reflect.RealmObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 78 with ScriptObject

use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.

the class ObjectEnvironmentRecord method getBindingValue.

/**
     * 8.1.1.2.6 GetBindingValue(N,S)
     */
@Override
public Object getBindingValue(String name, boolean strict) {
    /* step 1 (omitted) */
    /* step 2 */
    ScriptObject bindings = this.bindings;
    /* steps 3-4 */
    boolean foundBinding = HasProperty(cx, bindings, name);
    /* step 5 */
    if (!foundBinding) {
        if (!strict) {
            return UNDEFINED;
        }
        throw newReferenceError(cx, Messages.Key.UnresolvableReference, name);
    }
    /* step 6 */
    return Get(cx, bindings, name);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 79 with ScriptObject

use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.

the class ObjectEnvironmentRecord method hasBinding.

/**
     * 8.1.1.2.1 HasBinding(N)
     */
@Override
public boolean hasBinding(String name) {
    /* step 1 (omitted) */
    /* step 2 */
    ScriptObject bindings = this.bindings;
    /* steps 3-4 */
    boolean foundBinding = HasProperty(cx, bindings, name);
    /* step 5 */
    if (!foundBinding) {
        return false;
    }
    /* step 6 */
    if (!withEnvironment) {
        return true;
    }
    /* steps 7-8 */
    Object unscopables = Get(cx, bindings, BuiltinSymbol.unscopables.get());
    /* step 9 */
    if (Type.isObject(unscopables)) {
        boolean blocked = ToBoolean(Get(cx, Type.objectValue(unscopables), name));
        if (blocked) {
            return false;
        }
    }
    /* step 10 */
    return true;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 80 with ScriptObject

use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.

the class Properties method createExternalClass.

private static Constructor createExternalClass(ExecutionContext cx, String className, Class<?> constructorProperties, Class<?> prototypeProperties) {
    ObjectLayout ctorLayout = externalClassLayouts.get(constructorProperties);
    ObjectLayout protoLayout = externalClassLayouts.get(prototypeProperties);
    Converter converter = new Converter(cx);
    ScriptObject[] objects = ScriptRuntime.getDefaultClassProto(cx);
    ScriptObject constructorParent = objects[0];
    OrdinaryObject proto = (OrdinaryObject) objects[1];
    assert constructorParent == cx.getIntrinsic(Intrinsics.FunctionPrototype);
    OrdinaryObject constructor = createConstructor(cx, className, proto, converter, protoLayout);
    assert constructor instanceof Constructor;
    if (ctorLayout.functions != null) {
        createExternalFunctions(cx, constructor, ctorLayout, converter);
    }
    if (ctorLayout.accessors != null) {
        createExternalAccessors(cx, constructor, ctorLayout, converter);
    }
    if (protoLayout.functions != null) {
        createExternalFunctions(cx, proto, protoLayout, converter);
    }
    if (protoLayout.accessors != null) {
        createExternalAccessors(cx, proto, protoLayout, converter);
    }
    return (Constructor) constructor;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) NativeConstructor(com.github.anba.es6draft.runtime.types.builtins.NativeConstructor) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Aggregations

ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)129 Callable (com.github.anba.es6draft.runtime.types.Callable)43 Property (com.github.anba.es6draft.runtime.types.Property)32 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)26 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)21 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)16 Constructor (com.github.anba.es6draft.runtime.types.Constructor)11 Realm (com.github.anba.es6draft.runtime.Realm)9 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)9 ParserException (com.github.anba.es6draft.parser.ParserException)8 CompilationException (com.github.anba.es6draft.compiler.CompilationException)7 Source (com.github.anba.es6draft.runtime.internal.Source)7 ArrayList (java.util.ArrayList)7 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)6 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)6 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)6 Test (org.junit.Test)6 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)5 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)4 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)4