1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-15 14:54:40 -04:00

Bug 846: Add plenty of JS_InstanceOf assertions and checks.

(Adapted from 47dce0922b in ELinks 0.12.GIT.)
This commit is contained in:
Kalle Olavi Niemitalo 2006-11-25 21:24:25 +02:00 committed by Kalle Olavi Niemitalo
parent 9a829b3277
commit 0744d96213
9 changed files with 204 additions and 3 deletions

View File

@ -25,6 +25,7 @@
#include "ecmascript/spidermonkey/form.h"
#include "ecmascript/spidermonkey/location.h"
#include "ecmascript/spidermonkey/document.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
@ -79,7 +80,12 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct document *document;
struct session *ses;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -168,7 +174,12 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct document_view *doc_view;
struct document *document;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;

View File

@ -22,7 +22,9 @@
#include "document/forms.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/document.h"
#include "ecmascript/spidermonkey/form.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
@ -44,6 +46,9 @@
#include "viewer/text/vs.h"
static const JSClass form_class; /* defined below */
/* Accordingly to the JS specs, each input type should own object. That'd be a
* huge PITA though, however DOM comes to the rescue and defines just a single
* HTMLInputElement. The difference could be spotted only by some clever tricky
@ -131,9 +136,18 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
int linknum;
struct link *link = NULL;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &input_class, NULL));
if_assert_failed return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -253,9 +267,18 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
int linknum;
struct link *link = NULL;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &input_class, NULL));
if_assert_failed return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -348,9 +371,17 @@ input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
struct form_control *fc;
int linknum;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &input_class, argv)) return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -392,9 +423,17 @@ input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
struct form_control *fc;
int linknum;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &input_class, argv)) return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -512,9 +551,18 @@ form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct form_view *form_view;
struct form *form;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &form_elements_class, NULL));
if_assert_failed return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -560,9 +608,17 @@ form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval
int counter = -1;
int index;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &form_elements_class, argv)) return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -606,9 +662,17 @@ form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
struct form_control *fc;
unsigned char *string;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &form_elements_class, argv)) return JS_FALSE;
parent_form = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_form, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, parent_form);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -694,8 +758,15 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct form_view *fv;
struct form *form;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
fv = JS_GetPrivate(ctx, obj); /* from @form_class */
@ -809,8 +880,15 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct form *form;
unsigned char *string;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &form_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
fv = JS_GetPrivate(ctx, obj); /* from @form_class */
@ -874,8 +952,14 @@ form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
struct form_view *fv;
struct form *form;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &form_class, argv)) return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
fv = JS_GetPrivate(ctx, obj); /* from @form_class */
@ -903,8 +987,14 @@ form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
struct form_view *fv;
struct form *form;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &form_class, argv)) return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
ses = doc_view->session;
@ -935,8 +1025,6 @@ get_form_object(JSContext *ctx, JSObject *jsdoc, struct form_view *fv)
}
return fv->ecmascript_obj;
}
static JSBool forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
/* Each @forms_class object must have a @document_class parent. */
@ -975,8 +1063,15 @@ forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct document_view *doc_view;
struct document *document;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &forms_class, NULL));
if_assert_failed return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;
@ -1013,8 +1108,14 @@ forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
int counter = -1;
int index;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &forms_class, argv)) return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
if (argc != 1)
@ -1047,8 +1148,14 @@ forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
struct form *form;
unsigned char *string;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &forms_class, argv)) return JS_FALSE;
parent_doc = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_doc, (JSClass *) &document_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, parent_doc);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
document = doc_view->document;

View File

@ -23,6 +23,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/location.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
@ -148,7 +149,12 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &location_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
if (!JSVAL_IS_INT(id))
@ -176,7 +182,12 @@ location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct view_state *vs;
struct document_view *doc_view;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &location_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;

View File

@ -23,6 +23,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/unibar.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
@ -81,7 +82,13 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct session_status *status;
unsigned char *bar;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
|| JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
status = &doc_view->session->status;
@ -127,7 +134,13 @@ unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct session_status *status;
unsigned char *bar;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
|| JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL));
if_assert_failed return JS_FALSE;
parent_win = JS_GetParent(ctx, obj);
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view;
status = &doc_view->session->status;

View File

@ -120,6 +120,9 @@ window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct view_state *vs;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, obj); /* from @window_class */
/* No need for special window.location measurements - when
@ -239,6 +242,9 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct view_state *vs;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, obj); /* from @window_class */
if (JSVAL_IS_STRING(id)) {
@ -282,6 +288,8 @@ window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
struct view_state *vs;
unsigned char *string;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &window_class, argv)) return JS_FALSE;
vs = JS_GetPrivate(ctx, obj); /* from @window_class */
if (argc != 1)
@ -339,6 +347,8 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static time_t ratelimit_start;
static int ratelimit_count;
if (!JS_InstanceOf(ctx, obj, (JSClass *) &window_class, argv)) return JS_FALSE;
vs = JS_GetPrivate(ctx, obj); /* from @window_class */
doc_view = vs->doc_view;
ses = doc_view->session;

View File

@ -14,13 +14,19 @@
#include "util/memory.h"
static const JSClass bookmark_class, bookmark_folder_class; /* defined below */
/*** common code ***/
static JSObject *
smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
{
JSObject *jsobj;
assert(clasp == &bookmark_class || clasp == &bookmark_folder_class);
if_assert_failed return NULL;
jsobj = JS_NewObject(smjs_ctx, clasp, NULL, NULL);
if (!jsobj) return NULL;
@ -41,6 +47,10 @@ bookmark_finalize(JSContext *ctx, JSObject *obj)
{
struct bookmark *bookmark;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL)
|| JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_folder_class, NULL));
if_assert_failed return;
bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class or @bookmark_folder_class */
if (bookmark) object_unlock(bookmark);
@ -70,6 +80,9 @@ bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct bookmark *bookmark;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL));
if_assert_failed return JS_FALSE;
bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class */
if (!bookmark) return JS_FALSE;
@ -108,6 +121,9 @@ bookmark_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct bookmark *bookmark;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL));
if_assert_failed return JS_FALSE;
bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class */
if (!bookmark) return JS_FALSE;
@ -175,6 +191,9 @@ bookmark_folder_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
struct bookmark *folder;
unsigned char *title;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_folder_class, NULL));
if_assert_failed return JS_FALSE;
folder = JS_GetPrivate(ctx, obj); /* from @bookmark_folder_class */
title = JS_GetStringBytes(JS_ValueToString(ctx, id));

View File

@ -14,6 +14,8 @@
#include "util/error.h"
#include "util/memory.h"
static const JSClass cache_entry_class; /* defined below */
enum cache_entry_prop {
CACHE_ENTRY_CONTENT,
CACHE_ENTRY_TYPE,
@ -37,6 +39,9 @@ cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct cache_entry *cached;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL));
if_assert_failed return JS_FALSE;
cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */
if (!cache_entry_is_valid(cached)) return JS_FALSE;
@ -91,6 +96,9 @@ cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct cache_entry *cached;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL));
if_assert_failed return JS_FALSE;
cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */
if (!cache_entry_is_valid(cached)) return JS_FALSE;
@ -141,6 +149,9 @@ cache_entry_finalize(JSContext *ctx, JSObject *obj)
{
struct cache_entry *cached;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL));
if_assert_failed return;
cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */
if (!cached) return;

View File

@ -13,6 +13,8 @@
#include "scripting/smjs/elinks_object.h"
#include "util/memory.h"
static const JSClass keymap_class; /* defined below */
/* @keymap_class.getProperty */
static JSBool
keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
@ -22,6 +24,9 @@ keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
int *data;
enum keymap_id keymap_id = *data;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &keymap_class, NULL));
if_assert_failed return JS_FALSE;
data = JS_GetPrivate(ctx, obj); /* from @keymap_class */
keystroke_str = JS_GetStringBytes(JS_ValueToString(ctx, id));
@ -70,6 +75,9 @@ keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
unsigned char *keymap_str;
unsigned char *keystroke_str;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &keymap_class, NULL));
if_assert_failed return JS_FALSE;
data = JS_GetPrivate(ctx, obj); /* from @keymap_class */
/* Ugly fact: we need to get the string from the id to give to bind_do,
@ -139,6 +147,9 @@ keymap_finalize(JSContext *ctx, JSObject *obj)
{
void *data;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &keymap_class, NULL));
if_assert_failed return;
data = JS_GetPrivate(ctx, obj); /* from @keymap_class */
mem_free(data);

View File

@ -16,6 +16,8 @@
#include "util/memory.h"
#include "viewer/text/vs.h"
static const JSClass view_state_class; /* defined below */
enum view_state_prop {
VIEW_STATE_PLAIN,
VIEW_STATE_URI,
@ -33,6 +35,9 @@ view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct view_state *vs;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &view_state_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, obj); /* from @view_state_class */
undef_to_jsval(ctx, vp);
@ -64,6 +69,9 @@ view_state_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{
struct view_state *vs;
assert(JS_InstanceOf(ctx, obj, (JSClass *) &view_state_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetPrivate(ctx, obj); /* from @view_state_class */
if (!JSVAL_IS_INT(id))