ab432b
From a3f59264b9504e8bf3d0ac70b99a237bc964089d Mon Sep 17 00:00:00 2001
ab432b
From: Miciah Dashiel Butler Masters <miciah.masters@gmail.com>
ab432b
Date: Sat, 18 Jul 2009 23:41:01 +0000
ab432b
Subject: [PATCH 1/4] Heartbeat code using JS_TriggerOperationCallback
ab432b
ab432b
Implement new heartbeat code to catch runaway execution of document
ab432b
ECMAScript code.  The old code uses JS_SetBranchCallback which is
ab432b
deprecated in new versions of SpiderMonkey.  The new code uses setitimer(2)
ab432b
and the JS_SetOperationCallback and JS_TriggerOperationCallback interfaces,
ab432b
introduced in SpiderMonkey 1.8.1.  Compatibility with both the old
ab432b
JS_SetBranchCallback and the new interfaces is maintained.
ab432b
ab432b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ab432b
---
ab432b
 Makefile.config.in                      |    1 +
ab432b
 configure.in                            |   12 +++
ab432b
 src/ecmascript/ecmascript.h             |    4 +
ab432b
 src/ecmascript/spidermonkey.c           |   38 ++++++++-
ab432b
 src/ecmascript/spidermonkey/Makefile    |    2 +
ab432b
 src/ecmascript/spidermonkey/heartbeat.c |  125 +++++++++++++++++++++++++++++++
ab432b
 src/ecmascript/spidermonkey/heartbeat.h |   24 ++++++
ab432b
 7 files changed, 201 insertions(+), 5 deletions(-)
ab432b
 create mode 100644 src/ecmascript/spidermonkey/heartbeat.c
ab432b
 create mode 100644 src/ecmascript/spidermonkey/heartbeat.h
ab432b
ab432b
diff --git a/Makefile.config.in b/Makefile.config.in
ab432b
index c463868..40a8cd7 100644
ab432b
--- a/Makefile.config.in
ab432b
+++ b/Makefile.config.in
ab432b
@@ -115,6 +115,7 @@ CONFIG_DOC = @CONFIG_DOC@
ab432b
 CONFIG_DOM = @CONFIG_DOM@
ab432b
 CONFIG_ECMASCRIPT = @CONFIG_ECMASCRIPT@
ab432b
 CONFIG_ECMASCRIPT_SMJS = @CONFIG_ECMASCRIPT_SMJS@
ab432b
+CONFIG_ECMASCRIPT_SMJS_HEARTBEAT = @CONFIG_ECMASCRIPT_SMJS@
ab432b
 CONFIG_EXMODE = @CONFIG_EXMODE@
ab432b
 CONFIG_FASTMEM = @CONFIG_FASTMEM@
ab432b
 CONFIG_FINGER = @CONFIG_FINGER@
ab432b
diff --git a/configure.in b/configure.in
ab432b
index f3e3d77..f79ca78 100644
ab432b
--- a/configure.in
ab432b
+++ b/configure.in
ab432b
@@ -283,6 +283,7 @@ AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
ab432b
 AC_CHECK_FUNCS(getifaddrs getpwnam inet_pton inet_ntop)
ab432b
 AC_CHECK_FUNCS(fflush fsync fseeko ftello sigaction)
ab432b
 AC_CHECK_FUNCS(gettimeofday clock_gettime)
ab432b
+AC_CHECK_FUNCS(setitimer, HAVE_SETITIMER=yes)
ab432b
 
ab432b
 AC_CHECK_FUNCS([cygwin_conv_to_full_win32_path])
ab432b
 
ab432b
@@ -603,6 +604,8 @@ AC_MSG_RESULT($cf_result)
ab432b
 CONFIG_SPIDERMONKEY="$cf_result"
ab432b
 if test "$cf_result" = "yes"; then
ab432b
 	AC_CHECK_FUNCS([[JS_ReportAllocationOverflow]])
ab432b
+	AC_CHECK_FUNCS(JS_SetBranchCallback)
ab432b
+	AC_CHECK_FUNCS(JS_TriggerOperationCallback, HAVE_JS_TRIGGEROPERATIONCALLBACK=yes)
ab432b
 fi
ab432b
 EL_RESTORE_FLAGS
ab432b
 
ab432b
@@ -615,6 +618,15 @@ fi
ab432b
 EL_CONFIG_DEPENDS(CONFIG_ECMASCRIPT, [CONFIG_ECMASCRIPT_SMJS], [ECMAScript (JavaScript)])
ab432b
 AC_SUBST(CONFIG_ECMASCRIPT_SMJS)
ab432b
 
ab432b
+if test "x$CONFIG_ECMASCRIPT_SMJS" = xyes &&
ab432b
+   test "x$HAVE_JS_TRIGGEROPERATIONCALLBACK" = xyes &&
ab432b
+   test "x$HAVE_SETITIMER" = xyes; then
ab432b
+	EL_CONFIG(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT, [ECMAScript heartbeat support])
ab432b
+else
ab432b
+	CONFIG_ECMASCRIPT_SMJS_HEARTBEAT=no
ab432b
+fi
ab432b
+AC_SUBST(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+
ab432b
 
ab432b
 # ===================================================================
ab432b
 # Optional Spidermonkey-based ECMAScript browser scripting
ab432b
diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h
ab432b
index e8d84b5..8613b34 100644
ab432b
--- a/src/ecmascript/ecmascript.h
ab432b
+++ b/src/ecmascript/ecmascript.h
ab432b
@@ -33,7 +33,11 @@ struct ecmascript_interpreter {
ab432b
 	/* The code evaluated by setTimeout() */
ab432b
 	struct string code;
ab432b
 
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	struct heartbeat *heartbeat;
ab432b
+#elif defined(HAVE_JS_SETBRANCHCALLBACK)
ab432b
 	time_t exec_start;
ab432b
+#endif
ab432b
 
ab432b
 	/* This is a cross-rerenderings accumulator of
ab432b
 	 * @document.onload_snippets (see its description for juicy details).
ab432b
diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c
ab432b
index 78c3bca..16fb0a4 100644
ab432b
--- a/src/ecmascript/spidermonkey.c
ab432b
+++ b/src/ecmascript/spidermonkey.c
ab432b
@@ -25,6 +25,7 @@
ab432b
 #include "ecmascript/spidermonkey.h"
ab432b
 #include "ecmascript/spidermonkey/document.h"
ab432b
 #include "ecmascript/spidermonkey/form.h"
ab432b
+#include "ecmascript/spidermonkey/heartbeat.h"
ab432b
 #include "ecmascript/spidermonkey/location.h"
ab432b
 #include "ecmascript/spidermonkey/navigator.h"
ab432b
 #include "ecmascript/spidermonkey/unibar.h"
ab432b
@@ -109,6 +110,7 @@ reported:
ab432b
 	JS_ClearPendingException(ctx);
ab432b
 }
ab432b
 
ab432b
+#if !defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT) && defined(HAVE_JS_SETBRANCHCALLBACK)
ab432b
 static JSBool
ab432b
 safeguard(JSContext *ctx, JSScript *script)
ab432b
 {
ab432b
@@ -132,6 +134,7 @@ setup_safeguard(struct ecmascript_interpreter *interpreter,
ab432b
 	interpreter->exec_start = time(NULL);
ab432b
 	JS_SetBranchCallback(ctx, safeguard);
ab432b
 }
ab432b
+#endif
ab432b
 
ab432b
 
ab432b
 static void
ab432b
@@ -172,6 +175,9 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
ab432b
 	 * some kind of bytecode cache. (If we will ever do that.) */
ab432b
 	JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JSOPTION_COMPILE_N_GO);
ab432b
 	JS_SetErrorReporter(ctx, error_reporter);
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	JS_SetOperationCallback(ctx, heartbeat_callback);
ab432b
+#endif
ab432b
 
ab432b
 	window_obj = JS_NewObject(ctx, (JSClass *) &window_class, NULL, NULL);
ab432b
 	if (!window_obj) goto release_and_fail;
ab432b
@@ -263,10 +269,17 @@ spidermonkey_eval(struct ecmascript_interpreter *interpreter,
ab432b
 	assert(interpreter);
ab432b
 	if (!js_module_init_ok) return;
ab432b
 	ctx = interpreter->backend_data;
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	interpreter->heartbeat = add_heartbeat(interpreter);
ab432b
+#elif defined(HAVE_JS_SETBRANCHCALLBACK)
ab432b
 	setup_safeguard(interpreter, ctx);
ab432b
+#endif
ab432b
 	interpreter->ret = ret;
ab432b
 	JS_EvaluateScript(ctx, JS_GetGlobalObject(ctx),
ab432b
 	                  code->source, code->length, "", 0, &rval);
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	done_heartbeat(interpreter->heartbeat);
ab432b
+#endif
ab432b
 }
ab432b
 
ab432b
 
ab432b
@@ -274,17 +287,25 @@ unsigned char *
ab432b
 spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
ab432b
 			     struct string *code)
