MCPcopy Create free account
hub / github.com/dynjs/dynjs / IRJSFunction

Class IRJSFunction

src/main/java/org/dynjs/ir/IRJSFunction.java:18–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16import java.util.List;
17
18public class IRJSFunction extends DynObject implements JSFunction {
19 private final FunctionScope scope;
20 private Instruction[] instructions;
21 private final LexicalEnvironment lexicalEnvironment;
22 private String debugContext = "";
23 // Lexically-captured values of this function
24 private VariableValues capturedValues;
25
26 public JSFunction compile(ExecutionContext context) {
27 return new IRByteCodeCompiler(scope, getFileName(), isStrict()).compileFunction(context);
28 }
29
30 private static class IRJSFunctionBox {
31 public int callCount = 0;
32 public JSCallable compiledFunction;
33 public boolean compilationInProgress;
34 }
35
36 private IRJSFunctionBox box = new IRJSFunctionBox();
37
38 public IRJSFunction(FunctionScope scope, VariableValues capturedValues, LexicalEnvironment lexicalEnvironment,
39 GlobalContext globalContext) {
40 super(globalContext);
41 this.scope = scope;
42 this.instructions = scope.prepareForInterpret(); // FIXME This is a big up front cost...make lazy
43 this.lexicalEnvironment = lexicalEnvironment;
44 this.capturedValues = capturedValues;
45 }
46
47 public String[] getFormalParameters() {
48 return scope.getParameterNames();
49 }
50
51 public LexicalEnvironment getScope() {
52 return lexicalEnvironment;
53 }
54
55 @Override
56 public String getFileName() {
57 return scope.getFileName();
58 }
59
60 // FIXME: Not sure but constructor is likely a different beast than IRJSFunction
61 public boolean isConstructor() {
62 return false;
63 }
64
65 public String getDebugContext() {
66 return debugContext;
67 }
68
69 public void setDebugContext(String debugContext) {
70 this.debugContext = debugContext;
71 }
72
73 public JSObject createNewObject(ExecutionContext context) {
74 return new DynObject(context.getGlobalContext());
75 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected