1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-25 01:05:37 +00: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;
};
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 JSClassOps action_fn_ops = {
@ -39,25 +39,17 @@ static JSClassOps action_fn_ops = {
static const JSClass action_fn_class = {
"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_class.finalize */
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;
#if 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);
hop = JS::GetMaybePtrFromReservedSlot<struct smjs_action_fn_callback_hop>(obj, 0);
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));
if_assert_failed return false;
hop = (struct smjs_action_fn_callback_hop *)JS_GetInstancePrivate(ctx, fn_obj,
(JSClass *) &action_fn_class, NULL);
hop = JS::GetMaybePtrFromReservedSlot<struct smjs_action_fn_callback_hop>(fn_obj, 0);
if (!hop) {
args.rval().setBoolean(false);
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);
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;
}
@ -198,7 +189,6 @@ static JSClassOps action_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};

View File

@ -17,7 +17,7 @@
/*** 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 JSClassOps bookmark_ops = {
@ -32,7 +32,7 @@ static JSClassOps bookmark_ops = {
static const JSClass bookmark_class = {
"bookmark",
JSCLASS_HAS_PRIVATE, /* struct bookmark * */
JSCLASS_HAS_RESERVED_SLOTS(1), /* struct bookmark * */
&bookmark_ops
};
@ -45,14 +45,13 @@ static JSClassOps bookmark_folder_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass bookmark_folder_class = {
"bookmark_folder",
JSCLASS_HAS_PRIVATE, /* struct bookmark * */
JSCLASS_HAS_RESERVED_SLOTS(1), /* struct bookmark * */
&bookmark_folder_ops
};
@ -69,7 +68,7 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
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);
return jsobj;
@ -77,16 +76,11 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
/* @bookmark_class.finalize, @bookmark_folder_class.finalize */
static void
bookmark_finalize(JSFreeOp *op, JSObject *obj)
bookmark_finalize(JS::GCContext *op, JSObject *obj)
{
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);
}
@ -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))
return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &bookmark_class, NULL);
bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
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))
return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &bookmark_class, NULL);
bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
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))
return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &bookmark_class, NULL);
bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
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))
return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &bookmark_class, NULL);
bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
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))
return false;
bookmark = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &bookmark_class, NULL);
bookmark = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
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))
return false;
folder = (struct bookmark *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &bookmark_folder_class, NULL);
folder = JS::GetMaybePtrFromReservedSlot<struct bookmark>(hobj, 0);
hvp.setNull();

View File

@ -15,7 +15,7 @@
#include "util/error.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 = {
nullptr, // addProperty
@ -29,7 +29,7 @@ static JSClassOps cache_entry_ops = {
static const JSClass cache_entry_class = {
"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
};
@ -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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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,
* so cache_entry.jsobject won't be left dangling. */
static void
cache_entry_finalize(JSFreeOp *op, JSObject *obj)
cache_entry_finalize(JS::GCContext *op, JSObject *obj)
{
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 */
JS::SetPrivate(obj, NULL); /* perhaps not necessary */
JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
assert(cached->jsobject == obj);
if_assert_failed return;
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
* just forget the object and its finalizer won't attempt to
* 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;
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);
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject,
(JSClass *) &cache_entry_class, NULL)
== cached);
if_assert_failed {}
JS::SetPrivate(cached->jsobject, NULL);
JS::SetReservedSlot(cached->jsobject, 0, JS::UndefinedValue());
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
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))
return false;
cached = (struct cache_entry *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &cache_entry_class, NULL);
cached = JS::GetMaybePtrFromReservedSlot<struct cache_entry>(hobj, 0);
if (!cached) return false; /* already detached */
assert(cache_entry_is_valid(cached));

View File

