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

[mozjs31] SpiderMonkey updated to mozjs31. TODO: smjs scripting.

This commit is contained in:
Witold Filipczyk 2020-10-11 15:41:27 +02:00
parent 1f57e72212
commit dd704b900a
13 changed files with 1592 additions and 1550 deletions

View File

@ -612,11 +612,11 @@ case "$with_spidermonkey" in
;;
esac
for package in mozjs-24; do
for package in mozjs-31; do
if test -n "$CONFIG_SPIDERMONKEY"; then
break
else
AC_MSG_CHECKING([for SpiderMonkey (mozjs-24) in pkg-config $package])
AC_MSG_CHECKING([for SpiderMonkey (mozjs-31) in pkg-config $package])
if $PKG_CONFIG --cflags --libs $package > /dev/null 2>&AS_MESSAGE_LOG_FD; then
SPIDERMONKEY_LIBS="$($PKG_CONFIG --libs $package)"
SPIDERMONKEY_CFLAGS="$($PKG_CONFIG --cflags $package)"

View File

@ -44,6 +44,10 @@ spidermonkey_runtime_addref(void)
assert(spidermonkey_empty_context == NULL);
if_assert_failed return 0;
if (!JS_Init()) {
return 0;
}
spidermonkey_runtime = JS_NewRuntime(4L * 1024L * 1024L, JS_USE_HELPER_THREADS);
if (!spidermonkey_runtime) return 0;
@ -92,16 +96,17 @@ spidermonkey_runtime_release(void)
/** An ELinks-specific replacement for JS_DefineFunctions().
*
* @relates spidermonkeyFunctionSpec */
JSBool
bool
spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
const spidermonkeyFunctionSpec *fs)
{
JS::RootedObject hobj(cx, obj);
for (; fs->name; fs++) {
if (!JS_DefineFunction(cx, obj, fs->name, fs->call,
if (!JS_DefineFunction(cx, hobj, fs->name, fs->call,
fs->nargs, 0))
return JS_FALSE;
return false;
}
return JS_TRUE;
return true;
}
/** An ELinks-specific replacement for JS_InitClass().
@ -116,7 +121,9 @@ spidermonkey_InitClass(JSContext *cx, JSObject *obj,
JSPropertySpec *static_ps,
const spidermonkeyFunctionSpec *static_fs)
{
JSObject *proto = JS_InitClass(cx, obj, parent_proto, clasp,
JS::RootedObject hobj(cx, obj);
JS::RootedObject r_parent_proto(cx, parent_proto);
JSObject *proto = JS_InitClass(cx, hobj, r_parent_proto, clasp,
constructor, nargs,
ps, NULL, static_ps, NULL);
@ -129,7 +136,8 @@ spidermonkey_InitClass(JSContext *cx, JSObject *obj,
}
if (static_fs) {
JSObject *cons_obj = JS_GetConstructor(cx, proto);
JS::RootedObject r_proto(cx, proto);
JSObject *cons_obj = JS_GetConstructor(cx, r_proto);
if (cons_obj == NULL)
return NULL;

View File

@ -43,7 +43,7 @@ typedef struct spidermonkeyFunctionSpec {
/* ELinks does not use "flags" and "extra" so omit them here. */
} spidermonkeyFunctionSpec;
JSBool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
bool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
const spidermonkeyFunctionSpec *fs);
JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
JSObject *parent_proto, JSClass *clasp,
@ -68,23 +68,20 @@ undef_to_jsval(JSContext *ctx, jsval *vp)
static inline unsigned char *
jsval_to_string(JSContext *ctx, jsval *vp)
{
jsval val;
JS::RootedValue r_vp(ctx, *vp);
JSString *str = JS::ToString(ctx, r_vp);
if (JS_ConvertValue(ctx, *vp, JSTYPE_STRING, &val) == JS_FALSE) {
return "";
}
return empty_string_or_(JS_EncodeString(ctx, JS_ValueToString(ctx, val)));
return empty_string_or_(JS_EncodeString(ctx, str));
}
static inline unsigned char *
jsid_to_string(JSContext *ctx, jsid *id)
{
jsval v;
JS::RootedValue v(ctx);
/* TODO: check returned value */
JS_IdToValue(ctx, *id, &v);
return jsval_to_string(ctx, &v);
return jsval_to_string(ctx, v.address());
}
#define ELINKS_CAST_PROP_PARAMS JSObject *obj = (hobj.get()); \

View File