ab432b
 {
ab432b
+	JSBool ret;
ab432b
 	JSContext *ctx;
ab432b
 	jsval rval;
ab432b
 
ab432b
 	assert(interpreter);
ab432b
 	if (!js_module_init_ok) return NULL;
ab432b
 	ctx = interpreter->backend_data;
ab432b
-	setup_safeguard(interpreter, ctx);
ab432b
 	interpreter->ret = NULL;
ab432b
-	if (JS_EvaluateScript(ctx, JS_GetGlobalObject(ctx),
ab432b
-			      code->source, code->length, "", 0, &rval)
ab432b
-	    == JS_FALSE) {
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	interpreter->heartbeat = add_heartbeat(interpreter);
ab432b
+#elif defined(HAVE_JS_SETBRANCHCALLBACK)
ab432b
+	setup_safeguard(interpreter, ctx);
ab432b
+#endif
ab432b
+	ret = JS_EvaluateScript(ctx, JS_GetGlobalObject(ctx),
ab432b
+	                        code->source, code->length, "", 0, &rval);
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	done_heartbeat(interpreter->heartbeat);
ab432b
+#endif
ab432b
+	if (ret == JS_FALSE) {
ab432b
 		return NULL;
ab432b
 	}
ab432b
 	if (JSVAL_IS_VOID(rval)) {
ab432b
@@ -308,14 +329,21 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
ab432b
 	assert(interpreter);
ab432b
 	if (!js_module_init_ok) return 0;
ab432b
 	ctx = interpreter->backend_data;
ab432b
-	setup_safeguard(interpreter, ctx);
ab432b
 	interpreter->ret = NULL;
ab432b
 	fun = JS_CompileFunction(ctx, NULL, "", 0, NULL, code->source,
ab432b
 				 code->length, "", 0);
ab432b
 	if (!fun)
ab432b
 		return -1;
ab432b
 
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	interpreter->heartbeat = add_heartbeat(interpreter);
ab432b
+#elif defined(HAVE_JS_SETBRANCHCALLBACK)
ab432b
+	setup_safeguard(interpreter, ctx);
ab432b
+#endif
ab432b
 	ret = JS_CallFunction(ctx, NULL, fun, 0, NULL, &rval);
ab432b
+#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
+	done_heartbeat(interpreter->heartbeat);
ab432b
+#endif
ab432b
 	if (ret == 2) { /* onClick="history.back()" */
ab432b
 		return 0;
ab432b
 	}
ab432b
diff --git a/src/ecmascript/spidermonkey/Makefile b/src/ecmascript/spidermonkey/Makefile
ab432b
index f1c0fef..377ca80 100644
ab432b
--- a/src/ecmascript/spidermonkey/Makefile
ab432b
+++ b/src/ecmascript/spidermonkey/Makefile
ab432b
@@ -2,6 +2,8 @@ top_builddir=../../..
ab432b
 include $(top_builddir)/Makefile.config
ab432b
 INCLUDES += $(SPIDERMONKEY_CFLAGS)
ab432b
 
ab432b
+OBJS-$(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT) += heartbeat.o
ab432b
+
ab432b
 OBJS = document.o form.o location.o navigator.o unibar.o window.o
ab432b
 
ab432b
 include $(top_srcdir)/Makefile.lib
ab432b
diff --git a/src/ecmascript/spidermonkey/heartbeat.c b/src/ecmascript/spidermonkey/heartbeat.c
ab432b
new file mode 100644
ab432b
index 0000000..bf95d92
ab432b
--- /dev/null
ab432b
+++ b/src/ecmascript/spidermonkey/heartbeat.c
ab432b
@@ -0,0 +1,125 @@
ab432b
+/* The SpiderMonkey ECMAScript backend heartbeat fuctionality. */
ab432b
+
ab432b
+#ifdef HAVE_CONFIG_H
ab432b
+#include "config.h"
ab432b
+#endif
ab432b
+
ab432b
+#include <sys/time.h>    /* setitimer(2) */
ab432b
+
ab432b
+#include "elinks.h"
ab432b
+
ab432b
+#include "ecmascript/spidermonkey/util.h"
ab432b
+
ab432b
+#include "config/options.h"
ab432b
+#include "document/view.h"
ab432b
+#include "ecmascript/ecmascript.h"
ab432b
+#include "ecmascript/spidermonkey.h"
ab432b
+#include "ecmascript/spidermonkey/heartbeat.h"
ab432b
+#include "osdep/signals.h"
ab432b
+#include "session/session.h"
ab432b
+#include "util/lists.h"
ab432b
+#include "util/math.h"   /* int_upper_bound */
ab432b
+#include "util/memory.h"
ab432b
+#include "viewer/text/vs.h"
ab432b
+
ab432b
+
ab432b
+
ab432b
+static INIT_LIST_OF(struct heartbeat, heartbeats);
ab432b
+
ab432b
+static struct itimerval heartbeat_timer = { { 1, 0 }, { 1, 0 } };
ab432b
+
ab432b
+
ab432b
+/* This callback is installed by JS_SetOperationCallback and triggered
ab432b
+ * by JS_TriggerOperationCallback in the heartbeat code below.  Returning
ab432b
+ * JS_FALSE terminates script execution immediately. */
ab432b
+JSBool
ab432b
+heartbeat_callback(JSContext *ctx)
ab432b
+{
ab432b
+        return JS_FALSE;
ab432b
+}
ab432b
+
ab432b
+/* Callback for SIGVTALRM.  Go through all heartbeats, decrease each
ab432b
+ * one's TTL, and call JS_TriggerOperationCallback if a heartbeat's TTL
ab432b
+ * goes to 0. */
ab432b
+static void
ab432b
+check_heartbeats(void *data)
ab432b
+{
ab432b
+        struct heartbeat *hb;
ab432b
+
ab432b
+        foreach (hb, heartbeats) {
ab432b
+		assert(hb->interpreter);
ab432b
+
ab432b
+                --hb->ttl;
ab432b
+
ab432b
+                if (hb->ttl <= 0) {
ab432b
+			if (hb->interpreter->vs
ab432b
+			    && hb->interpreter->vs->doc_view
ab432b
+			    && hb->interpreter->vs->doc_view->session
ab432b
+			    && hb->interpreter->vs->doc_view->session->tab
ab432b
+			    && hb->interpreter->vs->doc_view->session->tab->term) {
ab432b
+				struct session *ses = hb->interpreter->vs->doc_view->session;
ab432b
+				struct terminal *term = ses->tab->term;
ab432b
+				int max_exec_time = get_opt_int("ecmascript.max_exec_time");
ab432b
+
ab432b
+				ecmascript_timeout_dialog(term, max_exec_time);
ab432b
+			}
ab432b
+
ab432b
+                        JS_TriggerOperationCallback(hb->interpreter->backend_data);
ab432b
+                }
ab432b
+        }
ab432b
+
ab432b
+        install_signal_handler(SIGVTALRM, check_heartbeats, NULL, 1);
ab432b
+}
ab432b
+
ab432b
+/* Create a new heartbeat for the given interpreter. */
ab432b
+struct heartbeat *
ab432b
+add_heartbeat(struct ecmascript_interpreter *interpreter)
ab432b
+{
ab432b
+	struct session *ses;
ab432b
+        struct heartbeat *hb;
ab432b
+
ab432b
+	assert(interpreter);
ab432b
+
ab432b
+	if (!interpreter->vs || !interpreter->vs->doc_view)
ab432b
+		ses = NULL;
ab432b
+	else
ab432b
+		ses = interpreter->vs->doc_view->session;
ab432b
+
ab432b
+        hb = mem_alloc(sizeof(struct heartbeat));
ab432b
+        if (!hb) return NULL;
ab432b
+
ab432b
+        hb->ttl = get_opt_int("ecmascript.max_exec_time");
ab432b
+        hb->interpreter = interpreter;
ab432b
+
ab432b
+        add_to_list(heartbeats, hb);
ab432b
+
ab432b
+        /* Update the heartbeat timer. */
ab432b
+        if (list_is_singleton(*hb)) {
ab432b
+                heartbeat_timer.it_value.tv_sec = 1;
ab432b
+                setitimer(ITIMER_VIRTUAL, &heartbeat_timer, NULL);
ab432b
+        }
ab432b
+
ab432b
+        /* We install the handler every call to add_heartbeat instead of only on
ab432b
+         * module initialisation because other code may set other handlers for
ab432b
+         * the signal.  */
ab432b
+        install_signal_handler(SIGVTALRM, check_heartbeats, NULL, 1);
ab432b
+
ab432b
+        return hb;
ab432b
+}
ab432b
+
ab432b
+/* Destroy the given heartbeat. */
ab432b
+void
ab432b
+done_heartbeat(struct heartbeat *hb)
ab432b
+{
ab432b
+	assert(hb->interpreter);
ab432b
+
ab432b
+        /* Stop the heartbeat timer if this heartbeat is the only one. */
ab432b
+        if (list_is_singleton(*hb)) {
ab432b
+                heartbeat_timer.it_value.tv_sec = 0;
ab432b
+                setitimer(ITIMER_VIRTUAL, &heartbeat_timer, NULL);
ab432b
+        }
ab432b
+
ab432b
+        del_from_list(hb);
ab432b
+        hb->interpreter->heartbeat = NULL;
ab432b
+        mem_free(hb);
ab432b
+}
ab432b
diff --git a/src/ecmascript/spidermonkey/heartbeat.h b/src/ecmascript/spidermonkey/heartbeat.h
ab432b
new file mode 100644
ab432b
index 0000000..f7c8b12
ab432b
--- /dev/null
ab432b
+++ b/src/ecmascript/spidermonkey/heartbeat.h
ab432b
@@ -0,0 +1,24 @@
ab432b
+#ifndef EL__ECMASCRIPT_SPIDERMONKEY_HEARTBEAT_H
ab432b
+#define EL__ECMASCRIPT_SPIDERMONKEY_HEARTBEAT_H
ab432b
+
ab432b
+#include "ecmascript/spidermonkey/util.h"
ab432b
+
ab432b
+#include "ecmascript/spidermonkey.h"
ab432b
+
ab432b
+struct heartbeat {
ab432b
+        LIST_HEAD(struct heartbeat);
ab432b
+
ab432b
+        int ttl; /* Time to live.  This value is assigned when the
ab432b
+                  * script begins execution and is decremented every
ab432b
+                  * second.  When it reaches 0, script execution is
ab432b
+                  * terminated. */
ab432b
+
ab432b
+        struct ecmascript_interpreter *interpreter;
ab432b
+};
ab432b
+
ab432b
+struct heartbeat *add_heartbeat(struct ecmascript_interpreter *interpreter);
ab432b
+void done_heartbeat(struct heartbeat *hb);
ab432b
+
ab432b
+JSBool heartbeat_callback(JSContext *ctx);
ab432b
+
ab432b
+#endif
ab432b
-- 
ab432b
1.7.4.2
ab432b
ab432b
ab432b
From dcaff5d937d63888c560727dda5f5348fa59a366 Mon Sep 17 00:00:00 2001
ab432b
From: witekfl <witekfl@poczta.onet.pl>
ab432b
Date: Tue, 19 Apr 2011 22:41:05 +0200
ab432b
Subject: [PATCH 2/4] JS_VERSION at least 185 is required for ECMASCript
ab432b
 (xulrunner-2.0 or later)
ab432b
ab432b
The code wasn't tested. It compiles
ab432b
ab432b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ab432b
---
ab432b
 configure.in                            |   10 ++-
ab432b
 src/ecmascript/spidermonkey-shared.h    |   13 ++-
ab432b
 src/ecmascript/spidermonkey.c           |   11 +--
ab432b
 src/ecmascript/spidermonkey/document.c  |   44 ++++----
ab432b
 src/ecmascript/spidermonkey/form.c      |  192 +++++++++++++++++++++----------
ab432b
 src/ecmascript/spidermonkey/location.c  |   42 ++++---
ab432b
 src/ecmascript/spidermonkey/navigator.c |   10 +-
ab432b
 src/ecmascript/spidermonkey/unibar.c    |   16 ++--
ab432b
 src/ecmascript/spidermonkey/window.c    |   57 ++++++----
ab432b
 src/scripting/smjs/action_object.c      |   29 +++--
ab432b
 src/scripting/smjs/bookmarks.c          |   24 ++--
ab432b
 src/scripting/smjs/cache_object.c       |   18 ++--
ab432b
 src/scripting/smjs/core.c               |   11 +-
ab432b
 src/scripting/smjs/elinks_object.c      |   26 +++--
ab432b
 src/scripting/smjs/global_object.c      |    6 +-
ab432b
 src/scripting/smjs/globhist.c           |   22 ++--
ab432b
 src/scripting/smjs/hooks.c              |    4 +-
ab432b
 src/scripting/smjs/keybinding.c         |   12 +-
ab432b
 src/scripting/smjs/load_uri.c           |   10 +-
ab432b
 src/scripting/smjs/view_state_object.c  |   16 ++--
ab432b
 20 files changed, 344 insertions(+), 229 deletions(-)
ab432b
ab432b
diff --git a/configure.in b/configure.in
ab432b
index f79ca78..64faf85 100644
ab432b
--- a/configure.in
ab432b
+++ b/configure.in
ab432b
@@ -593,7 +593,15 @@ if test -z "$disable_spidermonkey"; then
ab432b
 					CPPFLAGS="$CPPFLAGS_X $SPIDERMONKEY_CFLAGS"
ab432b
 
ab432b
 					AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define XP_UNIX
ab432b
-						     #include <jsapi.h>]], [[JS_GetReservedSlot(NULL, NULL, 0, NULL)]])],[cf_result=yes],[cf_result=no])
ab432b
+							#define XP_UNIX
ab432b
+							#include <jsapi.h>]], [[
ab432b
+							#ifndef JS_VERSION
ab432b
+							#error JS_VERSION
ab432b
+							#endif
ab432b
+							#if JS_VERSION < 185
ab432b
+							#error too old
ab432b
+							#endif]])],
ab432b
+                            [cf_result=yes],[cf_result=no])
ab432b
 				fi
ab432b
 			done
ab432b
 		done
ab432b
diff --git a/src/ecmascript/spidermonkey-shared.h b/src/ecmascript/spidermonkey-shared.h
ab432b
index 4cc0eeb..98bfe31 100644
ab432b
--- a/src/ecmascript/spidermonkey-shared.h
ab432b
+++ b/src/ecmascript/spidermonkey-shared.h
ab432b
@@ -50,6 +50,7 @@ JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
ab432b
 
ab432b
 static void undef_to_jsval(JSContext *ctx, jsval *vp);
ab432b
 static unsigned char *jsval_to_string(JSContext *ctx, jsval *vp);
ab432b
+static unsigned char *jsid_to_string(JSContext *ctx, jsid *id);
ab432b
 
ab432b
 /* Inline functions */
ab432b
 
ab432b
@@ -68,7 +69,17 @@ jsval_to_string(JSContext *ctx, jsval *vp)
ab432b
 		return "";
ab432b
 	}
ab432b
 
ab432b
-	return empty_string_or_(JS_GetStringBytes(JS_ValueToString(ctx, val)));
ab432b
+	return empty_string_or_(JS_EncodeString(ctx, JS_ValueToString(ctx, val)));
ab432b
+}
ab432b
+
ab432b
+static inline unsigned char *
ab432b
+jsid_to_string(JSContext *ctx, jsid *id)
ab432b
+{
ab432b
+	jsval v;
ab432b
+
ab432b
+	/* TODO: check returned value */
ab432b
+	JS_IdToValue(ctx, *id, &v);
ab432b
+	return jsval_to_string(ctx, &v);
ab432b
 }
