2006-05-03 09:52:58 -04:00
|
|
|
/* "elinks.globhist" */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "globhist/globhist.h"
|
2008-07-16 05:32:24 -04:00
|
|
|
#include "ecmascript/spidermonkey-shared.h"
|
2006-05-03 09:52:58 -04:00
|
|
|
#include "scripting/smjs/core.h"
|
|
|
|
#include "scripting/smjs/elinks_object.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
2020-10-23 16:34:58 -04:00
|
|
|
static bool smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
static void smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj);
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2020-10-27 09:53:24 -04:00
|
|
|
static const JSClassOps smjs_globhist_item_ops = {
|
2021-08-27 13:46:05 -04:00
|
|
|
nullptr, // addProperty
|
|
|
|
nullptr, // deleteProperty
|
|
|
|
nullptr, // enumerate
|
|
|
|
nullptr, // newEnumerate
|
|
|
|
nullptr, // resolve
|
|
|
|
nullptr, // mayResolve
|
|
|
|
nullptr, // finalize
|
|
|
|
nullptr, // call
|
|
|
|
nullptr, // hasInstance
|
|
|
|
nullptr, // construct
|
|
|
|
nullptr // trace JS_GlobalObjectTraceHook
|
2020-10-05 14:14:55 -04:00
|
|
|
};
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2020-10-27 09:53:24 -04:00
|
|
|
static const JSClass smjs_globhist_item_class = {
|
|
|
|
"global_history_item",
|
|
|
|
JSCLASS_HAS_PRIVATE, /* struct global_history_item * */
|
|
|
|
&smjs_globhist_item_ops
|
|
|
|
};
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @smjs_globhist_item_class.finalize */
|
2006-05-03 09:52:58 -04:00
|
|
|
static void
|
2019-02-10 15:00:37 -05:00
|
|
|
smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj)
|
2006-05-03 09:52:58 -04:00
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
struct global_history_item *history_item;
|
2019-02-10 15:00:37 -05:00
|
|
|
#if 0
|
2006-11-25 01:54:58 -05:00
|
|
|
assert(JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL));
|
|
|
|
if_assert_failed return;
|
2019-02-10 15:00:37 -05:00
|
|
|
#endif
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2019-02-10 15:00:37 -05:00
|
|
|
history_item = JS_GetPrivate(obj);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
|
|
|
if (history_item) object_unlock(history_item);
|
|
|
|
}
|
|
|
|
|
2006-12-06 16:09:14 -05:00
|
|
|
/* Tinyids of properties. Use negative values to distinguish these
|
|
|
|
* from array indexes (even though this object has no array elements).
|
|
|
|
* ECMAScript code should not use these directly as in global_history_item[-1];
|
|
|
|
* future future versions of ELinks may change the numbers. */
|
2006-05-03 09:52:58 -04:00
|
|
|
enum smjs_globhist_item_prop {
|
2006-12-06 16:09:14 -05:00
|
|
|
GLOBHIST_TITLE = -1,
|
|
|
|
GLOBHIST_URL = -2,
|
|
|
|
GLOBHIST_LAST_VISIT = -3,
|
2006-05-03 09:52:58 -04:00
|
|
|
};
|
|
|
|
|
2020-10-23 16:34:58 -04:00
|
|
|
static bool smjs_globhist_item_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
|
|
|
static bool smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
|
|
|
static bool smjs_globhist_item_get_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
|
|
|
static bool smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
|
|
|
static bool smjs_globhist_item_get_property_last_visit(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
|
|
|
static bool smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2006-05-03 09:52:58 -04:00
|
|
|
static const JSPropertySpec smjs_globhist_item_props[] = {
|
2020-10-12 12:43:56 -04:00
|
|
|
JS_PSGS("title", smjs_globhist_item_get_property_title, smjs_globhist_item_set_property_title, JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS("url", smjs_globhist_item_get_property_url, smjs_globhist_item_set_property_url, JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS("last_visit", smjs_globhist_item_get_property_last_visit, smjs_globhist_item_set_property_last_visit, JSPROP_ENUMERATE),
|
2020-11-21 11:54:47 -05:00
|
|
|
JS_PS_END
|
2006-05-03 09:52:58 -04:00
|
|
|
};
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @smjs_globhist_item_class.getProperty */
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-05 14:14:55 -04:00
|
|
|
smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
|
|
|
|
JS::MutableHandleValue hvp)
|
2006-05-03 09:52:58 -04:00
|
|
|
{
|
2020-10-05 14:14:55 -04:00
|
|
|
jsid id = hid.get();
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2006-11-24 01:50:12 -05:00
|
|
|
struct global_history_item *history_item;
|
|
|
|
|
2006-12-03 04:14:22 -05:00
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2007-05-27 11:32:53 -04:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
hvp.setUndefined();
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
if (!JSID_IS_INT(id))
|
2020-10-12 12:43:56 -04:00
|
|
|
return false;
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
switch (JSID_TO_INT(id)) {
|
2006-05-03 09:52:58 -04:00
|
|
|
case GLOBHIST_TITLE:
|
2020-10-12 12:43:56 -04:00
|
|
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx, history_item->title));
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
case GLOBHIST_URL:
|
2020-10-12 12:43:56 -04:00
|
|
|
hvp.setString(JS_NewStringCopyZ(smjs_ctx, history_item->url));
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
case GLOBHIST_LAST_VISIT:
|
|
|
|
/* TODO: I'd rather return a date object, but that introduces
|
|
|
|
* synchronisation issues:
|
|
|
|
*
|
|
|
|
* - How do we cause a change to that date object to affect
|
|
|
|
* the actual global history item?
|
|
|
|
* - How do we get a change to that global history item
|
|
|
|
* to affect all date objects?
|
|
|
|
*
|
|
|
|
* The biggest obstacle is that we have no way to trigger code
|
|
|
|
* when one messes with the date object.
|
|
|
|
*
|
|
|
|
* -- Miciah */
|
|
|
|
/* XXX: Currently, ECMAScript gets seconds since the epoch.
|
|
|
|
* Since the Date object uses milliseconds since the epoch,
|
|
|
|
* I'd rather export that, but SpiderMonkey doesn't provide
|
|
|
|
* a suitable type. -- Miciah */
|
2020-10-12 12:43:56 -04:00
|
|
|
hvp.setInt32(history_item->last_visit);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
default:
|
2007-05-27 11:36:31 -04:00
|
|
|
/* Unrecognized integer property ID; someone is using
|
|
|
|
* the object as an array. SMJS builtin classes (e.g.
|
2020-10-12 12:43:56 -04:00
|
|
|
* js_RegExpClass) just return true in this case
|
2006-12-03 05:07:07 -05:00
|
|
|
* and leave *@vp unchanged. Do the same here.
|
|
|
|
* (Actually not quite the same, as we already used
|
|
|
|
* @undef_to_jsval.) */
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @smjs_globhist_item_class.setProperty */
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
2006-05-03 09:52:58 -04:00
|
|
|
{
|
2020-10-05 14:14:55 -04:00
|
|
|
jsid id = hid.get();
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2006-11-24 01:50:12 -05:00
|
|
|
struct global_history_item *history_item;
|
|
|
|
|
2006-12-03 04:14:22 -05:00
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2007-05-27 11:32:53 -04:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
if (!JSID_IS_INT(id))
|
2020-10-12 12:43:56 -04:00
|
|
|
return false;
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
switch (JSID_TO_INT(id)) {
|
2006-05-03 09:52:58 -04:00
|
|
|
case GLOBHIST_TITLE: {
|
2021-08-27 13:46:05 -04:00
|
|
|
char *str = jsval_to_string(smjs_ctx, hvp);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
|
|
|
mem_free_set(&history_item->title, stracpy(str));
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
|
|
|
case GLOBHIST_URL: {
|
2021-08-27 13:46:05 -04:00
|
|
|
char *str = jsval_to_string(smjs_ctx, hvp);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
|
|
|
mem_free_set(&history_item->url, stracpy(str));
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
|
|
|
case GLOBHIST_LAST_VISIT: {
|
2007-01-13 08:26:21 -05:00
|
|
|
/* Bug 923: Assumes time_t values fit in uint32. */
|
2020-10-16 13:54:02 -04:00
|
|
|
history_item->last_visit = hvp.toInt32();
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
|
|
|
default:
|
2007-05-27 11:36:31 -04:00
|
|
|
/* Unrecognized integer property ID; someone is using
|
|
|
|
* the object as an array. SMJS builtin classes (e.g.
|
2020-10-12 12:43:56 -04:00
|
|
|
* js_RegExpClass) just return true in this case.
|
2006-12-03 05:07:07 -05:00
|
|
|
* Do the same here. */
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static JSObject *
|
|
|
|
smjs_get_globhist_item_object(struct global_history_item *history_item)
|
|
|
|
{
|
|
|
|
JSObject *jsobj;
|
|
|
|
|
2020-10-16 13:54:02 -04:00
|
|
|
jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class);
|
2020-10-12 12:43:56 -04:00
|
|
|
|
|
|
|
JS::RootedObject r_jsobj(smjs_ctx, jsobj);
|
|
|
|
|
2006-05-03 09:52:58 -04:00
|
|
|
if (!jsobj
|
2020-10-12 12:43:56 -04:00
|
|
|
|| true != JS_DefineProperties(smjs_ctx, r_jsobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSPropertySpec *) smjs_globhist_item_props)) {
|
2006-05-03 09:52:58 -04:00
|
|
|
return NULL;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|
|
|
|
JS_SetPrivate(jsobj, history_item); /* to @smjs_globhist_item_class */
|
2006-05-03 09:52:58 -04:00
|
|
|
object_lock(history_item);
|
|
|
|
|
|
|
|
return jsobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @smjs_globhist_class.getProperty */
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-05 14:14:55 -04:00
|
|
|
smjs_globhist_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
2006-05-03 09:52:58 -04:00
|
|
|
{
|
2020-10-05 14:14:55 -04:00
|
|
|
jsid id = hid.get();
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2006-05-03 09:52:58 -04:00
|
|
|
JSObject *jsobj;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *uri_string;
|
2006-05-03 09:52:58 -04:00
|
|
|
struct global_history_item *history_item;
|
2020-10-23 16:34:58 -04:00
|
|
|
JS::Value tmp;
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::RootedValue r_tmp(ctx, tmp);
|
|
|
|
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_IdToValue(ctx, id, &r_tmp))
|
2012-03-04 12:11:18 -05:00
|
|
|
goto ret_null;
|
|
|
|
|
2021-08-27 13:46:05 -04:00
|
|
|
uri_string = jsval_to_string(ctx, r_tmp);
|
2006-05-03 09:52:58 -04:00
|
|
|
if (!uri_string) goto ret_null;
|
|
|
|
|
|
|
|
history_item = get_global_history_item(uri_string);
|
|
|
|
if (!history_item) goto ret_null;
|
|
|
|
|
|
|
|
jsobj = smjs_get_globhist_item_object(history_item);
|
|
|
|
if (!jsobj) goto ret_null;
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
hvp.setObject(*jsobj);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
|
|
|
|
ret_null:
|
2020-10-12 12:43:56 -04:00
|
|
|
hvp.setNull();
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
|
|
|
|
2020-10-27 09:53:24 -04:00
|
|
|
static const JSClassOps smjs_globhist_ops = {
|
2021-08-27 13:46:05 -04:00
|
|
|
nullptr, // addProperty
|
|
|
|
nullptr, // deleteProperty
|
|
|
|
nullptr, // enumerate
|
|
|
|
nullptr, // newEnumerate
|
|
|
|
nullptr, // resolve
|
|
|
|
nullptr, // mayResolve
|
|
|
|
nullptr, // finalize
|
|
|
|
nullptr, // call
|
|
|
|
nullptr, // hasInstance
|
|
|
|
nullptr, // construct
|
|
|
|
nullptr // trace JS_GlobalObjectTraceHook
|
2019-04-21 06:27:40 -04:00
|
|
|
};
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-27 09:53:24 -04:00
|
|
|
static const JSClass smjs_globhist_class = {
|
|
|
|
"global_history", 0,
|
|
|
|
&smjs_globhist_ops
|
|
|
|
};
|
|
|
|
|
2006-05-03 09:52:58 -04:00
|
|
|
static JSObject *
|
|
|
|
smjs_get_globhist_object(void)
|
|
|
|
{
|
|
|
|
JSObject *globhist;
|
|
|
|
|
2020-10-16 13:54:02 -04:00
|
|
|
globhist = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_class);
|
2006-05-03 09:52:58 -04:00
|
|
|
if (!globhist) return NULL;
|
|
|
|
|
|
|
|
return globhist;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
smjs_init_globhist_interface(void)
|
|
|
|
{
|
2020-10-23 16:34:58 -04:00
|
|
|
JS::Value val;
|
2006-05-03 09:52:58 -04:00
|
|
|
struct JSObject *globhist;
|
|
|
|
|
|
|
|
if (!smjs_ctx || !smjs_elinks_object)
|
|
|
|
return;
|
|
|
|
|
|
|
|
globhist = smjs_get_globhist_object();
|
|
|
|
if (!globhist) return;
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::RootedObject r_smjs_elinks_object(smjs_ctx, smjs_elinks_object);
|
|
|
|
JS::RootedValue r_val(smjs_ctx, val);
|
|
|
|
r_val.setObject(*globhist);
|
2006-05-03 09:52:58 -04:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
JS_SetProperty(smjs_ctx, r_smjs_elinks_object, "globhist", r_val);
|
2006-05-03 09:52:58 -04:00
|
|
|
}
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 15:00:37 -05:00
|
|
|
{
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
struct global_history_item *history_item;
|
|
|
|
|
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, history_item->title));
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 15:00:37 -05:00
|
|
|
{
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
struct global_history_item *history_item;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *str;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2021-08-27 13:46:05 -04:00
|
|
|
str = jsval_to_string(smjs_ctx, args[0]);
|
2019-02-10 15:00:37 -05:00
|
|
|
mem_free_set(&history_item->title, stracpy(str));
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_get_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 15:00:37 -05:00
|
|
|
{
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
struct global_history_item *history_item;
|
|
|
|
|
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
args.rval().setString(JS_NewStringCopyZ(smjs_ctx, history_item->url));
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 15:00:37 -05:00
|
|
|
{
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
struct global_history_item *history_item;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *str;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2021-08-27 13:46:05 -04:00
|
|
|
str = jsval_to_string(smjs_ctx, args[0]);
|
2019-02-10 15:00:37 -05:00
|
|
|
mem_free_set(&history_item->url, stracpy(str));
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_get_property_last_visit(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 15:00:37 -05:00
|
|
|
{
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
struct global_history_item *history_item;
|
|
|
|
|
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
/* TODO: I'd rather return a date object, but that introduces
|
|
|
|
* synchronisation issues:
|
|
|
|
*
|
|
|
|
* - How do we cause a change to that date object to affect
|
|
|
|
* the actual global history item?
|
|
|
|
* - How do we get a change to that global history item
|
|
|
|
* to affect all date objects?
|
|
|
|
*
|
|
|
|
* The biggest obstacle is that we have no way to trigger code
|
|
|
|
* when one messes with the date object.
|
|
|
|
*
|
|
|
|
* -- Miciah */
|
|
|
|
/* XXX: Currently, ECMAScript gets seconds since the epoch.
|
|
|
|
* Since the Date object uses milliseconds since the epoch,
|
|
|
|
* I'd rather export that, but SpiderMonkey doesn't provide
|
|
|
|
* a suitable type. -- Miciah */
|
2020-10-12 12:43:56 -04:00
|
|
|
args.rval().setInt32(history_item->last_visit);
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* @smjs_globhist_item_class.setProperty */
|
2020-10-12 12:43:56 -04:00
|
|
|
static bool
|
2020-10-23 16:34:58 -04:00
|
|
|
smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 15:00:37 -05:00
|
|
|
{
|
2020-10-12 12:43:56 -04:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
struct global_history_item *history_item;
|
|
|
|
|
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL))
|
|
|
|
return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
history_item = JS_GetInstancePrivate(ctx, hobj,
|
2019-02-10 15:00:37 -05:00
|
|
|
(JSClass *) &smjs_globhist_item_class,
|
|
|
|
NULL);
|
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
if (!history_item) return false;
|
2019-02-10 15:00:37 -05:00
|
|
|
|
|
|
|
/* Bug 923: Assumes time_t values fit in uint32. */
|
2020-10-16 13:54:02 -04:00
|
|
|
history_item->last_visit = args[0].toInt32();
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2020-10-12 12:43:56 -04:00
|
|
|
return true;
|
2019-02-10 15:00:37 -05:00
|
|
|
}
|