MCPcopy Create free account
hub / github.com/buke/quickjs-go / eval_buf

Function eval_buf

deps/quickjs/qjs.c:107–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
108 const char *filename, int eval_flags)
109{
110 bool use_realpath;
111 JSValue val;
112 int ret;
113
114 if ((eval_flags & JS_EVAL_TYPE_MASK) == JS_EVAL_TYPE_MODULE) {
115 /* for the modules, we compile then run to be able to set
116 import.meta */
117 val = JS_Eval(ctx, buf, buf_len, filename,
118 eval_flags | JS_EVAL_FLAG_COMPILE_ONLY);
119 if (!JS_IsException(val)) {
120 // ex. "<cmdline>" pr "/dev/stdin"
121 use_realpath =
122 !(*filename == '<' || !strncmp(filename, "/dev/", 5));
123 if (js_module_set_import_meta(ctx, val, use_realpath, true) < 0) {
124 js_std_dump_error(ctx);
125 ret = -1;
126 goto end;
127 }
128 val = JS_EvalFunction(ctx, val);
129 }
130 val = js_std_await(ctx, val);
131 } else {
132 val = JS_Eval(ctx, buf, buf_len, filename, eval_flags);
133 }
134 if (JS_IsException(val)) {
135 js_std_dump_error(ctx);
136 ret = -1;
137 } else {
138 ret = 0;
139 }
140end:
141 JS_FreeValue(ctx, val);
142 return ret;
143}
144
145static int eval_file(JSContext *ctx, const char *filename, int module)
146{

Callers 3

qjs_init_argvFunction · 0.70
eval_fileFunction · 0.70
mainFunction · 0.70

Calls 4

JS_IsExceptionFunction · 0.85
js_std_dump_errorFunction · 0.85
js_std_awaitFunction · 0.85

Tested by

no test coverage detected