org.mozilla.javascript

Class Interpreter

Implemented Interfaces:
Evaluator

public class Interpreter
extends java.lang.Object
implements Evaluator

Method Summary

static NativeContinuation
captureContinuation(Context cx)
void
captureStackInfo(RhinoException ex)
Capture stack information from the given exception.
Object
compile(CompilerEnvirons compilerEnv, ScriptOrFnNode tree, String encodedSource, boolean returnFunction)
Compile the script or function from intermediate representation tree into an executable form.
Function
createFunctionObject(Context cx, Scriptable scope, Object bytecode, Object staticSecurityDomain)
Create a function object.
Script
createScriptObject(Object bytecode, Object staticSecurityDomain)
Create a script object.
String
getPatchedStack(RhinoException ex, String nativeStackTrace)
Given a native stack trace, patch it with script-specific source and line information
List
getScriptStack(RhinoException ex)
Get the script stack for the given exception
String
getSourcePositionFromStack(Context cx, int[] linep)
Get the source position information by examining the stack.
static Object
restartContinuation(NativeContinuation c, Context cx, Scriptable scope, Object[] args)
static Object
resumeGenerator(Context cx, Scriptable scope, int operation, Object savedState, Object value)
void
setEvalScriptFlag(Script script)
Mark the given script to indicate it was created by a call to eval() or to a Function constructor.

Method Details

captureContinuation

public static NativeContinuation captureContinuation(Context cx)

captureStackInfo

public void captureStackInfo(RhinoException ex)
Capture stack information from the given exception.
Specified by:
captureStackInfo in interface Evaluator
Parameters:
ex - an exception thrown during execution

compile

public Object compile(CompilerEnvirons compilerEnv,
                      ScriptOrFnNode tree,
                      String encodedSource,
                      boolean returnFunction)
Compile the script or function from intermediate representation tree into an executable form.
Specified by:
compile in interface Evaluator
Parameters:
compilerEnv - Compiler environment
tree - intermediate representation
encodedSource - encoding of the source code for decompilation
returnFunction - if true, compiling a function
Returns:
an opaque object that can be passed to either createFunctionObject or createScriptObject, depending on the value of returnFunction

createFunctionObject

public Function createFunctionObject(Context cx,
                                     Scriptable scope,
                                     Object bytecode,
                                     Object staticSecurityDomain)
Create a function object.
Specified by:
createFunctionObject in interface Evaluator
Parameters:
cx - Current context
scope - scope of the function
bytecode - opaque object returned by compile
staticSecurityDomain - security domain
Returns:
Function object that can be called

createScriptObject

public Script createScriptObject(Object bytecode,
                                 Object staticSecurityDomain)
Create a script object.
Specified by:
createScriptObject in interface Evaluator
Parameters:
bytecode - opaque object returned by compile
staticSecurityDomain - security domain
Returns:
Script object that can be evaluated

getPatchedStack

public String getPatchedStack(RhinoException ex,
                              String nativeStackTrace)
Given a native stack trace, patch it with script-specific source and line information
Specified by:
getPatchedStack in interface Evaluator
Parameters:
ex - exception
nativeStackTrace - the native stack trace
Returns:
patched stack trace

getScriptStack

public List getScriptStack(RhinoException ex)
Get the script stack for the given exception
Specified by:
getScriptStack in interface Evaluator
Parameters:
ex - exception from execution
Returns:
list of strings for the stack trace

getSourcePositionFromStack

public String getSourcePositionFromStack(Context cx,
                                         int[] linep)
Get the source position information by examining the stack.
Specified by:
getSourcePositionFromStack in interface Evaluator
Parameters:
cx - Context
linep - Array object of length >= 1; getSourcePositionFromStack will assign the line number to linep[0].
Returns:
the name of the file or other source container

restartContinuation

public static Object restartContinuation(NativeContinuation c,
                                         Context cx,
                                         Scriptable scope,
                                         Object[] args)

resumeGenerator

public static Object resumeGenerator(Context cx,
                                     Scriptable scope,
                                     int operation,
                                     Object savedState,
                                     Object value)

setEvalScriptFlag

public void setEvalScriptFlag(Script script)
Mark the given script to indicate it was created by a call to eval() or to a Function constructor.
Specified by:
setEvalScriptFlag in interface Evaluator
Parameters:
script - script to mark as from eval