| 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-proxies | |
| 29 | |
| 30 | |
| 31 // Helper. | |
| 32 | |
| 33 function TestWithProxies(test, x, y, z) { | |
| 34 test(function(h) { return new Proxy({}, h) }, x, y, z) | |
| 35 test(function(h) { | |
| 36 return Proxy.createFunction(h, function() {}) | |
| 37 }, x, y, z) | |
| 38 } | |
| 39 | |
| 40 | |
| 41 // No symbols should leak to proxy traps. | |
| 42 | |
| 43 function TestNoSymbolsToTrap(handler) { | |
| 44 TestWithProxies(TestNoSymbolsToTrap2, handler) | |
| 45 } | |
| 46 | |
| 47 function TestNoSymbolsToTrap2(create, handler) { | |
| 48 var p = create(handler) | |
| 49 var o = Object.create(p) | |
| 50 var symbol = Symbol("secret") | |
| 51 | |
| 52 assertFalse(symbol in p) | |
| 53 assertFalse(symbol in o) | |
| 54 assertEquals(undefined, p[symbol]) | |
| 55 assertEquals(undefined, o[symbol]) | |
| 56 assertEquals(47, p[symbol] = 47) | |
| 57 assertEquals(47, o[symbol] = 47) | |
| 58 assertFalse(delete p[symbol]) | |
| 59 assertTrue(delete o[symbol]) | |
| 60 assertTrue(delete o[symbol]) | |
| 61 assertFalse({}.hasOwnProperty.call(p, symbol)) | |
| 62 assertFalse({}.hasOwnProperty.call(o, symbol)) | |
| 63 assertEquals(undefined, Object.getOwnPropertyDescriptor(p, symbol)) | |
| 64 assertEquals(undefined, Object.getOwnPropertyDescriptor(o, symbol)) | |
| 65 } | |
| 66 | |
| 67 | |
| 68 TestNoSymbolsToTrap({ | |
| 69 has: assertUnreachable, | |
| 70 hasOwn: assertUnreachable, | |
| 71 get: assertUnreachable, | |
| 72 set: assertUnreachable, | |
| 73 delete: assertUnreachable, | |
| 74 getPropertyDescriptor: assertUnreachable, | |
| 75 getOwnPropertyDescriptor: assertUnreachable, | |
| 76 defineProperty: assertUnreachable | |
| 77 }) | |
| 78 | |
| 79 | |
| 80 // All symbols returned from proxy traps should be filtered. | |
| 81 | |
| 82 function TestNoSymbolsFromTrap(handler) { | |
| 83 TestWithProxies(TestNoSymbolsFromTrap2, handler) | |
| 84 } | |
| 85 | |
| 86 function TestNoSymbolsFromTrap2(create, handler) { | |
| 87 var p = create(handler) | |
| 88 var o = Object.create(p) | |
| 89 | |
| 90 assertEquals(0, Object.keys(p).length) | |
| 91 assertEquals(0, Object.keys(o).length) | |
| 92 assertEquals(0, Object.getOwnPropertyNames(p).length) | |
| 93 assertEquals(0, Object.getOwnPropertyNames(o).length) | |
| 94 for (var n in p) assertUnreachable() | |
| 95 for (var n in o) assertUnreachable() | |
| 96 } | |
| 97 | |
| 98 | |
| 99 function MakeSymbolArray() { | |
| 100 return [Symbol(), Symbol("a")] | |
| 101 } | |
| 102 | |
| 103 TestNoSymbolsFromTrap({ | |
| 104 enumerate: MakeSymbolArray, | |
| 105 keys: MakeSymbolArray, | |
| 106 getPropertyNames: MakeSymbolArray, | |
| 107 getOwnPropertyNames: MakeSymbolArray | |
| 108 }) | |
| OLD | NEW |