mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] context
This commit is contained in:
parent
a59ca3fb26
commit
b1f2bea2bb
@ -81,13 +81,14 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
return NULL;
|
||||
}
|
||||
interpreter->backend_data = J;
|
||||
mjs_window_init(interpreter, J);
|
||||
mjs_screen_init(interpreter, J);
|
||||
mjs_unibar_init(interpreter, J);
|
||||
mjs_navigator_init(interpreter, J);
|
||||
mjs_history_init(interpreter, J);
|
||||
mjs_console_init(interpreter, J);
|
||||
mjs_localstorage_init(interpreter, J);
|
||||
js_setcontext(J, interpreter);
|
||||
mjs_window_init(J);
|
||||
mjs_screen_init(J);
|
||||
mjs_unibar_init(J);
|
||||
mjs_navigator_init(J);
|
||||
mjs_history_init(J);
|
||||
mjs_console_init(J);
|
||||
mjs_localstorage_init(J);
|
||||
|
||||
return J;
|
||||
#if 0
|
||||
|
@ -38,7 +38,7 @@ mjs_console_log_common(js_State *J, const char *str, const char *log_filename)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "console");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
|
||||
@ -87,21 +87,19 @@ mjs_console_toString(js_State *J)
|
||||
}
|
||||
|
||||
int
|
||||
mjs_console_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_console_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "console", interpreter, NULL);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_console_log, "console.log", 1);
|
||||
js_defproperty(J, -2, "log", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_console_log, "console.prototype.log", 1);
|
||||
js_defproperty(J, -2, "log", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_console_error, "console.prototype.error", 1);
|
||||
js_defproperty(J, -2, "error", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_console_toString, "console.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_console_error, "console.error", 1);
|
||||
js_defproperty(J, -2, "error", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_console_toString, "console.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
}
|
||||
js_defglobal(J, "console", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_console_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_console_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
@ -49,7 +49,7 @@ mjs_history_back(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "history");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
@ -70,7 +70,7 @@ mjs_history_forward(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "history");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
@ -87,7 +87,7 @@ mjs_history_go(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "history");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
@ -120,24 +120,22 @@ mjs_history_toString(js_State *J)
|
||||
}
|
||||
|
||||
int
|
||||
mjs_history_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_history_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "history", interpreter, NULL);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_history_back, "history.back", 0);
|
||||
js_defproperty(J, -2, "back", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_history_back, "history.prototype.back", 0);
|
||||
js_defproperty(J, -2, "back", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_history_forward, "history.forward", 0);
|
||||
js_defproperty(J, -2, "forward", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_history_forward, "history.prototype.forward", 0);
|
||||
js_defproperty(J, -2, "forward", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_history_go, "history.prototype.go", 1);
|
||||
js_defproperty(J, -2, "go", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_history_toString, "history.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_history_go, "history.go", 1);
|
||||
js_defproperty(J, -2, "go", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_history_toString, "history.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
}
|
||||
js_defglobal(J, "history", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_history_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_history_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
@ -144,7 +144,7 @@ mjs_localstorage_setitem(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "localStorage");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
const char *key_str = js_tostring(J, 1);
|
||||
const char *val_str = js_tostring(J, 2);
|
||||
|
||||
@ -170,24 +170,22 @@ mjs_localstorage_toString(js_State *J)
|
||||
}
|
||||
|
||||
int
|
||||
mjs_localstorage_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_localstorage_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "localStorage", interpreter, NULL);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_localstorage_getitem, "localStorage.getItem", 1);
|
||||
js_defproperty(J, -2, "getItem", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_localstorage_getitem, "localStorage.prototype.getItem", 1);
|
||||
js_defproperty(J, -2, "getItem", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_localstorage_removeitem, "localStorage.removeItem", 1);
|
||||
js_defproperty(J, -2, "removeItem", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_localstorage_removeitem, "localStorage.prototype.removeItem", 1);
|
||||
js_defproperty(J, -2, "removeItem", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_localstorage_setitem, "localStorage.prototype.setItem", 2);
|
||||
js_defproperty(J, -2, "setItem", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_localstorage_toString, "localStorage.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_localstorage_setitem, "localStorage.setItem", 2);
|
||||
js_defproperty(J, -2, "setItem", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_localstorage_toString, "localStorage.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
}
|
||||
js_defglobal(J, "localStorage", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_localstorage_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_localstorage_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
@ -141,38 +141,37 @@ mjs_navigator_toString(js_State *J)
|
||||
}
|
||||
|
||||
int
|
||||
mjs_navigator_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_navigator_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "navigator", interpreter, NULL);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_navigator_toString, "navigator.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_toString, "navigator.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_navigator_get_property_appCodeName, "navigator.appCodeName", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appCodeName", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appCodeName, "navigator.prototype.appCodeName", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appCodeName", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_navigator_get_property_appName, "navigator.appName", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appName", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appName, "navigator.prototype.appName", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appName", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_navigator_get_property_appVersion, "navigator.appVersion", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appVersion", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appVersion, "navigator.prototype.appVersion", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appVersion", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_navigator_get_property_language, "navigator.language", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "language", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_language, "navigator.prototype.language", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "language", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_navigator_get_property_platform, "navigator.platform", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "platform", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_platform, "navigator.prototype.platform", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "platform", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_userAgent, "navigator.prototype.userAgent", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "userAgent", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_navigator_get_property_userAgent, "navigator.userAgent", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "userAgent", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
}
|
||||
|
||||
js_defglobal(J, "navigator", JS_DONTENUM);
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_navigator_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_navigator_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
@ -50,7 +50,7 @@ mjs_screen_get_property_availHeight(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "screen");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -69,7 +69,7 @@ mjs_screen_get_property_availWidth(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "screen");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -88,7 +88,7 @@ mjs_screen_get_property_height(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "screen");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -116,7 +116,7 @@ mjs_screen_get_property_width(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "screen");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -145,31 +145,29 @@ mjs_screen_toString(js_State *J)
|
||||
}
|
||||
|
||||
int
|
||||
mjs_screen_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_screen_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype"); // window.prototype.[[Prototype]] = Object.prototype
|
||||
js_newuserdata(J, "screen", interpreter, NULL);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_screen_toString, "screen.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_screen_toString, "screen.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
js_newcfunction(J, mjs_screen_get_property_availHeight, "screen.availHeight", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "availHeight", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_screen_get_property_availHeight, "screen.prototype.availHeight", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "availHeight", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_screen_get_property_availWidth, "screen.availWidth", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "availWidth", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_screen_get_property_availWidth, "screen.prototype.availWidth", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "availWidth", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_screen_get_property_height, "screen.prototype.height", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "height", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_screen_get_property_width, "screen.prototype.width", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "width", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
js_newcfunction(J, mjs_screen_get_property_height, "screen.height", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "height", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_screen_get_property_width, "screen.width", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "width", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
}
|
||||
js_defglobal(J, "screen", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_screen_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_screen_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
@ -48,7 +48,7 @@ mjs_menubar_get_property_visible(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "menubar");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -71,7 +71,7 @@ mjs_statusbar_get_property_visible(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "statusbar");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -94,7 +94,7 @@ mjs_menubar_set_property_visible(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "menubar");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
int val = js_toboolean(J, 1);
|
||||
@ -117,7 +117,7 @@ mjs_statusbar_set_property_visible(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "statusbar");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
int val = js_toboolean(J, 1);
|
||||
@ -147,44 +147,40 @@ mjs_statusbar_toString(js_State *J)
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_menubar_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_menubar_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "menubar", interpreter, NULL);
|
||||
|
||||
js_newcfunction(J, mjs_menubar_toString, "menubar.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_menubar_get_property_visible, "menubar.prototype.visible", 0);
|
||||
js_newcfunction(J, mjs_menubar_set_property_visible, "menubar.prototype.visible", 1);
|
||||
js_defaccessor(J, -3, "visible", JS_DONTENUM | JS_DONTCONF);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_menubar_toString, "menubar.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_menubar_get_property_visible, "menubar.visible", 0);
|
||||
js_newcfunction(J, mjs_menubar_set_property_visible, "menubar.visible", 1);
|
||||
js_defaccessor(J, -3, "visible", JS_DONTENUM | JS_DONTCONF);
|
||||
}
|
||||
js_defglobal(J, "menubar", JS_DONTENUM);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_statusbar_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_statusbar_init(js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "statusbar", interpreter, NULL);
|
||||
|
||||
js_newcfunction(J, mjs_statusbar_toString, "statusbar.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_statusbar_get_property_visible, "statusbar.prototype.visible", 0);
|
||||
js_newcfunction(J, mjs_statusbar_set_property_visible, "statusbar.prototype.visible", 1);
|
||||
js_defaccessor(J, -3, "visible", JS_DONTENUM | JS_DONTCONF);
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_statusbar_toString, "statusbar.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_statusbar_get_property_visible, "statusbar.visible", 0);
|
||||
js_newcfunction(J, mjs_statusbar_set_property_visible, "statusbar.visible", 1);
|
||||
js_defaccessor(J, -3, "visible", JS_DONTENUM | JS_DONTCONF);
|
||||
}
|
||||
js_defglobal(J, "statusbar", JS_DONTENUM);
|
||||
}
|
||||
|
||||
int
|
||||
mjs_unibar_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_unibar_init(js_State *J)
|
||||
{
|
||||
mjs_menubar_init(interpreter, J);
|
||||
mjs_statusbar_init(interpreter, J);
|
||||
mjs_menubar_init(J);
|
||||
mjs_statusbar_init(J);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_unibar_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_unibar_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
@ -409,14 +409,6 @@ js_window_alert(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *a
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_window_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
return JS_NewString(ctx, "[window object]");
|
||||
}
|
||||
|
||||
static const JSCFunctionListEntry js_window_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("closed", js_window_get_property_closed, nullptr),
|
||||
@ -432,31 +424,12 @@ static const JSCFunctionListEntry js_window_proto_funcs[] = {
|
||||
JS_CFUNC_DEF("toString", 0, js_window_toString)
|
||||
};
|
||||
|
||||
static JSClassDef js_window_class = {
|
||||
"window",
|
||||
};
|
||||
|
||||
int
|
||||
js_window_init(JSContext *ctx)
|
||||
{
|
||||
/* create the window class */
|
||||
JS_NewClassID(&js_window_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_window_class_id, &js_window_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, global_obj, js_window_proto_funcs, countof(js_window_proto_funcs));
|
||||
JS_SetPropertyStr(ctx, global_obj, "window", global_obj);
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
mjs_window_alert(js_State *J)
|
||||
{
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "window");
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
@ -471,58 +444,28 @@ mjs_window_alert(js_State *J)
|
||||
}
|
||||
|
||||
js_pushundefined(J);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
mjs_window_toString(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
|
||||
assert(interpreter);
|
||||
struct view_state *vs;
|
||||
const char *str;
|
||||
char *string;
|
||||
size_t len;
|
||||
|
||||
vs = interpreter->vs;
|
||||
|
||||
if (argc != 1)
|
||||
return JS_UNDEFINED;
|
||||
|
||||
str = JS_ToCStringLen(ctx, &len, argv[0]);
|
||||
|
||||
if (!str) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
string = stracpy(str);
|
||||
JS_FreeCString(ctx, str);
|
||||
|
||||
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
|
||||
N_("JavaScript Alert"), ALIGN_CENTER, string);
|
||||
|
||||
return JS_UNDEFINED;
|
||||
#endif
|
||||
js_pushstring(J, "[window object]");
|
||||
}
|
||||
|
||||
int
|
||||
mjs_window_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
mjs_window_init(js_State *J)
|
||||
{
|
||||
fprintf(stderr, "mjs_window_init\n");
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_window_alert, "window.alert", 1);
|
||||
js_defproperty(J, -2, "alert", JS_DONTENUM);
|
||||
|
||||
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype"); // window.prototype.[[Prototype]] = Object.prototype
|
||||
js_newuserdata(J, "window", interpreter, NULL);
|
||||
js_newcfunction(J, mjs_window_alert, "window.prototype.alert", 1);
|
||||
js_defproperty(J, -2, "alert", JS_DONTENUM);
|
||||
// js_newcfunction(J, File_prototype_readLine, "File.prototype.readLine", 0);
|
||||
// js_defproperty(J, -2, "readLine", JS_DONTENUM);
|
||||
|
||||
// js_newcfunction(J, File_prototype_close, "File.prototype.close", 0);
|
||||
// js_defproperty(J, -2, "close", JS_DONTENUM);
|
||||
//
|
||||
// js_newcconstructor(J, new_File, new_File, "File", 1);
|
||||
js_newcfunction(J, mjs_window_toString, "window.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
}
|
||||
js_defglobal(J, "window", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_window_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
int mjs_window_init(js_State *J);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user