[mw-devel] MW3 r1338 - trunk/src

psycodom at sucs.org psycodom at sucs.org
Mon Sep 16 16:44:36 BST 2013


Author: psycodom
Date: 2013-09-16 16:44:36 +0100 (Mon, 16 Sep 2013)
New Revision: 1338

Modified:
   trunk/src/js.c
Log:
js.c fixes for the spidermonkey 17 that's on the new silver (hopefully)



Modified: trunk/src/js.c
===================================================================
--- trunk/src/js.c	2013-09-16 09:03:17 UTC (rev 1337)
+++ trunk/src/js.c	2013-09-16 15:44:36 UTC (rev 1338)
@@ -1,14 +1,16 @@
 /* Add javascript functionality using spidermonkey */
 
 #include <fcntl.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <iconv.h>
 #include <sys/types.h>
-#include <unistd.h>
 #include <pwd.h>
 #include <readline/readline.h>
 #include <curl/curl.h>
-#include <errno.h>
 
 /* Ugly but necessary (this is how gjs shuts up the warnings,
    only gcc 4.6 has a nicer (push/pop) way to do it */
@@ -67,35 +69,35 @@
 JSClass globclass = {
 	"milliways", JSCLASS_GLOBAL_FLAGS,
 	JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_StrictPropertyStub,
-	JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub,
+	JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub, NULL,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
 JSClass js_dbresultclass = {
 	"dbresult", JSCLASS_HAS_PRIVATE,
 	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
 JSClass js_whoclass = {
 	"who", JSCLASS_HAS_PRIVATE,
 	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
 JSClass js_userrecordclass = {
 	"userrecord", JSCLASS_HAS_PRIVATE,
 	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
 JSClass js_termsizeclass = {
 	"termsize", JSCLASS_HAS_PRIVATE,
 	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
@@ -109,7 +111,7 @@
 	int lineno;
 	jsbytecode *pc;
 	
-	fp = JS_GetScriptedCaller(cx, NULL); // get the current js stack frame
+	fp = JS_FrameIterator(cx, &fp); // get the current js stack frame
 	script = JS_GetFrameScript(cx, fp); // get the current script from the stack frame
 	filename = JS_GetScriptFilename(cx, script); // get the file name of the script
 	pc = JS_GetFramePC(cx, fp); // get the current pc fro the stack frome
@@ -147,9 +149,9 @@
 /* Function for printing to standard out from javascript (helpful for
  * debugging and demonstrates how to call C from js) - also useful for event functions
  */
-static JSBool js_print(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_print(JSContext *cx, unsigned int argc, jsval *vp) 
 {
-	uintN i;
+	unsigned int i;
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER msg = NULL;
 	if (argc < 1) {
@@ -164,7 +166,7 @@
 		if (JSVAL_IS_NULL(argv[i])) {
 			display_message("jsval is NULL",0,1);
 		} else
-		if (JSVAL_IS_OBJECT(argv[i])) {
+		if (!JSVAL_IS_PRIMITIVE(argv[i])) {
 			printf("jsval at %p\n", (void *)JSVAL_TO_OBJECT(argv[i]));
 			if (JS_IsArrayObject(cx, JSVAL_TO_OBJECT(argv[i]))) {
 				display_message("jsval is an (Array)",0,1);
@@ -175,7 +177,7 @@
 }
 
 /* execute a talker command */
-static JSBool js_mwexec(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_mwexec(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER msg = NULL;
@@ -195,7 +197,7 @@
 
 
 /* say to the talker */
-static JSBool js_say(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_say(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER msg = NULL;
@@ -222,7 +224,7 @@
 }
 
 /* send an rpc/rpb */
-static JSBool js_rpc(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_rpc(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER msg = NULL;
@@ -259,7 +261,7 @@
 }
 
 /* send an ipc/ipb */
-static JSBool js_ipc(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_ipc(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER msg = NULL;
@@ -291,7 +293,7 @@
 }
 
 /* ask a user for extra input */
-static JSBool js_input(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_input(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	JSString *the_jsstring, *jsstr;
@@ -358,7 +360,7 @@
 
 
 /* beep */
-static JSBool js_beep(JSContext *cx, uintN argc, jsval *vp)
+static JSBool js_beep(JSContext *cx, unsigned int argc, jsval *vp)
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	int i, beeps=0;
@@ -383,7 +385,7 @@
 }
 
 /* bind something to a javascript function */
-static JSBool js_bind(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_bind(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER jbind = NULL;
@@ -509,7 +511,7 @@
 }
 
 /* bind something to a javascript function */
-static JSBool js_unbind(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_unbind(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER jbind = NULL;
@@ -630,7 +632,7 @@
 }
 
 // return the users terminal dimensions
-static JSBool js_termsize(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_termsize(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	JSObject *result_object;
 	int width, height;
@@ -654,7 +656,7 @@
 }
 
 // Provides a javascript function to query the wholist
-static JSBool js_wholist(JSContext *cx, uintN argc, jsval *vp) {
+static JSBool js_wholist(JSContext *cx, unsigned int argc, jsval *vp) {
 	struct person u;
 	struct who w;
 	int ufile, wfile;
@@ -740,7 +742,7 @@
 
 /* Function to make a url GET request and return the resulting page
  */
-static JSBool js_urlget(JSContext *cx, uintN argc, jsval *vp) 
+static JSBool js_urlget(JSContext *cx, unsigned int argc, jsval *vp) 
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	AUTOFREE_BUFFER url = NULL;
@@ -916,7 +918,7 @@
 // Provides a javascript function to query an sqlite3 database
 // This probably wants updating to not return JS_FALSE as that halts js execution
 // far better to return an error code in rsval which the javascript can handle
-static JSBool js_doquery(JSContext *cx, uintN argc, jsval *vp)
+static JSBool js_doquery(JSContext *cx, unsigned int argc, jsval *vp)
 {
 	jsval *argv = JS_ARGV(cx, vp);
 	struct js_db_result *dbres;
@@ -974,31 +976,31 @@
 	return retval;
 }
 
-static JSBool js_store_get(JSContext *cx, JSObject *obj, jsid idval, jsval *vp)
+static JSBool js_store_get(JSContext *cx, JSHandleObject obj, JSHandleId idval, JSMutableHandleValue vp)
 {
 	jsval sval;
-	JSBool ret = JS_IdToValue(cx, idval, &sval);
+	JSBool ret = JS_IdToValue(cx, *idval._, &sval);
 	if (ret == JS_TRUE && JSVAL_IS_STRING(sval)) {
 		AUTOFREE_BUFFER key = JS_EncodeString(cx, JS_ValueToString(cx, sval));
 		char *val = userdb_get(USERDB_PUBLIC, user->name, key);
 		if (val == NULL) {
-			*vp = JSVAL_VOID;
+			*vp._ = JSVAL_VOID;
 		} else {
 			JSString *str = JS_NewStringCopyZ(cx, val);
 			free(val);
-			*vp = STRING_TO_JSVAL(str);
+			*vp._ = STRING_TO_JSVAL(str);
 		}
 	}
 	return JS_TRUE;
 }
 
-static JSBool js_store_set(JSContext *cx, JSObject *obj, jsid idval, JSBool strict, jsval *vp)
+static JSBool js_store_set(JSContext *cx, JSHandleObject obj, JSHandleId idval, JSBool strict, JSMutableHandleValue vp)
 {
 	jsval sval;
-	JSBool ret = JS_IdToValue(cx, idval, &sval);
-	if (ret == JS_TRUE && JSVAL_IS_STRING(sval) && JSVAL_IS_STRING(*vp)) {
+	JSBool ret = JS_IdToValue(cx, *idval._, &sval);
+	if (ret == JS_TRUE && JSVAL_IS_STRING(sval) && JSVAL_IS_STRING(*vp._)) {
 		AUTOFREE_BUFFER key = JS_EncodeString(cx, JS_ValueToString(cx, sval));
-		AUTOFREE_BUFFER val = JS_EncodeString(cx, JS_ValueToString(cx, *vp));
+		AUTOFREE_BUFFER val = JS_EncodeString(cx, JS_ValueToString(cx, *vp._));
 		userdb_set(USERDB_PUBLIC, user->name, key, val);
 	}
 	return JS_TRUE;
@@ -1007,7 +1009,7 @@
 static JSClass js_storeclass = {
 	"Store", JSCLASS_HAS_PRIVATE,
 	JS_PropertyStub, JS_PropertyStub, js_store_get, js_store_set,
-	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
@@ -1028,7 +1030,7 @@
 	}
 	if (JSVAL_IS_NULL(j)) printf(" NULL");
 	if (JSVAL_IS_NUMBER(j)) printf(" NUMBER");
-	if (JSVAL_IS_OBJECT(j)) printf(" OBJECT");
+	if (!JSVAL_IS_PRIMITIVE(j)) printf(" OBJECT");
 	if (JSVAL_IS_PRIMITIVE(j)) printf(" PRIMITIVE");
 	if (JSVAL_IS_STRING(j)) printf(" STRING");
 	if (JSVAL_IS_VOID(j)) printf(" VOID");
@@ -1063,7 +1065,7 @@
 	js_clear_timeout();
 	//show_type("js_exec(rval)", rval);
 	free(argv);
-	JS_GC(jscx); // do we still need to do this now the actual bug has been found?
+	JS_GC(jsrt); // do we still need to do this now the actual bug has been found?
 	return ret;
 }
 
@@ -1123,7 +1125,7 @@
 	jsval retval;
 
 	/* Compile the js file specified */
-	script = JS_CompileFileHandle(jscx, jsroot, filename, f);
+	script = JS_CompileUTF8FileHandle(jscx, jsroot, filename, f);
 	if (script == NULL) {
 		printf("Failed to compile js script: %s\n", filename);
 		return 1;
@@ -1151,7 +1153,7 @@
 	if (res == JS_FALSE) {
 		return 0;
 	}
-	if (!JSVAL_IS_OBJECT(jv)) {
+	if (!!JSVAL_IS_PRIMITIVE(jv)) {
 		return 0;
 	}
 	if (JS_ObjectIsFunction(jscx, JSVAL_TO_OBJECT(jv))) {
@@ -1228,7 +1230,7 @@
 	JS_SetErrorReporter(jscx, js_error_handler);
 
 	/* create the root object */
-	jsroot = JS_NewCompartmentAndGlobalObject(jscx, &globclass, NULL);
+	jsroot = JS_NewGlobalObject(jscx, &globclass, NULL);
 	if (jsroot == NULL) {
 		printf("Failed to create global js object\n");
 		JS_EndRequest(jscx);




More information about the mw-devel mailing list