michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * Contributor: michael@0: * Jeff Walden michael@0: */ michael@0: michael@0: var gTestfile = '15.2.3.10-01.js'; michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 492849; michael@0: var summary = 'ES5: Implement Object.preventExtensions, Object.isExtensible'; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: function trySetProperty(o, p, v, strict) michael@0: { michael@0: function strictSetProperty() michael@0: { michael@0: "use strict"; michael@0: o[p] = v; michael@0: } michael@0: michael@0: function setProperty() michael@0: { michael@0: o[p] = v; michael@0: } michael@0: michael@0: assertEq(Object.prototype.hasOwnProperty.call(o, p), false); michael@0: michael@0: try michael@0: { michael@0: if (strict) michael@0: strictSetProperty(); michael@0: else michael@0: setProperty(); michael@0: if (o[p] === v) michael@0: return "set"; michael@0: if (p in o) michael@0: return "set-converted"; michael@0: return "swallowed"; michael@0: } michael@0: catch (e) michael@0: { michael@0: return "throw"; michael@0: } michael@0: } michael@0: michael@0: function tryDefineProperty(o, p, v) michael@0: { michael@0: assertEq(Object.prototype.hasOwnProperty.call(o, p), false); michael@0: michael@0: try michael@0: { michael@0: Object.defineProperty(o, p, { value: v }); michael@0: if (o[p] === v) michael@0: return "set"; michael@0: if (p in o) michael@0: return "set-converted"; michael@0: return "swallowed"; michael@0: } michael@0: catch (e) michael@0: { michael@0: return "throw"; michael@0: } michael@0: } michael@0: michael@0: assertEq(typeof Object.preventExtensions, "function"); michael@0: assertEq(Object.preventExtensions.length, 1); michael@0: michael@0: var slowArray = [1, 2, 3]; michael@0: slowArray.slow = 5; michael@0: var objs = michael@0: [{}, { 1: 2 }, { a: 3 }, [], [1], [, 1], slowArray, function a(){}, /a/]; michael@0: michael@0: for (var i = 0, sz = objs.length; i < sz; i++) michael@0: { michael@0: var o = objs[i]; michael@0: assertEq(Object.isExtensible(o), true, "object " + i + " not extensible?"); michael@0: michael@0: var o2 = Object.preventExtensions(o); michael@0: assertEq(o, o2); michael@0: michael@0: assertEq(Object.isExtensible(o), false, "object " + i + " is extensible?"); michael@0: michael@0: assertEq(trySetProperty(o, "baz", 17, true), "throw", michael@0: "unexpected behavior for strict-mode property-addition to " + michael@0: "object " + i); michael@0: assertEq(trySetProperty(o, "baz", 17, false), "swallowed", michael@0: "unexpected behavior for property-addition to object " + i); michael@0: michael@0: assertEq(tryDefineProperty(o, "baz", 17), "throw", michael@0: "unexpected behavior for new property definition on object " + i); michael@0: } michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: reportCompare(true, true); michael@0: michael@0: print("All tests passed!");