Search in sources :

Example 66 with ExecutionContext

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

the class InterpretedScriptBody method evalScriptEvaluation.

/**
 * 18.2.1.1 Runtime Semantics: PerformEval( x, evalRealm, strictCaller, direct)
 *
 * @param cx
 *            the execution context
 * @param script
 *            the script object
 * @param interpreter
 *            the interpreter
 * @return the script evaluation result
 */
private Object evalScriptEvaluation(ExecutionContext cx, Script script, Interpreter interpreter) {
    // TODO: Skip allocating lex-env if not needed
    /* steps 1-5 (not applicable) */
    /* steps 6-7 */
    boolean strictEval = parsedScript.isStrict();
    /* step 8 (omitted) */
    /* steps 9-10 */
    LexicalEnvironment<DeclarativeEnvironmentRecord> lexEnv;
    LexicalEnvironment<?> varEnv;
    if (parsedScript.isDirectEval()) {
        /* step 9 */
        lexEnv = newDeclarativeEnvironment(cx.getLexicalEnvironment());
        varEnv = cx.getVariableEnvironment();
    } else {
        Realm evalRealm = cx.getRealm();
        /* step 10 */
        lexEnv = newDeclarativeEnvironment(evalRealm.getGlobalEnv());
        varEnv = evalRealm.getGlobalEnv();
    }
    /* step 11 */
    if (strictEval) {
        varEnv = lexEnv;
    }
    /* steps 12-19 */
    ExecutionContext evalCxt = newEvalExecutionContext(cx, script, varEnv, lexEnv);
    /* step 20 */
    EvalDeclarationInstantiation(evalCxt, parsedScript, varEnv, lexEnv);
    /* steps 21-25 */
    return parsedScript.accept(interpreter, evalCxt);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newScriptExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newScriptExecutionContext) ExecutionContext.newEvalExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newEvalExecutionContext) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) Realm(com.github.anba.es6draft.runtime.Realm)

Example 67 with ExecutionContext

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

the class BigIntConstructor method call.

/**
 * BigInt ( value )
 */
@Override
public BigInteger call(ExecutionContext callerContext, Object thisValue, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object value = argument(args, 0);
    /* step 1 (not applicable) */
    /* step 2 */
    Object prim = ToPrimitive(calleeContext, value, ToPrimitiveHint.Number);
    /* step 3 */
    if (Type.isNumber(prim)) {
        return NumberToBigInt(calleeContext, Type.numberValue(prim));
    }
    /* step 4 */
    return ToBigInt(calleeContext, prim);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 68 with ExecutionContext

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

the class ArrayBufferConstructor method construct.

/**
 * 24.1.2.1 ArrayBuffer ( [ length ] )
 */
@Override
public ArrayBufferObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object length = argument(args, 0);
    /* step 1 (not applicable) */
    /* step 2 */
    long byteLength = ToIndex(calleeContext, length);
    /* step 3 */
    return AllocateArrayBuffer(calleeContext, newTarget, byteLength);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 69 with ExecutionContext

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

the class DataViewConstructor method construct.

/**
 * 24.2.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] )
 */
@Override
public DataViewObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object buffer = argument(args, 0);
    Object byteOffset = argument(args, 1);
    Object byteLength = argument(args, 2);
    /* steps 2-3 */
    if (!(buffer instanceof ArrayBuffer)) {
        throw newTypeError(calleeContext, Messages.Key.IncompatibleArgument, "DataView", Type.of(buffer).toString());
    }
    ArrayBuffer bufferObj = (ArrayBuffer) buffer;
    /* step 4 */
    long offset = ToIndex(calleeContext, byteOffset);
    /* step 5 */
    if (IsDetachedBuffer(bufferObj)) {
        throw newTypeError(calleeContext, Messages.Key.BufferDetached);
    }
    /* step 6 */
    long bufferByteLength = bufferObj.getByteLength();
    /* step 7 */
    if (offset > bufferByteLength) {
        throw newRangeError(calleeContext, Messages.Key.ArrayOffsetOutOfRange);
    }
    /* steps 8-9 */
    long viewByteLength;
    if (Type.isUndefined(byteLength)) {
        /* step 8 */
        viewByteLength = bufferByteLength - offset;
    } else {
        /* step 9 */
        viewByteLength = ToIndex(calleeContext, byteLength);
        if (offset + viewByteLength > bufferByteLength) {
            throw newRangeError(calleeContext, Messages.Key.ArrayOffsetOutOfRange);
        }
    }
    /* PR1025 */
    ScriptObject prototype = GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.DataViewPrototype);
    if (IsDetachedBuffer(bufferObj)) {
        throw newTypeError(calleeContext, Messages.Key.BufferDetached);
    }
    /* steps 10-15 */
    return new DataViewObject(calleeContext.getRealm(), bufferObj, viewByteLength, offset, prototype);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 70 with ExecutionContext

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

the class TypedArrayConstructor method construct.

/**
 * 22.2.4.1 TypedArray ( )<br>
 * 22.2.4.2 TypedArray ( length )<br>
 * 22.2.4.3 TypedArray ( typedArray )<br>
 * 22.2.4.4 TypedArray ( object )<br>
 * 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )<br>
 */
@Override
public TypedArrayObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    if (args.length == 0) {
        return constructWithNoArguments(calleeContext, newTarget);
    }
    Object arg0 = args[0];
    if (!Type.isObject(arg0)) {
        return constructWithLength(calleeContext, newTarget, arg0);
    }
    if (arg0 instanceof TypedArrayObject) {
        return constructWithTypedArray(calleeContext, newTarget, (TypedArrayObject) arg0);
    }
    if (arg0 instanceof ArrayBuffer) {
        Object byteOffset = argument(args, 1, 0);
        Object length = argument(args, 2);
        return constructWithArrayBuffer(calleeContext, newTarget, (ArrayBuffer) arg0, byteOffset, length);
    }
    return constructWithObject(calleeContext, newTarget, (ScriptObject) arg0);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) CloneArrayBuffer(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor.CloneArrayBuffer) AllocateArrayBuffer(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor.AllocateArrayBuffer) IsSharedArrayBuffer(com.github.anba.es6draft.runtime.objects.atomics.SharedArrayBufferConstructor.IsSharedArrayBuffer)

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