@ -114,7 +114,6 @@ static const JSClassOps elinks_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
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_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 = {
nullptr, // addProperty
@ -26,28 +26,23 @@ static const JSClassOps smjs_globhist_item_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass smjs_globhist_item_class = {
"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_class.finalize */
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;
#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);
}
@ -80,7 +75,7 @@ smjs_get_globhist_item_object(struct global_history_item *history_item)
(JSPropertySpec *) smjs_globhist_item_props)) {
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);
return jsobj;
@ -130,7 +125,6 @@ static const JSClassOps smjs_globhist_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
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))
return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &smjs_globhist_item_class,
NULL);
history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
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))
return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &smjs_globhist_item_class,
NULL);
history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
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))
return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &smjs_globhist_item_class,
NULL);
history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
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))
return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &smjs_globhist_item_class,
NULL);
history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
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))
return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &smjs_globhist_item_class,
NULL);
history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
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))
return false;
history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &smjs_globhist_item_class,
NULL);
history_item = JS::GetMaybePtrFromReservedSlot<struct global_history_item>(hobj, 0);
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_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 = {
nullptr, // addProperty
@ -26,14 +26,13 @@ static const JSClassOps keymap_ops = {
nullptr, // mayResolve
keymap_finalize, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass keymap_class = {
"keymap",
JSCLASS_HAS_PRIVATE, /* int * */
JSCLASS_HAS_RESERVED_SLOTS(1), /* int * */
&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))
return false;
data = (int *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &keymap_class, NULL);
data = JS::GetMaybePtrFromReservedSlot<int>(hobj, 0);
if (!JS_IdToValue(ctx, id, &r_tmp))
goto ret_null;
@ -123,8 +119,7 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
return false;
}
data = (int *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &keymap_class, NULL);
data = JS::GetMaybePtrFromReservedSlot<int>(hobj, 0);
/* 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... */
@ -200,15 +195,11 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
/* @keymap_class.finalize */
static void
keymap_finalize(JSFreeOp *op, JSObject *obj)
keymap_finalize(JS::GCContext *op, JSObject *obj)
{
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);
}
@ -228,7 +219,7 @@ smjs_get_keymap_object(keymap_id_T keymap_id)
data = intdup(keymap_id);
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;
}
@ -240,7 +231,7 @@ static const JSClassOps keymap_hash_ops = {
static const JSClass keymaps_hash_class = {
"keymaps_hash",
JSCLASS_HAS_PRIVATE,
JSCLASS_HAS_RESERVED_SLOTS(1),
&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_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 const JSClassOps session_ops = {
@ -44,19 +44,18 @@ static const JSClassOps session_ops = {
nullptr, // mayResolve
session_finalize, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass session_class = {
"session",
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */
JSCLASS_HAS_RESERVED_SLOTS(1), /* struct session *; a weak reference */
&session_ops
};
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 = {
nullptr, // addProperty
@ -67,14 +66,13 @@ static const JSClassOps location_array_ops = {
nullptr, // mayResolve
smjs_location_array_finalize, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook{
};
static const JSClass location_array_class = {
"location_array",
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */
JSCLASS_HAS_RESERVED_SLOTS(1), /* struct session *; a weak reference */
&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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &location_array_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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
* session.history_jsobject won't be left dangling. */
static void
smjs_location_array_finalize(JSFreeOp *op, JSObject *obj)
smjs_location_array_finalize(JS::GCContext *op, JSObject *obj)
{
struct session *ses;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &location_array_class, NULL));
if_assert_failed return;
#endif
ses = (struct session *)JS::GetPrivate(obj);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(obj, 0);
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);
if_assert_failed return;
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
* just forget the object and its finalizer won't attempt to
* access @ses. */
JS::SetPrivate(obj, ses);
JS::SetReservedSlot(obj, 0, JS::PrivateValue(ses));
ses->history_jsobject = 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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(hobj, 0);
if (!ses) return false;
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
* won't be left dangling. */
static void
session_finalize(JSFreeOp *op, JSObject *obj)
session_finalize(JS::GCContext *op, JSObject *obj)
{
struct session *ses;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &session_class, NULL));
if_assert_failed return;
#endif
ses = (struct session *)JS::GetPrivate(obj);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(obj, 0);
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);
if_assert_failed return;
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
* just forget the object and its finalizer won't attempt to
* access @ses. */
JS::SetPrivate(obj, ses); /* to @session_class */
JS::SetReservedSlot(obj, 0, JS::PrivateValue(ses)); /* to @session_class */
ses->jsobject = obj;
return obj;
@ -1001,25 +963,13 @@ smjs_detach_session_object(struct session *ses)
if (ses->jsobject) {
JS::RootedObject r_jsobject(smjs_ctx, ses->jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject,
(JSClass *) &session_class, NULL)
== ses);
if_assert_failed {}
JS::SetPrivate(ses->jsobject, NULL);
JS::SetReservedSlot(ses->jsobject, 0, JS::UndefinedValue());
ses->jsobject = NULL;
}
if (ses->history_jsobject) {
JS::RootedObject r_history_jsobject(smjs_ctx, ses->history_jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_history_jsobject,
(JSClass *) &location_array_class,
NULL)
== ses);
if_assert_failed {}
JS::SetPrivate(ses->history_jsobject, NULL);
JS::SetReservedSlot(ses->history_jsobject, 0, JS::UndefinedValue());
ses->history_jsobject = NULL;
}
}
@ -1036,7 +986,7 @@ session_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
ELINKS_CAST_PROP_PARAMS
JSObject *tabobj;
struct terminal *term = (struct terminal *)JS::GetPrivate(obj);
struct terminal *term = JS::GetMaybePtrFromReservedSlot<struct terminal>(obj, 0);
int index;
struct window *tab;
@ -1072,14 +1022,13 @@ static const JSClassOps session_array_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass session_array_class = {
"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
};
@ -1094,7 +1043,7 @@ smjs_get_session_array_object(struct terminal *term)
obj = JS_NewObject(smjs_ctx, (JSClass *) &session_array_class);
if (!obj) return NULL;
JS::SetPrivate(obj, term);
JS::SetReservedSlot(obj, 0, JS::PrivateValue(term));
return obj;
}
@ -1113,12 +1062,7 @@ smjs_detach_session_array_object(struct terminal *term)
if (!term->session_array_jsobject) return;
JS::RootedObject r_term_session_array_jsobject(smjs_ctx, term->session_array_jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_term_session_array_jsobject,
(JSClass *) &session_array_class, NULL)
== term);
if_assert_failed {}
JS::SetPrivate(term->session_array_jsobject, NULL);
JS::SetReservedSlot(term->session_array_jsobject, 0, JS::UndefinedValue());
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))
return false;
ses = (struct session *)JS_GetInstancePrivate(ctx, this_o,
(JSClass *) &session_class, NULL);
ses = JS::GetMaybePtrFromReservedSlot<struct session>(this_o, 0);
if (!ses) return false; /* detached */
url = jsval_to_string(ctx, args[0]);

