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

JS_VERSION at least 185 is required for ECMASCript (xulrunner-2.0 or later)

The code wasn't tested. It compiles
This commit is contained in:
witekfl 2011-04-19 22:41:05 +02:00
parent 9e4d7d1883
commit 2844f8b715
20 changed files with 352 additions and 230 deletions

View File

@ -652,7 +652,14 @@ if test -z "$disable_spidermonkey"; then
CPPFLAGS="$CPPFLAGS_X $SPIDERMONKEY_CFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define XP_UNIX
#include <jsapi.h>]], [[JS_GetReservedSlot(NULL, NULL, 0, NULL)]])],[cf_result=yes],[cf_result=no])
#include <jsapi.h>]], [[
#ifndef JS_VERSION
#error JS_VERSION
#endif
#if JS_VERSION < 185
#error too old
#endif]])],
[cf_result=yes],[cf_result=no])
else
for spidermonkeydir in "$withval" "" /usr /usr/local /opt/spidermonkey /opt/js; do
for spidermonkeyinclude in "/include" "/include/js" "/include/smjs" "/include/mozjs"; do
@ -666,7 +673,15 @@ if test -z "$disable_spidermonkey"; then
CPPFLAGS="$CPPFLAGS_X $SPIDERMONKEY_CFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define XP_UNIX
#include <jsapi.h>]], [[JS_GetReservedSlot(NULL, NULL, 0, NULL)]])],[cf_result=yes],[cf_result=no])
#define XP_UNIX
#include <jsapi.h>]], [[
#ifndef JS_VERSION
#error JS_VERSION
#endif
#if JS_VERSION < 185
#error too old
#endif]])],
[cf_result=yes],[cf_result=no])
fi
done
done

View File

@ -50,6 +50,7 @@ JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
static void undef_to_jsval(JSContext *ctx, jsval *vp);
static unsigned char *jsval_to_string(JSContext *ctx, jsval *vp);
static unsigned char *jsid_to_string(JSContext *ctx, jsid *id);
/* Inline functions */
@ -68,7 +69,17 @@ jsval_to_string(JSContext *ctx, jsval *vp)
return "";
}
return empty_string_or_(JS_GetStringBytes(JS_ValueToString(ctx, val)));
return empty_string_or_(JS_EncodeString(ctx, JS_ValueToString(ctx, val)));
}
static inline unsigned char *
jsid_to_string(JSContext *ctx, jsid *id)
{
jsval v;
/* TODO: check returned value */
JS_IdToValue(ctx, *id, &v);
return jsval_to_string(ctx, &v);
}
#endif

View File

@ -169,19 +169,14 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
return NULL;
interpreter->backend_data = ctx;
JS_SetContextPrivate(ctx, interpreter);
/* TODO: Make JSOPTION_STRICT and JSOPTION_WERROR configurable. */
#ifndef JSOPTION_COMPILE_N_GO
#define JSOPTION_COMPILE_N_GO 0 /* Older SM versions don't have it. */
#endif
/* XXX: JSOPTION_COMPILE_N_GO will go (will it?) when we implement
* some kind of bytecode cache. (If we will ever do that.) */
JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JSOPTION_COMPILE_N_GO);
JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
JS_SetVersion(ctx, JSVERSION_LATEST);
JS_SetErrorReporter(ctx, error_reporter);
#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
JS_SetOperationCallback(ctx, heartbeat_callback);
#endif
window_obj = JS_NewObject(ctx, (JSClass *) &window_class, NULL, NULL);
window_obj = JS_NewCompartmentAndGlobalObject(ctx, (JSClass *) &window_class, NULL);
if (!window_obj) goto release_and_fail;
if (!JS_InitStandardClasses(ctx, window_obj)) goto release_and_fail;
if (!JS_DefineProperties(ctx, window_obj, (JSPropertySpec *) window_props))

View File

