Search in sources :

Example 86 with ScriptObject

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

the class ObjectConstructor method call.

/**
     * 19.1.1.1 Object ( [ value ] )
     */
@Override
public ScriptObject call(ExecutionContext callerContext, Object thisValue, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object value = argument(args, 0);
    /* step 2 */
    if (Type.isUndefinedOrNull(value)) {
        // (= `this`) is not the intrinsic %Object% constructor function.
        return OrdinaryCreateFromConstructor(calleeContext, this, Intrinsics.ObjectPrototype);
    }
    /* step 3 */
    return ToObject(calleeContext, value);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ImmutablePrototypeObject(com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 87 with ScriptObject

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

the class ObjectConstructor method EnumerableOwnProperties.

/**
     * EnumerableOwnProperties (O)
     * 
     * @param cx
     *            the execution context
     * @param object
     *            the script object
     * @param kind
     *            the property kind
     * @return <var>object</var>'s own enumerable properties
     */
static List<Object> EnumerableOwnProperties(ExecutionContext cx, ScriptObject object, PropertyKind kind) {
    /* step 1 (not applicable) */
    /* steps 2-3 */
    List<?> ownKeys = object.ownPropertyKeys(cx);
    /* step 4 */
    int initialSize = Math.min(16, ownKeys.size());
    ArrayList<Object> properties = new ArrayList<>(initialSize);
    /* step 5 */
    for (Object key : ownKeys) {
        if (key instanceof String) {
            String skey = (String) key;
            Property desc = object.getOwnProperty(cx, skey);
            if (desc != null && desc.isEnumerable()) {
                if (kind == PropertyKind.Key) {
                    properties.add(skey);
                } else {
                    Object value = Get(cx, object, skey);
                    if (kind == PropertyKind.Value) {
                        properties.add(value);
                    } else {
                        ArrayObject entry = CreateArrayFromList(cx, key, value);
                        properties.add(entry);
                    }
                }
            }
        }
    }
    /* step 7 */
    return properties;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ArrayList(java.util.ArrayList) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ImmutablePrototypeObject(com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 88 with ScriptObject

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

the class ObjectConstructor method GetOwnPropertySymbols.

/**
     * 19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type ), with Type = Symbol
     * 
     * @param cx
     *            the execution context
     * @param o
     *            the script object
     * @return the own symbol-valued property keys of <var>o</var>
     */
public static ArrayObject GetOwnPropertySymbols(ExecutionContext cx, Object o) {
    /* steps 1-2 */
    ScriptObject obj = ToObject(cx, o);
    /* steps 3-4 */
    List<?> keys = obj.ownPropertyKeys(cx);
    /* step 5 */
    int initialSize = Math.min(8, keys.size());
    ArrayList<Symbol> nameList = new ArrayList<>(initialSize);
    /* step 6 */
    for (Object key : keys) {
        if (key instanceof Symbol) {
            nameList.add((Symbol) key);
        }
    }
    /* step 7 */
    return CreateArrayFromList(cx, nameList);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Symbol(com.github.anba.es6draft.runtime.types.Symbol) ArrayList(java.util.ArrayList) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ImmutablePrototypeObject(com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 89 with ScriptObject

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

the class AsyncFunctionConstructor method CreateDynamicFunction.

/**
     * 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
     * 
     * @param callerContext
     *            the caller execution context
     * @param cx
     *            the execution context
     * @param newTarget
     *            the newTarget constructor function
     * @param args
     *            the function arguments
     * @return the new generator function object
     */
private static OrdinaryAsyncFunction CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Intrinsics fallbackProto = Intrinsics.AsyncFunction;
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.AsyncFunction, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.asyncFunction(source, parameters, bodyText).getFunction();
    } catch (ParserException | CompilationException e) {
        throw e.toScriptException(cx);
    }
    /* step 12 */
    boolean strict = function.isStrict();
    /* steps 21-22 */
    ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
    /* step 23 */
    OrdinaryAsyncFunction f = FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
    /* steps 24-25 */
    LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
    /* step 26 */
    FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
    /* steps 27-28 (not applicable) */
    /* step 29 */
    SetFunctionName(f, "anonymous");
    /* step 30 */
    return f;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RuntimeInfo(com.github.anba.es6draft.runtime.internal.RuntimeInfo) GlobalEnvironmentRecord(com.github.anba.es6draft.runtime.GlobalEnvironmentRecord) FunctionConstructor.functionSource(com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource) Source(com.github.anba.es6draft.runtime.internal.Source) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryAsyncFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 90 with ScriptObject

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

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