Index: binaries/system/mozjs185-ps-debug-1.0.dll
===================================================================
Kann nicht anzeigen: Dateityp ist als binär angegeben.
svn:mime-type = application/octet-stream
Index: binaries/system/mozjs185-ps-release-1.0.dll
===================================================================
Kann nicht anzeigen: Dateityp ist als binär angegeben.
svn:mime-type = application/octet-stream
Index: build/premake/extern_libs4.lua
===================================================================
--- build/premake/extern_libs4.lua	(Revision 14578)
+++ build/premake/extern_libs4.lua	(Arbeitskopie)
@@ -562,38 +562,41 @@
 	},
 	spidermonkey = {
 		compile_settings = function()
-			if _OPTIONS["with-system-mozjs185"] then
-				if not _OPTIONS["android"] then
-					pkgconfig_cflags("mozjs185")
-				end
-				defines { "WITH_SYSTEM_MOZJS185" }
+			if _OPTIONS["with-system-mozjs24"] then
+				-- to be implemented when such system packages exist
+				--if not _OPTIONS["android"] then
+				--	pkgconfig_cflags("mozjs24")
+				--end
+				--defines { "WITH_SYSTEM_MOZJS24" }
 			else
 				if os.is("windows") then
 					include_dir = "include-win32"
 				elseif os.is("macosx") then
-					include_dir = "include"
+					include_dir = "include-unix"
 				else
 					include_dir = "include-unix"
 				end
 				configuration "Debug"
-					includedirs { libraries_source_dir.."spidermonkey/"..include_dir }
+					includedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-debug" }
+					defines { "DEBUG" }
 				configuration "Release"
-					includedirs { libraries_source_dir.."spidermonkey/"..include_dir }
+					includedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-release" }
 				configuration { }
 			end
 		end,
 		link_settings = function()
-			if _OPTIONS["with-system-mozjs185"] then
-				if _OPTIONS["android"] then
-					links { "mozjs185-1.0" }
-				else
-					pkgconfig_libs("mozjs185")
-				end
+			if _OPTIONS["with-system-mozjs24"] then
+				-- to be implemented when such system packages exist
+				--if _OPTIONS["android"] then
+				--	links { "mozjs185-1.0" }
+				--else
+				--	pkgconfig_libs("mozjs185")
+				--end
 			else
 				configuration "Debug"
-					links { "mozjs185-ps-debug" }
+					links { "mozjs24-ps-debug" }
 				configuration "Release"
-					links { "mozjs185-ps-release" }
+					links { "mozjs24-ps-release" }
 				configuration { }
 				add_source_lib_paths("spidermonkey")
 			end
Index: build/premake/premake4.lua
===================================================================
--- build/premake/premake4.lua	(Revision 14578)
+++ build/premake/premake4.lua	(Arbeitskopie)
@@ -15,7 +15,7 @@
 newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" }
 newoption { trigger = "with-system-enet", description = "Search standard paths for libenet, instead of using bundled copy" }
 newoption { trigger = "with-system-miniupnpc", description = "Search standard paths for libminiupnpc, instead of using bundled copy" }
-newoption { trigger = "with-system-mozjs185", description = "Search standard paths for libmozjs185, instead of using bundled copy" }
+newoption { trigger = "with-system-mozjs24", description = "Search standard paths for libmozjs24, instead of using bundled copy" }
 newoption { trigger = "with-c++11", description = "Enable C++11 on GCC" }
 newoption { trigger = "sysroot", description = "Set compiler system root path, used for building against a non-system SDK. For example /usr/local becomes SYSROOT/user/local" }
 newoption { trigger = "macosx-version-min", description = "Set minimum required version of the OS X API, the build will possibly fail if an older SDK is used, while newer API functions will be weakly linked (i.e. resolved at runtime)" }
Index: source/simulation2/serialization/BinarySerializer.h
===================================================================
--- source/simulation2/serialization/BinarySerializer.h	(Revision 14578)
+++ source/simulation2/serialization/BinarySerializer.h	(Arbeitskopie)
@@ -20,8 +20,6 @@
 
 #include "ISerializer.h"
 
-#include "scriptinterface/AutoRooters.h"
-
 #include "lib/byte_order.h"
 #include "lib/allocators/arena.h"
 
@@ -73,7 +71,7 @@
 	u32 m_ScriptBackrefsNext;
 	u32 GetScriptBackrefTag(JSObject* obj);
 
-	AutoGCRooter m_Rooter;
+	JS::AutoObjectVector m_Rooter;
 
 	std::map<JSObject*, std::wstring> m_SerializablePrototypes;
 
Index: source/simulation2/serialization/StdDeserializer.cpp
===================================================================
--- source/simulation2/serialization/StdDeserializer.cpp	(Revision 14578)
+++ source/simulation2/serialization/StdDeserializer.cpp	(Arbeitskopie)
@@ -25,37 +25,8 @@
 #include "scriptinterface/ScriptInterface.h"
 #include "scriptinterface/ScriptExtraHeaders.h" // for typed arrays
 
-#include "js/jsapi.h"
-
 #include "lib/byte_order.h"
 
-static uint32 GetJSArrayType(u8 arrayType)
-{
-	switch(arrayType)
-	{
-	case SCRIPT_TYPED_ARRAY_INT8:
-		return js::TypedArray::TYPE_INT8;
-	case SCRIPT_TYPED_ARRAY_UINT8:
-		return js::TypedArray::TYPE_UINT8;
-	case SCRIPT_TYPED_ARRAY_INT16:
-		return js::TypedArray::TYPE_INT16;
-	case SCRIPT_TYPED_ARRAY_UINT16:
-		return js::TypedArray::TYPE_UINT16;
-	case SCRIPT_TYPED_ARRAY_INT32:
-		return js::TypedArray::TYPE_INT32;
-	case SCRIPT_TYPED_ARRAY_UINT32:
-		return js::TypedArray::TYPE_UINT32;
-	case SCRIPT_TYPED_ARRAY_FLOAT32:
-		return js::TypedArray::TYPE_FLOAT32;
-	case SCRIPT_TYPED_ARRAY_FLOAT64:
-		return js::TypedArray::TYPE_FLOAT64;
-	case SCRIPT_TYPED_ARRAY_UINT8_CLAMPED:
-		return js::TypedArray::TYPE_UINT8_CLAMPED;
-	default:
-		throw PSERROR_Deserialize_ScriptError("Failed to deserialize unrecognized typed array view");
-	}
-}
-
 CStdDeserializer::CStdDeserializer(ScriptInterface& scriptInterface, std::istream& stream) :
 	m_ScriptInterface(scriptInterface), m_Stream(stream)
 {
@@ -138,11 +109,13 @@
 
 void CStdDeserializer::FreeScriptBackrefs()
 {
+	JSContext* cx = m_ScriptInterface.GetContext();
+	JSAutoRequest rq(cx);
+	
 	std::map<u32, JSObject*>::iterator it = m_ScriptBackrefs.begin();
 	for (; it != m_ScriptBackrefs.end(); ++it)
 	{
-		if (!JS_RemoveObjectRoot(m_ScriptInterface.GetContext(), &it->second))
-			throw PSERROR_Deserialize_ScriptError("JS_RemoveRoot failed");
+		JS_RemoveObjectRoot(m_ScriptInterface.GetContext(), &it->second);
 	}
 	m_ScriptBackrefs.clear();
 }
@@ -152,6 +125,8 @@
 jsval CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JSObject* appendParent)
 {
 	JSContext* cx = m_ScriptInterface.GetContext();
+	
+	JSAutoRequest rq(cx);
 
 	uint8_t type;
 	NumberU8_Unbounded("type", type);
@@ -192,7 +167,7 @@
 			if (!proto)
 				throw PSERROR_Deserialize_ScriptError("Failed to find serializable prototype for object");
 
-			JSObject* parent = JS_GetParent(cx, proto);
+			JSObject* parent = JS_GetParent(proto);
 			if (!proto || !parent)
 				throw PSERROR_Deserialize_ScriptError();
 
@@ -206,11 +181,11 @@
 			JSBool hasCustomDeserialize, hasCustomSerialize;
 			if (!JS_HasProperty(cx, obj, "Serialize", &hasCustomSerialize) || !JS_HasProperty(cx, obj, "Deserialize", &hasCustomDeserialize))
 				throw PSERROR_Serialize_ScriptError("JS_HasProperty failed");
-			
+
 			if (hasCustomDeserialize)
 			{
-				jsval serialize;
-				if (!JS_LookupProperty(cx, obj, "Serialize", &serialize))
+				JS::RootedValue serialize(cx);
+				if (!JS_LookupProperty(cx, obj, "Serialize", serialize.address()))
 					throw PSERROR_Serialize_ScriptError("JS_LookupProperty failed");
 				bool hasNullSerialize = hasCustomSerialize && JSVAL_IS_NULL(serialize);
 
@@ -241,10 +216,10 @@
 			utf16string propname;
 			ReadStringUTF16("prop name", propname);
 
-			jsval propval = ReadScriptVal("prop value", NULL);
+			JS::RootedValue propval(cx, ReadScriptVal("prop value", NULL));
 			CScriptValRooted propvalRoot(cx, propval);
 
-			if (!JS_SetUCProperty(cx, obj, (const jschar*)propname.data(), propname.length(), &propval))
+			if (!JS_SetUCProperty(cx, obj, (const jschar*)propname.data(), propname.length(), propval.address()))
 				throw PSERROR_Deserialize_ScriptError();
 		}
 
@@ -266,8 +241,8 @@
 	{
 		double value;
 		NumberDouble_Unbounded("value", value);
-		jsval rval;
-		if (!JS_NewNumberValue(cx, value, &rval))
+		jsval rval = JS_NumberValue(value);
+		if (JSVAL_IS_NULL(rval))
 			throw PSERROR_Deserialize_ScriptError("JS_NewNumberValue failed");
 		return rval;
 	}
@@ -275,7 +250,7 @@
 	{
 		uint8_t value;
 		NumberU8("value", value, 0, 1);
-		return BOOLEAN_TO_JSVAL(value ? JS_TRUE : JS_FALSE);
+		return BOOLEAN_TO_JSVAL(value ? true : false);
 	}
 	case SCRIPT_TYPE_BACKREF:
 	{
@@ -290,16 +265,14 @@
 	{
 		double value;
 		NumberDouble_Unbounded("value", value);
-		jsval val;
-		if (!JS_NewNumberValue(cx, value, &val))
-			throw PSERROR_Deserialize_ScriptError();
+		JS::RootedValue val(cx, JS_NumberValue(value));
 		CScriptValRooted objRoot(cx, val);
 
 		JSObject* ctorobj;
-		if (!JS_GetClassObject(cx, JS_GetGlobalObject(cx), JSProto_Number, &ctorobj))
+		if (!JS_GetClassObject(cx, JS_GetGlobalForScopeChain(cx), JSProto_Number, &ctorobj))
 			throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed");
 
-		JSObject* obj = JS_New(cx, ctorobj, 1, &val);
+		JSObject* obj = JS_New(cx, ctorobj, 1, val.address());
 		if (!obj)
 			throw PSERROR_Deserialize_ScriptError("JS_New failed");
 		AddScriptBackref(obj);
@@ -311,14 +284,14 @@
 		ScriptString("value", str);
 		if (!str)
 			throw PSERROR_Deserialize_ScriptError();
-		jsval val = STRING_TO_JSVAL(str);
+		JS::RootedValue val(cx, STRING_TO_JSVAL(str));
 		CScriptValRooted valRoot(cx, val);
 
 		JSObject* ctorobj;
-		if (!JS_GetClassObject(cx, JS_GetGlobalObject(cx), JSProto_String, &ctorobj))
+		if (!JS_GetClassObject(cx, JS_GetGlobalForScopeChain(cx), JSProto_String, &ctorobj))
 			throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed");
 
-		JSObject* obj = JS_New(cx, ctorobj, 1, &val);
+		JSObject* obj = JS_New(cx, ctorobj, 1, val.address());
 		if (!obj)
 			throw PSERROR_Deserialize_ScriptError("JS_New failed");
 		AddScriptBackref(obj);
@@ -328,14 +301,13 @@
 	{
 		bool value;
 		Bool("value", value);
-		jsval val = BOOLEAN_TO_JSVAL(value ? JS_TRUE : JS_FALSE);
-		CScriptValRooted objRoot(cx, val);
+		JS::RootedValue val(cx, BOOLEAN_TO_JSVAL(value));
 
 		JSObject* ctorobj;
-		if (!JS_GetClassObject(cx, JS_GetGlobalObject(cx), JSProto_Boolean, &ctorobj))
+		if (!JS_GetClassObject(cx, JS_GetGlobalForScopeChain(cx), JSProto_Boolean, &ctorobj))
 			throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed");
 
-		JSObject* obj = JS_New(cx, ctorobj, 1, &val);
+		JSObject* obj = JS_New(cx, ctorobj, 1, val.address());
 		if (!obj)
 			throw PSERROR_Deserialize_ScriptError("JS_New failed");
 		AddScriptBackref(obj);
@@ -354,16 +326,47 @@
 
 		// Get buffer object
 		jsval bufferVal = ReadScriptVal("buffer", NULL);
-		CScriptValRooted bufferValRoot(cx, bufferVal);
 
-		if (!JSVAL_IS_OBJECT(bufferVal))
+		if (JSVAL_IS_PRIMITIVE(bufferVal))
 			throw PSERROR_Deserialize_ScriptError();
 
 		JSObject* bufferObj = JSVAL_TO_OBJECT(bufferVal);
-		if (!js_IsArrayBuffer(bufferObj))
+		if (!JS_IsArrayBufferObject(bufferObj))
 			throw PSERROR_Deserialize_ScriptError("js_IsArrayBuffer failed");
 
-		JSObject* arrayObj = js_CreateTypedArrayWithBuffer(cx, GetJSArrayType(arrayType), bufferObj, byteOffset, length);
+		JSObject* arrayObj;
+		switch(arrayType)
+		{
+		case SCRIPT_TYPED_ARRAY_INT8:
+			arrayObj = JS_NewInt8ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_UINT8:
+			arrayObj = JS_NewUint8ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_INT16:
+			arrayObj = JS_NewInt16ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_UINT16:
+			arrayObj = JS_NewUint16ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_INT32:
+			arrayObj = JS_NewInt32ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_UINT32:
+			arrayObj = JS_NewUint32ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_FLOAT32:
+			arrayObj = JS_NewFloat32ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_FLOAT64:
+			arrayObj = JS_NewFloat64ArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		case SCRIPT_TYPED_ARRAY_UINT8_CLAMPED:
+			arrayObj = JS_NewUint8ClampedArrayWithBuffer(cx, bufferObj, byteOffset, length);
+			break;
+		default:
+			throw PSERROR_Deserialize_ScriptError("Failed to deserialize unrecognized typed array view");
+		}
 		if (!arrayObj)
 			throw PSERROR_Deserialize_ScriptError("js_CreateTypedArrayWithBuffer failed");
 
@@ -383,16 +386,9 @@
 #error TODO: need to convert JS ArrayBuffer data from little-endian
 #endif
 
-		JSObject* bufferObj = js_CreateArrayBuffer(cx, length);
-		if (!bufferObj)
-			throw PSERROR_Deserialize_ScriptError("js_CreateArrayBuffer failed");
-
+		JSObject* bufferObj = JS_NewArrayBufferWithContents(cx, (void*)bufferData);
 		AddScriptBackref(bufferObj);
 
-		js::ArrayBuffer* buffer = js::ArrayBuffer::fromJSObject(bufferObj);
-		memcpy(buffer->data, bufferData, length);
-		delete[] bufferData;
-
 		return OBJECT_TO_JSVAL(bufferObj);
 	}
 	default:
@@ -440,7 +436,7 @@
 
 void CStdDeserializer::ScriptObjectAppend(const char* name, jsval& obj)
 {
-	if (!JSVAL_IS_OBJECT(obj))
+	if (JSVAL_IS_PRIMITIVE(obj))
 		throw PSERROR_Deserialize_ScriptError();
 
 	ReadScriptVal(name, JSVAL_TO_OBJECT(obj));
Index: source/simulation2/serialization/BinarySerializer.cpp
===================================================================
--- source/simulation2/serialization/BinarySerializer.cpp	(Revision 14578)
+++ source/simulation2/serialization/BinarySerializer.cpp	(Arbeitskopie)
@@ -19,35 +19,34 @@
 
 #include "BinarySerializer.h"
 
-#include "SerializedScriptTypes.h"
-
 #include "lib/alignment.h"
 #include "ps/CLogger.h"
 
 #include "scriptinterface/ScriptInterface.h"
 #include "scriptinterface/ScriptExtraHeaders.h" // for JSDOUBLE_IS_INT32, typed arrays
+#include "SerializedScriptTypes.h"
 
-static u8 GetArrayType(uint32 arrayType)
+static u8 GetArrayType(JSArrayBufferViewType arrayType)
 {
 	switch(arrayType)
 	{
-	case js::TypedArray::TYPE_INT8:
+	case JSArrayBufferViewType::TYPE_INT8:
 		return SCRIPT_TYPED_ARRAY_INT8;
-	case js::TypedArray::TYPE_UINT8:
+	case JSArrayBufferViewType::TYPE_UINT8:
 		return SCRIPT_TYPED_ARRAY_UINT8;
-	case js::TypedArray::TYPE_INT16:
+	case JSArrayBufferViewType::TYPE_INT16:
 		return SCRIPT_TYPED_ARRAY_INT16;
-	case js::TypedArray::TYPE_UINT16:
+	case JSArrayBufferViewType::TYPE_UINT16:
 		return SCRIPT_TYPED_ARRAY_UINT16;
-	case js::TypedArray::TYPE_INT32:
+	case JSArrayBufferViewType::TYPE_INT32:
 		return SCRIPT_TYPED_ARRAY_INT32;
-	case js::TypedArray::TYPE_UINT32:
+	case JSArrayBufferViewType::TYPE_UINT32:
 		return SCRIPT_TYPED_ARRAY_UINT32;
-	case js::TypedArray::TYPE_FLOAT32:
+	case JSArrayBufferViewType::TYPE_FLOAT32:
 		return SCRIPT_TYPED_ARRAY_FLOAT32;
-	case js::TypedArray::TYPE_FLOAT64:
+	case JSArrayBufferViewType::TYPE_FLOAT64:
 		return SCRIPT_TYPED_ARRAY_FLOAT64;
-	case js::TypedArray::TYPE_UINT8_CLAMPED:
+	case JSArrayBufferViewType::TYPE_UINT8_CLAMPED:
 		return SCRIPT_TYPED_ARRAY_UINT8_CLAMPED;
 	default:
 		LOGERROR(L"Cannot serialize unrecognized typed array view: %d", arrayType);
@@ -56,14 +55,15 @@
 }
 
 CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer) :
-	m_ScriptInterface(scriptInterface), m_Serializer(serializer), m_Rooter(m_ScriptInterface),
+	m_ScriptInterface(scriptInterface), m_Serializer(serializer), m_Rooter(m_ScriptInterface.GetContext()),
 	m_ScriptBackrefsArena(1 * MiB), m_ScriptBackrefs(backrefs_t::key_compare(), ScriptBackrefsAlloc(m_ScriptBackrefsArena)), m_ScriptBackrefsNext(1)
 {
 }
-
+// TODO YGW: Test serialization...
 void CBinarySerializerScriptImpl::HandleScriptVal(jsval val)
 {
 	JSContext* cx = m_ScriptInterface.GetContext();
+	JSAutoRequest rq(cx);
 
 	switch (JS_TypeOfValue(cx, val))
 	{
@@ -85,7 +85,8 @@
 			break;
 		}
 
-		JSObject* obj = JSVAL_TO_OBJECT(val);
+		//JSObject* obj = JSVAL_TO_OBJECT(val);
+		JS::RootedObject obj(cx, JSVAL_TO_OBJECT(val));
 
 		// If we've already serialized this object, just output a reference to it
 		u32 tag = GetScriptBackrefTag(obj);
@@ -104,53 +105,52 @@
 
 			// Arrays like [1, 2, ] have an 'undefined' at the end which is part of the
 			// length but seemingly isn't enumerated, so store the length explicitly
-			jsuint length = 0;
+			uint length = 0;
 			if (!JS_GetArrayLength(cx, obj, &length))
 				throw PSERROR_Serialize_ScriptError("JS_GetArrayLength failed");
 			m_Serializer.NumberU32_Unbounded("array length", length);
 		}
-		else if (js_IsTypedArray(obj))
+		//JS_IsArrayBufferViewObject()
+		//JS_IsTypedArrayObject()
+		else if (JS_IsTypedArrayObject(obj))
 		{
 			m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_TYPED_ARRAY);
 
-			js::TypedArray* typedArray = js::TypedArray::fromJSObject(obj);
-			
-			m_Serializer.NumberU8_Unbounded("array type", GetArrayType(typedArray->type));
-			m_Serializer.NumberU32_Unbounded("byte offset", typedArray->byteOffset);
-			m_Serializer.NumberU32_Unbounded("length", typedArray->length);
+			m_Serializer.NumberU8_Unbounded("array type", GetArrayType(JS_GetArrayBufferViewType(obj)));
+			m_Serializer.NumberU32_Unbounded("byte offset", JS_GetTypedArrayByteOffset(obj));
+			m_Serializer.NumberU32_Unbounded("length", JS_GetTypedArrayLength(obj));
 
 			// Now handle its array buffer
 			// this may be a backref, since ArrayBuffers can be shared by multiple views
-			HandleScriptVal(OBJECT_TO_JSVAL(typedArray->bufferJS));
+			HandleScriptVal(OBJECT_TO_JSVAL(JS_GetArrayBufferViewBuffer(obj)));
 			break;
 		}
-		else if (js_IsArrayBuffer(obj))
+		else if (JS_IsArrayBufferObject(obj))
 		{
 			m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_ARRAY_BUFFER);
 
-			js::ArrayBuffer* arrayBuffer = js::ArrayBuffer::fromJSObject(obj);
-
 #if BYTE_ORDER != LITTLE_ENDIAN
 #error TODO: need to convert JS ArrayBuffer data to little-endian
 #endif
 
-			u32 length = arrayBuffer->byteLength;
+			u32 length = JS_GetArrayBufferByteLength(obj);
 			m_Serializer.NumberU32_Unbounded("buffer length", length);
-			m_Serializer.RawBytes("buffer data", (const u8*)arrayBuffer->data, length);
+			m_Serializer.RawBytes("buffer data", (const u8*)JS_GetArrayBufferData(obj), length);
 			break;
 		}
 		else
 		{
 			// Find type of object
-			JSClass* jsclass = JS_GET_CLASS(cx, obj);
+			JSClass* jsclass = JS_GetClass(obj);
 			if (!jsclass)
-				throw PSERROR_Serialize_ScriptError("JS_GET_CLASS failed");
+				throw PSERROR_Serialize_ScriptError("JS_GetClass failed");
 			JSProtoKey protokey = JSCLASS_CACHED_PROTO_KEY(jsclass);
 
 			if (protokey == JSProto_Object)
 			{
 				// Object class - check for user-defined prototype
-				JSObject* proto = JS_GetPrototype(cx, obj);
+				JS::RootedObject proto(cx);
+				JS_GetPrototype(cx, obj, proto.address());
 				if (!proto)
 					throw PSERROR_Serialize_ScriptError("JS_GetPrototype failed");
 
@@ -175,11 +175,11 @@
 					JSBool hasCustomSerialize;
 					if (!JS_HasProperty(cx, obj, "Serialize", &hasCustomSerialize))
 						throw PSERROR_Serialize_ScriptError("JS_HasProperty failed");
-					
+
 					if (hasCustomSerialize)
 					{
-						jsval serialize;
-						if (!JS_LookupProperty(cx, obj, "Serialize", &serialize))
+						JS::RootedValue serialize(cx);
+						if (!JS_LookupProperty(cx, obj, "Serialize", serialize.address()))
 							throw PSERROR_Serialize_ScriptError("JS_LookupProperty failed");
 
 						// If serialize is null, so don't serialize anything more
@@ -199,7 +199,7 @@
 				// Standard Number object
 				m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_OBJECT_NUMBER);
 				// Get primitive value
-				jsdouble d;
+				double d;
 				if (!JS_ValueToNumber(cx, val, &d))
 					throw PSERROR_Serialize_ScriptError("JS_ValueToNumber failed");
 				m_Serializer.NumberDouble_Unbounded("value", d);
@@ -224,7 +224,7 @@
 				JSBool b;
 				if (!JS_ValueToBoolean(cx, val, &b))
 					throw PSERROR_Serialize_ScriptError("JS_ValueToBoolean failed");
-				m_Serializer.Bool("value", b == JS_TRUE);
+				m_Serializer.Bool("value", b);
 				break;
 			}
 			else
@@ -240,8 +240,8 @@
 		// (Note that we don't do any rooting, because we assume nothing is going to trigger GC.
 		// I'm not absolute certain that's necessarily a valid assumption.)
 
-		AutoJSIdArray ida (cx, JS_Enumerate(cx, obj));
-		if (!ida.get())
+		JS::AutoIdArray ida (cx, JS_Enumerate(cx, obj));
+		if (!ida)
 			throw PSERROR_Serialize_ScriptError("JS_Enumerate failed");
 
 		m_Serializer.NumberU32_Unbounded("num props", (uint32_t)ida.length());
@@ -250,12 +250,13 @@
 		{
 			jsid id = ida[i];
 
-			jsval idval, propval;
-
+			JS::RootedValue idval(cx);
+			JS::RootedValue propval(cx);
+			
 			// Get the property name as a string
-			if (!JS_IdToValue(cx, id, &idval))
+			if (!JS_IdToValue(cx, id, idval.address()))
 				throw PSERROR_Serialize_ScriptError("JS_IdToValue failed");
-			JSString* idstr = JS_ValueToString(cx, idval);
+			JSString* idstr = JS_ValueToString(cx, idval.get());
 			if (!idstr)
 				throw PSERROR_Serialize_ScriptError("JS_ValueToString failed");
 
@@ -263,7 +264,7 @@
 
 			// Use LookupProperty instead of GetProperty to avoid the danger of getters
 			// (they might delete values and trigger GC)
-			if (!JS_LookupPropertyById(cx, obj, id, &propval))
+			if (!JS_LookupPropertyById(cx, obj, id, propval.address()))
 				throw PSERROR_Serialize_ScriptError("JS_LookupPropertyById failed");
 
 			HandleScriptVal(propval);
@@ -308,36 +309,18 @@
 		else
 		{
 			ENSURE(JSVAL_IS_DOUBLE(val));
-
-			// If the value fits in an int, serialise as an int
-			jsdouble d = JSVAL_TO_DOUBLE(val);
-			int32_t i;
-			if (JSDOUBLE_IS_INT32(d, &i))
-			{
-				m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_INT);
-				m_Serializer.NumberI32_Unbounded("value", i);
-			}
-			// Otherwise serialise as a double
-			else
-			{
-				m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_DOUBLE);
-				m_Serializer.NumberDouble_Unbounded("value", d);
-			}
+			m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_DOUBLE);
+			m_Serializer.NumberDouble_Unbounded("value", JSVAL_TO_DOUBLE(val));
 		}
 		break;
 	}
 	case JSTYPE_BOOLEAN:
 	{
 		m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_BOOLEAN);
-		JSBool b = JSVAL_TO_BOOLEAN(val);
+		bool b = JSVAL_TO_BOOLEAN(val);
 		m_Serializer.NumberU8_Unbounded("value", b ? 1 : 0);
 		break;
 	}
