Closed Bug 1287520 Opened 9 years ago Closed 9 years ago

Incorrect IsPackedArray optimization in Array.prototype.concat

Categories

(Core :: JavaScript: Standard Library, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox47 --- unaffected
firefox48 --- affected
firefox49 --- affected
firefox-esr45 --- unaffected
firefox50 --- fixed

People

(Reporter: anba, Assigned: arai)

References

()

Details

Attachments

(1 file)

The `IsPackedArray` optimization in ArrayConcat is not correct when proxies are used. Test case: --- var a = [1, 2, 3]; a.constructor = { [Symbol.species]: function(...args) { var p = new Proxy(new Array(...args), { defineProperty(target, propertyKey, receiver) { if (propertyKey === "0") delete a[1]; return Reflect.defineProperty(target, propertyKey, receiver); } }); return p; } }; var p = a.concat(); print(1 in p); --- Expected: Prints "false" Actual: Prints "true"
Thanks :) https://dxr.mozilla.org/mozilla-central/rev/4c05938a64a7fde3ac2d7f4493aee1c5f2ad8a0a/js/src/builtin/Array.js#993 > if (IsPackedArray(E)) { So, we should check `IsPackedArray(A)` there too. Will post a patch after performance check.
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Before entering optimized path for packed array, added a check for `IsPackedArray(A)`, to avoid entering it when the result array is a Proxy or some complicated thing. I don't see any notable performance regression with this.
Attachment #8772224 - Flags: review?(efaustbmo)
Attachment #8772224 - Flags: review?(efaustbmo) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/b40a60e2a4e138d4b99805b5471bcff268817f9a Bug 1287520 - Check IsPackedArray for the result array in Array.prototype.concat. r=efaust
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: