MCPcopy Create free account
hub / github.com/mozilla/rhino / NativeScript

Class NativeScript

rhino/src/main/java/org/mozilla/javascript/NativeScript.java:26–154  ·  view source on GitHub ↗

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, will forward

Source from the content-addressed store, hash-verified

24 * @author Norris Boyd
25 */
26class NativeScript extends BaseFunction {
27 @Serial private static final long serialVersionUID = -6795101161980121700L;
28
29 private static final String SCRIPT_TAG = "Script";
30
31 private static final ClassDescriptor DESCRIPTOR;
32
33 static {
34 DESCRIPTOR =
35 new ClassDescriptor.Builder(
36 SCRIPT_TAG,
37 1,
38 NativeScript::js_constructorCall,
39 NativeScript::js_constructor)
40 .withMethod(PROTO, "toString", 0, NativeScript::js_toString)
41 .withMethod(PROTO, "exec", 0, NativeScript::js_exec)
42 .withMethod(PROTO, "compile", 0, NativeScript::js_compile)
43 .build();
44 }
45
46 static JSFunction initLambda(Context cx, VarScope scope, boolean sealed) {
47 var proto = new NativeScript(null);
48 return DESCRIPTOR.buildConstructor(cx, scope, proto, sealed);
49 }
50
51 /**
52 * @deprecated Use {@link #init(Context, VarScope, boolean)} instead
53 */
54 @Deprecated
55 static void init(VarScope scope, boolean sealed) {
56 initLambda(Context.getContext(), scope, sealed);
57 }
58
59 private NativeScript(Script script) {
60 this.script = script;
61 }
62
63 /** Returns the name of this JavaScript class, "Script". */
64 @Override
65 public String getClassName() {
66 return "Script";
67 }
68
69 @Override
70 public Object call(Context cx, VarScope scope, Scriptable thisObj, Object[] args) {
71 if (script != null) {
72 return script.exec(cx, scope, thisObj);
73 }
74 return Undefined.instance;
75 }
76
77 @Override
78 public Scriptable construct(Context cx, VarScope scope, Object[] args) {
79 throw Context.reportRuntimeErrorById("msg.script.is.not.constructor");
80 }
81
82 @Override
83 public int getLength() {

Callers

nothing calls this directly

Calls 2

withMethodMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected