1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[smjs] migrated to mozjs-102

This commit is contained in:
Witold Filipczyk 2022-10-01 21:08:03 +02:00
parent b0cc7b00d4
commit 8caddc754f
9 changed files with 115 additions and 268 deletions

View File

@ -23,7 +23,7 @@ struct smjs_action_fn_callback_hop {
action_id_T action_id; action_id_T action_id;
}; };
static void smjs_action_fn_finalize(JSFreeOp *op, JSObject *obj); static void smjs_action_fn_finalize(JS::GCContext *op, JSObject *obj);
static bool smjs_action_fn_callback(JSContext *ctx, unsigned int argc, JS::Value *rval); static bool smjs_action_fn_callback(JSContext *ctx, unsigned int argc, JS::Value *rval);
static JSClassOps action_fn_ops = { static JSClassOps action_fn_ops = {
@ -39,25 +39,17 @@ static JSClassOps action_fn_ops = {
static const JSClass action_fn_class = { static const JSClass action_fn_class = {
"action_fn", "action_fn",
JSCLASS_HAS_PRIVATE, /* struct smjs_action_fn_callback_hop * */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct smjs_action_fn_callback_hop * */
&action_fn_ops &action_fn_ops
}; };
/* @action_fn_class.finalize */ /* @action_fn_class.finalize */
static void static void
smjs_action_fn_finalize(JSFreeOp *op, JSObject *obj) smjs_action_fn_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct smjs_action_fn_callback_hop *hop; struct smjs_action_fn_callback_hop *hop;
#if 0 hop = JS::GetMaybePtrFromReservedSlot<struct smjs_action_fn_callback_hop>(obj, 0);
assert(JS_InstanceOf(ctx, obj, (JSClass *) &action_fn_class, NULL));
if_assert_failed return;
hop = JS_GetInstancePrivate(ctx, obj,
(JSClass *) &action_fn_class, NULL);
#endif
hop = (struct smjs_action_fn_callback_hop *)JS::GetPrivate(obj);
mem_free_if(hop); mem_free_if(hop);
} }
@ -83,8 +75,7 @@ smjs_action_fn_callback(JSContext *ctx, unsigned int argc, JS::Value *rval)
assert(JS_InstanceOf(ctx, fn_obj, (JSClass *) &action_fn_class, NULL)); assert(JS_InstanceOf(ctx, fn_obj, (JSClass *) &action_fn_class, NULL));
if_assert_failed return false; if_assert_failed return false;
hop = (struct smjs_action_fn_callback_hop *)JS_GetInstancePrivate(ctx, fn_obj, hop = JS::GetMaybePtrFromReservedSlot<struct smjs_action_fn_callback_hop>(fn_obj, 0);
(JSClass *) &action_fn_class, NULL);
if (!hop) { if (!hop) {
args.rval().setBoolean(false); args.rval().setBoolean(false);
return true; return true;
@ -153,7 +144,7 @@ smjs_get_action_fn_object(char *action_str)
hop->action_id = get_action_from_string(KEYMAP_MAIN, action_str); hop->action_id = get_action_from_string(KEYMAP_MAIN, action_str);
if (-1 != hop->action_id) { if (-1 != hop->action_id) {
JS::SetPrivate(obj, hop); /* to @action_fn_class */ JS::SetReservedSlot(obj, 0, JS::PrivateValue(hop)); /* to @action_fn_class */
return obj; return obj;
} }
@ -198,7 +189,6 @@ static JSClassOps action_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };

View File

@ -17,7 +17,7 @@
/*** common code ***/ /*** common code ***/
static void bookmark_finalize(JSFreeOp *op, JSObject *obj); static void bookmark_finalize(JS::GCContext *op, JSObject *obj);
static bool bookmark_folder_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool bookmark_folder_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSClassOps bookmark_ops = { static JSClassOps bookmark_ops = {
@ -32,7 +32,7 @@ static JSClassOps bookmark_ops = {
static const JSClass bookmark_class = { static const JSClass bookmark_class = {
"bookmark", "bookmark",
JSCLASS_HAS_PRIVATE, /* struct bookmark * */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct bookmark * */
&bookmark_ops &bookmark_ops
}; };
@ -45,14 +45,13 @@ static JSClassOps bookmark_folder_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass bookmark_folder_class = { static const JSClass bookmark_folder_class = {
"bookmark_folder", "bookmark_folder",
JSCLASS_HAS_PRIVATE, /* struct bookmark * */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct bookmark * */
&bookmark_folder_ops &bookmark_folder_ops
}; };
@ -69,7 +68,7 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
if (!bookmark) return jsobj; if (!bookmark) return jsobj;
JS::SetPrivate(jsobj, bookmark); /* to @bookmark_class or @bookmark_folder_class */ JS::SetReservedSlot(jsobj, 0, JS::PrivateValue(bookmark)); /* to @bookmark_class or @bookmark_folder_class */
object_lock(bookmark); object_lock(bookmark);
return jsobj; return jsobj;
@ -77,16 +76,11 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
/* @bookmark_class.finalize, @bookmark_folder_class.finalize */ /* @bookmark_class.finalize, @bookmark_folder_class.finalize */
static void static void
bookmark_finalize(JSFreeOp *op, JSObject *obj) bookmark_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct bookmark *bookmark; struct bookmark *bookmark;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL)
|| JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_folder_class, NULL));
if_assert_failed return;
#endif
bookmark = (struct bookmark *)JS::GetPrivate(obj); /* from @bookmark_class or @bookmark_folder_class */ bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(obj, 0); /* from @bookmark_class or @bookmark_folder_class */
if (bookmark) object_unlock(bookmark); if (bookmark) object_unlock(bookmark);
} }
@ -173,8 +167,7 @@ bookmark_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
return false; return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj, bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
(JSClass *) &bookmark_class, NULL);
if (!bookmark) return false; if (!bookmark) return false;
@ -204,8 +197,7 @@ bookmark_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
return false; return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj, bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
(JSClass *) &bookmark_class, NULL);
if (!bookmark) return false; if (!bookmark) return false;
@ -232,8 +224,7 @@ bookmark_get_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
return false; return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj, bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
(JSClass *) &bookmark_class, NULL);
if (!bookmark) return false; if (!bookmark) return false;
@ -263,8 +254,7 @@ bookmark_set_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
return false; return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj, bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
(JSClass *) &bookmark_class, NULL);
if (!bookmark) return false; if (!bookmark) return false;
@ -291,8 +281,7 @@ bookmark_get_property_children(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
return false; return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj, bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
(JSClass *) &bookmark_class, NULL);
if (!bookmark) return false; if (!bookmark) return false;
@ -340,8 +329,7 @@ bookmark_folder_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_folder_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_folder_class, NULL))
return false; return false;
folder = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj, folder = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
(JSClass *) &bookmark_folder_class, NULL);
hvp.setNull(); hvp.setNull();

