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

Class AbstractCode

src/main/java/org/dynjs/runtime/AbstractCode.java:12–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import org.dynjs.parser.ast.VariableStatement;
11
12public abstract class AbstractCode implements JSCode {
13
14 private Statement block;
15 private boolean strict;
16
17 public AbstractCode(Statement block) {
18 this(block, false);
19 }
20
21 public AbstractCode(Statement block, boolean strict) {
22 this.block = block;
23 this.strict = strict;
24 }
25
26 public boolean isStrict() {
27 return this.strict;
28 }
29
30 public void setStrict(boolean strict) {
31 this.strict = strict;
32 }
33
34 public Statement getBlock() {
35 return this.block;
36 }
37
38 @Override
39 public List<FunctionDeclaration> getFunctionDeclarations() {
40 if (this.block instanceof BlockStatement) {
41 return ((BlockStatement) this.block).getFunctionDeclarations();
42 }
43
44 if (this.block instanceof FunctionDeclaration) {
45 return Collections.singletonList((FunctionDeclaration) this.block);
46 }
47
48 return Collections.emptyList();
49 }
50
51 public List<VariableDeclaration> getVariableDeclarations() {
52 if (block instanceof BlockStatement) {
53 return ((BlockStatement) block).getVariableDeclarations();
54 }
55
56 if (block instanceof VariableStatement) {
57 return ((VariableStatement) block).getVariableDeclarations();
58 }
59
60 return Collections.emptyList();
61 }
62
63 public String getFileName() {
64 String name = null;
65 if (this.block.getPosition() != null) {
66 name = this.block.getPosition().getFileName();
67 }
68 if (name == null) {
69 name = "<eval>";

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected