mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[quickjs] Call JS_GetGlobalObject in every init function
This commit is contained in:
parent
fa712cd0e5
commit
30dd9935d2
@ -163,18 +163,16 @@ quickjs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
|
||||
// JS::RootedObject window_obj(ctx, JS_NewGlobalObject(ctx, &window_class, NULL, JS::FireOnNewGlobalHook, options));
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
js_window_init(ctx, global_obj);
|
||||
js_screen_init(ctx, global_obj);
|
||||
js_unibar_init(ctx, global_obj);
|
||||
js_navigator_init(ctx, global_obj);
|
||||
js_history_init(ctx, global_obj);
|
||||
js_console_init(ctx, global_obj);
|
||||
js_localstorage_init(ctx, global_obj);
|
||||
interpreter->document_obj = js_document_init(ctx, global_obj);
|
||||
interpreter->location_obj = js_location_init(ctx, global_obj);
|
||||
js_window_init(ctx);
|
||||
js_screen_init(ctx);
|
||||
js_unibar_init(ctx);
|
||||
js_navigator_init(ctx);
|
||||
js_history_init(ctx);
|
||||
js_console_init(ctx);
|
||||
js_localstorage_init(ctx);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
interpreter->document_obj = js_document_init(ctx);
|
||||
interpreter->location_obj = js_location_init(ctx);
|
||||
|
||||
return ctx;
|
||||
#if 0
|
||||
|
@ -122,7 +122,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_console_init(JSContext *ctx, JSValue global_obj)
|
||||
js_console_init(JSContext *ctx)
|
||||
{
|
||||
JSValue console_proto, console_class;
|
||||
|
||||
@ -130,6 +130,8 @@ js_console_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_console_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_console_class_id, &js_console_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
console_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, console_proto, js_console_funcs, countof(js_console_funcs));
|
||||
|
||||
@ -139,5 +141,8 @@ js_console_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_console_class_id, console_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "console", console_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
int js_console_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_console_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -1652,7 +1652,7 @@ fail:
|
||||
}
|
||||
|
||||
JSValue
|
||||
js_document_init(JSContext *ctx, JSValue global_obj)
|
||||
js_document_init(JSContext *ctx)
|
||||
{
|
||||
JSValue document_proto, document_class;
|
||||
|
||||
@ -1660,6 +1660,8 @@ js_document_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_document_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_document_class_id, &js_document_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
document_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, document_proto, js_document_proto_funcs, countof(js_document_proto_funcs));
|
||||
|
||||
@ -1670,6 +1672,8 @@ js_document_init(JSContext *ctx, JSValue global_obj)
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "document", document_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
RETURN_JS(document_proto);
|
||||
}
|
||||
|
||||
@ -1720,7 +1724,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_doctype_init(JSContext *ctx, JSValue global_obj)
|
||||
js_doctype_init(JSContext *ctx)
|
||||
{
|
||||
JSValue doctype_proto, doctype_class;
|
||||
|
||||
@ -1728,6 +1732,8 @@ js_doctype_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_doctype_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_doctype_class_id, &js_doctype_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
doctype_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, doctype_proto, js_doctype_proto_funcs, countof(js_doctype_proto_funcs));
|
||||
|
||||
@ -1737,6 +1743,9 @@ js_doctype_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_doctype_class_id, doctype_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "doctype", doctype_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,6 @@
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
JSValue getDocument(JSContext *ctx, void *doc);
|
||||
JSValue js_document_init(JSContext *ctx, JSValue global_obj);
|
||||
JSValue js_document_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -157,7 +157,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_history_init(JSContext *ctx, JSValue global_obj)
|
||||
js_history_init(JSContext *ctx)
|
||||
{
|
||||
JSValue history_proto, history_class;
|
||||
|
||||
@ -165,6 +165,8 @@ js_history_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_history_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_history_class_id, &js_history_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
history_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, history_proto, js_history_funcs, countof(js_history_funcs));
|
||||
|
||||
@ -174,5 +176,8 @@ js_history_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_history_class_id, history_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "history", history_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
int js_history_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_history_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -202,7 +202,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_localstorage_init(JSContext *ctx, JSValue global_obj)
|
||||
js_localstorage_init(JSContext *ctx)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
@ -216,11 +216,15 @@ js_localstorage_init(JSContext *ctx, JSValue global_obj)
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
JSValue localstorage_obj = JS_NewObjectClass(ctx, js_localstorage_class_id);
|
||||
JS_SetPropertyFunctionList(ctx, localstorage_obj, js_localstorage_proto_funcs, countof(js_localstorage_proto_funcs));
|
||||
JS_SetClassProto(ctx, js_localstorage_class_id, localstorage_obj);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "localStorage", localstorage_obj);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
int js_localstorage_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_localstorage_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -622,7 +622,7 @@ fail:
|
||||
}
|
||||
|
||||
JSValue
|
||||
js_location_init(JSContext *ctx, JSValue global_obj)
|
||||
js_location_init(JSContext *ctx)
|
||||
{
|
||||
JSValue location_proto, location_class;
|
||||
|
||||
@ -630,6 +630,8 @@ js_location_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_location_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_location_class_id, &js_location_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
location_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, location_proto, js_location_proto_funcs, countof(js_location_proto_funcs));
|
||||
|
||||
@ -639,5 +641,8 @@ js_location_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_location_class_id, location_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "location", location_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
RETURN_JS(location_proto);
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
JSValue js_location_init(JSContext *ctx, JSValue global_obj);
|
||||
JSValue js_location_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -180,7 +180,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_navigator_init(JSContext *ctx, JSValue global_obj)
|
||||
js_navigator_init(JSContext *ctx)
|
||||
{
|
||||
JSValue navigator_proto, navigator_class;
|
||||
|
||||
@ -188,6 +188,8 @@ js_navigator_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_navigator_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_navigator_class_id, &js_navigator_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
navigator_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, navigator_proto, js_navigator_proto_funcs, countof(js_navigator_proto_funcs));
|
||||
|
||||
@ -197,5 +199,8 @@ js_navigator_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_navigator_class_id, navigator_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "navigator", navigator_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,5 +2,5 @@
|
||||
#define EL__ECMASCRIPT_QUICKJS_NAVIGATOR_H
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
int js_navigator_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_navigator_init(JSContext *ctx);
|
||||
#endif
|
||||
|
@ -171,7 +171,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_screen_init(JSContext *ctx, JSValue global_obj)
|
||||
js_screen_init(JSContext *ctx)
|
||||
{
|
||||
JSValue screen_proto, screen_class;
|
||||
|
||||
@ -179,6 +179,8 @@ js_screen_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_screen_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_screen_class_id, &js_screen_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
screen_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, screen_proto, js_screen_proto_funcs, countof(js_screen_proto_funcs));
|
||||
|
||||
@ -188,5 +190,8 @@ js_screen_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_screen_class_id, screen_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "screen", screen_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
int js_screen_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_screen_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -177,7 +177,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_unibar_init(JSContext *ctx, JSValue global_obj)
|
||||
js_unibar_init(JSContext *ctx)
|
||||
{
|
||||
JSValue menubar_proto, menubar_class;
|
||||
JSValue statusbar_proto, statusbar_class;
|
||||
@ -185,6 +185,9 @@ js_unibar_init(JSContext *ctx, JSValue global_obj)
|
||||
/* create the menubar class */
|
||||
JS_NewClassID(&js_menubar_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_menubar_class_id, &js_menubar_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
menubar_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, menubar_proto, js_menubar_proto_funcs, countof(js_menubar_proto_funcs));
|
||||
menubar_class = JS_NewCFunction2(ctx, js_menubar_ctor, "menubar", 2, JS_CFUNC_constructor, 0);
|
||||
@ -205,5 +208,7 @@ js_unibar_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_statusbar_class_id, statusbar_proto);
|
||||
JS_SetPropertyStr(ctx, global_obj, "statusbar", statusbar_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
int js_unibar_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_unibar_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -415,7 +415,7 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
js_window_init(JSContext *ctx, JSValue global_obj)
|
||||
js_window_init(JSContext *ctx)
|
||||
{
|
||||
JSValue window_proto, window_class;
|
||||
|
||||
@ -423,6 +423,8 @@ js_window_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_NewClassID(&js_window_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_window_class_id, &js_window_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
window_proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, window_proto, js_window_proto_funcs, countof(js_window_proto_funcs));
|
||||
|
||||
@ -432,5 +434,8 @@ js_window_init(JSContext *ctx, JSValue global_obj)
|
||||
JS_SetClassProto(ctx, js_window_class_id, window_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "window", window_proto);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
int js_window_init(JSContext *ctx, JSValue global_obj);
|
||||
int js_window_init(JSContext *ctx);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user