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 obj = []; 16 17Object.defineProperty (obj, "prop", { 18 value: 2010, 19 writable: true, 20 enumerable: true, 21 configurable: false 22}); 23 24assert (obj.hasOwnProperty ("prop")); 25function getFunc() { 26 return 20; 27} 28 29try { 30 Object.defineProperty (obj, "prop", { 31 get: getFunc 32 }); 33 assert (false); 34} catch (e) { 35 assert (e instanceof TypeError); 36 var desc = Object.getOwnPropertyDescriptor (obj, "prop"); 37 assert (desc.value === 2010); 38 assert (typeof (desc.get) === 'undefined'); 39} 40 41obj = {}; 42var setter = function () {}; 43 44Object.defineProperty(obj, "prop", { 45 set: setter, 46 configurable: true 47}); 48 49var desc1 = Object.getOwnPropertyDescriptor(obj, "prop"); 50 51Object.defineProperty(obj, "prop", { 52 set: undefined 53}); 54 55var desc2 = Object.getOwnPropertyDescriptor(obj, "prop"); 56assert (desc1.set === setter && desc2.set === undefined); 57 58obj = {}; 59 60/* This error is thrown even in non-strict mode. */ 61Object.defineProperty(obj, 'f', { 62 set: function(value) { throw 234; }, 63}); 64 65try { 66 obj.f = 5; 67 assert (false); 68} catch (err) { 69 assert (err === 234); 70} 71 72try { 73 Object.defineProperty(42, "prop", { 74 set: undefined 75 }); 76 assert (false); 77} catch (e) { 78 assert (e instanceof TypeError); 79} 80