summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/scripting/ejs/smbcalls_string.c26
-rw-r--r--source4/scripting/libjs/base.js3
-rw-r--r--swat/scripting/common.js2
-rwxr-xr-xtestprogs/ejs/sprintf.js2
4 files changed, 26 insertions, 7 deletions
diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c
index 657c8efc61..3d386abe2e 100644
--- a/source4/scripting/ejs/smbcalls_string.c
+++ b/source4/scripting/ejs/smbcalls_string.c
@@ -321,15 +321,27 @@ static int ejs_vsprintf(MprVarHandle eid, int argc, struct MprVar **argv)
}
/*
+ initialise string ejs subsystem
+*/
+static int ejs_string_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct MprVar *obj = mprInitObject(eid, "string", argc, argv);
+
+ mprSetStringCFunction(obj, "strlen", ejs_strlen);
+ mprSetStringCFunction(obj, "strlower", ejs_strlower);
+ mprSetStringCFunction(obj, "strupper", ejs_strupper);
+ mprSetStringCFunction(obj, "split", ejs_split);
+ mprSetCFunction(obj, "join", ejs_join);
+ mprSetCFunction(obj, "sprintf", ejs_sprintf);
+ mprSetCFunction(obj, "vsprintf", ejs_vsprintf);
+
+ return 0;
+}
+
+/*
setup C functions that be called from ejs
*/
void smb_setup_ejs_string(void)
{
- ejsDefineStringCFunction(-1, "strlen", ejs_strlen, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineStringCFunction(-1, "strlower", ejs_strlower, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineStringCFunction(-1, "strupper", ejs_strupper, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineStringCFunction(-1, "split", ejs_split, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "join", ejs_join, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "sprintf", ejs_sprintf, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "vsprintf", ejs_vsprintf, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineCFunction(-1, "string_init", ejs_string_init, NULL, MPR_VAR_SCRIPT_HANDLE);
}
diff --git a/source4/scripting/libjs/base.js b/source4/scripting/libjs/base.js
index 39b62b133e..8a07f4e383 100644
--- a/source4/scripting/libjs/base.js
+++ b/source4/scripting/libjs/base.js
@@ -9,6 +9,9 @@ if (global["HAVE_BASE_JS"] != undefined) {
}
HAVE_BASE_JS=1
+/* bring the string functions into the global frame */
+string_init(global);
+
/*
an essential function!
*/
diff --git a/swat/scripting/common.js b/swat/scripting/common.js
index baebe8af82..f868040f03 100644
--- a/swat/scripting/common.js
+++ b/swat/scripting/common.js
@@ -8,6 +8,8 @@ global.page = new Object();
/* fill in some defaults */
global.page.title = "Samba Web Administration Tool";
+libinclude("base.js");
+
/* to cope with browsers that don't support cookies we append the sessionid
to the URI */
global.SESSIONURI = "";
diff --git a/testprogs/ejs/sprintf.js b/testprogs/ejs/sprintf.js
index 4d3d9a7555..6ae8605718 100755
--- a/testprogs/ejs/sprintf.js
+++ b/testprogs/ejs/sprintf.js
@@ -3,6 +3,8 @@
test sprintf function
*/
+string_init(local);
+
function check_result(s, v)
{
if (s != v) {