use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ListIteratorNext method call.
@Override
public OrdinaryObject call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* steps 3, 6 */
if (!(thisValue instanceof ListIterator)) {
throw newTypeError(calleeContext, Messages.Key.IncompatibleObject);
}
ListIterator<?> listIterator = (ListIterator<?>) thisValue;
/* steps 4-5 */
if (this != listIterator.getIteratorNext()) {
throw newTypeError(calleeContext, Messages.Key.IncompatibleObject);
}
/* step 7 */
Iterator<?> iterator = listIterator.getIterator();
/* steps 8-10 */
if (!iterator.hasNext()) {
return CreateIterResultObject(calleeContext, UNDEFINED, true);
}
/* steps 11-12 */
return CreateIterResultObject(calleeContext, iterator.next(), false);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(SwitchStatement node, BlockDeclarationInstantiationGenerator generator) {
if (!isCompiled(node)) {
MethodCode method = newMethod(node);
BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
body.lineInfo(node);
body.begin();
Variable<ExecutionContext> cx = body.getExecutionContext();
Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
generator.generateMethod(node, cx, env, body);
body._return();
body.end();
}
return methodDesc(node);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(SwitchStatement node, List<Declaration> declarations, BlockDeclarationInstantiationGenerator generator) {
MethodCode method = newMethod2(node);
BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
body.lineInfo(node);
body.begin();
Variable<ExecutionContext> cx = body.getExecutionContext();
Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
generator.generateMethod(declarations, cx, env, body);
body._return();
body.end();
return methodDesc(node, method.methodName);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(BlockStatement node, BlockDeclarationInstantiationGenerator generator) {
if (!isCompiled(node)) {
MethodCode method = newMethod(node);
BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
body.lineInfo(node);
body.begin();
Variable<ExecutionContext> cx = body.getExecutionContext();
Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
generator.generateMethod(node, cx, env, body);
body._return();
body.end();
}
return methodDesc(node);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class FunctionCodeGenerator method generateLegacyFunctionConstruct.
/**
* Generate bytecode for:
*
* <pre>
* oldCaller = function.getLegacyCaller()
* oldArguments = function.getLegacyArguments()
* function.setLegacyCaller(callerContext.getCurrentFunction())
* try {
* thisArgument = OrdinaryCreateFromConstructor(callerContext, newTarget, %ObjectPrototype%)
* calleeContext = newFunctionExecutionContext(function, newTarget, thisArgument)
* result = OrdinaryCallEvaluateBody(function, argumentsList)
* return returnResultOrThis(result)
* } finally {
* function.restoreLegacyProperties(oldCaller, oldArguments)
* }
* </pre>
*
* @param node
* the function node
* @param mv
* the instruction visitor
*/
private void generateLegacyFunctionConstruct(FunctionNode node, InstructionVisitor mv) {
final boolean hasArguments = codegen.isEnabled(CompatibilityOption.FunctionArguments);
final boolean hasCaller = codegen.isEnabled(CompatibilityOption.FunctionCaller);
Variable<LegacyConstructorFunction> function = mv.getParameter(FUNCTION, LegacyConstructorFunction.class);
Variable<ExecutionContext> callerContext = mv.getParameter(EXECUTION_CONTEXT, ExecutionContext.class);
Variable<Constructor> newTarget = mv.getParameter(NEW_TARGET, Constructor.class);
Variable<Object[]> arguments = mv.getParameter(ARGUMENTS, Object[].class);
Variable<ScriptObject> thisArg = mv.newVariable("thisArgument", ScriptObject.class);
Variable<ExecutionContext> calleeContext = mv.newVariable("calleeContext", ExecutionContext.class);
Variable<FunctionObject> oldCaller = mv.newVariable("oldCaller", FunctionObject.class);
Variable<LegacyConstructorFunction.Arguments> oldArguments = mv.newVariable("oldArguments", LegacyConstructorFunction.Arguments.class);
Variable<Throwable> throwable = mv.newVariable("throwable", Throwable.class);
// (1) Retrieve 'caller' and 'arguments' and store in local variables
if (hasCaller) {
mv.load(function);
mv.invoke(Methods.LegacyConstructorFunction_getLegacyCaller);
} else {
mv.anull();
}
mv.store(oldCaller);
if (hasArguments) {
mv.load(function);
mv.invoke(Methods.LegacyConstructorFunction_getLegacyArguments);
} else {
mv.anull();
}
mv.store(oldArguments);
// (2) Update 'caller' and 'arguments' properties
if (hasCaller) {
setLegacyCaller(function, callerContext, mv);
}
if (hasArguments) {
setLegacyArguments(function, arguments, mv);
}
TryCatchLabel startFinally = new TryCatchLabel(), endFinally = new TryCatchLabel();
TryCatchLabel handlerFinally = new TryCatchLabel();
mv.mark(startFinally);
{
// (3) Create this-argument
ordinaryCreateFromConstructor(callerContext, newTarget, thisArg, mv);
// (4) Create a new ExecutionContext
prepareCallAndBindThis(node, calleeContext, function, newTarget, thisArg, mv);
// (5) Call OrdinaryCallEvaluateBody
ordinaryCallEvaluateBody(node, calleeContext, function, arguments, mv);
// (6) Restore 'caller' and 'arguments'
restoreLegacyProperties(function, oldCaller, oldArguments, mv);
// (7) Return result value
returnResultOrThis(thisArg, false, mv);
}
mv.mark(endFinally);
// Exception: Restore 'caller' and 'arguments' and then rethrow exception
mv.finallyHandler(handlerFinally);
mv.store(throwable);
restoreLegacyProperties(function, oldCaller, oldArguments, mv);
mv.load(throwable);
mv.athrow();
mv.tryFinally(startFinally, endFinally, handlerFinally);
}
Aggregations