diff --git a/src/scripting/smjs/elinks_object.c b/src/scripting/smjs/elinks_object.c index f25b0a66..0018a100 100644 --- a/src/scripting/smjs/elinks_object.c +++ b/src/scripting/smjs/elinks_object.c @@ -20,6 +20,7 @@ #include "scripting/smjs/globhist.h" #include "scripting/smjs/keybinding.h" #include "scripting/smjs/load_uri.h" +#include "scripting/smjs/view_state_object.h" #include "session/location.h" #include "session/session.h" #include "session/task.h" @@ -155,6 +156,7 @@ smjs_init_elinks_object(void) smjs_init_globhist_interface(); smjs_init_keybinding_interface(); smjs_init_load_uri_interface(); + smjs_init_view_state_interface(); } /* If elinks. is defined, call it with the given arguments, diff --git a/src/scripting/smjs/view_state_object.c b/src/scripting/smjs/view_state_object.c index a40457e7..8ba0762a 100644 --- a/src/scripting/smjs/view_state_object.c +++ b/src/scripting/smjs/view_state_object.c @@ -10,8 +10,12 @@ #include "ecmascript/spidermonkey/util.h" #include "protocol/uri.h" +#include "scripting/smjs/elinks_object.h" #include "scripting/smjs/view_state_object.h" #include "scripting/smjs/core.h" +#include "session/history.h" +#include "session/location.h" +#include "session/session.h" #include "util/error.h" #include "util/memory.h" #include "viewer/text/vs.h" @@ -107,3 +111,35 @@ smjs_get_view_state_object(struct view_state *vs) return view_state_object; } + +static JSBool +smjs_elinks_get_view_state(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) +{ + JSObject *vs_obj; + struct view_state *vs; + + *vp = JSVAL_NULL; + + if (!smjs_ses) return JS_TRUE; + + vs = &cur_loc(smjs_ses)->vs; + if (!vs) return JS_TRUE; + + vs_obj = smjs_get_view_state_object(vs); + if (!vs_obj) return JS_TRUE; + + *vp = OBJECT_TO_JSVAL(vs_obj); + + return JS_TRUE; +} + +void +smjs_init_view_state_interface(void) +{ + if (!smjs_ctx || !smjs_elinks_object) + return; + + JS_DefineProperty(smjs_ctx, smjs_elinks_object, "vs", JSVAL_NULL, + smjs_elinks_get_view_state, JS_PropertyStub, + JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); +} diff --git a/src/scripting/smjs/view_state_object.h b/src/scripting/smjs/view_state_object.h index daf770eb..ccf8085f 100644 --- a/src/scripting/smjs/view_state_object.h +++ b/src/scripting/smjs/view_state_object.h @@ -5,5 +5,7 @@ struct view_state; JSObject *smjs_get_view_state_object(struct view_state *vs); +void smjs_init_view_state_interface(void); + #endif