Search in sources :

Example 31 with Property

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

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

the class RegExpConstructor method RegExpAlloc.

/**
     * 21.2.3.2 Abstract Operations for the RegExp Constructor<br>
     * 21.2.3.2.1 Runtime Semantics: RegExpAlloc ( newTarget )
     * 
     * @param cx
     *            the execution context
     * @param newTarget
     *            the constructor function
     * @return the new regular expression object
     */
public static RegExpObject RegExpAlloc(ExecutionContext cx, Constructor newTarget) {
    /* steps 1-2 */
    RegExpObject obj = OrdinaryCreateFromConstructor(cx, newTarget, Intrinsics.RegExpPrototype, RegExpObject::new);
    /* steps 3-4 */
    obj.infallibleDefineOwnProperty("lastIndex", new Property(0, true, false, false));
    /* step 5 */
    return obj;
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 33 with Property

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

the class RegExpPrototype method isBuiltinRegExpPrototypeForExec.

private static boolean isBuiltinRegExpPrototypeForExec(ExecutionContext cx) {
    OrdinaryObject prototype = cx.getIntrinsic(Intrinsics.RegExpPrototype);
    Property execProp = prototype.getOwnProperty(cx, "exec");
    if (execProp == null || !isBuiltinExec(cx.getRealm(), execProp.getValue())) {
        return false;
    }
    Property globalProp = prototype.getOwnProperty(cx, "global");
    if (globalProp == null || !isBuiltinGlobal(cx.getRealm(), globalProp.getGetter())) {
        return false;
    }
    Property stickyProp = prototype.getOwnProperty(cx, "sticky");
    if (stickyProp == null || !isBuiltinSticky(cx.getRealm(), stickyProp.getGetter())) {
        return false;
    }
    return true;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 34 with Property

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

the class ModuleNamespaceObject method ModuleNamespaceCreate.

/**
     * 9.4.6.13 ModuleNamespaceCreate (module, exports)
     *
     * @param cx
     *            the execution context
     * @param module
     *            the module record
     * @param exports
     *            the exported bindings
     * @return the new module namespace object
     */
public static ModuleNamespaceObject ModuleNamespaceCreate(ExecutionContext cx, ModuleRecord module, Set<String> exports) {
    /* step 2 */
    assert module.getNamespace() == null;
    /* step 3 (not applicable) */
    /* steps 4-7 */
    ModuleNamespaceObject m = new ModuleNamespaceObject(cx.getRealm(), module, exports);
    /* step 8 */
    // 26.3.1 @@toStringTag
    m.infallibleDefineOwnProperty(BuiltinSymbol.toStringTag.get(), new Property("Module", false, false, true));
    // 26.3.2 [ @@iterator ] ( )
    BuiltinFunction iterator;
    if (cx.getRealm().isEnabled(CompatibilityOption.Enumerate)) {
        iterator = new ModuleIteratorFunction(cx.getRealm());
    } else {
        iterator = new ModuleExportsIteratorFunction(cx.getRealm());
    }
    m.infallibleDefineOwnProperty(BuiltinSymbol.iterator.get(), new Property(iterator, true, false, true));
    /* step 9 */
    module.setNamespace(m);
    /* step 10 */
    return m;
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 35 with Property

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

the class ArgumentsObject method CreateUnmappedArgumentsObject.

/**
     * 9.4.4.6 CreateUnmappedArgumentsObject(argumentsList)
     * <p>
     * [Called from generated code]
     * 
     * @param cx
     *            the execution context
     * @param argumentsList
     *            the function arguments
     * @return the strict mode arguments object
     */
public static ArgumentsObject CreateUnmappedArgumentsObject(ExecutionContext cx, Object[] argumentsList) {
    /* step 1 */
    int len = argumentsList.length;
    /* steps 2-3 */
    ArgumentsObject obj = new ArgumentsObject(cx.getRealm());
    obj.setPrototype(cx.getIntrinsic(Intrinsics.ObjectPrototype));
    /* step 4 */
    obj.infallibleDefineOwnProperty("length", new Property(len, true, false, true));
    /* steps 5-6 */
    for (int index = 0; index < len; ++index) {
        obj.setIndexed(index, argumentsList[index]);
    }
    Callable thrower = cx.getRealm().getThrowTypeError();
    /* step 7 */
    obj.infallibleDefineOwnProperty(BuiltinSymbol.iterator.get(), new Property(cx.getIntrinsic(Intrinsics.ArrayProto_values), true, false, true));
    /* step 8 */
    obj.infallibleDefineOwnProperty("callee", new Property(thrower, thrower, false, false));
    /* step 9 */
    obj.infallibleDefineOwnProperty("caller", new Property(thrower, thrower, false, false));
    /* step 11 */
    return obj;
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

Property (com.github.anba.es6draft.runtime.types.Property)51 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)33 Callable (com.github.anba.es6draft.runtime.types.Callable)26 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)10 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)8 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)2 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)2 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)2 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)2 HasOwnProperty (com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)1 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)1 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)1