Search in sources :

Example 71 with ExecutionContext

use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.

the class NativeErrorConstructor method construct.

/**
 * 19.5.6.1.1 NativeError (message)
 * <p>
 * <strong>Extension</strong>: NativeError (message, fileName, lineNumber, columnNumber)
 */
@Override
public ErrorObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object message = argument(args, 0);
    /* step 1 (not applicable) */
    /* step 2 */
    ErrorObject obj = OrdinaryCreateFromConstructor(calleeContext, newTarget, type.prototype(), ErrorObject::new);
    /* step 3 */
    if (!Type.isUndefined(message)) {
        CharSequence msg = ToString(calleeContext, message);
        obj.defineErrorProperty("message", msg, false);
    }
    /* extension: fileName, lineNumber and columnNumber arguments */
    if (args.length > 1) {
        CharSequence fileName = ToString(calleeContext, args[1]);
        obj.defineErrorProperty("fileName", fileName, true);
    }
    if (args.length > 2) {
        int line = ToInt32(calleeContext, args[2]);
        obj.defineErrorProperty("lineNumber", line, true);
    }
    if (args.length > 3) {
        int column = ToInt32(calleeContext, args[3]);
        obj.defineErrorProperty("columnNumber", column, true);
    }
    /* step 4 */
    return obj;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext)

Example 72 with ExecutionContext

use of com.github.anba.es6draft.runtime.ExecutionContext 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)) {
        return ObjectCreate(calleeContext, 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 73 with ExecutionContext

use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.

the class BooleanConstructor method construct.

/**
 * 19.3.1.1 Boolean (value)
 */
@Override
public BooleanObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    /* step 1 */
    boolean b = args.length > 0 && ToBoolean(args[0]);
    /* steps 3-5 */
    return BooleanCreate(calleeContext, b, GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.BooleanPrototype));
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext)

Example 74 with ExecutionContext

use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.

the class SymbolConstructor method call.

/**
 * 19.4.1.1 Symbol ( [ description ] )
 */
@Override
public Symbol call(ExecutionContext callerContext, Object thisValue, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object description = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-3 */
    String descString = Type.isUndefined(description) ? null : ToFlatString(calleeContext, description);
    /* step 4 */
    return new Symbol(descString);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) Symbol(com.github.anba.es6draft.runtime.types.Symbol) BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ToFlatString(com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)

Example 75 with ExecutionContext

use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.

the class PromiseConstructor method construct.

/**
 * 25.4.3.1 Promise ( executor )
 */
@Override
public PromiseObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object executor = argument(args, 0);
    /* step 2 */
    if (!IsCallable(executor)) {
        throw newTypeError(calleeContext, Messages.Key.NotCallable);
    }
    /* steps 3-7 */
    PromiseObject promise = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.PromisePrototype, GetPromiseAllocator(calleeContext.getRealm()));
    /* step 8 */
    ResolvingFunctions resolvingFunctions = CreateResolvingFunctions(calleeContext, promise);
    /* steps 9-10 */
    try {
        /* step 9 */
        ((Callable) executor).call(calleeContext, UNDEFINED, resolvingFunctions.getResolve(), resolvingFunctions.getReject());
    } catch (ScriptException e) {
        /* step 10 */
        resolvingFunctions.getReject().call(calleeContext, UNDEFINED, e.getValue());
    }
    /* step 11 */
    return promise;
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ResolvingFunctions(com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.ResolvingFunctions) CreateResolvingFunctions(com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.CreateResolvingFunctions) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)95 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)61 Realm (com.github.anba.es6draft.runtime.Realm)17 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)16 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)15 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)14 AbstractOperations (com.github.anba.es6draft.runtime.AbstractOperations)11 Declaration (com.github.anba.es6draft.ast.Declaration)10 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)10 Name (com.github.anba.es6draft.ast.scope.Name)10 Callable (com.github.anba.es6draft.runtime.types.Callable)10 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)10 HashSet (java.util.HashSet)10 StatementListItem (com.github.anba.es6draft.ast.StatementListItem)9 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)9 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)8 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)8 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)8 ArrayDeque (java.util.ArrayDeque)8 FunctionDeclaration (com.github.anba.es6draft.ast.FunctionDeclaration)7