@ -47,8 +47,8 @@
#include "viewer/text/vs.h"
static JSBool document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool document_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
static JSBool document_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
/* Each @document_class object must have a @window_class parent. */
const JSClass document_class = {
@ -81,7 +81,7 @@ const JSPropertySpec document_props[] = {
/* @document_class.getProperty */
static JSBool
document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
document_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -104,9 +104,9 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
document = doc_view->document;
ses = doc_view->session;
if (JSVAL_IS_STRING(id)) {
if (JSID_IS_STRING(id)) {
struct form *form;
unsigned char *string = jsval_to_string(ctx, &id);
unsigned char *string = jsid_to_string(ctx, &id);
#ifdef CONFIG_COOKIES
if (!strcmp(string, "cookie")) {
@ -135,12 +135,12 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_DOC_LOC:
JS_GetProperty(ctx, parent_win, "location", vp);
break;
@ -188,7 +188,7 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @document_class.setProperty */
static JSBool
document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
document_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -209,9 +209,9 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
doc_view = vs->doc_view;
document = doc_view->document;
if (JSVAL_IS_STRING(id)) {
if (JSID_IS_STRING(id)) {
#ifdef CONFIG_COOKIES
if (!strcmp(jsval_to_string(ctx, &id), "cookie")) {
if (!strcmp(jsid_to_string(ctx, &id), "cookie")) {
set_cookie(vs->uri, jsval_to_string(ctx, vp));
/* Do NOT touch our .cookie property, evil
* SpiderMonkey!! */
@ -221,10 +221,10 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_DOC_TITLE:
mem_free_set(&document->title, stracpy(jsval_to_string(ctx, vp)));
print_screen_status(doc_view->session);
@ -242,8 +242,8 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
static JSBool document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool document_writeln(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool document_write(JSContext *ctx, uintN argc, jsval *rval);
static JSBool document_writeln(JSContext *ctx, uintN argc, jsval *rval);
const spidermonkeyFunctionSpec document_funcs[] = {
{ "write", document_write, 1 },
@ -252,11 +252,12 @@ const spidermonkeyFunctionSpec document_funcs[] = {
};
static JSBool
document_write_do(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval, int newline)
document_write_do(JSContext *ctx, uintN 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);
if (argc >= 1 && ret) {
int i = 0;
@ -281,22 +282,23 @@ document_write_do(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J');
#endif
boolean_to_jsval(ctx, rval, 0);
boolean_to_jsval(ctx, &val, 0);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
/* @document_funcs{"write"} */
static JSBool
document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
document_write(JSContext *ctx, uintN argc, jsval *rval)
{
return document_write_do(ctx, obj, argc, argv, rval, 0);
return document_write_do(ctx, argc, rval, 0);
}
/* @document_funcs{"writeln"} */
static JSBool
document_writeln(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
document_writeln(JSContext *ctx, uintN argc, jsval *rval)
{
return document_write_do(ctx, obj, argc, argv, rval, 1);
return document_write_do(ctx, argc, rval, 1);
}

View File

@ -55,8 +55,8 @@ static const JSClass form_class; /* defined below */
* HTMLInputElement. The difference could be spotted only by some clever tricky
* JS code, but I hope it doesn't matter anywhere. --pasky */
static JSBool input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool input_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
static JSBool input_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
static void input_finalize(JSContext *ctx, JSObject *obj);
/* Each @input_class object must have a @form_class parent. */
@ -116,10 +116,10 @@ static const JSPropertySpec input_props[] = {
{ NULL }
};
static JSBool input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool input_select(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool input_blur(JSContext *ctx, uintN argc, jsval *rval);
static JSBool input_click(JSContext *ctx, uintN argc, jsval *rval);
static JSBool input_focus(JSContext *ctx, uintN argc, jsval *rval);
static JSBool input_select(JSContext *ctx, uintN argc, jsval *rval);
static const spidermonkeyFunctionSpec input_funcs[] = {
{ "blur", input_blur, 0 },
@ -150,7 +150,7 @@ input_get_form_state(JSContext *ctx, JSObject *jsinput)
/* @input_class.getProperty */
static JSBool
input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
input_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
@ -189,7 +189,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
assert(fc);
assert(fc->form && fs);
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
linknum = get_form_control_link(document, fc);
@ -198,7 +198,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_INPUT_ACCESSKEY:
{
JSString *keystr;
@ -301,7 +301,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @input_class.setProperty */
static JSBool
input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
input_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
@ -341,14 +341,14 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
assert(fc);
assert(fc->form && fs);
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
linknum = get_form_control_link(document, fc);
/* Hiddens have no link. */
if (linknum >= 0) link = &document->links[linknum];
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_INPUT_ACCESSKEY:
accesskey = jsval_to_accesskey(ctx, vp);
if (accesskey == UCS_NO_CHAR)
@ -422,7 +422,7 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @input_funcs{"blur"} */
static JSBool
input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
input_blur(JSContext *ctx, uintN argc, jsval *rval)
{
/* We are a text-mode browser and there *always* has to be something
* selected. So we do nothing for now. (That was easy.) */
@ -431,11 +431,14 @@ input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
/* @input_funcs{"click"} */
static JSBool
input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
input_click(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
@ -479,17 +482,21 @@ input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
else
print_screen_status(ses);
boolean_to_jsval(ctx, rval, 0);
boolean_to_jsval(ctx, &val, 0);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
/* @input_funcs{"focus"} */
static JSBool
input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
input_focus(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
@ -528,13 +535,14 @@ input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
jump_to_link_number(ses, doc_view, linknum);
boolean_to_jsval(ctx, rval, 0);
boolean_to_jsval(ctx, &val, 0);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
/* @input_funcs{"select"} */
static JSBool
input_select(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
input_select(JSContext *ctx, uintN argc, jsval *rval)
{
/* We support no text selecting yet. So we do nothing for now.
* (That was easy, too.) */
@ -662,19 +670,22 @@ get_form_control_object(JSContext *ctx, JSObject *jsform,
static struct form_view *form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv);
static JSBool form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool form_elements_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
/* Each @form_elements_class object must have a @form_class parent. */
static const JSClass form_elements_class = {
"elements",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub,
form_elements_get_property, JS_PropertyStub,
form_elements_get_property, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static JSBool form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool form_elements_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool form_elements_namedItem2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool form_elements_item(JSContext *ctx, uintN argc, jsval *rval);
static JSBool form_elements_namedItem(JSContext *ctx, uintN argc, jsval *rval);
static const spidermonkeyFunctionSpec form_elements_funcs[] = {
{ "item", form_elements_item, 1 },
@ -696,8 +707,9 @@ static const JSPropertySpec form_elements_props[] = {
/* @form_elements_class.getProperty */
static JSBool
form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
form_elements_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
@ -730,32 +742,46 @@ form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
if (!form_view) return JS_FALSE; /* detached */
form = find_form_by_form_view(document, form_view);
if (JSVAL_IS_STRING(id)) {
form_elements_namedItem(ctx, obj, 1, &id, vp);
if (JSID_IS_STRING(id)) {
JS_IdToValue(ctx, id, &idval);
form_elements_namedItem2(ctx, obj, 1, &idval, vp);
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_FORM_ELEMENTS_LENGTH:
int_to_jsval(ctx, vp, list_size(&form->items));
break;
default:
/* Array index. */
form_elements_item(ctx, obj, 1, &id, vp);
JS_IdToValue(ctx, id, &idval);
form_elements_item2(ctx, obj, 1, &idval, vp);
break;
}
return JS_TRUE;
}
static JSBool
form_elements_item(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
JSBool ret = form_elements_item2(ctx, obj, argc, argv, &val);
JS_SET_RVAL(ctx, rval, val);
return ret;
}
/* @form_elements_funcs{"item"} */
static JSBool
form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
form_elements_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
@ -813,9 +839,21 @@ form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval
return JS_TRUE;
}
static JSBool
form_elements_namedItem(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
JSBool ret = form_elements_namedItem2(ctx, obj, argc, argv, &val);
JS_SET_RVAL(ctx, rval, val);
return ret;
}
/* @form_elements_funcs{"namedItem"} */
static JSBool
form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
form_elements_namedItem2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc; /* instance of @document_class */
@ -876,8 +914,8 @@ form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
static JSBool form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool form_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
static JSBool form_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
static void form_finalize(JSContext *ctx, JSObject *obj);
/* Each @form_class object must have a @document_class parent. */
@ -914,8 +952,8 @@ static const JSPropertySpec form_props[] = {
{ NULL }
};
static JSBool form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool form_reset(JSContext *ctx, uintN argc, jsval *rval);
static JSBool form_submit(JSContext *ctx, uintN argc, jsval *rval);
static const spidermonkeyFunctionSpec form_funcs[] = {
{ "reset", form_reset, 0 },
@ -940,7 +978,7 @@ form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv)
/* @form_class.getProperty */
static JSBool
form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
form_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
/* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */
JSObject *parent_doc; /* instance of @document_class */
@ -971,11 +1009,11 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
assert(form);
if (JSVAL_IS_STRING(id)) {
if (JSID_IS_STRING(id)) {
struct form_control *fc;
unsigned char *string;
string = jsval_to_string(ctx, &id);
string = jsid_to_string(ctx, &id);
foreach (fc, form->items) {
JSObject *fcobj = NULL;
struct form_state *fs;
@ -996,12 +1034,12 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_FORM_ACTION:
string_to_jsval(ctx, vp, form->action);
break;
@ -1076,7 +1114,7 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @form_class.setProperty */
static JSBool
form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
form_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
@ -1107,10 +1145,10 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
assert(form);
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_FORM_ACTION:
string = stracpy(jsval_to_string(ctx, vp));
if (form->action) {
@ -1162,10 +1200,13 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @form_funcs{"reset"} */
static JSBool
form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
form_reset(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
struct form_view *fv;
@ -1191,17 +1232,21 @@ form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
do_reset_form(doc_view, form);
draw_forms(doc_view->session->tab->term, doc_view);
boolean_to_jsval(ctx, rval, 0);
boolean_to_jsval(ctx, &val, 0);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
/* @form_funcs{"submit"} */
static JSBool
form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
form_submit(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
struct session *ses;
@ -1227,7 +1272,8 @@ form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
assert(form);
submit_given_form(ses, doc_view, form, 0);
boolean_to_jsval(ctx, rval, 0);
boolean_to_jsval(ctx, &val, 0);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
@ -1308,19 +1354,20 @@ spidermonkey_detach_form_view(struct form_view *fv)
}
static JSBool forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool forms_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
/* Each @forms_class object must have a @document_class parent. */
const JSClass forms_class = {
"forms",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub,
forms_get_property, JS_PropertyStub,
forms_get_property, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static JSBool forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool forms_item(JSContext *ctx, uintN argc, jsval *rval);
static JSBool forms_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool forms_namedItem(JSContext *ctx, uintN argc, jsval *rval);
const spidermonkeyFunctionSpec forms_funcs[] = {
{ "item", forms_item, 1 },
@ -1365,8 +1412,9 @@ find_form_by_name(JSContext *ctx, JSObject *jsdoc,
/* @forms_class.getProperty */
static JSBool
forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
forms_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -1390,36 +1438,50 @@ forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
doc_view = vs->doc_view;
document = doc_view->document;
if (JSVAL_IS_STRING(id)) {
if (JSID_IS_STRING(id)) {
/* When SMJS evaluates forms.namedItem("foo"), it first
* calls forms_get_property with id = JSString "namedItem"
* and *vp = JSObject JSFunction forms_namedItem.
* If we don't find a form whose name is id,
* we must leave *vp unchanged here, to avoid
* "TypeError: forms.namedItem is not a function". */
find_form_by_name(ctx, parent_doc, doc_view, id, vp);
JS_IdToValue(ctx, id, &idval);
find_form_by_name(ctx, parent_doc, doc_view, idval, vp);
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_FORMS_LENGTH:
int_to_jsval(ctx, vp, list_size(&document->forms));
break;
default:
/* Array index. */
forms_item(ctx, obj, 1, &id, vp);
JS_IdToValue(ctx, id, &idval);
forms_item2(ctx, obj, 1, &idval, vp);
break;
}
return JS_TRUE;
}
static JSBool
forms_item(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
JSBool ret = forms_item2(ctx, obj, argc, argv, &val);
JS_SET_RVAL(ctx, rval, val);
return ret;
}
/* @forms_funcs{"item"} */
static JSBool
forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
forms_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
@ -1459,10 +1521,13 @@ forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
/* @forms_funcs{"namedItem"} */
static JSBool
forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
forms_namedItem(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win; /* instance of @window_class */
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
@ -1481,8 +1546,9 @@ forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
if (argc != 1)
return JS_TRUE;
undef_to_jsval(ctx, rval);
find_form_by_name(ctx, parent_doc, doc_view, argv[0], rval);
undef_to_jsval(ctx, &val);
find_form_by_name(ctx, parent_doc, doc_view, argv[0], &val);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
@ -1519,13 +1585,13 @@ static unicode_val_T
jsval_to_accesskey(JSContext *ctx, jsval *vp)
{
size_t len;
const jschar *chr;
const char *chr;
/* Convert the value in place, to protect the result from GC. */
if (JS_ConvertValue(ctx, *vp, JSTYPE_STRING, vp) == JS_FALSE)
return UCS_NO_CHAR;
len = JS_GetStringLength(JSVAL_TO_STRING(*vp));
chr = JS_GetStringChars(JSVAL_TO_STRING(*vp));
len = JS_GetStringEncodingLength(ctx, JSVAL_TO_STRING(*vp));
chr = JS_EncodeString(ctx, JSVAL_TO_STRING(*vp));
/* This implementation ignores extra characters in the string. */
if (len < 1)

View File

@ -45,15 +45,15 @@
#include "viewer/text/vs.h"
static JSBool history_back(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool history_forward(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool history_go(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool history_back(JSContext *ctx, uintN argc, jsval *rval);
static JSBool history_forward(JSContext *ctx, uintN argc, jsval *rval);
static JSBool history_go(JSContext *ctx, uintN argc, jsval *rval);
const JSClass history_class = {
"history",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
@ -66,7 +66,7 @@ const spidermonkeyFunctionSpec history_funcs[] = {
/* @history_funcs{"back"} */
static JSBool
history_back(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
history_back(JSContext *ctx, uintN argc, jsval *rval)
{
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
@ -83,7 +83,7 @@ history_back(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
/* @history_funcs{"forward"} */
static JSBool
history_forward(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
history_forward(JSContext *ctx, uintN argc, jsval *rval)
{
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
@ -96,11 +96,12 @@ history_forward(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
/* @history_funcs{"go"} */
static JSBool
history_go(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
history_go(JSContext *ctx, uintN 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);
int index;
struct location *loc;
@ -124,8 +125,8 @@ history_go(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
static JSBool location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool location_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
static JSBool location_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
/* Each @location_class object must have a @window_class parent. */
const JSClass location_class = {
@ -150,7 +151,7 @@ const JSPropertySpec location_props[] = {
/* @location_class.getProperty */
static JSBool
location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
location_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -167,12 +168,12 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
vs = JS_GetInstancePrivate(ctx, parent_win,
(JSClass *) &window_class, NULL);
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_LOC_HREF:
astring_to_jsval(ctx, vp, get_uri_string(vs->uri, URI_ORIGINAL));
break;
@ -191,7 +192,7 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @location_class.setProperty */
static JSBool
location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
location_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -210,10 +211,10 @@ location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
(JSClass *) &window_class, NULL);
doc_view = vs->doc_view;
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_LOC_HREF:
location_goto(doc_view, jsval_to_string(ctx, vp));
break;
@ -222,7 +223,7 @@ location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
static JSBool location_toString(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool location_toString(JSContext *ctx, uintN argc, jsval *rval);
const spidermonkeyFunctionSpec location_funcs[] = {
{ "toString", location_toString, 0 },
@ -232,9 +233,14 @@ const spidermonkeyFunctionSpec location_funcs[] = {
/* @location_funcs{"toString"}, @location_funcs{"toLocaleString"} */
static JSBool
location_toString(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
location_toString(JSContext *ctx, uintN argc, jsval *rval)
{
return JS_GetProperty(ctx, obj, "href", rval);
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
JSBool ret = JS_GetProperty(ctx, obj, "href", &val);
JS_SET_RVAL(ctx, rval, val);
return ret;
}
struct delayed_goto {

View File

@ -44,13 +44,13 @@
#include "viewer/text/vs.h"
static JSBool navigator_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool navigator_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
const JSClass navigator_class = {
"navigator",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub,
navigator_get_property, JS_PropertyStub,
navigator_get_property, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
@ -81,14 +81,14 @@ const JSPropertySpec navigator_props[] = {
/* @navigator_class.getProperty */
static JSBool
navigator_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
navigator_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_NAVIGATOR_APP_CODENAME:
string_to_jsval(ctx, vp, "Mozilla"); /* More like a constant nowadays. */
break;

View File

@ -45,8 +45,8 @@
#include "viewer/text/vs.h"
static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
/* Each @menubar_class object must have a @window_class parent. */
const JSClass menubar_class = {
@ -80,7 +80,7 @@ const JSPropertySpec unibar_props[] = {
/* @menubar_class.getProperty, @statusbar_class.getProperty */
static JSBool
unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -104,10 +104,10 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
status = &doc_view->session->status;
bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_UNIBAR_VISIBLE:
#define unibar_fetch(bar) \
boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
@ -139,7 +139,7 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
/* @menubar_class.setProperty, @statusbar_class.setProperty */
static JSBool
unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
JSObject *parent_win; /* instance of @window_class */
struct view_state *vs;
@ -163,10 +163,10 @@ unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
status = &doc_view->session->status;
bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_UNIBAR_VISIBLE:
switch (*bar) {
case 's':

View File

@ -44,12 +44,12 @@
#include "viewer/text/vs.h"
static JSBool window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
static JSBool window_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
static JSBool window_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
const JSClass window_class = {
"window",
JSCLASS_HAS_PRIVATE, /* struct view_state * */
JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS, /* struct view_state * */
JS_PropertyStub, JS_PropertyStub,
window_get_property, window_set_property,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
@ -122,7 +122,7 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
/* @window_class.getProperty */
static JSBool
window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
window_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
struct view_state *vs;
@ -138,11 +138,11 @@ window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
* location is then evaluated in string context, toString()
* is called which we overrode for that class below, so
* everything's fine. */
if (JSVAL_IS_STRING(id)) {
if (JSID_IS_STRING(id)) {
struct document_view *doc_view = vs->doc_view;
JSObject *obj;
obj = try_resolve_frame(doc_view, jsval_to_string(ctx, &id));
obj = try_resolve_frame(doc_view, jsid_to_string(ctx, &id));
/* TODO: Try other lookups (mainly element lookup) until
* something yields data. */
if (obj) {
@ -151,12 +151,12 @@ window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
undef_to_jsval(ctx, vp);
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_WIN_CLOSED:
/* TODO: It will be a major PITA to implement this properly.
* Well, perhaps not so much if we introduce reference tracking
@ -254,7 +254,7 @@ void location_goto(struct document_view *doc_view, unsigned char *url);
/* @window_class.setProperty */
static JSBool
window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
window_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
struct view_state *vs;
@ -266,8 +266,8 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
vs = JS_GetInstancePrivate(ctx, obj, (JSClass *) &window_class, NULL);
if (JSVAL_IS_STRING(id)) {
if (!strcmp(jsval_to_string(ctx, &id), "location")) {
if (JSID_IS_STRING(id)) {
if (!strcmp(jsid_to_string(ctx, &id), "location")) {
struct document_view *doc_view = vs->doc_view;
location_goto(doc_view, jsval_to_string(ctx, vp));
@ -278,10 +278,10 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE;
}
if (!JSVAL_IS_INT(id))
if (!JSID_IS_INT(id))
return JS_TRUE;
switch (JSVAL_TO_INT(id)) {
switch (JSID_TO_INT(id)) {
case JSP_WIN_STATUS:
mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, vp)));
print_screen_status(vs->doc_view->session);
@ -298,9 +298,9 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
}
static JSBool window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool window_alert(JSContext *ctx, uintN argc, jsval *rval);
static JSBool window_open(JSContext *ctx, uintN argc, jsval *rval);
static JSBool window_setTimeout(JSContext *ctx, uintN argc, jsval *rval);
const spidermonkeyFunctionSpec window_funcs[] = {
{ "alert", window_alert, 1 },
@ -311,8 +311,11 @@ const spidermonkeyFunctionSpec window_funcs[] = {
/* @window_funcs{"alert"} */
static JSBool
window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
window_alert(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
unsigned char *string;
@ -330,14 +333,18 @@ window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, stracpy(string));
undef_to_jsval(ctx, rval);
undef_to_jsval(ctx, &val);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
/* @window_funcs{"open"} */
static JSBool
window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
window_open(JSContext *ctx, uintN argc, jsval *rval)
{
jsval val;
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
jsval *argv = JS_ARGV(ctx, rval);
struct view_state *vs;
struct document_view *doc_view;
struct session *ses;
@ -407,7 +414,7 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
deo->uri = get_uri_reference(uri);
deo->target = stracpy(frame);
register_bottom_half(delayed_goto_uri_frame, deo);
boolean_to_jsval(ctx, rval, 1);
boolean_to_jsval(ctx, &val, 1);
goto end;
}
}
@ -418,7 +425,7 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
&& can_open_in_new(ses->tab->term)) {
open_uri_in_new_window(ses, uri, NULL, ENV_ANY,
CACHE_MODE_NORMAL, TASK_NONE);
boolean_to_jsval(ctx, rval, 1);
boolean_to_jsval(ctx, &val, 1);
} else {
/* When opening a new tab, we might get rerendered, losing our
* context and triggerring a disaster, so postpone that. */
@ -428,9 +435,9 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
deo->ses = ses;
deo->uri = get_uri_reference(uri);
register_bottom_half(delayed_open, deo);
boolean_to_jsval(ctx, rval, 1);
boolean_to_jsval(ctx, &val, 1);
} else {
undef_to_jsval(ctx, rval);
undef_to_jsval(ctx, &val);
}
}
@ -438,13 +445,15 @@ end:
done_uri(uri);
mem_free_if(frame);
JS_SET_RVAL(ctx, rval, val);
return JS_TRUE;
}
/* @window_funcs{"setTimeout"} */
static JSBool
window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
window_setTimeout(JSContext *ctx, uintN argc, jsval *rval)
{
jsval *argv = JS_ARGV(ctx, rval);
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
unsigned char *code;
int timeout;

View File

@ -40,25 +40,31 @@ smjs_action_fn_finalize(JSContext *ctx, JSObject *obj)
/* @action_fn_class.call */
static JSBool
smjs_action_fn_callback(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
smjs_action_fn_callback(JSContext *ctx, uintN argc, jsval *rval)
{
jsval value;
jsval *argv = JS_ARGV(ctx, rval);
struct smjs_action_fn_callback_hop *hop;
JSObject *fn_obj;
assert(smjs_ctx);
if_assert_failed return JS_FALSE;
*rval = JS_FALSE;
value = JS_FALSE;
if (JS_TRUE != JS_ValueToObject(ctx, argv[-2], &fn_obj))
if (JS_TRUE != JS_ValueToObject(ctx, argv[-2], &fn_obj)) {
JS_SET_RVAL(ctx, rval, value);
return JS_TRUE;
}
assert(JS_InstanceOf(ctx, fn_obj, (JSClass *) &action_fn_class, NULL));
if_assert_failed return JS_FALSE;
hop = JS_GetInstancePrivate(ctx, fn_obj,
(JSClass *) &action_fn_class, NULL);
if (!hop) return JS_TRUE;
if (!hop) {
JS_SET_RVAL(ctx, rval, value);
return JS_TRUE;
}
if (argc >= 1) {
int32 val;
@ -70,7 +76,8 @@ smjs_action_fn_callback(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
do_action(hop->ses, hop->action_id, 1);
*rval = JS_TRUE;
value = JS_TRUE;
JS_SET_RVAL(ctx, rval, value);
return JS_TRUE;
}
@ -79,7 +86,7 @@ static const JSClass action_fn_class = {
"action_fn",
JSCLASS_HAS_PRIVATE, /* struct smjs_action_fn_callback_hop * */
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,
smjs_action_fn_finalize,