| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010-2015 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Tests the Reflect.getPrototypeOf - ES6 26.1.8. |
| 29 // This is adapted from mjsunit/get-prototype-of.js. |
| 30 |
| 31 // Flags: --harmony-reflect |
| 32 |
| 33 |
| 34 |
| 28 function assertPrototypeOf(func, expected) { | 35 function assertPrototypeOf(func, expected) { |
| 29 assertEquals(expected, Object.getPrototypeOf(func)); | 36 assertEquals(expected, Reflect.getPrototypeOf(func)); |
| 30 } | 37 } |
| 31 | 38 |
| 32 | 39 |
| 33 assertThrows(function() { | 40 assertThrows(function() { |
| 34 Object.getPrototypeOf(undefined); | 41 Reflect.getPrototypeOf(undefined); |
| 35 }, TypeError); | 42 }, TypeError); |
| 36 | 43 |
| 37 | 44 |
| 38 assertThrows(function() { | 45 assertThrows(function() { |
| 39 Object.getPrototypeOf(null); | 46 Reflect.getPrototypeOf(null); |
| 40 }, TypeError); | 47 }, TypeError); |
| 41 | 48 |
| 42 | 49 |
| 43 function F(){}; | 50 function F(){}; |
| 44 var y = new F(); | 51 var y = new F(); |
| 45 | 52 |
| 46 assertPrototypeOf(y, F.prototype); | 53 assertPrototypeOf(y, F.prototype); |
| 47 assertPrototypeOf(F, Function.prototype); | 54 assertPrototypeOf(F, Function.prototype); |
| 48 | 55 |
| 49 assertPrototypeOf({x: 5}, Object.prototype); | 56 assertPrototypeOf({x: 5}, Object.prototype); |
| 50 assertPrototypeOf({x: 5, __proto__: null}, null); | 57 assertPrototypeOf({x: 5, __proto__: null}, null); |
| 51 | 58 |
| 52 assertPrototypeOf([1, 2], Array.prototype); | 59 assertPrototypeOf([1, 2], Array.prototype); |
| 53 | 60 |
| 54 | 61 |
| 55 assertPrototypeOf(1, Number.prototype); | 62 assertThrows(function () { |
| 56 assertPrototypeOf(true, Boolean.prototype); | 63 Reflect.getPrototypeOf(1); |
| 57 assertPrototypeOf(false, Boolean.prototype); | 64 }, TypeError); |
| 58 assertPrototypeOf('str', String.prototype); | 65 assertThrows(function () { |
| 59 assertPrototypeOf(Symbol(), Symbol.prototype); | 66 Reflect.getPrototypeOf(true); |
| 67 }, TypeError); |
| 68 assertThrows(function () { |
| 69 Reflect.getPrototypeOf(false); |
| 70 }, TypeError); |
| 71 assertThrows(function () { |
| 72 Reflect.getPrototypeOf('str'); |
| 73 }, TypeError); |
| 74 assertThrows(function () { |
| 75 Reflect.getPrototypeOf(Symbol()); |
| 76 }, TypeError); |
| 77 |
| 78 assertPrototypeOf(Object(1), Number.prototype); |
| 79 assertPrototypeOf(Object(true), Boolean.prototype); |
| 80 assertPrototypeOf(Object(false), Boolean.prototype); |
| 81 assertPrototypeOf(Object('str'), String.prototype); |
| 82 assertPrototypeOf(Object(Symbol()), Symbol.prototype); |
| 60 | 83 |
| 61 | 84 |
| 62 var errorFunctions = [ | 85 var errorFunctions = [ |
| 63 EvalError, | 86 EvalError, |
| 64 RangeError, | 87 RangeError, |
| 65 ReferenceError, | 88 ReferenceError, |
| 66 SyntaxError, | 89 SyntaxError, |
| 67 TypeError, | 90 TypeError, |
| 68 URIError, | 91 URIError, |
| 69 ]; | 92 ]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 for (var f of functions) { | 130 for (var f of functions) { |
| 108 assertPrototypeOf(f, Function.prototype); | 131 assertPrototypeOf(f, Function.prototype); |
| 109 assertPrototypeOf(new f(), f.prototype); | 132 assertPrototypeOf(new f(), f.prototype); |
| 110 } | 133 } |
| 111 | 134 |
| 112 var p = new Promise(function() {}); | 135 var p = new Promise(function() {}); |
| 113 assertPrototypeOf(p, Promise.prototype); | 136 assertPrototypeOf(p, Promise.prototype); |
| 114 | 137 |
| 115 var dv = new DataView(new ArrayBuffer()); | 138 var dv = new DataView(new ArrayBuffer()); |
| 116 assertPrototypeOf(dv, DataView.prototype); | 139 assertPrototypeOf(dv, DataView.prototype); |
| OLD | NEW |