View File

@ -15,7 +15,7 @@
#include "util/error.h" #include "util/error.h"
#include "util/memory.h" #include "util/memory.h"
static void cache_entry_finalize(JSFreeOp *op, JSObject *obj); static void cache_entry_finalize(JS::GCContext *op, JSObject *obj);
static JSClassOps cache_entry_ops = { static JSClassOps cache_entry_ops = {
nullptr, // addProperty nullptr, // addProperty
@ -29,7 +29,7 @@ static JSClassOps cache_entry_ops = {
static const JSClass cache_entry_class = { static const JSClass cache_entry_class = {
"cache_entry", "cache_entry",
JSCLASS_HAS_PRIVATE, /* struct cache_entry *; a weak reference */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct cache_entry *; a weak reference */
&cache_entry_ops &cache_entry_ops
}; };
@ -79,8 +79,7 @@ cache_entry_get_property_content(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -134,8 +133,7 @@ cache_entry_set_property_content(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -169,8 +167,7 @@ cache_entry_get_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -202,8 +199,7 @@ cache_entry_set_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -226,19 +222,15 @@ cache_entry_set_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
* automatically finalizes all objects before it frees the JSRuntime, * automatically finalizes all objects before it frees the JSRuntime,
* so cache_entry.jsobject won't be left dangling. */ * so cache_entry.jsobject won't be left dangling. */
static void static void
cache_entry_finalize(JSFreeOp *op, JSObject *obj) cache_entry_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct cache_entry *cached; struct cache_entry *cached;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL));
if_assert_failed return;
#endif
cached = (struct cache_entry *)JS::GetPrivate(obj); cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(obj, 0);
if (!cached) return; /* already detached */ if (!cached) return; /* already detached */
JS::SetPrivate(obj, NULL); /* perhaps not necessary */ JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
assert(cached->jsobject == obj); assert(cached->jsobject == obj);
if_assert_failed return; if_assert_failed return;
cached->jsobject = NULL; cached->jsobject = NULL;
@ -275,7 +267,7 @@ smjs_get_cache_entry_object(struct cache_entry *cached)
/* Do this last, so that if any previous step fails, we can /* Do this last, so that if any previous step fails, we can
* just forget the object and its finalizer won't attempt to * just forget the object and its finalizer won't attempt to
* access @cached. */ * access @cached. */
JS::SetPrivate(cache_entry_object, cached); /* to @cache_entry_class */ JS::SetReservedSlot(cache_entry_object, 0, JS::PrivateValue(cached)); /* to @cache_entry_class */
cached->jsobject = cache_entry_object; cached->jsobject = cache_entry_object;
return cache_entry_object; return cache_entry_object;
} }
@ -296,12 +288,7 @@ smjs_detach_cache_entry_object(struct cache_entry *cached)
JS::RootedObject r_jsobject(smjs_ctx, cached->jsobject); JS::RootedObject r_jsobject(smjs_ctx, cached->jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject, JS::SetReservedSlot(cached->jsobject, 0, JS::UndefinedValue());
(JSClass *) &cache_entry_class, NULL)
== cached);
if_assert_failed {}
JS::SetPrivate(cached->jsobject, NULL);
cached->jsobject = NULL; cached->jsobject = NULL;
} }
@ -319,8 +306,7 @@ cache_entry_get_property_length(JSContext *ctx, unsigned int argc, JS::Value *vp
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -351,8 +337,7 @@ cache_entry_get_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -384,8 +369,7 @@ cache_entry_set_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));
@ -419,8 +403,7 @@ cache_entry_get_property_uri(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
return false; return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj, cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
(JSClass *) &cache_entry_class, NULL);
if (!cached) return false; /* already detached */ if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached)); assert(cache_entry_is_valid(cached));

