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

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

Issue 118553003: Upgrade Symbol implementation to match current ES6 behavior. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Some test improvements. Created 6 years, 10 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') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/private.js
diff --git a/test/mjsunit/harmony/private.js b/test/mjsunit/harmony/private.js
index 09cf7f74084082e36ab1d66391022985dffe492c..c9066329d166c6d5098e7995cb607de5a704ab68 100644
--- a/test/mjsunit/harmony/private.js
+++ b/test/mjsunit/harmony/private.js
@@ -30,6 +30,16 @@
var symbols = []
+
+// Returns true if the string is a valid
+// serialization of Symbols added to the 'symbols'
+// array. Adjust if you extend 'symbols' with other
+// values.
+function isValidSymbolString(s) {
+ return ["Symbol(66)"].indexOf(s) >= 0;
+}
+
+
// Test different forms of constructor calls, all equivalent.
function TestNew() {
for (var i = 0; i < 2; ++i) {
@@ -49,7 +59,6 @@ function TestType() {
assertTrue(typeof symbols[i] === "symbol")
assertTrue(%SymbolIsPrivate(symbols[i]))
assertEquals(null, %_ClassOf(symbols[i]))
- assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i])))
assertEquals("Symbol", %_ClassOf(Object(symbols[i])))
}
}
@@ -67,28 +76,21 @@ TestPrototype()
function TestConstructor() {
for (var i in symbols) {
assertSame(Symbol, symbols[i].__proto__.constructor)
+ assertSame(Symbol, Object(symbols[i]).__proto__.constructor)
}
}
TestConstructor()
-function TestName() {
- for (var i in symbols) {
- var name = symbols[i].name
- assertTrue(name === "66")
- }
-}
-TestName()
-
-
function TestToString() {
for (var i in symbols) {
assertThrows(function() { String(symbols[i]) }, TypeError)
assertThrows(function() { symbols[i] + "" }, TypeError)
- assertThrows(function() { symbols[i].toString() }, TypeError)
- assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError)
- assertThrows(function() { Object(symbols[i]).toString() }, TypeError)
- assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i]))
+ assertTrue(isValidSymbolString(symbols[i].toString()))
+ assertTrue(isValidSymbolString(Object(symbols[i]).toString()))
+ assertTrue(isValidSymbolString(Symbol.prototype.toString.call(symbols[i])))
+ assertEquals(
+ "[object Symbol]", Object.prototype.toString.call(symbols[i]))
}
}
TestToString()
@@ -128,10 +130,14 @@ function TestEquality() {
assertTrue(Object.is(symbols[i], symbols[i]))
assertTrue(symbols[i] === symbols[i])
assertTrue(symbols[i] == symbols[i])
- assertFalse(symbols[i] === new Symbol(symbols[i]))
- assertFalse(new Symbol(symbols[i]) === symbols[i])
- assertTrue(symbols[i] == new Symbol(symbols[i]))
- assertTrue(new Symbol(symbols[i]) == symbols[i])
+ assertFalse(symbols[i] === Object(symbols[i]))
+ assertFalse(Object(symbols[i]) === symbols[i])
+ assertFalse(symbols[i] == Object(symbols[i]))
+ assertFalse(Object(symbols[i]) == symbols[i])
+ assertTrue(symbols[i] === symbols[i].valueOf())
+ assertTrue(symbols[i].valueOf() === symbols[i])
+ assertTrue(symbols[i] == symbols[i].valueOf())
+ assertTrue(symbols[i].valueOf() == symbols[i])
}
// All symbols should be distinct.
@@ -159,7 +165,7 @@ TestEquality()
function TestGet() {
for (var i in symbols) {
- assertThrows(function() { symbols[i].toString() }, TypeError)
+ assertTrue(isValidSymbolString(symbols[i].toString()))
assertEquals(symbols[i], symbols[i].valueOf())
assertEquals(undefined, symbols[i].a)
assertEquals(undefined, symbols[i]["a" + "b"])
@@ -173,7 +179,7 @@ TestGet()
function TestSet() {
for (var i in symbols) {
symbols[i].toString = 0
- assertThrows(function() { symbols[i].toString() }, TypeError)
+ assertTrue(isValidSymbolString(symbols[i].toString()))
symbols[i].valueOf = 0
assertEquals(symbols[i], symbols[i].valueOf())
symbols[i].a = 0
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698