Search in sources :

Example 61 with OrdinaryObject

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

the class AsyncGeneratorFunctionConstructor 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 async generator function object
     */
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Intrinsics fallbackProto = Intrinsics.AsyncGenerator;
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.AsyncGenerator, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.asyncGenerator(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 */
    OrdinaryAsyncGenerator 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));
    /* step 27 */
    OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
    f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
    /* 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) FunctionConstructor.functionSource(com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource) Source(com.github.anba.es6draft.runtime.internal.Source) OrdinaryAsyncGenerator(com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncGenerator) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 62 with OrdinaryObject

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

the class DateTimeFormatConstructor method ToDateTimeOptions.

/**
     * 12.1.2 ToDateTimeOptions (options, required, defaults)
     * 
     * @param cx
     *            the execution context
     * @param opts
     *            the options object
     * @param required
     *            the required date field
     * @param defaults
     *            the default date field
     * @return the date-time options script object
     */
public static ScriptObject ToDateTimeOptions(ExecutionContext cx, Object opts, String required, String defaults) {
    /* steps 1-2 */
    OrdinaryObject options = ObjectCreate(cx, Type.isUndefined(opts) ? null : ToObject(cx, opts));
    /* step 3 */
    boolean needDefaults = true;
    /* step 4 */
    if ("date".equals(required) || "any".equals(required)) {
        // FIXME: spec vs. impl (short circuit after first undefined value?)
        for (String prop : array("weekday", "year", "month", "day")) {
            Object kvalue = Get(cx, options, prop);
            if (!Type.isUndefined(kvalue)) {
                needDefaults = false;
            }
        }
    }
    /* step 5 */
    if ("time".equals(required) || "any".equals(required)) {
        // FIXME: spec vs. impl (short circuit after first undefined value?)
        for (String prop : array("hour", "minute", "second")) {
            Object kvalue = Get(cx, options, prop);
            if (!Type.isUndefined(kvalue)) {
                needDefaults = false;
            }
        }
    }
    /* step 6 */
    if (needDefaults && ("date".equals(defaults) || "all".equals(defaults))) {
        for (String prop : array("year", "month", "day")) {
            CreateDataPropertyOrThrow(cx, options, prop, "numeric");
        }
    }
    /* step 7 */
    if (needDefaults && ("time".equals(defaults) || "all".equals(defaults))) {
        for (String prop : array("hour", "minute", "second")) {
            CreateDataPropertyOrThrow(cx, options, prop, "numeric");
        }
    }
    /* step 8 */
    return options;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) 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)

Example 63 with OrdinaryObject

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

the class DateTimeFormatConstructor method FormatToPartDateTime.

/**
     * FormatToPartDateTime(dateTimeFormat, x)
     * 
     * @param cx
     *            the execution context
     * @param dateTimeFormat
     *            the date format object
     * @param x
     *            the number value
     * @return the formatted date-time object
     */
public static ArrayObject FormatToPartDateTime(ExecutionContext cx, DateTimeFormatObject dateTimeFormat, double x) {
    if (Double.isInfinite(x) || Double.isNaN(x)) {
        throw newRangeError(cx, Messages.Key.InvalidDateValue);
    }
    /* step 1 */
    List<Map.Entry<String, String>> parts = CreateDateTimeParts(dateTimeFormat, new Date((long) x));
    /* step 2 */
    ArrayObject result = ArrayCreate(cx, 0);
    /* step 3 */
    int n = 0;
    /* step 4 */
    for (Map.Entry<String, String> part : parts) {
        /* step 4.a */
        OrdinaryObject o = ObjectCreate(cx, Intrinsics.ObjectPrototype);
        /* steps 4.b-c */
        CreateDataProperty(cx, o, "type", part.getKey());
        /* steps 4.d-e */
        CreateDataProperty(cx, o, "value", part.getValue());
        /* steps 4.f-g */
        CreateDataProperty(cx, result, n++, o);
    }
    /* step 5 */
    return result;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Map(java.util.Map) AbstractMap(java.util.AbstractMap) Date(java.util.Date)

Example 64 with OrdinaryObject

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

the class ErrorObject method getErrorObjectProperty.

/**
     * Specialized property retrieval to prevent any script execution.
     * 
     * @param error
     *            the error object
     * @param propertyName
     *            the property key
     * @param defaultValue
     *            the default value
     * @return property string value
     */
private static String getErrorObjectProperty(ErrorObject error, String propertyName, String defaultValue) {
    Property property = error.lookupOwnProperty(propertyName);
    if (property == null) {
        ScriptObject proto = error.getPrototype();
        if (proto instanceof ErrorPrototype || proto instanceof NativeErrorPrototype) {
            property = ((OrdinaryObject) proto).lookupOwnProperty(propertyName);
        }
    }
    Object value = property != null && property.isDataDescriptor() ? property.getValue() : null;
    if (value == null || Type.isUndefined(value)) {
        return defaultValue;
    }
    // Prevent possible recursion
    if (value instanceof ErrorObject) {
        return "<error>";
    }
    return Objects.toString(value);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) 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 65 with OrdinaryObject

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

the class PropertyGenerator method visit.

@Override
public ValType visit(PropertyDefinitionsMethod node, CodeVisitor mv) {
    MethodName method = codegen.compile(node, decorators != null, mv);
    boolean hasResume = node.hasResumePoint();
    mv.enterVariableScope();
    Variable<OrdinaryObject> object = mv.newVariable("object", OrdinaryObject.class);
    // stack: [<object>] -> []
    mv.store(object);
    // stack: [] -> []
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    if (hasResume) {
        mv.callWithSuspend(method, object, decoratorsOrNull(mv));
    } else {
        mv.call(method, object, decoratorsOrNull(mv));
    }
    mv.exitVariableScope();
    return null;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

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