reviver-array-length-coerce-err.js (1087B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-internalizejsonproperty 5 description: > 6 Abrupt completion from coercing array "length" property to a number value 7 info: | 8 JSON.parse ( text [ , reviver ] ) 9 10 [...] 11 7. If IsCallable(reviver) is true, then 12 [...] 13 e. Return ? InternalizeJSONProperty(root, rootName). 14 15 Runtime Semantics: InternalizeJSONProperty ( holder, name) 16 17 1. Let val be ? Get(holder, name). 18 2. If Type(val) is Object, then 19 a. Let isArray be ? IsArray(val). 20 b. If isArray is true, then 21 i. Set I to 0. 22 ii. Let len be ? ToLength(? Get(val, "length")). 23 features: [Proxy] 24 ---*/ 25 26 var uncoercible = { 27 valueOf: function() { 28 throw new Test262Error(); 29 } 30 }; 31 var badLength = new Proxy([], { 32 get: function(_, name) { 33 if (name === 'length') { 34 return uncoercible; 35 } 36 } 37 }); 38 39 assert.throws(Test262Error, function() { 40 JSON.parse('[0,0]', function() { 41 this[1] = badLength; 42 }); 43 }); 44 45 reportCompare(0, 0);