2005-09-15 15:58:31 +02:00
|
|
|
/* The SpiderMonkey document object implementation. */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "ecmascript/spidermonkey/util.h"
|
2020-10-23 22:34:58 +02:00
|
|
|
#include <jsfriendapi.h>
|
2005-09-15 15:58:31 +02:00
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "cache/cache.h"
|
|
|
|
#include "cookies/cookies.h"
|
|
|
|
#include "dialogs/menu.h"
|
|
|
|
#include "dialogs/status.h"
|
|
|
|
#include "document/html/frames.h"
|
|
|
|
#include "document/document.h"
|
|
|
|
#include "document/forms.h"
|
|
|
|
#include "document/view.h"
|
|
|
|
#include "ecmascript/ecmascript.h"
|
|
|
|
#include "ecmascript/spidermonkey/form.h"
|
|
|
|
#include "ecmascript/spidermonkey/location.h"
|
|
|
|
#include "ecmascript/spidermonkey/document.h"
|
2006-11-25 08:54:58 +02:00
|
|
|
#include "ecmascript/spidermonkey/window.h"
|
2005-09-15 15:58:31 +02:00
|
|
|
#include "intl/gettext/libintl.h"
|
|
|
|
#include "main/select.h"
|
|
|
|
#include "osdep/newwin.h"
|
|
|
|
#include "osdep/sysname.h"
|
|
|
|
#include "protocol/http/http.h"
|
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/history.h"
|
|
|
|
#include "session/location.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "session/task.h"
|
|
|
|
#include "terminal/tab.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/conv.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "viewer/text/draw.h"
|
|
|
|
#include "viewer/text/form.h"
|
|
|
|
#include "viewer/text/link.h"
|
|
|
|
#include "viewer/text/vs.h"
|
|
|
|
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2006-11-23 23:33:43 +02:00
|
|
|
/* Each @document_class object must have a @window_class parent. */
|
2019-02-10 21:00:37 +01:00
|
|
|
JSClass document_class = {
|
2005-09-15 15:58:31 +02:00
|
|
|
"document",
|
|
|
|
JSCLASS_HAS_PRIVATE,
|
2020-10-16 19:54:02 +02:00
|
|
|
JS_PropertyStub, nullptr,
|
2019-02-10 21:00:37 +01:00
|
|
|
document_get_property, JS_StrictPropertyStub,
|
2020-10-16 19:54:02 +02:00
|
|
|
nullptr, nullptr, nullptr
|
2005-09-15 15:58:31 +02:00
|
|
|
};
|
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
#ifdef CONFIG_COOKIES
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_get_property_cookie(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
2019-04-21 12:27:40 +02:00
|
|
|
struct string *cookies;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-10 21:00:37 +01:00
|
|
|
cookies = send_cookies_js(vs->uri);
|
|
|
|
|
|
|
|
if (cookies) {
|
|
|
|
static unsigned char cookiestr[1024];
|
|
|
|
|
2019-11-15 16:40:29 +01:00
|
|
|
strncpy(cookiestr, cookies->source, 1023);
|
2019-02-10 21:00:37 +01:00
|
|
|
done_string(cookies);
|
2020-10-11 15:41:27 +02:00
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, cookiestr));
|
2019-02-10 21:00:37 +01:00
|
|
|
} else {
|
2020-10-11 15:41:27 +02:00
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, ""));
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_set_property_cookie(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
2020-10-11 15:41:27 +02:00
|
|
|
struct string *cookies;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
set_cookie(vs->uri, JS_EncodeString(ctx, args[0].toString()));
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
JS_GetProperty(ctx, parent_win, "location", args.rval());
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2005-09-15 15:58:31 +02:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2006-11-24 08:50:12 +02:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2006-11-25 08:54:58 +02:00
|
|
|
|
2007-05-27 18:32:53 +03:00
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
2019-02-10 21:00:37 +01:00
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-24 08:50:12 +02:00
|
|
|
doc_view = vs->doc_view;
|
2020-10-11 15:41:27 +02:00
|
|
|
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
2005-09-15 15:58:31 +02:00
|
|
|
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_get_property_referrer(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct document *document;
|
|
|
|
struct session *ses;
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
|
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-10 21:00:37 +01:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
document = doc_view->document;
|
|
|
|
ses = doc_view->session;
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
switch (get_opt_int("protocol.http.referer.policy", NULL)) {
|
|
|
|
case REFERER_NONE:
|
|
|
|
/* oh well */
|
2020-10-11 15:41:27 +02:00
|
|
|
args.rval().setUndefined();
|
2019-02-10 21:00:37 +01:00
|
|
|
break;
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
case REFERER_FAKE:
|
2020-10-11 15:41:27 +02:00
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, get_opt_str("protocol.http.referer.fake", NULL)));
|
2006-02-01 09:31:26 +01:00
|
|
|
break;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
case REFERER_TRUE:
|
|
|
|
/* XXX: Encode as in add_url_to_httset_prop_string(&prop, ) ? --pasky */
|
|
|
|
if (ses->referrer) {
|
2020-10-11 15:41:27 +02:00
|
|
|
unsigned char *str = get_uri_string(ses->referrer, URI_HTTP_REFERRER);
|
|
|
|
|
|
|
|
if (str) {
|
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, str));
|
|
|
|
mem_free(str);
|
|
|
|
} else {
|
|
|
|
args.rval().setUndefined();
|
|
|
|
}
|
2005-09-15 15:58:31 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
case REFERER_SAME_URL:
|
2020-10-11 15:41:27 +02:00
|
|
|
unsigned char *str = get_uri_string(document->uri, URI_HTTP_REFERRER);
|
|
|
|
|
|
|
|
if (str) {
|
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, str));
|
|
|
|
mem_free(str);
|
|
|
|
} else {
|
|
|
|
args.rval().setUndefined();
|
|
|
|
}
|
2005-09-15 15:58:31 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2005-09-15 15:58:31 +02:00
|
|
|
}
|
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2005-09-15 15:58:31 +02:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct document *document;
|
|
|
|
|
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-10 21:00:37 +01:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
document = doc_view->document;
|
2020-10-11 15:41:27 +02:00
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, document->title));
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_set_property_title(JSContext *ctx, int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2006-11-24 08:50:12 +02:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct document *document;
|
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2006-11-25 08:54:58 +02:00
|
|
|
|
2007-05-27 18:32:53 +03:00
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
2019-02-10 21:00:37 +01:00
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-24 08:50:12 +02:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
document = doc_view->document;
|
2020-10-11 15:41:27 +02:00
|
|
|
mem_free_set(&document->title, stracpy(JS_EncodeString(ctx, args[0].toString())));
|
2019-02-10 21:00:37 +01:00
|
|
|
print_screen_status(doc_view->session);
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_get_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct document *document;
|
|
|
|
|
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-10 21:00:37 +01:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
document = doc_view->document;
|
2020-10-11 15:41:27 +02:00
|
|
|
unsigned char *str = get_uri_string(document->uri, URI_ORIGINAL);
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
if (str) {
|
|
|
|
args.rval().setString(JS_NewStringCopyZ(ctx, str));
|
|
|
|
mem_free(str);
|
|
|
|
} else {
|
|
|
|
args.rval().setUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_set_property_url(JSContext *ctx, int argc, JS::Value *vp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::RootedObject parent_win(ctx, js::GetGlobalForObjectCrossCompartment(hobj));
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
2020-10-11 15:41:27 +02:00
|
|
|
struct document *document;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
2020-10-11 15:41:27 +02:00
|
|
|
if (!vs) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-10 21:00:37 +01:00
|
|
|
doc_view = vs->doc_view;
|
2020-10-11 15:41:27 +02:00
|
|
|
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2019-02-10 21:00:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* "cookie" is special; it isn't a regular property but we channel it to the
|
|
|
|
* cookie-module. XXX: Would it work if "cookie" was defined in this array? */
|
|
|
|
JSPropertySpec document_props[] = {
|
2005-09-15 15:58:31 +02:00
|
|
|
#ifdef CONFIG_COOKIES
|
2020-10-11 15:41:27 +02:00
|
|
|
JS_PSGS("cookie", document_get_property_cookie, document_set_property_cookie, JSPROP_ENUMERATE),
|
2005-09-15 15:58:31 +02:00
|
|
|
#endif
|
2020-10-11 15:41:27 +02:00
|
|
|
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
|
|
|
|
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
|
|
|
|
JS_PSGS("title", document_get_property_title, document_set_property_title, JSPROP_ENUMERATE), /* TODO: Charset? */
|
|
|
|
JS_PSGS("url", document_get_property_url, document_set_property_url, JSPROP_ENUMERATE),
|
2019-02-10 21:00:37 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
2005-09-15 15:58:31 +02:00
|
|
|
|
|
|
|
|
2019-02-10 21:00:37 +01:00
|
|
|
/* @document_class.getProperty */
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-05 20:14:55 +02:00
|
|
|
document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
2019-02-10 21:00:37 +01:00
|
|
|
{
|
|
|
|
ELINKS_CAST_PROP_PARAMS
|
2020-10-05 20:14:55 +02:00
|
|
|
jsid id = hid.get();
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::RootedObject parent_win(ctx); /* instance of @window_class */
|
2019-02-10 21:00:37 +01:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct document *document;
|
|
|
|
struct form *form;
|
|
|
|
unsigned char *string;
|
|
|
|
|
|
|
|
JSClass* classPtr = JS_GetClass(obj);
|
|
|
|
|
|
|
|
if (classPtr != &document_class)
|
2020-10-11 15:41:27 +02:00
|
|
|
return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2020-10-23 22:34:58 +02:00
|
|
|
parent_win = js::GetGlobalForObjectCrossCompartment(hobj);
|
2019-02-10 21:00:37 +01:00
|
|
|
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
|
2020-10-11 15:41:27 +02:00
|
|
|
if_assert_failed return false;
|
2019-02-10 21:00:37 +01:00
|
|
|
|
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
&window_class, NULL);
|
|
|
|
doc_view = vs->doc_view;
|
|
|
|
document = doc_view->document;
|
|
|
|
string = jsid_to_string(ctx, &id);
|
|
|
|
|
|
|
|
foreach (form, document->forms) {
|
|
|
|
if (!form->name || c_strcasecmp(string, form->name))
|
|
|
|
continue;
|
|
|
|
|
2019-04-21 12:26:27 +02:00
|
|
|
object_to_jsval(ctx, vp, get_form_object(ctx, obj, find_form_view(doc_view, form)));
|
2005-09-15 15:58:31 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2005-09-15 15:58:31 +02:00
|
|
|
}
|
|
|
|
|
2020-10-23 22:34:58 +02:00
|
|
|
static bool document_write(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
|
|
|
static bool document_writeln(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2008-06-17 00:25:59 +03:00
|
|
|
const spidermonkeyFunctionSpec document_funcs[] = {
|
2005-09-15 15:58:31 +02:00
|
|
|
{ "write", document_write, 1 },
|
2006-01-27 13:29:38 +01:00
|
|
|
{ "writeln", document_writeln, 1 },
|
2005-09-15 15:58:31 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_write_do(JSContext *ctx, unsigned int argc, JS::Value *rval, int newline)
|
2005-09-15 15:58:31 +02:00
|
|
|
{
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::Value val;
|
2005-09-15 15:58:31 +02:00
|
|
|
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
2019-04-21 12:27:40 +02:00
|
|
|
struct string *ret = interpreter->ret;
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
2006-01-27 13:29:38 +01:00
|
|
|
|
|
|
|
if (argc >= 1 && ret) {
|
2006-02-12 04:33:42 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (; i < argc; ++i) {
|
2020-10-11 15:41:27 +02:00
|
|
|
unsigned char *code = jsval_to_string(ctx, args[i].address());
|
2006-02-12 04:33:42 +00:00
|
|
|
|
|
|
|
add_to_string(ret, code);
|
|
|
|
}
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2006-01-28 20:39:07 +00:00
|
|
|
if (newline)
|
|
|
|
add_char_to_string(ret, '\n');
|
2006-01-27 13:29:38 +01:00
|
|
|
}
|
2005-09-15 15:58:31 +02:00
|
|
|
/* XXX: I don't know about you, but I have *ENOUGH* of those 'Undefined
|
|
|
|
* function' errors, I want to see just the useful ones. So just
|
|
|
|
* lighting a led and going away, no muss, no fuss. --pasky */
|
|
|
|
/* TODO: Perhaps we can introduce ecmascript.error_report_unsupported
|
|
|
|
* -> "Show information about the document using some valid,
|
|
|
|
* nevertheless unsupported methods/properties." --pasky too */
|
|
|
|
|
|
|
|
#ifdef CONFIG_LEDS
|
|
|
|
set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J');
|
|
|
|
#endif
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
args.rval().setBoolean(false);
|
2005-09-15 15:58:31 +02:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return true;
|
2005-09-15 15:58:31 +02:00
|
|
|
}
|
2006-01-27 13:29:38 +01:00
|
|
|
|
2006-11-23 23:33:43 +02:00
|
|
|
/* @document_funcs{"write"} */
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_write(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
2006-01-27 13:29:38 +01:00
|
|
|
{
|
|
|
|
|
2011-04-19 22:41:05 +02:00
|
|
|
return document_write_do(ctx, argc, rval, 0);
|
2006-01-28 20:39:07 +00:00
|
|
|
}
|
2006-01-27 13:29:38 +01:00
|
|
|
|
2006-11-23 23:33:43 +02:00
|
|
|
/* @document_funcs{"writeln"} */
|
2020-10-11 15:41:27 +02:00
|
|
|
static bool
|
2020-10-23 22:34:58 +02:00
|
|
|
document_writeln(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
2006-01-28 20:39:07 +00:00
|
|
|
{
|
2011-04-19 22:41:05 +02:00
|
|
|
return document_write_do(ctx, argc, rval, 1);
|
2006-01-27 13:29:38 +01:00
|
|
|
}
|