Package org.htmlunit.corejs.javascript
Class Interpreter
java.lang.Object
org.htmlunit.corejs.javascript.Icode
org.htmlunit.corejs.javascript.Interpreter
- All Implemented Interfaces:
Evaluator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classClass to hold data corresponding to one interpreted call stack frame.private static final class(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) InterpreterDataFields inherited from class org.htmlunit.corejs.javascript.Icode
Icode_CALLSPECIAL, Icode_CLOSURE_EXPR, Icode_CLOSURE_STMT, Icode_DEBUGGER, Icode_DELNAME, Icode_DUP, Icode_DUP2, Icode_ELEM_AND_THIS, Icode_ELEM_INC_DEC, Icode_ENTERDQ, Icode_GENERATOR, Icode_GENERATOR_END, Icode_GENERATOR_RETURN, Icode_GETVAR1, Icode_GOSUB, Icode_IFEQ_POP, Icode_INTNUMBER, Icode_LEAVEDQ, Icode_LINE, Icode_LITERAL_GETTER, Icode_LITERAL_NEW, Icode_LITERAL_SET, Icode_LITERAL_SETTER, Icode_LOCAL_CLEAR, Icode_NAME_AND_THIS, Icode_NAME_INC_DEC, Icode_ONE, Icode_POP, Icode_POP_RESULT, Icode_PROP_AND_THIS, Icode_PROP_INC_DEC, Icode_REF_INC_DEC, Icode_REG_BIGINT_C0, Icode_REG_BIGINT_C1, Icode_REG_BIGINT_C2, Icode_REG_BIGINT_C3, Icode_REG_BIGINT1, Icode_REG_BIGINT2, Icode_REG_BIGINT4, Icode_REG_IND_C0, Icode_REG_IND_C1, Icode_REG_IND_C2, Icode_REG_IND_C3, Icode_REG_IND_C4, Icode_REG_IND_C5, Icode_REG_IND1, Icode_REG_IND2, Icode_REG_IND4, Icode_REG_STR_C0, Icode_REG_STR_C1, Icode_REG_STR_C2, Icode_REG_STR_C3, Icode_REG_STR1, Icode_REG_STR2, Icode_REG_STR4, Icode_RETSUB, Icode_RETUNDEF, Icode_SCOPE_LOAD, Icode_SCOPE_SAVE, Icode_SETCONST, Icode_SETCONSTVAR, Icode_SETCONSTVAR1, Icode_SETVAR1, Icode_SHORTNUMBER, Icode_SPARE_ARRAYLIT, Icode_STARTSUB, Icode_SWAP, Icode_TAIL_CALL, Icode_TEMPLATE_LITERAL_CALLSITE, Icode_TYPEOFNAME, Icode_UNDEF, Icode_VALUE_AND_THIS, Icode_VAR_INC_DEC, Icode_YIELD_STAR, Icode_ZERO, MIN_ICODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddInstructionCount(Context cx, Interpreter.CallFrame frame, int extra) private static intbytecodeSpan(int bytecode) static NativeContinuationprivate static NativeContinuationcaptureContinuation(Context cx, Interpreter.CallFrame frame, boolean requireContinuationsTopFrame) private static Interpreter.CallFramevoidCapture stack information from the given exception.private static booleancompile(CompilerEnvirons compilerEnv, ScriptNode tree, String encodedSource, boolean returnFunction) Compile the script or function from intermediate representation tree into an executable form.createFunctionObject(Context cx, Scriptable scope, Object bytecode, Object staticSecurityDomain) Create a function object.createScriptObject(Object bytecode, Object staticSecurityDomain) Create a script object.private static voidprivate static intdoArithmetic(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static intdoBitNOT(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) private static intdoBitOp(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static intdoCallSpecial(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, byte[] iCode, int indexReg) private static intdoCompare(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static intdoDelName(Context cx, Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static intdoElemIncDec(Context cx, Interpreter.CallFrame frame, byte[] iCode, Object[] stack, double[] sDbl, int stackTop) private static booleanprivate static intdoGetElem(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) private static intdoGetVar(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int indexReg) private static intdoInOrInstanceof(Context cx, int op, Object[] stack, double[] sDbl, int stackTop) private static intdoRefMember(Context cx, Object[] stack, double[] sDbl, int stackTop, int flags) private static intdoRefNsMember(Context cx, Object[] stack, double[] sDbl, int stackTop, int flags) private static intdoRefNsName(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, int flags) private static intdoSetConstVar(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) private static intdoSetElem(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) private static intdoSetVar(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) private static booleandoShallowEquals(Object[] stack, double[] sDbl, int stackTop) private static intdoVarIncDec(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) (package private) static voiddumpICode(InterpreterData idata) private static voidenterFrame(Context cx, Interpreter.CallFrame frame, Object[] args, boolean continuationRestart) private static voidexitFrame(Context cx, Interpreter.CallFrame frame, Object throwable) private static ObjectfreezeGenerator(Context cx, Interpreter.CallFrame frame, int stackTop, Interpreter.GeneratorState generatorState, boolean yieldStar) private static Object[]getArgsArray(Object[] stack, double[] sDbl, int shift, int count) (package private) static StringgetEncodedSource(InterpreterData idata) private static intgetExceptionHandler(Interpreter.CallFrame frame, boolean onlyFinally) private static intgetIndex(byte[] iCode, int pc) private static intgetInt(byte[] iCode, int pc) (package private) static int[]getPatchedStack(RhinoException ex, String nativeStackTrace) Given a native stack trace, patch it with script-specific source and line informationGet the script stack for the given exceptionprivate static intgetShort(byte[] iCode, int pc) getSourcePositionFromStack(Context cx, int[] linep) Get the source position information by examining the stack.private static Interpreter.CallFrameinitFrame(Context cx, Scriptable callerScope, Scriptable thisObj, Object[] args, double[] argsDbl, int argShift, int argCount, InterpretedFunction fnOrScript, Interpreter.CallFrame parentFrame) private static Interpreter.CallFrameinitFrameForApplyOrCall(Context cx, Interpreter.CallFrame frame, int indexReg, Object[] stack, double[] sDbl, int stackTop, int op, Scriptable calleeScope, IdFunctionObject ifun, InterpretedFunction iApplyCallable) private static Interpreter.CallFrameinitFrameForNoSuchMethod(Context cx, Interpreter.CallFrame frame, int indexReg, Object[] stack, double[] sDbl, int stackTop, int op, Scriptable funThisObj, Scriptable calleeScope, ScriptRuntime.NoSuchMethodShim noSuchMethodShim, InterpretedFunction ifun) Call __noSuchMethod__.private static voidinitFunction(Context cx, Scriptable scope, InterpretedFunction parent, int index) (package private) static Objectinterpret(InterpretedFunction ifun, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) private static ObjectinterpretLoop(Context cx, Interpreter.CallFrame frame, Object throwable) private static Interpreter.CallFrameprocessThrowable(Context cx, Object throwable, Interpreter.CallFrame frame, int indexReg, boolean instructionCounting) static ObjectrestartContinuation(NativeContinuation c, Context cx, Scriptable scope, Object[] args) static ObjectresumeGenerator(Context cx, Scriptable scope, int operation, Object savedState, Object value) private static voidsetCallResult(Interpreter.CallFrame frame, Object callResult, double callResultDbl) voidsetEvalScriptFlag(Script script) Mark the given script to indicate it was created by a call to eval() or to a Function constructor.private static booleanstack_boolean(Interpreter.CallFrame frame, int i) private static doublestack_double(Interpreter.CallFrame frame, int i) private static intstack_int32(Interpreter.CallFrame frame, int i) private static Numberstack_numeric(Interpreter.CallFrame frame, int i) private static ObjectthawGenerator(Interpreter.CallFrame frame, int stackTop, Interpreter.GeneratorState generatorState, int op) Methods inherited from class org.htmlunit.corejs.javascript.Icode
bytecodeName, validBytecode, validIcode, validTokenCode
-
Field Details
-
itsData
InterpreterData itsData -
EXCEPTION_TRY_START_SLOT
static final int EXCEPTION_TRY_START_SLOT- See Also:
-
EXCEPTION_TRY_END_SLOT
static final int EXCEPTION_TRY_END_SLOT- See Also:
-
EXCEPTION_HANDLER_SLOT
static final int EXCEPTION_HANDLER_SLOT- See Also:
-
EXCEPTION_TYPE_SLOT
static final int EXCEPTION_TYPE_SLOT- See Also:
-
EXCEPTION_LOCAL_SLOT
static final int EXCEPTION_LOCAL_SLOT- See Also:
-
EXCEPTION_SCOPE_SLOT
static final int EXCEPTION_SCOPE_SLOT- See Also:
-
EXCEPTION_SLOT_SIZE
static final int EXCEPTION_SLOT_SIZE- See Also:
-
-
Constructor Details
-
Interpreter
public Interpreter()
-
-
Method Details
-
compareIdata
-
captureFrameForGenerator
-
compile
public Object compile(CompilerEnvirons compilerEnv, ScriptNode tree, String encodedSource, boolean returnFunction) Description copied from interface:EvaluatorCompile the script or function from intermediate representation tree into an executable form.- Specified by:
compilein interfaceEvaluator- Parameters:
compilerEnv- Compiler environmenttree- parse treeencodedSource- encoding of the source code for decompilationreturnFunction- if true, compiling a function- Returns:
- an opaque object that can be passed to either createFunctionObject or createScriptObject, depending on the value of returnFunction
-
createScriptObject
Description copied from interface:EvaluatorCreate a script object.- Specified by:
createScriptObjectin interfaceEvaluator- Parameters:
bytecode- opaque object returned by compilestaticSecurityDomain- security domain- Returns:
- Script object that can be evaluated
-
setEvalScriptFlag
Description copied from interface:EvaluatorMark the given script to indicate it was created by a call to eval() or to a Function constructor.- Specified by:
setEvalScriptFlagin interfaceEvaluator- Parameters:
script- script to mark as from eval
-
createFunctionObject
public Function createFunctionObject(Context cx, Scriptable scope, Object bytecode, Object staticSecurityDomain) Description copied from interface:EvaluatorCreate a function object.- Specified by:
createFunctionObjectin interfaceEvaluator- Parameters:
cx- Current contextscope- scope of the functionbytecode- opaque object returned by compilestaticSecurityDomain- security domain- Returns:
- Function object that can be called
-
getShort
private static int getShort(byte[] iCode, int pc) -
getIndex
private static int getIndex(byte[] iCode, int pc) -
getInt
private static int getInt(byte[] iCode, int pc) -
getExceptionHandler
-
dumpICode
-
bytecodeSpan
private static int bytecodeSpan(int bytecode) -
getLineNumbers
-
captureStackInfo
Description copied from interface:EvaluatorCapture stack information from the given exception.- Specified by:
captureStackInfoin interfaceEvaluator- Parameters:
ex- an exception thrown during execution
-
getSourcePositionFromStack
Description copied from interface:EvaluatorGet the source position information by examining the stack.- Specified by:
getSourcePositionFromStackin interfaceEvaluator- Parameters:
cx- Contextlinep- Array object of length >= 1; getSourcePositionFromStack will assign the line number to linep[0].- Returns:
- the name of the file or other source container
-
getPatchedStack
Description copied from interface:EvaluatorGiven a native stack trace, patch it with script-specific source and line information- Specified by:
getPatchedStackin interfaceEvaluator- Parameters:
ex- exceptionnativeStackTrace- the native stack trace- Returns:
- patched stack trace
-
getScriptStack
Description copied from interface:EvaluatorGet the script stack for the given exception- Specified by:
getScriptStackin interfaceEvaluator- Parameters:
ex- exception from execution- Returns:
- list of strings for the stack trace
-
getScriptStackElements
-
getEncodedSource
-
initFunction
private static void initFunction(Context cx, Scriptable scope, InterpretedFunction parent, int index) -
interpret
static Object interpret(InterpretedFunction ifun, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) -
resumeGenerator
public static Object resumeGenerator(Context cx, Scriptable scope, int operation, Object savedState, Object value) -
restartContinuation
public static Object restartContinuation(NativeContinuation c, Context cx, Scriptable scope, Object[] args) -
interpretLoop
-
doInOrInstanceof
-
doCompare
private static int doCompare(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) -
doBitOp
private static int doBitOp(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) -
doBitNOT
private static int doBitNOT(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) -
doDelName
private static int doDelName(Context cx, Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) -
doGetElem
private static int doGetElem(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) -
doSetElem
private static int doSetElem(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) -
doElemIncDec
private static int doElemIncDec(Context cx, Interpreter.CallFrame frame, byte[] iCode, Object[] stack, double[] sDbl, int stackTop) -
doCallSpecial
private static int doCallSpecial(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, byte[] iCode, int indexReg) -
doSetConstVar
private static int doSetConstVar(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) -
doSetVar
private static int doSetVar(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) -
doGetVar
private static int doGetVar(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int indexReg) -
doVarIncDec
private static int doVarIncDec(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) -
doRefMember
-
doRefNsMember
-
doRefNsName
private static int doRefNsName(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, int flags) -
initFrameForNoSuchMethod
private static Interpreter.CallFrame initFrameForNoSuchMethod(Context cx, Interpreter.CallFrame frame, int indexReg, Object[] stack, double[] sDbl, int stackTop, int op, Scriptable funThisObj, Scriptable calleeScope, ScriptRuntime.NoSuchMethodShim noSuchMethodShim, InterpretedFunction ifun) Call __noSuchMethod__. -
doEquals
-
doShallowEquals
-
processThrowable
private static Interpreter.CallFrame processThrowable(Context cx, Object throwable, Interpreter.CallFrame frame, int indexReg, boolean instructionCounting) -
freezeGenerator
private static Object freezeGenerator(Context cx, Interpreter.CallFrame frame, int stackTop, Interpreter.GeneratorState generatorState, boolean yieldStar) -
thawGenerator
private static Object thawGenerator(Interpreter.CallFrame frame, int stackTop, Interpreter.GeneratorState generatorState, int op) -
initFrameForApplyOrCall
private static Interpreter.CallFrame initFrameForApplyOrCall(Context cx, Interpreter.CallFrame frame, int indexReg, Object[] stack, double[] sDbl, int stackTop, int op, Scriptable calleeScope, IdFunctionObject ifun, InterpretedFunction iApplyCallable) -
initFrame
private static Interpreter.CallFrame initFrame(Context cx, Scriptable callerScope, Scriptable thisObj, Object[] args, double[] argsDbl, int argShift, int argCount, InterpretedFunction fnOrScript, Interpreter.CallFrame parentFrame) -
enterFrame
private static void enterFrame(Context cx, Interpreter.CallFrame frame, Object[] args, boolean continuationRestart) -
exitFrame
-
setCallResult
private static void setCallResult(Interpreter.CallFrame frame, Object callResult, double callResultDbl) -
captureContinuation
-
captureContinuation
private static NativeContinuation captureContinuation(Context cx, Interpreter.CallFrame frame, boolean requireContinuationsTopFrame) -
stack_int32
-
stack_double
-
stack_numeric
-
stack_boolean
-
doAdd
-
doArithmetic
private static int doArithmetic(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) -
getArgsArray
-
addInstructionCount
-