Class Interpreter
java.lang.Object
org.mozilla.javascript.Icode
org.mozilla.javascript.Interpreter
- All Implemented Interfaces:
Evaluator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Class 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) InterpreterData
Fields inherited from class 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 void
addInstructionCount
(Context cx, Interpreter.CallFrame frame, int extra) private static int
bytecodeSpan
(int bytecode) static NativeContinuation
private static NativeContinuation
captureContinuation
(Context cx, Interpreter.CallFrame frame, boolean requireContinuationsTopFrame) private static Interpreter.CallFrame
void
Capture stack information from the given exception.private static boolean
compile
(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 void
private static int
doArithmetic
(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static int
doBitNOT
(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) private static int
doBitOp
(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static int
doCallSpecial
(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, byte[] iCode, int indexReg) private static int
doCompare
(Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static int
doDelName
(Context cx, Interpreter.CallFrame frame, int op, Object[] stack, double[] sDbl, int stackTop) private static int
doElemIncDec
(Context cx, Interpreter.CallFrame frame, byte[] iCode, Object[] stack, double[] sDbl, int stackTop) private static boolean
private static int
doGetElem
(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) private static int
doGetVar
(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int indexReg) private static int
doInOrInstanceof
(Context cx, int op, Object[] stack, double[] sDbl, int stackTop) private static int
doRefMember
(Context cx, Object[] stack, double[] sDbl, int stackTop, int flags) private static int
doRefNsMember
(Context cx, Object[] stack, double[] sDbl, int stackTop, int flags) private static int
doRefNsName
(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, int flags) private static int
doSetConstVar
(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) private static int
doSetElem
(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop) private static int
doSetVar
(Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) private static boolean
doShallowEquals
(Object[] stack, double[] sDbl, int stackTop) private static int
doVarIncDec
(Context cx, Interpreter.CallFrame frame, Object[] stack, double[] sDbl, int stackTop, Object[] vars, double[] varDbls, int[] varAttributes, int indexReg) (package private) static void
dumpICode
(InterpreterData idata) private static void
enterFrame
(Context cx, Interpreter.CallFrame frame, Object[] args, boolean continuationRestart) private static void
exitFrame
(Context cx, Interpreter.CallFrame frame, Object throwable) private static Object
freezeGenerator
(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 String
getEncodedSource
(InterpreterData idata) private static int
getExceptionHandler
(Interpreter.CallFrame frame, boolean onlyFinally) private static int
getIndex
(byte[] iCode, int pc) private static int
getInt
(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 int
getShort
(byte[] iCode, int pc) getSourcePositionFromStack
(Context cx, int[] linep) Get the source position information by examining the stack.private static Interpreter.CallFrame
initFrame
(Context cx, Scriptable callerScope, Scriptable thisObj, Object[] args, double[] argsDbl, int argShift, int argCount, InterpretedFunction fnOrScript, Interpreter.CallFrame parentFrame) 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) 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__.private static void
initFunction
(Context cx, Scriptable scope, InterpretedFunction parent, int index) (package private) static Object
interpret
(InterpretedFunction ifun, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) private static Object
interpretLoop
(Context cx, Interpreter.CallFrame frame, Object throwable) private static Interpreter.CallFrame
processThrowable
(Context cx, Object throwable, Interpreter.CallFrame frame, int indexReg, boolean instructionCounting) static Object
restartContinuation
(NativeContinuation c, Context cx, Scriptable scope, Object[] args) static Object
resumeGenerator
(Context cx, Scriptable scope, int operation, Object savedState, Object value) private static void
setCallResult
(Interpreter.CallFrame frame, Object callResult, double callResultDbl) void
setEvalScriptFlag
(Script script) Mark the given script to indicate it was created by a call to eval() or to a Function constructor.private static boolean
stack_boolean
(Interpreter.CallFrame frame, int i) private static double
stack_double
(Interpreter.CallFrame frame, int i) private static int
stack_int32
(Interpreter.CallFrame frame, int i) private static Number
stack_numeric
(Interpreter.CallFrame frame, int i) private static Object
thawGenerator
(Interpreter.CallFrame frame, int stackTop, Interpreter.GeneratorState generatorState, int op) Methods inherited from class 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:Evaluator
Compile the script or function from intermediate representation tree into an executable form.- Specified by:
compile
in 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:Evaluator
Create a script object.- Specified by:
createScriptObject
in interfaceEvaluator
- Parameters:
bytecode
- opaque object returned by compilestaticSecurityDomain
- security domain- Returns:
- Script object that can be evaluated
-
setEvalScriptFlag
Description copied from interface:Evaluator
Mark the given script to indicate it was created by a call to eval() or to a Function constructor.- Specified by:
setEvalScriptFlag
in 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:Evaluator
Create a function object.- Specified by:
createFunctionObject
in 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:Evaluator
Capture stack information from the given exception.- Specified by:
captureStackInfo
in interfaceEvaluator
- Parameters:
ex
- an exception thrown during execution
-
getSourcePositionFromStack
Description copied from interface:Evaluator
Get the source position information by examining the stack.- Specified by:
getSourcePositionFromStack
in 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:Evaluator
Given a native stack trace, patch it with script-specific source and line information- Specified by:
getPatchedStack
in interfaceEvaluator
- Parameters:
ex
- exceptionnativeStackTrace
- the native stack trace- Returns:
- patched stack trace
-
getScriptStack
Description copied from interface:Evaluator
Get the script stack for the given exception- Specified by:
getScriptStack
in 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
-