@ -50,8 +50,6 @@
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
using namespace JS;
/*** Global methods */
@ -143,11 +141,10 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
interpreter->backend_data = ctx;
JSAutoRequest ar(ctx);
JS_SetContextPrivate(ctx, interpreter);
JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JS_METHODJIT);
//JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JS_METHODJIT);
JS_SetErrorReporter(ctx, error_reporter);
JS_SetOperationCallback(ctx, heartbeat_callback);
RootedObject window_obj(ctx);
window_obj = JS_NewGlobalObject(ctx, &window_class, NULL);
JS_SetInterruptCallback(spidermonkey_runtime, heartbeat_callback);
JS::RootedObject window_obj(ctx, JS_NewGlobalObject(ctx, &window_class, NULL, JS::DontFireOnNewGlobalHook));
if (window_obj) {
ac = new JSAutoCompartment(ctx, window_obj);
@ -204,7 +201,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
goto release_and_fail;
}
menubar_obj = JS_InitClass(ctx, window_obj, NULL,
menubar_obj = JS_InitClass(ctx, window_obj, JS::NullPtr(),
&menubar_class, NULL, 0,
unibar_props, NULL,
NULL, NULL);
@ -213,7 +210,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
}
JS_SetPrivate(menubar_obj, "t"); /* to @menubar_class */
statusbar_obj = JS_InitClass(ctx, window_obj, NULL,
statusbar_obj = JS_InitClass(ctx, window_obj, JS::NullPtr(),
&statusbar_class, NULL, 0,
unibar_props, NULL,
NULL, NULL);
@ -222,7 +219,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
}
JS_SetPrivate(statusbar_obj, "s"); /* to @statusbar_class */
navigator_obj = JS_InitClass(ctx, window_obj, NULL,
navigator_obj = JS_InitClass(ctx, window_obj, JS::NullPtr(),
&navigator_class, NULL, 0,
navigator_props, NULL,
NULL, NULL);
@ -266,8 +263,10 @@ spidermonkey_eval(struct ecmascript_interpreter *interpreter,
interpreter->heartbeat = add_heartbeat(interpreter);
interpreter->ret = ret;
JS_EvaluateScript(ctx, JS_GetGlobalForScopeChain(ctx),
code->source, code->length, "", 0, &rval);
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
JS::RootedValue r_val(ctx, rval);
JS_EvaluateScript(ctx, cg, code->source, code->length, "", 0, &r_val);
done_heartbeat(interpreter->heartbeat);
}
@ -276,7 +275,7 @@ unsigned char *
spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
JSBool ret;
bool ret;
JSContext *ctx;
jsval rval;
@ -286,19 +285,20 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
interpreter->ret = NULL;
interpreter->heartbeat = add_heartbeat(interpreter);
ret = JS_EvaluateScript(ctx, JS_GetGlobalForScopeChain(ctx),
code->source, code->length, "", 0, &rval);
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
JS::RootedValue r_rval(ctx, rval);
ret = JS_EvaluateScript(ctx, cg, code->source, code->length, "", 0, &r_rval);
done_heartbeat(interpreter->heartbeat);
if (ret == JS_FALSE) {
if (ret == false) {
return NULL;
}
if (JSVAL_IS_VOID(rval) || JSVAL_IS_NULL(rval)) {
if (r_rval.isNullOrUndefined()) {
/* Undefined value. */
return NULL;
}
return stracpy(jsval_to_string(ctx, &rval));
return stracpy(JS_EncodeString(ctx, JS::ToString(ctx, r_rval)));
}
@ -316,19 +316,23 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
ctx = interpreter->backend_data;
interpreter->ret = NULL;
fun = JS_CompileFunction(ctx, JS_GetGlobalForScopeChain(ctx), "", 0, NULL, code->source,
code->length, "", 0);
JS::CompileOptions options(ctx);
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
fun = JS_CompileFunction(ctx, cg, "", 0, NULL, code->source,
code->length, options);
if (!fun)
return -1;
interpreter->heartbeat = add_heartbeat(interpreter);
ret = JS_CallFunction(ctx, JS_GetGlobalForScopeChain(ctx), fun, 0, NULL, &rval);
JS::RootedFunction r_fun(ctx, fun);
JS::RootedValue r_val(ctx, rval);
ret = JS_CallFunction(ctx, cg, r_fun, JS::HandleValueArray::empty(), &r_val);
done_heartbeat(interpreter->heartbeat);
if (ret == 2) { /* onClick="history.back()" */
return 0;
}
if (ret == JS_FALSE) {
if (ret == false) {
return -1;
}
if (JSVAL_IS_VOID(rval)) {

View File

@ -47,7 +47,7 @@
#include "viewer/text/vs.h"
static JSBool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
/* Each @document_class object must have a @window_class parent. */
JSClass document_class = {
@ -59,25 +59,23 @@ JSClass document_class = {
};
#ifdef CONFIG_COOKIES
static JSBool
document_get_property_cookie(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
document_get_property_cookie(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct string *cookies;
JSClass* classPtr = JS_GetClass(obj);
if (classPtr != &document_class)
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
cookies = send_cookies_js(vs->uri);
if (cookies) {
@ -85,110 +83,98 @@ document_get_property_cookie(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
strncpy(cookiestr, cookies->source, 1023);
done_string(cookies);
string_to_jsval(ctx, vp, cookiestr);
args.rval().setString(JS_NewStringCopyZ(ctx, cookiestr));
} else {
string_to_jsval(ctx, vp, "");
args.rval().setString(JS_NewStringCopyZ(ctx, ""));
}
return JS_TRUE;
return true;
}
static JSBool
document_set_property_cookie(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
static bool
document_set_property_cookie(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct string *cookies;
/* 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, obj, &document_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
parent_win = JS_GetParent(hobj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
set_cookie(vs->uri, jsval_to_string(ctx, vp));
if (!vs) {
return false;
}
set_cookie(vs->uri, JS_EncodeString(ctx, args[0].toString()));
return JS_TRUE;
return true;
}
#endif
static JSBool
document_get_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
document_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());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
JSObject *parent_win; /* instance of @window_class */
JSClass* classPtr = JS_GetClass(obj);
if (classPtr != &document_class)
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
JS_GetProperty(ctx, parent_win, "location", vp);
JS_GetProperty(ctx, parent_win, "location", args.rval());
return JS_TRUE;
return true;
}
static JSBool
document_set_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
static bool
document_set_property_location(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct document_view *doc_view;
/* 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, obj, &document_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
location_goto(doc_view, jsval_to_string(ctx, vp));
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
return JS_TRUE;
return true;
}
static JSBool
document_get_property_referrer(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
document_get_property_referrer(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
struct session *ses;
JSClass* classPtr = JS_GetClass(obj);
if (classPtr != &document_class)
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
document = doc_view->document;
ses = doc_view->session;
@ -196,138 +182,148 @@ document_get_property_referrer(JSContext *ctx, JS::HandleObject hobj, JS::Handle
switch (get_opt_int("protocol.http.referer.policy", NULL)) {
case REFERER_NONE:
/* oh well */
undef_to_jsval(ctx, vp);
args.rval().setUndefined();
break;
case REFERER_FAKE:
string_to_jsval(ctx, vp, get_opt_str("protocol.http.referer.fake", NULL));
args.rval().setString(JS_NewStringCopyZ(ctx, get_opt_str("protocol.http.referer.fake", NULL)));
break;
case REFERER_TRUE:
/* XXX: Encode as in add_url_to_httset_prop_string(&prop, ) ? --pasky */
if (ses->referrer) {
astring_to_jsval(ctx, vp, get_uri_string(ses->referrer, URI_HTTP_REFERRER));
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();
}
}
break;
case REFERER_SAME_URL:
astring_to_jsval(ctx, vp, get_uri_string(document->uri, URI_HTTP_REFERRER));
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();
}
break;
}
return JS_TRUE;
return true;
}
static JSBool
document_get_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
document_get_property_title(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
JSClass* classPtr = JS_GetClass(obj);
if (classPtr != &document_class)
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
doc_view = vs->doc_view;
document = doc_view->document;
string_to_jsval(ctx, vp, document->title);
return JS_TRUE;
}
static JSBool
document_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
/* 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, obj, &document_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
document = doc_view->document;
mem_free_set(&document->title, stracpy(jsval_to_string(ctx, vp)));
args.rval().setString(JS_NewStringCopyZ(ctx, document->title));
return true;
}
static bool
document_set_property_title(JSContext *ctx, int argc, jsval *vp)
{
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
document = doc_view->document;
mem_free_set(&document->title, stracpy(JS_EncodeString(ctx, args[0].toString())));
print_screen_status(doc_view->session);
return JS_TRUE;
return true;
}
static JSBool
document_get_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
document_get_property_url(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
JSClass* classPtr = JS_GetClass(obj);
if (classPtr != &document_class)
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
document = doc_view->document;
astring_to_jsval(ctx, vp, get_uri_string(document->uri, URI_ORIGINAL));
unsigned char *str = get_uri_string(document->uri, URI_ORIGINAL);
return JS_TRUE;
if (str) {
args.rval().setString(JS_NewStringCopyZ(ctx, str));
mem_free(str);
} else {
args.rval().setUndefined();
}
return true;
}
static JSBool
document_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
static bool
document_set_property_url(JSContext *ctx, int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
/* 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, obj, &document_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
location_goto(doc_view, jsval_to_string(ctx, vp));
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
return JS_TRUE;
return true;
}
@ -335,24 +331,24 @@ document_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hi
* cookie-module. XXX: Would it work if "cookie" was defined in this array? */
JSPropertySpec document_props[] = {
#ifdef CONFIG_COOKIES
{ "cookie", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_cookie), JSOP_WRAPPER(document_set_property_cookie) },
JS_PSGS("cookie", document_get_property_cookie, document_set_property_cookie, JSPROP_ENUMERATE),
#endif
{ "location", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_location), JSOP_WRAPPER(document_set_property_location) },
{ "referrer", 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_referrer), JSOP_NULLWRAPPER },
{ "title", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_title), JSOP_WRAPPER(document_set_property_title) }, /* TODO: Charset? */
{ "url", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_url), JSOP_WRAPPER(document_set_property_url) },
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),
{ NULL }
};
/* @document_class.getProperty */
static JSBool
static bool
document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
{
ELINKS_CAST_PROP_PARAMS
jsid id = hid.get();
JSObject *parent_win; /* instance of @window_class */
JS::RootedObject parent_win(ctx); /* instance of @window_class */
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
@ -362,11 +358,11 @@ document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, J
JSClass* classPtr = JS_GetClass(obj);
if (classPtr != &document_class)
return JS_FALSE;
return false;
parent_win = JS_GetParent(obj);
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
@ -382,11 +378,11 @@ document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, J
break;
}
return JS_TRUE;
return true;
}
static JSBool document_write(JSContext *ctx, unsigned int argc, jsval *rval);
static JSBool document_writeln(JSContext *ctx, unsigned int argc, jsval *rval);
static bool document_write(JSContext *ctx, unsigned int argc, jsval *rval);
static bool document_writeln(JSContext *ctx, unsigned int argc, jsval *rval);
const spidermonkeyFunctionSpec document_funcs[] = {
{ "write", document_write, 1 },
@ -394,19 +390,19 @@ const spidermonkeyFunctionSpec document_funcs[] = {
{ NULL }
};
static JSBool
static bool
document_write_do(JSContext *ctx, unsigned int argc, jsval *rval, int newline)
{
jsval val;
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct string *ret = interpreter->ret;
jsval *argv = JS_ARGV(ctx, rval);
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
if (argc >= 1 && ret) {
int i = 0;
for (; i < argc; ++i) {
unsigned char *code = jsval_to_string(ctx, &argv[i]);
unsigned char *code = jsval_to_string(ctx, args[i].address());
add_to_string(ret, code);
}
@ -425,14 +421,13 @@ document_write_do(JSContext *ctx, unsigned int argc, jsval *rval, int newline)
set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J');
#endif
boolean_to_jsval(ctx, &val, 0);
JS_SET_RVAL(ctx, rval, val);
args.rval().setBoolean(false);
return JS_TRUE;
return true;
}
/* @document_funcs{"write"} */
static JSBool
static bool
document_write(JSContext *ctx, unsigned int argc, jsval *rval)
{
@ -440,7 +435,7 @@ document_write(JSContext *ctx, unsigned int argc, jsval *rval)
}
/* @document_funcs{"writeln"} */
static JSBool
static bool
document_writeln(JSContext *ctx, unsigned int argc, jsval *rval)
{
return document_write_do(ctx, argc, rval, 1);

File diff suppressed because it is too large Load Diff

View File

@ -30,17 +30,17 @@ static INIT_LIST_OF(struct heartbeat, heartbeats);
static struct itimerval heartbeat_timer = { { 1, 0 }, { 1, 0 } };
/* This callback is installed by JS_SetOperationCallback and triggered
* by JS_TriggerOperationCallback in the heartbeat code below. Returning
* JS_FALSE terminates script execution immediately. */
JSBool
/* This callback is installed by JS_SetInterruptCallback and triggered
* by JS_RequestInterruptCallback in the heartbeat code below. Returning
* false terminates script execution immediately. */
bool
heartbeat_callback(JSContext *ctx)
{
return JS_FALSE;
return false;
}
/* Callback for SIGVTALRM. Go through all heartbeats, decrease each
* one's TTL, and call JS_TriggerOperationCallback if a heartbeat's TTL
* one's TTL, and call JS_RequestInterruptCallback if a heartbeat's TTL
* goes to 0. */
static void
check_heartbeats(void *data)
@ -63,7 +63,7 @@ check_heartbeats(void *data)
ecmascript_timeout_dialog(term, max_exec_time);
}
JS_TriggerOperationCallback(JS_GetRuntime(hb->interpreter->backend_data));
JS_RequestInterruptCallback(JS_GetRuntime(hb->interpreter->backend_data));
}
}
install_signal_handler(SIGVTALRM, check_heartbeats, NULL, 1);

