Browse Source

Add DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER fix

v1.0-maintenance
Sami Vaarala 10 years ago
parent
commit
cc3b1515d5
  1. 19
      src/duk_bi_array.c
  2. 8
      src/duk_features.h.in

19
src/duk_bi_array.c

@ -222,17 +222,28 @@ duk_ret_t duk_bi_array_prototype_concat(duk_context *ctx) {
duk_def_prop_index_wec(ctx, -3, idx++);
idx_last = idx;
} else {
/* XXX: according to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' but test262 disagrees. Work
* as E5.1 mandates for now and don't touch idx_last.
*/
idx++;
duk_pop(ctx);
#if defined(DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER)
/* According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
*/
idx_last = idx;
#else
/* Strict standard behavior, ignore trailing elements for
* result 'length'.
*/
#endif
}
}
duk_pop(ctx);
}
/* The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
*/
duk_push_uarridx(ctx, idx_last);
duk_def_prop_stridx(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W);

8
src/duk_features.h.in

@ -2152,6 +2152,14 @@ typedef FILE duk_file;
#undef DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
#endif
/* Array.prototype.concat() non-standard but real world compatible behavior
* for non-existent trailing elements.
*/
#define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
#if defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER)
#undef DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
#endif
/* Non-standard 'caller' property for function instances, see
* test-bi-function-nonstd-caller-prop.js.
*/

Loading…
Cancel
Save