ref: 858d5890b344f4a5f6025c94b62a64d29673913e
parent: a6ba5356e2858fd6b105dacfc0a784f1969bebdb
author: Tor Andersson <tor@ccxvii.net>
date: Thu Mar 13 09:11:42 EDT 2014
Handle empty arguments to Function constructor.
--- a/jsfunction.c
+++ b/jsfunction.c
@@ -7,25 +7,24 @@
static void jsB_Function(js_State *J)
{
unsigned int i, top = js_gettop(J);
- const char *source;
- js_Buffer *sb;
+ js_Buffer *sb = NULL;
+ const char *body;
js_Ast *parse;
js_Function *fun;
- if (js_isundefined(J, 1))
- source = "";
- else {
- sb = NULL;
- if (top > 2) {
- for (i = 1; i < top - 1; ++i) {
- if (i > 1) js_putc(J, &sb, ',');
- js_puts(J, &sb, js_tostring(J, i));
- }
- js_putc(J, &sb, ')');
+ /* p1, p2, ..., pn */
+ if (top > 2) {
+ for (i = 1; i < top - 1; ++i) {
+ if (i > 1)
+ js_putc(J, &sb, ',');
+ js_puts(J, &sb, js_tostring(J, i));
}
- source = js_tostring(J, top - 1);
+ js_putc(J, &sb, ')');
}
+ /* body */
+ body = js_isdefined(J, top - 1) ? js_tostring(J, top - 1) : "";
+
if (js_try(J)) {
js_free(J, sb);
jsP_freeparse(J);
@@ -32,7 +31,7 @@
js_throw(J);
}
- parse = jsP_parsefunction(J, "Function", sb->s, source);
+ parse = jsP_parsefunction(J, "Function", sb ? sb->s : NULL, body);
fun = jsC_compilefunction(J, parse);
js_endtry(J);