The following code does not seem to work as expected in Chrome, and works differently in Firefox.
(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); })();
I expected the output to be:
Error : (for `arr.push(4)`) Error : (for `arr.pop()`) [1, 2, 3]
but when I run this code in Chrome 29.0.1547.49 (Official Build 216092) beta-m, I get the following output:
3 [1, 2, 3]
Why is there no exception? I ran this code in Firefox Nightly 26.0a1 (2013-08-12), and the result
TypeError: arr.push(...) is not extensible TypeError: property arr.pop(...) is non-configurable and can't be deleted [1, 2, 3]
as i expected.
I thought about why there is a difference between Chrome and Firefox, then I realized that this could be due to the strict fashion of the pop and push methods. To summarize, Firefox (SpiderMonkey) pop and push methods are defined in strict mode, but in Chrome (V8) these methods are not defined in strict mode.
I do not know what the actual specification is. (I read some ECMA-262 5.1th Edition, but I cannot find such a section.)
source share