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

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

Issue 108083005: ES6: Add Object.getOwnPropertySymbols (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment and formatting based on code review Created 6 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
« no previous file with comments | « test/cctest/test-api.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/symbols.js
diff --git a/test/mjsunit/harmony/symbols.js b/test/mjsunit/harmony/symbols.js
index 3fcd06dfdca985fcd81abd8630cb8ededa8fe0d7..ce02a05ace787196eb5971e416d6601beafa55c7 100644
--- a/test/mjsunit/harmony/symbols.js
+++ b/test/mjsunit/harmony/symbols.js
@@ -273,7 +273,7 @@ function TestKeyGet(obj) {
}
-function TestKeyHas() {
+function TestKeyHas(obj) {
for (var i in symbols) {
assertTrue(symbols[i] in obj)
assertTrue(Object.hasOwnProperty.call(obj, symbols[i]))
@@ -298,6 +298,15 @@ function TestKeyNames(obj) {
}
+function TestGetOwnPropertySymbols(obj) {
+ var syms = Object.getOwnPropertySymbols(obj)
+ assertEquals(syms.length, symbols.length)
+ for (var i in syms) {
+ assertEquals("symbol", typeof syms[i])
+ }
+}
+
+
function TestKeyDescriptor(obj) {
for (var i in symbols) {
var desc = Object.getOwnPropertyDescriptor(obj, symbols[i]);
@@ -331,6 +340,7 @@ for (var i in objs) {
TestKeyHas(obj)
TestKeyEnum(obj)
TestKeyNames(obj)
+ TestGetOwnPropertySymbols(obj)
TestKeyDescriptor(obj)
TestKeyDelete(obj)
}
@@ -350,3 +360,44 @@ function TestCachedKeyAfterScavenge() {
}
}
TestCachedKeyAfterScavenge();
+
+
+function TestGetOwnPropertySymbolsWithProto() {
+ // We need to be have fast properties to have insertion order for property
+ // keys. The current limit is currently 30 properties.
+ var syms = symbols.slice(0, 30);
+ var proto = {}
+ var object = Object.create(proto)
+ for (var i = 0; i < syms.length; i++) {
+ // Even on object, odd on proto.
+ if (i % 2) {
+ proto[syms[i]] = i
+ } else {
+ object[syms[i]] = i
+ }
+ }
+
+ assertTrue(%HasFastProperties(object));
+
+ var objectOwnSymbols = Object.getOwnPropertySymbols(object)
+ assertEquals(objectOwnSymbols.length, syms.length / 2)
+
+ for (var i = 0; i < objectOwnSymbols.length; i++) {
+ assertEquals(objectOwnSymbols[i], syms[i * 2])
+ }
+}
+TestGetOwnPropertySymbolsWithProto()
+
+
+function TestGetOwnPropertySymbolsWithPrivateSymbols() {
+ var privateSymbol = %CreatePrivateSymbol("private")
+ var publicSymbol = Symbol()
+ var publicSymbol2 = Symbol()
+ var obj = {}
+ obj[publicSymbol] = 1
+ obj[privateSymbol] = 2
+ obj[publicSymbol2] = 3
+ var syms = Object.getOwnPropertySymbols(obj)
+ assertEquals(syms, [publicSymbol, publicSymbol2])
+}
+TestGetOwnPropertySymbolsWithPrivateSymbols()
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698