| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 // Flags: --harmony-symbols |
| 29 |
| 30 // Fake Symbol if undefined, allowing test to run in non-Harmony mode as well. |
| 31 this.Symbol = typeof Symbol != 'undefined' ? Symbol : String; |
| 32 |
| 33 |
| 34 var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); |
| 35 var getProto = desc.get; |
| 36 var setProto = desc.set; |
| 37 |
| 38 function TestNoPoisonPill() { |
| 39 assertEquals("function", typeof desc.get); |
| 40 assertEquals("function", typeof desc.set); |
| 41 assertDoesNotThrow("desc.get.call({})"); |
| 42 assertDoesNotThrow("desc.set.call({}, {})"); |
| 43 |
| 44 var obj = {}; |
| 45 var obj2 = {}; |
| 46 desc.set.call(obj, obj2); |
| 47 assertEquals(obj.__proto__, obj2); |
| 48 assertEquals(desc.get.call(obj), obj2); |
| 49 } |
| 50 TestNoPoisonPill(); |
| 51 |
| 52 |
| 53 function TestRedefineObjectPrototypeProtoGetter() { |
| 54 Object.defineProperty(Object.prototype, "__proto__", { |
| 55 get: function() { |
| 56 return 42; |
| 57 } |
| 58 }); |
| 59 assertEquals({}.__proto__, 42); |
| 60 assertEquals(desc.get.call({}), Object.prototype); |
| 61 |
| 62 var desc2 = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); |
| 63 assertEquals(desc2.get.call({}), 42); |
| 64 assertEquals(desc2.set.call({}), undefined); |
| 65 |
| 66 Object.defineProperty(Object.prototype, "__proto__", { |
| 67 set: function(x) {} |
| 68 }); |
| 69 var desc3 = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); |
| 70 assertEquals(desc3.get.call({}), 42); |
| 71 assertEquals(desc3.set.call({}), undefined); |
| 72 } |
| 73 TestRedefineObjectPrototypeProtoGetter(); |
| 74 |
| 75 |
| 76 function TestRedefineObjectPrototypeProtoSetter() { |
| 77 Object.defineProperty(Object.prototype, "__proto__", { set: undefined }); |
| 78 assertThrows(function() { |
| 79 "use strict"; |
| 80 var o = {}; |
| 81 var p = {}; |
| 82 o.__proto__ = p; |
| 83 }, TypeError); |
| 84 } |
| 85 TestRedefineObjectPrototypeProtoSetter(); |
| 86 |
| 87 |
| 88 function TestGetProtoOfValues() { |
| 89 assertEquals(getProto.call(1), Number.prototype); |
| 90 assertEquals(getProto.call(true), Boolean.prototype); |
| 91 assertEquals(getProto.call(false), Boolean.prototype); |
| 92 assertEquals(getProto.call('s'), String.prototype); |
| 93 assertEquals(getProto.call(Symbol()), Symbol.prototype); |
| 94 |
| 95 assertThrows(function() { getProto.call(null); }, TypeError); |
| 96 assertThrows(function() { getProto.call(undefined); }, TypeError); |
| 97 } |
| 98 TestGetProtoOfValues(); |
| 99 |
| 100 |
| 101 var values = [1, true, false, 's', Symbol()]; |
| 102 |
| 103 |
| 104 function TestSetProtoOfValues() { |
| 105 for (var i = 0; i < values.length; i++) { |
| 106 assertEquals(setProto.call(values[i], i), undefined); |
| 107 } |
| 108 |
| 109 assertThrows(function() { setProto.call(null, 7); }, TypeError); |
| 110 assertThrows(function() { setProto.call(undefined, 8); }, TypeError); |
| 111 } |
| 112 TestSetProtoOfValues(); |
| 113 |
| 114 |
| 115 function TestSetProtoToValue() { |
| 116 var object = {}; |
| 117 var proto = {}; |
| 118 setProto.call(object, proto); |
| 119 |
| 120 var valuesWithUndefined = values.concat(undefined); |
| 121 |
| 122 for (var i = 0; i < valuesWithUndefined.length; i++) { |
| 123 assertEquals(setProto.call(object, valuesWithUndefined[i]), undefined); |
| 124 assertEquals(getProto.call(object), proto); |
| 125 } |
| 126 |
| 127 // null is the only valid value that can be used as a [[Prototype]]. |
| 128 assertEquals(setProto.call(object, null), undefined); |
| 129 assertEquals(getProto.call(object), null); |
| 130 } |
| 131 TestSetProtoToValue(); |
| 132 |
| 133 |
| 134 function TestDeleteProto() { |
| 135 assertTrue(delete Object.prototype.__proto__); |
| 136 var o = {}; |
| 137 var p = {}; |
| 138 o.__proto__ = p; |
| 139 assertEquals(Object.getPrototypeOf(o), Object.prototype); |
| 140 var desc4 = Object.getOwnPropertyDescriptor(o, "__proto__"); |
| 141 assertTrue(desc4.configurable); |
| 142 assertTrue(desc4.enumerable); |
| 143 assertTrue(desc4.writable); |
| 144 assertEquals(desc4.value, p); |
| 145 } |
| 146 TestDeleteProto(); |
| OLD | NEW |