Search in sources :

Example 76 with OrdinaryObject

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

the class ArrayPrototype method iterationKindForSparse.

private static IterationKind iterationKindForSparse(OrdinaryObject arrayLike, long length) {
    IterationKind iteration = IterationKind.SparseOwnKeys;
    int protoDepth = 0;
    long indexed = 0;
    for (OrdinaryObject object = arrayLike; ; ) {
        indexed += object.getIndexedSize();
        ScriptObject prototype = object.getPrototype();
        if (prototype == null) {
            break;
        }
        if (!(prototype instanceof OrdinaryObject)) {
            return IterationKind.Slow;
        }
        object = (OrdinaryObject) prototype;
        if (object.hasSpecialIndexedProperties()) {
            return IterationKind.Slow;
        }
        if (object.hasIndexedProperties()) {
            if (object.hasIndexedAccessors()) {
                return IterationKind.Slow;
            }
            iteration = IterationKind.InheritedKeys;
        }
        if (++protoDepth == MAX_PROTO_DEPTH) {
            return IterationKind.Slow;
        }
    }
    double density = indexed / (double) length;
    if (density > 0.75) {
        return IterationKind.Slow;
    }
    return iteration;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayIterationKind(com.github.anba.es6draft.runtime.objects.ArrayIteratorObject.ArrayIterationKind)

Example 77 with OrdinaryObject

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

the class Properties method createAliasFunction.

private static void createAliasFunction(Realm realm, OrdinaryObject target, AliasFunctionLayout layout) {
    Object propertyKey = layout.propertyKey;
    Property fun;
    if (propertyKey instanceof String) {
        fun = target.lookupOwnProperty((String) propertyKey);
    } else {
        fun = target.lookupOwnProperty(((BuiltinSymbol) propertyKey).get());
    }
    assert fun != null : "property not found: " + propertyKey;
    defineProperty(target, layout, valueProperty(layout, fun.getValue()));
}
Also used : BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 78 with OrdinaryObject

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

the class Properties method createConstructor.

private static OrdinaryObject createConstructor(ExecutionContext cx, String className, OrdinaryObject proto, Converter converter, ObjectLayout layout) {
    Entry<Function, MethodHandle> constructorEntry = findConstructor(layout);
    if (constructorEntry != null) {
        // User supplied method, perform manual ClassDefinitionEvaluation for constructors
        Function function = constructorEntry.getKey();
        MethodHandle unreflect = constructorEntry.getValue();
        MethodHandle callMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Call);
        MethodHandle constructMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Construct);
        NativeConstructor constructor = new NativeConstructor(cx.getRealm(), className, function.arity(), callMethod, constructMethod);
        constructor.defineOwnProperty(cx, "prototype", new PropertyDescriptor(proto, false, false, false));
        proto.defineOwnProperty(cx, "constructor", new PropertyDescriptor(constructor, true, false, true));
        return constructor;
    }
    // Create default constructor
    String sourceText = String.format("(class %s { })", sanitizeName(className));
    ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
    Script script = scriptLoader.script(new Source("<Constructor>", 1), sourceText);
    Object constructor = script.evaluate(cx);
    assert constructor instanceof OrdinaryConstructorFunction : constructor.getClass();
    return (OrdinaryConstructorFunction) constructor;
}
Also used : NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) BuiltinFunction(com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction) NativeTailCallFunction(com.github.anba.es6draft.runtime.types.builtins.NativeTailCallFunction) NativeConstructor(com.github.anba.es6draft.runtime.types.builtins.NativeConstructor) Script(com.github.anba.es6draft.Script) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 79 with OrdinaryObject

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

the class GeneratorFunctionConstructor method CreateDynamicConstructorGenerator.

private static OrdinaryConstructorGenerator CreateDynamicConstructorGenerator(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Intrinsics fallbackProto = Intrinsics.Generator;
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.Generator, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.generator(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 */
    OrdinaryConstructorGenerator f = OrdinaryConstructorGenerator.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));
    /* step 27 */
    OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
    MakeConstructor(f, true, prototype);
    /* step 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) OrdinaryConstructorGenerator(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorGenerator) 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) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 80 with OrdinaryObject

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

the class ReflectParser method visit.

@Override
public Object visit(SuperPropertyAccessor node, Void value) {
    Object object = superNode(node);
    Object property = createIdentifier(node.getName());
    boolean computed = false;
    if (hasBuilder(Type.MemberExpression)) {
        return call(Type.MemberExpression, node, object, property, computed);
    }
    OrdinaryObject expression = createExpression(node, Type.MemberExpression);
    addProperty(expression, "object", object);
    addProperty(expression, "property", property);
    addProperty(expression, "computed", computed);
    return expression;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Aggregations

OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)141 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)102 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)98 RegExpObject (com.github.anba.es6draft.runtime.objects.text.RegExpObject)84 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)14 Property (com.github.anba.es6draft.runtime.types.Property)5 CompilationException (com.github.anba.es6draft.compiler.CompilationException)3 ParserException (com.github.anba.es6draft.parser.ParserException)3 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)3 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)3 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)3 Source (com.github.anba.es6draft.runtime.internal.Source)3 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)3 AsyncGeneratorFunctionConstructor (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionConstructor)3 AsyncGeneratorFunctionPrototype (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionPrototype)3 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)3 IntlObject (com.github.anba.es6draft.runtime.objects.intl.IntlObject)3 ArrayList (java.util.ArrayList)3 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)2 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)2