-	case JSTYPE_XML:
-	{
-		LOGERROR(L"Cannot serialise JS objects of type 'xml'");
-		throw PSERROR_Serialize_InvalidScriptValue();
-	}
 	default:
 	{
 		debug_warn(L"Invalid TypeOfValue");
@@ -349,6 +332,8 @@
 void CBinarySerializerScriptImpl::ScriptString(const char* name, JSString* string)
 {
 	JSContext* cx = m_ScriptInterface.GetContext();
+	JSAutoRequest rq(cx);
+
 	size_t length;
 	const jschar* chars = JS_GetStringCharsAndLength(cx, string, &length);
 
@@ -382,7 +367,12 @@
 
 	// If it was newly inserted, we need to make sure it gets rooted
 	// for the duration that it's in m_ScriptBackrefs
-	m_Rooter.Push(it.first->first);
+	// Note: Spidermonkey has a moving GC. JSObject pointers in this mapping table can change,
+	// but we have registered a custom trace call for the time m_ScriptBackrefs is alive which
+	// takes care of updating the pointers in our mapping table.
+	// TODO: Could this be bad for GC-Performance if we serialize large objects and keep the Serializer
+    // (including m_ScriptBackrefs) alive? Do we keep it alive somewhere?
+    m_Rooter.append(it.first->first);
 	m_ScriptBackrefsNext++;
 	// Return a non-tag number so callers know they need to serialize the object
 	return 0;
Index: source/simulation2/system/ComponentManager.cpp
===================================================================
--- source/simulation2/system/ComponentManager.cpp	(Revision 14578)
+++ source/simulation2/system/ComponentManager.cpp	(Arbeitskopie)
@@ -243,12 +243,12 @@
 
 	// Find all the ctor prototype's On* methods, and subscribe to the appropriate messages:
 
-	CScriptVal proto;
+	JS::RootedObject proto(componentManager->m_ScriptInterface.GetContext());
 	if (!componentManager->m_ScriptInterface.GetProperty(ctor.get(), "prototype", proto))
 		return; // error
 
 	std::vector<std::string> methods;
-	if (!componentManager->m_ScriptInterface.EnumeratePropertyNamesWithPrefix(proto.get(), "On", methods))
+	if (!componentManager->m_ScriptInterface.EnumeratePropertyNamesWithPrefix(proto, "On", methods))
 		return; // error
 
 	for (std::vector<std::string>::const_iterator it = methods.begin(); it != methods.end(); ++it)
@@ -289,7 +289,10 @@
 		{
 			jsval instance = eit->second->GetJSInstance();
 			if (!JSVAL_IS_NULL(instance))
-				componentManager->m_ScriptInterface.SetPrototype(instance, proto.get());
+			{
+				JS::RootedObject instanceObj(componentManager->m_ScriptInterface.GetContext(),&instance.toObject());
+				componentManager->m_ScriptInterface.SetPrototype(instanceObj, proto);
+			}
 		}
 	}
 }
@@ -616,7 +619,7 @@
 	jsval obj = JSVAL_NULL;
 	if (ct.type == CT_Script)
 	{
-		obj = m_ScriptInterface.CallConstructor(ct.ctor.get(), JSVAL_VOID);
+		obj = m_ScriptInterface.CallConstructor(ct.ctor.get(), 0, JSVAL_VOID);
 		if (JSVAL_IS_VOID(obj))
 		{
 			LOGERROR(L"Script component constructor failed");
Index: source/simulation2/system/InterfaceScripted.h
===================================================================
--- source/simulation2/system/InterfaceScripted.h	(Revision 14578)
+++ source/simulation2/system/InterfaceScripted.h	(Arbeitskopie)
@@ -19,14 +19,12 @@
 #define INCLUDED_INTERFACE_SCRIPTED
 
 #include "scriptinterface/ScriptInterface.h"
-#include "js/jsapi.h"
 
 #define BEGIN_INTERFACE_WRAPPER(iname) \
 	JSClass class_ICmp##iname = { \
 		"ICmp" #iname, JSCLASS_HAS_PRIVATE, \
-		JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \
-		JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, \
-		JSCLASS_NO_OPTIONAL_MEMBERS \
+		JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \
+		JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub \
 	}; \
 	static JSFunctionSpec methods_ICmp##iname[] = {
 
@@ -35,7 +33,8 @@
 	}; \
 	void ICmp##iname::InterfaceInit(ScriptInterface& scriptInterface) { \
 		JSContext* cx = scriptInterface.GetContext(); \
-		JSObject* global = JS_GetGlobalObject(cx); \
+		JSAutoRequest rq(cx); \
+		JSObject* global = JS_GetGlobalForScopeChain(cx); \
 		JS_InitClass(cx, global, NULL, &class_ICmp##iname, NULL, 0, NULL, methods_ICmp##iname, NULL, NULL); \
 	} \
 	JSClass* ICmp##iname::GetJSClass() const { return &class_ICmp##iname; } \
