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 obj1 = {}; 16obj1.prop = "hi"; 17 18assert (obj1.hasOwnProperty('prop') === true); 19assert (obj1.hasOwnProperty('NO_PROP') === false); 20 21 22// Test if the toString fails. 23try { 24 obj1.hasOwnProperty({toString: function() { throw new ReferenceError ("foo"); }}); 25 26 assert (false); 27} catch (e) { 28 assert (e.message === "foo"); 29 assert (e instanceof ReferenceError); 30} 31 32// Test if the toObject fails. 33 34var obj2; 35try { 36 obj2.hasOwnProperty("fail"); 37 38 assert (false); 39} catch (e) { 40 assert (e instanceof TypeError); 41} 42 43var obj_undef; 44var obj3 = {}; 45Object.defineProperty(obj3, 'Test', { 'get' : function () {throw new ReferenceError ("foo"); } }); 46assert (obj3.hasOwnProperty("Test") === true); 47 48Object.defineProperty(obj3, 'Test2', { 'get' : function () { return 0/0; } }); 49assert (obj3.hasOwnProperty("Test2") === true); 50 51Object.defineProperty(obj3, 'Test4', { 'get' : function () { return obj_undef; } }); 52assert (obj3.hasOwnProperty("Test4") === true); 53