mirror of
https://github.com/rkd77/elinks.git
synced 2024-10-01 03:36:26 -04:00
[mozjs31] scripting smjs
It was not heavily tested.
This commit is contained in:
parent
dd704b900a
commit
ca24054cc6
@ -24,7 +24,7 @@ struct smjs_action_fn_callback_hop {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void smjs_action_fn_finalize(JSFreeOp *op, JSObject *obj);
|
static void smjs_action_fn_finalize(JSFreeOp *op, JSObject *obj);
|
||||||
static JSBool smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rval);
|
static bool smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rval);
|
||||||
|
|
||||||
static const JSClass action_fn_class = {
|
static const JSClass action_fn_class = {
|
||||||
"action_fn",
|
"action_fn",
|
||||||
@ -57,31 +57,31 @@ smjs_action_fn_finalize(JSFreeOp *op, JSObject *obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* @action_fn_class.call */
|
/* @action_fn_class.call */
|
||||||
static JSBool
|
static bool
|
||||||
smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rval)
|
smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rval)
|
||||||
{
|
{
|
||||||
jsval value;
|
jsval value;
|
||||||
jsval *argv = JS_ARGV(ctx, rval);
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
|
|
||||||
struct smjs_action_fn_callback_hop *hop;
|
struct smjs_action_fn_callback_hop *hop;
|
||||||
JSObject *fn_obj;
|
JS::RootedObject fn_obj(ctx);
|
||||||
|
|
||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
value = JSVAL_FALSE;
|
// if (true != JS_ValueToObject(ctx, JS_CALLEE(ctx, rval), &fn_obj)) {
|
||||||
|
if (true != JS_ValueToObject(ctx, args[0], &fn_obj)) {
|
||||||
if (JS_TRUE != JS_ValueToObject(ctx, JS_CALLEE(ctx, rval), &fn_obj)) {
|
args.rval().setBoolean(false);
|
||||||
JS_SET_RVAL(ctx, rval, value);
|
return true;
|
||||||
return JS_TRUE;
|
|
||||||
}
|
}
|
||||||
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 JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
hop = JS_GetInstancePrivate(ctx, fn_obj,
|
hop = JS_GetInstancePrivate(ctx, fn_obj,
|
||||||
(JSClass *) &action_fn_class, NULL);
|
(JSClass *) &action_fn_class, NULL);
|
||||||
if (!hop) {
|
if (!hop) {
|
||||||
JS_SET_RVAL(ctx, rval, value);
|
args.rval().setBoolean(false);
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!would_window_receive_keypresses(hop->ses->tab)) {
|
if (!would_window_receive_keypresses(hop->ses->tab)) {
|
||||||
@ -107,23 +107,21 @@ smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
JS_ReportError(ctx, "%s",
|
JS_ReportError(ctx, "%s",
|
||||||
_("Cannot run actions in a tab that doesn't "
|
_("Cannot run actions in a tab that doesn't "
|
||||||
"have the focus", hop->ses->tab->term));
|
"have the focus", hop->ses->tab->term));
|
||||||
return JS_FALSE; /* make JS propagate the exception */
|
return false; /* make JS propagate the exception */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc >= 1) {
|
if (argc >= 1) {
|
||||||
int32_t val;
|
int32_t val;
|
||||||
|
|
||||||
if (JS_TRUE == JS_ValueToInt32(smjs_ctx, argv[0], &val)) {
|
if (true == JS::ToInt32(smjs_ctx, args[0], &val)) {
|
||||||
set_kbd_repeat_count(hop->ses, val);
|
set_kbd_repeat_count(hop->ses, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_action(hop->ses, hop->action_id, 1);
|
do_action(hop->ses, hop->action_id, 1);
|
||||||
|
args.rval().setBoolean(true);
|
||||||
|
|
||||||
value = JSVAL_TRUE;
|
return true;
|
||||||
JS_SET_RVAL(ctx, rval, value);
|
|
||||||
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,7 +134,7 @@ smjs_get_action_fn_object(unsigned char *action_str)
|
|||||||
|
|
||||||
if (!smjs_ses) return NULL;
|
if (!smjs_ses) return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_fn_class, NULL, NULL);
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_fn_class, JS::NullPtr(), JS::NullPtr());
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
hop = mem_alloc(sizeof(*hop));
|
hop = mem_alloc(sizeof(*hop));
|
||||||
@ -164,29 +162,28 @@ smjs_get_action_fn_object(unsigned char *action_str)
|
|||||||
/*** elinks.action object ***/
|
/*** elinks.action object ***/
|
||||||
|
|
||||||
/* @action_class.getProperty */
|
/* @action_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
action_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
action_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
(void)obj;
|
|
||||||
|
|
||||||
jsval val;
|
jsval val;
|
||||||
|
JS::RootedValue rval(ctx, val);
|
||||||
JSObject *action_fn;
|
JSObject *action_fn;
|
||||||
unsigned char *action_str;
|
unsigned char *action_str;
|
||||||
|
|
||||||
*vp = JSVAL_NULL;
|
hvp.setNull();
|
||||||
|
|
||||||
JS_IdToValue(ctx, id, &val);
|
JS_IdToValue(ctx, id, &rval);
|
||||||
action_str = JS_EncodeString(ctx, JS_ValueToString(ctx, val));
|
action_str = JS_EncodeString(ctx, JS::ToString(ctx, rval));
|
||||||
if (!action_str) return JS_TRUE;
|
if (!action_str) return true;
|
||||||
|
|
||||||
action_fn = smjs_get_action_fn_object(action_str);
|
action_fn = smjs_get_action_fn_object(action_str);
|
||||||
if (!action_fn) return JS_TRUE;
|
if (!action_fn) return true;
|
||||||
|
|
||||||
*vp = OBJECT_TO_JSVAL(action_fn);
|
hvp.setObject(*action_fn);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JSClass action_class = {
|
static const JSClass action_class = {
|
||||||
@ -204,7 +201,7 @@ smjs_get_action_object(void)
|
|||||||
|
|
||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_class, NULL, NULL);
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_class, JS::NullPtr(), JS::NullPtr());
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -221,7 +218,10 @@ smjs_init_action_interface(void)
|
|||||||
action_object = smjs_get_action_object();
|
action_object = smjs_get_action_object();
|
||||||
if (!action_object) return;
|
if (!action_object) return;
|
||||||
|
|
||||||
val = OBJECT_TO_JSVAL(action_object);
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
|
|
||||||
JS_SetProperty(smjs_ctx, smjs_elinks_object, "action", &val);
|
JS::RootedValue r_val(smjs_ctx, val);
|
||||||
|
r_val.setObject(*r_smjs_elinks_object);
|
||||||
|
|
||||||
|
JS_SetProperty(smjs_ctx, r_smjs_elinks_object, "action", r_val);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
/*** common code ***/
|
/*** common code ***/
|
||||||
|
|
||||||
static void bookmark_finalize(JSFreeOp *op, JSObject *obj);
|
static void bookmark_finalize(JSFreeOp *op, JSObject *obj);
|
||||||
static JSBool 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 const JSClass bookmark_class = {
|
static const JSClass bookmark_class = {
|
||||||
"bookmark",
|
"bookmark",
|
||||||
@ -44,7 +44,7 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
|
|||||||
assert(clasp == &bookmark_class || clasp == &bookmark_folder_class);
|
assert(clasp == &bookmark_class || clasp == &bookmark_folder_class);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
jsobj = JS_NewObject(smjs_ctx, clasp, NULL, NULL);
|
jsobj = JS_NewObject(smjs_ctx, clasp, JS::NullPtr(), JS::NullPtr());
|
||||||
if (!jsobj) return NULL;
|
if (!jsobj) return NULL;
|
||||||
|
|
||||||
if (!bookmark) return jsobj;
|
if (!bookmark) return jsobj;
|
||||||
@ -84,16 +84,16 @@ enum bookmark_prop {
|
|||||||
BOOKMARK_CHILDREN = -3,
|
BOOKMARK_CHILDREN = -3,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSBool bookmark_get_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool bookmark_get_property_title(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool bookmark_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool bookmark_set_property_title(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool bookmark_get_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool bookmark_get_property_url(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool bookmark_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool bookmark_set_property_url(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool bookmark_get_property_children(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool bookmark_get_property_children(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
|
|
||||||
static const JSPropertySpec bookmark_props[] = {
|
static const JSPropertySpec bookmark_props[] = {
|
||||||
{ "title", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(bookmark_get_property_title), JSOP_WRAPPER(bookmark_set_property_title) },
|
JS_PSGS("title", bookmark_get_property_title, bookmark_set_property_title, JSPROP_ENUMERATE),
|
||||||
{ "url", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(bookmark_get_property_url), JSOP_WRAPPER(bookmark_set_property_url) },
|
JS_PSGS( "url", bookmark_get_property_url, bookmark_set_property_url, JSPROP_ENUMERATE),
|
||||||
{ "children", 0, JSPROP_ENUMERATE | JSPROP_READONLY, JSOP_WRAPPER(bookmark_get_property_children), JSOP_NULLWRAPPER },
|
JS_PSG("children", bookmark_get_property_children, JSPROP_ENUMERATE),
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,17 +101,17 @@ static JSObject *smjs_get_bookmark_folder_object(struct bookmark *bookmark);
|
|||||||
|
|
||||||
/** Convert a string retrieved from struct bookmark to a jsval.
|
/** Convert a string retrieved from struct bookmark to a jsval.
|
||||||
*
|
*
|
||||||
* @return JS_TRUE if successful. On error, report the error and
|
* @return true if successful. On error, report the error and
|
||||||
* return JS_FALSE. */
|
* return false. */
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_string_to_jsval(JSContext *ctx, const unsigned char *str, jsval *vp)
|
bookmark_string_to_jsval(JSContext *ctx, const unsigned char *str, jsval *vp)
|
||||||
{
|
{
|
||||||
JSString *jsstr = utf8_to_jsstring(ctx, str, -1);
|
JSString *jsstr = utf8_to_jsstring(ctx, str, -1);
|
||||||
|
|
||||||
if (jsstr == NULL)
|
if (jsstr == NULL)
|
||||||
return JS_FALSE;
|
return false;
|
||||||
*vp = STRING_TO_JSVAL(jsstr);
|
*vp = STRING_TO_JSVAL(jsstr);
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert a jsval to a string and store it in struct bookmark.
|
/** Convert a jsval to a string and store it in struct bookmark.
|
||||||
@ -124,72 +124,61 @@ bookmark_string_to_jsval(JSContext *ctx, const unsigned char *str, jsval *vp)
|
|||||||
* A string allocated with mem_alloc().
|
* A string allocated with mem_alloc().
|
||||||
* On success, this function frees the original string, if any.
|
* On success, this function frees the original string, if any.
|
||||||
*
|
*
|
||||||
* @return JS_TRUE if successful. On error, report the error to
|
* @return true if successful. On error, report the error to
|
||||||
* SpiderMonkey and return JS_FALSE. */
|
* SpiderMonkey and return false. */
|
||||||
static JSBool
|
static bool
|
||||||
jsval_to_bookmark_string(JSContext *ctx, jsval val, unsigned char **result)
|
jsval_to_bookmark_string(JSContext *ctx, JS::HandleValue val, unsigned char **result)
|
||||||
{
|
{
|
||||||
JSString *jsstr = NULL;
|
|
||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
|
|
||||||
/* JS_ValueToString constructs a new string if val is not
|
JSString *jsstr = JS::ToString(ctx, val);
|
||||||
* already a string. Protect the new string from the garbage
|
|
||||||
* collector, which jsstring_to_utf8() may trigger.
|
|
||||||
*
|
|
||||||
* Actually, SpiderMonkey 1.8.5 does not require this
|
|
||||||
* JS_AddNamedStringRoot call because it conservatively scans
|
|
||||||
* the C stack for GC roots. Do the call anyway, because:
|
|
||||||
* 1. Omitting the call would require somehow ensuring that the
|
|
||||||
* C compiler won't reuse the stack location too early.
|
|
||||||
* (See template class js::Anchor in <jsapi.h>.)
|
|
||||||
* 2. Later versions of SpiderMonkey are switching back to
|
|
||||||
* precise GC rooting, with a C++-only API.
|
|
||||||
* 3. jsval_to_bookmark_string() does not seem speed-critical. */
|
|
||||||
if (!JS_AddNamedStringRoot(ctx, &jsstr, "jsval_to_bookmark_string"))
|
|
||||||
return JS_FALSE;
|
|
||||||
|
|
||||||
jsstr = JS_ValueToString(ctx, val);
|
|
||||||
if (jsstr == NULL) {
|
if (jsstr == NULL) {
|
||||||
JS_RemoveStringRoot(ctx, &jsstr);
|
return false;
|
||||||
return JS_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str = jsstring_to_utf8(ctx, jsstr, NULL);
|
str = jsstring_to_utf8(ctx, jsstr, NULL);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
JS_RemoveStringRoot(ctx, &jsstr);
|
return false;
|
||||||
return JS_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_RemoveStringRoot(ctx, &jsstr);
|
|
||||||
mem_free_set(result, str);
|
mem_free_set(result, str);
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_get_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
bookmark_get_property_title(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct bookmark *bookmark;
|
struct bookmark *bookmark;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
bookmark = JS_GetInstancePrivate(ctx, obj,
|
bookmark = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &bookmark_class, NULL);
|
(JSClass *) &bookmark_class, NULL);
|
||||||
|
|
||||||
if (!bookmark) return JS_FALSE;
|
if (!bookmark) return false;
|
||||||
|
|
||||||
return bookmark_string_to_jsval(ctx, bookmark->title, vp);
|
JSString *jsstr = utf8_to_jsstring(ctx, bookmark->title, -1);
|
||||||
|
|
||||||
|
if (!jsstr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setString(jsstr);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
bookmark_set_property_title(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct bookmark *bookmark;
|
struct bookmark *bookmark;
|
||||||
unsigned char *title = NULL;
|
unsigned char *title = NULL;
|
||||||
@ -199,48 +188,56 @@ bookmark_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
bookmark = JS_GetInstancePrivate(ctx, obj,
|
bookmark = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &bookmark_class, NULL);
|
(JSClass *) &bookmark_class, NULL);
|
||||||
|
|
||||||
if (!bookmark) return JS_FALSE;
|
if (!bookmark) return false;
|
||||||
|
|
||||||
if (!jsval_to_bookmark_string(ctx, *vp, &title))
|
if (!jsval_to_bookmark_string(ctx, args[0], &title))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
ok = update_bookmark(bookmark, get_cp_index("UTF-8"), title, url);
|
ok = update_bookmark(bookmark, get_cp_index("UTF-8"), title, url);
|
||||||
mem_free_if(title);
|
mem_free_if(title);
|
||||||
mem_free_if(url);
|
mem_free_if(url);
|
||||||
return ok ? JS_TRUE : JS_FALSE;
|
return ok ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_get_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
bookmark_get_property_url(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct bookmark *bookmark;
|
struct bookmark *bookmark;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
bookmark = JS_GetInstancePrivate(ctx, obj,
|
bookmark = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &bookmark_class, NULL);
|
(JSClass *) &bookmark_class, NULL);
|
||||||
|
|
||||||
if (!bookmark) return JS_FALSE;
|
if (!bookmark) return false;
|
||||||
|
|
||||||
return bookmark_string_to_jsval(ctx, bookmark->url, vp);
|
JSString *jsstr = utf8_to_jsstring(ctx, bookmark->url, -1);
|
||||||
|
|
||||||
|
if (!jsstr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setString(jsstr);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
bookmark_set_property_url(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct bookmark *bookmark;
|
struct bookmark *bookmark;
|
||||||
unsigned char *title = NULL;
|
unsigned char *title = NULL;
|
||||||
@ -250,44 +247,45 @@ bookmark_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hi
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
bookmark = JS_GetInstancePrivate(ctx, obj,
|
bookmark = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &bookmark_class, NULL);
|
(JSClass *) &bookmark_class, NULL);
|
||||||
|
|
||||||
if (!bookmark) return JS_FALSE;
|
if (!bookmark) return false;
|
||||||
|
|
||||||
if (!jsval_to_bookmark_string(ctx, *vp, &url))
|
if (!jsval_to_bookmark_string(ctx, args[0], &url))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
ok = update_bookmark(bookmark, get_cp_index("UTF-8"), title, url);
|
ok = update_bookmark(bookmark, get_cp_index("UTF-8"), title, url);
|
||||||
mem_free_if(title);
|
mem_free_if(title);
|
||||||
mem_free_if(url);
|
mem_free_if(url);
|
||||||
return ok ? JS_TRUE : JS_FALSE;
|
return ok ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_get_property_children(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
bookmark_get_property_children(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct bookmark *bookmark;
|
struct bookmark *bookmark;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
bookmark = JS_GetInstancePrivate(ctx, obj,
|
bookmark = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &bookmark_class, NULL);
|
(JSClass *) &bookmark_class, NULL);
|
||||||
|
|
||||||
if (!bookmark) return JS_FALSE;
|
if (!bookmark) return false;
|
||||||
|
|
||||||
*vp = OBJECT_TO_JSVAL(smjs_get_bookmark_folder_object(bookmark));
|
args.rval().setObject(*smjs_get_bookmark_folder_object(bookmark));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -299,8 +297,9 @@ smjs_get_bookmark_object(struct bookmark *bookmark)
|
|||||||
jsobj = smjs_get_bookmark_generic_object(bookmark,
|
jsobj = smjs_get_bookmark_generic_object(bookmark,
|
||||||
(JSClass *) &bookmark_class);
|
(JSClass *) &bookmark_class);
|
||||||
|
|
||||||
|
JS::RootedObject r_jsobj(smjs_ctx, jsobj);
|
||||||
if (jsobj
|
if (jsobj
|
||||||
&& JS_TRUE == JS_DefineProperties(smjs_ctx, jsobj,
|
&& true == JS_DefineProperties(smjs_ctx, r_jsobj,
|
||||||
(JSPropertySpec *) bookmark_props))
|
(JSPropertySpec *) bookmark_props))
|
||||||
return jsobj;
|
return jsobj;
|
||||||
|
|
||||||
@ -311,41 +310,41 @@ smjs_get_bookmark_object(struct bookmark *bookmark)
|
|||||||
/*** bookmark folder object ***/
|
/*** bookmark folder object ***/
|
||||||
|
|
||||||
/* @bookmark_folder_class.getProperty */
|
/* @bookmark_folder_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
bookmark_folder_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
bookmark_folder_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
struct bookmark *bookmark;
|
struct bookmark *bookmark;
|
||||||
struct bookmark *folder;
|
struct bookmark *folder;
|
||||||
jsval title_jsval = JSVAL_VOID;
|
jsval val;
|
||||||
|
JS::RootedValue title_jsval(ctx, val);
|
||||||
unsigned char *title = NULL;
|
unsigned char *title = NULL;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_folder_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &bookmark_folder_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
folder = JS_GetInstancePrivate(ctx, obj,
|
folder = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &bookmark_folder_class, NULL);
|
(JSClass *) &bookmark_folder_class, NULL);
|
||||||
|
|
||||||
*vp = JSVAL_NULL;
|
hvp.setNull();
|
||||||
|
|
||||||
if (!JS_IdToValue(ctx, id, &title_jsval))
|
if (!JS_IdToValue(ctx, id, &title_jsval))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!jsval_to_bookmark_string(ctx, title_jsval, &title))
|
if (!jsval_to_bookmark_string(ctx, title_jsval, &title))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
bookmark = get_bookmark_by_name(folder, title);
|
bookmark = get_bookmark_by_name(folder, title);
|
||||||
if (bookmark) {
|
if (bookmark) {
|
||||||
*vp = OBJECT_TO_JSVAL(smjs_get_bookmark_object(bookmark));
|
hvp.setObject(*smjs_get_bookmark_object(bookmark));
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_free(title);
|
mem_free(title);
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -368,7 +367,9 @@ smjs_init_bookmarks_interface(void)
|
|||||||
bookmarks_object = smjs_get_bookmark_folder_object(NULL);
|
bookmarks_object = smjs_get_bookmark_folder_object(NULL);
|
||||||
if (!bookmarks_object) return;
|
if (!bookmarks_object) return;
|
||||||
|
|
||||||
val = OBJECT_TO_JSVAL(bookmarks_object);
|
JS::RootedValue rval(smjs_ctx, val);
|
||||||
|
rval.setObject(*bookmarks_object);
|
||||||
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
|
|
||||||
JS_SetProperty(smjs_ctx, smjs_elinks_object, "bookmarks", &val);
|
JS_SetProperty(smjs_ctx, r_smjs_elinks_object, "bookmarks", rval);
|
||||||
}
|
}
|
||||||
|
@ -37,45 +37,46 @@ enum cache_entry_prop {
|
|||||||
CACHE_ENTRY_URI = -5,
|
CACHE_ENTRY_URI = -5,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSBool cache_entry_get_property_content(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool cache_entry_get_property_content(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_set_property_content(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool cache_entry_set_property_content(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_get_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool cache_entry_get_property_type(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_set_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool cache_entry_set_property_type(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool cache_entry_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_get_property_head(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool cache_entry_get_property_head(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_set_property_head(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool cache_entry_set_property_head(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool cache_entry_get_property_uri(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool cache_entry_get_property_uri(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
|
|
||||||
static const JSPropertySpec cache_entry_props[] = {
|
static const JSPropertySpec cache_entry_props[] = {
|
||||||
{ "content", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(cache_entry_get_property_content), JSOP_WRAPPER(cache_entry_set_property_content) },
|
JS_PSGS("content", cache_entry_get_property_content, cache_entry_set_property_content, JSPROP_ENUMERATE),
|
||||||
{ "type", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(cache_entry_get_property_type), JSOP_WRAPPER(cache_entry_set_property_type)},
|
JS_PSGS("type", cache_entry_get_property_type, cache_entry_set_property_type, JSPROP_ENUMERATE),
|
||||||
{ "length", 0, JSPROP_ENUMERATE | JSPROP_READONLY, JSOP_WRAPPER(cache_entry_get_property_length), JSOP_NULLWRAPPER },
|
JS_PSG("length", cache_entry_get_property_length, JSPROP_ENUMERATE),
|
||||||
{ "head", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(cache_entry_get_property_head), JSOP_WRAPPER(cache_entry_set_property_head) },
|
JS_PSGS("head", cache_entry_get_property_head, cache_entry_set_property_head, JSPROP_ENUMERATE),
|
||||||
{ "uri", 0, JSPROP_ENUMERATE | JSPROP_READONLY, JSOP_WRAPPER(cache_entry_get_property_uri), JSOP_NULLWRAPPER },
|
JS_PSG("uri", cache_entry_get_property_uri, JSPROP_ENUMERATE),
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_get_property_content(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
cache_entry_get_property_content(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
struct fragment *fragment;
|
struct fragment *fragment;
|
||||||
JSBool ret;
|
bool ret;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
@ -83,24 +84,26 @@ cache_entry_get_property_content(JSContext *ctx, JS::HandleObject hobj, JS::Hand
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
args.rval().setUndefined();
|
||||||
|
|
||||||
fragment = get_cache_fragment(cached);
|
fragment = get_cache_fragment(cached);
|
||||||
|
|
||||||
if (!fragment) {
|
if (!fragment) {
|
||||||
ret = JS_FALSE;
|
ret = false;
|
||||||
} else {
|
} else {
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyN(smjs_ctx, fragment->data, fragment->length));
|
args.rval().setString(JS_NewStringCopyN(smjs_ctx, fragment->data, fragment->length));
|
||||||
ret = JS_TRUE;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_set_property_content(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
cache_entry_set_property_content(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
@ -110,15 +113,15 @@ cache_entry_set_property_content(JSContext *ctx, JS::HandleObject hobj, JS::Hand
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
@ -126,51 +129,53 @@ cache_entry_set_property_content(JSContext *ctx, JS::HandleObject hobj, JS::Hand
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
len = JS_GetStringLength(jsstr);
|
len = JS_GetStringLength(jsstr);
|
||||||
add_fragment(cached, 0, str, len);
|
add_fragment(cached, 0, str, len);
|
||||||
normalize_cache_entry(cached, len);
|
normalize_cache_entry(cached, len);
|
||||||
|
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_get_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
cache_entry_get_property_type(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
* collect garbage. After this, all code paths must
|
* collect garbage. After this, all code paths must
|
||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, cached->content_type));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, cached->content_type));
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_set_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
cache_entry_set_property_type(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
@ -179,15 +184,15 @@ cache_entry_set_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleI
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
@ -195,13 +200,13 @@ cache_entry_set_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleI
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&cached->content_type, stracpy(str));
|
mem_free_set(&cached->content_type, stracpy(str));
|
||||||
|
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -249,11 +254,13 @@ smjs_get_cache_entry_object(struct cache_entry *cached)
|
|||||||
|
|
||||||
cache_entry_object = JS_NewObject(smjs_ctx,
|
cache_entry_object = JS_NewObject(smjs_ctx,
|
||||||
(JSClass *) &cache_entry_class,
|
(JSClass *) &cache_entry_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(), JS::NullPtr());
|
||||||
|
|
||||||
if (!cache_entry_object) return NULL;
|
if (!cache_entry_object) return NULL;
|
||||||
|
|
||||||
if (JS_FALSE == JS_DefineProperties(smjs_ctx, cache_entry_object,
|
JS::RootedObject r_cache_entry_object(smjs_ctx, cache_entry_object);
|
||||||
|
|
||||||
|
if (false == JS_DefineProperties(smjs_ctx, r_cache_entry_object,
|
||||||
(JSPropertySpec *) cache_entry_props))
|
(JSPropertySpec *) cache_entry_props))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -279,7 +286,9 @@ smjs_detach_cache_entry_object(struct cache_entry *cached)
|
|||||||
|
|
||||||
if (!cached->jsobject) return;
|
if (!cached->jsobject) return;
|
||||||
|
|
||||||
assert(JS_GetInstancePrivate(smjs_ctx, cached->jsobject,
|
JS::RootedObject r_jsobject(smjs_ctx, cached->jsobject);
|
||||||
|
|
||||||
|
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject,
|
||||||
(JSClass *) &cache_entry_class, NULL)
|
(JSClass *) &cache_entry_class, NULL)
|
||||||
== cached);
|
== cached);
|
||||||
if_assert_failed {}
|
if_assert_failed {}
|
||||||
@ -288,72 +297,75 @@ smjs_detach_cache_entry_object(struct cache_entry *cached)
|
|||||||
cached->jsobject = NULL;
|
cached->jsobject = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
cache_entry_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
* collect garbage. After this, all code paths must
|
* collect garbage. After this, all code paths must
|
||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
*vp = INT_TO_JSVAL(cached->length);
|
args.rval().setInt32(cached->length);
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_get_property_head(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
cache_entry_get_property_head(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
* collect garbage. After this, all code paths must
|
* collect garbage. After this, all code paths must
|
||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, cached->head));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, cached->head));
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_set_property_head(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
cache_entry_set_property_head(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
@ -362,15 +374,15 @@ cache_entry_set_property_head(JSContext *ctx, JS::HandleObject hobj, JS::HandleI
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
@ -378,42 +390,43 @@ cache_entry_set_property_head(JSContext *ctx, JS::HandleObject hobj, JS::HandleI
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&cached->head, stracpy(str));
|
mem_free_set(&cached->head, stracpy(str));
|
||||||
|
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
cache_entry_get_property_uri(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
cache_entry_get_property_uri(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &cache_entry_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
cached = JS_GetInstancePrivate(ctx, obj,
|
cached = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &cache_entry_class, NULL);
|
(JSClass *) &cache_entry_class, NULL);
|
||||||
if (!cached) return JS_FALSE; /* already detached */
|
if (!cached) return false; /* already detached */
|
||||||
|
|
||||||
assert(cache_entry_is_valid(cached));
|
assert(cache_entry_is_valid(cached));
|
||||||
if_assert_failed return JS_FALSE;
|
if_assert_failed return false;
|
||||||
|
|
||||||
/* Get a strong reference to the cache entry to prevent it
|
/* Get a strong reference to the cache entry to prevent it
|
||||||
* from being deleted if some function called below decides to
|
* from being deleted if some function called below decides to
|
||||||
* collect garbage. After this, all code paths must
|
* collect garbage. After this, all code paths must
|
||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, struri(cached->uri)));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, struri(cached->uri)));
|
||||||
object_unlock(cached);
|
object_unlock(cached);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -75,14 +75,16 @@ static int
|
|||||||
smjs_do_file(unsigned char *path)
|
smjs_do_file(unsigned char *path)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
jsval rval;
|
|
||||||
struct string script;
|
struct string script;
|
||||||
|
|
||||||
if (!init_string(&script)) return 0;
|
if (!init_string(&script)) return 0;
|
||||||
|
|
||||||
|
jsval val;
|
||||||
|
JS::RootedValue rval(smjs_ctx, val);
|
||||||
|
JS::RootedObject cg(smjs_ctx, JS::CurrentGlobalOrNull(smjs_ctx));
|
||||||
|
|
||||||
if (!add_file_to_string(&script, path)
|
if (!add_file_to_string(&script, path)
|
||||||
|| JS_FALSE == JS_EvaluateScript(smjs_ctx,
|
|| false == JS_EvaluateScript(smjs_ctx, cg,
|
||||||
JS_GetGlobalForScopeChain(smjs_ctx),
|
|
||||||
script.source, script.length, path, 1, &rval)) {
|
script.source, script.length, path, 1, &rval)) {
|
||||||
alert_smjs_error("error loading script file");
|
alert_smjs_error("error loading script file");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -93,17 +95,18 @@ smjs_do_file(unsigned char *path)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_do_file_wrapper(JSContext *ctx, unsigned int argc, jsval *rval)
|
smjs_do_file_wrapper(JSContext *ctx, unsigned int argc, jsval *rval)
|
||||||
{
|
{
|
||||||
jsval *argv = JS_ARGV(ctx, rval);
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
JSString *jsstr = JS_ValueToString(smjs_ctx, *argv);
|
|
||||||
|
JSString *jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
unsigned char *path = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *path = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
if (smjs_do_file(path))
|
if (smjs_do_file(path))
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -136,15 +139,15 @@ init_smjs(struct module *module)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_SetOptions(smjs_ctx, JSOPTION_VAROBJFIX | JS_METHODJIT);
|
|
||||||
|
|
||||||
JS_SetErrorReporter(smjs_ctx, error_reporter);
|
JS_SetErrorReporter(smjs_ctx, error_reporter);
|
||||||
|
|
||||||
smjs_init_global_object();
|
smjs_init_global_object();
|
||||||
|
|
||||||
smjs_init_elinks_object();
|
smjs_init_elinks_object();
|
||||||
|
|
||||||
JS_DefineFunction(smjs_ctx, smjs_global_object, "do_file",
|
JS::RootedObject r_smjs_global_object(smjs_ctx, smjs_global_object);
|
||||||
|
|
||||||
|
JS_DefineFunction(smjs_ctx, r_smjs_global_object, "do_file",
|
||||||
&smjs_do_file_wrapper, 1, 0);
|
&smjs_do_file_wrapper, 1, 0);
|
||||||
|
|
||||||
smjs_load_hooks();
|
smjs_load_hooks();
|
||||||
|
@ -32,20 +32,21 @@
|
|||||||
|
|
||||||
|
|
||||||
/* @elinks_funcs{"alert"} */
|
/* @elinks_funcs{"alert"} */
|
||||||
static JSBool
|
static bool
|
||||||
elinks_alert(JSContext *ctx, unsigned int argc, jsval *rval)
|
elinks_alert(JSContext *ctx, unsigned int argc, jsval *rval)
|
||||||
{
|
{
|
||||||
jsval val;
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
jsval *argv = JS_ARGV(ctx, rval);
|
|
||||||
unsigned char *string;
|
unsigned char *string;
|
||||||
struct terminal *term;
|
struct terminal *term;
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
|
string = JS_EncodeString(ctx, args[0].toString());
|
||||||
|
|
||||||
string = jsval_to_string(ctx, &argv[0]);
|
|
||||||
if (!*string)
|
if (!*string)
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
if (smjs_ses) {
|
if (smjs_ses) {
|
||||||
term = smjs_ses->tab->term;
|
term = smjs_ses->tab->term;
|
||||||
@ -61,32 +62,30 @@ elinks_alert(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
undef_to_jsval(ctx, &val);
|
args.rval().setUndefined();
|
||||||
JS_SET_RVAL(ctx, rval, val);
|
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @elinks_funcs{"execute"} */
|
/* @elinks_funcs{"execute"} */
|
||||||
static JSBool
|
static bool
|
||||||
elinks_execute(JSContext *ctx, unsigned int argc, jsval *rval)
|
elinks_execute(JSContext *ctx, unsigned int argc, jsval *rval)
|
||||||
{
|
{
|
||||||
jsval val;
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
jsval *argv = JS_ARGV(ctx, rval);
|
|
||||||
unsigned char *string;
|
unsigned char *string;
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
string = jsval_to_string(ctx, &argv[0]);
|
string = JS_EncodeString(ctx, args[0].toString());
|
||||||
if (!*string)
|
if (!*string)
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
exec_on_terminal(smjs_ses->tab->term, string, "", TERM_EXEC_BG);
|
exec_on_terminal(smjs_ses->tab->term, string, "", TERM_EXEC_BG);
|
||||||
|
|
||||||
undef_to_jsval(ctx, &val);
|
args.rval().setUndefined();
|
||||||
JS_SET_RVAL(ctx, rval, val);
|
return true;
|
||||||
return JS_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum elinks_prop {
|
enum elinks_prop {
|
||||||
@ -95,20 +94,19 @@ enum elinks_prop {
|
|||||||
ELINKS_SESSION,
|
ELINKS_SESSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSBool elinks_get_property_home(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool elinks_get_property_home(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool elinks_get_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool elinks_get_property_location(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool elinks_set_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool elinks_set_property_location(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool elinks_get_property_session(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool elinks_get_property_session(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
|
|
||||||
static const JSPropertySpec elinks_props[] = {
|
static const JSPropertySpec elinks_props[] = {
|
||||||
{ "home", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, JSOP_WRAPPER(elinks_get_property_home), JSOP_NULLWRAPPER },
|
JS_PSG("home", elinks_get_property_home, JSPROP_ENUMERATE),
|
||||||
{ "location", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(elinks_get_property_location), JSOP_WRAPPER(elinks_set_property_location) },
|
JS_PSGS("location", elinks_get_property_location, elinks_set_property_location, JSPROP_ENUMERATE),
|
||||||
{ "session", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, JSOP_WRAPPER(elinks_get_property_session), JSOP_NULLWRAPPER},
|
JS_PSG("session", elinks_get_property_session, JSPROP_ENUMERATE),
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSBool elinks_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool elinks_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
||||||
static JSBool elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp);
|
||||||
|
|
||||||
static const JSClass elinks_class = {
|
static const JSClass elinks_class = {
|
||||||
"elinks",
|
"elinks",
|
||||||
@ -120,80 +118,78 @@ static const JSClass elinks_class = {
|
|||||||
|
|
||||||
|
|
||||||
/* @elinks_class.getProperty */
|
/* @elinks_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
elinks_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
elinks_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &elinks_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!JSID_IS_INT(id)) {
|
if (!JSID_IS_INT(id)) {
|
||||||
/* Note: If we return JS_FALSE here, the object's methods and
|
/* Note: If we return false here, the object's methods and
|
||||||
* user-added properties do not work. */
|
* user-added properties do not work. */
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
hvp.setUndefined();
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case ELINKS_HOME:
|
case ELINKS_HOME:
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, elinks_home));
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx, elinks_home));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
case ELINKS_LOCATION: {
|
case ELINKS_LOCATION: {
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
|
|
||||||
if (!smjs_ses) return JS_FALSE;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
uri = have_location(smjs_ses) ? cur_loc(smjs_ses)->vs.uri
|
uri = have_location(smjs_ses) ? cur_loc(smjs_ses)->vs.uri
|
||||||
: smjs_ses->loading_uri;
|
: smjs_ses->loading_uri;
|
||||||
|
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx,
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx,
|
||||||
uri ? (const char *) struri(uri) : ""));
|
uri ? (const char *) struri(uri) : ""));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
case ELINKS_SESSION: {
|
case ELINKS_SESSION: {
|
||||||
JSObject *jsobj;
|
JSObject *jsobj;
|
||||||
|
|
||||||
if (!smjs_ses) return JS_FALSE;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
jsobj = smjs_get_session_object(smjs_ses);
|
jsobj = smjs_get_session_object(smjs_ses);
|
||||||
if (!jsobj) return JS_FALSE;
|
if (!jsobj) return false;
|
||||||
|
|
||||||
object_to_jsval(ctx, vp, jsobj);
|
hvp.setObject(*jsobj);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
INTERNAL("Invalid ID %d in elinks_get_property().",
|
INTERNAL("Invalid ID %d in elinks_get_property().",
|
||||||
JSID_TO_INT(id));
|
JSID_TO_INT(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &elinks_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!JSID_IS_INT(id)) {
|
if (!JSID_IS_INT(id)) {
|
||||||
/* Note: If we return JS_FALSE here, the object's methods and
|
/* Note: If we return false here, the object's methods and
|
||||||
* user-added properties do not work. */
|
* user-added properties do not work. */
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
@ -201,24 +197,24 @@ elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSB
|
|||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
unsigned char *url;
|
unsigned char *url;
|
||||||
|
|
||||||
if (!smjs_ses) return JS_FALSE;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, hvp);
|
||||||
if (!jsstr) return JS_FALSE;
|
if (!jsstr) return false;
|
||||||
|
|
||||||
url = JS_EncodeString(smjs_ctx, jsstr);
|
url = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
if (!url) return JS_FALSE;
|
if (!url) return false;
|
||||||
|
|
||||||
goto_url(smjs_ses, url);
|
goto_url(smjs_ses, url);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
INTERNAL("Invalid ID %d in elinks_set_property().",
|
INTERNAL("Invalid ID %d in elinks_set_property().",
|
||||||
JSID_TO_INT(id));
|
JSID_TO_INT(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -256,107 +252,117 @@ smjs_init_elinks_object(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If elinks.<method> is defined, call it with the given arguments,
|
/* If elinks.<method> is defined, call it with the given arguments,
|
||||||
* store the return value in rval, and return JS_TRUE. Else return JS_FALSE. */
|
* store the return value in rval, and return true. Else return false. */
|
||||||
JSBool
|
bool
|
||||||
smjs_invoke_elinks_object_method(unsigned char *method, jsval argv[], int argc,
|
smjs_invoke_elinks_object_method(unsigned char *method, int argc, jsval *argv, JS::MutableHandleValue rval)
|
||||||
jsval *rval)
|
|
||||||
{
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, argv);
|
||||||
|
|
||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
assert(smjs_elinks_object);
|
assert(smjs_elinks_object);
|
||||||
assert(rval);
|
|
||||||
assert(argv);
|
assert(argv);
|
||||||
|
|
||||||
if (JS_FALSE == JS_GetProperty(smjs_ctx, smjs_elinks_object,
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
method, rval))
|
jsval val;
|
||||||
return JS_FALSE;
|
JS::RootedValue fun(smjs_ctx, val);
|
||||||
|
|
||||||
if (JSVAL_IS_VOID(*rval))
|
if (false == JS_GetProperty(smjs_ctx, r_smjs_elinks_object,
|
||||||
return JS_FALSE;
|
method, &fun))
|
||||||
|
return false;
|
||||||
|
|
||||||
return JS_CallFunctionValue(smjs_ctx, smjs_elinks_object,
|
if (rval.isUndefined())
|
||||||
*rval, argc, argv, rval);
|
return false;
|
||||||
|
|
||||||
|
return JS_CallFunctionValue(smjs_ctx, r_smjs_elinks_object, fun, args, rval);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
elinks_get_property_home(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
elinks_get_property_home(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &elinks_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, elinks_home));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, elinks_home));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
elinks_get_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
elinks_get_property_location(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &elinks_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!smjs_ses) return JS_FALSE;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
uri = have_location(smjs_ses) ? cur_loc(smjs_ses)->vs.uri : smjs_ses->loading_uri;
|
uri = have_location(smjs_ses) ? cur_loc(smjs_ses)->vs.uri : smjs_ses->loading_uri;
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, uri ? (const char *) struri(uri) : ""));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, uri ? (const char *) struri(uri) : ""));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
elinks_set_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
elinks_set_property_location(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
unsigned char *url;
|
unsigned char *url;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &elinks_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!smjs_ses) return JS_FALSE;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
if (!jsstr) return JS_FALSE;
|
if (!jsstr) return false;
|
||||||
|
|
||||||
url = JS_EncodeString(smjs_ctx, jsstr);
|
url = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
if (!url) return JS_FALSE;
|
if (!url) return false;
|
||||||
|
|
||||||
goto_url(smjs_ses, url);
|
goto_url(smjs_ses, url);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
elinks_get_property_session(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
elinks_get_property_session(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
JSObject *jsobj;
|
JSObject *jsobj;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &elinks_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!smjs_ses) return JS_FALSE;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
jsobj = smjs_get_session_object(smjs_ses);
|
jsobj = smjs_get_session_object(smjs_ses);
|
||||||
if (!jsobj) return JS_FALSE;
|
if (!jsobj) return false;
|
||||||
|
|
||||||
object_to_jsval(ctx, vp, jsobj);
|
args.rval().setObject(*jsobj);;
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ void smjs_init_elinks_object(void);
|
|||||||
|
|
||||||
/* Invoke elinks.<method> with the given arguments and put the return value
|
/* Invoke elinks.<method> with the given arguments and put the return value
|
||||||
* into *rval. */
|
* into *rval. */
|
||||||
JSBool smjs_invoke_elinks_object_method(unsigned char *method,
|
bool smjs_invoke_elinks_object_method(unsigned char *method, int argc, jsval *argv, JS::MutableHandleValue rval);
|
||||||
jsval argv[], int argc, jsval *rval);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,7 +32,7 @@ smjs_get_global_object(void)
|
|||||||
JSAutoRequest ar(smjs_ctx);
|
JSAutoRequest ar(smjs_ctx);
|
||||||
RootedObject jsobj(smjs_ctx);
|
RootedObject jsobj(smjs_ctx);
|
||||||
|
|
||||||
jsobj = JS_NewGlobalObject(smjs_ctx, (JSClass *) &global_class, NULL);
|
jsobj = JS_NewGlobalObject(smjs_ctx, (JSClass *) &global_class, NULL, JS::DontFireOnNewGlobalHook);
|
||||||
|
|
||||||
if (!jsobj) return NULL;
|
if (!jsobj) return NULL;
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "scripting/smjs/elinks_object.h"
|
#include "scripting/smjs/elinks_object.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
static JSBool 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 JSBool smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp);
|
||||||
|
|
||||||
static void smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj);
|
static void smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj);
|
||||||
|
|
||||||
@ -51,26 +51,25 @@ enum smjs_globhist_item_prop {
|
|||||||
GLOBHIST_LAST_VISIT = -3,
|
GLOBHIST_LAST_VISIT = -3,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSBool smjs_globhist_item_get_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_get_property_title(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool smjs_globhist_item_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool smjs_globhist_item_get_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_get_property_url(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool smjs_globhist_item_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool smjs_globhist_item_get_property_last_visit(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_get_property_last_visit(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
static JSBool smjs_globhist_item_set_property_last_visit(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, jsval *vp);
|
||||||
|
|
||||||
static const JSPropertySpec smjs_globhist_item_props[] = {
|
static const JSPropertySpec smjs_globhist_item_props[] = {
|
||||||
{ "title", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(smjs_globhist_item_get_property_title), JSOP_WRAPPER(smjs_globhist_item_set_property_title) },
|
JS_PSGS("title", smjs_globhist_item_get_property_title, smjs_globhist_item_set_property_title, JSPROP_ENUMERATE),
|
||||||
{ "url", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(smjs_globhist_item_get_property_url), JSOP_WRAPPER(smjs_globhist_item_set_property_url) },
|
JS_PSGS("url", smjs_globhist_item_get_property_url, smjs_globhist_item_set_property_url, JSPROP_ENUMERATE),
|
||||||
{ "last_visit", 0, JSPROP_ENUMERATE, JSOP_WRAPPER(smjs_globhist_item_get_property_last_visit), JSOP_WRAPPER(smjs_globhist_item_set_property_last_visit) },
|
JS_PSGS("last_visit", smjs_globhist_item_get_property_last_visit, smjs_globhist_item_set_property_last_visit, JSPROP_ENUMERATE),
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* @smjs_globhist_item_class.getProperty */
|
/* @smjs_globhist_item_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
||||||
JS::MutableHandleValue hvp)
|
JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
@ -78,31 +77,29 @@ smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
hvp.setUndefined();
|
||||||
|
|
||||||
if (!JSID_IS_INT(id))
|
if (!JSID_IS_INT(id))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case GLOBHIST_TITLE:
|
case GLOBHIST_TITLE:
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx,
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx, history_item->title));
|
||||||
history_item->title));
|
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
case GLOBHIST_URL:
|
case GLOBHIST_URL:
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx,
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx, history_item->url));
|
||||||
history_item->url));
|
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
case GLOBHIST_LAST_VISIT:
|
case GLOBHIST_LAST_VISIT:
|
||||||
/* TODO: I'd rather return a date object, but that introduces
|
/* TODO: I'd rather return a date object, but that introduces
|
||||||
* synchronisation issues:
|
* synchronisation issues:
|
||||||
@ -120,25 +117,24 @@ smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
* Since the Date object uses milliseconds since the epoch,
|
* Since the Date object uses milliseconds since the epoch,
|
||||||
* I'd rather export that, but SpiderMonkey doesn't provide
|
* I'd rather export that, but SpiderMonkey doesn't provide
|
||||||
* a suitable type. -- Miciah */
|
* a suitable type. -- Miciah */
|
||||||
*vp = JS_NumberValue(history_item->last_visit);
|
hvp.setInt32(history_item->last_visit);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
default:
|
default:
|
||||||
/* Unrecognized integer property ID; someone is using
|
/* Unrecognized integer property ID; someone is using
|
||||||
* the object as an array. SMJS builtin classes (e.g.
|
* the object as an array. SMJS builtin classes (e.g.
|
||||||
* js_RegExpClass) just return JS_TRUE in this case
|
* js_RegExpClass) just return true in this case
|
||||||
* and leave *@vp unchanged. Do the same here.
|
* and leave *@vp unchanged. Do the same here.
|
||||||
* (Actually not quite the same, as we already used
|
* (Actually not quite the same, as we already used
|
||||||
* @undef_to_jsval.) */
|
* @undef_to_jsval.) */
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @smjs_globhist_item_class.setProperty */
|
/* @smjs_globhist_item_class.setProperty */
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
@ -146,50 +142,50 @@ smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
if (!JSID_IS_INT(id))
|
if (!JSID_IS_INT(id))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case GLOBHIST_TITLE: {
|
case GLOBHIST_TITLE: {
|
||||||
JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
|
JSString *jsstr = JS::ToString(smjs_ctx, hvp);
|
||||||
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
mem_free_set(&history_item->title, stracpy(str));
|
mem_free_set(&history_item->title, stracpy(str));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
case GLOBHIST_URL: {
|
case GLOBHIST_URL: {
|
||||||
JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
|
JSString *jsstr = JS::ToString(smjs_ctx, hvp);
|
||||||
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
mem_free_set(&history_item->url, stracpy(str));
|
mem_free_set(&history_item->url, stracpy(str));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
case GLOBHIST_LAST_VISIT: {
|
case GLOBHIST_LAST_VISIT: {
|
||||||
uint32_t seconds;
|
uint32_t seconds;
|
||||||
|
|
||||||
/* Bug 923: Assumes time_t values fit in uint32. */
|
/* Bug 923: Assumes time_t values fit in uint32. */
|
||||||
JS_ValueToECMAUint32(smjs_ctx, *vp, &seconds);
|
JS::ToInt32(smjs_ctx, hvp, &seconds);
|
||||||
history_item->last_visit = seconds;
|
history_item->last_visit = seconds;
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* Unrecognized integer property ID; someone is using
|
/* Unrecognized integer property ID; someone is using
|
||||||
* the object as an array. SMJS builtin classes (e.g.
|
* the object as an array. SMJS builtin classes (e.g.
|
||||||
* js_RegExpClass) just return JS_TRUE in this case.
|
* js_RegExpClass) just return true in this case.
|
||||||
* Do the same here. */
|
* Do the same here. */
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,9 +196,12 @@ smjs_get_globhist_item_object(struct global_history_item *history_item)
|
|||||||
JSObject *jsobj;
|
JSObject *jsobj;
|
||||||
|
|
||||||
jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class,
|
jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(), JS::NullPtr());
|
||||||
|
|
||||||
|
JS::RootedObject r_jsobj(smjs_ctx, jsobj);
|
||||||
|
|
||||||
if (!jsobj
|
if (!jsobj
|
||||||
|| JS_TRUE != JS_DefineProperties(smjs_ctx, jsobj,
|
|| true != JS_DefineProperties(smjs_ctx, r_jsobj,
|
||||||
(JSPropertySpec *) smjs_globhist_item_props)) {
|
(JSPropertySpec *) smjs_globhist_item_props)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -214,22 +213,22 @@ smjs_get_globhist_item_object(struct global_history_item *history_item)
|
|||||||
|
|
||||||
|
|
||||||
/* @smjs_globhist_class.getProperty */
|
/* @smjs_globhist_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
smjs_globhist_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
(void)obj;
|
|
||||||
|
|
||||||
JSObject *jsobj;
|
JSObject *jsobj;
|
||||||
unsigned char *uri_string;
|
unsigned char *uri_string;
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
jsval tmp;
|
jsval tmp;
|
||||||
|
JS::RootedValue r_tmp(ctx, tmp);
|
||||||
|
|
||||||
if (!JS_IdToValue(ctx, id, &tmp))
|
|
||||||
|
if (!JS_IdToValue(ctx, id, &r_tmp))
|
||||||
goto ret_null;
|
goto ret_null;
|
||||||
|
|
||||||
uri_string = JS_EncodeString(ctx, JS_ValueToString(ctx, tmp));
|
uri_string = JS_EncodeString(ctx, JS::ToString(ctx, r_tmp));
|
||||||
if (!uri_string) goto ret_null;
|
if (!uri_string) goto ret_null;
|
||||||
|
|
||||||
history_item = get_global_history_item(uri_string);
|
history_item = get_global_history_item(uri_string);
|
||||||
@ -238,14 +237,14 @@ smjs_globhist_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
|||||||
jsobj = smjs_get_globhist_item_object(history_item);
|
jsobj = smjs_get_globhist_item_object(history_item);
|
||||||
if (!jsobj) goto ret_null;
|
if (!jsobj) goto ret_null;
|
||||||
|
|
||||||
*vp = OBJECT_TO_JSVAL(jsobj);
|
hvp.setObject(*jsobj);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
ret_null:
|
ret_null:
|
||||||
*vp = JSVAL_NULL;
|
hvp.setNull();
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JSClass smjs_globhist_class = {
|
static const JSClass smjs_globhist_class = {
|
||||||
@ -261,7 +260,7 @@ smjs_get_globhist_object(void)
|
|||||||
JSObject *globhist;
|
JSObject *globhist;
|
||||||
|
|
||||||
globhist = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_class,
|
globhist = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(), JS::NullPtr());
|
||||||
if (!globhist) return NULL;
|
if (!globhist) return NULL;
|
||||||
|
|
||||||
return globhist;
|
return globhist;
|
||||||
@ -279,40 +278,43 @@ smjs_init_globhist_interface(void)
|
|||||||
globhist = smjs_get_globhist_object();
|
globhist = smjs_get_globhist_object();
|
||||||
if (!globhist) return;
|
if (!globhist) return;
|
||||||
|
|
||||||
val = OBJECT_TO_JSVAL(globhist);
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
|
JS::RootedValue r_val(smjs_ctx, val);
|
||||||
|
r_val.setObject(*globhist);
|
||||||
|
|
||||||
JS_SetProperty(smjs_ctx, smjs_elinks_object, "globhist", &val);
|
JS_SetProperty(smjs_ctx, r_smjs_elinks_object, "globhist", r_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_get_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
smjs_globhist_item_get_property_title(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
JS::MutableHandleValue hvp)
|
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, history_item->title));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, history_item->title));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
@ -321,51 +323,52 @@ smjs_globhist_item_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS:
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&history_item->title, stracpy(str));
|
mem_free_set(&history_item->title, stracpy(str));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_get_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
smjs_globhist_item_get_property_url(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
JS::MutableHandleValue hvp)
|
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, history_item->url));
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, history_item->url));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
@ -374,41 +377,41 @@ smjs_globhist_item_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::H
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&history_item->url, stracpy(str));
|
mem_free_set(&history_item->url, stracpy(str));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_get_property_last_visit(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
smjs_globhist_item_get_property_last_visit(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
JS::MutableHandleValue hvp)
|
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
/* TODO: I'd rather return a date object, but that introduces
|
/* TODO: I'd rather return a date object, but that introduces
|
||||||
* synchronisation issues:
|
* synchronisation issues:
|
||||||
@ -426,16 +429,17 @@ smjs_globhist_item_get_property_last_visit(JSContext *ctx, JS::HandleObject hobj
|
|||||||
* Since the Date object uses milliseconds since the epoch,
|
* Since the Date object uses milliseconds since the epoch,
|
||||||
* I'd rather export that, but SpiderMonkey doesn't provide
|
* I'd rather export that, but SpiderMonkey doesn't provide
|
||||||
* a suitable type. -- Miciah */
|
* a suitable type. -- Miciah */
|
||||||
*vp = JS_NumberValue(history_item->last_visit);
|
args.rval().setInt32(history_item->last_visit);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @smjs_globhist_item_class.setProperty */
|
/* @smjs_globhist_item_class.setProperty */
|
||||||
static JSBool
|
static bool
|
||||||
smjs_globhist_item_set_property_last_visit(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
uint32_t seconds;
|
uint32_t seconds;
|
||||||
@ -443,18 +447,18 @@ smjs_globhist_item_set_property_last_visit(JSContext *ctx, JS::HandleObject hobj
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
history_item = JS_GetInstancePrivate(ctx, obj,
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &smjs_globhist_item_class,
|
(JSClass *) &smjs_globhist_item_class,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!history_item) return JS_FALSE;
|
if (!history_item) return false;
|
||||||
|
|
||||||
/* Bug 923: Assumes time_t values fit in uint32. */
|
/* Bug 923: Assumes time_t values fit in uint32. */
|
||||||
JS_ValueToECMAUint32(smjs_ctx, *vp, &seconds);
|
JS::ToInt32(smjs_ctx, args[0], &seconds);
|
||||||
history_item->last_visit = seconds;
|
history_item->last_visit = seconds;
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -27,20 +27,20 @@ script_hook_url(va_list ap, void *data)
|
|||||||
unsigned char **url = va_arg(ap, unsigned char **);
|
unsigned char **url = va_arg(ap, unsigned char **);
|
||||||
struct session *ses = va_arg(ap, struct session *);
|
struct session *ses = va_arg(ap, struct session *);
|
||||||
enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
|
enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
|
||||||
jsval args[1], rval;
|
jsval args[3], rval;
|
||||||
|
JS::RootedValue r_rval(smjs_ctx, rval);
|
||||||
|
|
||||||
if (*url == NULL) return EVENT_HOOK_STATUS_NEXT;
|
if (*url == NULL) return EVENT_HOOK_STATUS_NEXT;
|
||||||
|
|
||||||
smjs_ses = ses;
|
smjs_ses = ses;
|
||||||
|
args[2].setString(JS_NewStringCopyZ(smjs_ctx, *url));
|
||||||
|
|
||||||
args[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, *url));
|
if (true == smjs_invoke_elinks_object_method(data, 1, args, &r_rval)) {
|
||||||
|
if (r_rval.isBoolean()) {
|
||||||
if (JS_TRUE == smjs_invoke_elinks_object_method(data, args, 1, &rval)) {
|
if (false == (r_rval.toBoolean()))
|
||||||
if (JSVAL_IS_BOOLEAN(rval)) {
|
|
||||||
if (JS_FALSE == JSVAL_TO_BOOLEAN(rval))
|
|
||||||
ret = EVENT_HOOK_STATUS_LAST;
|
ret = EVENT_HOOK_STATUS_LAST;
|
||||||
} else {
|
} else {
|
||||||
JSString *jsstr = JS_ValueToString(smjs_ctx, rval);
|
JSString *jsstr = JS::ToString(smjs_ctx, r_rval);
|
||||||
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
mem_free_set(url, stracpy(str));
|
mem_free_set(url, stracpy(str));
|
||||||
@ -59,7 +59,8 @@ script_hook_pre_format_html(va_list ap, void *data)
|
|||||||
struct cache_entry *cached = va_arg(ap, struct cache_entry *);
|
struct cache_entry *cached = va_arg(ap, struct cache_entry *);
|
||||||
enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
|
enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
|
||||||
JSObject *cache_entry_object, *view_state_object = NULL;
|
JSObject *cache_entry_object, *view_state_object = NULL;
|
||||||
jsval args[2], rval;
|
jsval args[4], rval;
|
||||||
|
JS::RootedValue r_rval(smjs_ctx, rval);
|
||||||
|
|
||||||
evhook_use_params(ses && cached);
|
evhook_use_params(ses && cached);
|
||||||
|
|
||||||
@ -76,12 +77,12 @@ script_hook_pre_format_html(va_list ap, void *data)
|
|||||||
cache_entry_object = smjs_get_cache_entry_object(cached);
|
cache_entry_object = smjs_get_cache_entry_object(cached);
|
||||||
if (!cache_entry_object) goto end;
|
if (!cache_entry_object) goto end;
|
||||||
|
|
||||||
args[0] = OBJECT_TO_JSVAL(cache_entry_object);
|
args[2].setObject(*cache_entry_object);
|
||||||
args[1] = OBJECT_TO_JSVAL(view_state_object);
|
args[3].setObject(*view_state_object);
|
||||||
|
|
||||||
if (JS_TRUE == smjs_invoke_elinks_object_method("preformat_html",
|
if (true == smjs_invoke_elinks_object_method("preformat_html",
|
||||||
args, 2, &rval))
|
2, args, &r_rval))
|
||||||
if (JS_FALSE == JSVAL_TO_BOOLEAN(rval))
|
if (false == JSVAL_TO_BOOLEAN(rval))
|
||||||
ret = EVENT_HOOK_STATUS_LAST;
|
ret = EVENT_HOOK_STATUS_LAST;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
#include "scripting/smjs/elinks_object.h"
|
#include "scripting/smjs/elinks_object.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
static JSBool 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 JSBool keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp);
|
||||||
static void keymap_finalize(JSFreeOp *op, JSObject *obj);
|
static void keymap_finalize(JSFreeOp *op, JSObject *obj);
|
||||||
|
|
||||||
static const JSClass keymap_class = {
|
static const JSClass keymap_class = {
|
||||||
@ -26,50 +26,53 @@ static const JSClass keymap_class = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* @keymap_class.getProperty */
|
/* @keymap_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
unsigned char *action_str;
|
unsigned char *action_str;
|
||||||
const unsigned char *keystroke_str;
|
const unsigned char *keystroke_str;
|
||||||
int *data;
|
int *data;
|
||||||
jsval tmp;
|
jsval tmp;
|
||||||
|
JS::RootedValue r_tmp(ctx, tmp);
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &keymap_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &keymap_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
data = JS_GetInstancePrivate(ctx, obj,
|
data = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &keymap_class, NULL);
|
(JSClass *) &keymap_class, NULL);
|
||||||
|
|
||||||
if (!JS_IdToValue(ctx, id, &tmp))
|
if (!JS_IdToValue(ctx, id, &r_tmp))
|
||||||
goto ret_null;
|
goto ret_null;
|
||||||
|
|
||||||
keystroke_str = JS_EncodeString(ctx, JS_ValueToString(ctx, tmp));
|
keystroke_str = JS_EncodeString(ctx, JS::ToString(ctx, r_tmp));
|
||||||
if (!keystroke_str) goto ret_null;
|
if (!keystroke_str) goto ret_null;
|
||||||
|
|
||||||
action_str = get_action_name_from_keystroke((enum keymap_id) *data,
|
action_str = get_action_name_from_keystroke((enum keymap_id) *data,
|
||||||
keystroke_str);
|
keystroke_str);
|
||||||
if (!action_str || !strcmp(action_str, "none")) goto ret_null;
|
if (!action_str || !strcmp(action_str, "none")) goto ret_null;
|
||||||
|
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx, action_str));
|
hvp.setString(JS_NewStringCopyZ(ctx, action_str));
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
ret_null:
|
ret_null:
|
||||||
*vp = JSVAL_NULL;
|
hvp.setNull();
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum evhook_status
|
static enum evhook_status
|
||||||
smjs_keybinding_action_callback(va_list ap, void *data)
|
smjs_keybinding_action_callback(va_list ap, void *data)
|
||||||
{
|
{
|
||||||
|
JS::CallArgs args;
|
||||||
|
|
||||||
jsval rval;
|
jsval rval;
|
||||||
|
JS::RootedValue r_rval(smjs_ctx, rval);
|
||||||
struct session *ses = va_arg(ap, struct session *);
|
struct session *ses = va_arg(ap, struct session *);
|
||||||
JSObject *jsobj = data;
|
JSObject *jsobj = data;
|
||||||
|
|
||||||
@ -77,8 +80,12 @@ smjs_keybinding_action_callback(va_list ap, void *data)
|
|||||||
|
|
||||||
smjs_ses = ses;
|
smjs_ses = ses;
|
||||||
|
|
||||||
JS_CallFunctionValue(smjs_ctx, NULL, OBJECT_TO_JSVAL(jsobj),
|
jsval r2;
|
||||||
0, NULL, &rval);
|
JS::RootedValue r_jsobject(smjs_ctx, r2);
|
||||||
|
r_jsobject.setObject(*jsobj);
|
||||||
|
|
||||||
|
JS_CallFunctionValue(smjs_ctx, JS::NullPtr(), r_jsobject,
|
||||||
|
args, &r_rval);
|
||||||
|
|
||||||
smjs_ses = NULL;
|
smjs_ses = NULL;
|
||||||
|
|
||||||
@ -86,10 +93,9 @@ smjs_keybinding_action_callback(va_list ap, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* @keymap_class.setProperty */
|
/* @keymap_class.setProperty */
|
||||||
static JSBool
|
static bool
|
||||||
keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
int *data;
|
int *data;
|
||||||
@ -100,48 +106,49 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSB
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &keymap_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &keymap_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
data = JS_GetInstancePrivate(ctx, obj,
|
data = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &keymap_class, NULL);
|
(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... */
|
||||||
keymap_str = get_keymap_name((enum keymap_id) *data);
|
keymap_str = get_keymap_name((enum keymap_id) *data);
|
||||||
if (!keymap_str) return JS_FALSE;
|
if (!keymap_str) return false;
|
||||||
|
|
||||||
JS_IdToValue(ctx, id, &val);
|
JS::RootedValue rval(ctx, val);
|
||||||
keystroke_str = JS_EncodeString(ctx, JS_ValueToString(ctx, val));
|
JS_IdToValue(ctx, id, &rval);
|
||||||
if (!keystroke_str) return JS_FALSE;
|
keystroke_str = JS_EncodeString(ctx, JS::ToString(ctx, rval));
|
||||||
|
if (!keystroke_str) return false;
|
||||||
|
|
||||||
if (JSVAL_IS_STRING(*vp)) {
|
if (hvp.isString()) {
|
||||||
unsigned char *action_str;
|
unsigned char *action_str;
|
||||||
|
|
||||||
action_str = JS_EncodeString(ctx, JS_ValueToString(ctx, *vp));
|
action_str = JS_EncodeString(ctx, JS::ToString(ctx, hvp));
|
||||||
if (!action_str) return JS_FALSE;
|
if (!action_str) return false;
|
||||||
|
|
||||||
if (bind_do(keymap_str, keystroke_str, action_str, 0))
|
if (bind_do(keymap_str, keystroke_str, action_str, 0))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
} else if (JSVAL_IS_NULL(*vp)) { /* before JSVAL_IS_OBJECT */
|
} else if (hvp.isNull()) { /* before JSVAL_IS_OBJECT */
|
||||||
if (bind_do(keymap_str, keystroke_str, "none", 0))
|
if (bind_do(keymap_str, keystroke_str, "none", 0))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
|
|
||||||
} else if (!JSVAL_IS_PRIMITIVE(*vp) || JSVAL_IS_NULL(*vp)) {
|
} else if (hvp.isObject() || hvp.isNull()) {
|
||||||
unsigned char *err = NULL;
|
unsigned char *err = NULL;
|
||||||
int event_id;
|
int event_id;
|
||||||
struct string event_name = NULL_STRING;
|
struct string event_name = NULL_STRING;
|
||||||
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
|
JSObject *jsobj = &hvp.toObject();
|
||||||
|
|
||||||
if (JS_FALSE == JS_ObjectIsFunction(ctx, jsobj))
|
if (false == JS_ObjectIsFunction(ctx, jsobj))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
if (!init_string(&event_name)) return JS_FALSE;
|
if (!init_string(&event_name)) return false;
|
||||||
|
|
||||||
add_format_to_string(&event_name, "smjs-run-func %p", jsobj);
|
add_format_to_string(&event_name, "smjs-run-func %p", jsobj);
|
||||||
|
|
||||||
@ -154,7 +161,7 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSB
|
|||||||
if (err) {
|
if (err) {
|
||||||
alert_smjs_error(err);
|
alert_smjs_error(err);
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_id = register_event_hook(event_id,
|
event_id = register_event_hook(event_id,
|
||||||
@ -165,13 +172,13 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSB
|
|||||||
alert_smjs_error("error registering event hook"
|
alert_smjs_error("error registering event hook"
|
||||||
" for keybinding");
|
" for keybinding");
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @keymap_class.finalize */
|
/* @keymap_class.finalize */
|
||||||
@ -198,7 +205,7 @@ smjs_get_keymap_object(enum keymap_id keymap_id)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
|
|
||||||
keymap_object = JS_NewObject(smjs_ctx, (JSClass *) &keymap_class,
|
keymap_object = JS_NewObject(smjs_ctx, (JSClass *) &keymap_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(),JS::NullPtr());
|
||||||
|
|
||||||
if (!keymap_object) return NULL;
|
if (!keymap_object) return NULL;
|
||||||
|
|
||||||
@ -225,9 +232,12 @@ smjs_get_keymap_hash_object(void)
|
|||||||
JSObject *keymaps_hash;
|
JSObject *keymaps_hash;
|
||||||
|
|
||||||
keymaps_hash = JS_NewObject(smjs_ctx, (JSClass *) &keymaps_hash_class,
|
keymaps_hash = JS_NewObject(smjs_ctx, (JSClass *) &keymaps_hash_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(), JS::NullPtr());
|
||||||
if (!keymaps_hash) return NULL;
|
if (!keymaps_hash) return NULL;
|
||||||
|
|
||||||
|
JS::RootedObject r_keymaps_hash(smjs_ctx, keymaps_hash);
|
||||||
|
JS::RootedValue r_val(smjs_ctx, val);
|
||||||
|
|
||||||
for (keymap_id = 0; keymap_id < KEYMAP_MAX; ++keymap_id) {
|
for (keymap_id = 0; keymap_id < KEYMAP_MAX; ++keymap_id) {
|
||||||
unsigned char *keymap_str = get_keymap_name(keymap_id);
|
unsigned char *keymap_str = get_keymap_name(keymap_id);
|
||||||
JSObject *map = smjs_get_keymap_object(keymap_id);
|
JSObject *map = smjs_get_keymap_object(keymap_id);
|
||||||
@ -236,9 +246,9 @@ smjs_get_keymap_hash_object(void)
|
|||||||
|
|
||||||
if (!map) return NULL;
|
if (!map) return NULL;
|
||||||
|
|
||||||
val = OBJECT_TO_JSVAL(map);
|
r_val.setObject(*map);
|
||||||
|
|
||||||
JS_SetProperty(smjs_ctx, keymaps_hash, keymap_str, &val);
|
JS_SetProperty(smjs_ctx, r_keymaps_hash, keymap_str, r_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return keymaps_hash;
|
return keymaps_hash;
|
||||||
@ -256,7 +266,9 @@ smjs_init_keybinding_interface(void)
|
|||||||
keymaps_hash = smjs_get_keymap_hash_object();
|
keymaps_hash = smjs_get_keymap_hash_object();
|
||||||
if (!keymaps_hash) return;
|
if (!keymaps_hash) return;
|
||||||
|
|
||||||
val = OBJECT_TO_JSVAL(keymaps_hash);
|
JS::RootedValue r_val(smjs_ctx, val);
|
||||||
|
r_val.setObject(*keymaps_hash);
|
||||||
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
|
|
||||||
JS_SetProperty(smjs_ctx, smjs_elinks_object, "keymaps", &val);
|
JS_SetProperty(smjs_ctx, r_smjs_elinks_object, "keymaps", r_val);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ struct smjs_load_uri_hop {
|
|||||||
* jsval that points to the corresponding JSObject. Besides,
|
* jsval that points to the corresponding JSObject. Besides,
|
||||||
* JS_AddNamedRoot is not documented to support JSFunction
|
* JS_AddNamedRoot is not documented to support JSFunction
|
||||||
* pointers. */
|
* pointers. */
|
||||||
jsval callback;
|
JS::MutableHandleValue callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -32,11 +32,15 @@ smjs_loading_callback(struct download *download, void *data)
|
|||||||
{
|
{
|
||||||
struct session *saved_smjs_ses = smjs_ses;
|
struct session *saved_smjs_ses = smjs_ses;
|
||||||
struct smjs_load_uri_hop *hop = data;
|
struct smjs_load_uri_hop *hop = data;
|
||||||
|
|
||||||
jsval args[1], rval;
|
jsval args[1], rval;
|
||||||
JSObject *cache_entry_object;
|
JSObject *cache_entry_object;
|
||||||
|
|
||||||
if (is_in_progress_state(download->state)) return;
|
if (is_in_progress_state(download->state)) return;
|
||||||
|
|
||||||
|
JS::CallArgs argv;
|
||||||
|
JS::RootedValue r_rval(smjs_ctx, rval);
|
||||||
|
|
||||||
if (!download->cached) goto end;
|
if (!download->cached) goto end;
|
||||||
|
|
||||||
/* download->cached->object.refcount is typically 0 here
|
/* download->cached->object.refcount is typically 0 here
|
||||||
@ -52,22 +56,24 @@ smjs_loading_callback(struct download *download, void *data)
|
|||||||
if (!cache_entry_object) goto end;
|
if (!cache_entry_object) goto end;
|
||||||
|
|
||||||
args[0] = OBJECT_TO_JSVAL(cache_entry_object);
|
args[0] = OBJECT_TO_JSVAL(cache_entry_object);
|
||||||
JS_CallFunctionValue(smjs_ctx, NULL, hop->callback, 1, args, &rval);
|
argv = CallArgsFromVp(1, args);
|
||||||
|
|
||||||
|
JS_CallFunctionValue(smjs_ctx, JS::NullPtr(), hop->callback, argv, &r_rval);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (download->cached)
|
if (download->cached)
|
||||||
object_unlock(download->cached);
|
object_unlock(download->cached);
|
||||||
JS_RemoveValueRoot(smjs_ctx, &hop->callback);
|
|
||||||
mem_free(download->data);
|
mem_free(download->data);
|
||||||
mem_free(download);
|
mem_free(download);
|
||||||
|
|
||||||
smjs_ses = saved_smjs_ses;
|
smjs_ses = saved_smjs_ses;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_load_uri(JSContext *ctx, unsigned int argc, jsval *rval)
|
smjs_load_uri(JSContext *ctx, unsigned int argc, jsval *rval)
|
||||||
{
|
{
|
||||||
jsval *argv = JS_ARGV(ctx, rval);
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
|
|
||||||
struct smjs_load_uri_hop *hop;
|
struct smjs_load_uri_hop *hop;
|
||||||
struct download *download;
|
struct download *download;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
@ -75,45 +81,38 @@ smjs_load_uri(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
unsigned char *uri_string;
|
unsigned char *uri_string;
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
|
|
||||||
if (argc < 2) return JS_FALSE;
|
if (argc < 2) return false;
|
||||||
|
|
||||||
jsstr = JS_ValueToString(smjs_ctx, argv[0]);
|
jsstr = JS::ToString(smjs_ctx, args[0]);
|
||||||
uri_string = JS_EncodeString(smjs_ctx, jsstr);
|
uri_string = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
if (!uri_string || !*uri_string) return JS_FALSE;
|
if (!uri_string || !*uri_string) return false;
|
||||||
|
|
||||||
uri = get_uri(uri_string, 0);
|
uri = get_uri(uri_string, 0);
|
||||||
if (!uri) return JS_FALSE;
|
if (!uri) return false;
|
||||||
|
|
||||||
external_handler = get_protocol_external_handler(NULL, uri);
|
external_handler = get_protocol_external_handler(NULL, uri);
|
||||||
if (external_handler) {
|
if (external_handler) {
|
||||||
/* Because smjs_load_uri is carrying out an asynchronous
|
/* Because smjs_load_uri is carrying out an asynchronous
|
||||||
* operation, it is inappropriate to call an external
|
* operation, it is inappropriate to call an external
|
||||||
* handler here, so just return. */
|
* handler here, so just return. */
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
download = mem_alloc(sizeof(*download));
|
download = mem_alloc(sizeof(*download));
|
||||||
if (!download) {
|
if (!download) {
|
||||||
done_uri(uri);
|
done_uri(uri);
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hop = mem_alloc(sizeof(*hop));
|
hop = mem_alloc(sizeof(*hop));
|
||||||
if (!hop) {
|
if (!hop) {
|
||||||
mem_free(download);
|
mem_free(download);
|
||||||
done_uri(uri);
|
done_uri(uri);
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hop->callback = argv[1];
|
hop->callback.set(args[1]);
|
||||||
hop->ses = smjs_ses;
|
hop->ses = smjs_ses;
|
||||||
if (!JS_AddNamedValueRoot(smjs_ctx, &hop->callback,
|
|
||||||
"smjs_load_uri_hop.callback")) {
|
|
||||||
mem_free(hop);
|
|
||||||
mem_free(download);
|
|
||||||
done_uri(uri);
|
|
||||||
return JS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
download->data = hop;
|
download->data = hop;
|
||||||
download->callback = (download_callback_T *) smjs_loading_callback;
|
download->callback = (download_callback_T *) smjs_loading_callback;
|
||||||
@ -122,7 +121,7 @@ smjs_load_uri(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
|
|
||||||
done_uri(uri);
|
done_uri(uri);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -131,6 +130,8 @@ smjs_init_load_uri_interface(void)
|
|||||||
if (!smjs_ctx || !smjs_elinks_object)
|
if (!smjs_ctx || !smjs_elinks_object)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JS_DefineFunction(smjs_ctx, smjs_elinks_object, "load_uri",
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
|
|
||||||
|
JS_DefineFunction(smjs_ctx, r_smjs_elinks_object, "load_uri",
|
||||||
&smjs_load_uri, 2, 0);
|
&smjs_load_uri, 2, 0);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@
|
|||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "viewer/text/vs.h"
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
static JSBool terminal_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
static bool terminal_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
||||||
static void terminal_finalize(JSFreeOp *op, JSObject *obj);
|
static void terminal_finalize(JSFreeOp *op, JSObject *obj);
|
||||||
|
|
||||||
static const JSClass terminal_class = {
|
static const JSClass terminal_class = {
|
||||||
@ -38,10 +38,9 @@ static const JSPropertySpec terminal_props[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* @terminal_class.getProperty */
|
/* @terminal_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
terminal_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
terminal_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
struct terminal *term;
|
struct terminal *term;
|
||||||
@ -49,31 +48,33 @@ terminal_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, J
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &terminal_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &terminal_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
term = JS_GetInstancePrivate(ctx, obj,
|
term = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &terminal_class, NULL);
|
(JSClass *) &terminal_class, NULL);
|
||||||
if (!term) return JS_FALSE; /* already detached */
|
if (!term) return false; /* already detached */
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
hvp.setUndefined();
|
||||||
|
|
||||||
if (!JSID_IS_INT(id)) return JS_FALSE;
|
if (!JSID_IS_INT(id)) return false;
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case TERMINAL_TAB: {
|
case TERMINAL_TAB: {
|
||||||
JSObject *obj = smjs_get_session_array_object(term);
|
JSObject *obj = smjs_get_session_array_object(term);
|
||||||
|
|
||||||
if (obj) object_to_jsval(ctx, vp, obj);
|
if (obj) {
|
||||||
|
hvp.setObject(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
INTERNAL("Invalid ID %d in terminal_get_property().",
|
INTERNAL("Invalid ID %d in terminal_get_property().",
|
||||||
JSID_TO_INT(id));
|
JSID_TO_INT(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Pointed to by terminal_class.finalize. SpiderMonkey automatically
|
/** Pointed to by terminal_class.finalize. SpiderMonkey automatically
|
||||||
@ -111,11 +112,12 @@ smjs_get_terminal_object(struct terminal *term)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &terminal_class, NULL, NULL);
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &terminal_class, JS::NullPtr(), JS::NullPtr());
|
||||||
|
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
if (JS_FALSE == JS_DefineProperties(smjs_ctx, obj,
|
JS::RootedObject robj(smjs_ctx, obj);
|
||||||
|
if (false == JS_DefineProperties(smjs_ctx, robj,
|
||||||
(JSPropertySpec *) terminal_props))
|
(JSPropertySpec *) terminal_props))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -143,7 +145,9 @@ smjs_detach_terminal_object(struct terminal *term)
|
|||||||
|
|
||||||
if (!term->jsobject) return;
|
if (!term->jsobject) return;
|
||||||
|
|
||||||
assert(JS_GetInstancePrivate(smjs_ctx, term->jsobject,
|
JS::RootedObject r_jsobject(smjs_ctx, term->jsobject);
|
||||||
|
|
||||||
|
assert(JS_GetInstancePrivate(smjs_ctx, r_jsobject,
|
||||||
(JSClass *) &terminal_class, NULL)
|
(JSClass *) &terminal_class, NULL)
|
||||||
== term);
|
== term);
|
||||||
if_assert_failed {}
|
if_assert_failed {}
|
||||||
@ -154,31 +158,32 @@ smjs_detach_terminal_object(struct terminal *term)
|
|||||||
|
|
||||||
|
|
||||||
/* @terminal_array_class.getProperty */
|
/* @terminal_array_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
terminal_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
terminal_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
struct terminal *term;
|
struct terminal *term;
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
hvp.setUndefined();
|
||||||
|
|
||||||
if (!JSID_IS_INT(id))
|
if (!JSID_IS_INT(id))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
index = JSID_TO_INT(id);
|
index = JSID_TO_INT(id);
|
||||||
foreach (term, terminals) {
|
foreach (term, terminals) {
|
||||||
if (!index) break;
|
if (!index) break;
|
||||||
--index;
|
--index;
|
||||||
}
|
}
|
||||||
if ((void *) term == (void *) &terminals) return JS_FALSE;
|
if ((void *) term == (void *) &terminals) return false;
|
||||||
|
|
||||||
obj = smjs_get_terminal_object(term);
|
JSObject *obj = smjs_get_terminal_object(term);
|
||||||
if (obj) object_to_jsval(ctx, vp, obj);
|
if (obj) {
|
||||||
|
hvp.setObject(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +204,7 @@ smjs_get_terminal_array_object(void)
|
|||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
return JS_NewObject(smjs_ctx, (JSClass *) &terminal_array_class,
|
return JS_NewObject(smjs_ctx, (JSClass *) &terminal_array_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(), JS::NullPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -214,7 +219,9 @@ smjs_init_terminal_interface(void)
|
|||||||
obj = smjs_get_terminal_array_object();
|
obj = smjs_get_terminal_array_object();
|
||||||
if (!obj) return;
|
if (!obj) return;
|
||||||
|
|
||||||
val = OBJECT_TO_JSVAL(obj);
|
JS::RootedValue rval(smjs_ctx, val);
|
||||||
|
rval.setObject(*obj);
|
||||||
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
|
|
||||||
JS_SetProperty(smjs_ctx, smjs_elinks_object, "terminal", &val);
|
JS_SetProperty(smjs_ctx, r_smjs_elinks_object, "terminal", rval);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "viewer/text/vs.h"
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
static JSBool 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 JSBool view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
|
static bool view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp);
|
||||||
static void view_state_finalize(JSFreeOp *op, JSObject *obj);
|
static void view_state_finalize(JSFreeOp *op, JSObject *obj);
|
||||||
|
|
||||||
static const JSClass view_state_class = {
|
static const JSClass view_state_class = {
|
||||||
@ -42,16 +42,15 @@ enum view_state_prop {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const JSPropertySpec view_state_props[] = {
|
static const JSPropertySpec view_state_props[] = {
|
||||||
{ "plain", VIEW_STATE_PLAIN, JSPROP_ENUMERATE },
|
{ "plain", (unsigned char)VIEW_STATE_PLAIN, JSPROP_ENUMERATE },
|
||||||
{ "uri", VIEW_STATE_URI, JSPROP_ENUMERATE | JSPROP_READONLY },
|
{ "uri", (unsigned char)VIEW_STATE_URI, JSPROP_ENUMERATE | JSPROP_READONLY },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* @view_state_class.getProperty */
|
/* @view_state_class.getProperty */
|
||||||
static JSBool
|
static bool
|
||||||
view_state_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
view_state_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
@ -59,44 +58,42 @@ view_state_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &view_state_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
vs = JS_GetInstancePrivate(ctx, obj,
|
vs = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &view_state_class, NULL);
|
(JSClass *) &view_state_class, NULL);
|
||||||
if (!vs) return JS_FALSE;
|
if (!vs) return false;
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
hvp.setUndefined();
|
||||||
|
|
||||||
if (!JSID_IS_INT(id))
|
if (!JSID_IS_INT(id))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case VIEW_STATE_PLAIN:
|
case VIEW_STATE_PLAIN:
|
||||||
*vp = INT_TO_JSVAL(vs->plain);
|
hvp.setInt32(vs->plain);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
case VIEW_STATE_URI:
|
case VIEW_STATE_URI:
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx,
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx, struri(vs->uri)));
|
||||||
struri(vs->uri)));
|
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
default:
|
default:
|
||||||
/* Unrecognized integer property ID; someone is using
|
/* Unrecognized integer property ID; someone is using
|
||||||
* the object as an array. SMJS builtin classes (e.g.
|
* the object as an array. SMJS builtin classes (e.g.
|
||||||
* js_RegExpClass) just return JS_TRUE in this case
|
* js_RegExpClass) just return true in this case
|
||||||
* and leave *@vp unchanged. Do the same here.
|
* and leave *@vp unchanged. Do the same here.
|
||||||
* (Actually not quite the same, as we already used
|
* (Actually not quite the same, as we already used
|
||||||
* @undef_to_jsval.) */
|
* @undef_to_jsval.) */
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @view_state_class.setProperty */
|
/* @view_state_class.setProperty */
|
||||||
static JSBool
|
static bool
|
||||||
view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
|
view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
@ -104,28 +101,28 @@ view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
|||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
* such calls. */
|
* such calls. */
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &view_state_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
vs = JS_GetInstancePrivate(ctx, obj,
|
vs = JS_GetInstancePrivate(ctx, hobj,
|
||||||
(JSClass *) &view_state_class, NULL);
|
(JSClass *) &view_state_class, NULL);
|
||||||
if (!vs) return JS_FALSE;
|
if (!vs) return false;
|
||||||
|
|
||||||
if (!JSID_IS_INT(id))
|
if (!JSID_IS_INT(id))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case VIEW_STATE_PLAIN: {
|
case VIEW_STATE_PLAIN: {
|
||||||
vs->plain = atol(jsval_to_string(ctx, vp));
|
vs->plain = hvp.toInt32();
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* Unrecognized integer property ID; someone is using
|
/* Unrecognized integer property ID; someone is using
|
||||||
* the object as an array. SMJS builtin classes (e.g.
|
* the object as an array. SMJS builtin classes (e.g.
|
||||||
* js_RegExpClass) just return JS_TRUE in this case.
|
* js_RegExpClass) just return true in this case.
|
||||||
* Do the same here. */
|
* Do the same here. */
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,11 +166,13 @@ smjs_get_view_state_object(struct view_state *vs)
|
|||||||
|
|
||||||
view_state_object = JS_NewObject(smjs_ctx,
|
view_state_object = JS_NewObject(smjs_ctx,
|
||||||
(JSClass *) &view_state_class,
|
(JSClass *) &view_state_class,
|
||||||
NULL, NULL);
|
JS::NullPtr(), JS::NullPtr());
|
||||||
|
|
||||||
if (!view_state_object) return NULL;
|
if (!view_state_object) return NULL;
|
||||||
|
|
||||||
if (JS_FALSE == JS_DefineProperties(smjs_ctx, view_state_object,
|
JS::RootedObject r_view_state_object(smjs_ctx, view_state_object);
|
||||||
|
|
||||||
|
if (false == JS_DefineProperties(smjs_ctx, r_view_state_object,
|
||||||
(JSPropertySpec *) view_state_props))
|
(JSPropertySpec *) view_state_props))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -186,28 +185,25 @@ smjs_get_view_state_object(struct view_state *vs)
|
|||||||
return view_state_object;
|
return view_state_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBool
|
static bool
|
||||||
smjs_elinks_get_view_state(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
smjs_elinks_get_view_state(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
(void)obj;
|
|
||||||
|
|
||||||
JSObject *vs_obj;
|
JSObject *vs_obj;
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
|
|
||||||
*vp = JSVAL_NULL;
|
hvp.setNull();
|
||||||
|
|
||||||
if (!smjs_ses || !have_location(smjs_ses)) return JS_TRUE;
|
if (!smjs_ses || !have_location(smjs_ses)) return true;
|
||||||
|
|
||||||
vs = &cur_loc(smjs_ses)->vs;
|
vs = &cur_loc(smjs_ses)->vs;
|
||||||
if (!vs) return JS_TRUE;
|
if (!vs) return true;
|
||||||
|
|
||||||
vs_obj = smjs_get_view_state_object(vs);
|
vs_obj = smjs_get_view_state_object(vs);
|
||||||
if (!vs_obj) return JS_TRUE;
|
if (!vs_obj) return true;
|
||||||
|
|
||||||
*vp = OBJECT_TO_JSVAL(vs_obj);
|
hvp.setObject(*vs_obj);
|
||||||
|
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ensure that no JSObject contains the pointer @a vs. This is called from
|
/** Ensure that no JSObject contains the pointer @a vs. This is called from
|
||||||
@ -223,7 +219,9 @@ smjs_detach_view_state_object(struct view_state *vs)
|
|||||||
|
|
||||||
if (!vs->jsobject) return;
|
if (!vs->jsobject) return;
|
||||||
|
|
||||||
assert(JS_GetInstancePrivate(smjs_ctx, vs->jsobject,
|
JS::RootedObject r_vs_jsobject(smjs_ctx, vs->jsobject);
|
||||||
|
|
||||||
|
assert(JS_GetInstancePrivate(smjs_ctx, r_vs_jsobject,
|
||||||
(JSClass *) &view_state_class, NULL)
|
(JSClass *) &view_state_class, NULL)
|
||||||
== vs);
|
== vs);
|
||||||
if_assert_failed {}
|
if_assert_failed {}
|
||||||
@ -238,7 +236,9 @@ smjs_init_view_state_interface(void)
|
|||||||
if (!smjs_ctx || !smjs_elinks_object)
|
if (!smjs_ctx || !smjs_elinks_object)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JS_DefineProperty(smjs_ctx, smjs_elinks_object, "vs", JSVAL_NULL,
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
||||||
smjs_elinks_get_view_state, JS_StrictPropertyStub,
|
|
||||||
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY);
|
JS_DefineProperty(smjs_ctx, r_smjs_elinks_object, "vs", (int32_t)0,
|
||||||
|
(unsigned int)(JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY), smjs_elinks_get_view_state, JS_StrictPropertyStub
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user