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

Unified Diff: test/mjsunit/harmony/private-symbols.js

Issue 1573143002: Do not leak private property names to proxy traps and interceptors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Typo Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/private-symbols.js
diff --git a/test/mjsunit/harmony/private-symbols.js b/test/mjsunit/harmony/private-symbols.js
new file mode 100644
index 0000000000000000000000000000000000000000..369c222897a51b189cebb596b38ed2e95a0d310a
--- /dev/null
+++ b/test/mjsunit/harmony/private-symbols.js
@@ -0,0 +1,78 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-proxies --harmony-reflect --allow-natives-syntax
+
+
+var symbol = %CreatePrivateSymbol("private");
+
+
+// Private symbols must never be listed.
+
+var object = {};
+object[symbol] = 42;
+for (var key of Object.keys(object)) assertUnreachable();
+for (var key of Object.getOwnPropertySymbols(object)) assertUnreachable();
+for (var key of Object.getOwnPropertyNames(object)) assertUnreachable();
+for (var key of Reflect.ownKeys(object)) assertUnreachable();
+for (var key of Reflect.enumerate(object)) assertUnreachable();
+for (var key in object) assertUnreachable();
+
+var object2 = {__proto__: object};
+for (var key of Object.keys(object2)) assertUnreachable();
+for (var key of Object.getOwnPropertySymbols(object2)) assertUnreachable();
+for (var key of Object.getOwnPropertyNames(object2)) assertUnreachable();
+for (var key of Reflect.ownKeys(object2)) assertUnreachable();
+for (var key of Reflect.enumerate(object2)) assertUnreachable();
+for (var key in object2) assertUnreachable();
+
+
+// Private symbols must never leak to proxy traps.
+
+var proxy = new Proxy({}, new Proxy({}, {get() {return () => {throw 666}}}));
+var object = {__proto__: proxy};
+
+// [[Set]]
+assertEquals(42, proxy[symbol] = 42);
+assertThrows(function() { "use strict"; proxy[symbol] = 42 }, TypeError);
+assertEquals(false, Reflect.set(proxy, symbol, 42));
+assertEquals(42, object[symbol] = 42);
+assertEquals(43, (function() {"use strict"; return object[symbol] = 43})());
+assertEquals(true, Reflect.set(object, symbol, 44));
+
+// [[DefineOwnProperty]]
+assertEquals(false, Reflect.defineProperty(proxy, symbol, {}));
+assertThrows(() => Object.defineProperty(proxy, symbol, {}), TypeError);
+assertEquals(true, Reflect.defineProperty(object, symbol, {}));
+assertEquals(object, Object.defineProperty(object, symbol, {}));
+
+// [[Delete]]
+assertEquals(true, delete proxy[symbol]);
+assertEquals(true, (function() {"use strict"; return delete proxy[symbol]})());
+assertEquals(true, Reflect.deleteProperty(proxy, symbol));
+assertEquals(true, delete object[symbol]);
+assertEquals(true, (function() {"use strict"; return delete object[symbol]})());
+assertEquals(true, Reflect.deleteProperty(object, symbol));
+
+// [[GetOwnPropertyDescriptor]]
+assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, symbol));
+assertEquals(undefined, Reflect.getOwnPropertyDescriptor(proxy, symbol));
+assertFalse(Object.prototype.hasOwnProperty.call(proxy, symbol));
+assertEquals(undefined, Object.getOwnPropertyDescriptor(object, symbol));
+assertEquals(undefined, Reflect.getOwnPropertyDescriptor(object, symbol));
+assertFalse(Object.prototype.hasOwnProperty.call(object, symbol));
+
+// [[Has]]
+assertFalse(symbol in proxy);
+assertFalse(Reflect.has(proxy, symbol));
+assertFalse(symbol in object);
+assertFalse(Reflect.has(object, symbol));
+
+// [[Get]]
+assertEquals(undefined, proxy[symbol]);
+assertEquals(undefined, Reflect.get(proxy, symbol));
+assertEquals(undefined, Reflect.get(proxy, symbol, 42));
+assertEquals(undefined, object[symbol]);
+assertEquals(undefined, Reflect.get(object, symbol));
+assertEquals(undefined, Reflect.get(object, symbol, 42));
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698