1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15var array = ["foo", [], Infinity, 4]; 16 17function f(arg1, arg2, arg3) { 18 assert(arg1 === array[arg2]); 19 assert(arg3 === array); 20 return false; 21} 22 23assert(array.some(f) === false); 24 25function g(arg1, arg2, arg3) { 26 if (arg1 === 1) { 27 return true; 28 } else { 29 return false; 30 } 31} 32 33var arr1 = [2, 2, 2, 2, 2, 2]; 34assert(arr1.some(g) === false); 35 36var arr2 = [2, 2, 2, 2, 2, 1]; 37assert(arr2.some(g) === true); 38 39// Checking behavior when unable to get length 40var obj = { some : Array.prototype.some }; 41Object.defineProperty(obj, 'length', { 'get' : function () {throw new ReferenceError ("foo"); } }); 42 43try { 44 obj.some(f); 45 assert(false); 46} catch (e) { 47 assert(e.message === "foo"); 48 assert(e instanceof ReferenceError); 49} 50 51// Checking behavior when unable to get element 52var obj = { some : Array.prototype.some, length : 1}; 53Object.defineProperty(obj, '0', { 'get' : function () {throw new ReferenceError ("foo"); } }); 54 55try { 56 obj.some(f); 57 assert(false); 58} catch (e) { 59 assert(e.message === "foo"); 60 assert(e instanceof ReferenceError); 61} 62