View File

@ -19,6 +19,6 @@ struct heartbeat {
struct heartbeat *add_heartbeat(struct ecmascript_interpreter *interpreter);
void done_heartbeat(struct heartbeat *hb);
JSBool heartbeat_callback(JSContext *ctx);
bool heartbeat_callback(JSContext *ctx);
#endif

View File

@ -45,9 +45,9 @@
#include "viewer/text/vs.h"
static JSBool history_back(JSContext *ctx, unsigned int argc, jsval *rval);
static JSBool history_forward(JSContext *ctx, unsigned int argc, jsval *rval);
static JSBool history_go(JSContext *ctx, unsigned int argc, jsval *rval);
static bool history_back(JSContext *ctx, unsigned int argc, jsval *rval);
static bool history_forward(JSContext *ctx, unsigned int argc, jsval *rval);
static bool history_go(JSContext *ctx, unsigned int argc, jsval *rval);
JSClass history_class = {
"history",
@ -65,12 +65,13 @@ const spidermonkeyFunctionSpec history_funcs[] = {
};
/* @history_funcs{"back"} */
static JSBool
static bool
history_back(JSContext *ctx, unsigned int argc, jsval *rval)
{
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
go_back(ses);
@ -78,39 +79,42 @@ history_back(JSContext *ctx, unsigned int argc, jsval *rval)
* and return non zero for <a href="javascript:history.back()"> to prevent
* "calculating" new link. Returned value 2 is changed to 0 in function
* spidermonkey_eval_boolback */
JS_SET_RVAL(ctx, rval, JSVAL_NULL);
args.rval().setNull();
return 2;
}
/* @history_funcs{"forward"} */
static JSBool
static bool
history_forward(JSContext *ctx, unsigned int argc, jsval *rval)
{
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
go_unback(ses);
JS_SET_RVAL(ctx, rval, JSVAL_NULL);
args.rval().setNull();
return 2;
}
/* @history_funcs{"go"} */
static JSBool
static bool
history_go(JSContext *ctx, unsigned int argc, jsval *rval)
{
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
jsval *argv = JS_ARGV(ctx, rval);
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
// jsval *argv = JS_ARGV(ctx, rval);
int index;
struct location *loc;
if (argc != 1)
return JS_TRUE;
return true;
index = atol(jsval_to_string(ctx, &argv[0]));
index = atol(jsval_to_string(ctx, args[0].address()));
for (loc = cur_loc(ses);
loc != (struct location *) &ses->history.history;
@ -123,13 +127,13 @@ history_go(JSContext *ctx, unsigned int argc, jsval *rval)
index += index > 0 ? -1 : 1;
}
JS_SET_RVAL(ctx, rval, JSVAL_NULL);
args.rval().setNull();
return 2;
}
static JSBool location_get_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool location_set_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
static bool location_get_property_href(JSContext *ctx, unsigned int argc, jsval *vp);
static bool location_set_property_href(JSContext *ctx, unsigned int argc, jsval *vp);
/* Each @location_class object must have a @window_class parent. */
JSClass location_class = {
@ -148,63 +152,79 @@ enum location_prop {
JSP_LOC_HREF = -1,
};
JSPropertySpec location_props[] = {
{ "href", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(location_get_property_href), JSOP_WRAPPER(location_set_property_href) },
JS_PSGS("href", location_get_property_href, location_set_property_href, JSPROP_ENUMERATE),
{ NULL }
};
static JSBool
location_get_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
location_get_property_href(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 *parent_win; /* instance of @window_class */
struct view_state *vs;
/* 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, obj, &location_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
if (!JS_InstanceOf(ctx, hobj, &location_class, NULL))
return false;
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
astring_to_jsval(ctx, vp, get_uri_string(vs->uri, URI_ORIGINAL));
unsigned char *str = get_uri_string(vs->uri, URI_ORIGINAL);
return JS_TRUE;
if (!str) {
return false;
}
args.rval().setString(JS_NewStringCopyZ(ctx, str));
mem_free(str);
return true;
}
static JSBool
location_set_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
static bool
location_set_property_href(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JSObject *parent_win; /* instance of @window_class */
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct view_state *vs;
struct document_view *doc_view;
/* 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, obj, &location_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
if (!JS_InstanceOf(ctx, hobj, &location_class, NULL))
return false;
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return;
}
doc_view = vs->doc_view;
location_goto(doc_view, jsval_to_string(ctx, vp));
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
return JS_TRUE;
return true;
}
static JSBool location_toString(JSContext *ctx, unsigned int argc, jsval *rval);
static bool location_toString(JSContext *ctx, unsigned int argc, jsval *rval);
const spidermonkeyFunctionSpec location_funcs[] = {
{ "toString", location_toString, 0 },
@ -213,14 +233,17 @@ const spidermonkeyFunctionSpec location_funcs[] = {
};
/* @location_funcs{"toString"}, @location_funcs{"toLocaleString"} */
static JSBool
static bool
location_toString(JSContext *ctx, unsigned int argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
JSBool ret = JS_GetProperty(ctx, obj, "href", &val);
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
JS::RootedObject hobj(ctx, obj);
JS::RootedValue r_val(ctx, val);
bool ret = JS_GetProperty(ctx, hobj, "href", &r_val);
JS_SET_RVAL(ctx, rval, val);
args.rval().set(val);
return ret;
}

View File

@ -44,12 +44,12 @@
#include "viewer/text/vs.h"
static JSBool navigator_get_property_appCodeName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool navigator_get_property_appName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool navigator_get_property_appVersion(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool navigator_get_property_language(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool navigator_get_property_platform(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool navigator_get_property_userAgent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool navigator_get_property_appCodeName(JSContext *ctx, unsigned int argc, jsval *vp);
static bool navigator_get_property_appName(JSContext *ctx, unsigned int argc, jsval *vp);
static bool navigator_get_property_appVersion(JSContext *ctx, unsigned int argc, jsval *vp);
static bool navigator_get_property_language(JSContext *ctx, unsigned int argc, jsval *vp);
static bool navigator_get_property_platform(JSContext *ctx, unsigned int argc, jsval *vp);
static bool navigator_get_property_userAgent(JSContext *ctx, unsigned int argc, jsval *vp);
JSClass navigator_class = {
"navigator",
@ -74,83 +74,76 @@ enum navigator_prop {
JSP_NAVIGATOR_USER_AGENT = -8,
};
JSPropertySpec navigator_props[] = {
{ "appCodeName",0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_appCodeName), JSOP_NULLWRAPPER },
{ "appName", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_appName), JSOP_NULLWRAPPER },
{ "appVersion", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_appVersion), JSOP_NULLWRAPPER },
{ "language", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_language), JSOP_NULLWRAPPER },
{ "platform", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_platform), JSOP_NULLWRAPPER },
{ "userAgent", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_userAgent), JSOP_NULLWRAPPER },
JS_PSG("appCodeName", navigator_get_property_appCodeName, JSPROP_ENUMERATE),
JS_PSG("appName", navigator_get_property_appName, JSPROP_ENUMERATE),
JS_PSG("appVersion", navigator_get_property_appVersion, JSPROP_ENUMERATE),
JS_PSG("language", navigator_get_property_language, JSPROP_ENUMERATE),
JS_PSG("platform", navigator_get_property_platform, JSPROP_ENUMERATE),
JS_PSG("userAgent", navigator_get_property_userAgent, JSPROP_ENUMERATE),
{ NULL }
};
/* @navigator_class.getProperty */
static JSBool
navigator_get_property_appCodeName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
navigator_get_property_appCodeName(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
(void)obj;
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setString(JS_NewStringCopyZ(ctx, "Mozilla")); /* More like a constant nowadays. */
string_to_jsval(ctx, vp, "Mozilla"); /* More like a constant nowadays. */
return JS_TRUE;
return true;
}
static JSBool
navigator_get_property_appName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
navigator_get_property_appName(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
(void)obj;
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setString(JS_NewStringCopyZ(ctx,
"ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)"));
string_to_jsval(ctx, vp, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
return JS_TRUE;
return true;
}
static JSBool
navigator_get_property_appVersion(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
navigator_get_property_appVersion(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
(void)obj;
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setString(JS_NewStringCopyZ(ctx, VERSION));
string_to_jsval(ctx, vp, VERSION);
return JS_TRUE;
return true;
}
static JSBool
navigator_get_property_language(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
navigator_get_property_language(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
(void)obj;
JS::CallArgs args = CallArgsFromVp(argc, vp);
undef_to_jsval(ctx, vp);
#ifdef CONFIG_NLS
if (get_opt_bool("protocol.http.accept_ui_language", NULL))
string_to_jsval(ctx, vp, language_to_iso639(current_language));
if (get_opt_bool("protocol.http.accept_ui_language", NULL)) {
args.rval().setString(JS_NewStringCopyZ(ctx, language_to_iso639(current_language)));
return true;
}
#endif
return JS_TRUE;
args.rval().setUndefined();
return true;
}
static JSBool
navigator_get_property_platform(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
navigator_get_property_platform(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
(void)obj;
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setString(JS_NewStringCopyZ(ctx, system_name));
string_to_jsval(ctx, vp, system_name);
return JS_TRUE;
return true;
}
static JSBool
navigator_get_property_userAgent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
navigator_get_property_userAgent(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JS::CallArgs args = CallArgsFromVp(argc, vp);
unsigned char *optstr;
(void)obj;
optstr = get_opt_str("protocol.http.user_agent", NULL);
@ -173,12 +166,12 @@ navigator_get_property_userAgent(JSContext *ctx, JS::HandleObject hobj, JS::Hand
if (ustr) {
safe_strncpy(custr, ustr, 256);
mem_free(ustr);
string_to_jsval(ctx, vp, custr);
args.rval().setString(JS_NewStringCopyZ(ctx, custr));
return JS_TRUE;
return true;
}
}
string_to_jsval(ctx, vp, system_name);
args.rval().setString(JS_NewStringCopyZ(ctx, system_name));
return JS_TRUE;
return true;
}

View File

@ -44,8 +44,8 @@
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
static JSBool unibar_get_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool unibar_set_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
static bool unibar_get_property_visible(JSContext *ctx, unsigned int argc, jsval *vp);
static bool unibar_set_property_visible(JSContext *ctx, unsigned int argc, jsval *vp);
/* Each @menubar_class object must have a @window_class parent. */
JSClass menubar_class = {
@ -72,18 +72,18 @@ enum unibar_prop {
JSP_UNIBAR_VISIBLE = -1,
};
JSPropertySpec unibar_props[] = {
{ "visible", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(unibar_get_property_visible), JSOP_WRAPPER(unibar_set_property_visible) },
JS_PSGS("visible", unibar_get_property_visible, unibar_set_property_visible, JSPROP_ENUMERATE),
{ NULL }
};
static JSBool
unibar_get_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
unibar_get_property_visible(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 *parent_win; /* instance of @window_class */
struct view_state *vs;
struct document_view *doc_view;
struct session_status *status;
@ -92,45 +92,49 @@ unibar_get_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
/* This can be called if @obj if not itself an instance of either
* appropriate class but has one in its prototype chain. Fail
* such calls. */
if (!JS_InstanceOf(ctx, obj, &menubar_class, NULL)
&& !JS_InstanceOf(ctx, obj, &statusbar_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
if (!JS_InstanceOf(ctx, hobj, &menubar_class, NULL)
&& !JS_InstanceOf(ctx, hobj, &statusbar_class, NULL))
return false;
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
status = &doc_view->session->status;
bar = JS_GetPrivate(obj); /* from @menubar_class or @statusbar_class */
bar = JS_GetPrivate(hobj); /* from @menubar_class or @statusbar_class */
#define unibar_fetch(bar) \
boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
status->force_show_##bar##_bar >= 0 \
? status->force_show_##bar##_bar \
: status->show_##bar##_bar)
: status->show_##bar##_bar
switch (*bar) {
case 's':
unibar_fetch(status);
args.rval().setBoolean(unibar_fetch(status));
break;
case 't':
unibar_fetch(title);
args.rval().setBoolean(unibar_fetch(title));
break;
default:
boolean_to_jsval(ctx, vp, 0);
args.rval().setBoolean(false);
break;
}
#undef unibar_fetch
return JS_TRUE;
return true;
}
static JSBool
unibar_set_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
static bool
unibar_set_property_visible(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 *parent_win; /* instance of @window_class */
struct view_state *vs;
struct document_view *doc_view;
struct session_status *status;
@ -139,30 +143,34 @@ unibar_set_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
/* This can be called if @obj if not itself an instance of either
* appropriate class but has one in its prototype chain. Fail
* such calls. */
if (!JS_InstanceOf(ctx, obj, &menubar_class, NULL)
&& !JS_InstanceOf(ctx, obj, &statusbar_class, NULL))
return JS_FALSE;
parent_win = JS_GetParent(obj);
if (!JS_InstanceOf(ctx, hobj, &menubar_class, NULL)
&& !JS_InstanceOf(ctx, hobj, &statusbar_class, NULL))
return false;
JS::RootedObject parent_win(ctx, JS_GetParent(hobj));
assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL));
if_assert_failed return JS_FALSE;
if_assert_failed return false;
vs = JS_GetInstancePrivate(ctx, parent_win,
&window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
status = &doc_view->session->status;
bar = JS_GetPrivate(obj); /* from @menubar_class or @statusbar_class */
bar = JS_GetPrivate(hobj); /* from @menubar_class or @statusbar_class */
switch (*bar) {
case 's':
status->force_show_status_bar = jsval_to_boolean(ctx, vp);
status->force_show_status_bar = args[0].toBoolean();
break;
case 't':
status->force_show_title_bar = jsval_to_boolean(ctx, vp);
status->force_show_title_bar = args[0].toBoolean();
break;
default:
break;
}
register_bottom_half(update_status, NULL);
return JS_TRUE;
return true;
}

View File

@ -56,25 +56,8 @@ boolean_to_jsval(JSContext *ctx, jsval *vp, int boolean)
static inline int
jsval_to_boolean(JSContext *ctx, jsval *vp)
{
jsval val;
if (JS_ConvertValue(ctx, *vp, JSTYPE_BOOLEAN, &val) == JS_FALSE) {
return JS_FALSE;
}
return JSVAL_TO_BOOLEAN(val);
}
static inline JSObject *
jsval_to_object(JSContext *ctx, jsval *vp)
{
jsval val;
if (JS_ConvertValue(ctx, *vp, JSTYPE_OBJECT, &val) == JS_FALSE) {
return NULL;
}
return JSVAL_TO_OBJECT(val);
JS::RootedValue r_vp(ctx, *vp);
return (int)JS::ToBoolean(r_vp);
}
#endif

View File

@ -44,14 +44,13 @@
#include "viewer/text/vs.h"
static JSBool window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool window_get_property_parent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool window_get_property_self(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool window_get_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool window_set_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp);
static JSBool window_get_property_top(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static JSBool window_get_property_window(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static bool window_get_property_closed(JSContext *cx, unsigned int argc, jsval *vp);
static bool window_get_property_parent(JSContext *ctx, unsigned int argc, jsval *vp);
static bool window_get_property_self(JSContext *ctx, unsigned int argc, jsval *vp);
static bool window_get_property_status(JSContext *ctx, unsigned int argc, jsval *vp);
static bool window_set_property_status(JSContext *ctx, unsigned int argc, jsval *vp);
static bool window_get_property_top(JSContext *ctx, unsigned int argc, jsval *vp);
JSClass window_class = {
"window",
@ -80,12 +79,12 @@ enum window_prop {
* assigning to it once), instead we do just a little string
* comparing. */
JSPropertySpec window_props[] = {
{ "closed", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_closed), JSOP_NULLWRAPPER },
{ "parent", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_parent), JSOP_NULLWRAPPER },
{ "self", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_self), JSOP_NULLWRAPPER },
{ "status", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_status), JSOP_WRAPPER(window_set_property_status) },
{ "top", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_top), JSOP_NULLWRAPPER },
{ "window", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_window), JSOP_NULLWRAPPER },
JS_PSG("closed", window_get_property_closed, JSPROP_ENUMERATE),
JS_PSG("parent", window_get_property_parent, JSPROP_ENUMERATE),
JS_PSG("self", window_get_property_self, JSPROP_ENUMERATE),
JS_PSGS("status", window_get_property_status, window_set_property_status, 0),
JS_PSG("top", window_get_property_top, JSPROP_ENUMERATE),
JS_PSG("window", window_get_property_self, JSPROP_ENUMERATE),
{ NULL }
};
@ -102,7 +101,7 @@ try_resolve_frame(struct document_view *doc_view, unsigned char *id)
if (target->vs.ecmascript_fragile)
ecmascript_reset_state(&target->vs);
if (!target->vs.ecmascript) return NULL;
return JS_GetGlobalForScopeChain(target->vs.ecmascript->backend_data);
return JS::CurrentGlobalOrNull(target->vs.ecmascript->backend_data);
}
#if 0
@ -127,7 +126,7 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
#endif
/* @window_class.getProperty */
static JSBool
static bool
window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
{
ELINKS_CAST_PROP_PARAMS
@ -138,10 +137,10 @@ window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
/* 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, obj, &window_class, NULL))
return JS_FALSE;
if (!JS_InstanceOf(ctx, hobj, &window_class, NULL))
return false;
vs = JS_GetInstancePrivate(ctx, obj, &window_class, NULL);
vs = JS_GetInstancePrivate(ctx, hobj, &window_class, NULL);
/* No need for special window.location measurements - when
* location is then evaluated in string context, toString()
@ -155,11 +154,11 @@ window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
if (obj) {
object_to_jsval(ctx, vp, obj);
}
return JS_TRUE;
return true;
}
if (!JSID_IS_INT(id))
return JS_TRUE;
return true;
undef_to_jsval(ctx, vp);
@ -216,7 +215,7 @@ found_parent:
}
#endif
case JSP_WIN_STATUS:
return JS_FALSE;
return false;
case JSP_WIN_TOP:
{
struct document_view *doc_view = vs->doc_view;
@ -228,7 +227,7 @@ found_parent:
ecmascript_reset_state(top_view->vs);
if (!top_view->vs->ecmascript)
break;
newjsframe = JS_GetGlobalForScopeChain(top_view->vs->ecmascript->backend_data);
newjsframe = JS::CurrentGlobalOrNull(top_view->vs->ecmascript->backend_data);
/* Keep this unrolled this way. Will have to check document.domain
* JS property. */
@ -247,21 +246,21 @@ found_parent:
default:
/* Unrecognized integer property ID; someone is using
* 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.
* (Actually not quite the same, as we already used
* @undef_to_jsval.) */
break;
}
return JS_TRUE;
return true;
}
void location_goto(struct document_view *doc_view, unsigned char *url);
static JSBool window_alert(JSContext *ctx, unsigned int argc, jsval *rval);
static JSBool window_open(JSContext *ctx, unsigned int argc, jsval *rval);
static JSBool window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval);
static bool window_alert(JSContext *ctx, unsigned int argc, jsval *rval);
static bool window_open(JSContext *ctx, unsigned int argc, jsval *rval);
static bool window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval);
const spidermonkeyFunctionSpec window_funcs[] = {
{ "alert", window_alert, 1 },
@ -271,41 +270,44 @@ const spidermonkeyFunctionSpec window_funcs[] = {
};
/* @window_funcs{"alert"} */
static JSBool
static bool
window_alert(JSContext *ctx, unsigned int argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
JS::RootedObject hobj(ctx, obj);
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
// jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
unsigned char *string;
if (!JS_InstanceOf(ctx, obj, &window_class, argv)) return JS_FALSE;
if (!JS_InstanceOf(ctx, hobj, &window_class, &args)) return false;
vs = JS_GetInstancePrivate(ctx, obj, &window_class, argv);
vs = JS_GetInstancePrivate(ctx, hobj, &window_class, &args);
if (argc != 1)
return JS_TRUE;
return true;
string = jsval_to_string(ctx, &argv[0]);
string = jsval_to_string(ctx, args[0].address());
if (!*string)
return JS_TRUE;
return true;
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, stracpy(string));
undef_to_jsval(ctx, &val);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
args.rval().setUndefined();
return true;
}
/* @window_funcs{"open"} */
static JSBool
static bool
window_open(JSContext *ctx, unsigned int argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
JS::RootedObject hobj(ctx, obj);
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
// jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
struct session *ses;
@ -315,9 +317,9 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval)
static time_t ratelimit_start;
static int ratelimit_count;
if (!JS_InstanceOf(ctx, obj, &window_class, argv)) return JS_FALSE;
if (!JS_InstanceOf(ctx, hobj, &window_class, &args)) return false;
vs = JS_GetInstancePrivate(ctx, obj, &window_class, argv);
vs = JS_GetInstancePrivate(ctx, hobj, &window_class, &args);
doc_view = vs->doc_view;
ses = doc_view->session;
@ -325,10 +327,10 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval)
#ifdef CONFIG_LEDS
set_led_value(ses->status.popup_led, 'P');
#endif
return JS_TRUE;
return true;
}
if (argc < 1) return JS_TRUE;
if (argc < 1) return true;
/* Ratelimit window opening. Recursive window.open() is very nice.
* We permit at most 20 tabs in 2 seconds. The ratelimiter is very
@ -339,22 +341,22 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval)
} else {
ratelimit_count++;
if (ratelimit_count > 20) {
return JS_TRUE;
return true;
}
}
url = stracpy(jsval_to_string(ctx, &argv[0]));
url = stracpy(jsval_to_string(ctx, args[0].address()));
trim_chars(url, ' ', 0);
url2 = join_urls(doc_view->document->uri, url);
mem_free(url);
if (!url2) {
return JS_TRUE;
return true;
}
if (argc > 1) {
frame = stracpy(jsval_to_string(ctx, &argv[1]));
frame = stracpy(jsval_to_string(ctx, args[1].address()));
if (!frame) {
mem_free(url2);
return JS_TRUE;
return true;
}
}
@ -364,7 +366,7 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval)
mem_free(url2);
if (!uri) {
mem_free_if(frame);
return JS_TRUE;
return true;
}
if (frame && *frame && c_strcasecmp(frame, "_blank")) {
@ -406,39 +408,41 @@ end:
done_uri(uri);
mem_free_if(frame);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
args.rval().set(val);
return true;
}
/* @window_funcs{"setTimeout"} */
static JSBool
static bool
window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval)
{
jsval *argv = JS_ARGV(ctx, rval);
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
// jsval *argv = JS_ARGV(ctx, rval);
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
unsigned char *code;
int timeout;
if (argc != 2)
return JS_TRUE;
return true;
code = jsval_to_string(ctx, &argv[0]);
code = jsval_to_string(ctx, args[0].address());
if (!*code)
return JS_TRUE;
return true;
code = stracpy(code);
if (!code)
return JS_TRUE;
timeout = atoi(jsval_to_string(ctx, &argv[1]));
return true;
timeout = atoi(jsval_to_string(ctx, args[1].address()));
if (timeout <= 0) {
mem_free(code);
return JS_TRUE;
return true;
}
ecmascript_set_timeout(interpreter, code, timeout);
return JS_TRUE;
return true;
}
static JSBool
#if 0
static bool
window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
{
ELINKS_CAST_PROP_PARAMS
@ -446,24 +450,28 @@ window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
/* 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, obj, &window_class, NULL))
return JS_FALSE;
if (!JS_InstanceOf(ctx, hobj, &window_class, NULL))
return false;
boolean_to_jsval(ctx, vp, 0);
return JS_TRUE;
return true;
}
#endif
static bool
window_get_property_closed(JSContext *ctx, unsigned int argc, jsval *vp)
{
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setBoolean(false);
return true;
}
static JSBool
window_get_property_parent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
window_get_property_parent(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
/* 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, obj, &window_class, NULL))
return JS_FALSE;
JS::CallArgs args = CallArgsFromVp(argc, vp);
/* XXX: It would be nice if the following worked, yes.
* The problem is that we get called at the point where
@ -475,93 +483,79 @@ window_get_property_parent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
/* FIXME: So now we alias window.parent to window.top, which is
* INCORRECT but works for the most common cases of just two
* frames. Better something than nothing. */
args.rval().setUndefined();
undef_to_jsval(ctx, vp);
return JS_TRUE;
return true;
}
static JSBool
window_get_property_self(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
window_get_property_self(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setObject(args.thisv().toObject());
/* 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, obj, &window_class, NULL))
return JS_FALSE;
object_to_jsval(ctx, vp, obj);
return JS_TRUE;
return true;
}
static JSBool
window_get_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
window_get_property_status(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setUndefined();
/* 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, obj, &window_class, NULL))
return JS_FALSE;
undef_to_jsval(ctx, vp);
return JS_TRUE;
return true;
}
static JSBool
window_set_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp)
static bool
window_set_property_status(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JS::CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() != 1) {
return false;
}
struct view_state *vs;
JS::RootedObject hobj(ctx, &args.thisv().toObject());
/* 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, obj, &window_class, NULL))
return JS_FALSE;
struct view_state *vs = JS_GetInstancePrivate(ctx, hobj, &window_class, NULL);
vs = JS_GetInstancePrivate(ctx, obj, &window_class, NULL);
if (!vs) {
return true;
}
mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, vp)));
mem_free_set(&vs->doc_view->session->status.window_status, stracpy(JS_EncodeString(ctx, args[0].toString())));
print_screen_status(vs->doc_view->session);
return JS_TRUE;
return true;
}
static JSBool
window_get_property_top(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
static bool
window_get_property_top(JSContext *ctx, unsigned int argc, jsval *vp)
{
ELINKS_CAST_PROP_PARAMS
JS::CallArgs args = CallArgsFromVp(argc, vp);
struct view_state *vs;
struct document_view *doc_view;
struct document_view *top_view;
JSObject *newjsframe;
/* 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, obj, &window_class, NULL))
return JS_FALSE;
JS::RootedObject hobj(ctx, &args.thisv().toObject());
vs = JS_GetInstancePrivate(ctx, obj, &window_class, NULL);
vs = JS_GetInstancePrivate(ctx, hobj, &window_class, NULL);
if (!vs) {
return false;
}
doc_view = vs->doc_view;
top_view = doc_view->session->doc_view;
undef_to_jsval(ctx, vp);
assert(top_view && top_view->vs);
if (top_view->vs->ecmascript_fragile)
ecmascript_reset_state(top_view->vs);
if (!top_view->vs->ecmascript)
return JS_TRUE;
newjsframe = JS_GetGlobalForScopeChain(top_view->vs->ecmascript->backend_data);
if (!top_view->vs->ecmascript) {
args.rval().setUndefined();
return true;
}
newjsframe = JS::CurrentGlobalOrNull(top_view->vs->ecmascript->backend_data);
/* Keep this unrolled this way. Will have to check document.domain
* JS property. */
@ -569,18 +563,14 @@ window_get_property_top(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
* is alien but some other child window is not, we should still
* let the script walk thru. That'd mean moving the check to
* other individual properties in this switch. */
if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST))
object_to_jsval(ctx, vp, newjsframe);
if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST)) {
args.rval().setObject(*newjsframe);
return true;
}
/* else */
/****X*X*X*** SECURITY VIOLATION! RED ALERT, SHIELDS UP! ***X*X*X****\
|* (Pasky was apparently looking at the Links2 JS code . ___ ^.^ *|
\* for too long.) `.(,_,)\o/ */
return JS_TRUE;
}
static JSBool
window_get_property_window(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
{
return window_get_property_self(ctx, hobj, hid, hvp);
args.rval().setUndefined();
return true;
}