Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | //----------------------------------------------------------------------------- |
michael@0 | 7 | var BUGNUMBER = 492840; |
michael@0 | 8 | var summary = 'ES5 Object.create(O [, Properties])'; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | assertEq("create" in Object, true); |
michael@0 | 17 | assertEq(Object.create.length, 2); |
michael@0 | 18 | |
michael@0 | 19 | var o, desc, props, proto; |
michael@0 | 20 | |
michael@0 | 21 | o = Object.create(null); |
michael@0 | 22 | assertEq(Object.getPrototypeOf(o), null, "bad null-proto"); |
michael@0 | 23 | |
michael@0 | 24 | o = Object.create(null, { a: { value: 17, enumerable: false } }); |
michael@0 | 25 | assertEq(Object.getPrototypeOf(o), null, "bad null-proto"); |
michael@0 | 26 | assertEq("a" in o, true); |
michael@0 | 27 | desc = Object.getOwnPropertyDescriptor(o, "a"); |
michael@0 | 28 | assertEq(desc !== undefined, true, "no descriptor?"); |
michael@0 | 29 | assertEq(desc.value, 17); |
michael@0 | 30 | assertEq(desc.enumerable, false); |
michael@0 | 31 | assertEq(desc.configurable, false); |
michael@0 | 32 | assertEq(desc.writable, false); |
michael@0 | 33 | |
michael@0 | 34 | props = Object.create({ bar: 15 }); |
michael@0 | 35 | Object.defineProperty(props, "foo", { enumerable: false, value: 42 }); |
michael@0 | 36 | proto = { baz: 12 }; |
michael@0 | 37 | o = Object.create(proto, props); |
michael@0 | 38 | assertEq(Object.getPrototypeOf(o), proto); |
michael@0 | 39 | assertEq(Object.getOwnPropertyDescriptor(o, "foo"), undefined); |
michael@0 | 40 | assertEq("foo" in o, false); |
michael@0 | 41 | assertEq(Object.getOwnPropertyDescriptor(o, "bar"), undefined); |
michael@0 | 42 | assertEq("bar" in o, false); |
michael@0 | 43 | assertEq(Object.getOwnPropertyDescriptor(o, "baz"), undefined); |
michael@0 | 44 | assertEq(o.baz, 12); |
michael@0 | 45 | assertEq(o.hasOwnProperty("baz"), false); |
michael@0 | 46 | |
michael@0 | 47 | try { |
michael@0 | 48 | var actual = |
michael@0 | 49 | Object.create(Object.create({}, |
michael@0 | 50 | { boom: { get: function() { return "base"; }}}), |
michael@0 | 51 | { boom: { get: function() { return "overridden"; }}}).boom |
michael@0 | 52 | } catch (e) { |
michael@0 | 53 | } |
michael@0 | 54 | assertEq(actual, "overridden"); |
michael@0 | 55 | |
michael@0 | 56 | /******************************************************************************/ |
michael@0 | 57 | |
michael@0 | 58 | reportCompare(true, true); |
michael@0 | 59 | |
michael@0 | 60 | print("All tests passed!"); |