Frozen array' pop and push difference between chrome and firefox
This is the example code.
(function () {
'use strict';
var
arr = Object.freeze([1, 2, 3]);
try {
arr.push(4);
} catch (e) {
console.log(e);
}
try {
console.log(arr.pop());
}catch (e) {
console.log(e);
}
console.log(arr);
})();
How do you expect this code to run? I expected outputting this,
Error : (for `arr.push(4)`)
Error : (for `arr.pop()`)
[1, 2, 3]
but realy output is this code on Chrome 29.0.1547.49 (Official Build
216092) beta-m,
3
[1, 2, 3]
Why no exception? I disbelieve it. so I tried to run this code on Firefox
Nightly 26.0a1(2013-08-12), result is,
TypeError: arr.push(...) is not extensible
TypeError: property arr.pop(...) is non-configurable and can't be deleted
[1, 2, 3]
This result was wanted by me.
I thought about why it is difference between Chrome and Firefox, then I
understood it probably is by strict mode of pop and push methods. To sum
up, Firefox(SpiderMonkey) is that pop and push methods is defined in
strict mode, but Chrome(V8) is that these methods isn't defined in strict
mode.
I don't know which is actual specifection. (I read some ECMA-262 5.1th
Edition, but I can't find such section.) Please tell me!
No comments:
Post a Comment