diff --git a/src/scripting/smjs/globhist.cpp b/src/scripting/smjs/globhist.cpp index 2755e7002..19f6216bb 100644 --- a/src/scripting/smjs/globhist.cpp +++ b/src/scripting/smjs/globhist.cpp @@ -52,16 +52,6 @@ smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj) if (history_item) object_unlock(history_item); } -/* 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. */ -enum smjs_globhist_item_prop { - GLOBHIST_TITLE = -1, - GLOBHIST_URL = -2, - GLOBHIST_LAST_VISIT = -3, -}; - 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); @@ -76,126 +66,6 @@ static const JSPropertySpec smjs_globhist_item_props[] = { JS_PS_END }; -/* @smjs_globhist_item_class.getProperty */ -static bool -smjs_globhist_item_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, - JS::MutableHandleValue hvp) -{ - jsid id = hid.get(); - - 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. */ - if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) - return false; - - history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, - (JSClass *) &smjs_globhist_item_class, - NULL); - - if (!history_item) return false; - - hvp.setUndefined(); - - if (!JSID_IS_INT(id)) - return false; - - switch (JSID_TO_INT(id)) { - case GLOBHIST_TITLE: - hvp.setString(JS_NewStringCopyZ(smjs_ctx, history_item->title)); - - return true; - case GLOBHIST_URL: - hvp.setString(JS_NewStringCopyZ(smjs_ctx, history_item->url)); - - return true; - 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 */ - hvp.setInt32(history_item->last_visit); - - return true; - default: - /* Unrecognized integer property ID; someone is using - * the object as an array. SMJS builtin classes (e.g. - * js_RegExpClass) just return true in this case - * and leave *@vp unchanged. Do the same here. - * (Actually not quite the same, as we already used - * @undef_to_jsval.) */ - return true; - } -} - -/* @smjs_globhist_item_class.setProperty */ -static bool -smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) -{ - jsid id = hid.get(); - - 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. */ - if (!JS_InstanceOf(ctx, hobj, (JSClass *) &smjs_globhist_item_class, NULL)) - return false; - - history_item = (struct global_history_item *)JS_GetInstancePrivate(ctx, hobj, - (JSClass *) &smjs_globhist_item_class, - NULL); - - if (!history_item) return false; - - if (!JSID_IS_INT(id)) - return false; - - switch (JSID_TO_INT(id)) { - case GLOBHIST_TITLE: { - char *str = jsval_to_string(smjs_ctx, hvp); - - mem_free_set(&history_item->title, stracpy(str)); - - return true; - } - case GLOBHIST_URL: { - char *str = jsval_to_string(smjs_ctx, hvp); - - mem_free_set(&history_item->url, stracpy(str)); - - return true; - } - case GLOBHIST_LAST_VISIT: { - /* Bug 923: Assumes time_t values fit in uint32. */ - history_item->last_visit = hvp.toInt32(); - - return true; - } - default: - /* Unrecognized integer property ID; someone is using - * the object as an array. SMJS builtin classes (e.g. - * js_RegExpClass) just return true in this case. - * Do the same here. */ - return true; - } -} - - static JSObject * smjs_get_globhist_item_object(struct global_history_item *history_item) {