mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] addmethod copied from mupdf
This commit is contained in:
parent
b1f2bea2bb
commit
72b8c508a3
@ -330,6 +330,28 @@ mujs_eval_boolback(struct ecmascript_interpreter *interpreter,
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
addmethod(js_State *J, const char *name, js_CFunction fun, int n)
|
||||
{
|
||||
const char *realname = strchr(name, '.');
|
||||
realname = realname ? realname + 1 : name;
|
||||
js_newcfunction(J, fun, name, n);
|
||||
js_defproperty(J, -2, realname, JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
}
|
||||
|
||||
void addproperty(js_State *J, const char *name, js_CFunction getfun, js_CFunction setfun)
|
||||
{
|
||||
const char *realname = strchr(name, '.');
|
||||
realname = realname ? realname + 1 : name;
|
||||
js_newcfunction(J, getfun, name, 0);
|
||||
if (setfun) {
|
||||
js_newcfunction(J, setfun, name, 1);
|
||||
} else {
|
||||
js_pushnull(J);
|
||||
}
|
||||
js_defaccessor(J, -3, realname, JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
}
|
||||
|
||||
struct module mujs_module = struct_module(
|
||||
/* name: */ N_("mujs"),
|
||||
/* options: */ NULL,
|
||||
|
@ -41,5 +41,8 @@ int mujs_eval_boolback(struct ecmascript_interpreter *interpreter, struct string
|
||||
|
||||
//void mujs_call_function(struct ecmascript_interpreter *interpreter, JSValueConst fun, struct string *ret);
|
||||
|
||||
void addmethod(js_State *J, const char *name, js_CFunction fun, int n);
|
||||
void addproperty(js_State *J, const char *name, js_CFunction getfun, js_CFunction setfun);
|
||||
|
||||
extern struct module mujs_module;
|
||||
#endif
|
||||
|
@ -91,14 +91,9 @@ mjs_console_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_console_log, "console.log", 1);
|
||||
js_defproperty(J, -2, "log", 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);
|
||||
addmethod(J, "console.log", mjs_console_log, 1);
|
||||
addmethod(J, "console.error", mjs_console_error, 1);
|
||||
addmethod(J, "console.toString", mjs_console_toString, 0);
|
||||
}
|
||||
js_defglobal(J, "console", JS_DONTENUM);
|
||||
|
||||
|
@ -124,17 +124,10 @@ mjs_history_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_history_back, "history.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_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);
|
||||
addmethod(J, "history.back", mjs_history_back, 0);
|
||||
addmethod(J, "history.forward", mjs_history_forward, 0);
|
||||
addmethod(J, "history.go", mjs_history_go, 1);
|
||||
addmethod(J, "history.toString", mjs_history_toString, 0);
|
||||
}
|
||||
js_defglobal(J, "history", JS_DONTENUM);
|
||||
|
||||
|
@ -174,17 +174,10 @@ mjs_localstorage_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_localstorage_getitem, "localStorage.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_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);
|
||||
addmethod(J, "localStorage.getItem", mjs_localstorage_getitem, 1);
|
||||
addmethod(J, "localStorage.removeItem", mjs_localstorage_removeitem, 1);
|
||||
addmethod(J, "localStorage.setItem", mjs_localstorage_setitem, 2);
|
||||
addmethod(J, "localStorage.toString", mjs_localstorage_toString, 0);
|
||||
}
|
||||
js_defglobal(J, "localStorage", JS_DONTENUM);
|
||||
|
||||
|
@ -145,8 +145,7 @@ mjs_navigator_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_navigator_toString, "navigator.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
addmethod(J, "navigator.toString", mjs_navigator_toString, 0);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appCodeName, "navigator.appCodeName", 0);
|
||||
js_pushnull(J);
|
||||
|
@ -149,8 +149,7 @@ mjs_screen_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_screen_toString, "screen.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
addmethod(J, "screen.toString", mjs_screen_toString, 0);
|
||||
|
||||
js_newcfunction(J, mjs_screen_get_property_availHeight, "screen.availHeight", 0);
|
||||
js_pushnull(J);
|
||||
|
@ -151,8 +151,7 @@ mjs_menubar_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_menubar_toString, "menubar.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
addmethod(J, "menubar.toString", mjs_menubar_toString, 0);
|
||||
|
||||
js_newcfunction(J, mjs_menubar_get_property_visible, "menubar.visible", 0);
|
||||
js_newcfunction(J, mjs_menubar_set_property_visible, "menubar.visible", 1);
|
||||
@ -166,8 +165,7 @@ mjs_statusbar_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_statusbar_toString, "statusbar.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
addmethod(J, "statusbar.toString", mjs_statusbar_toString, 0);
|
||||
|
||||
js_newcfunction(J, mjs_statusbar_get_property_visible, "statusbar.visible", 0);
|
||||
js_newcfunction(J, mjs_statusbar_set_property_visible, "statusbar.visible", 1);
|
||||
|
@ -460,11 +460,8 @@ mjs_window_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newcfunction(J, mjs_window_alert, "window.alert", 1);
|
||||
js_defproperty(J, -2, "alert", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_window_toString, "window.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
addmethod(J, "window.alert", mjs_window_alert, 1);
|
||||
addmethod(J, "window.toString", mjs_window_toString, 0);
|
||||
}
|
||||
js_defglobal(J, "window", JS_DONTENUM);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user