View File

@ -114,7 +114,6 @@ static const JSClassOps elinks_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };

View File

@ -15,7 +15,7 @@
static bool smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static void smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj); static void smjs_globhist_item_finalize(JS::GCContext *op, JSObject *obj);
static const JSClassOps smjs_globhist_item_ops = { static const JSClassOps smjs_globhist_item_ops = {
nullptr, // addProperty nullptr, // addProperty
@ -26,28 +26,23 @@ static const JSClassOps smjs_globhist_item_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass smjs_globhist_item_class = { static const JSClass smjs_globhist_item_class = {
"global_history_item", "global_history_item",
JSCLASS_HAS_PRIVATE, /* struct global_history_item * */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct global_history_item * */
&smjs_globhist_item_ops &smjs_globhist_item_ops
}; };
/* @smjs_globhist_item_class.finalize */ /* @smjs_globhist_item_class.finalize */
static void static void
smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj) smjs_globhist_item_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct global_history_item *history_item; struct global_history_item *history_item;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL));
if_assert_failed return;
#endif
history_item = (struct global_history_item *)JS::GetPrivate(obj); history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(obj, 0);
if (history_item) object_unlock(history_item); if (history_item) object_unlock(history_item);
} }
@ -80,7 +75,7 @@ smjs_get_globhist_item_object(struct global_history_item *history_item)
(JSPropertySpec *) smjs_globhist_item_props)) { (JSPropertySpec *) smjs_globhist_item_props)) {
return NULL; return NULL;
} }
JS::SetPrivate(jsobj, history_item); /* to @smjs_globhist_item_class */ JS::SetReservedSlot(jsobj, 0, JS::PrivateValue(history_item)); /* to @smjs_globhist_item_class */
object_lock(history_item); object_lock(history_item);
return jsobj; return jsobj;
@ -130,7 +125,6 @@ static const JSClassOps smjs_globhist_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
@ -184,9 +178,7 @@ smjs_globhist_item_get_property_title(JSContext *ctx, unsigned int argc, JS::Val
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
return false; return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
(JSClass *) &smjs_globhist_item_class,
NULL);
if (!history_item) return false; if (!history_item) return false;
@ -210,9 +202,7 @@ smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, JS::Val
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
return false; return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
(JSClass *) &smjs_globhist_item_class,
NULL);
if (!history_item) return false; if (!history_item) return false;
@ -236,9 +226,7 @@ smjs_globhist_item_get_property_url(JSContext *ctx, unsigned int argc, JS::Value
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
return false; return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
(JSClass *) &smjs_globhist_item_class,
NULL);
if (!history_item) return false; if (!history_item) return false;
@ -262,9 +250,7 @@ smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, JS::Value
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
return false; return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
(JSClass *) &smjs_globhist_item_class,
NULL);
if (!history_item) return false; if (!history_item) return false;
@ -288,9 +274,7 @@ smjs_globhist_item_get_property_last_visit(JSContext *ctx, unsigned int argc, JS
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
return false; return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
(JSClass *) &smjs_globhist_item_class,
NULL);
if (!history_item) return false; if (!history_item) return false;
@ -330,9 +314,7 @@ smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, JS
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
return false; return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
(JSClass *) &smjs_globhist_item_class,
NULL);
if (!history_item) return false; if (!history_item) return false;

View File

