|
| 1 | +// Copyright 2015 Samsung Electronics Co., Ltd. |
| 2 | +// Copyright 2015 University of Szeged. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +var obj = {}; |
| 17 | + |
| 18 | +// Test if the toString fails. |
| 19 | +try { |
| 20 | + obj.propertyIsEnumerable({ toString: function() { throw new ReferenceError ("foo"); } }); |
| 21 | + |
| 22 | + assert (false); |
| 23 | +} catch (e) { |
| 24 | + assert (e.message === "foo"); |
| 25 | + assert (e instanceof ReferenceError); |
| 26 | +} |
| 27 | + |
| 28 | +// Test if the toObject fails. |
| 29 | +var obj1; |
| 30 | +try { |
| 31 | + obj1.propertyIsEnumerable("fail"); |
| 32 | + |
| 33 | + assert (false); |
| 34 | +} catch (e) { |
| 35 | + assert (e instanceof TypeError); |
| 36 | +} |
| 37 | + |
| 38 | +var array = []; |
| 39 | +obj.prop = "bar"; |
| 40 | +array[0] = "bar"; |
| 41 | + |
| 42 | +assert (obj.propertyIsEnumerable('prop') === true); |
| 43 | +assert (array.propertyIsEnumerable(0) === true); |
| 44 | + |
| 45 | +assert (obj.propertyIsEnumerable('length') === false); |
| 46 | +assert (array.propertyIsEnumerable('length') === false); |
| 47 | +assert (Math.propertyIsEnumerable('random') === false); |
| 48 | + |
| 49 | +// Creating a new property |
| 50 | +Object.defineProperty(obj, 'prop1', { value: 'foo', enumerable: true }); |
| 51 | +Object.defineProperty(obj, 'prop2', { value: 'foo', enumerable: false }); |
| 52 | +Object.defineProperty(obj, 'prop3', { value: 'foo' }); |
| 53 | +assert (obj.propertyIsEnumerable('prop1') === true); |
| 54 | +assert (obj.propertyIsEnumerable('prop2') === false); |
| 55 | +assert (obj.propertyIsEnumerable('prop3') === false); |
| 56 | + |
| 57 | +Object.defineProperty(array, 'prop1', { value: 'foo', enumerable: true }); |
| 58 | +Object.defineProperty(array, 'prop2', { value: 'foo', enumerable: false }); |
| 59 | +Object.defineProperty(array, 'prop3', { value: 'foo' }); |
| 60 | +assert (array.propertyIsEnumerable('prop1') === true); |
| 61 | +assert (array.propertyIsEnumerable('prop2') === false); |
| 62 | +assert (array.propertyIsEnumerable('prop3') === false); |
| 63 | + |
| 64 | +// Modify an existing one |
| 65 | +Object.defineProperty(obj, 'prop', { value: 'foo', enumerable: false }); |
| 66 | +assert (obj.propertyIsEnumerable('prop') === false); |
| 67 | +Object.defineProperty(obj, 'prop', { value: 'foo', enumerable: true }); |
| 68 | +assert (obj.propertyIsEnumerable('prop') === true); |
| 69 | + |
| 70 | +Object.defineProperty(array, 0, { value: 'foo', enumerable: false }); |
| 71 | +assert (array.propertyIsEnumerable(0) === false); |
| 72 | +Object.defineProperty(array, 0, { value: 'foo', enumerable: true }); |
| 73 | +assert (array.propertyIsEnumerable(0) === true); |
| 74 | + |
| 75 | +// Enumerability of inherited properties |
| 76 | +function construct1() |
| 77 | +{ |
| 78 | + this.prop1 = 'foo'; |
| 79 | +} |
| 80 | + |
| 81 | +function construct2() |
| 82 | +{ |
| 83 | + this.prop2 = 'foo'; |
| 84 | +} |
| 85 | + |
| 86 | +construct2.prototype = new construct1; |
| 87 | +construct2.prototype.constructor = construct2; |
| 88 | + |
| 89 | +var obj2 = new construct2(); |
| 90 | +obj2.prop3 = 'foo'; |
| 91 | + |
| 92 | +assert (obj2.propertyIsEnumerable('prop3') === true); |
| 93 | +assert (obj2.propertyIsEnumerable('prop2') === true); |
| 94 | +assert (obj2.propertyIsEnumerable('prop1') === false); |
| 95 | + |
| 96 | +obj2.prop1 = 'foo'; |
| 97 | + |
| 98 | +assert (obj2.propertyIsEnumerable('prop1') === true); |
0 commit comments