ab432b
 
ab432b
 #endif
ab432b
diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c
ab432b
index 16fb0a4..021e6bd 100644
ab432b
--- a/src/ecmascript/spidermonkey.c
ab432b
+++ b/src/ecmascript/spidermonkey.c
ab432b
@@ -167,19 +167,14 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
ab432b
 		return NULL;
ab432b
 	interpreter->backend_data = ctx;
ab432b
 	JS_SetContextPrivate(ctx, interpreter);
ab432b
-	/* TODO: Make JSOPTION_STRICT and JSOPTION_WERROR configurable. */
ab432b
-#ifndef JSOPTION_COMPILE_N_GO
ab432b
-#define JSOPTION_COMPILE_N_GO 0 /* Older SM versions don't have it. */
ab432b
-#endif
ab432b
-	/* XXX: JSOPTION_COMPILE_N_GO will go (will it?) when we implement
ab432b
-	 * some kind of bytecode cache. (If we will ever do that.) */
ab432b
-	JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JSOPTION_COMPILE_N_GO);
ab432b
+	JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
ab432b
+	JS_SetVersion(ctx, JSVERSION_LATEST);
ab432b
 	JS_SetErrorReporter(ctx, error_reporter);
ab432b
 #if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
ab432b
 	JS_SetOperationCallback(ctx, heartbeat_callback);
ab432b
 #endif
ab432b
 
ab432b
-	window_obj = JS_NewObject(ctx, (JSClass *) &window_class, NULL, NULL);
ab432b
+	window_obj = JS_NewCompartmentAndGlobalObject(ctx, (JSClass *) &window_class, NULL);
ab432b
 	if (!window_obj) goto release_and_fail;
ab432b
 	if (!JS_InitStandardClasses(ctx, window_obj)) goto release_and_fail;
ab432b
 	if (!JS_DefineProperties(ctx, window_obj, (JSPropertySpec *) window_props))
ab432b
diff --git a/src/ecmascript/spidermonkey/document.c b/src/ecmascript/spidermonkey/document.c
ab432b
index 8f7bb92..dd72aae 100644
ab432b
--- a/src/ecmascript/spidermonkey/document.c
ab432b
+++ b/src/ecmascript/spidermonkey/document.c
ab432b
@@ -47,8 +47,8 @@
ab432b
 #include "viewer/text/vs.h"
ab432b
 
ab432b
 
ab432b
-static JSBool document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
-static JSBool document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool document_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
+static JSBool document_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
ab432b
 
ab432b
 /* Each @document_class object must have a @window_class parent.  */