@ -15,7 +15,7 @@
static bool keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static void keymap_finalize(JSFreeOp *op, JSObject *obj); static void keymap_finalize(JS::GCContext *op, JSObject *obj);
static const JSClassOps keymap_ops = { static const JSClassOps keymap_ops = {
nullptr, // addProperty nullptr, // addProperty
@ -26,14 +26,13 @@ static const JSClassOps keymap_ops = {
nullptr, // mayResolve nullptr, // mayResolve
keymap_finalize, // finalize keymap_finalize, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass keymap_class = { static const JSClass keymap_class = {
"keymap", "keymap",
JSCLASS_HAS_PRIVATE, /* int * */ JSCLASS_HAS_RESERVED_SLOTS(1), /* int * */
&keymap_ops &keymap_ops
}; };
@ -55,10 +54,7 @@ keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &keymap_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &keymap_class, NULL))
return false; return false;
data = (int *)JS_GetInstancePrivate(ctx, hobj, data = JS::GetMaybePtrFromReservedSlot<int>(hobj, 0);
(JSClass *) &keymap_class, NULL);
if (!JS_IdToValue(ctx, id, &r_tmp)) if (!JS_IdToValue(ctx, id, &r_tmp))
goto ret_null; goto ret_null;
@ -123,8 +119,7 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
return false; return false;
} }
data = (int *)JS_GetInstancePrivate(ctx, hobj, data = JS::GetMaybePtrFromReservedSlot<int>(hobj, 0);
(JSClass *) &keymap_class, NULL);
/* Ugly fact: we need to get the string from the id to give to bind_do, /* Ugly fact: we need to get the string from the id to give to bind_do,
* which will of course then convert the string back to an id... */ * which will of course then convert the string back to an id... */
@ -200,15 +195,11 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
/* @keymap_class.finalize */ /* @keymap_class.finalize */
static void static void
keymap_finalize(JSFreeOp *op, JSObject *obj) keymap_finalize(JS::GCContext *op, JSObject *obj)
{ {
void *data; void *data;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &keymap_class, NULL));
if_assert_failed return;
#endif
data = JS::GetPrivate(obj); data = JS::GetMaybePtrFromReservedSlot<void>(obj, 0);
mem_free(data); mem_free(data);
} }
@ -228,7 +219,7 @@ smjs_get_keymap_object(keymap_id_T keymap_id)
data = intdup(keymap_id); data = intdup(keymap_id);
if (!data) return NULL; if (!data) return NULL;
JS::SetPrivate(keymap_object, data); /* to @keymap_class */ JS::SetReservedSlot(keymap_object, 0, JS::PrivateValue(data)); /* to @keymap_class */
return keymap_object; return keymap_object;
} }
@ -240,7 +231,7 @@ static const JSClassOps keymap_hash_ops = {
static const JSClass keymaps_hash_class = { static const JSClass keymaps_hash_class = {
"keymaps_hash", "keymaps_hash",
JSCLASS_HAS_PRIVATE, JSCLASS_HAS_RESERVED_SLOTS(1),
&keymap_hash_ops &keymap_hash_ops
}; };

View File

@ -32,7 +32,7 @@ static JSObject *smjs_session_object;
static bool session_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool session_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool session_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool session_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static void session_finalize(JSFreeOp *op, JSObject *obj); static void session_finalize(JS::GCContext *op, JSObject *obj);
static bool session_construct(JSContext *ctx, unsigned int argc, JS::Value *rval); static bool session_construct(JSContext *ctx, unsigned int argc, JS::Value *rval);
static const JSClassOps session_ops = { static const JSClassOps session_ops = {
@ -44,19 +44,18 @@ static const JSClassOps session_ops = {
nullptr, // mayResolve nullptr, // mayResolve
session_finalize, // finalize session_finalize, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass session_class = { static const JSClass session_class = {
"session", "session",
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct session *; a weak reference */
&session_ops &session_ops
}; };
static bool smjs_location_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool smjs_location_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static void smjs_location_array_finalize(JSFreeOp *op, JSObject *obj); static void smjs_location_array_finalize(JS::GCContext *op, JSObject *obj);
static const JSClassOps location_array_ops = { static const JSClassOps location_array_ops = {
nullptr, // addProperty nullptr, // addProperty
@ -67,14 +66,13 @@ static const JSClassOps location_array_ops = {
nullptr, // mayResolve nullptr, // mayResolve
smjs_location_array_finalize, // finalize smjs_location_array_finalize, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook{ nullptr // trace JS_GlobalObjectTraceHook{
}; };
static const JSClass location_array_class = { static const JSClass location_array_class = {
"location_array", "location_array",
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct session *; a weak reference */
&location_array_ops &location_array_ops
}; };
@ -100,8 +98,7 @@ smjs_location_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Hand
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &location_array_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &location_array_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &location_array_class, NULL);
if (!ses) return false; if (!ses) return false;
hvp.setUndefined(); hvp.setUndefined();
@ -138,20 +135,15 @@ smjs_location_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Hand
* finalizes all objects before it frees the JSRuntime, so * finalizes all objects before it frees the JSRuntime, so
* session.history_jsobject won't be left dangling. */ * session.history_jsobject won't be left dangling. */
static void static void
smjs_location_array_finalize(JSFreeOp *op, JSObject *obj) smjs_location_array_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct session *ses; struct session *ses;
#if 0 ses = JS::GetMaybePtrFromReservedSlot<struct session>(obj, 0);
assert(JS_InstanceOf(ctx, obj, (JSClass *) &location_array_class, NULL));
if_assert_failed return;
#endif
ses = (struct session *)JS::GetPrivate(obj);
if (!ses) return; /* already detached */ if (!ses) return; /* already detached */
JS::SetPrivate(obj, NULL); /* perhaps not necessary */ JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
assert(ses->history_jsobject == obj); assert(ses->history_jsobject == obj);
if_assert_failed return; if_assert_failed return;
ses->history_jsobject = NULL; ses->history_jsobject = NULL;
@ -177,7 +169,7 @@ smjs_get_session_location_array_object(struct session *ses)
/* Do this last, so that if any previous step fails, we can /* Do this last, so that if any previous step fails, we can
* just forget the object and its finalizer won't attempt to * just forget the object and its finalizer won't attempt to
* access @ses. */ * access @ses. */
JS::SetPrivate(obj, ses); JS::SetReservedSlot(obj, 0, JS::PrivateValue(ses));
ses->history_jsobject = obj; ses->history_jsobject = obj;
return obj; return obj;
@ -265,8 +257,7 @@ session_get_property_visited(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setInt32(ses->status.visited); args.rval().setInt32(ses->status.visited);
@ -288,8 +279,7 @@ session_get_property_history(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
JSObject *obj = smjs_get_session_location_array_object(ses); JSObject *obj = smjs_get_session_location_array_object(ses);
@ -317,8 +307,7 @@ session_get_property_loading_uri(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
struct uri *uri = have_location(ses) ? cur_loc(ses)->vs.uri struct uri *uri = have_location(ses) ? cur_loc(ses)->vs.uri
@ -347,8 +336,7 @@ session_get_property_reloadlevel(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setInt32(ses->reloadlevel); args.rval().setInt32(ses->reloadlevel);
@ -370,8 +358,7 @@ session_get_property_redirect_cnt(JSContext *ctx, unsigned int argc, JS::Value *
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setInt32(ses->redirect_cnt); args.rval().setInt32(ses->redirect_cnt);
@ -393,8 +380,7 @@ session_get_property_search_direction(JSContext *ctx, unsigned int argc, JS::Val
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setString(JS_NewStringCopyZ(ctx, ses->search_direction == 1 ? "down" : "up")); args.rval().setString(JS_NewStringCopyZ(ctx, ses->search_direction == 1 ? "down" : "up"));
@ -416,8 +402,7 @@ session_get_property_kbdprefix(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setInt32(ses->kbdprefix.repeat_count); args.rval().setInt32(ses->kbdprefix.repeat_count);
@ -439,8 +424,7 @@ session_get_property_mark(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setString(JS_NewStringCopyZ(ctx, ses->kbdprefix.mark == KP_MARK_NOTHING args.rval().setString(JS_NewStringCopyZ(ctx, ses->kbdprefix.mark == KP_MARK_NOTHING
@ -466,8 +450,7 @@ session_get_property_exit_query(JSContext *ctx, unsigned int argc, JS::Value *vp
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setInt32(ses->exit_query); args.rval().setInt32(ses->exit_query);
@ -489,8 +472,7 @@ session_get_property_insert_mode(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setString(JS_NewStringCopyZ(ctx, args.rval().setString(JS_NewStringCopyZ(ctx,
@ -517,8 +499,7 @@ session_get_property_navigate_mode(JSContext *ctx, unsigned int argc, JS::Value
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setString(JS_NewStringCopyZ(ctx, args.rval().setString(JS_NewStringCopyZ(ctx,
@ -543,8 +524,7 @@ session_get_property_search_word(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setString(JS_NewStringCopyZ(ctx, ses->search_word)); args.rval().setString(JS_NewStringCopyZ(ctx, ses->search_word));
@ -566,8 +546,7 @@ session_get_property_last_search_word(JSContext *ctx, unsigned int argc, JS::Val
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
args.rval().setString(JS_NewStringCopyZ(ctx, ses->last_search_word)); args.rval().setString(JS_NewStringCopyZ(ctx, ses->last_search_word));
@ -589,8 +568,7 @@ session_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
if (!id.isInt()) { if (!id.isInt()) {
@ -616,8 +594,7 @@ session_set_property_visited(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
int v = args[0].toInt32(); int v = args[0].toInt32();
@ -640,8 +617,7 @@ session_set_property_reloadlevel(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
ses->reloadlevel = args[0].toInt32(); ses->reloadlevel = args[0].toInt32();
@ -663,8 +639,7 @@ session_set_property_redirect_cnt(JSContext *ctx, unsigned int argc, JS::Value *
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
ses->redirect_cnt = args[0].toInt32(); ses->redirect_cnt = args[0].toInt32();
@ -686,8 +661,7 @@ session_set_property_search_direction(JSContext *ctx, unsigned int argc, JS::Val
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
char *str = jsval_to_string(ctx, args[0]); char *str = jsval_to_string(ctx, args[0]);
@ -717,8 +691,7 @@ session_set_property_kbdprefix(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
ses->kbdprefix.repeat_count = args[0].toInt32(); ses->kbdprefix.repeat_count = args[0].toInt32();
@ -740,8 +713,7 @@ session_set_property_mark(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
char *str = jsval_to_string(ctx, args[0]); char *str = jsval_to_string(ctx, args[0]);
@ -773,8 +745,7 @@ session_set_property_insert_mode(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
char *str = jsval_to_string(ctx, args[0]); char *str = jsval_to_string(ctx, args[0]);
@ -806,8 +777,7 @@ session_set_property_navigate_mode(JSContext *ctx, unsigned int argc, JS::Value
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
char *str = jsval_to_string(ctx, args[0]); char *str = jsval_to_string(ctx, args[0]);
@ -837,8 +807,7 @@ session_set_property_search_word(JSContext *ctx, unsigned int argc, JS::Value *v
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
char *str = jsval_to_string(ctx, args[0]); char *str = jsval_to_string(ctx, args[0]);
@ -863,8 +832,7 @@ session_set_property_last_search_word(JSContext *ctx, unsigned int argc, JS::Val
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
char *str = jsval_to_string(ctx, args[0]); char *str = jsval_to_string(ctx, args[0]);
@ -890,8 +858,7 @@ session_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj, ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; if (!ses) return false;
if (!id.isInt()) if (!id.isInt())
@ -937,20 +904,15 @@ session_construct(JSContext *ctx, unsigned int argc, JS::Value *rval)
* finalizes all objects before it frees the JSRuntime, so session.jsobject * finalizes all objects before it frees the JSRuntime, so session.jsobject
* won't be left dangling. */ * won't be left dangling. */
static void static void
session_finalize(JSFreeOp *op, JSObject *obj) session_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct session *ses; struct session *ses;
#if 0 ses = JS::GetMaybePtrFromReservedSlot<struct session>(obj, 0);
assert(JS_InstanceOf(ctx, obj, (JSClass *) &session_class, NULL));
if_assert_failed return;
#endif
ses = (struct session *)JS::GetPrivate(obj);
if (!ses) return; /* already detached */ if (!ses) return; /* already detached */
JS::SetPrivate(obj, NULL); /* perhaps not necessary */ JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
assert(ses->jsobject == obj); assert(ses->jsobject == obj);
if_assert_failed return; if_assert_failed return;
ses->jsobject = NULL; ses->jsobject = NULL;
@ -982,7 +944,7 @@ smjs_get_session_object(struct session *ses)
/* Do this last, so that if any previous step fails, we can /* Do this last, so that if any previous step fails, we can
* just forget the object and its finalizer won't attempt to * just forget the object and its finalizer won't attempt to
* access @ses. */ * access @ses. */
JS::SetPrivate(obj, ses); /* to @session_class */ JS::SetReservedSlot(obj, 0, JS::PrivateValue(ses)); /* to @session_class */
ses->jsobject = obj; ses->jsobject = obj;
return obj; return obj;
@ -1001,25 +963,13 @@ smjs_detach_session_object(struct session *ses)
if (ses->jsobject) { if (ses->jsobject) {
JS::RootedObject r_jsobject(smjs_ctx, ses->jsobject); JS::RootedObject r_jsobject(smjs_ctx, ses->jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject, JS::SetReservedSlot(ses->jsobject, 0, JS::UndefinedValue());
(JSClass *) &session_class, NULL)
== ses);
if_assert_failed {}
JS::SetPrivate(ses->jsobject, NULL);
ses->jsobject = NULL; ses->jsobject = NULL;
} }
if (ses->history_jsobject) { if (ses->history_jsobject) {
JS::RootedObject r_history_jsobject(smjs_ctx, ses->history_jsobject); JS::RootedObject r_history_jsobject(smjs_ctx, ses->history_jsobject);
JS::SetReservedSlot(ses->history_jsobject, 0, JS::UndefinedValue());
assert(JS_GetInstancePrivate(smjs_ctx, r_history_jsobject,
(JSClass *) &location_array_class,
NULL)
== ses);
if_assert_failed {}
JS::SetPrivate(ses->history_jsobject, NULL);
ses->history_jsobject = NULL; ses->history_jsobject = NULL;
} }
} }
@ -1036,7 +986,7 @@ session_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
ELINKS_CAST_PROP_PARAMS ELINKS_CAST_PROP_PARAMS
JSObject *tabobj; JSObject *tabobj;
struct terminal *term = (struct terminal *)JS::GetPrivate(obj); struct terminal *term = JS::GetMaybePtrFromReservedSlot<struct terminal>(obj, 0);
int index; int index;
struct window *tab; struct window *tab;
@ -1072,14 +1022,13 @@ static const JSClassOps session_array_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass session_array_class = { static const JSClass session_array_class = {
"session_array", "session_array",
JSCLASS_HAS_PRIVATE, /* struct terminal *term; a weak reference */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct terminal *term; a weak reference */
&session_array_ops &session_array_ops
}; };
@ -1094,7 +1043,7 @@ smjs_get_session_array_object(struct terminal *term)
obj = JS_NewObject(smjs_ctx, (JSClass *) &session_array_class); obj = JS_NewObject(smjs_ctx, (JSClass *) &session_array_class);
if (!obj) return NULL; if (!obj) return NULL;
JS::SetPrivate(obj, term); JS::SetReservedSlot(obj, 0, JS::PrivateValue(term));
return obj; return obj;
} }
@ -1113,12 +1062,7 @@ smjs_detach_session_array_object(struct terminal *term)
if (!term->session_array_jsobject) return; if (!term->session_array_jsobject) return;
JS::RootedObject r_term_session_array_jsobject(smjs_ctx, term->session_array_jsobject); JS::RootedObject r_term_session_array_jsobject(smjs_ctx, term->session_array_jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_term_session_array_jsobject, JS::SetReservedSlot(term->session_array_jsobject, 0, JS::UndefinedValue());
(JSClass *) &session_array_class, NULL)
== term);
if_assert_failed {}
JS::SetPrivate(term->session_array_jsobject, NULL);
term->session_array_jsobject = NULL; term->session_array_jsobject = NULL;
} }
@ -1139,8 +1083,7 @@ smjs_session_goto_url(JSContext *ctx, unsigned int argc, JS::Value *rval)
if (!JS_InstanceOf(ctx, this_o, (JSClass *) &session_class, NULL)) if (!JS_InstanceOf(ctx, this_o, (JSClass *) &session_class, NULL))
return false; return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, this_o, ses = JS::GetMaybePtrFromReservedSlot<struct session>(this_o, 0);
(JSClass *) &session_class, NULL);
if (!ses) return false; /* detached */ if (!ses) return false; /* detached */
url = jsval_to_string(ctx, args[0]); url = jsval_to_string(ctx, args[0]);

View File

@ -17,7 +17,7 @@
#include "util/memory.h" #include "util/memory.h"
#include "viewer/text/vs.h" #include "viewer/text/vs.h"
static void terminal_finalize(JSFreeOp *op, JSObject *obj); static void terminal_finalize(JS::GCContext *op, JSObject *obj);
static const JSClassOps terminal_ops = { static const JSClassOps terminal_ops = {
nullptr, // addProperty nullptr, // addProperty
@ -28,14 +28,13 @@ static const JSClassOps terminal_ops = {
nullptr, // mayResolve nullptr, // mayResolve
terminal_finalize, // finalize terminal_finalize, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass terminal_class = { static const JSClass terminal_class = {
"terminal", "terminal",
JSCLASS_HAS_PRIVATE, /* struct terminal *; a weak refernce */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct terminal *; a weak refernce */
&terminal_ops &terminal_ops
}; };
@ -55,8 +54,7 @@ terminal_get_property_tab(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct terminal *term; struct terminal *term;
term = (struct terminal *)JS_GetInstancePrivate(ctx, hobj, term = JS::GetMaybePtrFromReservedSlot<struct terminal>(hobj, 0);
(JSClass *) &terminal_class, NULL);
if (!term) return false; /* already detached */ if (!term) return false; /* already detached */
JSObject *obj = smjs_get_session_array_object(term); JSObject *obj = smjs_get_session_array_object(term);
@ -79,18 +77,14 @@ static const JSPropertySpec terminal_props[] = {
* finalizes all objects before it frees the JSRuntime, so terminal.jsobject * finalizes all objects before it frees the JSRuntime, so terminal.jsobject
* won't be left dangling. */ * won't be left dangling. */
static void static void
terminal_finalize(JSFreeOp *op, JSObject *obj) terminal_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct terminal *term; struct terminal *term;
#if 0 term = JS::GetMaybePtrFromReservedSlot<struct terminal>(obj, 0);
assert(JS_InstanceOf(ctx, obj, (JSClass *) &terminal_class, NULL));
if_assert_failed return;
#endif
term = (struct terminal *)JS::GetPrivate(obj);
if (!term) return; /* already detached */ if (!term) return; /* already detached */
JS::SetPrivate(obj, NULL); /* perhaps not necessary */ JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
assert(term->jsobject == obj); assert(term->jsobject == obj);
if_assert_failed return; if_assert_failed return;
term->jsobject = NULL; term->jsobject = NULL;
@ -122,7 +116,7 @@ smjs_get_terminal_object(struct terminal *term)
/* Do this last, so that if any previous step fails, we can /* Do this last, so that if any previous step fails, we can
* just forget the object and its finalizer won't attempt to * just forget the object and its finalizer won't attempt to
* access @cached. */ * access @cached. */
JS::SetPrivate(obj, term); /* to @terminal_class */ JS::SetReservedSlot(obj, 0, JS::PrivateValue(term)); /* to @terminal_class */
term->jsobject = obj; term->jsobject = obj;
return obj; return obj;
@ -144,13 +138,7 @@ smjs_detach_terminal_object(struct terminal *term)
if (!term->jsobject) return; if (!term->jsobject) return;
JS::RootedObject r_jsobject(smjs_ctx, term->jsobject); JS::RootedObject r_jsobject(smjs_ctx, term->jsobject);
JS::SetReservedSlot(term->jsobject, 0, JS::UndefinedValue());
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject,
(JSClass *) &terminal_class, NULL)
== term);
if_assert_failed {}
JS::SetPrivate(term->jsobject, NULL);
term->jsobject = NULL; term->jsobject = NULL;
} }
@ -163,7 +151,6 @@ static const JSClassOps terminal_array_ops = {
nullptr, // mayResolve nullptr, // mayResolve
nullptr, // finalize nullptr, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
JS_GlobalObjectTraceHook JS_GlobalObjectTraceHook
}; };

View File

@ -22,7 +22,7 @@
static bool view_state_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool view_state_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); static bool view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static void view_state_finalize(JSFreeOp *op, JSObject *obj); static void view_state_finalize(JS::GCContext *op, JSObject *obj);
static const JSClassOps view_state_ops = { static const JSClassOps view_state_ops = {
nullptr, // addProperty nullptr, // addProperty
@ -33,14 +33,13 @@ static const JSClassOps view_state_ops = {
nullptr, // mayResolve nullptr, // mayResolve
view_state_finalize, // finalize view_state_finalize, // finalize
nullptr, // call nullptr, // call
nullptr, // hasInstance
nullptr, // construct nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook nullptr // trace JS_GlobalObjectTraceHook
}; };
static const JSClass view_state_class = { static const JSClass view_state_class = {
"view_state", "view_state",
JSCLASS_HAS_PRIVATE, /* struct view_state * */ JSCLASS_HAS_RESERVED_SLOTS(1), /* struct view_state * */
&view_state_ops &view_state_ops
}; };
@ -67,8 +66,7 @@ view_state_get_property_plain(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
return false; return false;
vs = (struct view_state *)JS_GetInstancePrivate(ctx, hobj, vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(hobj, 0);
(JSClass *) &view_state_class, NULL);
if (!vs) return false; if (!vs) return false;
@ -94,8 +92,7 @@ view_state_set_property_plain(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
return false; return false;
vs = (struct view_state *)JS_GetInstancePrivate(ctx, hobj, vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(hobj, 0);
(JSClass *) &view_state_class, NULL);
if (!vs) return false; if (!vs) return false;
@ -116,8 +113,7 @@ view_state_get_property_uri(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL)) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
return false; return false;
struct view_state *vs = (struct view_state *)JS_GetInstancePrivate(ctx, hobj, struct view_state *vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(hobj, 0);
(JSClass *) &view_state_class, NULL);
if (!vs) return false; if (!vs) return false;
@ -136,24 +132,17 @@ static const JSPropertySpec view_state_props[] = {
* finalizes all objects before it frees the JSRuntime, so view_state.jsobject * finalizes all objects before it frees the JSRuntime, so view_state.jsobject
* won't be left dangling. */ * won't be left dangling. */
static void static void
view_state_finalize(JSFreeOp *op, JSObject *obj) view_state_finalize(JS::GCContext *op, JSObject *obj)
{ {
struct view_state *vs; struct view_state *vs;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &view_state_class, NULL));
if_assert_failed return;
vs = JS_GetInstancePrivate(ctx, obj, vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(obj, 0);
(JSClass *) &view_state_class, NULL);
#endif
vs = (struct view_state *)JS::GetPrivate(obj);
if (!vs) return; /* already detached */ if (!vs) return; /* already detached */
assert(vs->jsobject == obj); assert(vs->jsobject == obj);
if_assert_failed return; if_assert_failed return;
JS::SetPrivate(obj, NULL); /* perhaps not necessary */ JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
vs->jsobject = NULL; vs->jsobject = NULL;
} }
@ -185,7 +174,7 @@ smjs_get_view_state_object(struct view_state *vs)
* just forget the object and its finalizer won't attempt to * just forget the object and its finalizer won't attempt to
* access @vs. */ * access @vs. */
JS::SetPrivate(view_state_object, vs); /* to @view_state_class */ JS::SetReservedSlot(view_state_object, 0, JS::PrivateValue(vs)); /* to @view_state_class */
vs->jsobject = view_state_object; vs->jsobject = view_state_object;
return view_state_object; return view_state_object;
@ -230,12 +219,7 @@ smjs_detach_view_state_object(struct view_state *vs)
if (!JS_InstanceOf(smjs_ctx, robj, (JSClass *) &view_state_class, NULL)) if (!JS_InstanceOf(smjs_ctx, robj, (JSClass *) &view_state_class, NULL))
return; return;
assert(JS_GetInstancePrivate(smjs_ctx, robj, JS::SetReservedSlot(vs->jsobject, 0, JS::UndefinedValue());
(JSClass *) &view_state_class, NULL) == vs);
if_assert_failed return;
JS::SetPrivate(vs->jsobject, NULL);
vs->jsobject = NULL; vs->jsobject = NULL;
} }