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

Class JSFunction

rhino/src/main/java/org/mozilla/javascript/JSFunction.java:11–256  ·  view source on GitHub ↗

Represents a JavaScript function built upon a a JSDescriptor. All the immutable metadata associated with the function is stored on the descriptor, with only the lexically bound this, the home object required for super calls, and mutable properties held on the function object itself.

Source from the content-addressed store, hash-verified

9 * home object required for super calls, and mutable properties held on the function object itself.
10 */
11public class JSFunction extends BaseFunction implements ScriptOrFn<JSFunction> {
12 private final JSDescriptor<JSFunction> descriptor;
13 private final Scriptable lexicalThis;
14 private final Scriptable homeObject;
15
16 public JSFunction(
17 Context cx,
18 VarScope scope,
19 JSDescriptor<JSFunction> descriptor,
20 Scriptable lexicalThis,
21 Scriptable homeObject) {
22 this.descriptor = descriptor;
23 this.lexicalThis = lexicalThis;
24 this.homeObject = homeObject;
25 ScriptRuntime.setFunctionProtoAndParent(this, cx, scope, descriptor.isES6Generator());
26 if (!descriptor.isShorthand()) {
27 setupDefaultPrototype(scope);
28 }
29 }
30
31 JSFunction(
32 VarScope scope,
33 JSDescriptor<JSFunction> descriptor,
34 Scriptable lexicalThis,
35 Scriptable homeObject) {
36 this.descriptor = descriptor;
37 this.lexicalThis = lexicalThis;
38 this.homeObject = homeObject;
39 setParentScope(scope);
40 setPrototype(ScriptableObject.getFunctionPrototype(scope));
41 }
42
43 @Override
44 protected void setPrototypeProperty(Object prototype) {
45 super.setPrototypeProperty(prototype);
46 }
47
48 @Override
49 public VarScope getDeclarationScope() {
50 return this.getParentScope();
51 }
52
53 @Override
54 public JSDescriptor<JSFunction> getDescriptor() {
55 return descriptor;
56 }
57
58 @Override
59 final String decompile(int indent, EnumSet<DecompilerFlag> flags) {
60 return descriptor.getRawSource();
61 }
62
63 public boolean isShorthand() {
64 return descriptor.isShorthand();
65 }
66
67 public boolean isStrict() {
68 return descriptor.isStrict();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected