public ExecutionContext createEvalExecutionContext(JSProgram eval, boolean direct) { // 10.4.2 (with caller) ExecutionContext context = null; Object evalThisBinding = null; LexicalEnvironment evalLexEnv = null; LexicalEnvironment evalVarEnv = null; if (!direct) { evalThisBinding = getGlobalObject(); evalLexEnv = LexicalEnvironment.newGlobalEnvironment(getGlobalObject()); evalVarEnv = LexicalEnvironment.newGlobalEnvironment(getGlobalObject()); } else { evalThisBinding = this.thisBinding; evalLexEnv = this.getLexicalEnvironment(); evalVarEnv = this.getVariableEnvironment(); } if (eval.isStrict()) { LexicalEnvironment strictVarEnv = LexicalEnvironment.newDeclarativeEnvironment(this.getLexicalEnvironment()); evalLexEnv = strictVarEnv; evalVarEnv = strictVarEnv; } context = new ExecutionContext(this, evalLexEnv, evalVarEnv, evalThisBinding, eval.isStrict()); context.performFunctionDeclarationBindings(eval, true); context.performVariableDeclarationBindings(eval, true); context.fileName = eval.getFileName(); return context; }
public static ExecutionContext createGlobalExecutionContext(DynJS runtime) { // 10.4.1.1 LexicalEnvironment env = LexicalEnvironment.newGlobalEnvironment(runtime); ExecutionContext context = new ExecutionContext(null, env, env, env.getGlobalObject(), false); context.clock = runtime.getConfig().getClock(); context.timeZone = runtime.getConfig().getTimeZone(); context.locale = runtime.getConfig().getLocale(); return context; }
public ExecutionContext createFunctionExecutionContext( Object functionReference, JSFunction function, Object thisArg, Object... arguments) { // 10.4.3 Object thisBinding = null; if (function.isStrict()) { thisBinding = thisArg; } else { if (thisArg == null || thisArg == Types.NULL || thisArg == Types.UNDEFINED) { thisBinding = this.getLexicalEnvironment().getGlobalObject(); } else if (!(thisArg instanceof JSObject)) { // thisBinding = Types.toObject(this, thisArg); thisBinding = Types.toThisObject(this, thisArg); } else { thisBinding = thisArg; } } LexicalEnvironment scope = function.getScope(); LexicalEnvironment localEnv = LexicalEnvironment.newDeclarativeEnvironment(scope); ExecutionContext context = new ExecutionContext(this, localEnv, localEnv, thisBinding, function.isStrict()); context.performDeclarationBindingInstantiation(function, arguments); context.fileName = function.getFileName(); // System.err.println( "debug null: " + ( function.getDebugContext() == null ? function : "not // null") ); context.debugContext = function.getDebugContext(); context.functionReference = functionReference; return context; }
public Completion executeCatch(BasicBlock block, String identifier, Object thrown) { // 12.14 LexicalEnvironment oldEnv = this.lexicalEnvironment; LexicalEnvironment catchEnv = LexicalEnvironment.newDeclarativeEnvironment(oldEnv); catchEnv.getRecord().createMutableBinding(this, identifier, false); catchEnv.getRecord().setMutableBinding(this, identifier, thrown, false); try { this.lexicalEnvironment = catchEnv; return block.call(this); } catch (ThrowException e) { throw e; } catch (Throwable t) { throw new ThrowException(this, t); } finally { this.lexicalEnvironment = oldEnv; } }
public AbstractNativeFunction(GlobalContext globalContext, String... formalParameters) { super( globalContext, LexicalEnvironment.newObjectEnvironment(globalContext.getObject(), false, null), true, formalParameters); setupDebugContext(); setFileName(); }
public Completion executeWith(JSObject withObj, BasicBlock block) { LexicalEnvironment oldEnv = this.lexicalEnvironment; LexicalEnvironment withEnv = LexicalEnvironment.newObjectEnvironment(withObj, true, oldEnv); try { this.lexicalEnvironment = withEnv; return block.call(this); } finally { this.lexicalEnvironment = oldEnv; } }