Skip to content

Commit

Permalink
Backported minimal fix for GH-1513
Browse files Browse the repository at this point in the history
  • Loading branch information
svaarala committed Jul 27, 2017
1 parent 91eaafd commit c65550b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src-input/duk_api_bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,9 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t

/* If _Formals wasn't present in the original function, the list
* here will be empty. Same happens if _Formals was present but
* had zero length. We can omit _Formals from the result if its
* length is zero and matches nargs.
* had zero length. We'll omit the _Formals list if it is empty,
* regardless of whether it was present in the original or not,
* this is a workaround for https://github.com/svaarala/duktape/issues/1513.
*/
duk_push_array(ctx); /* _Formals */
for (arr_idx = 0; ; arr_idx++) {
Expand All @@ -671,7 +672,16 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
}
duk_put_prop_index(ctx, -2, arr_idx);
}
if (arr_idx == 0 && h_fun->nargs == 0) {
if (arr_idx == 0) {
/* Omitting _Formals when the list is empty is technically
* incorrect because the result will differ from the input
* function. This could matter for function templates if:
* _Formals exists, _Formals.length == 0, and nargs > 0.
* This doesn't happen in practice. But if it did, it would
* affect the .length property of function instances created
* from the closure (0 with _Formals present, nargs with
* _Formals absent).
*/
duk_pop(ctx);
} else {
duk_compact_m1(ctx);
Expand Down

0 comments on commit c65550b

Please sign in to comment.