Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: test/mjsunit/harmony/proxies-symbols.js

Issue 12422019: ES6 symbols: prevent reflection and proxy APIs from leaking symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Deal with Object.observe as well Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/object-observe.js ('k') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 --harmony-symbols
29
30
31 // Helper.
32
33 function TestWithProxies(test, x, y, z) {
34 test(Proxy.create, x, y, z)
35 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z)
36 }
37
38
39 // No symbols should leak to proxy traps.
40
41 function TestNoSymbolsToTrap(handler) {
42 TestWithProxies(TestNoSymbolsToTrap2, handler)
43 }
44
45 function TestNoSymbolsToTrap2(create, handler) {
46 var p = create(handler)
47 var o = Object.create(p)
48 var symbol = Symbol("secret")
49
50 assertFalse(symbol in p)
51 assertFalse(symbol in o)
52 assertEquals(undefined, p[symbol])
53 assertEquals(undefined, o[symbol])
54 assertEquals(47, p[symbol] = 47)
55 assertEquals(47, o[symbol] = 47)
56 assertFalse(delete p[symbol])
57 assertTrue(delete o[symbol])
58 assertTrue(delete o[symbol])
59 assertFalse({}.hasOwnProperty.call(p, symbol))
60 assertFalse({}.hasOwnProperty.call(o, symbol))
61 assertEquals(undefined, Object.getOwnPropertyDescriptor(p, symbol))
62 assertEquals(undefined, Object.getOwnPropertyDescriptor(o, symbol))
63 }
64
65
66 TestNoSymbolsToTrap({
67 has: assertUnreachable,
68 hasOwn: assertUnreachable,
69 get: assertUnreachable,
70 set: assertUnreachable,
71 delete: assertUnreachable,
72 getPropertyDescriptor: assertUnreachable,
73 getOwnPropertyDescriptor: assertUnreachable,
74 defineProperty: assertUnreachable
75 })
76
77
78 // All symbols returned from proxy traps should be filtered.
79
80 function TestNoSymbolsFromTrap(handler) {
81 TestWithProxies(TestNoSymbolsFromTrap2, handler)
82 }
83
84 function TestNoSymbolsFromTrap2(create, handler) {
85 var p = create(handler)
86 var o = Object.create(p)
87
88 assertEquals(0, Object.keys(p).length)
89 assertEquals(0, Object.keys(o).length)
90 assertEquals(0, Object.getOwnPropertyNames(p).length)
91 assertEquals(0, Object.getOwnPropertyNames(o).length)
92 for (var n in p) assertUnreachable()
93 for (var n in o) assertUnreachable()
94 }
95
96
97 function MakeSymbolArray() {
98 return [Symbol(), Symbol("a")]
99 }
100
101 TestNoSymbolsFromTrap({
102 enumerate: MakeSymbolArray,
103 keys: MakeSymbolArray,
104 getPropertyNames: MakeSymbolArray,
105 getOwnPropertyNames: MakeSymbolArray
106 })
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/object-observe.js ('k') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698