org.mozilla.javascript
Class NativeScript

java.lang.Object
  |
  +--org.mozilla.javascript.ScriptableObject
        |
        +--org.mozilla.javascript.IdScriptable
              |
              +--org.mozilla.javascript.BaseFunction
                    |
                    +--org.mozilla.javascript.NativeFunction
                          |
                          +--org.mozilla.javascript.NativeScript
All Implemented Interfaces:
Function, IdFunctionMaster, Script, Scriptable, java.io.Serializable
Direct Known Subclasses:
InterpretedScript

public class NativeScript
extends NativeFunction
implements Script

The JavaScript Script object. Note that the C version of the engine uses XDR as the format used by freeze and thaw. Since this depends on the internal format of structures in the C runtime, we cannot duplicate it. Since we cannot replace 'this' as a result of the compile method, this class has a dual nature. Generated scripts will have a null 'script' field and will override 'exec' and 'call'. Scripts created using the JavaScript constructor will forward requests to the nonnull 'script' field.

Since:
1.3
Author:
Norris Boyd
See Also:
Serialized Form

Fields inherited from class org.mozilla.javascript.NativeFunction
debug_level, debug_srcName, nestedFunctions
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
DONTENUM, EMPTY, PERMANENT, READONLY
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
NativeScript()
           
 
Method Summary
 java.lang.Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
          Should be overridden.
static Script compile(Scriptable scope, java.lang.String source)
           
 Scriptable construct(Context cx, Scriptable scope, java.lang.Object[] args)
          Call the function as a constructor.
 java.lang.Object exec(Context cx, Scriptable scope)
          Execute the script.
 java.lang.Object execMethod(int methodId, IdFunction f, Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
          'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned.
 java.lang.String getClassName()
          Returns the name of this JavaScript class, "Script".
 java.lang.String getFunctionName()
           
static void init(Context cx, Scriptable scope, boolean sealed)
           
 void initScript(Scriptable scope)
          Initialize script.
 int methodArity(int methodId)
          Get arity or defined argument count for method with given id.
 
Methods inherited from class org.mozilla.javascript.NativeFunction
decompile, getArity, getLength, jsGet_name
 
Methods inherited from class org.mozilla.javascript.BaseFunction
hasInstance, setImmunePrototypeProperty
 
Methods inherited from class org.mozilla.javascript.IdScriptable
addAsPrototype, defineProperty, delete, get, getAttributes, has, put, setAttributes
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
callMethod, defineClass, defineClass, defineFunctionProperties, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, get, getAllIds, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, has, hasProperty, hasProperty, isSealed, put, putProperty, putProperty, sealObject, setAttributes, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mozilla.javascript.Scriptable
delete, delete, get, get, getDefaultValue, getIds, getParentScope, getPrototype, has, has, put, put, setParentScope, setPrototype
 

Constructor Detail

NativeScript

public NativeScript()
Method Detail

init

public static void init(Context cx,
                        Scriptable scope,
                        boolean sealed)

getClassName

public java.lang.String getClassName()
Returns the name of this JavaScript class, "Script".
Overrides:
getClassName in class BaseFunction

initScript

public void initScript(Scriptable scope)
Initialize script. Does nothing here, but scripts will override with code to initialize contained functions, regexp literals, etc.

methodArity

public int methodArity(int methodId)
Description copied from class: IdScriptable
Get arity or defined argument count for method with given id. Should return -1 if methodId is not known or can not be used with execMethod call.
Overrides:
methodArity in class BaseFunction

execMethod

public java.lang.Object execMethod(int methodId,
                                   IdFunction f,
                                   Context cx,
                                   Scriptable scope,
                                   Scriptable thisObj,
                                   java.lang.Object[] args)
                            throws JavaScriptException
Description copied from class: IdScriptable
'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned.
Overrides:
execMethod in class BaseFunction

compile

public static Script compile(Scriptable scope,
                             java.lang.String source)

getFunctionName

public java.lang.String getFunctionName()
Overrides:
getFunctionName in class BaseFunction

exec

public java.lang.Object exec(Context cx,
                             Scriptable scope)
                      throws JavaScriptException
Execute the script. Will be overridden by generated scripts; needed to implement Script.
Specified by:
exec in interface Script
Following copied from interface: org.mozilla.javascript.Script
Parameters:
cx - the Context associated with the current thread
scope - the scope to execute relative to
Returns:
the result of executing the script
Throws:
JavaScriptException - if an uncaught JavaScript exception occurred while executing the script
See Also:
Context.initStandardObjects(org.mozilla.javascript.ScriptableObject)

call

public java.lang.Object call(Context cx,
                             Scriptable scope,
                             Scriptable thisObj,
                             java.lang.Object[] args)
                      throws JavaScriptException
Description copied from class: BaseFunction
Should be overridden.
Overrides:
call in class BaseFunction
Following copied from interface: org.mozilla.javascript.Function
Parameters:
cx - the current Context for this thread
scope - the scope to execute the function relative to. This is set to the value returned by getParentScope() except when the function is called from a closure.
thisObj - the JavaScript this object
args - the array of arguments
Returns:
the result of the call
Throws:
JavaScriptException - if an uncaught exception occurred while executing the function

construct

public Scriptable construct(Context cx,
                            Scriptable scope,
                            java.lang.Object[] args)
                     throws JavaScriptException
Description copied from interface: Function
Call the function as a constructor. This method is invoked by the runtime in order to satisfy a use of the JavaScript new operator. This method is expected to create a new object and return it.
Overrides:
construct in class BaseFunction
Following copied from interface: org.mozilla.javascript.Function
Parameters:
cx - the current Context for this thread
scope - an enclosing scope of the caller except when the function is called from a closure.
args - the array of arguments
Returns:
the allocated object
Throws:
JavaScriptException - if an uncaught exception occurred while executing the constructor