@@ -45,49 +44,49 @@
 
 #define DEFINE_INTERFACE_METHOD_0(scriptname, rettype, classname, methodname) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, &class_##classname, classname, &classname::methodname>, NULL }, \
 		0, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_1(scriptname, rettype, classname, methodname, arg1) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, &class_##classname, classname, &classname::methodname>, NULL}, \
 		1, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_2(scriptname, rettype, classname, methodname, arg1, arg2) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, arg2, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, arg2, &class_##classname, classname, &classname::methodname>, NULL }, \
 		2, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_3(scriptname, rettype, classname, methodname, arg1, arg2, arg3) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, arg2, arg3, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, arg2, arg3, &class_##classname, classname, &classname::methodname>, NULL }, \
 		3, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_4(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, &class_##classname, classname, &classname::methodname>, NULL }, \
 		4, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_5(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4, arg5) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, &class_##classname, classname, &classname::methodname>, NULL }, \
 		5, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_6(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4, arg5, arg6) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, arg6, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, arg6, &class_##classname, classname, &classname::methodname>, NULL }, \
 		6, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
 #define DEFINE_INTERFACE_METHOD_7(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
 	{ scriptname, \
-		ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, arg6, arg7, &class_##classname, classname, &classname::methodname>, \
+		{ ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, arg6, arg7, &class_##classname, classname, &classname::methodname>, NULL }, \
 		7, \
 		JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
 
Index: source/simulation2/system/ParamNode.cpp
===================================================================
--- source/simulation2/system/ParamNode.cpp	(Revision 14578)
+++ source/simulation2/system/ParamNode.cpp	(Arbeitskopie)
@@ -25,8 +25,6 @@
 #include "ps/Filesystem.h"
 #include "ps/XML/Xeromyces.h"
 
-#include "js/jsapi.h"
-
 #include <sstream>
 
 // Disable "'boost::algorithm::detail::is_classifiedF' : assignment operator could not be generated"
@@ -328,6 +326,7 @@
 
 jsval CParamNode::ConstructJSVal(JSContext* cx) const
 {
+	JSAutoRequest rq(cx);
 	if (m_Childs.empty())
 	{
 		// Empty node - map to undefined
@@ -351,8 +350,8 @@
 
 	for (std::map<std::string, CParamNode>::const_iterator it = m_Childs.begin(); it != m_Childs.end(); ++it)
 	{
-		jsval childVal = it->second.ConstructJSVal(cx);
-		if (!JS_SetProperty(cx, obj, it->first.c_str(), &childVal))
+		JS::RootedValue childVal(cx, it->second.ConstructJSVal(cx));
+		if (!JS_SetProperty(cx, obj, it->first.c_str(), childVal.address()))
 			return JSVAL_VOID; // TODO: report error
 	}
 
@@ -363,8 +362,8 @@
 		JSString* str = JS_InternUCStringN(cx, reinterpret_cast<const jschar*>(text.data()), text.length());
 		if (!str)
 			return JSVAL_VOID; // TODO: report error
-		jsval childVal = STRING_TO_JSVAL(str);
-		if (!JS_SetProperty(cx, obj, "_string", &childVal))
+		JS::RootedValue childVal(cx, STRING_TO_JSVAL(str));
+		if (!JS_SetProperty(cx, obj, "_string", childVal.address()))
 			return JSVAL_VOID; // TODO: report error
 	}
 
Index: source/simulation2/system/ComponentManager.h
===================================================================
--- source/simulation2/system/ComponentManager.h	(Revision 14578)
+++ source/simulation2/system/ComponentManager.h	(Arbeitskopie)
@@ -96,6 +96,8 @@
 	void RegisterComponentType(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char*, const std::string& schema);
 	void RegisterComponentTypeScriptWrapper(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char*, const std::string& schema);
 
+
+    void Tick() { m_ScriptInterface.Tick(); };
 	/**
 	 * Subscribe the current component type to the given message type.
 	 * Each component's HandleMessage will be called on any BroadcastMessage of this message type,
Index: source/simulation2/components/CCmpAIManager.cpp
===================================================================
--- source/simulation2/components/CCmpAIManager.cpp	(Revision 14578)
+++ source/simulation2/components/CCmpAIManager.cpp	(Arbeitskopie)
@@ -152,7 +152,9 @@
 				ENSURE(m_Worker.m_HasLoadedEntityTemplates);
 				m_ScriptInterface->SetProperty(settings.get(), "templates", m_Worker.m_EntityTemplates, false);
 
-				obj = m_ScriptInterface->CallConstructor(ctor.get(), settings.get());
+				JS::AutoValueVector argv(m_ScriptInterface->GetContext());
+				argv.append(settings.get());
+				obj = m_ScriptInterface->CallConstructor(ctor.get(), argv.length(), argv.handleAt(0));
 			}
 			else
 			{
@@ -209,12 +211,7 @@
 	};
 
 	CAIWorker() :
-		// TODO: Passing a 32 MB argument to CreateRuntime() is a temporary fix
-		// to prevent frequent AI out-of-memory crashes. The argument should be
-		// removed as soon whenever the new pathfinder is committed
-		// And the AIs can stop relying on their own little hands.
-		m_ScriptRuntime(ScriptInterface::CreateRuntime(33554432)),
-		m_ScriptInterface(new ScriptInterface("Engine", "AI", m_ScriptRuntime)),
+		m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptRuntime)),
 		m_TurnNum(0),
 		m_CommandsComputed(true),
 		m_HasLoadedEntityTemplates(false),
@@ -305,7 +302,7 @@
 	static void ForceGC(ScriptInterface::CxPrivate* pCxPrivate)
 	{
 		PROFILE3("AI compute GC");
-		JS_GC(pCxPrivate->pScriptInterface->GetContext());
+		JS_GC(pCxPrivate->pScriptInterface->GetJSRuntime());
 	}
 	
 	/**
@@ -408,7 +405,10 @@
 			m_ScriptInterface->Eval("({})", fakeTech);
 			m_ScriptInterface->SetProperty(settings.get(), "techTemplates", fakeTech, false);
 		}
-		m_SharedAIObj = CScriptValRooted(m_ScriptInterface->GetContext(),m_ScriptInterface->CallConstructor(ctor.get(), settings.get()));
+		
+		JS::AutoValueVector argv(m_ScriptInterface->GetContext());
+		argv.append(settings.get());
+		m_SharedAIObj = CScriptValRooted(m_ScriptInterface->GetContext(),m_ScriptInterface->CallConstructor(ctor.get(), argv.length(), argv.handleAt(0)));
 	
 		
 		if (m_SharedAIObj.undefined())
@@ -754,14 +754,15 @@
 				m_Players[i]->Run(state, m_Players[i]->m_Player);
 		}
 
+/*
 		// Run GC if we are about to overflow
 		if (JS_GetGCParameter(m_ScriptInterface->GetJSRuntime(), JSGC_BYTES) > 33000000)
 		{
 			PROFILE3("AI compute GC");
 
-			JS_GC(m_ScriptInterface->GetContext());
+			JS_GC(m_ScriptInterface->GetJSRuntime());
 		}
-		
+	*/	
 		// Run the GC every so often.
 		// (This isn't particularly necessary, but it makes profiling clearer
 		// since it avoids random GC delays while running other scripts)
Index: source/simulation2/components/ICmpFootprint.cpp
===================================================================
--- source/simulation2/components/ICmpFootprint.cpp	(Revision 14578)
+++ source/simulation2/components/ICmpFootprint.cpp	(Arbeitskopie)
@@ -38,23 +38,23 @@
 
 	if (shape == CIRCLE)
 	{
-		jsval ptype = ScriptInterface::ToJSVal<std::string>(cx, "circle");
-		jsval pradius = ScriptInterface::ToJSVal(cx, size0);
-		jsval pheight = ScriptInterface::ToJSVal(cx, height);
-		JS_SetProperty(cx, obj, "type", &ptype);
-		JS_SetProperty(cx, obj, "radius", &pradius);
-		JS_SetProperty(cx, obj, "height", &pheight);
+		JS::RootedValue ptype(cx, ScriptInterface::ToJSVal<std::string>(cx, "circle"));
+		JS::RootedValue pradius(cx, ScriptInterface::ToJSVal(cx, size0));
+		JS::RootedValue pheight(cx, ScriptInterface::ToJSVal(cx, height));
+		JS_SetProperty(cx, obj, "type", ptype.address());
+		JS_SetProperty(cx, obj, "radius", pradius.address());
+		JS_SetProperty(cx, obj, "height", pheight.address());
 	}
 	else
 	{
-		jsval ptype = ScriptInterface::ToJSVal<std::string>(cx, "square");
-		jsval pwidth = ScriptInterface::ToJSVal(cx, size0);
-		jsval pdepth = ScriptInterface::ToJSVal(cx, size1);
-		jsval pheight = ScriptInterface::ToJSVal(cx, height);
-		JS_SetProperty(cx, obj, "type", &ptype);
-		JS_SetProperty(cx, obj, "width", &pwidth);
-		JS_SetProperty(cx, obj, "depth", &pdepth);
-		JS_SetProperty(cx, obj, "height", &pheight);
+		JS::RootedValue ptype(cx, ScriptInterface::ToJSVal<std::string>(cx, "square"));
+		JS::RootedValue pwidth(cx, ScriptInterface::ToJSVal(cx, size0));
+		JS::RootedValue pdepth(cx, ScriptInterface::ToJSVal(cx, size1));
+		JS::RootedValue pheight(cx, ScriptInterface::ToJSVal(cx, height));
+		JS_SetProperty(cx, obj, "type", ptype.address());
+		JS_SetProperty(cx, obj, "width", pwidth.address());
+		JS_SetProperty(cx, obj, "depth", pdepth.address());
+		JS_SetProperty(cx, obj, "height", pheight.address());
 	}
 
 	return OBJECT_TO_JSVAL(obj);
Index: source/simulation2/Simulation2.cpp
===================================================================
--- source/simulation2/Simulation2.cpp	(Revision 14578)
+++ source/simulation2/Simulation2.cpp	(Arbeitskopie)
@@ -155,6 +155,8 @@
 	}
 
 	int ProgressiveLoad();
+
+	void Tick();
 	void Update(int turnLength, const std::vector<SimulationCommand>& commands);
 	static void UpdateComponents(CSimContext& simContext, fixed turnLengthFixed, const std::vector<SimulationCommand>& commands);
 	void Interpolate(float simFrameLength, float frameOffset, float realFrameLength);
@@ -336,6 +338,11 @@
 	debug_warn(L"Serialization test failure");
 }
 
+void CSimulation2Impl::Tick()
+{
+    m_ComponentManager.Tick();
+}
+
 void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands)
 {
 	PROFILE3("sim update");
@@ -637,6 +644,11 @@
 	return m->m_ComponentManager.GetEntitiesWithInterfaceUnordered(iid);
 }
 
+void CSimulation2::Tick()
+{
+    m->Tick();
+}
+
 const CSimContext& CSimulation2::GetSimContext() const
 {
 	return m->m_SimContext;
Index: source/simulation2/Simulation2.h
===================================================================
--- source/simulation2/Simulation2.h	(Revision 14578)
+++ source/simulation2/Simulation2.h	(Arbeitskopie)
@@ -53,6 +53,7 @@
 	~CSimulation2();
 
 	void EnableOOSLog();
+	void Tick();
 	void EnableSerializationTest();
 
 	/**
Index: source/simulation2/scripting/MessageTypeConversions.cpp
===================================================================
--- source/simulation2/scripting/MessageTypeConversions.cpp	(Revision 14578)
+++ source/simulation2/scripting/MessageTypeConversions.cpp	(Arbeitskopie)
@@ -21,32 +21,39 @@
 #include "scriptinterface/ScriptInterface.h"
 #include "simulation2/MessageTypes.h"
 
-#include "js/jsapi.h"
-
 #define TOJSVAL_SETUP() \
-	JSObject* obj = JS_NewObject(scriptInterface.GetContext(), NULL, NULL, NULL); \
-	if (! obj) \
-		return JSVAL_VOID;
+	JSObject* obj; \
+	{\
+	JSAutoRequest rq(scriptInterface.GetContext()); \
+	obj = JS_NewObject(scriptInterface.GetContext(), NULL, NULL, NULL); \
+	if (!obj) \
+		return JSVAL_VOID; \
+	}
 
 #define SET_MSG_PROPERTY(name) \
 	do { \
-		jsval prop = ScriptInterface::ToJSVal(scriptInterface.GetContext(), this->name); \
-		if (! JS_SetProperty(scriptInterface.GetContext(), obj, #name, &prop)) \
+		JSAutoRequest rq(scriptInterface.GetContext()); \
+		JSContext* cx = scriptInterface.GetContext(); \
+		JS::RootedValue prop(cx, ScriptInterface::ToJSVal(cx, this->name)); \
+		if (! JS_SetProperty(cx, obj, #name, prop.address())) \
 			return JSVAL_VOID; \
 	} while (0);
 
 #define FROMJSVAL_SETUP() \
-	if (! JSVAL_IS_OBJECT(val)) \
+	if ( JSVAL_IS_PRIMITIVE(val)) \
 		return NULL; \
 	JSObject* obj = JSVAL_TO_OBJECT(val); \
-	jsval prop;
+	JS::RootedValue prop(scriptInterface.GetContext());
 
 #define GET_MSG_PROPERTY(type, name) \
-	if (! JS_GetProperty(scriptInterface.GetContext(), obj, #name, &prop)) \
+	type name; \
+	{ \
+	JSAutoRequest rq(scriptInterface.GetContext()); \
+	if (! JS_GetProperty(scriptInterface.GetContext(), obj, #name, prop.address())) \
 		return NULL; \
-	type name; \
-	if (! ScriptInterface::FromJSVal(scriptInterface.GetContext(), prop, name)) \
-		return NULL;
+	if (! ScriptInterface::FromJSVal(scriptInterface.GetContext(), prop.get(), name)) \
+		return NULL; \
+	}
 
 jsval CMessage::ToJSValCached(ScriptInterface& scriptInterface) const
 {
Index: source/simulation2/scripting/EngineScriptConversions.cpp
===================================================================
--- source/simulation2/scripting/EngineScriptConversions.cpp	(Revision 14578)
+++ source/simulation2/scripting/EngineScriptConversions.cpp	(Arbeitskopie)
@@ -34,6 +34,7 @@
 
 template<> jsval ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, IComponent* const& val)
 {
+	JSAutoRequest rq(cx);
 	if (val == NULL)
 		return JSVAL_NULL;
 
@@ -58,18 +59,19 @@
 		LOGERROR(L"Failed to construct IComponent script object");
 		return JSVAL_VOID;
 	}
-	JS_SetPrivate(cx, obj, static_cast<void*>(val));
+	JS_SetPrivate(obj, static_cast<void*>(val));
 
 	return OBJECT_TO_JSVAL(obj);
 }
 
 template<> jsval ScriptInterface::ToJSVal<CParamNode>(JSContext* cx, CParamNode const& val)
 {
+	JSAutoRequest rq(cx);
 	jsval rval = val.ToJSVal(cx, true);
 
 	// Prevent modifications to the object, so that it's safe to share between
 	// components and to reconstruct on deserialization
-	if (JSVAL_IS_OBJECT(rval))
+	if (!JSVAL_IS_PRIMITIVE(rval))
 		JS_DeepFreezeObject(cx, JSVAL_TO_OBJECT(rval));
 
 	return rval;
@@ -85,19 +87,23 @@
 
 template<> bool ScriptInterface::FromJSVal<CColor>(JSContext* cx, jsval v, CColor& out)
 {
-	if (!JSVAL_IS_OBJECT(v))
+	if (JSVAL_IS_PRIMITIVE(v))
 		FAIL("jsval not an object");
 
+	JSAutoRequest rq(cx);
 	JSObject* obj = JSVAL_TO_OBJECT(v);
 
-	jsval r, g, b, a;
-	if (!JS_GetProperty(cx, obj, "r", &r) || !FromJSVal(cx, r, out.r))
+	JS::RootedValue r(cx);
+	JS::RootedValue g(cx);
+	JS::RootedValue b(cx);
+	JS::RootedValue a(cx);
+	if (!JS_GetProperty(cx, obj, "r", r.address()) || !FromJSVal(cx, r, out.r))
 		FAIL("Failed to get property CColor.r");
-	if (!JS_GetProperty(cx, obj, "g", &g) || !FromJSVal(cx, g, out.g))
+	if (!JS_GetProperty(cx, obj, "g", g.address()) || !FromJSVal(cx, g, out.g))
 		FAIL("Failed to get property CColor.g");
-	if (!JS_GetProperty(cx, obj, "b", &b) || !FromJSVal(cx, b, out.b))
+	if (!JS_GetProperty(cx, obj, "b", b.address()) || !FromJSVal(cx, b, out.b))
 		FAIL("Failed to get property CColor.b");
-	if (!JS_GetProperty(cx, obj, "a", &a) || !FromJSVal(cx, a, out.a))
+	if (!JS_GetProperty(cx, obj, "a", a.address()) || !FromJSVal(cx, a, out.a))
 		FAIL("Failed to get property CColor.a");
 	// TODO: this probably has GC bugs if a getter returns an unrooted value
 
@@ -106,26 +112,28 @@
 
 template<> jsval ScriptInterface::ToJSVal<CColor>(JSContext* cx, CColor const& val)
 {
+	JSAutoRequest rq(cx);
 	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
 	if (!obj)
 		return JSVAL_VOID;
 
-	jsval r = ToJSVal(cx, val.r);
-	jsval g = ToJSVal(cx, val.g);
-	jsval b = ToJSVal(cx, val.b);
-	jsval a = ToJSVal(cx, val.a);
+	JS::RootedValue r(cx, ToJSVal(cx, val.r));
+	JS::RootedValue g(cx, ToJSVal(cx, val.g));
+	JS::RootedValue b(cx, ToJSVal(cx, val.b));
+	JS::RootedValue a(cx, ToJSVal(cx, val.a));
 
-	JS_SetProperty(cx, obj, "r", &r);
-	JS_SetProperty(cx, obj, "g", &g);
-	JS_SetProperty(cx, obj, "b", &b);
-	JS_SetProperty(cx, obj, "a", &a);
+	JS_SetProperty(cx, obj, "r", r.address());
+	JS_SetProperty(cx, obj, "g", g.address());
+	JS_SetProperty(cx, obj, "b", b.address());
+	JS_SetProperty(cx, obj, "a", a.address());
 
 	return OBJECT_TO_JSVAL(obj);
 }
 
 template<> bool ScriptInterface::FromJSVal<fixed>(JSContext* cx, jsval v, fixed& out)
 {
-	jsdouble ret;
+	JSAutoRequest rq(cx);
+	double ret;
 	if (!JS_ValueToNumber(cx, v, &ret))
 		return false;
 	out = fixed::FromDouble(ret);
@@ -134,28 +142,29 @@
 	return true;
 }
 
-template<> jsval ScriptInterface::ToJSVal<fixed>(JSContext* cx, const fixed& val)
+template<> jsval ScriptInterface::ToJSVal<fixed>(JSContext* UNUSED(cx), const fixed& val)
 {
-	jsval rval = JSVAL_VOID;
-	JS_NewNumberValue(cx, val.ToDouble(), &rval); // ignore return value
+	jsval rval = JS_NumberValue(val.ToDouble());
 	return rval;
 }
 
 template<> bool ScriptInterface::FromJSVal<CFixedVector3D>(JSContext* cx, jsval v, CFixedVector3D& out)
 {
-	if (!JSVAL_IS_OBJECT(v))
+	if (JSVAL_IS_PRIMITIVE(v))
 		return false; // TODO: report type error
+
+	JSAutoRequest rq(cx);
 	JSObject* obj = JSVAL_TO_OBJECT(v);
 
-	jsval p;
+	JS::RootedValue p(cx);
 
-	if (!JS_GetProperty(cx, obj, "x", &p)) return false; // TODO: report type errors
+	if (!JS_GetProperty(cx, obj, "x", p.address())) return false; // TODO: report type errors
 	if (!FromJSVal(cx, p, out.X)) return false;
 
-	if (!JS_GetProperty(cx, obj, "y", &p)) return false;
+	if (!JS_GetProperty(cx, obj, "y", p.address())) return false;
 	if (!FromJSVal(cx, p, out.Y)) return false;
 
-	if (!JS_GetProperty(cx, obj, "z", &p)) return false;
+	if (!JS_GetProperty(cx, obj, "z", p.address())) return false;
 	if (!FromJSVal(cx, p, out.Z)) return false;
 
 	return true;
@@ -163,33 +172,35 @@
 
 template<> jsval ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, const CFixedVector3D& val)
 {
+	JSAutoRequest rq(cx);
 	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
 	if (!obj)
 		return JSVAL_VOID;
 
-	jsval x = ToJSVal(cx, val.X);
-	jsval y = ToJSVal(cx, val.Y);
-	jsval z = ToJSVal(cx, val.Z);
+	JS::RootedValue x(cx, ToJSVal(cx, val.X));
+	JS::RootedValue y(cx, ToJSVal(cx, val.Y));
+	JS::RootedValue z(cx, ToJSVal(cx, val.Z));
 
-	JS_SetProperty(cx, obj, "x", &x);
-	JS_SetProperty(cx, obj, "y", &y);
-	JS_SetProperty(cx, obj, "z", &z);
+	JS_SetProperty(cx, obj, "x", x.address());
+	JS_SetProperty(cx, obj, "y", y.address());
+	JS_SetProperty(cx, obj, "z", z.address());
 
 	return OBJECT_TO_JSVAL(obj);
 }
 
 template<> bool ScriptInterface::FromJSVal<CFixedVector2D>(JSContext* cx, jsval v, CFixedVector2D& out)
 {
-	if (!JSVAL_IS_OBJECT(v))
+	JSAutoRequest rq(cx);
+	if (JSVAL_IS_PRIMITIVE(v))
 		return false; // TODO: report type error
 	JSObject* obj = JSVAL_TO_OBJECT(v);
 
-	jsval p;
+	JS::RootedValue p(cx);
 
-	if (!JS_GetProperty(cx, obj, "x", &p)) return false; // TODO: report type errors
+	if (!JS_GetProperty(cx, obj, "x", p.address())) return false; // TODO: report type errors
 	if (!FromJSVal(cx, p, out.X)) return false;
 
-	if (!JS_GetProperty(cx, obj, "y", &p)) return false;
+	if (!JS_GetProperty(cx, obj, "y", p.address())) return false;
 	if (!FromJSVal(cx, p, out.Y)) return false;
 
 	return true;
@@ -197,52 +208,57 @@
 
 template<> jsval ScriptInterface::ToJSVal<CFixedVector2D>(JSContext* cx, const CFixedVector2D& val)
 {
+	JSAutoRequest rq(cx);
 	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
 	if (!obj)
 		return JSVAL_VOID;
 
-	jsval x = ToJSVal(cx, val.X);
-	jsval y = ToJSVal(cx, val.Y);
+	JS::RootedValue x(cx, ToJSVal(cx, val.X));
+	JS::RootedValue y(cx, ToJSVal(cx, val.Y));
 
-	JS_SetProperty(cx, obj, "x", &x);
-	JS_SetProperty(cx, obj, "y", &y);
+	JS_SetProperty(cx, obj, "x", x.address());
+	JS_SetProperty(cx, obj, "y", y.address());
 
 	return OBJECT_TO_JSVAL(obj);
 }
 
-template<jsint atype, typename T> jsval ToJSVal_Grid(JSContext* cx, const Grid<T>& val)
+template<> jsval ScriptInterface::ToJSVal<Grid<u8> >(JSContext* cx, const Grid<u8>& val)
 {
-	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
-	if (!obj)
-		return JSVAL_VOID;
+	JSAutoRequest rq(cx);
+	uint32_t length = (uint32_t)(val.m_W * val.m_H);
+	uint32_t nbytes = (uint32_t)(length * sizeof(uint8_t));
+	JSObject* objArr = JS_NewUint8Array(cx, length);
+	memcpy((void*)JS_GetUint8ArrayData(objArr), val.m_Data, nbytes);
 
-	jsuint len = val.m_W * val.m_H;
-	JSObject *darray = js_CreateTypedArray(cx, atype, len);
-	if (!darray)
-		return JSVAL_VOID;
+	JS::RootedValue data(cx, OBJECT_TO_JSVAL(objArr));
+	JS::RootedValue w(cx, ScriptInterface::ToJSVal(cx, val.m_W));
+	JS::RootedValue h(cx, ScriptInterface::ToJSVal(cx, val.m_H));
 
-	js::TypedArray *tdest = js::TypedArray::fromJSObject(darray);
-	ENSURE(tdest->byteLength == len*sizeof(T));
 
-	memcpy(tdest->data, val.m_Data, tdest->byteLength);
+	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
+	JS_SetProperty(cx, obj, "width", w.address());
+	JS_SetProperty(cx, obj, "height", h.address());
+	JS_SetProperty(cx, obj, "data", data.address());
 
-	jsval w = ScriptInterface::ToJSVal(cx, val.m_W);
-	jsval h = ScriptInterface::ToJSVal(cx, val.m_H);
-	jsval data = OBJECT_TO_JSVAL(darray);
-
-	JS_SetProperty(cx, obj, "width", &w);
-	JS_SetProperty(cx, obj, "height", &h);
-	JS_SetProperty(cx, obj, "data", &data);
-
 	return OBJECT_TO_JSVAL(obj);
 }
+ 
+template<> jsval ScriptInterface::ToJSVal<Grid<u16> >(JSContext* cx, const Grid<u16>& val)
+ {
+	JSAutoRequest rq(cx);
+	uint32_t length = (uint32_t)(val.m_W * val.m_H);
+	uint32_t nbytes = (uint32_t)(length * sizeof(uint16_t));
+	JSObject* objArr = JS_NewUint16Array(cx, length);
+	memcpy((void*)JS_GetUint16ArrayData(objArr), val.m_Data, nbytes);
+ 
+	JS::RootedValue data(cx, OBJECT_TO_JSVAL(objArr));
+	JS::RootedValue w(cx, ScriptInterface::ToJSVal(cx, val.m_W));
+	JS::RootedValue h(cx, ScriptInterface::ToJSVal(cx, val.m_H));
 
-template<> jsval ScriptInterface::ToJSVal<Grid<u8> >(JSContext* cx, const Grid<u8>& val)
-{
-	return ToJSVal_Grid<js::TypedArray::TYPE_UINT8>(cx, val);
-}
+	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
+	JS_SetProperty(cx, obj, "width", w.address());
+	JS_SetProperty(cx, obj, "height", h.address());
+	JS_SetProperty(cx, obj, "data", data.address());
 
-template<> jsval ScriptInterface::ToJSVal<Grid<u16> >(JSContext* cx, const Grid<u16>& val)
-{
-	return ToJSVal_Grid<js::TypedArray::TYPE_UINT16>(cx, val);
+	return OBJECT_TO_JSVAL(obj);
 }
Index: source/lobby/XmppClient.cpp
===================================================================
--- source/lobby/XmppClient.cpp	(Revision 14578)
+++ source/lobby/XmppClient.cpp	(Arbeitskopie)
@@ -284,7 +284,7 @@
 void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, CScriptVal data)
 {
 	glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
-	jsval dataval = data.get();
+	JS::RootedValue dataval(scriptInterface.GetContext(), data.get());
 
 	// Setup some base stanza attributes
 	GameReport* game = new GameReport();
@@ -292,7 +292,7 @@
 
 	// Iterate through all the properties reported and add them to the stanza.
 	std::vector<std::string> properties;
-	scriptInterface.EnumeratePropertyNamesWithPrefix(dataval, "", properties);
+	scriptInterface.EnumeratePropertyNamesWithPrefix(JS::RootedObject(scriptInterface.GetContext(), JSVAL_TO_OBJECT(dataval)), "", properties);
 	for (std::vector<int>::size_type i = 0; i != properties.size(); i++)
 	{
 		std::wstring value;
@@ -318,7 +318,7 @@
 void XmppClient::SendIqRegisterGame(ScriptInterface& scriptInterface, CScriptVal data)
 {
 	glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
-	jsval dataval = data.get();
+	JS::RootedValue dataval(scriptInterface.GetContext(), data.get());
 
 	// Setup some base stanza attributes
 	GameListQuery* g = new GameListQuery();
@@ -329,7 +329,8 @@
 
 	// Iterate through all the properties reported and add them to the stanza.
 	std::vector<std::string> properties;
-	scriptInterface.EnumeratePropertyNamesWithPrefix(dataval, "", properties);
+	JS::RootedObject dataobj(scriptInterface.GetContext(), JSVAL_TO_OBJECT(dataval.get()));
+	scriptInterface.EnumeratePropertyNamesWithPrefix(dataobj, "", properties);
 	for (std::vector<int>::size_type i = 0; i != properties.size(); i++)
 	{
 		std::wstring value;
Index: source/ps/scripting/JSInterface_VFS.cpp
===================================================================
--- source/ps/scripting/JSInterface_VFS.cpp	(Revision 14578)
+++ source/ps/scripting/JSInterface_VFS.cpp	(Arbeitskopie)
@@ -68,8 +68,8 @@
 {
 	BuildDirEntListState* s = (BuildDirEntListState*)cbData;
 
-	jsval val = ScriptInterface::ToJSVal(s->cx, CStrW(pathname.string()));
-	JS_SetElement(s->cx, s->filename_array, s->cur_idx++, &val);
+	JS::RootedValue val(s->cx, ScriptInterface::ToJSVal( s->cx, CStrW(pathname.string()) ));
+	JS_SetElement(s->cx, s->filename_array, s->cur_idx++, val.address());
 	return INFO::OK;
 }
 
@@ -191,8 +191,8 @@
 	while (std::getline(ss, line))
 	{
 		// Decode each line as UTF-8
-		jsval val = ScriptInterface::ToJSVal(cx, CStr(line).FromUTF8());
-		JS_SetElement(cx, line_array, cur_line++, &val);
+		JS::RootedValue val(cx, ScriptInterface::ToJSVal(cx, CStr(line).FromUTF8()));
+		JS_SetElement(cx, line_array, cur_line++, val.address());
 	}
 
 	return OBJECT_TO_JSVAL( line_array );
Index: source/ps/Profile.cpp
===================================================================
--- source/ps/Profile.cpp	(Revision 14578)
+++ source/ps/Profile.cpp	(Arbeitskopie)
@@ -29,13 +29,13 @@
 # define USE_CRT_SET_ALLOC_HOOK
 #endif
 
-#if defined(__GLIBC__) && !defined(NDEBUG)
-//# define USE_GLIBC_MALLOC_HOOK
-# define USE_GLIBC_MALLOC_OVERRIDE
-# include <dlfcn.h>
-# include <malloc.h>
-# include "lib/sysdep/cpu.h"
-#endif
+//#if defined(__GLIBC__) && !defined(NDEBUG)
+////# define USE_GLIBC_MALLOC_HOOK
+//# define USE_GLIBC_MALLOC_OVERRIDE
+//# include <dlfcn.h>
+//# include <malloc.h>
+//# include "lib/sysdep/cpu.h"
+//#endif
 
 #include <numeric>
 
Index: source/ps/GameSetup/GameSetup.cpp
===================================================================
--- source/ps/GameSetup/GameSetup.cpp	(Revision 14578)
+++ source/ps/GameSetup/GameSetup.cpp	(Arbeitskopie)
@@ -1099,7 +1099,7 @@
 		CStr seedArg = args.Get("autostart-random");
 
 		// Default seed is 0
-		uint32 seed = 0;
+		uint32_t seed = 0;
 		if (!seedArg.empty())
 		{
 			if (seedArg.compare("-1") == 0)
Index: source/ps/Errors.h
===================================================================
--- source/ps/Errors.h	(Revision 14578)
+++ source/ps/Errors.h	(Arbeitskopie)
@@ -72,7 +72,8 @@
 
 #include <exception>
 
-typedef u32 PSRETURN;
+//typedef u32 PSRETURN;
+typedef uint32_t PSRETURN;
 
 class PSERROR : public std::exception
 {
Index: source/ps/Replay.cpp
===================================================================
--- source/ps/Replay.cpp	(Revision 14578)
+++ source/ps/Replay.cpp	(Arbeitskopie)
@@ -127,7 +127,7 @@
 	new CProfileManager;
 	g_ScriptStatsTable = new CScriptStatsTable;
 	g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
-	g_ScriptRuntime = ScriptInterface::CreateRuntime(128 * 1024 * 1024);
+	g_ScriptRuntime = ScriptInterface::CreateRuntime(256 * 1024 * 1024);
 
 	CGame game(true);
 	g_Game = &game;
@@ -210,6 +210,7 @@
 				g_Profiler2.IncrementFrameNumber();
 				PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber());
 
+                game.GetSimulation2()->Tick();
 				game.GetSimulation2()->Update(turnLength, commands);
 				commands.clear();
 			}
Index: source/scriptinterface/ScriptExtraHeaders.h
===================================================================
--- source/scriptinterface/ScriptExtraHeaders.h	(Revision 14578)
+++ source/scriptinterface/ScriptExtraHeaders.h	(Arbeitskopie)
@@ -31,6 +31,7 @@
 # endif
 # pragma GCC diagnostic ignored "-Wunused-parameter"
 # pragma GCC diagnostic ignored "-Wredundant-decls"
+# pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
 # if GCC_VERSION >= 408
 #  pragma GCC diagnostic ignored "-Wunused-local-typedefs" // caused by js/debug.h
 # endif
@@ -46,8 +47,11 @@
 # define signbit std::signbit
 #endif
 
-#include "js/jstypedarray.h"
-#include "js/jsdbgapi.h"
+//#include "js/jstypedarray.h"
+//#include "jspubtd.h"
+//#include "jsatom.h"
+#include "jsfriendapi.h"
+#include "jsdbgapi.h"
 
 #undef signbit
 
@@ -57,6 +61,7 @@
 #if GCC_VERSION >= 402
 # pragma GCC diagnostic warning "-Wunused-parameter"
 # pragma GCC diagnostic warning "-Wredundant-decls"
+# pragma GCC diagnostic warning "-Wnon-virtual-dtor"
 # if GCC_VERSION >= 406
 #  pragma GCC diagnostic pop // restore user flags
 # endif
Index: source/scriptinterface/ScriptVal.h
===================================================================
--- source/scriptinterface/ScriptVal.h	(Revision 14578)
+++ source/scriptinterface/ScriptVal.h	(Arbeitskopie)
@@ -58,12 +58,16 @@
 	 */
 	jsval get() const;
 
+	void Wrap(JSContext* cx);
+
 	/**
 	 * Returns reference to the current value.
 	 * Fails if the value is not yet initialised.
 	 */
 	jsval& getRef() const;
 
+	void getPtr(JS::Value** val);
+
 	/**
 	 * Returns whether the value is uninitialised or is JSVAL_VOID.
 	 */
Index: source/scriptinterface/tests/test_ScriptConversions.h
===================================================================
--- source/scriptinterface/tests/test_ScriptConversions.h	(Revision 14578)
+++ source/scriptinterface/tests/test_ScriptConversions.h	(Arbeitskopie)
@@ -23,7 +23,7 @@
 #include "maths/MathUtil.h"
 #include "ps/CLogger.h"
 
-#include "js/jsapi.h"
+#include "jsapi.h"
 
 class TestScriptConversions : public CxxTest::TestSuite
 {
@@ -38,7 +38,7 @@
 		// We want to convert values to strings, but can't just call toSource() on them
 		// since they might not be objects. So just use uneval.
 		std::string source;
-		TS_ASSERT(script.CallFunction(OBJECT_TO_JSVAL(JS_GetGlobalObject(cx)), "uneval", CScriptVal(v1), source));
+		TS_ASSERT(script.CallFunction(OBJECT_TO_JSVAL(JS_GetGlobalForScopeChain(cx)), "uneval", CScriptVal(v1), source));
 
 		TS_ASSERT_STR_EQUALS(source, expected);
 	}
@@ -52,7 +52,7 @@
 		jsval v1 = ScriptInterface::ToJSVal(cx, value);
 
 		std::string source;
-		TS_ASSERT(script.CallFunction(OBJECT_TO_JSVAL(JS_GetGlobalObject(cx)), "uneval", CScriptVal(v1), source));
+		TS_ASSERT(script.CallFunction(OBJECT_TO_JSVAL(JS_GetGlobalForScopeChain(cx)), "uneval", CScriptVal(v1), source));
 
 		if (expected)
 			TS_ASSERT_STR_EQUALS(source, expected);
Index: source/scriptinterface/tests/test_ScriptVal.h
===================================================================
--- source/scriptinterface/tests/test_ScriptVal.h	(Revision 14578)
+++ source/scriptinterface/tests/test_ScriptVal.h	(Arbeitskopie)
@@ -20,7 +20,7 @@
 #include "scriptinterface/ScriptInterface.h"
 #include "scriptinterface/ScriptVal.h"
 
-#include "js/jsapi.h"
+#include "jsapi.h"
 
 class TestScriptVal : public CxxTest::TestSuite
 {
@@ -35,12 +35,12 @@
 
 		CScriptValRooted root(cx, OBJECT_TO_JSVAL(obj));
 
-		JS_GC(cx);
+		JS_GC(script.GetRuntime());
 
 		jsval val = INT_TO_JSVAL(123);
 		TS_ASSERT(JS_SetProperty(cx, obj, "test", &val));
 
-		JS_GC(cx);
+		JS_GC(script.GetRuntime());
 
 		jsval rval;
 		TS_ASSERT(JS_GetProperty(cx, obj, "test", &rval));
Index: source/scriptinterface/AutoRooters.cpp
===================================================================
--- source/scriptinterface/AutoRooters.cpp	(Revision 14578)
+++ source/scriptinterface/AutoRooters.cpp	(Arbeitskopie)
@@ -1,61 +0,0 @@
-/* Copyright (C) 2010 Wildfire Games.
- * This file is part of 0 A.D.
- *
- * 0 A.D. is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * 0 A.D. is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "precompiled.h"
-
-#include "AutoRooters.h"
-
-#include "scriptinterface/ScriptInterface.h"
-
-AutoGCRooter::AutoGCRooter(ScriptInterface& scriptInterface)
-	: m_ScriptInterface(scriptInterface)
-{
-	m_Previous = m_ScriptInterface.ReplaceAutoGCRooter(this);
-}
-
-AutoGCRooter::~AutoGCRooter()
-{
-	AutoGCRooter* r = m_ScriptInterface.ReplaceAutoGCRooter(m_Previous);
-	ENSURE(r == this); // must be correctly nested
-}
-
-void AutoGCRooter::Trace(JSTracer* trc)
-{
-	if (m_Previous)
-		m_Previous->Trace(trc);
-
-	for (size_t i = 0; i < m_Objects.size(); ++i)
-	{
-		JS_CALL_OBJECT_TRACER(trc, m_Objects[i], "AutoGCRooter object");
-	}
-
-	for (size_t i = 0; i < m_Vals.size(); ++i)
-	{
-		JS_CALL_VALUE_TRACER(trc, m_Vals[i], "AutoGCRooter val");
-	}
-
-	for (size_t i = 0; i < m_IdArrays.size(); ++i)
-	{
-		for (jsint j = 0; j < m_IdArrays[i]->length; ++j)
-		{
-			jsval val = JSVAL_VOID;
-			JS_IdToValue(m_ScriptInterface.GetContext(), m_IdArrays[i]->vector[j], &val);
-			JS_CALL_VALUE_TRACER(trc, val, "AutoGCRooter id array");
-		}
-	}
-
-}
Index: source/scriptinterface/ScriptInterface.h
===================================================================
--- source/scriptinterface/ScriptInterface.h	(Revision 14578)
+++ source/scriptinterface/ScriptInterface.h	(Arbeitskopie)
@@ -25,8 +25,6 @@
 #include "ScriptTypes.h"
 #include "ScriptVal.h"
 
-#include "js/jsapi.h"
-
 #include "ps/Errors.h"
 ERROR_GROUP(Scripting);
 ERROR_TYPE(Scripting, SetupFailed);
@@ -52,8 +50,6 @@
 
 #include <boost/random/linear_congruential.hpp>
 
-class AutoGCRooter;
-
 // Set the maximum number of function arguments that can be handled
 // (This should be as small as possible (for compiler efficiency),
 // but as large as necessary for all wrapped functions)
@@ -114,6 +110,7 @@
 		void* pCBData; // meant to be used as the "this" object for callback functions
 	} m_CxPrivate;
 
+	void Tick();
 	void SetCallbackData(void* pCBData);
 	static CxPrivate* GetScriptInterfaceAndCBData(JSContext* cx);
 
@@ -136,7 +133,7 @@
 	 * Call a constructor function, equivalent to JS "new ctor(arg)".
 	 * @return The new object; or JSVAL_VOID on failure, and logs an error message
 	 */
-	jsval CallConstructor(jsval ctor, jsval arg);
+	jsval CallConstructor(jsval ctor, int argc, jsval argv);
 
 	/**
 	 * Create an object as with CallConstructor except don't actually execute the
@@ -251,9 +248,9 @@
 	 */
 	bool HasProperty(jsval obj, const char* name);
 
-	bool EnumeratePropertyNamesWithPrefix(jsval obj, const char* prefix, std::vector<std::string>& out);
+	bool EnumeratePropertyNamesWithPrefix(JS::HandleObject obj, const char* prefix, std::vector<std::string>& out);
 
-	bool SetPrototype(jsval obj, jsval proto);
+	bool SetPrototype(JS::HandleObject obj, JS::HandleObject proto);
 
 	bool FreezeObject(jsval obj, bool deep);
 
@@ -326,8 +323,6 @@
 	 */
 	template<typename T> static jsval ToJSVal(JSContext* cx, T const& val);
 
-	AutoGCRooter* ReplaceAutoGCRooter(AutoGCRooter* rooter);
-
 	/**
 	 * Dump some memory heap debugging information to stderr.
 	 */
@@ -338,6 +333,8 @@
 	 */
 	void MaybeGC();
 
+	bool MathRandom(double& nbr);
+
 	/**
 	 * Structured clones are a way to serialize 'simple' JS values into a buffer
 	 * that can safely be passed between contexts and runtimes and threads.
@@ -351,8 +348,7 @@
 	public:
 		StructuredClone();
 		~StructuredClone();
-		JSContext* m_Context;
-		uint64* m_Data;
+		uint64_t* m_Data;
 		size_t m_Size;
 	};
 
@@ -367,11 +363,11 @@
 	bool SetProperty_(jsval obj, const char* name, jsval value, bool readonly, bool enumerate);
 	bool SetProperty_(jsval obj, const wchar_t* name, jsval value, bool readonly, bool enumerate);
 	bool SetPropertyInt_(jsval obj, int name, jsval value, bool readonly, bool enumerate);
-	bool GetProperty_(jsval obj, const char* name, jsval& value);
-	bool GetPropertyInt_(jsval obj, int name, jsval& value);
+	bool GetProperty_(jsval obj, const char* name, JS::MutableHandleValue out);
+	bool GetPropertyInt_(jsval obj, int name, JS::MutableHandleValue value);
 	static bool IsExceptionPending(JSContext* cx);
-	static JSClass* GetClass(JSContext* cx, JSObject* obj);
-	static void* GetPrivate(JSContext* cx, JSObject* obj);
+	static JSClass* GetClass(JSObject* obj);
+	static void* GetPrivate(JSObject* obj);
 
 	class CustomType
 	{
@@ -383,6 +379,7 @@
 	void Register(const char* name, JSNative fptr, size_t nargs);
 	std::auto_ptr<ScriptInterface_impl> m;
 	
+	boost::rand48* m_rng;
 	std::map<std::string, CustomType> m_CustomObjectTypes;
 
 // The nasty macro/template bits are split into a separate file so you don't have to look at them
@@ -527,17 +524,19 @@
 template<typename T>
 bool ScriptInterface::GetProperty(jsval obj, const char* name, T& out)
 {
-	jsval val;
-	if (! GetProperty_(obj, name, val))
+	JSContext* cx = GetContext();
+	JSAutoRequest rq(cx);
+	JS::RootedValue val(cx);
+	if (! GetProperty_(obj, name, &val))
 		return false;
-	return FromJSVal(GetContext(), val, out);
+	return FromJSVal(cx, val, out);
 }
 
 template<typename T>
 bool ScriptInterface::GetPropertyInt(jsval obj, int name, T& out)
 {
-	jsval val;
-	if (! GetPropertyInt_(obj, name, val))
+	JS::RootedValue val(GetContext());
+	if (! GetPropertyInt_(obj, name, &val))
 		return false;
 	return FromJSVal(GetContext(), val, out);
 }
Index: source/scriptinterface/ScriptTypes.h
===================================================================
--- source/scriptinterface/ScriptTypes.h	(Revision 14578)
+++ source/scriptinterface/ScriptTypes.h	(Arbeitskopie)
@@ -33,42 +33,32 @@
 // the ones that are needed and this avoids conflicting definitions
 # define JS_SYS_TYPES_H_DEFINES_EXACT_SIZE_TYPES
 
+
 #else // If not Windows, then Unix:
 
 # define XP_UNIX
 
-// In DEBUG mode, jsval defaults to struct types. Normally we build separate
-// debug/release mode versions of the library, but when using --with-system-mozjs185
-// it's always a release mode library, so we have to disable struct types for
-// ABI compatibility
-# if defined(DEBUG) && defined(WITH_SYSTEM_MOZJS185)
-#  define JS_NO_JSVAL_JSID_STRUCT_TYPES
-# endif
-
 #endif
 // (we don't support XP_OS2 or XP_BEOS)
 
 
 // Guess whether the library was compiled with the release-mode or debug-mode ABI
 // (for JS_DumpHeap etc)
-#if defined(DEBUG) && !defined(WITH_SYSTEM_MOZJS185)
+#if defined(DEBUG) && !defined(WITH_SYSTEM_MOZJS24)
 # define MOZJS_DEBUG_ABI 1
 #else
 # define MOZJS_DEBUG_ABI 0
 #endif
 
-
-// SpiderMonkey wants the DEBUG flag
-#ifndef NDEBUG
-# ifndef DEBUG
-#  define DEBUG
-# endif
-#endif
-
 // Ignore some harmless warnings triggered by jsapi.h
-#if GCC_VERSION >= 402 // (older GCCs don't support this pragma)
+// TODO: Optimize this for different GCC versions if we find a list which pragma is supported in which version of GCC)
+// Also some versions of GCC will still print warnings (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431).
+#if GCC_VERSION >= 402 
 # pragma GCC diagnostic ignored "-Wunused-parameter"
 # pragma GCC diagnostic ignored "-Wredundant-decls"
+# pragma GCC diagnostic ignored "-Wundef"
+# pragma GCC diagnostic ignored "-Wignored-qualifiers"
+# pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
 #endif
 #if MSC_VERSION
 # pragma warning(push)
@@ -76,22 +66,27 @@
 # pragma warning(disable:4100) // "unreferenced formal parameter"
 #endif
 
-#include "js/jsapi.h"
+#include "jspubtd.h"
+#include "jsapi.h"
 
+
 #if MSC_VERSION
 # pragma warning(pop)
 #endif
 #if GCC_VERSION >= 402
 # pragma GCC diagnostic warning "-Wunused-parameter"
 # pragma GCC diagnostic warning "-Wredundant-decls"
+# pragma GCC diagnostic warning "-Wundef"
+# pragma GCC diagnostic warning "-Wignored-qualifiers"
+# pragma GCC diagnostic warning "-Wnon-virtual-dtor"
 #endif
 
-#if JS_VERSION != 185
-#error Your compiler is trying to use an incorrect version of the SpiderMonkey library.
-#error The only version that works is the one in the libraries/spidermonkey/ directory,
-#error and it will not work with a typical system-installed version.
-#error Make sure you have got all the right files and include paths.
-#endif
+//#if MOZJS_MAJOR_VERSION != 24 || MOZJS_MINOR_VERSION != 0
+//#error Your compiler is trying to use an incorrect version of the SpiderMonkey library.
+//#error The only version that works is the one in the libraries/spidermonkey/ directory,
+//#error and it will not work with a typical system-installed version.
+//#error Make sure you have got all the right files and include paths.
+//#endif
 
 class ScriptInterface;
 class CScriptVal;
Index: source/scriptinterface/NativeWrapperDecls.h
===================================================================
--- source/scriptinterface/NativeWrapperDecls.h	(Revision 14578)
+++ source/scriptinterface/NativeWrapperDecls.h	(Arbeitskopie)
@@ -26,7 +26,7 @@
 #define NUMBERED_LIST_BALANCED(z, i, data) BOOST_PP_COMMA_IF(i) data##i
 // Some other things
 #define TYPED_ARGS(z, i, data) , T##i a##i
-#define CONVERT_ARG(z, i, data) T##i a##i; if (! ScriptInterface::FromJSVal<T##i>(cx, i < argc ? JS_ARGV(cx, vp)[i] : JSVAL_VOID, a##i)) return JS_FALSE;
+#define CONVERT_ARG(z, i, data) T##i a##i; if (! ScriptInterface::FromJSVal<T##i>(cx, i < argc ? JS_ARGV(cx, vp)[i] : JSVAL_VOID, a##i)) return false;
 
 // List-generating macros, named roughly after their first list item
 #define TYPENAME_T0_HEAD(z, i) BOOST_PP_REPEAT_##z (i, NUMBERED_LIST_HEAD, typename T) // "typename T0, typename T1, "
@@ -51,14 +51,14 @@
 // (Definition comes later, since it depends on some things we haven't defined yet)
 #define OVERLOADS(z, i, data) \
 	template <typename R, TYPENAME_T0_HEAD(z,i)  R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL(z,i) )> \
-	static JSBool call(JSContext* cx, uintN argc, jsval* vp);
+	static JSBool call(JSContext* cx, uint32_t argc, jsval* vp);
 BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
 #undef OVERLOADS
 
 // Similar, for class methods
 #define OVERLOADS(z, i, data) \
 	template <typename R, TYPENAME_T0_HEAD(z,i)  JSClass* CLS, typename TC, R (TC::*fptr) ( T0(z,i) )> \
-	static JSBool callMethod(JSContext* cx, uintN argc, jsval* vp);
+	static JSBool callMethod(JSContext* cx, uint32_t argc, jsval* vp);
 BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
 #undef OVERLOADS
 
Index: source/scriptinterface/ScriptVal.cpp
===================================================================
--- source/scriptinterface/ScriptVal.cpp	(Revision 14578)
+++ source/scriptinterface/ScriptVal.cpp	(Arbeitskopie)
@@ -17,19 +17,24 @@
 
 #include "precompiled.h"
 
+#include "ScriptInterface.h"
 #include "ScriptVal.h"
 
-#include "js/jsapi.h"
 
 struct Unrooter
 {
 	Unrooter(JSContext* cx) : cx(cx) { }
-	void operator()(jsval* p) { JS_RemoveValueRoot(cx, p); delete p; }
+	void operator()(jsval* p)
+	{
+        JSAutoRequest rq(cx);
+		JS_RemoveValueRoot(cx, p); delete p;
+    }
 	JSContext* cx;
 };
 
 CScriptValRooted::CScriptValRooted(JSContext* cx, jsval val)
 {
+    JSAutoRequest rq(cx);
 	jsval* p = new jsval(val);
 	JS_AddNamedValueRoot(cx, p, "CScriptValRooted");
 	m_Val = boost::shared_ptr<jsval>(p, Unrooter(cx));
@@ -37,6 +42,7 @@
 
 CScriptValRooted::CScriptValRooted(JSContext* cx, CScriptVal val)
 {
+    JSAutoRequest rq(cx);
 	jsval* p = new jsval(val.get());
 	JS_AddNamedValueRoot(cx, p, "CScriptValRooted");
 	m_Val = boost::shared_ptr<jsval>(p, Unrooter(cx));
@@ -49,6 +55,11 @@
 	return *m_Val;
 }
 
+void CScriptValRooted::getPtr(JS::Value** val)
+{
+	*val = &*m_Val;
+}
+
 jsval& CScriptValRooted::getRef() const
 {
 	ENSURE(m_Val);
@@ -65,6 +76,7 @@
 	return !m_Val;
 }
 
+/*
 AutoJSIdArray::AutoJSIdArray(JSContext* cx, JSIdArray* ida) :
 	m_Context(cx), m_IdArray(ida)
 {
@@ -85,7 +97,7 @@
 {
 	if (!m_IdArray)
 		return 0;
-	return m_IdArray->length;
+	return JS_IdArrayLength(m_Context, m_IdArray);
 }
 
 jsid AutoJSIdArray::operator[](size_t i) const
@@ -93,4 +105,13 @@
 	if (!(m_IdArray && i < (size_t)m_IdArray->length))
 		return JSID_VOID;
 	return m_IdArray->vector[i];
-}
+}*/
+
+
+//CRootedWrapper::CRootedWrapper(JSContext* cx, JS::Value val)
+//{
+//	JSAutoRequest rq(cx);
+//	JS::Value* wrap = &val;
+//	JS_WrapValue(cx, val);
+//	m_Val = boost::shared_ptr<JS::Value>(wrap, Unrooter(cx));
+//}
Index: source/scriptinterface/NativeWrapperDefns.h
===================================================================
--- source/scriptinterface/NativeWrapperDefns.h	(Revision 14578)
+++ source/scriptinterface/NativeWrapperDefns.h	(Arbeitskopie)
@@ -79,11 +79,11 @@
 #define SCRIPT_PROFILE \
 	if (g_ScriptProfilingEnabled) \
 	{ \
-		ENSURE(JSVAL_IS_OBJECT(JS_CALLEE(cx, vp)) && JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)))); \
+		ENSURE(!JSVAL_IS_PRIMITIVE(JS_CALLEE(cx, vp)) && JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)))); \
 		const char* name = "(unknown)"; \
 		jsval nameval; \