ab432b
 const JSClass document_class = {
ab432b
@@ -81,7 +81,7 @@ const JSPropertySpec document_props[] = {
ab432b
 
ab432b
 /* @document_class.getProperty */
ab432b
 static JSBool
ab432b
-document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+document_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -104,9 +104,9 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	document = doc_view->document;
ab432b
 	ses = doc_view->session;
ab432b
 
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
 		struct form *form;
ab432b
-		unsigned char *string = jsval_to_string(ctx, &id;;
ab432b
+		unsigned char *string = jsid_to_string(ctx, &id;;
ab432b
 
ab432b
 #ifdef CONFIG_COOKIES
ab432b
 		if (!strcmp(string, "cookie")) {
ab432b
@@ -135,12 +135,12 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_DOC_LOC:
ab432b
 		JS_GetProperty(ctx, parent_win, "location", vp);
ab432b
 		break;
ab432b
@@ -188,7 +188,7 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @document_class.setProperty */
ab432b
 static JSBool
ab432b
-document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+document_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -209,9 +209,9 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	doc_view = vs->doc_view;
ab432b
 	document = doc_view->document;
ab432b
 
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
 #ifdef CONFIG_COOKIES
ab432b
-		if (!strcmp(jsval_to_string(ctx, &id), "cookie")) {
ab432b
+		if (!strcmp(jsid_to_string(ctx, &id), "cookie")) {
ab432b
 			set_cookie(vs->uri, jsval_to_string(ctx, vp));
ab432b
 			/* Do NOT touch our .cookie property, evil
ab432b
 			 * SpiderMonkey!! */
ab432b
@@ -221,10 +221,10 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_DOC_TITLE:
ab432b
 		mem_free_set(&document->title, stracpy(jsval_to_string(ctx, vp)));
ab432b
 		print_screen_status(doc_view->session);
ab432b
@@ -242,8 +242,8 @@ document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
-static JSBool document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool document_writeln(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool document_write(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool document_writeln(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 const spidermonkeyFunctionSpec document_funcs[] = {
ab432b
 	{ "write",		document_write,		1 },
ab432b
@@ -252,11 +252,12 @@ const spidermonkeyFunctionSpec document_funcs[] = {
ab432b
 };
ab432b
 
ab432b
 static JSBool
ab432b
-document_write_do(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
-                  jsval *rval, int newline)
ab432b
+document_write_do(JSContext *ctx, uintN argc, jsval *rval, int newline)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
ab432b
 	struct string *ret = interpreter->ret;
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 
ab432b
 	if (argc >= 1 && ret) {
ab432b
 		int i = 0;
ab432b
@@ -281,22 +282,23 @@ document_write_do(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
 	set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J');
ab432b
 #endif
ab432b
 
ab432b
-	boolean_to_jsval(ctx, rval, 0);
ab432b
+	boolean_to_jsval(ctx, &val, 0);
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @document_funcs{"write"} */
ab432b
 static JSBool
ab432b
-document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+document_write(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
 
ab432b
-	return document_write_do(ctx, obj, argc, argv, rval, 0);
ab432b
+	return document_write_do(ctx, argc, rval, 0);
ab432b
 }
ab432b
 
ab432b
 /* @document_funcs{"writeln"} */
ab432b
 static JSBool
ab432b
-document_writeln(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+document_writeln(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
-	return document_write_do(ctx, obj, argc, argv, rval, 1);
ab432b
+	return document_write_do(ctx, argc, rval, 1);
ab432b
 }
ab432b
diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c
ab432b
index ff436a1..824b170 100644
ab432b
--- a/src/ecmascript/spidermonkey/form.c
ab432b
+++ b/src/ecmascript/spidermonkey/form.c
ab432b
@@ -55,8 +55,8 @@ static const JSClass form_class;	     /* defined below */
ab432b
  * HTMLInputElement. The difference could be spotted only by some clever tricky
ab432b
  * JS code, but I hope it doesn't matter anywhere. --pasky */
ab432b
 
ab432b
-static JSBool input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
-static JSBool input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool input_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
+static JSBool input_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
ab432b
 static void input_finalize(JSContext *ctx, JSObject *obj);
ab432b
 
ab432b
 /* Each @input_class object must have a @form_class parent.  */
ab432b
@@ -116,10 +116,10 @@ static const JSPropertySpec input_props[] = {
ab432b
 	{ NULL }
ab432b
 };
ab432b
 
ab432b
-static JSBool input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool input_select(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool input_blur(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool input_click(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool input_focus(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool input_select(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 static const spidermonkeyFunctionSpec input_funcs[] = {
ab432b
 	{ "blur",	input_blur,	0 },
ab432b
@@ -150,7 +150,7 @@ input_get_form_state(JSContext *ctx, JSObject *jsinput)
ab432b
 
ab432b
 /* @input_class.getProperty */
ab432b
 static JSBool
ab432b
-input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+input_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
@@ -189,7 +189,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	assert(fc);
ab432b
 	assert(fc->form && fs);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	linknum = get_form_control_link(document, fc);
ab432b
@@ -198,7 +198,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_INPUT_ACCESSKEY:
ab432b
 	{
ab432b
 		JSString *keystr;
ab432b
@@ -301,7 +301,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @input_class.setProperty */
ab432b
 static JSBool
ab432b
-input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+input_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
@@ -341,14 +341,14 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	assert(fc);
ab432b
 	assert(fc->form && fs);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	linknum = get_form_control_link(document, fc);
ab432b
 	/* Hiddens have no link. */
ab432b
 	if (linknum >= 0) link = &document->links[linknum];
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_INPUT_ACCESSKEY:
ab432b
 		accesskey = jsval_to_accesskey(ctx, vp);
ab432b
 		if (accesskey == UCS_NO_CHAR)
ab432b
@@ -422,7 +422,7 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @input_funcs{"blur"} */
ab432b
 static JSBool
ab432b
-input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+input_blur(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
 	/* We are a text-mode browser and there *always* has to be something
ab432b
 	 * selected.  So we do nothing for now. (That was easy.) */
ab432b
@@ -431,11 +431,14 @@ input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 
ab432b
 /* @input_funcs{"click"} */
ab432b
 static JSBool
ab432b
-input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+input_click(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	struct document_view *doc_view;
ab432b
 	struct document *document;
ab432b
@@ -479,17 +482,21 @@ input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 	else
ab432b
 		print_screen_status(ses);
ab432b
 
ab432b
-	boolean_to_jsval(ctx, rval, 0);
ab432b
+	boolean_to_jsval(ctx, &val, 0);
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @input_funcs{"focus"} */
ab432b
 static JSBool
ab432b
-input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+input_focus(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	struct document_view *doc_view;
ab432b
 	struct document *document;
ab432b
@@ -528,13 +535,14 @@ input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 
ab432b
 	jump_to_link_number(ses, doc_view, linknum);
ab432b
 
ab432b
-	boolean_to_jsval(ctx, rval, 0);
ab432b
+	boolean_to_jsval(ctx, &val, 0);
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @input_funcs{"select"} */
ab432b
 static JSBool
ab432b
-input_select(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+input_select(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
 	/* We support no text selecting yet.  So we do nothing for now.
ab432b
 	 * (That was easy, too.) */
ab432b
@@ -662,19 +670,22 @@ get_form_control_object(JSContext *ctx, JSObject *jsform,
ab432b
 
ab432b
 
ab432b
 static struct form_view *form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv);
ab432b
-static JSBool form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool form_elements_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
 
ab432b
 /* Each @form_elements_class object must have a @form_class parent.  */
ab432b
 static const JSClass form_elements_class = {
ab432b
 	"elements",
ab432b
 	JSCLASS_HAS_PRIVATE,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	form_elements_get_property, JS_PropertyStub,
ab432b
+	form_elements_get_property, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
 };
ab432b
 
ab432b
-static JSBool form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool form_elements_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool form_elements_namedItem2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool form_elements_item(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool form_elements_namedItem(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+
ab432b
 
ab432b
 static const spidermonkeyFunctionSpec form_elements_funcs[] = {
ab432b
 	{ "item",		form_elements_item,		1 },
ab432b
@@ -696,8 +707,9 @@ static const JSPropertySpec form_elements_props[] = {
ab432b
 
ab432b
 /* @form_elements_class.getProperty */
ab432b
 static JSBool
ab432b
-form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+form_elements_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
+	jsval idval;
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
@@ -730,32 +742,46 @@ form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	if (!form_view) return JS_FALSE; /* detached */
ab432b
 	form = find_form_by_form_view(document, form_view);
ab432b
 
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
-		form_elements_namedItem(ctx, obj, 1, &id, vp);
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
+		JS_IdToValue(ctx, id, &idval);
ab432b
+		form_elements_namedItem2(ctx, obj, 1, &idval, vp);
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_FORM_ELEMENTS_LENGTH:
ab432b
 		int_to_jsval(ctx, vp, list_size(&form->items));
ab432b
 		break;
ab432b
 	default:
ab432b
 		/* Array index. */
ab432b
-		form_elements_item(ctx, obj, 1, &id, vp);
ab432b
+		JS_IdToValue(ctx, id, &idval);
ab432b
+		form_elements_item2(ctx, obj, 1, &idval, vp);
ab432b
 		break;
ab432b
 	}
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
+static JSBool
ab432b
+form_elements_item(JSContext *ctx, uintN argc, jsval *rval)
ab432b
+{
ab432b
+	jsval val;
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
+	JSBool ret = form_elements_item2(ctx, obj, argc, argv, &val;;
ab432b
+
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
+	return ret;
ab432b
+}
ab432b
+
ab432b
 /* @form_elements_funcs{"item"} */
ab432b
 static JSBool
ab432b
-form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+form_elements_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 {
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
@@ -813,9 +839,21 @@ form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
+static JSBool
ab432b
+form_elements_namedItem(JSContext *ctx, uintN argc, jsval *rval)
ab432b
+{
ab432b
+	jsval val;
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
+	JSBool ret = form_elements_namedItem2(ctx, obj, argc, argv, &val;;
ab432b
+
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
+	return ret;
ab432b
+}
ab432b
+
ab432b
 /* @form_elements_funcs{"namedItem"} */
ab432b
 static JSBool
ab432b
-form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+form_elements_namedItem2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 {
ab432b
 	JSObject *parent_form;	/* instance of @form_class */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
@@ -876,8 +914,8 @@ form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
 
ab432b
 
ab432b
 
ab432b
-static JSBool form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
-static JSBool form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool form_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
+static JSBool form_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
ab432b
 static void form_finalize(JSContext *ctx, JSObject *obj);
ab432b
 
ab432b
 /* Each @form_class object must have a @document_class parent.  */
ab432b
@@ -914,8 +952,8 @@ static const JSPropertySpec form_props[] = {
ab432b
 	{ NULL }
ab432b
 };
ab432b
 
ab432b
-static JSBool form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool form_reset(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool form_submit(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 static const spidermonkeyFunctionSpec form_funcs[] = {
ab432b
 	{ "reset",	form_reset,	0 },
ab432b
@@ -940,7 +978,7 @@ form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv)
ab432b
 
ab432b
 /* @form_class.getProperty */
ab432b
 static JSBool
ab432b
-form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+form_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	/* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
@@ -971,11 +1009,11 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	assert(form);
ab432b
 
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
 		struct form_control *fc;
ab432b
 		unsigned char *string;
ab432b
 
ab432b
-		string = jsval_to_string(ctx, &id;;
ab432b
+		string = jsid_to_string(ctx, &id;;
ab432b
 		foreach (fc, form->items) {
ab432b
 			JSObject *fcobj = NULL;
ab432b
 			struct form_state *fs;
ab432b
@@ -996,12 +1034,12 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_FORM_ACTION:
ab432b
 		string_to_jsval(ctx, vp, form->action);
ab432b
 		break;
ab432b
@@ -1076,7 +1114,7 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @form_class.setProperty */
ab432b
 static JSBool
ab432b
-form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+form_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
@@ -1107,10 +1145,10 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	assert(form);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_FORM_ACTION:
ab432b
 		string = stracpy(jsval_to_string(ctx, vp));
ab432b
 		if (form->action) {
ab432b
@@ -1162,10 +1200,13 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @form_funcs{"reset"} */
ab432b
 static JSBool
ab432b
-form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+form_reset(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	struct document_view *doc_view;
ab432b
 	struct form_view *fv;
ab432b
@@ -1191,17 +1232,21 @@ form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 	do_reset_form(doc_view, form);
ab432b
 	draw_forms(doc_view->session->tab->term, doc_view);
ab432b
 
ab432b
-	boolean_to_jsval(ctx, rval, 0);
ab432b
+	boolean_to_jsval(ctx, &val, 0);
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @form_funcs{"submit"} */
ab432b
 static JSBool
ab432b
-form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+form_submit(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	struct document_view *doc_view;
ab432b
 	struct session *ses;
ab432b
@@ -1227,7 +1272,8 @@ form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 	assert(form);
ab432b
 	submit_given_form(ses, doc_view, form, 0);
ab432b
 
ab432b
-	boolean_to_jsval(ctx, rval, 0);
ab432b
+	boolean_to_jsval(ctx, &val, 0);
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
@@ -1308,19 +1354,20 @@ spidermonkey_detach_form_view(struct form_view *fv)
ab432b
 }
ab432b
 
ab432b
 
ab432b
-static JSBool forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool forms_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
 
ab432b
 /* Each @forms_class object must have a @document_class parent.  */
ab432b
 const JSClass forms_class = {
ab432b
 	"forms",
ab432b
 	JSCLASS_HAS_PRIVATE,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	forms_get_property, JS_PropertyStub,
ab432b
+	forms_get_property, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
 };
ab432b
 
ab432b
-static JSBool forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool forms_item(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool forms_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool forms_namedItem(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 const spidermonkeyFunctionSpec forms_funcs[] = {
ab432b
 	{ "item",		forms_item,		1 },
ab432b
@@ -1365,8 +1412,9 @@ find_form_by_name(JSContext *ctx, JSObject *jsdoc,
ab432b
 
ab432b
 /* @forms_class.getProperty */
ab432b
 static JSBool
ab432b
-forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+forms_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
+	jsval idval;
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -1390,36 +1438,50 @@ forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	doc_view = vs->doc_view;
ab432b
 	document = doc_view->document;
ab432b
 
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
 		/* When SMJS evaluates forms.namedItem("foo"), it first
ab432b
 		 * calls forms_get_property with id = JSString "namedItem"
ab432b
 		 * and *vp = JSObject JSFunction forms_namedItem.
ab432b
 		 * If we don't find a form whose name is id,
ab432b
 		 * we must leave *vp unchanged here, to avoid
ab432b
 		 * "TypeError: forms.namedItem is not a function".  */
ab432b
-		find_form_by_name(ctx, parent_doc, doc_view, id, vp);
ab432b
+		JS_IdToValue(ctx, id, &idval);
ab432b
+		find_form_by_name(ctx, parent_doc, doc_view, idval, vp);
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_FORMS_LENGTH:
ab432b
 		int_to_jsval(ctx, vp, list_size(&document->forms));
ab432b
 		break;
ab432b
 	default:
ab432b
 		/* Array index. */
ab432b
-		forms_item(ctx, obj, 1, &id, vp);
ab432b
+		JS_IdToValue(ctx, id, &idval);
ab432b
+		forms_item2(ctx, obj, 1, &idval, vp);
ab432b
 		break;
ab432b
 	}
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
+static JSBool
ab432b
+forms_item(JSContext *ctx, uintN argc, jsval *rval)
ab432b
+{
ab432b
+	jsval val;
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
+	JSBool ret = forms_item2(ctx, obj, argc, argv, &val;;
ab432b
+
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
+	return ret;
ab432b
+}
ab432b
+
ab432b
 /* @forms_funcs{"item"} */
ab432b
 static JSBool
ab432b
-forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+forms_item2(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 {
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
@@ -1459,10 +1521,13 @@ forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 
ab432b
 /* @forms_funcs{"namedItem"} */
ab432b
 static JSBool
ab432b
-forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+forms_namedItem(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	JSObject *parent_doc;	/* instance of @document_class */
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	struct document_view *doc_view;
ab432b
 
ab432b
@@ -1481,8 +1546,9 @@ forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
ab432b
 	if (argc != 1)
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	undef_to_jsval(ctx, rval);
ab432b
-	find_form_by_name(ctx, parent_doc, doc_view, argv[0], rval);
ab432b
+	undef_to_jsval(ctx, &val;;
ab432b
+	find_form_by_name(ctx, parent_doc, doc_view, argv[0], &val;;
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
@@ -1519,13 +1585,13 @@ static unicode_val_T
ab432b
 jsval_to_accesskey(JSContext *ctx, jsval *vp)
ab432b
 {
ab432b
 	size_t len;
ab432b
-	const jschar *chr;
ab432b
+	const char *chr;
ab432b
 
ab432b
 	/* Convert the value in place, to protect the result from GC.  */
ab432b
 	if (JS_ConvertValue(ctx, *vp, JSTYPE_STRING, vp) == JS_FALSE)
ab432b
 		return UCS_NO_CHAR;
ab432b
-	len = JS_GetStringLength(JSVAL_TO_STRING(*vp));
ab432b
-	chr = JS_GetStringChars(JSVAL_TO_STRING(*vp));
ab432b
+	len = JS_GetStringEncodingLength(ctx, JSVAL_TO_STRING(*vp));
ab432b
+	chr = JS_EncodeString(ctx, JSVAL_TO_STRING(*vp));
ab432b
 
ab432b
 	/* This implementation ignores extra characters in the string.  */
ab432b
 	if (len < 1)
ab432b
diff --git a/src/ecmascript/spidermonkey/location.c b/src/ecmascript/spidermonkey/location.c
ab432b
index dd5b40b..752a890 100644
ab432b
--- a/src/ecmascript/spidermonkey/location.c
ab432b
+++ b/src/ecmascript/spidermonkey/location.c
ab432b
@@ -45,15 +45,15 @@
ab432b
 #include "viewer/text/vs.h"
ab432b
 
ab432b
 
ab432b
-static JSBool history_back(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool history_forward(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool history_go(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool history_back(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool history_forward(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool history_go(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 const JSClass history_class = {
ab432b
 	"history",
ab432b
 	JSCLASS_HAS_PRIVATE,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	JS_PropertyStub, JS_PropertyStub,
ab432b
+	JS_PropertyStub, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
 };
ab432b
 
ab432b
@@ -66,7 +66,7 @@ const spidermonkeyFunctionSpec history_funcs[] = {
ab432b
 
ab432b
 /* @history_funcs{"back"} */
ab432b
 static JSBool
ab432b
-history_back(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+history_back(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
 	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
ab432b
 	struct document_view *doc_view = interpreter->vs->doc_view;
ab432b
@@ -83,7 +83,7 @@ history_back(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
ab432b
 
ab432b
 /* @history_funcs{"forward"} */
ab432b
 static JSBool
ab432b
-history_forward(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+history_forward(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
 	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
ab432b
 	struct document_view *doc_view = interpreter->vs->doc_view;
ab432b
@@ -96,11 +96,12 @@ history_forward(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
ab432b
 
ab432b
 /* @history_funcs{"go"} */
ab432b
 static JSBool
ab432b
-history_go(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+history_go(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
 	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
ab432b
 	struct document_view *doc_view = interpreter->vs->doc_view;
ab432b
 	struct session *ses = doc_view->session;
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	int index;
ab432b
 	struct location *loc;
ab432b
 
ab432b
@@ -124,8 +125,8 @@ history_go(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 }
ab432b
 
ab432b
 
ab432b
-static JSBool location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
-static JSBool location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool location_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
+static JSBool location_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
ab432b
 
ab432b
 /* Each @location_class object must have a @window_class parent.  */
ab432b
 const JSClass location_class = {
ab432b
@@ -150,7 +151,7 @@ const JSPropertySpec location_props[] = {
ab432b
 
ab432b
 /* @location_class.getProperty */
ab432b
 static JSBool
ab432b
-location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+location_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -167,12 +168,12 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	vs = JS_GetInstancePrivate(ctx, parent_win,
ab432b
 				   (JSClass *) &window_class, NULL);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_LOC_HREF:
ab432b
 		astring_to_jsval(ctx, vp, get_uri_string(vs->uri, URI_ORIGINAL));
ab432b
 		break;
ab432b
@@ -191,7 +192,7 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @location_class.setProperty */
ab432b
 static JSBool
ab432b
-location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+location_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -210,10 +211,10 @@ location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 				   (JSClass *) &window_class, NULL);
ab432b
 	doc_view = vs->doc_view;
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_LOC_HREF:
ab432b
 		location_goto(doc_view, jsval_to_string(ctx, vp));
ab432b
 		break;
ab432b
@@ -222,7 +223,7 @@ location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
-static JSBool location_toString(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool location_toString(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 const spidermonkeyFunctionSpec location_funcs[] = {
ab432b
 	{ "toString",		location_toString,	0 },
ab432b
@@ -232,7 +233,12 @@ const spidermonkeyFunctionSpec location_funcs[] = {
ab432b
 
ab432b
 /* @location_funcs{"toString"}, @location_funcs{"toLocaleString"} */
ab432b
 static JSBool
ab432b
-location_toString(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+location_toString(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
-	return JS_GetProperty(ctx, obj, "href", rval);
ab432b
+	jsval val;
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	JSBool ret = JS_GetProperty(ctx, obj, "href", &val;;
ab432b
+
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
+	return ret;
ab432b
 }
ab432b
diff --git a/src/ecmascript/spidermonkey/navigator.c b/src/ecmascript/spidermonkey/navigator.c
ab432b
index a009d62..e08a224 100644
ab432b
--- a/src/ecmascript/spidermonkey/navigator.c
ab432b
+++ b/src/ecmascript/spidermonkey/navigator.c
ab432b
@@ -44,13 +44,13 @@
ab432b
 #include "viewer/text/vs.h"
ab432b
 
ab432b
 
ab432b
-static JSBool navigator_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool navigator_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
 
ab432b
 const JSClass navigator_class = {
ab432b
 	"navigator",
ab432b
 	JSCLASS_HAS_PRIVATE,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	navigator_get_property, JS_PropertyStub,
ab432b
+	navigator_get_property, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
 };
ab432b
 
ab432b
@@ -81,14 +81,14 @@ const JSPropertySpec navigator_props[] = {
ab432b
 
ab432b
 /* @navigator_class.getProperty */
ab432b
 static JSBool
ab432b
-navigator_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+navigator_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_NAVIGATOR_APP_CODENAME:
ab432b
 		string_to_jsval(ctx, vp, "Mozilla"); /* More like a constant nowadays. */
ab432b
 		break;
ab432b
diff --git a/src/ecmascript/spidermonkey/unibar.c b/src/ecmascript/spidermonkey/unibar.c
ab432b
index 3c290a3..576c0a7 100644
ab432b
--- a/src/ecmascript/spidermonkey/unibar.c
ab432b
+++ b/src/ecmascript/spidermonkey/unibar.c
ab432b
@@ -45,8 +45,8 @@
ab432b
 #include "viewer/text/vs.h"
ab432b
 
ab432b
 
ab432b
-static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
-static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
+static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
ab432b
 
ab432b
 /* Each @menubar_class object must have a @window_class parent.  */
ab432b
 const JSClass menubar_class = {
ab432b
@@ -80,7 +80,7 @@ const JSPropertySpec unibar_props[] = {
ab432b
 
ab432b
 /* @menubar_class.getProperty, @statusbar_class.getProperty */
ab432b
 static JSBool
ab432b
-unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -104,10 +104,10 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	status = &doc_view->session->status;
ab432b
 	bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_UNIBAR_VISIBLE:
ab432b
 #define unibar_fetch(bar) \
ab432b
 	boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
ab432b
@@ -139,7 +139,7 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @menubar_class.setProperty, @statusbar_class.setProperty */
ab432b
 static JSBool
ab432b
-unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	JSObject *parent_win;	/* instance of @window_class */
ab432b
 	struct view_state *vs;
ab432b
@@ -163,10 +163,10 @@ unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	status = &doc_view->session->status;
ab432b
 	bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_UNIBAR_VISIBLE:
ab432b
 		switch (*bar) {
ab432b
 		case 's':
ab432b
diff --git a/src/ecmascript/spidermonkey/window.c b/src/ecmascript/spidermonkey/window.c
ab432b
index 5e93a6f..9bc8dd9 100644
ab432b
--- a/src/ecmascript/spidermonkey/window.c
ab432b
+++ b/src/ecmascript/spidermonkey/window.c
ab432b
@@ -44,12 +44,12 @@
ab432b
 #include "viewer/text/vs.h"
ab432b
 
ab432b
 
ab432b
-static JSBool window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
-static JSBool window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
ab432b
+static JSBool window_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
ab432b
+static JSBool window_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
ab432b
 
ab432b
 const JSClass window_class = {
ab432b
 	"window",
ab432b
-	JSCLASS_HAS_PRIVATE,	/* struct view_state * */
ab432b
+	JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,	/* struct view_state * */
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
 	window_get_property, window_set_property,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
@@ -122,7 +122,7 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
ab432b
 
ab432b
 /* @window_class.getProperty */
ab432b
 static JSBool
ab432b
-window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+window_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	struct view_state *vs;
ab432b
 
ab432b
@@ -138,11 +138,11 @@ window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	 * location is then evaluated in string context, toString()
ab432b
 	 * is called which we overrode for that class below, so
ab432b
 	 * everything's fine. */
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
 		struct document_view *doc_view = vs->doc_view;
ab432b
 		JSObject *obj;
ab432b
 
ab432b
-		obj = try_resolve_frame(doc_view, jsval_to_string(ctx, &id));
ab432b
+		obj = try_resolve_frame(doc_view, jsid_to_string(ctx, &id));
ab432b
 		/* TODO: Try other lookups (mainly element lookup) until
ab432b
 		 * something yields data. */
ab432b
 		if (obj) {
ab432b
@@ -151,12 +151,12 @@ window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_WIN_CLOSED:
ab432b
 		/* TODO: It will be a major PITA to implement this properly.
ab432b
 		 * Well, perhaps not so much if we introduce reference tracking
ab432b
@@ -252,7 +252,7 @@ found_parent:
ab432b
 
ab432b
 /* @window_class.setProperty */
ab432b
 static JSBool
ab432b
-window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+window_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	struct view_state *vs;
ab432b
 
ab432b
@@ -264,8 +264,8 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	vs = JS_GetInstancePrivate(ctx, obj, (JSClass *) &window_class, NULL);
ab432b
 
ab432b
-	if (JSVAL_IS_STRING(id)) {
ab432b
-		if (!strcmp(jsval_to_string(ctx, &id), "location")) {
ab432b
+	if (JSID_IS_STRING(id)) {
ab432b
+		if (!strcmp(jsid_to_string(ctx, &id), "location")) {
ab432b
 			struct document_view *doc_view = vs->doc_view;
ab432b
 
ab432b
 			location_goto(doc_view, jsval_to_string(ctx, vp));
ab432b
@@ -276,10 +276,10 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 		return JS_TRUE;
ab432b
 	}
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case JSP_WIN_STATUS:
ab432b
 		mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, vp)));
ab432b
 		print_screen_status(vs->doc_view->session);
ab432b
@@ -296,9 +296,9 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 }
ab432b
 
ab432b
 
ab432b
-static JSBool window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
-static JSBool window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
ab432b
+static JSBool window_alert(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool window_open(JSContext *ctx, uintN argc, jsval *rval);
ab432b
+static JSBool window_setTimeout(JSContext *ctx, uintN argc, jsval *rval);
ab432b
 
ab432b
 const spidermonkeyFunctionSpec window_funcs[] = {
ab432b
 	{ "alert",	window_alert,		1 },
ab432b
@@ -309,8 +309,11 @@ const spidermonkeyFunctionSpec window_funcs[] = {
ab432b
 
ab432b
 /* @window_funcs{"alert"} */
ab432b
 static JSBool
ab432b
-window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+window_alert(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	unsigned char *string;
ab432b
 
ab432b
@@ -328,14 +331,18 @@ window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
ab432b
 	info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
ab432b
 		N_("JavaScript Alert"), ALIGN_CENTER, stracpy(string));
ab432b
 
ab432b
-	undef_to_jsval(ctx, rval);
ab432b
+	undef_to_jsval(ctx, &val;;
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @window_funcs{"open"} */
ab432b
 static JSBool
ab432b
-window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+window_open(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
+	JSObject *obj = JS_THIS_OBJECT(ctx, rval);
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct view_state *vs;
ab432b
 	struct document_view *doc_view;
ab432b
 	struct session *ses;
ab432b
@@ -405,7 +412,7 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 			deo->uri = get_uri_reference(uri);
ab432b
 			deo->target = stracpy(frame);
ab432b
 			register_bottom_half(delayed_goto_uri_frame, deo);
ab432b
-			boolean_to_jsval(ctx, rval, 1);
ab432b
+			boolean_to_jsval(ctx, &val, 1);
ab432b
 			goto end;
ab432b
 		}
ab432b
 	}
ab432b
@@ -416,7 +423,7 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 	    && can_open_in_new(ses->tab->term)) {
ab432b
 		open_uri_in_new_window(ses, uri, NULL, ENV_ANY,
ab432b
 				       CACHE_MODE_NORMAL, TASK_NONE);
ab432b
-		boolean_to_jsval(ctx, rval, 1);
ab432b
+		boolean_to_jsval(ctx, &val, 1);
ab432b
 	} else {
ab432b
 		/* When opening a new tab, we might get rerendered, losing our
ab432b
 		 * context and triggerring a disaster, so postpone that. */
ab432b
@@ -426,9 +433,9 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
 			deo->ses = ses;
ab432b
 			deo->uri = get_uri_reference(uri);
ab432b
 			register_bottom_half(delayed_open, deo);
ab432b
-			boolean_to_jsval(ctx, rval, 1);
ab432b
+			boolean_to_jsval(ctx, &val, 1);
ab432b
 		} else {
ab432b
-			undef_to_jsval(ctx, rval);
ab432b
+			undef_to_jsval(ctx, &val;;
ab432b
 		}
ab432b
 	}
ab432b
 
ab432b
@@ -436,13 +443,15 @@ end:
ab432b
 	done_uri(uri);
ab432b
 	mem_free_if(frame);
ab432b
 
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @window_funcs{"setTimeout"} */
ab432b
 static JSBool
ab432b
-window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+window_setTimeout(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
ab432b
 	unsigned char *code;
ab432b
 	int timeout;
ab432b
diff --git a/src/scripting/smjs/action_object.c b/src/scripting/smjs/action_object.c
ab432b
index d95564d..d0379e0 100644
ab432b
--- a/src/scripting/smjs/action_object.c
ab432b
+++ b/src/scripting/smjs/action_object.c
ab432b
@@ -42,25 +42,31 @@ smjs_action_fn_finalize(JSContext *ctx, JSObject *obj)
ab432b
 
ab432b
 /* @action_fn_class.call */
ab432b
 static JSBool
ab432b
-smjs_action_fn_callback(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
-                        jsval *rval)
ab432b
+smjs_action_fn_callback(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval value;
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct smjs_action_fn_callback_hop *hop;
ab432b
 	JSObject *fn_obj;
ab432b
 
ab432b
 	assert(smjs_ctx);
ab432b
 	if_assert_failed return JS_FALSE;
ab432b
 
ab432b
-	*rval = JS_FALSE;
ab432b
+	value = JS_FALSE;
ab432b
 
ab432b
-	if (JS_TRUE != JS_ValueToObject(ctx, argv[-2], &fn_obj))
ab432b
+	if (JS_TRUE != JS_ValueToObject(ctx, argv[-2], &fn_obj)) {
ab432b
+		JS_SET_RVAL(ctx, rval, value);
ab432b
 		return JS_TRUE;
ab432b
+	}
ab432b
 	assert(JS_InstanceOf(ctx, fn_obj, (JSClass *) &action_fn_class, NULL));
ab432b
 	if_assert_failed return JS_FALSE;
ab432b
 
ab432b
 	hop = JS_GetInstancePrivate(ctx, fn_obj,
ab432b
 				    (JSClass *) &action_fn_class, NULL);
ab432b
-	if (!hop) return JS_TRUE;
ab432b
+	if (!hop) {
ab432b
+		JS_SET_RVAL(ctx, rval, value);
ab432b
+		return JS_TRUE;
ab432b
+	}
ab432b
 
ab432b
 	if (!would_window_receive_keypresses(hop->ses->tab)) {
ab432b
 		/* The user cannot run actions in this tab by pressing
ab432b
@@ -98,7 +104,8 @@ smjs_action_fn_callback(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
 
ab432b
 	do_action(hop->ses, hop->action_id, 1);
ab432b
 
ab432b
-	*rval = JS_TRUE;
ab432b
+	value = JS_TRUE;
ab432b
+	JS_SET_RVAL(ctx, rval, value);
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
@@ -107,7 +114,7 @@ static const JSClass action_fn_class = {
ab432b
 	"action_fn",
ab432b
 	JSCLASS_HAS_PRIVATE,	/* struct smjs_action_fn_callback_hop * */
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	JS_PropertyStub, JS_PropertyStub,
ab432b
+	JS_PropertyStub, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,
ab432b
 	smjs_action_fn_finalize,
ab432b
 	NULL, NULL,
ab432b
@@ -152,14 +159,16 @@ smjs_get_action_fn_object(unsigned char *action_str)
ab432b
 
ab432b
 /* @action_class.getProperty */
ab432b
 static JSBool
ab432b
-action_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+action_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
+	jsval val;
ab432b
 	JSObject *action_fn;
ab432b
 	unsigned char *action_str;
ab432b
 
ab432b
 	*vp = JSVAL_NULL;
ab432b
 
ab432b
-	action_str = JS_GetStringBytes(JS_ValueToString(ctx, id));
ab432b
+	JS_IdToValue(ctx, id, &val;;
ab432b
+	action_str = JS_EncodeString(ctx, JS_ValueToString(ctx, val));
ab432b
 	if (!action_str) return JS_TRUE;
ab432b
 
ab432b
 	action_fn = smjs_get_action_fn_object(action_str);
ab432b
@@ -174,7 +183,7 @@ static const JSClass action_class = {
ab432b
 	"action",
ab432b
 	0,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	action_get_property, JS_PropertyStub,
ab432b
+	action_get_property, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
ab432b
 };
ab432b
 
ab432b
diff --git a/src/scripting/smjs/bookmarks.c b/src/scripting/smjs/bookmarks.c
ab432b
index f12f84b..6c8b7fa 100644
ab432b
--- a/src/scripting/smjs/bookmarks.c
ab432b
+++ b/src/scripting/smjs/bookmarks.c
ab432b
@@ -113,29 +113,29 @@ jsval_to_bookmark_string(JSContext *ctx, jsval val, unsigned char **result)
ab432b
 	unsigned char *str;
ab432b
 
ab432b
 	/* jsstring_to_utf8() might GC; protect the string to come.  */
ab432b
-	if (!JS_AddNamedRoot(ctx, &jsstr, "jsval_to_bookmark_string"))
ab432b
+	if (!JS_AddNamedStringRoot(ctx, &jsstr, "jsval_to_bookmark_string"))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
 	jsstr = JS_ValueToString(ctx, val);
ab432b
 	if (jsstr == NULL) {
ab432b
-		JS_RemoveRoot(ctx, &jsstr);
ab432b
+		JS_RemoveStringRoot(ctx, &jsstr);
ab432b
 		return JS_FALSE;
ab432b
 	}
ab432b
 
ab432b
 	str = jsstring_to_utf8(ctx, jsstr, NULL);
ab432b
 	if (str == NULL) {
ab432b
-		JS_RemoveRoot(ctx, &jsstr);
ab432b
+		JS_RemoveStringRoot(ctx, &jsstr);
ab432b
 		return JS_FALSE;
ab432b
 	}
ab432b
 
ab432b
-	JS_RemoveRoot(ctx, &jsstr);
ab432b
+	JS_RemoveStringRoot(ctx, &jsstr);
ab432b
 	mem_free_set(result, str);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @bookmark_class.getProperty */
ab432b
 static JSBool
ab432b
-bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+bookmark_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	struct bookmark *bookmark;
ab432b
 
ab432b
@@ -152,10 +152,10 @@ bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case BOOKMARK_TITLE:
ab432b
 		return bookmark_string_to_jsval(ctx, bookmark->title, vp);
ab432b
 	case BOOKMARK_URL:
ab432b
@@ -177,7 +177,7 @@ bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @bookmark_class.setProperty */
ab432b
 static JSBool
ab432b
-bookmark_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+bookmark_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	struct bookmark *bookmark;
ab432b
 	unsigned char *title = NULL;
ab432b
@@ -195,10 +195,10 @@ bookmark_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	if (!bookmark) return JS_FALSE;
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case BOOKMARK_TITLE:
ab432b
 		if (!jsval_to_bookmark_string(ctx, *vp, &title))
ab432b
 			return JS_FALSE;
ab432b
@@ -250,7 +250,7 @@ smjs_get_bookmark_object(struct bookmark *bookmark)
ab432b
 
ab432b
 /* @bookmark_folder_class.getProperty */
ab432b
 static JSBool
ab432b
-bookmark_folder_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+bookmark_folder_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	struct bookmark *bookmark;
ab432b
 	struct bookmark *folder;
ab432b
@@ -283,7 +283,7 @@ static const JSClass bookmark_folder_class = {
ab432b
 	"bookmark_folder",
ab432b
 	JSCLASS_HAS_PRIVATE,	/* struct bookmark * */
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	bookmark_folder_get_property, JS_PropertyStub,
ab432b
+	bookmark_folder_get_property, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, bookmark_finalize,
ab432b
 };
ab432b
 
ab432b
diff --git a/src/scripting/smjs/cache_object.c b/src/scripting/smjs/cache_object.c
ab432b
index cd23842..0bdb563 100644
ab432b
--- a/src/scripting/smjs/cache_object.c
ab432b
+++ b/src/scripting/smjs/cache_object.c
ab432b
@@ -40,7 +40,7 @@ static const JSPropertySpec cache_entry_props[] = {
ab432b
 
ab432b
 /* @cache_entry_class.getProperty */
ab432b
 static JSBool
ab432b
-cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+cache_entry_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	struct cache_entry *cached;
ab432b
 	JSBool ret;
ab432b
@@ -66,9 +66,9 @@ cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		ret = JS_FALSE;
ab432b
-	else switch (JSVAL_TO_INT(id)) {
ab432b
+	else switch (JSID_TO_INT(id)) {
ab432b
 	case CACHE_ENTRY_CONTENT: {
ab432b
 		struct fragment *fragment = get_cache_fragment(cached);
ab432b
 
ab432b
@@ -121,7 +121,7 @@ cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @cache_entry_class.setProperty */
ab432b
 static JSBool
ab432b
-cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+cache_entry_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	struct cache_entry *cached;
ab432b
 	JSBool ret;
ab432b
@@ -145,12 +145,12 @@ cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	 * eventually unlock the object.  */
ab432b
 	object_lock(cached);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		ret = JS_FALSE;
ab432b
-	else switch (JSVAL_TO_INT(id)) {
ab432b
+	else switch (JSID_TO_INT(id)) {
ab432b
 	case CACHE_ENTRY_CONTENT: {
ab432b
 		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
ab432b
-		unsigned char *str = JS_GetStringBytes(jsstr);
ab432b
+		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 		size_t len = JS_GetStringLength(jsstr);
ab432b
 
ab432b
 		add_fragment(cached, 0, str, len);
ab432b
@@ -161,7 +161,7 @@ cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	}
ab432b
 	case CACHE_ENTRY_TYPE: {
ab432b
 		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
ab432b
-		unsigned char *str = JS_GetStringBytes(jsstr);
ab432b
+		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 		mem_free_set(&cached->content_type, stracpy(str));
ab432b
 
ab432b
@@ -170,7 +170,7 @@ cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	}
ab432b
 	case CACHE_ENTRY_HEAD: {
ab432b
 		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
ab432b
-		unsigned char *str = JS_GetStringBytes(jsstr);
ab432b
+		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 		mem_free_set(&cached->head, stracpy(str));
ab432b
 
ab432b
diff --git a/src/scripting/smjs/core.c b/src/scripting/smjs/core.c
ab432b
index 2493904..ced28b0 100644
ab432b
--- a/src/scripting/smjs/core.c
ab432b
+++ b/src/scripting/smjs/core.c
ab432b
@@ -94,11 +94,11 @@ smjs_do_file(unsigned char *path)
ab432b
 }
ab432b
 
ab432b
 static JSBool
ab432b
-smjs_do_file_wrapper(JSContext *ctx, JSObject *obj, uintN argc,
ab432b
-                     jsval *argv, jsval *rval)
ab432b
+smjs_do_file_wrapper(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	JSString *jsstr = JS_ValueToString(smjs_ctx, *argv);
ab432b
-	unsigned char *path = JS_GetStringBytes(jsstr);
ab432b
+	unsigned char *path = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 	if (smjs_do_file(path))
ab432b
 		return JS_TRUE;
ab432b
@@ -136,6 +136,9 @@ init_smjs(struct module *module)
ab432b
 		return;
ab432b
 	}
ab432b
 
ab432b
+	JS_SetOptions(smjs_ctx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
ab432b
+	JS_SetVersion(smjs_ctx, JSVERSION_LATEST);
ab432b
+
ab432b
 	JS_SetErrorReporter(smjs_ctx, error_reporter);
ab432b
 
ab432b
 	smjs_init_global_object();
ab432b
@@ -308,7 +311,7 @@ jsstring_to_utf8(JSContext *ctx, JSString *jsstr, int *length)
ab432b
 	struct string utf8;
ab432b
 
ab432b
 	utf16_len = JS_GetStringLength(jsstr);
ab432b
-	utf16 = JS_GetStringChars(jsstr); /* stays owned by jsstr */
ab432b
+	utf16 = JS_GetStringCharsZ(ctx, jsstr); /* stays owned by jsstr */
ab432b
 	if (utf16 == NULL) {
ab432b
 		/* JS_GetStringChars doesn't have a JSContext *
ab432b
 		 * parameter so it can't report the error
ab432b
diff --git a/src/scripting/smjs/elinks_object.c b/src/scripting/smjs/elinks_object.c
ab432b
index 5a9b394..3c51ec9 100644
ab432b
--- a/src/scripting/smjs/elinks_object.c
ab432b
+++ b/src/scripting/smjs/elinks_object.c
ab432b
@@ -27,7 +27,7 @@
ab432b
 
ab432b
 
ab432b
 static JSBool
ab432b
-elinks_get_home(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+elinks_get_home(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, elinks_home));
ab432b
 
ab432b
@@ -35,7 +35,7 @@ elinks_get_home(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 }
ab432b
 
ab432b
 static JSBool
ab432b
-elinks_get_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+elinks_get_location(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	struct uri *uri;
ab432b
 
ab432b
@@ -51,7 +51,7 @@ elinks_get_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 }
ab432b
 
ab432b
 static JSBool
ab432b
-elinks_set_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+elinks_set_location(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	JSString *jsstr;
ab432b
 	unsigned char *url;
ab432b
@@ -61,7 +61,7 @@ elinks_set_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	jsstr = JS_ValueToString(smjs_ctx, *vp);
ab432b
 	if (!jsstr) return JS_FALSE;
ab432b
 
ab432b
-	url = JS_GetStringBytes(jsstr);
ab432b
+	url = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 	if (!url) return JS_FALSE;
ab432b
 
ab432b
 	goto_url(smjs_ses, url);
ab432b
@@ -71,8 +71,10 @@ elinks_set_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @elinks_funcs{"alert"} */
ab432b
 static JSBool
ab432b
-elinks_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+elinks_alert(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	unsigned char *string;
ab432b
 
ab432b
 	if (argc != 1)
ab432b
@@ -85,15 +87,18 @@ elinks_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
ab432b
 	info_box(smjs_ses->tab->term, MSGBOX_NO_TEXT_INTL,
ab432b
 	         N_("User script alert"), ALIGN_LEFT, string);
ab432b
 
ab432b
-	undef_to_jsval(ctx, rval);
ab432b
+	undef_to_jsval(ctx, &val;;
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
 /* @elinks_funcs{"execute"} */
ab432b
 static JSBool
ab432b
-elinks_execute(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ab432b
+elinks_execute(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval val;
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	unsigned char *string;
ab432b
 
ab432b
 	if (argc != 1)
ab432b
@@ -104,8 +109,9 @@ elinks_execute(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
ab432b
 		return JS_TRUE;
ab432b
 
ab432b
 	exec_on_terminal(smjs_ses->tab->term, string, "", TERM_EXEC_BG);
ab432b
-	undef_to_jsval(ctx, rval);
ab432b
 
ab432b
+	undef_to_jsval(ctx, &val;;
ab432b
+	JS_SET_RVAL(ctx, rval, val);
ab432b
 	return JS_TRUE;
ab432b
 }
ab432b
 
ab432b
@@ -113,7 +119,7 @@ static const JSClass elinks_class = {
ab432b
 	"elinks",
ab432b
 	0,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	JS_PropertyStub, JS_PropertyStub,
ab432b
+	JS_PropertyStub, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
 };
ab432b
 
ab432b
@@ -142,7 +148,7 @@ smjs_get_elinks_object(void)
ab432b
 		return NULL;
ab432b
 
ab432b
 	if (!JS_DefineProperty(smjs_ctx, jsobj, "home", JSVAL_NULL,
ab432b
-			       elinks_get_home, JS_PropertyStub,
ab432b
+			       elinks_get_home, JS_StrictPropertyStub,
ab432b
 			       JSPROP_ENUMERATE
ab432b
 			       | JSPROP_PERMANENT
ab432b
 			       | JSPROP_READONLY))
ab432b
diff --git a/src/scripting/smjs/global_object.c b/src/scripting/smjs/global_object.c
ab432b
index 3a59782..0976f8a 100644
ab432b
--- a/src/scripting/smjs/global_object.c
ab432b
+++ b/src/scripting/smjs/global_object.c
ab432b
@@ -16,9 +16,9 @@ JSObject *smjs_global_object;
ab432b
 
ab432b
 
ab432b
 static const JSClass global_class = {
ab432b
-	"global", 0,
ab432b
-	JS_PropertyStub, JS_PropertyStub,
ab432b
+	"global", JSCLASS_GLOBAL_FLAGS,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
+	JS_PropertyStub, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
ab432b
 };
ab432b
 
ab432b
@@ -29,7 +29,7 @@ smjs_get_global_object(void)
ab432b
 
ab432b
 	assert(smjs_ctx);
ab432b
 
ab432b
-	jsobj  = JS_NewObject(smjs_ctx, (JSClass *) &global_class, NULL, NULL);
ab432b
+	jsobj  = JS_NewCompartmentAndGlobalObject(smjs_ctx, (JSClass *) &global_class, NULL);
ab432b
 
ab432b
 	if (!jsobj) return NULL;
ab432b
 
ab432b
diff --git a/src/scripting/smjs/globhist.c b/src/scripting/smjs/globhist.c
ab432b
index 0ab6938..376c44e 100644
ab432b
--- a/src/scripting/smjs/globhist.c
ab432b
+++ b/src/scripting/smjs/globhist.c
ab432b
@@ -51,7 +51,7 @@ static const JSPropertySpec smjs_globhist_item_props[] = {
ab432b
 
ab432b
 /* @smjs_globhist_item_class.getProperty */
ab432b
 static JSBool
ab432b
-smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsval id,
ab432b
+smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsid id,
ab432b
                                 jsval *vp)
ab432b
 {
ab432b
 	struct global_history_item *history_item;
ab432b
@@ -70,10 +70,10 @@ smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsval id,
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case GLOBHIST_TITLE:
ab432b
 		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx,
ab432b
 		                                        history_item->title));
ab432b
@@ -117,7 +117,7 @@ smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsval id,
ab432b
 
ab432b
 /* @smjs_globhist_item_class.setProperty */
ab432b
 static JSBool
ab432b
-smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	struct global_history_item *history_item;
ab432b
 
ab432b
@@ -133,13 +133,13 @@ smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *
ab432b
 
ab432b
 	if (!history_item) return JS_FALSE;
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case GLOBHIST_TITLE: {
ab432b
 		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
ab432b
-		unsigned char *str = JS_GetStringBytes(jsstr);
ab432b
+		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 		mem_free_set(&history_item->title, stracpy(str));
ab432b
 
ab432b
@@ -147,7 +147,7 @@ smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *
ab432b
 	}
ab432b
 	case GLOBHIST_URL: {
ab432b
 		JSString *jsstr = JS_ValueToString(smjs_ctx, *vp);
ab432b
-		unsigned char *str = JS_GetStringBytes(jsstr);
ab432b
+		unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 		mem_free_set(&history_item->url, stracpy(str));
ab432b
 
ab432b
@@ -201,13 +201,13 @@ smjs_get_globhist_item_object(struct global_history_item *history_item)
ab432b
 
ab432b
 /* @smjs_globhist_class.getProperty */
ab432b
 static JSBool
ab432b
-smjs_globhist_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+smjs_globhist_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	JSObject *jsobj;
ab432b
 	unsigned char *uri_string;
ab432b
 	struct global_history_item *history_item;
ab432b
 
ab432b
-	uri_string = JS_GetStringBytes(JS_ValueToString(ctx, id));
ab432b
+	uri_string = JS_EncodeString(ctx, JS_ValueToString(ctx, id));
ab432b
 	if (!uri_string) goto ret_null;
ab432b
 
ab432b
 	history_item = get_global_history_item(uri_string);
ab432b
@@ -229,7 +229,7 @@ ret_null:
ab432b
 static const JSClass smjs_globhist_class = {
ab432b
 	"global_history", 0,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	smjs_globhist_get_property, JS_PropertyStub,
ab432b
+	smjs_globhist_get_property, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
ab432b
 };
ab432b
 
ab432b
diff --git a/src/scripting/smjs/hooks.c b/src/scripting/smjs/hooks.c
ab432b
index 291039c..d69daf6 100644
ab432b
--- a/src/scripting/smjs/hooks.c
ab432b
+++ b/src/scripting/smjs/hooks.c
ab432b
@@ -41,7 +41,7 @@ script_hook_url(va_list ap, void *data)
ab432b
 				ret = EVENT_HOOK_STATUS_LAST;
ab432b
 		} else {
ab432b
 			JSString *jsstr = JS_ValueToString(smjs_ctx, rval);
ab432b
-			unsigned char *str = JS_GetStringBytes(jsstr);
ab432b
+			unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 			mem_free_set(url, stracpy(str));
ab432b
 		}
ab432b
@@ -58,7 +58,7 @@ script_hook_pre_format_html(va_list ap, void *data)
ab432b
 	struct session *ses = va_arg(ap, struct session *);
ab432b
 	struct cache_entry *cached = va_arg(ap, struct cache_entry *);
ab432b
 	enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
ab432b
-	JSObject *cache_entry_object, *view_state_object = JSVAL_NULL;
ab432b
+	JSObject *cache_entry_object, *view_state_object = NULL;
ab432b
 	jsval args[2], rval;
ab432b
 
ab432b
 	evhook_use_params(ses && cached);
ab432b
diff --git a/src/scripting/smjs/keybinding.c b/src/scripting/smjs/keybinding.c
ab432b
index 2b35477..b452298 100644
ab432b
--- a/src/scripting/smjs/keybinding.c
ab432b
+++ b/src/scripting/smjs/keybinding.c
ab432b
@@ -17,7 +17,7 @@ static const JSClass keymap_class; /* defined below */
ab432b
 
ab432b
 /* @keymap_class.getProperty */
ab432b
 static JSBool
ab432b
-keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+keymap_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	unsigned char *action_str;
ab432b
 	const unsigned char *keystroke_str;
ab432b
@@ -32,7 +32,7 @@ keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	data = JS_GetInstancePrivate(ctx, obj,
ab432b
 				     (JSClass *) &keymap_class, NULL);
ab432b
 
ab432b
-	keystroke_str = JS_GetStringBytes(JS_ValueToString(ctx, id));
ab432b
+	keystroke_str = JS_EncodeString(ctx, JS_ValueToString(ctx, id));
ab432b
 	if (!keystroke_str) goto ret_null;
ab432b
 
ab432b
 	action_str = get_action_name_from_keystroke((enum keymap_id) *data,
ab432b
@@ -70,7 +70,7 @@ smjs_keybinding_action_callback(va_list ap, void *data)
ab432b
 
ab432b
 /* @keymap_class.setProperty */
ab432b
 static JSBool
ab432b
-keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+keymap_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	int *data;
ab432b
 	unsigned char *keymap_str;
ab432b
@@ -90,13 +90,13 @@ keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	keymap_str = get_keymap_name((enum keymap_id) *data);
ab432b
 	if (!keymap_str) return JS_FALSE;
ab432b
 
ab432b
-	keystroke_str = JS_GetStringBytes(JS_ValueToString(ctx, id));
ab432b
+	keystroke_str = JS_EncodeString(ctx, JS_ValueToString(ctx, id));
ab432b
 	if (!keystroke_str) return JS_FALSE;
ab432b
 
ab432b
 	if (JSVAL_IS_STRING(*vp)) {
ab432b
 		unsigned char *action_str;
ab432b
 
ab432b
-		action_str = JS_GetStringBytes(JS_ValueToString(ctx, *vp));
ab432b
+		action_str = JS_EncodeString(ctx, JS_ValueToString(ctx, *vp));
ab432b
 		if (!action_str) return JS_FALSE;
ab432b
 
ab432b
 		if (bind_do(keymap_str, keystroke_str, action_str, 0))
ab432b
@@ -203,7 +203,7 @@ static const JSClass keymaps_hash_class = {
ab432b
 	"keymaps_hash",
ab432b
 	JSCLASS_HAS_PRIVATE,
ab432b
 	JS_PropertyStub, JS_PropertyStub,
ab432b
-	JS_PropertyStub, JS_PropertyStub,
ab432b
+	JS_PropertyStub, JS_StrictPropertyStub,
ab432b
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
ab432b
 };
ab432b
 
ab432b
diff --git a/src/scripting/smjs/load_uri.c b/src/scripting/smjs/load_uri.c
ab432b
index 4f2dcf2..7e3881c 100644
ab432b
--- a/src/scripting/smjs/load_uri.c
ab432b
+++ b/src/scripting/smjs/load_uri.c
ab432b
@@ -56,7 +56,7 @@ smjs_loading_callback(struct download *download, void *data)
ab432b
 end:
ab432b
 	if (download->cached)
ab432b
 		object_unlock(download->cached);
ab432b
-	JS_RemoveRoot(smjs_ctx, &hop->callback);
ab432b
+	JS_RemoveValueRoot(smjs_ctx, &hop->callback);
ab432b
 	mem_free(download->data);
ab432b
 	mem_free(download);
ab432b
 
ab432b
@@ -64,9 +64,9 @@ end:
ab432b
 }
ab432b
 
ab432b
 static JSBool
ab432b
-smjs_load_uri(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
-              jsval *rval)
ab432b
+smjs_load_uri(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 {
ab432b
+	jsval *argv = JS_ARGV(ctx, rval);
ab432b
 	struct smjs_load_uri_hop *hop;
ab432b
 	struct download *download;
ab432b
 	JSString *jsstr;
ab432b
@@ -76,7 +76,7 @@ smjs_load_uri(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
 	if (argc < 2) return JS_FALSE;
ab432b
 
ab432b
 	jsstr = JS_ValueToString(smjs_ctx, argv[0]);
ab432b
-	uri_string = JS_GetStringBytes(jsstr);
ab432b
+	uri_string = JS_EncodeString(smjs_ctx, jsstr);
ab432b
 
ab432b
 	uri = get_uri(uri_string, 0);
ab432b
 	if (!uri) return JS_FALSE;
ab432b
@@ -96,7 +96,7 @@ smjs_load_uri(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
ab432b
 
ab432b
 	hop->callback = argv[1];
ab432b
 	hop->ses = smjs_ses;
ab432b
-	if (!JS_AddNamedRoot(smjs_ctx, &hop->callback,
ab432b
+	if (!JS_AddNamedValueRoot(smjs_ctx, &hop->callback,
ab432b
 			     "smjs_load_uri_hop.callback")) {
ab432b
 		mem_free(hop);
ab432b
 		mem_free(download);
ab432b
diff --git a/src/scripting/smjs/view_state_object.c b/src/scripting/smjs/view_state_object.c
ab432b
index 64f43ca..636b37b 100644
ab432b
--- a/src/scripting/smjs/view_state_object.c
ab432b
+++ b/src/scripting/smjs/view_state_object.c
ab432b
@@ -39,7 +39,7 @@ static const JSPropertySpec view_state_props[] = {
ab432b
 
ab432b
 /* @view_state_class.getProperty */
ab432b
 static JSBool
ab432b
-view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+view_state_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	struct view_state *vs;
ab432b
 
ab432b
@@ -54,10 +54,10 @@ view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 	undef_to_jsval(ctx, vp);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case VIEW_STATE_PLAIN:
ab432b
 		*vp = INT_TO_JSVAL(vs->plain);
ab432b
 
ab432b
@@ -80,7 +80,7 @@ view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 
ab432b
 /* @view_state_class.setProperty */
ab432b
 static JSBool
ab432b
-view_state_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+view_state_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
ab432b
 {
ab432b
 	struct view_state *vs;
ab432b
 
ab432b
@@ -93,10 +93,10 @@ view_state_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
 	vs = JS_GetInstancePrivate(ctx, obj,
ab432b
 				   (JSClass *) &view_state_class, NULL);
ab432b
 
ab432b
-	if (!JSVAL_IS_INT(id))
ab432b
+	if (!JSID_IS_INT(id))
ab432b
 		return JS_FALSE;
ab432b
 
ab432b
-	switch (JSVAL_TO_INT(id)) {
ab432b
+	switch (JSID_TO_INT(id)) {
ab432b
 	case VIEW_STATE_PLAIN: {
ab432b
 		vs->plain = atol(jsval_to_string(ctx, vp));
ab432b
 
ab432b
@@ -143,7 +143,7 @@ smjs_get_view_state_object(struct view_state *vs)
ab432b
 }
ab432b
 
ab432b
 static JSBool
ab432b
-smjs_elinks_get_view_state(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
ab432b
+smjs_elinks_get_view_state(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
ab432b
 {
ab432b
 	JSObject *vs_obj;
ab432b
 	struct view_state *vs;
ab432b
@@ -170,6 +170,6 @@ smjs_init_view_state_interface(void)
ab432b
 		return;
ab432b
 
ab432b
 	JS_DefineProperty(smjs_ctx, smjs_elinks_object, "vs", JSVAL_NULL,
ab432b
-	                smjs_elinks_get_view_state, JS_PropertyStub,
ab432b
+	                smjs_elinks_get_view_state, JS_StrictPropertyStub,
ab432b
 	                JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY);
ab432b
 }
ab432b
-- 
ab432b
1.7.4.2
ab432b
ab432b
From 32109054ce40067b8c55837fb69f1bc1249e38fd Mon Sep 17 00:00:00 2001
ab432b
From: witekfl <witekfl@poczta.onet.pl>
ab432b
Date: Mon, 25 Apr 2011 21:04:03 +0200
ab432b
Subject: [PATCH 3/4] SpiderMonkey: fix issue with javascript:history.back()
ab432b
ab432b
In history.back() and others set rval to NULL.
ab432b
Do not convert NULL to string in spidermoney_eval_stringback.
ab432b
ab432b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ab432b
---
ab432b
 src/ecmascript/spidermonkey.c          |    2 +-
ab432b
 src/ecmascript/spidermonkey/location.c |    3 +++
ab432b
 2 files changed, 4 insertions(+), 1 deletions(-)
ab432b
ab432b
diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c
ab432b
index 021e6bd..5360455 100644
ab432b
--- a/src/ecmascript/spidermonkey.c
ab432b
+++ b/src/ecmascript/spidermonkey.c
ab432b
@@ -303,7 +303,7 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
ab432b
 	if (ret == JS_FALSE) {
ab432b
 		return NULL;
ab432b
 	}
ab432b
-	if (JSVAL_IS_VOID(rval)) {
ab432b
+	if (JSVAL_IS_VOID(rval) || JSVAL_IS_NULL(rval)) {
ab432b
 		/* Undefined value. */
ab432b
 		return NULL;
ab432b
 	}
ab432b
diff --git a/src/ecmascript/spidermonkey/location.c b/src/ecmascript/spidermonkey/location.c
ab432b
index 752a890..d1fbdfb 100644
ab432b
--- a/src/ecmascript/spidermonkey/location.c
ab432b
+++ b/src/ecmascript/spidermonkey/location.c
ab432b
@@ -78,6 +78,7 @@ history_back(JSContext *ctx, uintN argc, jsval *rval)
ab432b
  * and return non zero for  to prevent
ab432b
  * "calculating" new link. Returned value 2 is changed to 0 in function
ab432b
  * spidermonkey_eval_boolback */
ab432b
+	JS_SET_RVAL(ctx, rval, JSVAL_NULL);
ab432b
 	return 2;
ab432b
 }
ab432b
 
ab432b
@@ -91,6 +92,7 @@ history_forward(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 
ab432b
 	go_unback(ses);
ab432b
 
ab432b
+	JS_SET_RVAL(ctx, rval, JSVAL_NULL);
ab432b
 	return 2;
ab432b
 }
ab432b
 
ab432b
@@ -121,6 +123,7 @@ history_go(JSContext *ctx, uintN argc, jsval *rval)
ab432b
 		index += index > 0 ? -1 : 1;
ab432b
 	}
ab432b
 
ab432b
+	JS_SET_RVAL(ctx, rval, JSVAL_NULL);
ab432b
 	return 2;
ab432b
 }
ab432b
 
ab432b
-- 
ab432b
1.7.4.4
ab432b
ab432b
ab432b
From 725e389837d565cc3f9e787bd268fa5933c7bbb6 Mon Sep 17 00:00:00 2001
ab432b
From: witekfl <witekfl@poczta.onet.pl>
ab432b
Date: Sun, 4 Mar 2012 18:20:48 +0100
ab432b
Subject: [PATCH 4/4] Check if hb is NULL.
ab432b
ab432b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ab432b
---
ab432b
 src/ecmascript/spidermonkey/heartbeat.c |    1 +
ab432b
 1 files changed, 1 insertions(+), 0 deletions(-)
ab432b
ab432b
diff --git a/src/ecmascript/spidermonkey/heartbeat.c b/src/ecmascript/spidermonkey/heartbeat.c
ab432b
index bf95d92..b3dff58 100644
ab432b
--- a/src/ecmascript/spidermonkey/heartbeat.c
ab432b
+++ b/src/ecmascript/spidermonkey/heartbeat.c
ab432b
@@ -111,6 +111,7 @@ add_heartbeat(struct ecmascript_interpreter *interpreter)
ab432b
 void
ab432b
 done_heartbeat(struct heartbeat *hb)
ab432b
 {
ab432b
+	if (!hb) return; /* add_heartbeat returned NULL */
ab432b
 	assert(hb->interpreter);
ab432b
 
ab432b
         /* Stop the heartbeat timer if this heartbeat is the only one. */
ab432b
-- 
ab432b
1.7.9.1
ab432b