Index: test/mjsunit/harmony/symbols.js |
diff --git a/test/mjsunit/harmony/symbols.js b/test/mjsunit/harmony/symbols.js |
index cdc63628ae9d219bde3ecb3a271d1396cbbf345a..fe7fd0aed4f1f083d1f08cd8bcafb1097f8fcded 100644 |
--- a/test/mjsunit/harmony/symbols.js |
+++ b/test/mjsunit/harmony/symbols.js |
@@ -34,20 +34,19 @@ var symbols = [] |
function TestNew() { |
function IndirectSymbol() { return new Symbol } |
function indirect() { return new IndirectSymbol() } |
- for (var i = 0; i < 10; ++i) { |
- symbols.push(new Symbol) |
- symbols.push(new Symbol()) |
- symbols.push(Symbol()) |
- symbols.push(indirect()) |
- } |
- %OptimizeFunctionOnNextCall(indirect) |
- indirect() // Call once before GC throws away type feedback. |
- gc() // Promote existing symbols and then allocate some more. |
- for (var i = 0; i < 10; ++i) { |
- symbols.push(new Symbol) |
- symbols.push(new Symbol()) |
- symbols.push(Symbol()) |
- symbols.push(indirect()) |
+ for (var i = 0; i < 2; ++i) { |
+ for (var j = 0; j < 5; ++j) { |
+ symbols.push(Symbol()) |
+ symbols.push(Symbol(Symbol())) |
+ symbols.push((new Symbol).valueOf()) |
+ symbols.push((new Symbol()).valueOf()) |
+ symbols.push((new Symbol(Symbol())).valueOf()) |
+ symbols.push(Object(Symbol()).valueOf()) |
+ symbols.push((indirect()).valueOf()) |
+ } |
+ %OptimizeFunctionOnNextCall(indirect) |
+ indirect() // Call once before GC throws away type feedback. |
+ gc() // Promote existing symbols and then allocate some more. |
} |
} |
TestNew() |
@@ -55,15 +54,70 @@ TestNew() |
function TestType() { |
for (var i in symbols) { |
- assertTrue(%_IsSymbol(symbols[i])) |
- assertEquals("object", typeof symbols[i]) |
- assertTrue(typeof symbols[i] === "object") |
- assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i])) |
+ assertEquals("symbol", typeof symbols[i]) |
+ assertTrue(typeof symbols[i] === "symbol") |
+ assertEquals(null, %_ClassOf(symbols[i])) |
+ assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i]))) |
+ assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) |
} |
} |
TestType() |
+function TestPrototype() { |
+ assertSame(Object.prototype, Symbol.prototype.__proto__) |
+ assertSame(Symbol.prototype, Symbol().__proto__) |
+ assertSame(Symbol.prototype, Symbol(Symbol()).__proto__) |
+ assertSame(Symbol.prototype, (new Symbol).__proto__) |
+ assertSame(Symbol.prototype, (new Symbol()).__proto__) |
+ assertSame(Symbol.prototype, (new Symbol(Symbol())).__proto__) |
+ assertSame(Symbol.prototype, Object(Symbol()).__proto__) |
+ for (var i in symbols) { |
+ assertSame(Symbol.prototype, symbols[i].__proto__) |
+ } |
+} |
+TestPrototype() |
+ |
+ |
+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])) |
+ } |
+} |
+TestToString() |
+ |
+ |
+function TestToBoolean() { |
+ for (var i in symbols) { |
+ assertTrue(Boolean(symbols[i]).valueOf()) |
+ assertFalse(!symbols[i]) |
+ assertTrue(!!symbols[i]) |
+ assertTrue(symbols[i] && true) |
+ assertFalse(!symbols[i] && false) |
+ assertTrue(!symbols[i] || true) |
+ assertEquals(1, symbols[i] ? 1 : 2) |
+ assertEquals(2, !symbols[i] ? 1 : 2) |
+ if (!symbols[i]) assertUnreachable(); |
+ if (symbols[i]) {} else assertUnreachable(); |
+ } |
+} |
+TestToBoolean() |
+ |
+ |
+function TestToNumber() { |
+ for (var i in symbols) { |
+ assertSame(NaN, Number(symbols[i]).valueOf()) |
+ assertSame(NaN, symbols[i] + 0) |
+ } |
+} |
+TestToNumber() |
+ |
+ |
function TestEquality() { |
// Every symbol should equal itself. |
for (var i in symbols) { |
@@ -88,8 +142,8 @@ TestEquality() |
function TestGet() { |
for (var i in symbols) { |
- assertEquals("[object Symbol]", symbols[i].toString()) |
- assertEquals(undefined, symbols[i].valueOf) |
+ assertThrows(function() { symbols[i].toString() }, TypeError) |
+ assertEquals(symbols[i], symbols[i].valueOf()) |
assertEquals(undefined, symbols[i].a) |
assertEquals(undefined, symbols[i]["a" + "b"]) |
assertEquals(undefined, symbols[i]["" + "1"]) |
@@ -102,7 +156,9 @@ TestGet() |
function TestSet() { |
for (var i in symbols) { |
symbols[i].toString = 0 |
- assertEquals("[object Symbol]", symbols[i].toString()) |
+ assertThrows(function() { symbols[i].toString() }, TypeError) |
+ symbols[i].valueOf = 0 |
+ assertEquals(symbols[i], symbols[i].valueOf()) |
symbols[i].a = 0 |
assertEquals(undefined, symbols[i].a) |
symbols[i]["a" + "b"] = 0 |
@@ -179,7 +235,7 @@ function TestKeyHas() { |
function TestKeyEnum(obj) { |
for (var name in obj) { |
- assertFalse(%_IsSymbol(name)) |
+ assertTrue(typeof name !== "symbol") |
} |
} |
@@ -195,9 +251,7 @@ function TestKeyNames(obj) { |
for (var i = 0; i < symbols.length; ++i) expected.add(symbols[i]) |
for (var i = 0; i < names.length; ++i) { |
var name = names[i] |
- var asString = String(name) |
- if (asString !== name) { |
- assertEquals("[object Symbol]", asString) |
+ if (typeof name === 'symbol') { |
assertTrue(expected.has(name)) |
expected.delete(name) |
} |