-		if (JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0, &nameval) \
-			&& !JSVAL_IS_VOID(nameval)) \
+		nameval = JS_GetReservedSlot(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0); \
+		if (!JSVAL_IS_VOID(nameval)) \
 			name = static_cast<const char*>(JSVAL_TO_PRIVATE(nameval)); \
 		CProfileSampleScript profile(name); \
 	}
@@ -91,14 +91,14 @@
 // JSFastNative-compatible function that wraps the function identified in the template argument list
 #define OVERLOADS(z, i, data) \
 	template <typename R, TYPENAME_T0_HEAD(z,i)  R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL(z,i) )> \
-	JSBool ScriptInterface::call(JSContext* cx, uintN argc, jsval* vp) { \
+	JSBool ScriptInterface::call(JSContext* cx, uint32_t argc, jsval* vp) { \
 		UNUSED2(argc); \
 		SCRIPT_PROFILE \
 		BOOST_PP_REPEAT_##z (i, CONVERT_ARG, ~) \
 		jsval rval = JSVAL_VOID; \
 		ScriptInterface_NativeWrapper<R>::call(cx, rval, fptr  A0_TAIL(z,i)); \
 		JS_SET_RVAL(cx, vp, rval); \
-		return (ScriptInterface::IsExceptionPending(cx) ? JS_FALSE : JS_TRUE); \
+		return !ScriptInterface::IsExceptionPending(cx); \
 	}
 BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
 #undef OVERLOADS
@@ -106,17 +106,17 @@
 // Same idea but for methods
 #define OVERLOADS(z, i, data) \
 	template <typename R, TYPENAME_T0_HEAD(z,i)  JSClass* CLS, typename TC, R (TC::*fptr) ( T0(z,i) )> \
-	JSBool ScriptInterface::callMethod(JSContext* cx, uintN argc, jsval* vp) { \
+	JSBool ScriptInterface::callMethod(JSContext* cx, uint32_t argc, jsval* vp) { \
 		UNUSED2(argc); \
 		SCRIPT_PROFILE \
-		if (ScriptInterface::GetClass(cx, JS_THIS_OBJECT(cx, vp)) != CLS) return JS_FALSE; \
-		TC* c = static_cast<TC*>(ScriptInterface::GetPrivate(cx, JS_THIS_OBJECT(cx, vp))); \
-		if (! c) return JS_FALSE; \
+		if (ScriptInterface::GetClass(JS_THIS_OBJECT(cx, vp)) != CLS) return false; \
+		TC* c = static_cast<TC*>(ScriptInterface::GetPrivate(JS_THIS_OBJECT(cx, vp))); \
+		if (! c) return false; \
 		BOOST_PP_REPEAT_##z (i, CONVERT_ARG, ~) \
 		jsval rval = JSVAL_VOID; \
 		ScriptInterface_NativeMethodWrapper<R, TC>::call(cx, rval, c, fptr  A0_TAIL(z,i)); \
 		JS_SET_RVAL(cx, vp, rval); \
-		return (ScriptInterface::IsExceptionPending(cx) ? JS_FALSE : JS_TRUE); \
+		return !ScriptInterface::IsExceptionPending(cx); \
 	}
 BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
 #undef OVERLOADS
Index: source/scriptinterface/ScriptStats.cpp
===================================================================
--- source/scriptinterface/ScriptStats.cpp	(Revision 14578)
+++ source/scriptinterface/ScriptStats.cpp	(Arbeitskopie)
@@ -21,8 +21,6 @@
 
 #include "scriptinterface/ScriptInterface.h"
 
-#include "js/jsapi.h"
-
 CScriptStatsTable* g_ScriptStatsTable;
 
 enum
Index: source/scriptinterface/ScriptInterface.cpp
===================================================================
--- source/scriptinterface/ScriptInterface.cpp	(Revision 14578)
+++ source/scriptinterface/ScriptInterface.cpp	(Arbeitskopie)
@@ -20,7 +20,6 @@
 #include "ScriptInterface.h"
 // #include "DebuggingServer.h" // JS debugger temporarily disabled during the SpiderMonkey upgrade (check trac ticket #2348 for details)
 #include "ScriptStats.h"
-#include "AutoRooters.h"
 
 #include "lib/debug.h"
 #include "lib/utf8.h"
@@ -68,12 +67,15 @@
 class ScriptRuntime
 {
 public:
-	ScriptRuntime(int runtimeSize) :
-		m_rooter(NULL)
+	ScriptRuntime(int runtimeSize)
 	{
-		m_rt = JS_NewRuntime(runtimeSize);
+		// TODO: check what JS_Init() actually does and what the constraints are
+		// What I know: It must be called before calling JS_NewRuntime
+		m_rt = JS_NewRuntime(runtimeSize, JS_USE_HELPER_THREADS);
+
 		ENSURE(m_rt); // TODO: error handling
 
+		JS_SetNativeStackQuota(m_rt, 128 * sizeof(size_t) * 1024);
 		if (g_ScriptProfilingEnabled)
 		{
 			// Profiler isn't thread-safe, so only enable this on the main thread
@@ -86,22 +88,26 @@
 				}
 			}
 		}
+		JS_SetGCParameter(m_rt, JSGC_MAX_MALLOC_BYTES, 256 * 1024 * 1024);
+		JS_SetGCParameter(m_rt, JSGC_MAX_BYTES, 256 * 1024 * 1024);
 
-		JS_SetExtraGCRoots(m_rt, jshook_trace, this);
+		m_dummyContext = JS_NewContext(m_rt, STACK_CHUNK_SIZE);
+		ENSURE(m_dummyContext);
 	}
 
 	~ScriptRuntime()
 	{
+		JS_DestroyContext(m_dummyContext);
 		JS_DestroyRuntime(m_rt);
 	}
 
+	JSContext* m_dummyContext;
 	JSRuntime* m_rt;
-	AutoGCRooter* m_rooter;
 
 private:
 
 
-	static void* jshook_script(JSContext* UNUSED(cx), JSStackFrame* UNUSED(fp), JSBool before, JSBool* UNUSED(ok), void* closure)
+	static void* jshook_script(JSContext* UNUSED(cx), JSAbstractFramePtr UNUSED(fp), bool UNUSED(isConstructing), JSBool before, JSBool* UNUSED(ok), void* closure)
 	{
 		if (before)
 			g_Profiler.StartScript("script invocation");
@@ -154,7 +160,7 @@
 			if (slash != filename.npos)
 				filename = filename.substr(slash+1);
 
-			uintN line = JS_PCToLineNumber(cx, script, pc);
+			uint line = JS_PCToLineNumber(cx, script, pc);
 
 			std::stringstream ss;
 			ss << "(" << filename << ":" << line << ")";
@@ -178,7 +184,7 @@
 		boost::flyweights::no_locking
 	> LocFlyweight;
 
-	static void* jshook_function(JSContext* cx, JSStackFrame* fp, JSBool before, JSBool* UNUSED(ok), void* closure)
+	static void* jshook_function(JSContext* cx, JSAbstractFramePtr fp, bool UNUSED(isConstructing), JSBool before, JSBool* UNUSED(ok), void* closure)
 	{
 		if (!before)
 		{
@@ -186,7 +192,7 @@
 			return closure;
 		}
 
-		JSFunction* fn = JS_GetFrameFunction(cx, fp);
+		JSFunction* fn = fp.maybeFun();
 		if (!fn)
 		{
 			g_Profiler.StartScript("(function)");
@@ -207,19 +213,15 @@
 		}
 
 		// No name - compute from the location instead
-		ScriptLocation loc = { cx, JS_GetFrameScript(cx, fp), JS_GetFramePC(cx, fp) };
+		JSScript* script;
+		unsigned lineno;
+		JS_DescribeScriptedCaller(cx, &script, &lineno);
+		ENSURE(script == fp.script());
+		ScriptLocation loc = { cx, fp.script(), JS_LineNumberToPC(cx, script, lineno) };
 		g_Profiler.StartScript(LocFlyweight(loc).get().name.c_str());
 
 		return closure;
 	}
-
-	static void jshook_trace(JSTracer* trc, void* data)
-	{
-		ScriptRuntime* m = static_cast<ScriptRuntime*>(data);
-
-		if (m->m_rooter)
-			m->m_rooter->Trace(trc);
-	}
 };
 
 shared_ptr<ScriptRuntime> ScriptInterface::CreateRuntime(int runtimeSize)
@@ -233,11 +235,13 @@
 {
 	ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime);
 	~ScriptInterface_impl();
-	void Register(const char* name, JSNative fptr, uintN nargs);
+	void Register(const char* name, JSNative fptr, uint nargs);
 
 	shared_ptr<ScriptRuntime> m_runtime;
 	JSContext* m_cx;
 	JSObject* m_glob; // global scope object
+	JSCompartment* m_comp;
+	boost::rand48* m_rng;
 	JSObject* m_nativeScope; // native function scope object
 };
 
@@ -246,19 +250,15 @@
 
 JSClass global_class = {
 	"global", JSCLASS_GLOBAL_FLAGS,
-	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
-	NULL, NULL, NULL, NULL,
+	JS_PropertyStub, JS_DeletePropertyStub, 
+	JS_PropertyStub, JS_StrictPropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, 
+	JS_ConvertStub, NULL, 
 	NULL, NULL, NULL, NULL
 };
 
 void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report)
 {
-	// XXX Ugly hack: we want to compile code with 'use strict' and with JSOPTION_STRICT,
-	// but the latter causes the former to be reported as a useless expression, so
-	// ignore that specific warning here
-	if (report->flags == 5 && report->lineno == 0 && report->errorNumber == 163)
-		return;
 
 	std::stringstream msg;
 	bool isWarning = JSREPORT_IS_WARNING(report->flags);
@@ -273,7 +273,7 @@
 
 	// If there is an exception, then print its stack trace
 	jsval excn;
-	if (JS_GetPendingException(cx, &excn) && JSVAL_IS_OBJECT(excn))
+	if (JS_GetPendingException(cx, &excn) && !JSVAL_IS_PRIMITIVE(excn))
 	{
 		// TODO: this violates the docs ("The error reporter callback must not reenter the JSAPI.")
 
@@ -309,9 +309,9 @@
 
 // Functions in the global namespace:
 
-JSBool print(JSContext* cx, uintN argc, jsval* vp)
+JSBool print(JSContext* cx, uint argc, jsval* vp)
 {
-	for (uintN i = 0; i < argc; ++i)
+	for (uint i = 0; i < argc; ++i)
 	{
 		std::wstring str;
 		if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[i], str))
@@ -323,7 +323,7 @@
 	return JS_TRUE;
 }
 
-JSBool logmsg(JSContext* cx, uintN argc, jsval* vp)
+JSBool logmsg(JSContext* cx, uint argc, jsval* vp)
 {
 	if (argc < 1)
 	{
@@ -334,12 +334,12 @@
 	std::wstring str;
 	if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], str))
 		return JS_FALSE;
-	LOGMESSAGE(L"%ls", str.c_str());
+	LOGMESSAGE(L"%ls%f", str.c_str(), timer_Time());
 	JS_SET_RVAL(cx, vp, JSVAL_VOID);
 	return JS_TRUE;
 }
 
-JSBool warn(JSContext* cx, uintN argc, jsval* vp)
+JSBool warn(JSContext* cx, uint argc, jsval* vp)
 {
 	if (argc < 1)
 	{
@@ -355,7 +355,7 @@
 	return JS_TRUE;
 }
 
-JSBool error(JSContext* cx, uintN argc, jsval* vp)
+JSBool error(JSContext* cx, uint argc, jsval* vp)
 {
 	if (argc < 1)
 	{
@@ -371,7 +371,7 @@
 	return JS_TRUE;
 }
 
-JSBool deepcopy(JSContext* cx, uintN argc, jsval* vp)
+JSBool deepcopy(JSContext* cx, uint argc, jsval* vp)
 {
 	if (argc < 1)
 	{
@@ -381,21 +381,14 @@
 
 	jsval ret;
 
-	// We'd usually do:
-	//	if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret, NULL, NULL))
-	//		return JS_FALSE;
-	// but that function is broken in the 1.8.5 release
-	// (https://bugzilla.mozilla.org/show_bug.cgi?id=651510)
-	// so do an equivalent operation with a different API:
-	JSAutoStructuredCloneBuffer buf;
-	if (!buf.write(cx, JS_ARGV(cx, vp)[0]) || !buf.read(&ret, cx))
+	if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret, NULL, NULL))
 		return JS_FALSE;
 
 	JS_SET_RVAL(cx, vp, ret);
 	return JS_TRUE;
 }
 
-JSBool ProfileStart(JSContext* cx, uintN argc, jsval* vp)
+JSBool ProfileStart(JSContext* cx, uint argc, jsval* vp)
 {
 	const char* name = "(ProfileStart)";
 
@@ -423,7 +416,7 @@
 	return JS_TRUE;
 }
 
-JSBool ProfileStop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* vp)
+JSBool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* vp)
 {
 	if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread())
 		g_Profiler.Stop();
@@ -452,33 +445,41 @@
 	}
 }
 
-JSBool Math_random(JSContext* cx, uintN UNUSED(argc), jsval* vp)
+JSBool Math_random(JSContext* cx, uint UNUSED(argc), jsval* vp)
 {
-	// Grab the RNG that was hidden in our slot
-	jsval rngp;
-	if (!JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0, &rngp))
+	double r;
+	if(!ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->MathRandom(r))
+	{
 		return JS_FALSE;
-	boost::rand48* rng = static_cast<boost::rand48*>(JSVAL_TO_PRIVATE(rngp));
+	}
+	else
+	{
+		jsval rv = JS_NumberValue(r);
+		JS_SET_RVAL(cx, vp, rv);
+		return JS_TRUE;
+	}
+}
 
-	double r = generate_uniform_real(*rng, 0.0, 1.0);
+} // anonymous namespace
 
-	jsval rv;
-	if (!JS_NewNumberValue(cx, r, &rv))
-		return JS_FALSE;
-	JS_SET_RVAL(cx, vp, rv);
-	return JS_TRUE;
+bool ScriptInterface::MathRandom(double& nbr)
+{
+	if (m->m_rng == NULL)
+		return false;
+	nbr = generate_uniform_real(*(m->m_rng), 0.0, 1.0);
+	return true;
 }
 
-} // anonymous namespace
-
 ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) :
 	m_runtime(runtime)
 {
-	JSBool ok;
+	bool ok;
 
 	m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE);
 	ENSURE(m_cx);
 
+	JS_SetParallelCompilationEnabled(m_cx, true);
+
 	// For GC debugging:
 	// JS_SetGCZeal(m_cx, 2);
 
@@ -486,9 +487,12 @@
 
 	JS_SetErrorReporter(m_cx, ErrorReporter);
 
-	uint32 options = 0;
-	options |= JSOPTION_STRICT; // "warn on dubious practice"
-	options |= JSOPTION_XML; // "ECMAScript for XML support: parse <!-- --> as a token"
+	uint32_t options = 0;
+	options |= JSOPTION_EXTRA_WARNINGS; // "warn on dubious practice"
+	// We use strict mode to encourage better coding practices and
+	//to get code that can be optimized better by Spidermonkey's JIT compiler.
+	options |= JSOPTION_STRICT_MODE;
+	//options |= JSOPTION_ALLOW_XML; // "ECMAScript for XML support: parse <!-- --> as a token"
 	options |= JSOPTION_VAROBJFIX; // "recommended" (fixes variable scoping)
 
 	// Enable method JIT, unless script profiling/debugging is enabled (since profiling/debugging
@@ -496,21 +500,31 @@
 	// TODO: Verify what exactly is incompatible
 	if (!g_ScriptProfilingEnabled && !g_JSDebuggerEnabled)
 	{
-		options |= JSOPTION_METHODJIT;
+		options |= JSOPTION_BASELINE;
+		options |= JSOPTION_ION;
+		options |= JSOPTION_TYPE_INFERENCE;
+		options |= JSOPTION_COMPILE_N_GO;
 
 		// Some other JIT flags to experiment with:
-		options |= JSOPTION_JIT;
-		options |= JSOPTION_PROFILING;
+		//options |= JSOPTION_METHODJIT_ALWAYS;
 	}
 
 	JS_SetOptions(m_cx, options);
-	JS_SetVersion(m_cx, JSVERSION_LATEST);
+	
+	JSAutoRequest rq(m_cx);
+	
+	JS::CompartmentOptions opt;
+	opt.setVersion(JSVERSION_LATEST);
+	m_glob = JS_NewGlobalObject(m_cx, &global_class, NULL, opt);
+	m_comp = JS_EnterCompartment(m_cx, m_glob);
+	JS_SetGlobalObject(m_cx, m_glob);
 
-	m_glob = JS_NewCompartmentAndGlobalObject(m_cx, &global_class, NULL);
-
 	ok = JS_InitStandardClasses(m_cx, m_glob);
 	ENSURE(ok);
+	
+	//JS_SetVersionForCompartment(m_comp, JSVERSION_LATEST);
 
+
 	JS_DefineProperty(m_cx, m_glob, "global", OBJECT_TO_JSVAL(m_glob), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
 			| JSPROP_PERMANENT);
 
