1// Copyright 2013 the V8 project authors. All rights reserved. 2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24description("Test to ensure correct behaviour of Object.getOwnPropertyNames"); 25 26function argumentsObject() { return arguments; }; 27 28var expectedPropertyNamesSet = { 29 "{}": "[]", 30 "{a:null}": "['a']", 31 "{a:null, b:null}": "['a', 'b']", 32 "{b:null, a:null}": "['a', 'b']", 33 "{__proto__:{a:null}}": "[]", 34 "{__proto__:[1,2,3]}": "[]", 35 "Object.create({}, { 'a': { 'value': 1, 'enumerable': false } })": "['a']", 36 "Object.create([1,2,3], { 'a': { 'value': 1, 'enumerable': false } })": "['a']", 37// Function objects 38 "new Function()": "['arguments', 'caller', 'length', 'name', 'prototype']", 39 "(function(){var x=new Function();x.__proto__=[1,2,3];return x;})()": "['arguments', 'caller', 'length', 'name', 'prototype']", 40// String objects 41 "new String('')": "['length']", 42 "new String('a')": "['0', 'length']", 43 "new String('abc')": "['0', '1', '2', 'length']", 44 "(function(){var x=new String('');x.__proto__=[1,2,3];return x;})()": "['length']", 45// Array objects 46 "[]": "['length']", 47 "[null]": "['0', 'length']", 48 "[null,null]": "['0','1', 'length']", 49 "[null,null,,,,null]": "['0','1','5', 'length']", 50 "(function(){var x=[];x.__proto__=[1,2,3];return x;})()": "['length']", 51// Date objects 52 "new Date()": "[]", 53 "(function(){var x=new Date();x.__proto__=[1,2,3];return x;})()": "[]", 54// RegExp objects 55 "new RegExp('foo')": "['global', 'ignoreCase', 'lastIndex', 'multiline', 'source']", 56 "(function(){var x=new RegExp();x.__proto__=[1,2,3];return x;})()": "['global', 'ignoreCase', 'lastIndex', 'multiline', 'source']", 57// Arguments objects 58 "argumentsObject()": "['callee', 'length']", 59 "argumentsObject(1)": "['0', 'callee', 'length']", 60 "argumentsObject(1,2,3)": "['0', '1', '2', 'callee', 'length']", 61 "(function(){arguments.__proto__=[1,2,3];return arguments;})()": "['callee', 'length']", 62// Built-in ECMA functions 63 "parseInt": "['arguments', 'caller', 'length', 'name']", 64 "parseFloat": "['arguments', 'caller', 'length', 'name']", 65 "isNaN": "['arguments', 'caller', 'length', 'name']", 66 "isFinite": "['arguments', 'caller', 'length', 'name']", 67 "escape": "['arguments', 'caller', 'length', 'name']", 68 "unescape": "['arguments', 'caller', 'length', 'name']", 69 "decodeURI": "['arguments', 'caller', 'length', 'name']", 70 "decodeURIComponent": "['arguments', 'caller', 'length', 'name']", 71 "encodeURI": "['arguments', 'caller', 'length', 'name']", 72 "encodeURIComponent": "['arguments', 'caller', 'length', 'name']", 73// Built-in ECMA objects 74 "Object": "['arguments', 'caller', 'create', 'defineProperties', 'defineProperty', 'deliverChangeRecords', 'freeze', 'getNotifier', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'observe', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf', 'unobserve']", 75 "Object.prototype": "['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']", 76 "Function": "['arguments', 'caller', 'length', 'name', 'prototype']", 77 "Function.prototype": "['apply', 'arguments', 'bind', 'call', 'caller', 'constructor', 'length', 'name', 'toString']", 78 "Array": "['arguments', 'caller', 'isArray', 'length', 'name', 'observe', 'prototype', 'unobserve']", 79 "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']", 80 "String": "['arguments', 'caller', 'fromCharCode', 'length', 'name', 'prototype']", 81 "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'normalize', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']", 82 "Boolean": "['arguments', 'caller', 'length', 'name', 'prototype']", 83 "Boolean.prototype": "['constructor', 'toString', 'valueOf']", 84 "Number": "['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'arguments', 'caller', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']", 85 "Number.prototype": "['constructor', 'toExponential', 'toFixed', 'toLocaleString', 'toPrecision', 'toString', 'valueOf']", 86 "Date": "['UTC', 'arguments', 'caller', 'length', 'name', 'now', 'parse', 'prototype']", 87 "Date.prototype": "['constructor', 'getDate', 'getDay', 'getFullYear', 'getHours', 'getMilliseconds', 'getMinutes', 'getMonth', 'getSeconds', 'getTime', 'getTimezoneOffset', 'getUTCDate', 'getUTCDay', 'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth', 'getUTCSeconds', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', 'setYear', 'toDateString', 'toGMTString', 'toISOString', 'toJSON', 'toLocaleDateString', 'toLocaleString', 'toLocaleTimeString', 'toString', 'toTimeString', 'toUTCString', 'valueOf']", 88 "RegExp": "['$&', \"$'\", '$*', '$+', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$_', '$`', 'arguments', 'caller', 'input', 'lastMatch', 'lastParen', 'leftContext', 'length', 'multiline', 'name', 'prototype', 'rightContext']", 89 "RegExp.prototype": "['compile', 'constructor', 'exec', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'test', 'toString']", 90 "Error": "['arguments', 'caller', 'captureStackTrace', 'length', 'name', 'prototype', 'stackTraceLimit']", 91 "Error.prototype": "['constructor', 'message', 'name', 'toString']", 92 "Math": "['E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2', 'abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'cbrt', 'ceil', 'clz32', 'cos', 'cosh', 'exp', 'expm1', 'floor', 'fround', 'hypot', 'imul', 'log', 'log10', 'log1p', 'log2', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']", 93 "JSON": "['parse', 'stringify']" 94}; 95 96function getSortedOwnPropertyNames(obj) 97{ 98 return Object.getOwnPropertyNames(obj).sort(); 99} 100 101for (var expr in expectedPropertyNamesSet) 102 shouldBe("getSortedOwnPropertyNames(" + expr + ")", expectedPropertyNamesSet[expr]); 103 104// Global Object 105// Only check for ECMA properties here 106var globalPropertyNames = Object.getOwnPropertyNames(this); 107var expectedGlobalPropertyNames = [ 108 "NaN", 109 "Infinity", 110 "undefined", 111 "parseInt", 112 "parseFloat", 113 "isNaN", 114 "isFinite", 115 "escape", 116 "unescape", 117 "decodeURI", 118 "decodeURIComponent", 119 "encodeURI", 120 "encodeURIComponent", 121 "Object", 122 "Function", 123 "Array", 124 "String", 125 "Boolean", 126 "Number", 127 "Date", 128 "RegExp", 129 "Error", 130 "Math", 131 "JSON" 132]; 133 134for (var i = 0; i < expectedGlobalPropertyNames.length; ++i) 135 shouldBeTrue("globalPropertyNames.indexOf('" + expectedGlobalPropertyNames[i] + "') != -1"); 136