1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[spidermonkey] window.{innerHeight,innerWidth}

This commit is contained in:
Witold Filipczyk 2024-01-28 15:14:48 +01:00
parent 7b3c450293
commit c0a3bce766

View File

@ -57,6 +57,8 @@
static bool window_get_property_closed(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_get_property_event(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_get_property_innerHeight(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_get_property_innerWidth(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_get_property_location(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_set_property_location(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_get_property_parent(JSContext *ctx, unsigned int argc, JS::Value *vp);
@ -132,6 +134,8 @@ JSClass window_class = {
JSPropertySpec window_props[] = {
JS_PSG("closed", window_get_property_closed, JSPROP_ENUMERATE),
JS_PSG("event", window_get_property_event, JSPROP_ENUMERATE),
JS_PSG("innerHeight", window_get_property_innerHeight, JSPROP_ENUMERATE),
JS_PSG("innerWidth", window_get_property_innerWidth, JSPROP_ENUMERATE),
JS_PSGS("location", window_get_property_location, window_set_property_location, JSPROP_ENUMERATE),
JS_PSG("parent", window_get_property_parent, JSPROP_ENUMERATE),
JS_PSG("self", window_get_property_self, JSPROP_ENUMERATE),
@ -809,6 +813,122 @@ window_get_property_event(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
static bool
window_get_property_innerHeight(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct view_state *vs;
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
/* 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, &window_class, NULL)) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct session *ses = doc_view->session;
if (!ses) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
args.rval().setInt32(doc_view->box.height * ses->tab->term->cell_height);
return true;
}
static bool
window_get_property_innerWidth(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct view_state *vs;
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
/* 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, &window_class, NULL)) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct session *ses = doc_view->session;
if (!ses) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
args.rval().setInt32(doc_view->box.width * ses->tab->term->cell_width);
return true;
}
static bool
window_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
{