@@ -529,11 +543,16 @@
 
 ScriptInterface_impl::~ScriptInterface_impl()
 {
+	{
+		JSAutoRequest rq(m_cx);
+		JS_LeaveCompartment(m_cx, m_comp);
+	}
 	JS_DestroyContext(m_cx);
 }
 
-void ScriptInterface_impl::Register(const char* name, JSNative fptr, uintN nargs)
+void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs)
 {
+	JSAutoRequest rq(m_cx);
 	JSFunction* func = JS_DefineFunction(m_cx, m_nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
 
 	if (!func)
@@ -552,7 +571,7 @@
 		> LockedStringFlyweight;
 
 		LockedStringFlyweight fw(name);
-		JS_SetReservedSlot(m_cx, JS_GetFunctionObject(func), 0, PRIVATE_TO_JSVAL((void*)fw.get().c_str()));
+		JS_SetReservedSlot(JS_GetFunctionObject(func), 0, PRIVATE_TO_JSVAL((void*)fw.get().c_str()));
 	}
 }
 
@@ -599,6 +618,11 @@
 	JS_ShutDown();
 }
 
+void ScriptInterface::Tick()
+{
+	js::NotifyAnimationActivity(m->m_glob);
+}
+
 void ScriptInterface::SetCallbackData(void* pCBData)
 {
 	m_CxPrivate.pCBData = pCBData;
@@ -633,16 +657,16 @@
 
 bool ScriptInterface::ReplaceNondeterministicRNG(boost::rand48& rng)
 {
-	jsval math;
-	if (JS_GetProperty(m->m_cx, m->m_glob, "Math", &math) && JSVAL_IS_OBJECT(math))
+	JSAutoRequest rq(m->m_cx);
+	JS::RootedValue math(m->m_cx);
+	if (JS_GetProperty(m->m_cx, m->m_glob, "Math", math.address()) && !JSVAL_IS_PRIMITIVE(math.get()))
 	{
 		JSFunction* random = JS_DefineFunction(m->m_cx, JSVAL_TO_OBJECT(math), "random", Math_random, 0,
 			JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
 		if (random)
 		{
-			// Store the RNG in a slot which is sort-of-guaranteed to be unused by the JS engine
-			if (JS_SetReservedSlot(m->m_cx, JS_GetFunctionObject(random), 0, PRIVATE_TO_JSVAL(&rng)))
-				return true;
+			m->m_rng = &rng;
+			return true;
 		}
 	}
 
@@ -652,7 +676,7 @@
 
 void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs)
 {
-	m->Register(name, fptr, (uintN)nargs);
+	m->Register(name, fptr, (uint)nargs);
 }
 
 JSContext* ScriptInterface::GetContext() const
@@ -670,44 +694,45 @@
 	return m->m_runtime;
 }
 
-AutoGCRooter* ScriptInterface::ReplaceAutoGCRooter(AutoGCRooter* rooter)
-{
-	AutoGCRooter* ret = m->m_runtime->m_rooter;
-	m->m_runtime->m_rooter = rooter;
-	return ret;
-}
 
-
-jsval ScriptInterface::CallConstructor(jsval ctor, jsval arg)
+jsval ScriptInterface::CallConstructor(jsval ctor, int argc, jsval argv)
 {
-	if (!JSVAL_IS_OBJECT(ctor))
+	JSAutoRequest rq(m->m_cx);
+	if (JSVAL_IS_PRIMITIVE(ctor))
 	{
 		LOGERROR(L"CallConstructor: ctor is not an object");
 		return JSVAL_VOID;
 	}
 
-	return OBJECT_TO_JSVAL(JS_New(m->m_cx, JSVAL_TO_OBJECT(ctor), 1, &arg));
+	// Passing argc 0 and argv JSVAL_VOID causes a crash in mozjs24
+	if (argc == 0)
+	{
+		return OBJECT_TO_JSVAL(JS_New(m->m_cx, JSVAL_TO_OBJECT(ctor), 0, NULL));
+	}
+	else
+		return OBJECT_TO_JSVAL(JS_New(m->m_cx, JSVAL_TO_OBJECT(ctor), argc, &argv));
 }
 
 jsval ScriptInterface::NewObjectFromConstructor(jsval ctor)
 {
+	JSAutoRequest rq(m->m_cx);
 	// Get the constructor's prototype
 	// (Can't use JS_GetPrototype, since we want .prototype not .__proto__)
-	jsval protoVal;
-	if (!JS_GetProperty(m->m_cx, JSVAL_TO_OBJECT(ctor), "prototype", &protoVal))
+	JS::RootedValue protoVal(m->m_cx);
+	if (!JS_GetProperty(m->m_cx, JSVAL_TO_OBJECT(ctor), "prototype", protoVal.address()))
 	{
 		LOGERROR(L"NewObjectFromConstructor: can't get prototype");
 		return JSVAL_VOID;
 	}
 
-	if (!JSVAL_IS_OBJECT(protoVal))
+	if (JSVAL_IS_PRIMITIVE(protoVal.get()))
 	{
 		LOGERROR(L"NewObjectFromConstructor: prototype is not an object");
 		return JSVAL_VOID;
 	}
 
-	JSObject* proto = JSVAL_TO_OBJECT(protoVal);
-	JSObject* parent = JS_GetParent(m->m_cx, JSVAL_TO_OBJECT(ctor));
+	JSObject* proto = JSVAL_TO_OBJECT(protoVal.get());
+	JSObject* parent = JS_GetParent(JSVAL_TO_OBJECT(ctor));
 	// TODO: rooting?
 	if (!proto || !parent)
 	{
@@ -727,6 +752,7 @@
 
 void ScriptInterface::DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs)
 {
+	JSAutoRequest rq(m->m_cx);
 	std::string typeName = clasp->name;
 
 	if (m_CustomObjectTypes.find(typeName) != m_CustomObjectTypes.end())
@@ -774,6 +800,7 @@
 
 bool ScriptInterface::CallFunction_(jsval val, const char* name, size_t argc, jsval* argv, jsval& ret)
 {
+	JSAutoRequest rq(m->m_cx);
 	JSObject* obj;
 	if (!JS_ValueToObject(m->m_cx, val, &obj) || obj == NULL)
 		return false;
@@ -782,16 +809,17 @@
 	// when calling an undefined value
 	JSBool found;
 	if (!JS_HasProperty(m->m_cx, obj, name, &found) || !found)
-		return false;
+		return JS_FALSE;
 
-	JSBool ok = JS_CallFunctionName(m->m_cx, obj, name, (uintN)argc, argv, &ret);
+	bool ok = JS_CallFunctionName(m->m_cx, obj, name, (uint)argc, argv, &ret);
 
-	return ok ? true : false;
+	return ok ? JS_TRUE : JS_FALSE;
 }
 
 jsval ScriptInterface::GetGlobalObject()
 {
-	return OBJECT_TO_JSVAL(JS_GetGlobalObject(m->m_cx));
+	JSAutoRequest rq(m->m_cx);
+	return OBJECT_TO_JSVAL(JS_GetGlobalForScopeChain(m->m_cx));
 }
 
 JSClass* ScriptInterface::GetGlobalClass()
@@ -801,32 +829,34 @@
 
 bool ScriptInterface::SetGlobal_(const char* name, jsval value, bool replace)
 {
+	JSAutoRequest rq(m->m_cx);
 	if (!replace)
 	{
 		JSBool found;
 		if (!JS_HasProperty(m->m_cx, m->m_glob, name, &found))
-			return false;
+			return JS_FALSE;
 		if (found)
 		{
 			JS_ReportError(m->m_cx, "SetGlobal \"%s\" called multiple times", name);
-			return false;
+			return JS_FALSE;
 		}
 	}
 
-	JSBool ok = JS_DefineProperty(m->m_cx, m->m_glob, name, value, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
-			| JSPROP_PERMANENT);
-	return ok ? true : false;
+	bool ok = JS_DefineProperty(m->m_cx, m->m_glob, name, value, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
+ 			| JSPROP_PERMANENT);
+	return ok ? JS_TRUE : JS_FALSE;
 }
 
 bool ScriptInterface::SetProperty_(jsval obj, const char* name, jsval value, bool constant, bool enumerate)
 {
-	uintN attrs = 0;
+	JSAutoRequest rq(m->m_cx);
+	uint attrs = 0;
 	if (constant)
 		attrs |= JSPROP_READONLY | JSPROP_PERMANENT;
 	if (enumerate)
 		attrs |= JSPROP_ENUMERATE;
 
-	if (! JSVAL_IS_OBJECT(obj))
+	if (JSVAL_IS_PRIMITIVE(obj))
 		return false;
 	JSObject* object = JSVAL_TO_OBJECT(obj);
 
@@ -837,13 +867,14 @@
 
 bool ScriptInterface::SetProperty_(jsval obj, const wchar_t* name, jsval value, bool constant, bool enumerate)
 {
-	uintN attrs = 0;
+	JSAutoRequest rq(m->m_cx);
+	uint attrs = 0;
 	if (constant)
 		attrs |= JSPROP_READONLY | JSPROP_PERMANENT;
 	if (enumerate)
 		attrs |= JSPROP_ENUMERATE;
 
-	if (! JSVAL_IS_OBJECT(obj))
+	if ( JSVAL_IS_PRIMITIVE(obj))
 		return false;
 	JSObject* object = JSVAL_TO_OBJECT(obj);
 
@@ -855,13 +886,14 @@
 
 bool ScriptInterface::SetPropertyInt_(jsval obj, int name, jsval value, bool constant, bool enumerate)
 {
-	uintN attrs = 0;
+	JSAutoRequest rq(m->m_cx);
+	uint attrs = 0;
 	if (constant)
 		attrs |= JSPROP_READONLY | JSPROP_PERMANENT;
 	if (enumerate)
 		attrs |= JSPROP_ENUMERATE;
 
-	if (! JSVAL_IS_OBJECT(obj))
+	if ( JSVAL_IS_PRIMITIVE(obj))
 		return false;
 	JSObject* object = JSVAL_TO_OBJECT(obj);
 
@@ -870,48 +902,54 @@
 	return true;
 }
 
-bool ScriptInterface::GetProperty_(jsval obj, const char* name, jsval& out)
+bool ScriptInterface::GetProperty_(jsval obj, const char* name, JS::MutableHandleValue out)
 {
-	if (! JSVAL_IS_OBJECT(obj))
+	JSAutoRequest rq(m->m_cx);
+	if ( JSVAL_IS_PRIMITIVE(obj))
 		return false;
 	JSObject* object = JSVAL_TO_OBJECT(obj);
 
-	if (!JS_GetProperty(m->m_cx, object, name, &out))
+	if (!JS_GetProperty(m->m_cx, object, name, out.address()))
 		return false;
 	return true;
 }
 
-bool ScriptInterface::GetPropertyInt_(jsval obj, int name, jsval& out)
+bool ScriptInterface::GetPropertyInt_(jsval obj, int name, JS::MutableHandleValue out)
 {
-	if (! JSVAL_IS_OBJECT(obj))
+	JSAutoRequest rq(m->m_cx);
+	if ( JSVAL_IS_PRIMITIVE(obj))
 		return false;
 	JSObject* object = JSVAL_TO_OBJECT(obj);
 
-	if (!JS_GetPropertyById(m->m_cx, object, INT_TO_JSID(name), &out))
+	if (!JS_GetPropertyById(m->m_cx, object, INT_TO_JSID(name), out.address()))
 		return false;
 	return true;
 }
 
 bool ScriptInterface::HasProperty(jsval obj, const char* name)
 {
-	if (! JSVAL_IS_OBJECT(obj))
-		return false;
+	// TODO: proper errorhandling 
+	JSAutoRequest rq(m->m_cx);
+	if ( JSVAL_IS_PRIMITIVE(obj))
+		return JS_FALSE;
 	JSObject* object = JSVAL_TO_OBJECT(obj);
 
 	JSBool found;
 	if (!JS_HasProperty(m->m_cx, object, name, &found))
-		return false;
-	return (found != JS_FALSE);
+		return JS_FALSE;
+	return found;
 }
 
-bool ScriptInterface::EnumeratePropertyNamesWithPrefix(jsval obj, const char* prefix, std::vector<std::string>& out)
+bool ScriptInterface::EnumeratePropertyNamesWithPrefix(JS::HandleObject obj, const char* prefix, std::vector<std::string>& out)
 {
-	utf16string prefix16 (prefix, prefix+strlen(prefix));
+	JSAutoRequest rq(m->m_cx);
+	if (obj.get() == 0x0)
+		return true;
 
-	if (! JSVAL_IS_OBJECT(obj))
-		return false; // TODO: log error messages
+//	if ( obj.get().isPrimitive() )
+//		return false; // TODO: log error messages
 
-	JSObject* it = JS_NewPropertyIterator(m->m_cx, JSVAL_TO_OBJECT(obj));
+	JSObject* it = JS_NewPropertyIterator(m->m_cx, obj.get());
 	if (!it)
 		return false;
 
@@ -927,33 +965,45 @@
 			continue; // ignore integer properties
 
 		JSString* name = JSVAL_TO_STRING(val);
-		size_t len;
-		const jschar* chars = JS_GetStringCharsAndLength(m->m_cx, name, &len);
-		if (chars && len >= prefix16.size() && memcmp(chars, prefix16.c_str(), prefix16.size()*2) == 0)
-			out.push_back(std::string(chars, chars+len)); // handles Unicode poorly
+		size_t len = strlen(prefix)+1;
+		char buf[len];
+		size_t prefixLen = strlen(prefix) * sizeof(char);
+		JS_EncodeStringToBuffer(m->m_cx, name, buf, prefixLen);
+		buf[len-1]= '\0';
+		if(0 == strcmp(buf, prefix))
+		{
+			size_t len;
+			const jschar* chars = JS_GetStringCharsAndLength(m->m_cx, name, &len);
+			out.push_back(std::string(chars, chars+len));
+		}
+//		if (chars && len >= prefix16.size() && memcmp(chars, prefix16.c_str(), prefix16.size()*2) == 0)
+//			out.push_back(std::string(chars, chars+len)); // handles Unicode poorly
+
 	}
 
 	// Recurse up the prototype chain
-	JSObject* prototype = JS_GetPrototype(m->m_cx, JSVAL_TO_OBJECT(obj));
-	if (prototype)
+	JS::RootedObject prototype(m->m_cx);
+	if (JS_GetPrototype(m->m_cx, obj, prototype.address()))
 	{
-		if (! EnumeratePropertyNamesWithPrefix(OBJECT_TO_JSVAL(prototype), prefix, out))
+		if (! EnumeratePropertyNamesWithPrefix(prototype, prefix, out))
 			return false;
 	}
 
 	return true;
 }
 
-bool ScriptInterface::SetPrototype(jsval obj, jsval proto)
+bool ScriptInterface::SetPrototype(JS::HandleObject obj, JS::HandleObject proto)
 {
-	if (!JSVAL_IS_OBJECT(obj) || !JSVAL_IS_OBJECT(proto))
-		return false;
-	return JS_SetPrototype(m->m_cx, JSVAL_TO_OBJECT(obj), JSVAL_TO_OBJECT(proto)) ? true : false;
+	JSAutoRequest rq(m->m_cx);
+	//if (JSVAL_IS_PRIMITIVE(obj) || JSVAL_IS_PRIMITIVE(proto))
+	//	return false;
+	return JS_SetPrototype(m->m_cx, obj, proto);
 }
 
 bool ScriptInterface::FreezeObject(jsval obj, bool deep)
 {
-	if (!JSVAL_IS_OBJECT(obj))
+	JSAutoRequest rq(m->m_cx);
+	if (JSVAL_IS_PRIMITIVE(obj))
 		return false;
 
 	if (deep)
@@ -964,43 +1014,41 @@
 
 bool ScriptInterface::LoadScript(const VfsPath& filename, const std::string& code)
 {
-	// Compile the code in strict mode, to encourage better coding practices and
-	// to possibly help SpiderMonkey with optimisations
-	std::wstring codeStrict = L"\"use strict\";\n" + wstring_from_utf8(code);
-	utf16string codeUtf16(codeStrict.begin(), codeStrict.end());
-	uintN lineNo = 0; // put the automatic 'use strict' on line 0, so the real code starts at line 1
+	JSAutoRequest rq(m->m_cx);
+	utf16string codeUtf16(code.begin(), code.end());
+	uint lineNo = 1;
 
-	JSFunction* func = JS_CompileUCFunction(m->m_cx, NULL, NULL, 0, NULL,
-			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uintN)(codeUtf16.length()),
-			utf8_from_wstring(filename.string()).c_str(), lineNo);
-
+	JS::Rooted<JSFunction*> func(m->m_cx,
+		JS_CompileUCFunction(m->m_cx, m->m_glob, utf8_from_wstring(filename.string()).c_str(), 0, NULL,
+			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uint)(codeUtf16.length()),
+			utf8_from_wstring(filename.string()).c_str(), lineNo)
+	);
 	if (!func)
 		return false;
 
-	jsval scriptRval;
-	JSBool ok = JS_CallFunction(m->m_cx, NULL, func, 0, NULL, &scriptRval);
+	JS::RootedValue val(m->m_cx);
+	bool ok = JS_CallFunction(m->m_cx, NULL, func, 0, NULL, val.address());
 
 	return ok ? true : false;
 }
 
 bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::wstring& code)
 {
-	// Compile the code in strict mode, to encourage better coding practices and
-	// to possibly help SpiderMonkey with optimisations
-	std::wstring codeStrict = L"\"use strict\";\n" + code;
-	utf16string codeUtf16(codeStrict.begin(), codeStrict.end());
-	uintN lineNo = 0; // put the automatic 'use strict' on line 0, so the real code starts at line 1
+	JSAutoRequest rq(m->m_cx);
+	utf16string codeUtf16(code.begin(), code.end());
+	uint lineNo = 1;
 
 	jsval rval;
-	JSBool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob,
-			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uintN)(codeUtf16.length()),
+	bool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob,
+			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uint)(codeUtf16.length()),
 			utf8_from_wstring(filename.string()).c_str(), lineNo, &rval);
 
-	return ok ? true : false;
+	return ok;
 }
 
 bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
 {
+	JSAutoRequest rq(m->m_cx);
 	if (!VfsFileExists(path))
 	{
 		LOGERROR(L"File '%ls' does not exist", path.string().c_str());
@@ -1019,18 +1067,15 @@
 
 	std::wstring code = wstring_from_utf8(file.DecodeUTF8()); // assume it's UTF-8
 
-	// Compile the code in strict mode, to encourage better coding practices and
-	// to possibly help SpiderMonkey with optimisations
-	std::wstring codeStrict = L"\"use strict\";\n" + code;
-	utf16string codeUtf16(codeStrict.begin(), codeStrict.end());
-	uintN lineNo = 0; // put the automatic 'use strict' on line 0, so the real code starts at line 1
+	utf16string codeUtf16(code.begin(), code.end());
+	uint lineNo = 1;
 
 	jsval rval;
-	JSBool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob,
-			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uintN)(codeUtf16.length()),
+	bool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob,
+			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uint)(codeUtf16.length()),
 			utf8_from_wstring(path.string()).c_str(), lineNo, &rval);
 
-	return ok ? true : false;
+	return ok;
 }
 
 
@@ -1042,45 +1087,29 @@
 
 bool ScriptInterface::Eval_(const char* code, jsval& rval)
 {
+	JSAutoRequest rq(m->m_cx);
 	utf16string codeUtf16(code, code+strlen(code));
 
-	JSBool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob, (const jschar*)codeUtf16.c_str(), (uintN)codeUtf16.length(), "(eval)", 1, &rval);
-	return ok ? true : false;
+	bool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob, (const jschar*)codeUtf16.c_str(), (uint)codeUtf16.length(), "(eval)", 1, &rval);
+	return ok;
 }
 
 bool ScriptInterface::Eval_(const wchar_t* code, jsval& rval)
 {
+	JSAutoRequest rq(m->m_cx);
 	utf16string codeUtf16(code, code+wcslen(code));
 
-	JSBool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob, (const jschar*)codeUtf16.c_str(), (uintN)codeUtf16.length(), "(eval)", 1, &rval);
-	return ok ? true : false;
+	bool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob, (const jschar*)codeUtf16.c_str(), (uint)codeUtf16.length(), "(eval)", 1, &rval);
+	return ok;
 }
 
 CScriptValRooted ScriptInterface::ParseJSON(const std::string& string_utf8)
 {
+	JSAutoRequest rq(m->m_cx);
 	std::wstring attrsW = wstring_from_utf8(string_utf8);
-	utf16string string(attrsW.begin(), attrsW.end());
-
-	jsval vp;
-	JSONParser* parser = JS_BeginJSONParse(m->m_cx, &vp);
-	if (!parser)
-	{
-		LOGERROR(L"ParseJSON failed to begin");
-		return CScriptValRooted();
-	}
-
-	if (!JS_ConsumeJSONText(m->m_cx, parser, reinterpret_cast<const jschar*>(string.c_str()), (uint32)string.size()))
-	{
-		LOGERROR(L"ParseJSON failed to consume");
-		return CScriptValRooted();
-	}
-
-	if (!JS_FinishJSONParse(m->m_cx, parser, JSVAL_NULL))
-	{
-		LOGERROR(L"ParseJSON failed to finish");
-		return CScriptValRooted();
-	}
-
+ 	utf16string string(attrsW.begin(), attrsW.end());
+	JS::Rooted<jsval> vp(m->m_cx);
+	JS_ParseJSON(m->m_cx, reinterpret_cast<const jschar*>(string.c_str()), (uint32_t)string.size(), &vp);
 	return CScriptValRooted(m->m_cx, vp);
 }
 
