mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 11:15:34 +00:00
Backed out changeset 35b1a010cb9f (bug 1041586)
This commit is contained in:
parent
fac746e08b
commit
b96ed92209
@ -1,37 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
"use strict";
|
||||
|
||||
const x = Object.freeze([1, 2, 3]);
|
||||
|
||||
let fakeArray = {
|
||||
[Symbol.isConcatSpreadable]: true,
|
||||
length: 2,
|
||||
0: "hello",
|
||||
1: "world"
|
||||
}
|
||||
assertDeepEq(x.concat(fakeArray), [1, 2, 3, "hello", "world"]);
|
||||
assertDeepEq(x.concat(fakeArray, fakeArray), [1, 2, 3, "hello", "world", "hello", "world"]);
|
||||
|
||||
for (let truthy of [true, 3.41, "abc", Symbol(), {}]) {
|
||||
let obj = {[Symbol.isConcatSpreadable]: truthy, length: 1, 0: "hey"}
|
||||
assertDeepEq(x.concat(obj), [1, 2, 3, "hey"]);
|
||||
}
|
||||
|
||||
for (let notTruthy of [null, undefined, false, 0, NaN, ""]) {
|
||||
let obj = {[Symbol.isConcatSpreadable]: notTruthy, length: 1, 0: "hey"}
|
||||
assertDeepEq(x.concat(obj), [1, 2, 3, obj]);
|
||||
}
|
||||
|
||||
let array = [5, 4];
|
||||
assertDeepEq(x.concat(array), [1, 2, 3, 5, 4]);
|
||||
|
||||
// Can make arrays non-spreadable
|
||||
array[Symbol.isConcatSpreadable] = false;
|
||||
assertDeepEq(x.concat(array), [1, 2, 3, [5, 4]]);
|
||||
|
||||
// Explicitly spreadable
|
||||
array[Symbol.isConcatSpreadable] = true;
|
||||
assertDeepEq(x.concat(array), [1, 2, 3, 5, 4]);
|
||||
|
||||
reportCompare(true, true);
|
@ -1,34 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
"use strict";
|
||||
|
||||
// Primitive values should never be tried to spread
|
||||
let primitives = [
|
||||
10,
|
||||
false,
|
||||
Symbol()
|
||||
// Can't change String.prototype.length
|
||||
];
|
||||
|
||||
for (let value of primitives) {
|
||||
let prototype = Object.getPrototypeOf(value);
|
||||
prototype[Symbol.isConcatSpreadable] = true;
|
||||
|
||||
Object.defineProperty(prototype, "length", {
|
||||
configurable: true,
|
||||
get() {
|
||||
// Should never invoke length getter
|
||||
assertEq(true, false);
|
||||
},
|
||||
});
|
||||
|
||||
let x = [1, 2].concat(value);
|
||||
assertDeepEq(x, [1, 2, value]);
|
||||
|
||||
delete prototype[Symbol.isConcatSpreadable];
|
||||
delete prototype.length;
|
||||
|
||||
prototype.length;
|
||||
}
|
||||
|
||||
reportCompare(true, true);
|
@ -172,7 +172,7 @@ assertEq(b.constructor, Date);
|
||||
`);
|
||||
}
|
||||
|
||||
test("concat", [], 0, "get:concat,get:constructor,c-get:Symbol(Symbol.species),get:Symbol(Symbol.isConcatSpreadable),get:length,get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
|
||||
test("concat", [], 0, "get:concat,get:constructor,c-get:Symbol(Symbol.species),get:length,get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
|
||||
test("filter", [x => x % 2], 0, "get:filter,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:1:true:true:true,get:1,get:2,define:1:3:true:true:true,get:3,get:4,define:2:5:true:true:true,");
|
||||
test("map", [x => x * 2], 5, "get:map,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:2:true:true:true,get:1,define:1:4:true:true:true,get:2,define:2:6:true:true:true,get:3,define:3:8:true:true:true,get:4,define:4:10:true:true:true,");
|
||||
test("slice", [], 5, "get:slice,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
|
||||
|
Loading…
Reference in New Issue
Block a user