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

Method call

src/main/java/org/dynjs/runtime/builtins/Include.java:30–65  ·  view source on GitHub ↗
(ExecutionContext context, Object self, Object... args)

Source from the content-addressed store, hash-verified

28 }
29
30 @Override
31 public Object call(ExecutionContext context, Object self, Object... args) {
32 String includePath = Types.toString(context, args[0]);
33 File includeFile = new File(includePath);
34
35 try {
36 ExecutionContext parent = context.getParent();
37 while (parent != null) {
38 context = parent;
39 parent = context.getParent();
40 }
41 Runner runner = context.getRuntime().newRunner();
42 if (includeFile.exists()) {
43 runner.withContext(context)
44 .withSource(includeFile)
45 .execute();
46 } else {
47 InputStream is = context.getClassLoader().getResourceAsStream(includePath);
48 if (is == null) {
49 throw new FileNotFoundException(includePath);
50 }
51 BufferedReader reader = new BufferedReader(new InputStreamReader(is));
52 Object ret = runner.withContext(context).withSource(reader).execute();
53 try {
54 is.close();
55 } catch (IOException e) {
56 // ignore
57 }
58 return ret;
59 }
60 } catch (IOException e) {
61 throw new ThrowException(context, context.createError("Error", e.getMessage()));
62 }
63
64 return Types.UNDEFINED;
65 }
66
67 @Override
68 public void setFileName() {

Callers

nothing calls this directly

Calls 10

toStringMethod · 0.95
withContextMethod · 0.95
newRunnerMethod · 0.80
createErrorMethod · 0.80
executeMethod · 0.65
getClassLoaderMethod · 0.65
getParentMethod · 0.45
getRuntimeMethod · 0.45
withSourceMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected