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

Class ScriptRuntime

rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java:60–6301  ·  view source on GitHub ↗

This is the class that implements the runtime. @author Norris Boyd

Source from the content-addressed store, hash-verified

58 * @author Norris Boyd
59 */
60public class ScriptRuntime {
61
62 /** No instances should be created. */
63 protected ScriptRuntime() {}
64
65 /**
66 * Returns representation of the [[ThrowTypeError]] object. See ECMA 5 spec, 13.2.3
67 *
68 * @return a {@link BaseFunction}
69 * @deprecated {@link #typeErrorThrower(Context)}
70 */
71 @Deprecated
72 public static BaseFunction typeErrorThrower() {
73 return typeErrorThrower(Context.getCurrentContext());
74 }
75
76 /** Returns representation of the [[ThrowTypeError]] object. See ECMA 5 spec, 13.2.3 */
77 public static BaseFunction typeErrorThrower(Context cx) {
78 return typeErrorThrower(cx.topCallScope);
79 }
80
81 private static final SymbolKey TYPE_ERROR_THROWER = new SymbolKey("TypeErrorThrower", REGULAR);
82
83 public static BaseFunction typeErrorThrower(VarScope scope) {
84 TopLevel top = ScriptableObject.getTopLevelScope(scope);
85 var thrower = top.get(TYPE_ERROR_THROWER, top);
86 if (thrower == NOT_FOUND) {
87 thrower = new ThrowTypeError(top);
88 top.defineProperty(TYPE_ERROR_THROWER, thrower, DONTENUM | READONLY | PERMANENT);
89 }
90 return (BaseFunction) thrower;
91 }
92
93 static final class ThrowTypeError extends BaseFunction {
94 private static final long serialVersionUID = -5891740962154902286L;
95
96 ThrowTypeError(VarScope scope) {
97 setPrototype(ScriptableObject.getFunctionPrototype(scope));
98
99 setAttributes("length", DONTENUM | PERMANENT | READONLY);
100 setAttributes("name", DONTENUM | PERMANENT | READONLY);
101
102 // delete arity and arguments (without further checking)
103 getMap().compute(this, "arity", 0, ThrowTypeError::removeWithoutChecking);
104 getMap().compute(this, "arguments", 0, ThrowTypeError::removeWithoutChecking);
105
106 preventExtensions();
107 }
108
109 private static <T extends PropHolder<T>> Slot<T> removeWithoutChecking(
110 Object key,
111 int index,
112 Slot slot,
113 CompoundOperationMap<T> compoundOp,
114 SlotMapOwner<T> owner) {
115 return null;
116 }
117

Callers

nothing calls this directly

Calls 4

classOrNullMethod · 0.95
detectAndroidApiMethod · 0.95
valueOfMethod · 0.45

Tested by

no test coverage detected