@@ -1109,7 +1138,7 @@
 
 struct Stringifier
 {
-	static JSBool callback(const jschar* buf, uint32 len, void* data)
+	static JSBool callback(const jschar* buf, uint32_t len, void* data)
 	{
 		utf16string str(buf, buf+len);
 		std::wstring strw(str.begin(), str.end());
@@ -1124,7 +1153,7 @@
 
 struct StringifierW
 {
-	static JSBool callback(const jschar* buf, uint32 len, void* data)
+	static JSBool callback(const jschar* buf, uint32_t len, void* data)
 	{
 		utf16string str(buf, buf+len);
 		static_cast<StringifierW*>(data)->stream << std::wstring(str.begin(), str.end());
@@ -1136,6 +1165,7 @@
 
 std::string ScriptInterface::StringifyJSON(jsval obj, bool indent)
 {
+	JSAutoRequest rq(m->m_cx);
 	Stringifier str;
 	if (!JS_Stringify(m->m_cx, &obj, NULL, indent ? INT_TO_JSVAL(2) : JSVAL_VOID, &Stringifier::callback, &str))
 	{
@@ -1151,6 +1181,7 @@
 
 std::wstring ScriptInterface::ToString(jsval obj, bool pretty)
 {
+	JSAutoRequest rq(m->m_cx);
 	if (JSVAL_IS_VOID(obj))
 		return L"(void 0)";
 
@@ -1163,7 +1194,7 @@
 		// Temporary disable the error reporter, so we don't print complaints about cyclic values
 		JSErrorReporter er = JS_SetErrorReporter(m->m_cx, NULL);
 
-		bool ok = JS_Stringify(m->m_cx, &obj, NULL, INT_TO_JSVAL(2), &StringifierW::callback, &str) == JS_TRUE;
+		JSBool ok = JS_Stringify(m->m_cx, &obj, NULL, INT_TO_JSVAL(2), &StringifierW::callback, &str);
 
 		// Restore error reporter
 		JS_SetErrorReporter(m->m_cx, er);
@@ -1185,6 +1216,7 @@
 
 void ScriptInterface::ReportError(const char* msg)
 {
+	JSAutoRequest rq(m->m_cx);
 	// JS_ReportError by itself doesn't seem to set a JS-style exception, and so
 	// script callers will be unable to catch anything. So use JS_SetPendingException
 	// to make sure there really is a script-level exception. But just set it to undefined
@@ -1198,29 +1230,28 @@
 
 bool ScriptInterface::IsExceptionPending(JSContext* cx)
 {
+	JSAutoRequest rq(cx);
 	return JS_IsExceptionPending(cx) ? true : false;
 }
 
-JSClass* ScriptInterface::GetClass(JSContext* cx, JSObject* obj)
+JSClass* ScriptInterface::GetClass(JSObject* obj)
 {
-	UNUSED2(cx); // unused if not JS_THREADSAFE
-
-	return JS_GET_CLASS(cx, obj);
+	return JS_GetClass(obj);
 }
 
-void* ScriptInterface::GetPrivate(JSContext* cx, JSObject* obj)
+void* ScriptInterface::GetPrivate(JSObject* obj)
 {
 	// TODO: use JS_GetInstancePrivate
-	return JS_GetPrivate(cx, obj);
+	return JS_GetPrivate(obj);
 }
 
 void ScriptInterface::DumpHeap()
 {
 #if MOZJS_DEBUG_ABI
-	JS_DumpHeap(m->m_cx, stderr, NULL, 0, NULL, (size_t)-1, NULL);
+	JS_DumpHeap(GetJSRuntime(), stderr, NULL, JSTRACE_OBJECT, NULL, (size_t)-1, NULL);
 #endif
 	fprintf(stderr, "# Bytes allocated: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES));
-	JS_GC(m->m_cx);
+	JS_GC(GetJSRuntime());
 	fprintf(stderr, "# Bytes allocated after GC: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES));
 }
 
@@ -1233,7 +1264,7 @@
 {
 public:
 	ValueCloner(ScriptInterface& from, ScriptInterface& to) :
-		scriptInterfaceFrom(from), cxFrom(from.GetContext()), cxTo(to.GetContext()), m_RooterFrom(from), m_RooterTo(to)
+		scriptInterfaceFrom(from), cxFrom(from.GetContext()), cxTo(to.GetContext()), m_RooterFrom(from.GetContext()), m_RooterTo(to.GetContext())
 	{
 	}
 
@@ -1247,7 +1278,7 @@
 		if (it != m_Mapping.end())
 			return it->second;
 
-		m_RooterFrom.Push(val); // root it so our mapping doesn't get invalidated
+		m_RooterFrom.append(val); // root it so our mapping doesn't get invalidated
 
 		return Clone(val);
 	}
@@ -1259,11 +1290,12 @@
 	// Clone a new value (and root it and add it to the mapping)
 	jsval Clone(jsval val)
 	{
+		JSAutoRequest rq(cxFrom);
 		if (JSVAL_IS_DOUBLE(val))
 		{
-			jsval rval;
-			CLONE_REQUIRE(JS_NewNumberValue(cxTo, JSVAL_TO_DOUBLE(val), &rval), L"JS_NewNumberValue");
-			m_RooterTo.Push(rval);
+			jsval rval = JS_NumberValue(JSVAL_TO_DOUBLE(val));
+			CLONE_REQUIRE(!JSVAL_IS_VOID(rval), L"JS_NumberValue");
+			m_RooterTo.append(rval);
 			return rval;
 		}
 
@@ -1272,52 +1304,63 @@
 			size_t len;
 			const jschar* chars = JS_GetStringCharsAndLength(cxFrom, JSVAL_TO_STRING(val), &len);
 			CLONE_REQUIRE(chars, L"JS_GetStringCharsAndLength");
-			JSString* str = JS_NewUCStringCopyN(cxTo, chars, len);
-			CLONE_REQUIRE(str, L"JS_NewUCStringCopyN");
-			jsval rval = STRING_TO_JSVAL(str);
-			m_Mapping[JSVAL_TO_GCTHING(val)] = rval;
-			m_RooterTo.Push(rval);
-			return rval;
+			{
+			    JSAutoRequest rq(cxTo);
+				JSString* str = JS_NewUCStringCopyN(cxTo, chars, len);
+				CLONE_REQUIRE(str, L"JS_NewUCStringCopyN");
+				jsval rval = STRING_TO_JSVAL(str);
+				m_Mapping[JSVAL_TO_GCTHING(val)] = rval;
+				m_RooterTo.append(rval);
+				return rval;
+			}
 		}
 
-		ENSURE(JSVAL_IS_OBJECT(val));
+		ENSURE(!JSVAL_IS_PRIMITIVE(val));
 
 		JSObject* newObj;
 		if (JS_IsArrayObject(cxFrom, JSVAL_TO_OBJECT(val)))
 		{
-			jsuint length;
+			uint length;
 			CLONE_REQUIRE(JS_GetArrayLength(cxFrom, JSVAL_TO_OBJECT(val), &length), L"JS_GetArrayLength");
-			newObj = JS_NewArrayObject(cxTo, length, NULL);
+			{
+				JSAutoRequest rq(cxTo);
+				newObj = JS_NewArrayObject(cxTo, length, NULL);
+			}	
 			CLONE_REQUIRE(newObj, L"JS_NewArrayObject");
 		}
 		else
 		{
-			newObj = JS_NewObject(cxTo, NULL, NULL, NULL);
+			{
+				JSAutoRequest rq(cxTo);
+				newObj = JS_NewObject(cxTo, NULL, NULL, NULL);
+			}
 			CLONE_REQUIRE(newObj, L"JS_NewObject");
 		}
 
 		m_Mapping[JSVAL_TO_GCTHING(val)] = OBJECT_TO_JSVAL(newObj);
-		m_RooterTo.Push(newObj);
+		m_RooterTo.append(OBJECT_TO_JSVAL(newObj));
 
-		AutoJSIdArray ida (cxFrom, JS_Enumerate(cxFrom, JSVAL_TO_OBJECT(val)));
-		CLONE_REQUIRE(ida.get(), L"JS_Enumerate");
+		JS::AutoIdArray ida (cxFrom, JS_Enumerate(cxFrom, JSVAL_TO_OBJECT(val)));
+		CLONE_REQUIRE(ida, L"JS_Enumerate");
+		
+//		AutoGCRooter idaRooter(scriptInterfaceFrom);
+//		idaRooter.Push(&ida);
 
-		AutoGCRooter idaRooter(scriptInterfaceFrom);
-		idaRooter.Push(ida.get());
-
 		for (size_t i = 0; i < ida.length(); ++i)
 		{
 			jsid id = ida[i];
-			jsval idval, propval;
-			CLONE_REQUIRE(JS_IdToValue(cxFrom, id, &idval), L"JS_IdToValue");
-			CLONE_REQUIRE(JS_GetPropertyById(cxFrom, JSVAL_TO_OBJECT(val), id, &propval), L"JS_GetPropertyById");
-			jsval newPropval = GetOrClone(propval);
+			JS::RootedValue idval(cxTo);
+			JS::RootedValue propval(cxTo);
+			CLONE_REQUIRE(JS_IdToValue(cxFrom, id, idval.address()), L"JS_IdToValue");
+			CLONE_REQUIRE(JS_GetPropertyById(cxFrom, JSVAL_TO_OBJECT(val), id, propval.address()), L"JS_GetPropertyById");
+			JS::RootedValue newPropval(cxTo, GetOrClone(propval));
 
 			if (JSVAL_IS_INT(idval))
 			{
 				// int jsids are portable across runtimes
-				CLONE_REQUIRE(JS_SetPropertyById(cxTo, newObj, id, &newPropval), L"JS_SetPropertyById");
-			}
+				JSAutoRequest rq(cxTo);
+				CLONE_REQUIRE(JS_SetPropertyById(cxTo, newObj, id, newPropval.address()), L"JS_SetPropertyById");
+ 						}
 			else if (JSVAL_IS_STRING(idval))
 			{
 				// string jsids are runtime-specific, so we need to copy the string content
@@ -1326,7 +1369,10 @@
 				size_t len;
 				const jschar* chars = JS_GetStringCharsAndLength(cxFrom, idstr, &len);
 				CLONE_REQUIRE(idstr, L"JS_GetStringCharsAndLength (id)");
-				CLONE_REQUIRE(JS_SetUCProperty(cxTo, newObj, chars, len, &newPropval), L"JS_SetUCProperty");
+				{
+					JSAutoRequest rq(cxTo);
+		                	CLONE_REQUIRE(JS_SetUCProperty(cxTo, newObj, chars, len, newPropval.address()), L"JS_SetUCProperty");
+				}
 			}
 			else
 			{
@@ -1341,8 +1387,8 @@
 	JSContext* cxFrom;
 	JSContext* cxTo;
 	std::map<void*, jsval> m_Mapping;
-	AutoGCRooter m_RooterFrom;
-	AutoGCRooter m_RooterTo;
+	JS::AutoValueVector m_RooterFrom;
+	JS::AutoValueVector m_RooterTo;
 };
 
 jsval ScriptInterface::CloneValueFromOtherContext(ScriptInterface& otherContext, jsval val)
@@ -1354,28 +1400,28 @@
 }
 
 ScriptInterface::StructuredClone::StructuredClone() :
-	m_Context(NULL), m_Data(NULL), m_Size(0)
+	m_Data(NULL), m_Size(0)
 {
 }
 
 ScriptInterface::StructuredClone::~StructuredClone()
 {
 	if (m_Data)
-		JS_free(m_Context, m_Data);
+		JS_ClearStructuredClone(m_Data, m_Size);
 }
 
 shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClone(jsval v)
 {
-	uint64* data = NULL;
+	JSAutoRequest rq(m->m_cx);
+	uint64_t* data = NULL;
 	size_t nbytes = 0;
-	if (!JS_WriteStructuredClone(m->m_cx, v, &data, &nbytes, NULL, NULL))
+	if (!JS_WriteStructuredClone(m->m_cx, v, &data, &nbytes, NULL, NULL, JSVAL_VOID))
 	{
 		debug_warn(L"Writing a structured clone with JS_WriteStructuredClone failed!");
 		return shared_ptr<StructuredClone>();
 	}
 
 	shared_ptr<StructuredClone> ret (new StructuredClone);
-	ret->m_Context = m->m_cx;
 	ret->m_Data = data;
 	ret->m_Size = nbytes;
 	return ret;
@@ -1383,6 +1429,7 @@
 
 jsval ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr)
 {
+	JSAutoRequest rq(m->m_cx);
 	jsval ret = JSVAL_VOID;
 	JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, &ret, NULL, NULL);
 	return ret;
Index: source/scriptinterface/AutoRooters.h
===================================================================
--- source/scriptinterface/AutoRooters.h	(Revision 14578)
+++ source/scriptinterface/AutoRooters.h	(Arbeitskopie)
@@ -1,53 +0,0 @@
-/* Copyright (C) 2010 Wildfire Games.
- * This file is part of 0 A.D.
- *
- * 0 A.D. is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * 0 A.D. is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef INCLUDED_AUTOROOTERS
-#define INCLUDED_AUTOROOTERS
-
-#include "scriptinterface/ScriptTypes.h"
-
-#include "js/jsapi.h"
-
-/**
- * Helper for rooting large groups of script values.
- * Construct this object, push values into it, and they will all be rooted until this
- * object is destroyed.
- * Many of these objects can be used at once, but their lifetimes must be correctly nested.
- */
-class AutoGCRooter
-{
-	NONCOPYABLE(AutoGCRooter);
-public:
-	AutoGCRooter(ScriptInterface& scriptInterface);
-	~AutoGCRooter();
-
-	void Push(JSObject* obj) { m_Objects.push_back(obj); }
-	void Push(jsval val) { m_Vals.push_back(val); }
-	void Push(JSIdArray* ida) { m_IdArrays.push_back(ida); }
-
-	void Trace(JSTracer* trc);
-private:
-	ScriptInterface& m_ScriptInterface;
-	AutoGCRooter* m_Previous;
-
-	std::vector<JSObject*> m_Objects;
-	std::vector<jsval> m_Vals;
-	std::vector<JSIdArray*> m_IdArrays;
-	// TODO: add vectors of other value types
-};
-
-#endif // INCLUDED_AUTOROOTERS
Index: source/scriptinterface/ScriptConversions.cpp
===================================================================
--- source/scriptinterface/ScriptConversions.cpp	(Revision 14578)
+++ source/scriptinterface/ScriptConversions.cpp	(Arbeitskopie)
@@ -32,6 +32,7 @@
 
 template<> bool ScriptInterface::FromJSVal<bool>(JSContext* cx, jsval v, bool& out)
 {
+    JSAutoRequest rq(cx);
 	JSBool ret;
 	WARN_IF_NOT(JSVAL_IS_BOOLEAN(v), v);
 	if (!JS_ValueToBoolean(cx, v, &ret))
@@ -42,7 +43,8 @@
 
 template<> bool ScriptInterface::FromJSVal<float>(JSContext* cx, jsval v, float& out)
 {
-	jsdouble ret;
+    JSAutoRequest rq(cx);
+	double ret;
 	WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
 	if (!JS_ValueToNumber(cx, v, &ret))
 		return false;
@@ -52,7 +54,8 @@
 
 template<> bool ScriptInterface::FromJSVal<double>(JSContext* cx, jsval v, double& out)
 {
-	jsdouble ret;
+    JSAutoRequest rq(cx);
+	double ret;
 	WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
 	if (!JS_ValueToNumber(cx, v, &ret))
 		return false;
@@ -62,9 +65,12 @@
 
 template<> bool ScriptInterface::FromJSVal<i32>(JSContext* cx, jsval v, i32& out)
 {
-	int32 ret;
+    JSAutoRequest rq(cx);
+    // TODO: Change FromJSVal to use JS::RootedValue and remove this temporary workaround here
+    JS::RootedValue v1(cx, v);
+	int32_t ret;
 	WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
-	if (!JS_ValueToECMAInt32(cx, v, &ret))
+	if (!JS::ToInt32(cx, v1, &ret))
 		return false;
 	out = ret;
 	return true;
@@ -72,7 +78,8 @@
 
 template<> bool ScriptInterface::FromJSVal<u32>(JSContext* cx, jsval v, u32& out)
 {
-	uint32 ret;
+    JSAutoRequest rq(cx);
+	uint32_t ret;
 	WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
 	if (!JS_ValueToECMAUint32(cx, v, &ret))
 		return false;
@@ -82,7 +89,8 @@
 
 template<> bool ScriptInterface::FromJSVal<u16>(JSContext* cx, jsval v, u16& out)
 {
-	uint16 ret;
+    JSAutoRequest rq(cx);
+	uint16_t ret;
 	WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
 	if (!JS_ValueToUint16(cx, v, &ret))
 		return false;
@@ -92,7 +100,8 @@
 
 template<> bool ScriptInterface::FromJSVal<u8>(JSContext* cx, jsval v, u8& out)
 {
-	uint16 ret;
+    JSAutoRequest rq(cx);
+	uint16_t ret;
 	WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
 	if (!JS_ValueToUint16(cx, v, &ret))
 		return false;
@@ -102,18 +111,18 @@
 
 template<> bool ScriptInterface::FromJSVal<long>(JSContext* cx, jsval v, long& out)
 {
-	int32 tmp;
-	JSBool ok = JS_ValueToInt32(cx, v, &tmp);
+	int32_t tmp;
+	bool ok = JS_ValueToInt32(cx, v, &tmp);
 	out = (long)tmp;
-	return ok == JS_TRUE;
+	return ok;
 }
 
 template<> bool ScriptInterface::FromJSVal<unsigned long>(JSContext* cx, jsval v, unsigned long& out)
 {
-	int32 tmp;
-	JSBool ok = JS_ValueToInt32(cx, v, &tmp);
+	int32_t tmp;
+	bool ok = JS_ValueToInt32(cx, v, &tmp);
 	out = (unsigned long)tmp;
-	return ok == JS_TRUE;
+	return ok;
 }
 
 // see comment below (where the same preprocessor condition is used)
@@ -143,13 +152,27 @@
 
 #endif
 
-// NOTE: we can't define a jsval specialisation, because that conflicts with integer types
+template<> jsval ScriptInterface::ToJSVal<JS::Value>(JSContext* UNUSED(cx), const JS::Value& val)
+{
+	return val;
+}
+
 template<> bool ScriptInterface::FromJSVal<CScriptVal>(JSContext* UNUSED(cx), jsval v, CScriptVal& out)
 {
 	out = v;
 	return true;
 }
 
+template<> bool ScriptInterface::FromJSVal<JS::RootedObject>(JSContext* UNUSED(cx), jsval v, JS::RootedObject& out)
+{
+	if (v.isObjectOrNull())
+	{
+		out.set(JSVAL_TO_OBJECT(v));
+		return true;
+	}
+	return false;
+}
+
 template<> bool ScriptInterface::FromJSVal<CScriptValRooted>(JSContext* cx, jsval v, CScriptValRooted& out)
 {
 	out = CScriptValRooted(cx, v);
@@ -158,6 +181,7 @@
 
 template<> bool ScriptInterface::FromJSVal<std::wstring>(JSContext* cx, jsval v, std::wstring& out)
 {
+    JSAutoRequest rq(cx);
 	WARN_IF_NOT(JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v), v); // allow implicit number conversions
 	JSString* ret = JS_ValueToString(cx, v);
 	if (!ret)
@@ -181,6 +205,7 @@
 
 template<> bool ScriptInterface::FromJSVal<std::string>(JSContext* cx, jsval v, std::string& out)
 {
+    JSAutoRequest rq(cx);
 	WARN_IF_NOT(JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v), v); // allow implicit number conversions
 	JSString* ret = JS_ValueToString(cx, v);
 	if (!ret)
@@ -205,22 +230,27 @@
 
 template<> bool ScriptInterface::FromJSVal<Entity>(JSContext* cx, jsval v, Entity& out)
 {
+    JSAutoRequest rq(cx);
 	JSObject* obj;
 	if (!JS_ValueToObject(cx, v, &obj) || obj == NULL)
 		FAIL("Argument must be an object");
 
-	jsval templateName, id, player, position, rotation;
+	JS::RootedValue templateName(cx);
+	JS::RootedValue id(cx);
+	JS::RootedValue player(cx);
+	JS::RootedValue position(cx);
+	JS::RootedValue rotation(cx);
 
 	// TODO: Report type errors
-	if(!JS_GetProperty(cx, obj, "player", &player) || !FromJSVal(cx, player, out.playerID))
+	if(!JS_GetProperty(cx, obj, "player", player.address()) || !FromJSVal(cx, player, out.playerID))
 		FAIL("Failed to read Entity.player property");
-	if (!JS_GetProperty(cx, obj, "templateName", &templateName) || !FromJSVal(cx, templateName, out.templateName))
+	if (!JS_GetProperty(cx, obj, "templateName", templateName.address()) || !FromJSVal(cx, templateName, out.templateName))
 		FAIL("Failed to read Entity.templateName property");
-	if (!JS_GetProperty(cx, obj, "id", &id) || !FromJSVal(cx, id, out.entityID))
+	if (!JS_GetProperty(cx, obj, "id", id.address()) || !FromJSVal(cx, id, out.entityID))
 		FAIL("Failed to read Entity.id property");
-	if (!JS_GetProperty(cx, obj, "position", &position) || !FromJSVal(cx, position, out.position))
+	if (!JS_GetProperty(cx, obj, "position", position.address()) || !FromJSVal(cx, position, out.position))
 		FAIL("Failed to read Entity.position property");
-	if (!JS_GetProperty(cx, obj, "rotation", &rotation) || !FromJSVal(cx, rotation, out.rotation))
+	if (!JS_GetProperty(cx, obj, "rotation", rotation.address()) || !FromJSVal(cx, rotation, out.rotation))
 		FAIL("Failed to read Entity.rotation property");
 
 	return true;
@@ -234,17 +264,15 @@
 	return val ? JSVAL_TRUE : JSVAL_FALSE;
 }
 
-template<> jsval ScriptInterface::ToJSVal<float>(JSContext* cx, const float& val)
+template<> jsval ScriptInterface::ToJSVal<float>(JSContext* UNUSED(cx), const float& val)
 {
-	jsval rval = JSVAL_VOID;
-	JS_NewNumberValue(cx, val, &rval); // ignore return value
+	jsval rval = JS_NumberValue(val);
 	return rval;
 }
 
-template<> jsval ScriptInterface::ToJSVal<double>(JSContext* cx, const double& val)
+template<> jsval ScriptInterface::ToJSVal<double>(JSContext* UNUSED(cx), const double& val)
 {
-	jsval rval = JSVAL_VOID;
-	JS_NewNumberValue(cx, val, &rval); // ignore return value
+	jsval rval = JS_NumberValue(val);
 	return rval;
 }
 
@@ -264,12 +292,11 @@
 	return INT_TO_JSVAL(val);
 }
 
-template<> jsval ScriptInterface::ToJSVal<u32>(JSContext* cx, const u32& val)
+template<> jsval ScriptInterface::ToJSVal<u32>(JSContext* UNUSED(cx), const u32& val)
 {
 	if (val <= JSVAL_INT_MAX)
 		return INT_TO_JSVAL(val);
-	jsval rval = JSVAL_VOID;
-	JS_NewNumberValue(cx, val, &rval); // ignore return value
+	jsval rval = JS_NumberValue(val);
 	return rval;
 }
 
@@ -315,6 +342,7 @@
 
 template<> jsval ScriptInterface::ToJSVal<std::wstring>(JSContext* cx, const std::wstring& val)
 {
+    JSAutoRequest rq(cx);
 	utf16string utf16(val.begin(), val.end());
 	JSString* str = JS_NewUCStringCopyN(cx, reinterpret_cast<const jschar*> (utf16.c_str()), utf16.length());
 	if (str)
@@ -329,6 +357,7 @@
 
 template<> jsval ScriptInterface::ToJSVal<std::string>(JSContext* cx, const std::string& val)
 {
+    JSAutoRequest rq(cx);
 	JSString* str = JS_NewStringCopyN(cx, val.c_str(), val.length());
 	if (str)
 		return STRING_TO_JSVAL(str);
@@ -342,6 +371,7 @@
 
 template<> jsval ScriptInterface::ToJSVal<const char*>(JSContext* cx, const char* const& val)
 {
+    JSAutoRequest rq(cx);
 	JSString* str = JS_NewStringCopyZ(cx, val);
 	if (str)
 		return STRING_TO_JSVAL(str);
@@ -363,30 +393,32 @@
 
 template<typename T> static jsval ToJSVal_vector(JSContext* cx, const std::vector<T>& val)
 {
-	JSObject* obj = JS_NewArrayObject(cx, (jsint)val.size(), NULL);
+	JSAutoRequest rq(cx);
+	JSObject* obj = JS_NewArrayObject(cx, val.size(), NULL);
 	if (!obj)
 		return JSVAL_VOID;
-	for (size_t i = 0; i < val.size(); ++i)
+	for (uint32_t i = 0; i < val.size(); ++i)
 	{
-		jsval el = ScriptInterface::ToJSVal<T>(cx, val[i]);
-		JS_SetElement(cx, obj, (jsint)i, &el);
+		JS::RootedValue el(cx, ScriptInterface::ToJSVal<T>(cx, val[i]));
+		JS_SetElement(cx, obj, i, el.address());
 	}
 	return OBJECT_TO_JSVAL(obj);
 }
 
 template<typename T> static bool FromJSVal_vector(JSContext* cx, jsval v, std::vector<T>& out)
 {
+	JSAutoRequest rq(cx);
 	JSObject* obj;
-	if (!JS_ValueToObject(cx, v, &obj) || obj == NULL || !(JS_IsArrayObject(cx, obj) || js_IsTypedArray(obj)))
+	if (!JS_ValueToObject(cx, v, &obj) || obj == NULL || !(JS_IsArrayObject(cx, obj) || JS_IsTypedArrayObject(obj)))
 		FAIL("Argument must be an array");
-	jsuint length;
+	uint32_t length;
 	if (!JS_GetArrayLength(cx, obj, &length))
 		FAIL("Failed to get array length");
 	out.reserve(length);
-	for (jsuint i = 0; i < length; ++i)
+	for (uint32_t i = 0; i < length; ++i)
 	{
-		jsval el;
-		if (!JS_GetElement(cx, obj, i, &el))
+		JS::RootedValue el(cx);
+		if (!JS_GetElement(cx, obj, i, el.address()))
 			FAIL("Failed to read array element");
 		T el2;
 		if (!ScriptInterface::FromJSVal<T>(cx, el, el2))
Index: source/scripting/JSUtil.cpp
===================================================================
--- source/scripting/JSUtil.cpp	(Revision 14578)
+++ source/scripting/JSUtil.cpp	(Arbeitskopie)
@@ -1,32 +0,0 @@
-/* Copyright (C) 2009 Wildfire Games.
- * This file is part of 0 A.D.
- *
- * 0 A.D. is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * 0 A.D. is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "precompiled.h"
-
-#include "SpiderMonkey.h"
-
-JSBool jsu_report_param_error(JSContext* cx, jsval* vp)
-{
-	JS_ReportError(cx, "Invalid parameter(s) or count");
-
-	if (vp)
-		JS_SET_RVAL(cx, vp, JSVAL_NULL);
-
-	// yes, we had an error, but returning JS_FALSE would cause SpiderMonkey
-	// to abort. that would be hard to debug.
-	return JS_TRUE;
-}
Index: source/scripting/SpiderMonkey.h
===================================================================
--- source/scripting/SpiderMonkey.h	(Arbeitskopie)
+++ source/scripting/SpiderMonkey.h	(Arbeitskopie)
@@ -35,8 +35,6 @@
 
 #include "scriptinterface/ScriptTypes.h"
 
-#include "JSUtil.h"
-
 // Make JS debugging a little easier by automatically naming GC roots
 // Don't simply #define NAME_ALL_GC_ROOTS, because jsapi.h is horridly broken
 #ifndef NDEBUG
Index: source/scripting/JSUtil.h
===================================================================
--- source/scripting/JSUtil.h	(Revision 14578)
+++ source/scripting/JSUtil.h	(Arbeitskopie)
@@ -1,64 +0,0 @@
-/* Copyright (C) 2009 Wildfire Games.
- * This file is part of 0 A.D.
- *
- * 0 A.D. is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * 0 A.D. is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// included from SpiderMonkey.h
-
-extern JSBool jsu_report_param_error(JSContext* cx, jsval* vp);
-
-
-// consistent argc checking for normal function wrappers: reports an
-// error via JS and returns if number of parameters is incorrect.
-// .. require exact number (most common case)
-#define JSU_REQUIRE_PARAMS(exact_number)\
-	if(argc != exact_number)\
-		return jsu_report_param_error(cx, vp);
-// .. require 0 params (avoids L4 warning "unused argv param")
-#define JSU_REQUIRE_NO_PARAMS()\
-	if(argc != 0)\
-		return jsu_report_param_error(cx, vp);
-// .. require a certain range (e.g. due to optional params)
-#define JSU_REQUIRE_PARAM_RANGE(min_number, max_number)\
-	if(!(min_number <= argc && argc <= max_number))\
-		return jsu_report_param_error(cx, vp);
-// .. require at most a certain count
-#define JSU_REQUIRE_MAX_PARAMS(max_number)\
-	if(argc > max_number)\
-		return jsu_report_param_error(cx, vp);
-// .. require at least a certain count (rarely needed)
-#define JSU_REQUIRE_MIN_PARAMS(min_number)\
-	if(argc < min_number)\
-		return jsu_report_param_error(cx, vp);
-
-// same as JSU_REQUIRE_PARAMS, but used from C++ functions that are
-// a bit further removed from SpiderMonkey, i.e. return a
-// C++ bool indicating success, and not taking an rval param.
-#define JSU_REQUIRE_PARAMS_CPP(exact_number)\
-	if(argc != exact_number)\
-	{\
-		jsu_report_param_error(cx, 0);\
-		return false;\
-	}
-
-
-#define JSU_ASSERT(expr, msg)\
-STMT(\
-	if(!(expr))\
-	{\
-		JS_ReportError(cx, msg);\
-		return JS_FALSE;\
-	}\
-)
Index: source/lib/types.h
===================================================================
--- source/lib/types.h	(Revision 14578)
+++ source/lib/types.h	(Arbeitskopie)
@@ -33,12 +33,15 @@
 
 #define i8 int8_t
 #define i16 int16_t
-#define i32 int32_t
+//#define i32 int32_t
+typedef int32_t i32;
 #define i64 int64_t
 
 #define u8  uint8_t
-#define u16 uint16_t
-#define u32 uint32_t
+//#define u16 uint16_t
+typedef uint16_t u16;
+//#define u32 uint32_t
+typedef uint32_t u32;
 #define u64 uint64_t
 
 #endif // #ifndef INCLUDED_TYPES
Index: source/gui/IGUIObject.cpp
===================================================================
--- source/gui/IGUIObject.cpp	(Revision 14578)
+++ source/gui/IGUIObject.cpp	(Arbeitskopie)
@@ -420,6 +420,7 @@
 		throw PSERROR_GUI_OperationNeedsGUIObject();
 		
 	JSContext* cx = pGUI->GetScriptInterface()->GetContext();
+	JSAutoRequest rq(cx);
 	
 	const int paramCount = 1;
 	const char* paramNames[paramCount] = { "mouse" };
@@ -467,7 +468,8 @@
 		return;
 
 	JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
-
+	JSAutoRequest rq(cx);
+	
 	// Set up the 'mouse' parameter
 	CScriptVal mouse;
 	m_pGUI->GetScriptInterface()->Eval("({})", mouse);
@@ -478,7 +480,7 @@
 	jsval paramData[] = { mouse.get() };
 
 	jsval result;
-	JSBool ok = JS_CallFunctionValue(cx, GetJSObject(), (*it).second.get(), ARRAY_SIZE(paramData), paramData, &result);
+	bool ok = JS_CallFunctionValue(cx, GetJSObject(), (*it).second.get(), ARRAY_SIZE(paramData), paramData, &result);
 	if (!ok)
 	{
 		// We have no way to propagate the script exception, so just ignore it
@@ -498,7 +500,7 @@
 	jsval arg = Argument.get();
 
 	jsval result;
-	JSBool ok = JS_CallFunctionValue(cx, object, (*it).second.get(), 1, &arg, &result);
+	bool ok = JS_CallFunctionValue(cx, object, (*it).second.get(), 1, &arg, &result);
 	if (!ok)
 	{
 		JS_ReportError(cx, "Errors executing script action \"%s\"", Action.c_str());
@@ -508,6 +510,7 @@
 JSObject* IGUIObject::GetJSObject()
 {
 	JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
+	JSAutoRequest rq(cx);
 	// Cache the object when somebody first asks for it, because otherwise
 	// we end up doing far too much object allocation. TODO: Would be nice to
 	// not have these objects hang around forever using up memory, though.
@@ -515,7 +518,7 @@
 	{
 		JSObject* obj = JS_NewObject(cx, &JSI_IGUIObject::JSI_class, NULL, NULL);
 		m_JSObject = CScriptValRooted(cx, OBJECT_TO_JSVAL(obj));
-		JS_SetPrivate(cx, JSVAL_TO_OBJECT(m_JSObject.get()), this);
+		JS_SetPrivate(JSVAL_TO_OBJECT(m_JSObject.get()), this);
 	}
 	return JSVAL_TO_OBJECT(m_JSObject.get());;
 }
Index: source/gui/scripting/JSInterface_GUITypes.cpp
===================================================================
--- source/gui/scripting/JSInterface_GUITypes.cpp	(Revision 14578)
+++ source/gui/scripting/JSInterface_GUITypes.cpp	(Arbeitskopie)
@@ -23,10 +23,10 @@
 /**** GUISize ****/
 JSClass JSI_GUISize::JSI_class = {
 	"GUISize", 0,
-		JS_PropertyStub, JS_PropertyStub,
+		JS_PropertyStub, JS_DeletePropertyStub,
 		JS_PropertyStub, JS_StrictPropertyStub,
 		JS_EnumerateStub, JS_ResolveStub,
-		JS_ConvertStub, JS_FinalizeStub,
+		JS_ConvertStub, NULL,
 		NULL, NULL, NULL, JSI_GUISize::construct
 };
 
@@ -45,48 +45,61 @@
 
 JSFunctionSpec JSI_GUISize::JSI_methods[] = 
 {
-	{ "toString", JSI_GUISize::toString, 0, 0 },
-	{ 0 }
+	JS_FS("toString", JSI_GUISize::toString, 0, 0),
+	JS_FS_END
 };
 
-JSBool JSI_GUISize::construct(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_GUISize::construct(JSContext* cx, uint argc, jsval* vp)
 {
 	JSObject* obj = JS_NewObject(cx, &JSI_GUISize::JSI_class, NULL, NULL);
 
+	// TODO: ugly with so much repetition...?
 	if (argc == 8)
 	{
-		JS_SetProperty(cx, obj, "left",		&JS_ARGV(cx, vp)[0]);
-		JS_SetProperty(cx, obj, "top",		&JS_ARGV(cx, vp)[1]);
-		JS_SetProperty(cx, obj, "right",	&JS_ARGV(cx, vp)[2]);
-		JS_SetProperty(cx, obj, "bottom",	&JS_ARGV(cx, vp)[3]);
-		JS_SetProperty(cx, obj, "rleft",	&JS_ARGV(cx, vp)[4]);
-		JS_SetProperty(cx, obj, "rtop",		&JS_ARGV(cx, vp)[5]);
-		JS_SetProperty(cx, obj, "rright",	&JS_ARGV(cx, vp)[6]);
-		JS_SetProperty(cx, obj, "rbottom",	&JS_ARGV(cx, vp)[7]);
+		JS::RootedValue v0(cx, JS_ARGV(cx, vp)[0]);
+		JS::RootedValue v1(cx, JS_ARGV(cx, vp)[1]);
+		JS::RootedValue v2(cx, JS_ARGV(cx, vp)[2]);
+		JS::RootedValue v3(cx, JS_ARGV(cx, vp)[3]);
+		JS::RootedValue v4(cx, JS_ARGV(cx, vp)[4]);
+		JS::RootedValue v5(cx, JS_ARGV(cx, vp)[5]);
+		JS::RootedValue v6(cx, JS_ARGV(cx, vp)[6]);
+		JS::RootedValue v7(cx, JS_ARGV(cx, vp)[7]);
+		JS_SetProperty(cx, obj, "left",		v0.address());
+		JS_SetProperty(cx, obj, "top",		v1.address());
+		JS_SetProperty(cx, obj, "right",	v2.address());
+		JS_SetProperty(cx, obj, "bottom",	v3.address());
+		JS_SetProperty(cx, obj, "rleft",	v4.address());
+		JS_SetProperty(cx, obj, "rtop",		v5.address());
+		JS_SetProperty(cx, obj, "rright",	v6.address());
+		JS_SetProperty(cx, obj, "rbottom",	v7.address());
 	}
 	else if (argc == 4)
 	{
-		jsval zero = JSVAL_ZERO;
-		JS_SetProperty(cx, obj, "left",		&JS_ARGV(cx, vp)[0]);
-		JS_SetProperty(cx, obj, "top",		&JS_ARGV(cx, vp)[1]);
-		JS_SetProperty(cx, obj, "right",	&JS_ARGV(cx, vp)[2]);
-		JS_SetProperty(cx, obj, "bottom",	&JS_ARGV(cx, vp)[3]);
-		JS_SetProperty(cx, obj, "rleft",	&zero);
-		JS_SetProperty(cx, obj, "rtop",		&zero);
-		JS_SetProperty(cx, obj, "rright",	&zero);
-		JS_SetProperty(cx, obj, "rbottom",	&zero);
+		JS::RootedValue zero(cx, JSVAL_ZERO);
+		JS::RootedValue v0(cx, JS_ARGV(cx, vp)[0]);
+		JS::RootedValue v1(cx, JS_ARGV(cx, vp)[1]);
+		JS::RootedValue v2(cx, JS_ARGV(cx, vp)[2]);
+		JS::RootedValue v3(cx, JS_ARGV(cx, vp)[3]);
+		JS_SetProperty(cx, obj, "left",		v0.address());
+		JS_SetProperty(cx, obj, "top",		v1.address());
+		JS_SetProperty(cx, obj, "right",	v2.address());
+		JS_SetProperty(cx, obj, "bottom",	v3.address());
+		JS_SetProperty(cx, obj, "rleft",	zero.address());
+		JS_SetProperty(cx, obj, "rtop",		zero.address());
+		JS_SetProperty(cx, obj, "rright",	zero.address());
+		JS_SetProperty(cx, obj, "rbottom",	zero.address());
 	}
 	else
 	{
-		jsval zero = JSVAL_ZERO;
-		JS_SetProperty(cx, obj, "left",		&zero);
-		JS_SetProperty(cx, obj, "top",		&zero);
-		JS_SetProperty(cx, obj, "right",	&zero);
-		JS_SetProperty(cx, obj, "bottom",	&zero);
-		JS_SetProperty(cx, obj, "rleft",	&zero);
-		JS_SetProperty(cx, obj, "rtop",		&zero);
-		JS_SetProperty(cx, obj, "rright",	&zero);
-		JS_SetProperty(cx, obj, "rbottom",	&zero);
+		JS::RootedValue zero(cx, JSVAL_ZERO);
+		JS_SetProperty(cx, obj, "left",		zero.address());
+		JS_SetProperty(cx, obj, "top",		zero.address());
+		JS_SetProperty(cx, obj, "right",	zero.address());
+		JS_SetProperty(cx, obj, "bottom",	zero.address());
+		JS_SetProperty(cx, obj, "rleft",	zero.address());
+		JS_SetProperty(cx, obj, "rtop",		zero.address());
+		JS_SetProperty(cx, obj, "rright",	zero.address());
+		JS_SetProperty(cx, obj, "rbottom",	zero.address());
 	}
 
 	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
@@ -102,7 +115,7 @@
 		return CStr::FromDouble(per)+"%"+( pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix) );
 }
 
-JSBool JSI_GUISize::toString(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 
@@ -141,10 +154,10 @@
 
 JSClass JSI_GUIColor::JSI_class = {
 	"GUIColor", 0,
-		JS_PropertyStub, JS_PropertyStub,
+		JS_PropertyStub, JS_DeletePropertyStub,
 		JS_PropertyStub, JS_StrictPropertyStub,
 		JS_EnumerateStub, JS_ResolveStub,
-		JS_ConvertStub, JS_FinalizeStub,
+		JS_ConvertStub, NULL,
 		NULL, NULL, NULL, JSI_GUIColor::construct
 };
 
@@ -159,11 +172,11 @@
 
 JSFunctionSpec JSI_GUIColor::JSI_methods[] = 
 {
-	{ "toString", JSI_GUIColor::toString, 0, 0 },
-	{ 0 }
+	JS_FS("toString", JSI_GUIColor::toString, 0, 0),
+	JS_FS_END
 };
 
-JSBool JSI_GUIColor::construct(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_GUIColor::construct(JSContext* cx, uint argc, jsval* vp)
 {
 	JSObject* obj = JS_NewObject(cx, &JSI_GUIColor::JSI_class, NULL, NULL);
 
@@ -177,22 +190,23 @@
 	else
 	{
 		// Nice magenta:
-		jsval c;
-		if (!JS_NewNumberValue(cx, 1.0, &c))
+		JS::RootedValue c(cx, JS_NumberValue(1.0));
+		if (JSVAL_IS_NULL(c))
 			return JS_FALSE;
-		JS_SetProperty(cx, obj, "r", &c);
-		JS_SetProperty(cx, obj, "b", &c);
-		JS_SetProperty(cx, obj, "a", &c);
-		if (!JS_NewNumberValue(cx, 0.0, &c))
+		JS_SetProperty(cx, obj, "r", c.address());
+		JS_SetProperty(cx, obj, "b", c.address());
+		JS_SetProperty(cx, obj, "a", c.address());
+		c = JS_NumberValue(0.0);
+		if (JSVAL_IS_NULL(c))
 			return JS_FALSE;
-		JS_SetProperty(cx, obj, "g", &c);
+		JS_SetProperty(cx, obj, "g", c.address());
 	}
 
 	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
 	return JS_TRUE;
 }
 
-JSBool JSI_GUIColor::toString(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_GUIColor::toString(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 
@@ -218,10 +232,10 @@
 
 JSClass JSI_GUIMouse::JSI_class = {
 	"GUIMouse", 0,
-		JS_PropertyStub, JS_PropertyStub,
+		JS_PropertyStub, JS_DeletePropertyStub,
 		JS_PropertyStub, JS_StrictPropertyStub,
 		JS_EnumerateStub, JS_ResolveStub,
-		JS_ConvertStub, JS_FinalizeStub,
+		JS_ConvertStub, NULL,
 		NULL, NULL, NULL, JSI_GUIMouse::construct
 };
 
@@ -235,37 +249,40 @@
 
 JSFunctionSpec JSI_GUIMouse::JSI_methods[] = 
 {
-	{ "toString", JSI_GUIMouse::toString, 0, 0 },
-	{ 0 }
+	JS_FS("toString", JSI_GUIMouse::toString, 0, 0),
+	JS_FS_END
 };
 
-JSBool JSI_GUIMouse::construct(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_GUIMouse::construct(JSContext* cx, uint argc, jsval* vp)
 {
 	JSObject* obj = JS_NewObject(cx, &JSI_GUIMouse::JSI_class, NULL, NULL);
 
 	if (argc == 3)
 	{
-		JS_SetProperty(cx, obj, "x", &JS_ARGV(cx, vp)[0]);
-		JS_SetProperty(cx, obj, "y", &JS_ARGV(cx, vp)[1]);
-		JS_SetProperty(cx, obj, "buttons", &JS_ARGV(cx, vp)[2]);
+		JS::RootedValue v0(cx, JS_ARGV(cx, vp)[0]);
+		JS::RootedValue v1(cx, JS_ARGV(cx, vp)[1]);
+		JS::RootedValue v2(cx, JS_ARGV(cx, vp)[2]);
+		JS_SetProperty(cx, obj, "x", v0.address());
+		JS_SetProperty(cx, obj, "y", v1.address());
+		JS_SetProperty(cx, obj, "buttons", v2.address());
 	}
 	else
 	{
-		jsval zero = JSVAL_ZERO;
-		JS_SetProperty(cx, obj, "x", &zero);
-		JS_SetProperty(cx, obj, "y", &zero);
-		JS_SetProperty(cx, obj, "buttons", &zero);
+		JS::RootedValue zero (cx, JSVAL_ZERO);
+		JS_SetProperty(cx, obj, "x", zero.address());
+		JS_SetProperty(cx, obj, "y", zero.address());
+		JS_SetProperty(cx, obj, "buttons", zero.address());
 	}
 
 	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
 	return JS_TRUE;
 }
 
-JSBool JSI_GUIMouse::toString(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_GUIMouse::toString(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 
-	int32 x, y, buttons;
+	int32_t x, y, buttons;
 	ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
 	pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "x", x);
 	pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "y", y);
Index: source/gui/scripting/JSInterface_GUITypes.h
===================================================================
--- source/gui/scripting/JSInterface_GUITypes.h	(Revision 14578)
+++ source/gui/scripting/JSInterface_GUITypes.h	(Arbeitskopie)
@@ -26,8 +26,8 @@
 		extern JSClass JSI_class;				\
 		extern JSPropertySpec JSI_props[];		\
 		extern JSFunctionSpec JSI_methods[];	\
-		JSBool construct(JSContext* cx, uintN argc, jsval* vp);	\
-		JSBool toString(JSContext* cx, uintN argc, jsval* vp);	\
+		JSBool construct(JSContext* cx, uint argc, jsval* vp);	\
+		JSBool toString(JSContext* cx, uint argc, jsval* vp);	\
 	}
 
 GUISTDTYPE(Size)
Index: source/gui/scripting/ScriptFunctions.cpp
===================================================================
--- source/gui/scripting/ScriptFunctions.cpp	(Revision 14578)
+++ source/gui/scripting/ScriptFunctions.cpp	(Arbeitskopie)
@@ -69,7 +69,6 @@
 #include "soundmanager/SoundManager.h"
 #include "soundmanager/scripting/JSInterface_Sound.h"
 
-#include "js/jsapi.h"
 /*
  * This file defines a set of functions that are available to GUI scripts, to allow
  * interaction with the rest of the engine.
@@ -552,7 +551,7 @@
 void ForceGC(ScriptInterface::CxPrivate* pCxPrivate)
 {
 	double time = timer_Time();
-	JS_GC(pCxPrivate->pScriptInterface->GetContext());
+	JS_GC(pCxPrivate->pScriptInterface->GetJSRuntime());
 	time = timer_Time() - time;
 	g_Console->InsertMessage(L"Garbage collection completed in: %f", time);
 }
Index: source/gui/scripting/JSInterface_IGUIObject.cpp
===================================================================
--- source/gui/scripting/JSInterface_IGUIObject.cpp	(Revision 14578)
+++ source/gui/scripting/JSInterface_IGUIObject.cpp	(Arbeitskopie)
@@ -32,28 +32,28 @@
 
 JSClass JSI_IGUIObject::JSI_class = {
 	"GUIObject", JSCLASS_HAS_PRIVATE,
-	JS_PropertyStub, JS_PropertyStub,
+	JS_PropertyStub, JS_DeletePropertyStub,
 	JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty,
 	JS_EnumerateStub, JS_ResolveStub,
-	JS_ConvertStub, JS_FinalizeStub,
+	JS_ConvertStub, NULL,
 	NULL, NULL, NULL, JSI_IGUIObject::construct
 };
 
-JSPropertySpec JSI_IGUIObject::JSI_props[] = 
+JSPropertySpec JSI_IGUIObject::JSI_props[] =
 {
 	{ 0 }
 };
 
-JSFunctionSpec JSI_IGUIObject::JSI_methods[] = 
+JSFunctionSpec JSI_IGUIObject::JSI_methods[] =
 {
-	{ "toString", JSI_IGUIObject::toString, 0, 0 },
-	{ "focus", JSI_IGUIObject::focus, 0, 0 },
-	{ "blur", JSI_IGUIObject::blur, 0, 0 },
-	{ "getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0 },
-	{ 0 }
+	JS_FS("toString", JSI_IGUIObject::toString, 0, 0),
+	JS_FS("focus", JSI_IGUIObject::focus, 0, 0),
+	JS_FS("blur", JSI_IGUIObject::blur, 0, 0),
+	JS_FS("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0),
+	JS_FS_END
 };
 
-JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)
+JSBool JSI_IGUIObject::getProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<jsval> vp)
 {
 	IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
 	if (!e)
@@ -88,9 +88,9 @@
 		CStr eventName (CStr(propName.substr(2)).LowerCase());
 		std::map<CStr, CScriptValRooted>::iterator it = e->m_ScriptHandlers.find(eventName);
 		if (it == e->m_ScriptHandlers.end())
-			*vp = JSVAL_NULL;
+			vp.set(JSVAL_NULL);
 		else
-			*vp = it->second.get();
+			vp.set((*it).second.get());
 		return JS_TRUE;
 	}
 
@@ -102,19 +102,19 @@
 		if (parent)
 		{
 			// If the object isn't parentless, return a new object
-			*vp = OBJECT_TO_JSVAL(parent->GetJSObject());
+			vp.set(OBJECT_TO_JSVAL(parent->GetJSObject()));
 		}
 		else
 		{
 			// Return null if there's no parent
-			*vp = JSVAL_NULL;
+			vp.set(JSVAL_NULL);
 		}
 		return JS_TRUE;
 	}
 	// Also handle "name" specially
 	else if (propName == "name")
 	{
-		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, e->GetName().c_str()));
+		vp.set(STRING_TO_JSVAL(JS_NewStringCopyZ(cx, e->GetName().c_str())));
 		return JS_TRUE;
 	}
 	// Handle all other properties
@@ -135,7 +135,8 @@
 			{
 				bool value;
 				GUI<bool>::GetSetting(e, propName, value);
-				*vp = value ? JSVAL_TRUE : JSVAL_FALSE;
+				vp.set(BOOLEAN_TO_JSVAL(value));
+				//value ? JSVAL_TRUE : JSVAL_FALSE;
 				break;
 			}
 
@@ -143,7 +144,7 @@
 			{
 				int value;
 				GUI<int>::GetSetting(e, propName, value);
-				*vp = INT_TO_JSVAL(value);
+				vp.set(INT_TO_JSVAL(value));
 				break;
 			}
 
@@ -152,7 +153,8 @@
 				float value;
 				GUI<float>::GetSetting(e, propName, value);
 				// Create a garbage-collectable double
-				return JS_NewNumberValue(cx, value, vp);
+				vp.set(JS_NumberValue(value));
+				return !JSVAL_IS_NULL(vp.get());
 			}
 
 		case GUIST_CColor:
@@ -160,11 +162,12 @@
 				CColor colour;
 				GUI<CColor>::GetSetting(e, propName, colour);
 				JSObject* obj = JS_NewObject(cx, &JSI_GUIColor::JSI_class, NULL, NULL);
-				*vp = OBJECT_TO_JSVAL(obj); // root it
+				vp.set(OBJECT_TO_JSVAL(obj)); // root it
 
-				jsval c;
+				JS::RootedValue c(cx);
 				// Attempt to minimise ugliness through macrosity
-				#define P(x) if (!JS_NewNumberValue(cx, colour.x, &c)) return JS_FALSE; JS_SetProperty(cx, obj, #x, &c)
+				#define P(x) c = JS_NumberValue(colour.x); \
+				if (JSVAL_IS_NULL(c)) return false; JS_SetProperty(cx, obj, #x, c.address())
 					P(r);
 					P(g);
 					P(b);
@@ -179,7 +182,7 @@
 				CClientArea area;
 				GUI<CClientArea>::GetSetting(e, propName, area);
 				JSObject* obj = JS_NewObject(cx, &JSI_GUISize::JSI_class, NULL, NULL);
-				*vp = OBJECT_TO_JSVAL(obj); // root it
+				vp.set(OBJECT_TO_JSVAL(obj)); // root it
 				try
 				{
 					ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
@@ -207,7 +210,7 @@
 			{
 				CGUIString value;
 				GUI<CGUIString>::GetSetting(e, propName, value);
-				*vp = ScriptInterface::ToJSVal(cx, value.GetOriginalString());
+				vp.set(ScriptInterface::ToJSVal(cx, value.GetOriginalString()));
 				break;
 			}
 
@@ -215,7 +218,7 @@
 			{
 				CStr value;
 				GUI<CStr>::GetSetting(e, propName, value);
-				*vp = ScriptInterface::ToJSVal(cx, value);
+				vp.set(ScriptInterface::ToJSVal(cx, value));
 				break;
 			}
 
@@ -223,7 +226,7 @@
 			{
 				CStrW value;
 				GUI<CStrW>::GetSetting(e, propName, value);
-				*vp = ScriptInterface::ToJSVal(cx, value);
+				vp.set(ScriptInterface::ToJSVal(cx, value));
 				break;
 			}
 
@@ -231,7 +234,7 @@
 			{
 				CGUISpriteInstance *value;
 				GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
-				*vp = ScriptInterface::ToJSVal(cx, value->GetName());
+				vp.set(ScriptInterface::ToJSVal(cx, value->GetName()));
 				break;
 			}
 
@@ -247,7 +250,7 @@
 				case EAlign_Center: word = "center"; break;
 				default: debug_warn(L"Invalid EAlign!"); word = "error"; break;
 				}
-				*vp = ScriptInterface::ToJSVal(cx, word);
+				vp.set(ScriptInterface::ToJSVal(cx, word));
 				break;
 			}
 
@@ -263,7 +266,7 @@
 				case EVAlign_Center: word = "center"; break;
 				default: debug_warn(L"Invalid EVAlign!"); word = "error"; break;
 				}
-				*vp = ScriptInterface::ToJSVal(cx, word);
+				vp.set(ScriptInterface::ToJSVal(cx, word));
 				break;
 			}
 
@@ -273,12 +276,12 @@
 				GUI<CGUIList>::GetSetting(e, propName, value);
 
 				JSObject *obj = JS_NewArrayObject(cx, 0, NULL);
-				*vp = OBJECT_TO_JSVAL(obj); // root it
-				
+				vp.set(OBJECT_TO_JSVAL(obj)); // root it
+
 				for (size_t i = 0; i < value.m_Items.size(); ++i)
 				{
-					jsval val = ScriptInterface::ToJSVal(cx, value.m_Items[i].GetOriginalString());
-					JS_SetElement(cx, obj, (jsint)i, &val);
+					JS::RootedValue val(cx, ScriptInterface::ToJSVal(cx, value.m_Items[i].GetOriginalString()));
+					JS_SetElement(cx, obj, (uint32_t)i, val.address());
 				}
 
 				break;
@@ -294,7 +297,7 @@
 	}
 }
 
-JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp)
+JSBool JSI_IGUIObject::setProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JSBool UNUSED(strict), JS::MutableHandle<jsval> vp)
 {
 	IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
 	if (!e)
@@ -311,7 +314,7 @@
 	if (propName == "name")
 	{
 		std::string value;
-		if (!ScriptInterface::FromJSVal(cx, *vp, value))
+		if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 			return JS_FALSE;
 		e->SetName(value);
 		return JS_TRUE;
@@ -320,14 +323,14 @@
 	// Use onWhatever to set event handlers
 	if (propName.substr(0, 2) == "on")
 	{
-		if (!JSVAL_IS_OBJECT(*vp) || !JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(*vp)))
+		if (JSVAL_IS_PRIMITIVE(vp.get()) || !JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(vp.get())))
 		{
 			JS_ReportError(cx, "on- event-handlers must be functions");
 			return JS_FALSE;
 		}
 
 		CStr eventName (CStr(propName.substr(2)).LowerCase());
-		e->SetScriptHandler(eventName, JSVAL_TO_OBJECT(*vp));
+		e->SetScriptHandler(eventName, JSVAL_TO_OBJECT(vp.get()));
 
 		return JS_TRUE;
 	}
@@ -346,7 +349,7 @@
 	case GUIST_CStr:
 		{
 			std::string value;
-			if (!ScriptInterface::FromJSVal(cx, *vp, value))
+			if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 				return JS_FALSE;
 
 			GUI<CStr>::SetSetting(e, propName, value);
@@ -356,8 +359,8 @@
 	case GUIST_CStrW:
 		{
 			std::wstring value;
-			if (!ScriptInterface::FromJSVal(cx, *vp, value))
-				return JS_FALSE;
+			if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
+				return false;
 
 			GUI<CStrW>::SetSetting(e, propName, value);
 			break;
@@ -366,8 +369,8 @@
 	case GUIST_CGUISpriteInstance:
 		{
 			std::string value;
-			if (!ScriptInterface::FromJSVal(cx, *vp, value))
-				return JS_FALSE;
+			if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
+				return false;
 
 			GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value));
 			break;
@@ -376,7 +379,7 @@
 	case GUIST_CGUIString:
 		{
 			std::wstring value;
-			if (!ScriptInterface::FromJSVal(cx, *vp, value))
+			if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 				return JS_FALSE;
 
 			CGUIString str;
@@ -388,7 +391,7 @@
 	case GUIST_EAlign:
 		{
 			std::string value;
-			if (!ScriptInterface::FromJSVal(cx, *vp, value))
+			if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 				return JS_FALSE;
 
 			EAlign a;
@@ -407,7 +410,7 @@
 	case GUIST_EVAlign:
 		{
 			std::string value;
-			if (!ScriptInterface::FromJSVal(cx, *vp, value))
+			if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 				return JS_FALSE;
 
 			EVAlign a;
@@ -425,8 +428,8 @@
 
 	case GUIST_int:
 		{
-			int32 value;
-			if (JS_ValueToInt32(cx, *vp, &value) == JS_TRUE)
+			int32_t value;
+			if (JS_ValueToInt32(cx, vp.get(), &value) == true)
 				GUI<int>::SetSetting(e, propName, value);
 			else
 			{
@@ -438,8 +441,8 @@
 
 	case GUIST_float:
 		{
-			jsdouble value;
-			if (JS_ValueToNumber(cx, *vp, &value) == JS_TRUE)
+			double value;
+			if (JS_ValueToNumber(cx, vp.get(), &value) == true)
 				GUI<float>::SetSetting(e, propName, (float)value);
 			else
 			{
@@ -452,8 +455,8 @@
 	case GUIST_bool:
 		{
 			JSBool value;
-			if (JS_ValueToBoolean(cx, *vp, &value) == JS_TRUE)
-				GUI<bool>::SetSetting(e, propName, value == JS_TRUE);
+			if (JS_ValueToBoolean(cx, vp.get(), &value))
+				GUI<bool>::SetSetting(e, propName, value);
 			else
 			{
 				JS_ReportError(cx, "Cannot convert value to bool");
@@ -464,10 +467,10 @@
 
 	case GUIST_CClientArea:
 		{
-			if (JSVAL_IS_STRING(*vp))
+			if (JSVAL_IS_STRING(vp.get()))
 			{
 				std::wstring value;
-				if (!ScriptInterface::FromJSVal(cx, *vp, value))
+				if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 					return JS_FALSE;
 
 				if (e->SetSetting(propName, value) != PSRETURN_OK)
@@ -476,12 +479,12 @@
 					return JS_FALSE;
 				}
 			}
-			else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUISize::JSI_class, NULL))
+			else if (!JSVAL_IS_PRIMITIVE(vp.get()) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(vp.get()), &JSI_GUISize::JSI_class, NULL))
 			{
 				CClientArea area;
 				GUI<CClientArea>::GetSetting(e, propName, area);
 
-				JSObject* obj = JSVAL_TO_OBJECT(*vp);
+				JSObject* obj = JSVAL_TO_OBJECT(vp.get());
 				ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
 				#define P(x, y, z) pScriptInterface->GetProperty(OBJECT_TO_JSVAL(obj), #z, area.x.y)
 					P(pixel,	left,	left);
@@ -506,10 +509,10 @@
 
 	case GUIST_CColor:
 		{
-			if (JSVAL_IS_STRING(*vp))
+			if (JSVAL_IS_STRING(vp.get()))
 			{
 				std::wstring value;
-				if (!ScriptInterface::FromJSVal(cx, *vp, value))
+				if (!ScriptInterface::FromJSVal(cx, vp.get(), value))
 					return JS_FALSE;
 
 				if (e->SetSetting(propName, value) != PSRETURN_OK)
@@ -518,12 +521,13 @@
 					return JS_FALSE;
 				}
 			}
-			else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUIColor::JSI_class, NULL))
+			else if (!JSVAL_IS_PRIMITIVE(vp.get()) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(vp.get()), &JSI_GUIColor::JSI_class, NULL))
 			{
 				CColor colour;
-				JSObject* obj = JSVAL_TO_OBJECT(*vp);
-				jsval t; double s;
-				#define PROP(x) JS_GetProperty(cx, obj, #x, &t); \
+				JSObject* obj = JSVAL_TO_OBJECT(vp.get());
+				JS::RootedValue t(cx);
+				double s;
+				#define PROP(x) JS_GetProperty(cx, obj, #x, t.address()); \
 								JS_ValueToNumber(cx, t, &s); \
 								colour.x = (float)s
 				PROP(r); PROP(g); PROP(b); PROP(a);
@@ -541,16 +545,16 @@
 
 	case GUIST_CGUIList:
 		{
-			JSObject* obj = JSVAL_TO_OBJECT(*vp);
-			jsuint length;
-			if (JSVAL_IS_OBJECT(*vp) && JS_GetArrayLength(cx, obj, &length) == JS_TRUE)
+			JSObject* obj = JSVAL_TO_OBJECT(vp.get());
+			uint length;
+			if (!JSVAL_IS_PRIMITIVE(vp.get()) && JS_GetArrayLength(cx, obj, &length) == true)
 			{
 				CGUIList list;
 
 				for (int i=0; i<(int)length; ++i)
 				{
-					jsval element;
-					if (! JS_GetElement(cx, obj, i, &element))
+					JS::RootedValue element(cx);
+					if (! JS_GetElement(cx, obj, i, element.address()))
 					{
 						JS_ReportError(cx, "Failed to get list element");
 						return JS_FALSE;
@@ -562,7 +566,7 @@
 
 					CGUIString str;
 					str.SetValue(value);
-					
+
 					list.m_Items.push_back(str);
 				}
 
@@ -587,7 +591,7 @@
 }
 
 
-JSBool JSI_IGUIObject::construct(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_IGUIObject::construct(JSContext* cx, uint argc, jsval* vp)
 {
 	if (argc == 0)
 	{
@@ -599,7 +603,7 @@
 
 	// Store the IGUIObject in the JS object's 'private' area
 	IGUIObject* guiObject = (IGUIObject*)JSVAL_TO_PRIVATE(JS_ARGV(cx, vp)[0]);
-	JS_SetPrivate(cx, obj, guiObject);
+	JS_SetPrivate(obj, guiObject);
 
 	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
 	return JS_TRUE;
@@ -610,7 +614,7 @@
 	scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL);
 }
 
-JSBool JSI_IGUIObject::toString(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 
@@ -625,7 +629,7 @@
 	return JS_TRUE;
 }
 
-JSBool JSI_IGUIObject::focus(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 
@@ -639,7 +643,7 @@
 	return JS_TRUE;
 }
 
-JSBool JSI_IGUIObject::blur(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 
@@ -653,7 +657,7 @@
 	return JS_TRUE;
 }
 
-JSBool JSI_IGUIObject::getComputedSize(JSContext* cx, uintN argc, jsval* vp)
+JSBool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp)
 {
 	UNUSED2(argc);
 	IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx, vp), &JSI_IGUIObject::JSI_class, NULL);
Index: source/gui/scripting/GuiScriptConversions.cpp
===================================================================
--- source/gui/scripting/GuiScriptConversions.cpp	(Revision 14578)
+++ source/gui/scripting/GuiScriptConversions.cpp	(Arbeitskopie)
@@ -23,14 +23,13 @@
 #include "lib/external_libraries/libsdl.h"
 #include "ps/Hotkey.h"
 
-#include "js/jsapi.h"
-
-#define SET(obj, name, value) STMT(jsval v_ = ToJSVal(cx, (value)); JS_SetProperty(cx, (obj), (name), &v_))
+#define SET(obj, name, value) STMT(JS::RootedValue v_(cx, ToJSVal(cx, (value))); JS_SetProperty(cx, (obj), (name), v_.address()))
 	// ignore JS_SetProperty return value, because errors should be impossible
 	// and we can't do anything useful in the case of errors anyway
 
 template<> jsval ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, SDL_Event_ const& val)
 {
+	JSAutoRequest rq(cx);
 	const char* typeName;
 
 	switch (val.ev.type)
@@ -78,8 +77,8 @@
 		JSObject* keysym = JS_NewObject(cx, NULL, NULL, NULL);
 		if (! keysym)
 			return JSVAL_VOID;
-		jsval keysymVal = OBJECT_TO_JSVAL(keysym);
-		JS_SetProperty(cx, obj, "keysym", &keysymVal);
+		JS::RootedValue keysymVal(cx, OBJECT_TO_JSVAL(keysym));
+		JS_SetProperty(cx, obj, "keysym", keysymVal.address());
 
 		// SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h)
 		SET(keysym, "sym", (int)val.ev.key.keysym.sym);
Index: source/gui/scripting/JSInterface_IGUIObject.h
===================================================================
--- source/gui/scripting/JSInterface_IGUIObject.h	(Revision 14578)
+++ source/gui/scripting/JSInterface_IGUIObject.h	(Arbeitskopie)
@@ -25,13 +25,13 @@
 	extern JSClass JSI_class;
 	extern JSPropertySpec JSI_props[];
 	extern JSFunctionSpec JSI_methods[];
-	JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
-	JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp);
-	JSBool construct(JSContext* cx, uintN argc, jsval* vp);
-	JSBool toString(JSContext* cx, uintN argc, jsval* vp);
-	JSBool focus(JSContext* cx, uintN argc, jsval* vp);
-	JSBool blur(JSContext* cx, uintN argc, jsval* vp);
-	JSBool getComputedSize(JSContext* cx, uintN argc, jsval* vp);
+	JSBool getProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<jsval> vp);
+	JSBool setProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JSBool UNUSED(strict), JS::MutableHandle<jsval> vp);
+	JSBool construct(JSContext* cx, uint argc, jsval* vp);
+	JSBool toString(JSContext* cx, uint argc, jsval* vp);
+	JSBool focus(JSContext* cx, uint argc, jsval* vp);
+	JSBool blur(JSContext* cx, uint argc, jsval* vp);
+	JSBool getComputedSize(JSContext* cx, uint argc, jsval* vp);
 	void init(ScriptInterface& scriptInterface);
 }
 
Index: source/gui/IGUIObject.h
===================================================================
--- source/gui/IGUIObject.h	(Revision 14578)
+++ source/gui/IGUIObject.h	(Arbeitskopie)
@@ -142,9 +142,9 @@
 	friend class GUITooltip;
 
 	// Allow getProperty to access things like GetParent()
-	friend JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
-	friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp);
-	friend JSBool JSI_IGUIObject::getComputedSize(JSContext* cx, uintN argc, jsval* vp);
+	friend JSBool JSI_IGUIObject::getProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<jsval> vp);
+	friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JSBool UNUSED(strict), JS::MutableHandle<jsval> vp);
+	friend JSBool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp);
 
 public:
 	IGUIObject();
Index: libraries/source/spidermonkey/lib/mozjs185-ps-release.lib
===================================================================
Kann nicht anzeigen: Dateityp ist als binär angegeben.
svn:mime-type = application/octet-stream
Index: libraries/source/spidermonkey/lib/mozjs185-ps-debug.lib
===================================================================
Kann nicht anzeigen: Dateityp ist als binär angegeben.
svn:mime-type = application/octet-stream
Index: libraries/source/spidermonkey/js185-1.0.0.tar.gz
===================================================================
Kann nicht anzeigen: Dateityp ist als binär angegeben.
svn:mime-type = application/octet-stream
Index: libraries/source/spidermonkey/build.sh
===================================================================
--- libraries/source/spidermonkey/build.sh	(Revision 14578)
+++ libraries/source/spidermonkey/build.sh	(Arbeitskopie)
@@ -17,14 +17,15 @@
 echo "Building SpiderMonkey..."
 echo
 
-JOBS=${JOBS:="-j2"}
+
+JOBS=${JOBS:="-j5"}
 MAKE=${MAKE:="make"}
 
 MAKE_OPTS="${JOBS}"
+NSPR_INCLUDES="`pkg-config nspr --cflags`"
+NSPR_LIBS="`pkg-config nspr --libs`"
 
-CONF_OPTS="--disable-tests"
-# (We don't use --enable-threadsafe because we don't use a single runtime in
-# multiple threads, so it is unnecessary complexity and performance overhead)
+CONF_OPTS="--disable-e4x --enable-threadsafe --enable-shared-js --disable-tests" # --enable-trace-logging"
 
 # If Valgrind looks like it's installed, then set up SM to support it
 # (else the JITs will interact poorly with it)
@@ -33,9 +34,6 @@
   CONF_OPTS="${CONF_OPTS} --enable-valgrind"
 fi
 
-#CONF_OPTS="${CONF_OPTS} --enable-threadsafe --with-system-nspr"
-#CONF_OPTS="${CONF_OPTS} --enable-trace-jscalls"
-
 # We need to be able to override CHOST in case it is 32bit userland on 64bit kernel
 CONF_OPTS="${CONF_OPTS} \
   ${CBUILD:+--build=${CBUILD}} \
@@ -43,42 +41,44 @@
   ${CTARGET:+--target=${CTARGET}}"
 
 echo "SpiderMonkey build options: ${CONF_OPTS}"
+echo ${CONF_OPTS}
 
-# Extract the tarball
-tar xzf js185-1.0.0.tar.gz
+# Delete the existing directory to avoid conflicts and extract the tarball
+rm -rf mozjs24
+tar xjf mozjs-24.2.0.tar.bz2
 
-# Apply patches
-patch -p0 < openbsd-spidermonkey-650742.diff
-patch -p0 < openbsd-spidermonkey-634609.diff
+# Apply patches if needed
+#patch -p0 < name_of_thepatch.diff
 
-cd js-1.8.5/js/src
+# rename the extracted directory to something shorter
+mv mozjs-24.2.0 mozjs24
 
+cd mozjs24/js/src
+
 # We want separate debug/release versions of the library, so we have to change
 # the LIBRARY_NAME for each build.
 # (We use perl instead of sed so that it works with MozillaBuild on Windows,
 # which has an ancient sed.)
-perl -i.bak -pe 's/^(LIBRARY_NAME\s+= mozjs185)(-ps-debug|-ps-release)?/$1-ps-debug/' Makefile.in
+perl -i.bak -pe 's/(^LIBRARY_NAME\s+=).*/$1mozjs24-ps-debug/' Makefile.in
 mkdir -p build-debug
 cd build-debug
-../configure ${CONF_OPTS} --enable-debug --disable-optimize
+../configure ${CONF_OPTS} --with-nspr-libs="$NSPR_LIBS" --with-nspr-cflags="$NSPR_INCLUDES" --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal # --enable-root-analysis
 ${MAKE} ${MAKE_OPTS}
 cd ..
 
-perl -i.bak -pe 's/^(LIBRARY_NAME\s+= mozjs185)(-ps-debug|-ps-release)?/$1-ps-release/' Makefile.in
+perl -i.bak -pe 's/(^LIBRARY_NAME\s+=).*/$1mozjs24-ps-release/' Makefile.in
 mkdir -p build-release
 cd build-release
-../configure ${CONF_OPTS} # --enable-gczeal --enable-debug-symbols
+../configure ${CONF_OPTS} --with-nspr-libs="$NSPR_LIBS" --with-nspr-cflags="$NSPR_INCLUDES" --enable-optimize  # --enable-gczeal --enable-debug-symbols
 ${MAKE} ${MAKE_OPTS}
 cd ..
 
-# Remove the library suffixes to avoid spurious SVN diffs
-perl -i.bak -pe 's/^(LIBRARY_NAME\s+= mozjs185)(-ps-debug|-ps-release)?/$1/' Makefile.in
-
 cd ../../..
 
 if [ "${OS}" = "Windows_NT" ]
 then
-  INCLUDE_DIR=include-win32
+  INCLUDE_DIR_DEBUG=include-win32-debug
+  INCLUDE_DIR_RELEASE=include-win32-release
   DLL_SRC_SUFFIX=-1.0.dll
   DLL_DST_SUFFIX=-1.0.dll
   LIB_PREFIX=
@@ -86,19 +86,21 @@
   LIB_DST_SUFFIX=.lib
 elif [ "`uname -s`" = "Darwin" ]
 then
-  INCLUDE_DIR=include-unix
+  INCLUDE_DIR_DEBUG=include-unix-debug
+  INCLUDE_DIR_RELEASE=include-unix-release
   DLL_SRC_SUFFIX=.dylib
   DLL_DST_SUFFIX=.1.0.dylib
   LIB_PREFIX=lib
   LIB_SRC_SUFFIX=.dylib
   LIB_DST_SUFFIX=.dylib
   # Fix libtool's use of an absolute path
-  install_name_tool -id @executable_path/${LIB_PREFIX}mozjs185-ps-debug${DLL_DST_SUFFIX} js-1.8.5/js/src/build-debug/dist/bin/${LIB_PREFIX}mozjs185-ps-debug${DLL_SRC_SUFFIX}
-  install_name_tool -id @executable_path/${LIB_PREFIX}mozjs185-ps-release${DLL_DST_SUFFIX} js-1.8.5/js/src/build-release/dist/bin/${LIB_PREFIX}mozjs185-ps-release${DLL_SRC_SUFFIX}
+  install_name_tool -id @executable_path/${LIB_PREFIX}mozjs24-ps-debug${DLL_DST_SUFFIX} mozjs24/js/src/build-debug/dist/bin/${LIB_PREFIX}mozjs24-ps-debug${DLL_SRC_SUFFIX}
+  install_name_tool -id @executable_path/${LIB_PREFIX}mozjs24-ps-release${DLL_DST_SUFFIX} mozjs24/js/src/build-release/dist/bin/${LIB_PREFIX}mozjs24-ps-release${DLL_SRC_SUFFIX}
 else
-  INCLUDE_DIR=include-unix
+  INCLUDE_DIR_DEBUG=include-unix-debug
+  INCLUDE_DIR_RELEASE=include-unix-release
   DLL_SRC_SUFFIX=.so
-  DLL_DST_SUFFIX=.so.1.0
+  DLL_DST_SUFFIX=.so
   LIB_PREFIX=lib
   LIB_SRC_SUFFIX=.so
   LIB_DST_SUFFIX=.so
@@ -113,15 +115,17 @@
 
 # Copy files into the necessary locations for building and running the game
 
-# js-config.h is the same for both debug and release builds, so we only need to copy one
-mkdir -p ${INCLUDE_DIR}/js
-cp -L js-1.8.5/js/src/build-release/dist/include/* ${INCLUDE_DIR}/js/
+# js-config.h is different for debug and release builds, so we need different include directories for both
+mkdir -p ${INCLUDE_DIR_DEBUG}
+mkdir -p ${INCLUDE_DIR_RELEASE}
+cp -R -L mozjs24/js/src/build-release/dist/include/* ${INCLUDE_DIR_RELEASE}/
+cp -R -L mozjs24/js/src/build-debug/dist/include/* ${INCLUDE_DIR_DEBUG}/
 
 mkdir -p lib/
-cp -L js-1.8.5/js/src/build-debug/dist/lib/${LIB_PREFIX}mozjs185-ps-debug${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs185-ps-debug${LIB_DST_SUFFIX}
-cp -L js-1.8.5/js/src/build-release/dist/lib/${LIB_PREFIX}mozjs185-ps-release${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs185-ps-release${LIB_DST_SUFFIX}
-cp -L js-1.8.5/js/src/build-debug/dist/bin/${LIB_PREFIX}mozjs185-ps-debug${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs185-ps-debug${DLL_DST_SUFFIX}
-cp -L js-1.8.5/js/src/build-release/dist/bin/${LIB_PREFIX}mozjs185-ps-release${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs185-ps-release${DLL_DST_SUFFIX}
+cp -L mozjs24/js/src/build-debug/dist/lib/${LIB_PREFIX}mozjs24-ps-debug${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs24-ps-debug${LIB_DST_SUFFIX}
+cp -L mozjs24/js/src/build-release/dist/lib/${LIB_PREFIX}mozjs24-ps-release${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs24-ps-release${LIB_DST_SUFFIX}
+cp -L mozjs24/js/src/build-debug/dist/bin/${LIB_PREFIX}mozjs24-ps-debug${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs24-ps-debug${DLL_DST_SUFFIX}
+cp -L mozjs24/js/src/build-release/dist/bin/${LIB_PREFIX}mozjs24-ps-release${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs24-ps-release${DLL_DST_SUFFIX}
 
 # Flag that it's already been built successfully so we can skip it next time
 touch .already-built
Index: libraries/source/spidermonkey/README.txt
===================================================================
--- libraries/source/spidermonkey/README.txt	(Revision 14578)
+++ libraries/source/spidermonkey/README.txt	(Arbeitskopie)
@@ -5,10 +5,11 @@
 then run start-msvc8.bat and run ./build.sh here.
 
 This version of SpiderMonkey comes from
-http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz
-(see also https://developer.mozilla.org/en/SpiderMonkey/1.8.5)
+https://ftp.mozilla.org/pub/mozilla.org/js/mozjs-24.2.0.tar.bz2
 
-The game must be compiled with precisely this version, and must not use a
-standard system-provided version of the library, since SpiderMonkey does not
-guarantee API stability and may have behavioural changes that cause subtle
-bugs or network out-of-sync errors.
+The game must be compiled with precisely this version since SpiderMonkey 
+does not guarantee API stability and may have behavioural changes that 
+cause subtle bugs or network out-of-sync errors.
+A standard system-provided version of the library may only be used if it's
+exactly the same version or if it's another minor release that does not 
+change the behaviour of the scripts executed by SpiderMonkey.
Index: libraries/source/spidermonkey/openbsd-spidermonkey-650742.diff
===================================================================
--- libraries/source/spidermonkey/openbsd-spidermonkey-650742.diff	(Revision 14578)
+++ libraries/source/spidermonkey/openbsd-spidermonkey-650742.diff	(Arbeitskopie)
@@ -1,27 +0,0 @@
---- js-1.8.5/js/src/configure.in
-+++ js-1.8.5/js/src/configure.in
-@@ -3041,6 +3041,9 @@
- *-freebsd*|*-kfreebsd*)
-     AC_DEFINE(AVMPLUS_UNIX)
-     ;;
-+*-openbsd*)
-+    AC_DEFINE(AVMPLUS_UNIX)
-+    ;;
- *-gnu*)
-     AC_DEFINE(AVMPLUS_UNIX)
-     ;;
---- js-1.8.5/js/src/configure
-+++ js-1.8.5/js/src/configure
-@@ -8093,6 +8093,12 @@
- EOF
- 
-     ;;
-+*-openbsd*)
-+    cat >> confdefs.h <<\EOF
-+#define AVMPLUS_UNIX 1
-+EOF
-+
-+    ;;
- *-gnu*)
-     cat >> confdefs.h <<\EOF
- #define AVMPLUS_UNIX 1
Index: libraries/source/spidermonkey/openbsd-spidermonkey-634609.diff
===================================================================
--- libraries/source/spidermonkey/openbsd-spidermonkey-634609.diff	(Revision 14578)
+++ libraries/source/spidermonkey/openbsd-spidermonkey-634609.diff	(Arbeitskopie)
@@ -1,36 +0,0 @@
---- js-1.8.5/js/src/jsnativestack.cpp
-+++ js-1.8.5/js/src/jsnativestack.cpp
-@@ -50,7 +50,7 @@
- #elif defined(XP_MACOSX) || defined(DARWIN) || defined(XP_UNIX)
- # include <pthread.h>
- 
--# if defined(__FreeBSD__)
-+# if defined(__FreeBSD__) || defined(__OpenBSD__)
- #  include <pthread_np.h>
- # endif
- 
-@@ -196,7 +196,9 @@
- # else
-     pthread_attr_t sattr;
-     pthread_attr_init(&sattr);
--#  if defined(PTHREAD_NP_H) || defined(_PTHREAD_NP_H_) || defined(NETBSD)
-+#  if defined(__OpenBSD__)
-+    stack_t ss;
-+#  elif defined(PTHREAD_NP_H) || defined(_PTHREAD_NP_H_) || defined(NETBSD)
-     /* e.g. on FreeBSD 4.8 or newer, neundorf@kde.org */
-     pthread_attr_get_np(thread, &sattr);
- #  else
-@@ -212,7 +214,13 @@
- #  ifdef DEBUG
-     int rc = 
- #  endif
-+# if defined(__OpenBSD__)
-+        pthread_stackseg_np(pthread_self(), &ss);
-+    stackBase = (void*)((size_t) ss.ss_sp - ss.ss_size);
-+    stackSize = ss.ss_size;
-+# else
-         pthread_attr_getstack(&sattr, &stackBase, &stackSize);
-+# endif
-     JS_ASSERT(!rc);
-     JS_ASSERT(stackBase);
-     pthread_attr_destroy(&sattr);
