@@ -137,13 +137,20 @@ static JSValue js_gc(JSContext *ctx, JSValue this_val,
137
137
return JS_UNDEFINED ;
138
138
}
139
139
140
- static const JSCFunctionListEntry navigator_obj [] = {
141
- JS_PROP_STRING_DEF ("userAgent" , "quickjs-ng" , JS_PROP_ENUMERABLE ),
140
+ static JSValue js_navigator_get_userAgent (JSContext * ctx , JSValue this_val )
141
+ {
142
+ char version [32 ];
143
+ snprintf (version , sizeof (version ), "quickjs-ng/%s" , JS_GetVersion ());
144
+ return JS_NewString (ctx , version );
145
+ }
146
+
147
+ static const JSCFunctionListEntry navigator_proto_funcs [] = {
148
+ JS_CGETSET_DEF2 ("userAgent" , js_navigator_get_userAgent , NULL , JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE ),
149
+ JS_PROP_STRING_DEF ("[Symbol.toStringTag]" , "Navigator" , JS_PROP_CONFIGURABLE ),
142
150
};
143
151
144
152
static const JSCFunctionListEntry global_obj [] = {
145
153
JS_CFUNC_DEF ("gc" , 0 , js_gc ),
146
- JS_OBJECT_DEF ("navigator" , navigator_obj , countof (navigator_obj ), JS_PROP_C_W_E ),
147
154
#if defined(__ASAN__ ) || defined (__UBSAN__ )
148
155
JS_PROP_INT32_DEF ("__running_with_sanitizer__" , 1 , JS_PROP_C_W_E ),
149
156
#endif
@@ -164,7 +171,12 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
164
171
JSValue global = JS_GetGlobalObject (ctx );
165
172
JS_SetPropertyFunctionList (ctx , global , global_obj , countof (global_obj ));
166
173
JS_SetPropertyFunctionList (ctx , global , & argv0 , 1 );
174
+ JSValue navigator_proto = JS_NewObject (ctx );
175
+ JS_SetPropertyFunctionList (ctx , navigator_proto , navigator_proto_funcs , countof (navigator_proto_funcs ));
176
+ JSValue navigator = JS_NewObjectProto (ctx , navigator_proto );
177
+ JS_DefinePropertyValueStr (ctx , global , "navigator" , navigator , JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE );
167
178
JS_FreeValue (ctx , global );
179
+ JS_FreeValue (ctx , navigator_proto );
168
180
169
181
return ctx ;
170
182
}
0 commit comments