summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2013-05-21 17:43:34 +0200
committerportix <portix@gmx.net>2013-05-21 17:43:34 +0200
commit29f75485ce1ead1d20067d3ca16dd7846f53cba4 (patch)
tree25f9a58d3cdb0baedd155e797ccbb4d5acaec7d2
parentb9daa1ba9dac8ae61bd066c156cc568540c21eeb (diff)
downloaddwb-29f75485ce1ead1d20067d3ca16dd7846f53cba4.zip
Pass additinal arguments to xinclude
-rw-r--r--src/scripts.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/scripts.c b/src/scripts.c
index 061df30d..a7592f34 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -1731,7 +1731,7 @@ settings_get(JSContextRef ctx, JSObjectRef jsobj, JSStringRef js_name, JSValueRe
/*}}}*/
static JSValueRef
-do_include(JSContextRef ctx, const char *path, const char *script, gboolean global, gboolean is_archive, JSValueRef *exc)
+do_include(JSContextRef ctx, const char *path, const char *script, gboolean global, gboolean is_archive, size_t argc, const JSValueRef *argv, JSValueRef *exc)
{
JSStringRef js_script;
JSValueRef ret = NIL;
@@ -1748,7 +1748,7 @@ do_include(JSContextRef ctx, const char *path, const char *script, gboolean glob
JSObjectRef function = JSObjectMakeFunction(ctx, NULL, 0, NULL, js_script, NULL, 1, exc);
if (function != NULL)
{
- ret = JSObjectCallAsFunction(ctx, function, function, 0, NULL, exc);
+ ret = JSObjectCallAsFunction(ctx, function, function, argc, argv, exc);
}
g_free(debug);
}
@@ -1843,7 +1843,7 @@ global_include(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, c
} while(*tmp && *tmp != '\n');
tmp++;
}
- ret = do_include(ctx, path, tmp, global, false, exc);
+ ret = do_include(ctx, path, tmp, global, false, 0, NULL, exc);
error_out:
g_free(content);
@@ -1865,9 +1865,38 @@ error_out:
* @name xinclude
* @param path {String}
* Path of the file in the archive
+ * @param {...Object} {varargs}
+ * Additional arguments passed to include, the arguments are accessible via
+ * arguments
*
* @returns {Object}
* The object returned from the included file.
+ *
+ * @example
+ * // Archive structure
+ * //
+ * // main.js
+ * // content/foo.js
+ * // content/bar.js
+ *
+ * // main.js
+ * var foo = xinclude("content/foo.js");
+ * var bar = xinclude("content/bar.js", foo);
+ *
+ * // content/foo.js
+ * function getFoo() {
+ * return 37;
+ * }
+ * return {
+ * getFoo : getFoo
+ * };
+ *
+ * // content/bar.js
+ * var foo = arguments[0];
+ *
+ * var x = foo.getFoo();
+ *
+ *
* */
static JSValueRef
@@ -1886,7 +1915,7 @@ global_xinclude(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t
content = (char*)exar_extract(archive, path, &fs);
if (content != NULL)
- do_include(ctx, archive, content, false, true, exc);
+ ret = do_include(ctx, archive, content, false, true, argc-2, argc > 2 ? &argv[2] : NULL, exc);
error_out:
g_free(archive);