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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations