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

Function JS_NewCustomContext

deps/quickjs/qjs.c:223–251  ·  view source on GitHub ↗

also used to initialize the worker context */

Source from the content-addressed store, hash-verified

221
222/* also used to initialize the worker context */
223static JSContext *JS_NewCustomContext(JSRuntime *rt)
224{
225 JSContext *ctx;
226 ctx = JS_NewContext(rt);
227 if (!ctx)
228 return NULL;
229 /* system modules */
230 js_init_module_std(ctx, "qjs:std");
231 js_init_module_os(ctx, "qjs:os");
232 js_init_module_bjson(ctx, "qjs:bjson");
233
234 JSValue global = JS_GetGlobalObject(ctx);
235 JS_SetPropertyFunctionList(ctx, global, global_obj, countof(global_obj));
236 JSValue args = JS_NewArray(ctx);
237 int i;
238 for(i = 0; i < qjs__argc; i++) {
239 JS_SetPropertyUint32(ctx, args, i, JS_NewString(ctx, qjs__argv[i]));
240 }
241 JS_SetPropertyStr(ctx, global, "execArgv", args);
242 JS_SetPropertyStr(ctx, global, "argv0", JS_NewString(ctx, qjs__argv[0]));
243 JSValue navigator_proto = JS_NewObject(ctx);
244 JS_SetPropertyFunctionList(ctx, navigator_proto, navigator_proto_funcs, countof(navigator_proto_funcs));
245 JSValue navigator = JS_NewObjectProto(ctx, navigator_proto);
246 JS_DefinePropertyValueStr(ctx, global, "navigator", navigator, JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE);
247 JS_FreeValue(ctx, global);
248 JS_FreeValue(ctx, navigator_proto);
249
250 return ctx;
251}
252
253struct trace_malloc_data {
254 uint8_t *base;

Callers 2

qjs_init_argvFunction · 0.70
mainFunction · 0.70

Calls 4

js_init_module_stdFunction · 0.85
js_init_module_osFunction · 0.85
js_init_module_bjsonFunction · 0.85
JS_NewStringFunction · 0.85

Tested by

no test coverage detected