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

Function js_loadScript

deps/quickjs/quickjs-libc.c:492–514  ·  view source on GitHub ↗

load and evaluate a file */

Source from the content-addressed store, hash-verified

490
491/* load and evaluate a file */
492static JSValue js_loadScript(JSContext *ctx, JSValueConst this_val,
493 int argc, JSValueConst *argv)
494{
495 uint8_t *buf;
496 const char *filename;
497 JSValue ret;
498 size_t buf_len;
499
500 filename = JS_ToCString(ctx, argv[0]);
501 if (!filename)
502 return JS_EXCEPTION;
503 buf = js_load_file(ctx, &buf_len, filename);
504 if (!buf) {
505 JS_ThrowReferenceError(ctx, "could not load '%s'", filename);
506 JS_FreeCString(ctx, filename);
507 return JS_EXCEPTION;
508 }
509 ret = JS_Eval(ctx, (char *)buf, buf_len, filename,
510 JS_EVAL_TYPE_GLOBAL);
511 js_free(ctx, buf);
512 JS_FreeCString(ctx, filename);
513 return ret;
514}
515
516static int get_bool_option(JSContext *ctx, bool *pbool,
517 JSValueConst obj,

Callers

nothing calls this directly

Calls 2

JS_ToCStringFunction · 0.85
js_load_fileFunction · 0.85

Tested by

no test coverage detected