12bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
22bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com//
32bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// Redistribution and use in source and binary forms, with or without
42bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// modification, are permitted provided that the following conditions
52bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// are met:
62bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com//
72bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// 1. Redistributions of source code must retain the above copyright
82bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// notice, this list of conditions and the following disclaimer.
92bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com//
102bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// 2. Redistributions in binary form must reproduce the above
112bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// copyright notice, this list of conditions and the following
122bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// disclaimer in the documentation and/or other materials provided
132bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// with the distribution.
142bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com//
152bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// 3. Neither the name of the copyright holder(s) nor the names of any
162bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// contributors may be used to endorse or promote products derived
172bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// from this software without specific prior written permission.
182bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com//
192bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
202bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
212bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
222bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
232bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
242bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
252bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
262bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
282bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
292bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
302bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// OF THE POSSIBILITY OF SUCH DAMAGE.
312bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com
322bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com// Based on LayoutTests/fast/js/Object-keys.html
332bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com
342bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertThrows(function () { Object.keys(2) }, TypeError);
352bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertThrows(function () { Object.keys("foo") }, TypeError);
362bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertThrows(function () { Object.keys(null) }, TypeError);
372bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertThrows(function () { Object.keys(undefined) }, TypeError);
382bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com
392bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys({}), []);
402bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys({a:null}), ['a']);
412bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys({a:null, b:null}), ['a', 'b']);
422bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys({b:null, a:null}), ['b', 'a']);
432bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys([]), []);
442bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys([null]), ['0']);
452bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys([null,null]), ['0', '1']);
462bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys([null,null,,,,null]), ['0', '1', '5']);
472bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys({__proto__:{a:null}}), []);
482bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys({__proto__:[1,2,3]}), []);
492bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comvar x = [];
502bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comx.__proto__ = [1, 2, 3];
512bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys(x), []);
522bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(Object.keys(function () {}), []);
532bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com
54c514574143c1bf74d4fb6e7dccb175fe9ff2f5d3sgjesse@chromium.orgassertEquals('string', typeof(Object.keys([1])[0]));
55c514574143c1bf74d4fb6e7dccb175fe9ff2f5d3sgjesse@chromium.org
562bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comfunction argsTest(a, b, c) {
57160a7b0747492f3f735353d9582521f3314bf4dfdanno@chromium.org  assertEquals(['0', '1', '2'], Object.keys(arguments));
582bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com}
592bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com
602bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comargsTest(1, 2, 3);
612bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.com
622bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comvar literal = {a: 1, b: 2, c: 3};
632bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comvar keysBefore = Object.keys(literal);
642bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(['a', 'b', 'c'], keysBefore);
652bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comkeysBefore[0] = 'x';
662bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comvar keysAfter = Object.keys(literal);
672bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(['a', 'b', 'c'], keysAfter);
682bc58ef330b2d92ba287754282872699c151db4achristian.plesner.hansen@gmail.comassertEquals(['x', 'b', 'c'], keysBefore);
69