Add navigator.userAgent to qjs CLI

This commit is contained in:
Saúl Ibarra Corretgé 2023-12-11 09:52:48 +01:00
parent bace4f635e
commit 030a0ddf3f

8
qjs.c
View file

@ -104,6 +104,14 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
/* system modules */
js_init_module_std(ctx, "std");
js_init_module_os(ctx, "os");
/* navigator.userAgent */
JSValue global = JS_GetGlobalObject(ctx);
JSValue navigator = JS_NewObject(ctx);
JS_DefinePropertyValueStr(ctx, navigator, "userAgent", JS_NewString(ctx, "quickjs-ng"), JS_PROP_ENUMERABLE);
JS_DefinePropertyValueStr(ctx, global, "navigator", navigator, JS_PROP_ENUMERABLE);
JS_FreeValue(ctx, global);
return ctx;
}