View File

@ -17,7 +17,7 @@
#include "util/memory.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 = {
nullptr, // addProperty
@ -28,14 +28,13 @@ static const JSClassOps terminal_ops = {
nullptr, // mayResolve
terminal_finalize, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass terminal_class = {
"terminal",
JSCLASS_HAS_PRIVATE, /* struct terminal *; a weak refernce */
JSCLASS_HAS_RESERVED_SLOTS(1), /* struct terminal *; a weak refernce */
&terminal_ops
};
@ -55,8 +54,7 @@ terminal_get_property_tab(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct terminal *term;
term = (struct terminal *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &terminal_class, NULL);
term = JS::GetMaybePtrFromReservedSlot<struct terminal>(hobj, 0);
if (!term) return false; /* already detached */
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
* won't be left dangling. */
static void
terminal_finalize(JSFreeOp *op, JSObject *obj)
terminal_finalize(JS::GCContext *op, JSObject *obj)
{
struct terminal *term;
#if 0
assert(JS_InstanceOf(ctx, obj, (JSClass *) &terminal_class, NULL));
if_assert_failed return;
#endif
term = (struct terminal *)JS::GetPrivate(obj);
term = JS::GetMaybePtrFromReservedSlot<struct terminal>(obj, 0);
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);
if_assert_failed return;
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
* just forget the object and its finalizer won't attempt to
* access @cached. */
JS::SetPrivate(obj, term); /* to @terminal_class */
JS::SetReservedSlot(obj, 0, JS::PrivateValue(term)); /* to @terminal_class */
term->jsobject = obj;
return obj;
@ -144,13 +138,7 @@ smjs_detach_terminal_object(struct terminal *term)
if (!term->jsobject) return;
JS::RootedObject r_jsobject(smjs_ctx, term->jsobject);
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject,
(JSClass *) &terminal_class, NULL)
== term);
if_assert_failed {}
JS::SetPrivate(term->jsobject, NULL);
JS::SetReservedSlot(term->jsobject, 0, JS::UndefinedValue());
term->jsobject = NULL;
}
@ -163,7 +151,6 @@ static const JSClassOps terminal_array_ops = {
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
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_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 = {
nullptr, // addProperty
@ -33,14 +33,13 @@ static const JSClassOps view_state_ops = {
nullptr, // mayResolve
view_state_finalize, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass view_state_class = {
"view_state",
JSCLASS_HAS_PRIVATE, /* struct view_state * */
JSCLASS_HAS_RESERVED_SLOTS(1), /* struct view_state * */
&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))
return false;
vs = (struct view_state *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &view_state_class, NULL);
vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(hobj, 0);
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))
return false;
vs = (struct view_state *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &view_state_class, NULL);
vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(hobj, 0);
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))
return false;
struct view_state *vs = (struct view_state *)JS_GetInstancePrivate(ctx, hobj,
(JSClass *) &view_state_class, NULL);
struct view_state *vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(hobj, 0);
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
* won't be left dangling. */
static void
view_state_finalize(JSFreeOp *op, JSObject *obj)
view_state_finalize(JS::GCContext *op, JSObject *obj)
{
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,
(JSClass *) &view_state_class, NULL);
#endif
vs = (struct view_state *)JS::GetPrivate(obj);
vs = JS::GetMaybePtrFromReservedSlot<struct view_state>(obj, 0);
if (!vs) return; /* already detached */
assert(vs->jsobject == obj);
if_assert_failed return;
JS::SetPrivate(obj, NULL); /* perhaps not necessary */
JS::SetReservedSlot(obj, 0, JS::UndefinedValue()); /* perhaps not necessary */
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
* 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;
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))
return;
assert(JS_GetInstancePrivate(smjs_ctx, robj,
(JSClass *) &view_state_class, NULL) == vs);
if_assert_failed return;
JS::SetPrivate(vs->jsobject, NULL);
JS::SetReservedSlot(vs->jsobject, 0, JS::UndefinedValue());
vs->jsobject = NULL;
}