[Freeswitch-branches] [commit] r7332 - freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey

Freeswitch SVN anthonyl at freeswitch.org
Wed Jan 23 15:35:41 EST 2008


Author: anthonyl
Date: Wed Jan 23 15:35:41 2008
New Revision: 7332

Modified:
   freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c

Log:
add the ability to set global variables as well as get them, also. setGlobalVar and getGlobalVar are both documented in the wiki, but it looks like the names of these hae changed to setGlobalVariable(new) and getGlobalVariable.



Modified: freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Wed Jan 23 15:35:41 2008
@@ -3161,9 +3161,21 @@
 	return JS_FALSE;
 }
 
+static JSBool js_global_set(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+	char *var_name = NULL, *val = NULL;
+	if (argc > 1) {
+		var_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+		val =  JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+		switch_core_set_variable(var_name, val);
+		return JS_TRUE;
+	}
+	/* this is so the wrong error message to throw for this one */
+	eval_some_js("~throw new Error(\"var name not supplied!\");", cx, obj, rval);
+	return JS_FALSE;
+}
 
-
-static JSBool js_global(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool js_global_get(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *var_name = NULL, *val = NULL;
 
@@ -3358,7 +3370,8 @@
 static JSFunctionSpec fs_functions[] = {
 	{"console_log", js_log, 2},
 	{"consoleLog", js_log, 2},
-	{"getGlobalVariable", js_global, 2},
+	{"getGlobalVariable", js_global_get, 2},
+	{"setGlobalVariable", js_global_set, 2},
 	{"exit", js_exit, 0},
 	{"include", js_include, 1},
 	{"bridge", js_bridge, 2},



More information about the Freeswitch-branches mailing list