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

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

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: 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/mjsunit/harmony/proxies.js ('k') | test/mjsunit/mjsunit.status » ('j') | 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 154eca08d2dd6d4e877750fbd11235d12aecfd58..ce02a05ace787196eb5971e416d6601beafa55c7 100644
--- a/test/mjsunit/harmony/symbols.js
+++ b/test/mjsunit/harmony/symbols.js
@@ -30,35 +30,27 @@
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)", "Symbol()"].indexOf(s) >= 0;
-}
-
-
-// Test different forms of constructor calls.
+// Test different forms of constructor calls, all equivalent.
function TestNew() {
- function indirectSymbol() { return Symbol() }
- function indirect() { return indirectSymbol() }
+ function IndirectSymbol() { return new Symbol }
+ function indirect() { return new IndirectSymbol() }
for (var i = 0; i < 2; ++i) {
for (var j = 0; j < 5; ++j) {
symbols.push(Symbol())
symbols.push(Symbol(undefined))
symbols.push(Symbol("66"))
symbols.push(Symbol(66))
- symbols.push(Symbol().valueOf())
- symbols.push(indirect())
+ 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.
}
- assertThrows(function () { Symbol(Symbol()) }, TypeError)
- assertThrows(function () { new Symbol(66) }, TypeError)
}
TestNew()
@@ -69,6 +61,7 @@ function TestType() {
assertTrue(typeof symbols[i] === "symbol")
assertFalse(%SymbolIsPrivate(symbols[i]))
assertEquals(null, %_ClassOf(symbols[i]))
+ assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i])))
assertEquals("Symbol", %_ClassOf(Object(symbols[i])))
}
}
@@ -78,6 +71,10 @@ 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__)
@@ -87,11 +84,14 @@ TestPrototype()
function TestConstructor() {
- assertSame(Function.prototype, Symbol.__proto__)
assertFalse(Object === Symbol.prototype.constructor)
assertFalse(Symbol === Object.prototype.constructor)
assertSame(Symbol, Symbol.prototype.constructor)
assertSame(Symbol, Symbol().__proto__.constructor)
+ assertSame(Symbol, Symbol(Symbol()).__proto__.constructor)
+ assertSame(Symbol, (new Symbol).__proto__.constructor)
+ assertSame(Symbol, (new Symbol()).__proto__.constructor)
+ assertSame(Symbol, (new Symbol(Symbol())).__proto__.constructor)
assertSame(Symbol, Object(Symbol()).__proto__.constructor)
for (var i in symbols) {
assertSame(Symbol, symbols[i].__proto__.constructor)
@@ -100,26 +100,23 @@ function TestConstructor() {
TestConstructor()
-function TestValueOf() {
+function TestName() {
for (var i in symbols) {
- assertTrue(symbols[i] === symbols[i].valueOf())
- assertTrue(Symbol.prototype.valueOf.call(symbols[i]) === symbols[i])
+ var name = symbols[i].name
+ assertTrue(name === undefined || name === "66")
}
}
-TestValueOf()
+TestName()
function TestToString() {
for (var i in symbols) {
assertThrows(function() { String(symbols[i]) }, TypeError)
assertThrows(function() { symbols[i] + "" }, TypeError)
- assertTrue(isValidSymbolString(String(Object(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]))
+ 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()
@@ -159,16 +156,10 @@ function TestEquality() {
assertTrue(Object.is(symbols[i], symbols[i]))
assertTrue(symbols[i] === symbols[i])
assertTrue(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])
- assertFalse(Object(symbols[i]) === Object(symbols[i]))
- assertEquals(Object(symbols[i]).valueOf(), Object(symbols[i]).valueOf())
+ 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])
}
// All symbols should be distinct.
@@ -196,7 +187,7 @@ TestEquality()
function TestGet() {
for (var i in symbols) {
- assertTrue(isValidSymbolString(symbols[i].toString()))
+ assertThrows(function() { symbols[i].toString() }, TypeError)
assertEquals(symbols[i], symbols[i].valueOf())
assertEquals(undefined, symbols[i].a)
assertEquals(undefined, symbols[i]["a" + "b"])
@@ -210,7 +201,7 @@ TestGet()
function TestSet() {
for (var i in symbols) {
symbols[i].toString = 0
- assertTrue(isValidSymbolString(symbols[i].toString()))
+ assertThrows(function() { symbols[i].toString() }, TypeError)
symbols[i].valueOf = 0
assertEquals(symbols[i], symbols[i].valueOf())
symbols[i].a = 0
@@ -224,18 +215,6 @@ function TestSet() {
TestSet()
-// Test Symbol wrapping/boxing over non-builtins.
-Symbol.prototype.getThisProto = function () {
- return Object.getPrototypeOf(this);
-}
-function TestCall() {
- for (var i in symbols) {
- assertTrue(symbols[i].getThisProto() === Symbol.prototype)
- }
-}
-TestCall()
-
-
function TestCollections() {
var set = new Set
var map = new Map
@@ -330,7 +309,7 @@ function TestGetOwnPropertySymbols(obj) {
function TestKeyDescriptor(obj) {
for (var i in symbols) {
- var desc = Object.getOwnPropertyDescriptor(obj, symbols[i])
+ var desc = Object.getOwnPropertyDescriptor(obj, symbols[i]);
assertEquals(i|0, desc.value)
assertTrue(desc.configurable)
assertEquals(i % 2 == 0, desc.writable)
« no previous file with comments | « test/mjsunit/harmony/proxies.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698