2013-03-01 13:28:55 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2016-03-11 18:19:05 +00:00
|
|
|
// Flags: --expose-gc --allow-natives-syntax
|
2013-03-01 13:28:55 +00:00
|
|
|
|
|
|
|
var symbols = []
|
|
|
|
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
|
|
|
|
// 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.
|
2013-03-01 13:28:55 +00:00
|
|
|
function TestNew() {
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
function indirectSymbol() { return Symbol() }
|
|
|
|
function indirect() { return indirectSymbol() }
|
2013-03-22 16:33:50 +00:00
|
|
|
for (var i = 0; i < 2; ++i) {
|
|
|
|
for (var j = 0; j < 5; ++j) {
|
|
|
|
symbols.push(Symbol())
|
2013-03-22 16:51:28 +00:00
|
|
|
symbols.push(Symbol(undefined))
|
|
|
|
symbols.push(Symbol("66"))
|
|
|
|
symbols.push(Symbol(66))
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
symbols.push(Symbol().valueOf())
|
|
|
|
symbols.push(indirect())
|
2013-03-22 16:33:50 +00:00
|
|
|
}
|
|
|
|
%OptimizeFunctionOnNextCall(indirect)
|
|
|
|
indirect() // Call once before GC throws away type feedback.
|
|
|
|
gc() // Promote existing symbols and then allocate some more.
|
2013-03-01 13:28:55 +00:00
|
|
|
}
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertThrows(function () { Symbol(Symbol()) }, TypeError)
|
|
|
|
assertThrows(function () { new Symbol(66) }, TypeError)
|
2013-03-01 13:28:55 +00:00
|
|
|
}
|
|
|
|
TestNew()
|
|
|
|
|
|
|
|
|
|
|
|
function TestType() {
|
|
|
|
for (var i in symbols) {
|
2013-03-22 16:33:50 +00:00
|
|
|
assertEquals("symbol", typeof symbols[i])
|
|
|
|
assertTrue(typeof symbols[i] === "symbol")
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
assertFalse(%SymbolIsPrivate(symbols[i]))
|
2013-03-01 13:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TestType()
|
|
|
|
|
|
|
|
|
2013-03-22 16:33:50 +00:00
|
|
|
function TestPrototype() {
|
|
|
|
assertSame(Object.prototype, Symbol.prototype.__proto__)
|
|
|
|
assertSame(Symbol.prototype, Symbol().__proto__)
|
|
|
|
assertSame(Symbol.prototype, Object(Symbol()).__proto__)
|
|
|
|
for (var i in symbols) {
|
|
|
|
assertSame(Symbol.prototype, symbols[i].__proto__)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestPrototype()
|
|
|
|
|
|
|
|
|
2013-04-11 12:27:55 +00:00
|
|
|
function TestConstructor() {
|
2016-04-05 10:56:16 +00:00
|
|
|
assertEquals(0, Symbol.length);
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertSame(Function.prototype, Symbol.__proto__)
|
2013-04-11 12:27:55 +00:00
|
|
|
assertFalse(Object === Symbol.prototype.constructor)
|
|
|
|
assertFalse(Symbol === Object.prototype.constructor)
|
|
|
|
assertSame(Symbol, Symbol.prototype.constructor)
|
|
|
|
assertSame(Symbol, Symbol().__proto__.constructor)
|
|
|
|
assertSame(Symbol, Object(Symbol()).__proto__.constructor)
|
|
|
|
for (var i in symbols) {
|
|
|
|
assertSame(Symbol, symbols[i].__proto__.constructor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestConstructor()
|
|
|
|
|
|
|
|
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
function TestValueOf() {
|
2013-03-22 16:51:28 +00:00
|
|
|
for (var i in symbols) {
|
2014-07-16 09:26:11 +00:00
|
|
|
assertTrue(symbols[i] === Object(symbols[i]).valueOf())
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertTrue(symbols[i] === symbols[i].valueOf())
|
2014-07-16 09:26:11 +00:00
|
|
|
assertTrue(Symbol.prototype.valueOf.call(Object(symbols[i])) === symbols[i])
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertTrue(Symbol.prototype.valueOf.call(symbols[i]) === symbols[i])
|
2013-03-22 16:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
TestValueOf()
|
2013-03-22 16:51:28 +00:00
|
|
|
|
|
|
|
|
2013-03-22 16:33:50 +00:00
|
|
|
function TestToString() {
|
|
|
|
for (var i in symbols) {
|
2014-09-12 16:17:27 +00:00
|
|
|
assertThrows(function() { new String(symbols[i]) }, TypeError)
|
|
|
|
assertEquals(symbols[i].toString(), String(symbols[i]))
|
2013-03-22 16:33:50 +00:00
|
|
|
assertThrows(function() { symbols[i] + "" }, TypeError)
|
2014-07-16 09:26:11 +00:00
|
|
|
assertThrows(function() { String(Object(symbols[i])) }, TypeError)
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
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]))
|
2013-03-22 16:33:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TestToString()
|
|
|
|
|
|
|
|
|
|
|
|
function TestToBoolean() {
|
|
|
|
for (var i in symbols) {
|
2014-07-16 09:26:11 +00:00
|
|
|
assertTrue(Boolean(Object(symbols[i])))
|
|
|
|
assertFalse(!Object(symbols[i]))
|
2013-03-22 16:33:50 +00:00
|
|
|
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) {
|
2014-07-16 09:26:11 +00:00
|
|
|
assertThrows(function() { Number(Object(symbols[i])) }, TypeError)
|
|
|
|
assertThrows(function() { +Object(symbols[i]) }, TypeError)
|
2014-08-11 19:24:05 +00:00
|
|
|
assertThrows(function() { Number(symbols[i]) }, TypeError)
|
|
|
|
assertThrows(function() { symbols[i] + 0 }, TypeError)
|
2013-03-22 16:33:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TestToNumber()
|
|
|
|
|
|
|
|
|
2013-03-01 13:28:55 +00:00
|
|
|
function TestEquality() {
|
2013-04-03 17:06:22 +00:00
|
|
|
// Every symbol should equal itself, and non-strictly equal its wrapper.
|
2013-03-01 13:28:55 +00:00
|
|
|
for (var i in symbols) {
|
|
|
|
assertSame(symbols[i], symbols[i])
|
|
|
|
assertEquals(symbols[i], symbols[i])
|
|
|
|
assertTrue(Object.is(symbols[i], symbols[i]))
|
|
|
|
assertTrue(symbols[i] === symbols[i])
|
|
|
|
assertTrue(symbols[i] == symbols[i])
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertFalse(symbols[i] === Object(symbols[i]))
|
|
|
|
assertFalse(Object(symbols[i]) === symbols[i])
|
2015-10-27 20:20:08 +00:00
|
|
|
assertTrue(symbols[i] == Object(symbols[i]))
|
|
|
|
assertTrue(Object(symbols[i]) == symbols[i])
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
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())
|
2013-03-01 13:28:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// All symbols should be distinct.
|
|
|
|
for (var i = 0; i < symbols.length; ++i) {
|
|
|
|
for (var j = i + 1; j < symbols.length; ++j) {
|
|
|
|
assertFalse(Object.is(symbols[i], symbols[j]))
|
|
|
|
assertFalse(symbols[i] === symbols[j])
|
|
|
|
assertFalse(symbols[i] == symbols[j])
|
|
|
|
}
|
2013-04-03 17:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Symbols should not be equal to any other value (and the test terminates).
|
|
|
|
var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}]
|
|
|
|
for (var i in symbols) {
|
|
|
|
for (var j in values) {
|
|
|
|
assertFalse(symbols[i] === values[j])
|
|
|
|
assertFalse(values[j] === symbols[i])
|
|
|
|
assertFalse(symbols[i] == values[j])
|
|
|
|
assertFalse(values[j] == symbols[i])
|
|
|
|
}
|
2013-03-01 13:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TestEquality()
|
|
|
|
|
|
|
|
|
|
|
|
function TestGet() {
|
|
|
|
for (var i in symbols) {
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertTrue(isValidSymbolString(symbols[i].toString()))
|
2013-03-22 16:33:50 +00:00
|
|
|
assertEquals(symbols[i], symbols[i].valueOf())
|
2013-03-01 13:28:55 +00:00
|
|
|
assertEquals(undefined, symbols[i].a)
|
|
|
|
assertEquals(undefined, symbols[i]["a" + "b"])
|
|
|
|
assertEquals(undefined, symbols[i]["" + "1"])
|
|
|
|
assertEquals(undefined, symbols[i][62])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestGet()
|
|
|
|
|
|
|
|
|
|
|
|
function TestSet() {
|
|
|
|
for (var i in symbols) {
|
|
|
|
symbols[i].toString = 0
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
assertTrue(isValidSymbolString(symbols[i].toString()))
|
2013-03-22 16:33:50 +00:00
|
|
|
symbols[i].valueOf = 0
|
|
|
|
assertEquals(symbols[i], symbols[i].valueOf())
|
2013-03-01 13:28:55 +00:00
|
|
|
symbols[i].a = 0
|
|
|
|
assertEquals(undefined, symbols[i].a)
|
|
|
|
symbols[i]["a" + "b"] = 0
|
|
|
|
assertEquals(undefined, symbols[i]["a" + "b"])
|
|
|
|
symbols[i][62] = 0
|
|
|
|
assertEquals(undefined, symbols[i][62])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestSet()
|
|
|
|
|
|
|
|
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
// 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()
|
|
|
|
|
|
|
|
|
2013-03-05 17:24:08 +00:00
|
|
|
function TestCollections() {
|
|
|
|
var set = new Set
|
2013-03-04 15:00:57 +00:00
|
|
|
var map = new Map
|
2013-03-01 13:28:55 +00:00
|
|
|
for (var i in symbols) {
|
2013-03-05 17:24:08 +00:00
|
|
|
set.add(symbols[i])
|
2013-03-01 13:28:55 +00:00
|
|
|
map.set(symbols[i], i)
|
|
|
|
}
|
2013-03-05 17:24:08 +00:00
|
|
|
assertEquals(symbols.length, set.size)
|
|
|
|
assertEquals(symbols.length, map.size)
|
2013-03-01 13:28:55 +00:00
|
|
|
for (var i in symbols) {
|
2013-03-05 17:24:08 +00:00
|
|
|
assertTrue(set.has(symbols[i]))
|
2013-03-01 13:28:55 +00:00
|
|
|
assertTrue(map.has(symbols[i]))
|
|
|
|
assertEquals(i, map.get(symbols[i]))
|
|
|
|
}
|
2013-03-05 17:24:08 +00:00
|
|
|
for (var i in symbols) {
|
|
|
|
assertTrue(set.delete(symbols[i]))
|
|
|
|
assertTrue(map.delete(symbols[i]))
|
|
|
|
}
|
|
|
|
assertEquals(0, set.size)
|
|
|
|
assertEquals(0, map.size)
|
2013-03-01 13:28:55 +00:00
|
|
|
}
|
2013-03-05 17:24:08 +00:00
|
|
|
TestCollections()
|
2013-03-04 15:00:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function TestKeySet(obj) {
|
2013-03-28 12:01:46 +00:00
|
|
|
assertTrue(%HasFastProperties(obj))
|
2013-03-04 15:00:57 +00:00
|
|
|
// Set the even symbols via assignment.
|
|
|
|
for (var i = 0; i < symbols.length; i += 2) {
|
|
|
|
obj[symbols[i]] = i
|
2013-03-28 12:01:46 +00:00
|
|
|
// Object should remain in fast mode until too many properties were added.
|
|
|
|
assertTrue(%HasFastProperties(obj) || i >= 30)
|
2013-03-04 15:00:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TestKeyDefine(obj) {
|
|
|
|
// Set the odd symbols via defineProperty (as non-enumerable).
|
|
|
|
for (var i = 1; i < symbols.length; i += 2) {
|
|
|
|
Object.defineProperty(obj, symbols[i], {value: i, configurable: true})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TestKeyGet(obj) {
|
|
|
|
var obj2 = Object.create(obj)
|
|
|
|
for (var i in symbols) {
|
|
|
|
assertEquals(i|0, obj[symbols[i]])
|
|
|
|
assertEquals(i|0, obj2[symbols[i]])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-09 15:57:30 +00:00
|
|
|
function TestKeyHas(obj) {
|
2013-03-04 15:00:57 +00:00
|
|
|
for (var i in symbols) {
|
|
|
|
assertTrue(symbols[i] in obj)
|
|
|
|
assertTrue(Object.hasOwnProperty.call(obj, symbols[i]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TestKeyEnum(obj) {
|
2013-03-06 13:55:21 +00:00
|
|
|
for (var name in obj) {
|
2013-03-22 17:27:44 +00:00
|
|
|
assertEquals("string", typeof name)
|
2013-03-04 15:00:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-07 15:43:47 +00:00
|
|
|
function TestKeyNames(obj) {
|
2013-03-06 13:55:21 +00:00
|
|
|
assertEquals(0, Object.keys(obj).length)
|
2013-03-07 15:43:47 +00:00
|
|
|
|
|
|
|
var names = Object.getOwnPropertyNames(obj)
|
2013-03-22 17:27:44 +00:00
|
|
|
for (var i in names) {
|
|
|
|
assertEquals("string", typeof names[i])
|
2013-03-07 15:43:47 +00:00
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-09 15:57:30 +00:00
|
|
|
function TestGetOwnPropertySymbols(obj) {
|
|
|
|
var syms = Object.getOwnPropertySymbols(obj)
|
|
|
|
assertEquals(syms.length, symbols.length)
|
|
|
|
for (var i in syms) {
|
|
|
|
assertEquals("symbol", typeof syms[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
function TestKeyDescriptor(obj) {
|
|
|
|
for (var i in symbols) {
|
Upgrade Symbol implementation to match current ES6 behavior.
Refresh the implementation of Symbols to catch up with what the
specification now mandates:
* The global Symbol() function manufactures new Symbol values,
optionally with a string description attached.
* Invoking Symbol() as a constructor will now throw.
* ToString() over Symbol values still throws, and
Object.prototype.toString() stringifies like before.
* A Symbol value is wrapped in a Symbol object either implicitly if
it is the receiver, or explicitly done via Object(symbolValue) or
(new Object(symbolValue).)
* The Symbol.prototype.toString() method no longer throws on Symbol
wrapper objects (nor Symbol values.) Ditto for Symbol.prototype.valueOf().
* Symbol.prototype.toString() stringifies as "Symbol("<description>"),
valueOf() returns the wrapper's Symbol value.
* ToPrimitive() over Symbol wrapper objects now throws.
Overall, this provides a stricter separation between Symbol values and
wrapper objects than before, and the explicit fetching out of the
description (nee name) via the "name" property is no longer supported
(by the spec nor the implementation.)
Adjusted existing Symbol test files to fit current, adding some extra
tests for new/changed behavior.
LOG=N
R=arv@chromium.org, rossberg@chromium.org, arv, rossberg
BUG=v8:3053
Review URL: https://codereview.chromium.org/118553003
Patch from Sigbjorn Finne <sigbjornf@opera.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19490 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-02-19 14:19:42 +00:00
|
|
|
var desc = Object.getOwnPropertyDescriptor(obj, symbols[i])
|
2013-03-04 15:00:57 +00:00
|
|
|
assertEquals(i|0, desc.value)
|
|
|
|
assertTrue(desc.configurable)
|
|
|
|
assertEquals(i % 2 == 0, desc.writable)
|
|
|
|
assertEquals(i % 2 == 0, desc.enumerable)
|
|
|
|
assertEquals(i % 2 == 0,
|
|
|
|
Object.prototype.propertyIsEnumerable.call(obj, symbols[i]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TestKeyDelete(obj) {
|
|
|
|
for (var i in symbols) {
|
|
|
|
delete obj[symbols[i]]
|
|
|
|
}
|
|
|
|
for (var i in symbols) {
|
|
|
|
assertEquals(undefined, Object.getOwnPropertyDescriptor(obj, symbols[i]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-25 08:30:37 +00:00
|
|
|
var objs = [{}, [], Object.create({}), Object(1), new Map, function(){}]
|
2013-03-04 15:00:57 +00:00
|
|
|
|
|
|
|
for (var i in objs) {
|
|
|
|
var obj = objs[i]
|
|
|
|
TestKeySet(obj)
|
|
|
|
TestKeyDefine(obj)
|
|
|
|
TestKeyGet(obj)
|
|
|
|
TestKeyHas(obj)
|
|
|
|
TestKeyEnum(obj)
|
2013-03-07 15:43:47 +00:00
|
|
|
TestKeyNames(obj)
|
2014-01-09 15:57:30 +00:00
|
|
|
TestGetOwnPropertySymbols(obj)
|
2013-03-04 15:00:57 +00:00
|
|
|
TestKeyDescriptor(obj)
|
|
|
|
TestKeyDelete(obj)
|
|
|
|
}
|
2013-03-28 13:52:31 +00:00
|
|
|
|
|
|
|
|
2014-07-14 14:00:33 +00:00
|
|
|
function TestDefineProperties() {
|
|
|
|
var properties = {}
|
|
|
|
for (var i in symbols) {
|
|
|
|
Object.defineProperty(
|
|
|
|
properties, symbols[i], {value: {value: i}, enumerable: i % 2 === 0})
|
|
|
|
}
|
|
|
|
var o = Object.defineProperties({}, properties)
|
|
|
|
for (var i in symbols) {
|
|
|
|
assertEquals(i % 2 === 0, symbols[i] in o)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestDefineProperties()
|
|
|
|
|
|
|
|
|
|
|
|
function TestCreate() {
|
|
|
|
var properties = {}
|
|
|
|
for (var i in symbols) {
|
|
|
|
Object.defineProperty(
|
|
|
|
properties, symbols[i], {value: {value: i}, enumerable: i % 2 === 0})
|
|
|
|
}
|
|
|
|
var o = Object.create(Object.prototype, properties)
|
|
|
|
for (var i in symbols) {
|
|
|
|
assertEquals(i % 2 === 0, symbols[i] in o)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestCreate()
|
|
|
|
|
|
|
|
|
2013-03-28 13:52:31 +00:00
|
|
|
function TestCachedKeyAfterScavenge() {
|
|
|
|
gc();
|
|
|
|
// Keyed property lookup are cached. Hereby we assume that the keys are
|
|
|
|
// tenured, so that we only have to clear the cache between mark compacts,
|
|
|
|
// but not between scavenges. This must also apply for symbol keys.
|
|
|
|
var key = Symbol("key");
|
|
|
|
var a = {};
|
|
|
|
a[key] = "abc";
|
|
|
|
|
2013-11-26 11:32:39 +00:00
|
|
|
for (var i = 0; i < 100000; i++) {
|
2013-03-28 13:52:31 +00:00
|
|
|
a[key] += "a"; // Allocations cause a scavenge.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestCachedKeyAfterScavenge();
|
2014-01-09 15:57:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
2014-03-24 15:45:52 +00:00
|
|
|
function TestWellKnown() {
|
|
|
|
var symbols = [
|
2016-02-11 11:58:47 +00:00
|
|
|
"hasInstance",
|
2014-08-06 09:31:21 +00:00
|
|
|
// TODO(rossberg): reactivate once implemented.
|
2016-02-11 11:58:47 +00:00
|
|
|
// "isConcatSpreadable", "isRegExp",
|
2014-08-08 11:42:59 +00:00
|
|
|
"iterator", /* "toStringTag", */ "unscopables"
|
2014-03-24 15:45:52 +00:00
|
|
|
]
|
2014-03-20 16:13:09 +00:00
|
|
|
|
2014-03-24 15:45:52 +00:00
|
|
|
for (var i in symbols) {
|
|
|
|
var name = symbols[i]
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(Symbol, name)
|
|
|
|
assertSame("symbol", typeof desc.value)
|
|
|
|
assertSame("Symbol(Symbol." + name + ")", desc.value.toString())
|
|
|
|
assertFalse(desc.writable)
|
|
|
|
assertFalse(desc.configurable)
|
|
|
|
assertFalse(desc.enumerable)
|
|
|
|
|
|
|
|
assertFalse(Symbol.for("Symbol." + name) === desc.value)
|
|
|
|
assertTrue(Symbol.keyFor(desc.value) === undefined)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestWellKnown()
|
|
|
|
|
|
|
|
|
|
|
|
function TestRegistry() {
|
2014-03-20 16:13:09 +00:00
|
|
|
var symbol1 = Symbol.for("x1")
|
|
|
|
var symbol2 = Symbol.for("x2")
|
|
|
|
assertFalse(symbol1 === symbol2)
|
|
|
|
|
|
|
|
assertSame(symbol1, Symbol.for("x1"))
|
|
|
|
assertSame(symbol2, Symbol.for("x2"))
|
|
|
|
assertSame("x1", Symbol.keyFor(symbol1))
|
|
|
|
assertSame("x2", Symbol.keyFor(symbol2))
|
|
|
|
|
|
|
|
assertSame(Symbol.for("1"), Symbol.for(1))
|
|
|
|
assertThrows(function() { Symbol.keyFor("bla") }, TypeError)
|
|
|
|
assertThrows(function() { Symbol.keyFor({}) }, TypeError)
|
|
|
|
|
|
|
|
var realm = Realm.create()
|
|
|
|
assertFalse(Symbol === Realm.eval(realm, "Symbol"))
|
|
|
|
assertFalse(Symbol.for === Realm.eval(realm, "Symbol.for"))
|
|
|
|
assertFalse(Symbol.keyFor === Realm.eval(realm, "Symbol.keyFor"))
|
|
|
|
assertSame(Symbol.create, Realm.eval(realm, "Symbol.create"))
|
|
|
|
assertSame(Symbol.iterator, Realm.eval(realm, "Symbol.iterator"))
|
|
|
|
|
|
|
|
assertSame(symbol1, Realm.eval(realm, "Symbol.for")("x1"))
|
|
|
|
assertSame(symbol1, Realm.eval(realm, "Symbol.for('x1')"))
|
|
|
|
assertSame("x1", Realm.eval(realm, "Symbol.keyFor")(symbol1))
|
|
|
|
Realm.shared = symbol1
|
|
|
|
assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)"))
|
|
|
|
|
|
|
|
var symbol3 = Realm.eval(realm, "Symbol.for('x3')")
|
|
|
|
assertFalse(symbol1 === symbol3)
|
|
|
|
assertFalse(symbol2 === symbol3)
|
|
|
|
assertSame(symbol3, Symbol.for("x3"))
|
|
|
|
assertSame("x3", Symbol.keyFor(symbol3))
|
2014-01-09 15:57:30 +00:00
|
|
|
}
|
2014-03-20 16:13:09 +00:00
|
|
|
TestRegistry()
|
2014-10-15 14:01:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
function TestGetOwnPropertySymbolsOnPrimitives() {
|
|
|
|
assertEquals(Object.getOwnPropertySymbols(true), []);
|
|
|
|
assertEquals(Object.getOwnPropertySymbols(5000), []);
|
|
|
|
assertEquals(Object.getOwnPropertySymbols("OK"), []);
|
|
|
|
}
|
|
|
|
TestGetOwnPropertySymbolsOnPrimitives();
|
2015-05-05 14:11:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
function TestComparison() {
|
2015-05-06 15:04:39 +00:00
|
|
|
function lt() { var a = Symbol(); var b = Symbol(); a < b; }
|
|
|
|
function gt() { var a = Symbol(); var b = Symbol(); a > b; }
|
|
|
|
function le() { var a = Symbol(); var b = Symbol(); a <= b; }
|
|
|
|
function ge() { var a = Symbol(); var b = Symbol(); a >= b; }
|
|
|
|
function lt_same() { var a = Symbol(); a < a; }
|
|
|
|
function gt_same() { var a = Symbol(); a > a; }
|
|
|
|
function le_same() { var a = Symbol(); a <= a; }
|
|
|
|
function ge_same() { var a = Symbol(); a >= a; }
|
|
|
|
|
|
|
|
var throwFuncs = [lt, gt, le, ge, lt_same, gt_same, le_same, ge_same];
|
|
|
|
|
|
|
|
for (var f of throwFuncs) {
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
}
|
2015-05-05 14:11:49 +00:00
|
|
|
}
|
|
|
|
TestComparison();
|
2015-12-02 07:31:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Make sure that throws occur in the context of the Symbol function.
|
|
|
|
function TestContext() {
|
|
|
|
var r = Realm.create();
|
|
|
|
var rSymbol = Realm.eval(r, "Symbol");
|
|
|
|
var rError = Realm.eval(r, "TypeError");
|
|
|
|
|
|
|
|
function verifier(symbol, error) {
|
|
|
|
try {
|
|
|
|
new symbol();
|
|
|
|
} catch(e) {
|
|
|
|
return e.__proto__ === error.__proto__;
|
|
|
|
}
|
|
|
|
assertTrue(false); // should never get here.
|
|
|
|
}
|
|
|
|
|
|
|
|
assertTrue(verifier(Symbol, TypeError()));
|
|
|
|
assertTrue(verifier(rSymbol, rError()));
|
|
|
|
assertFalse(verifier(Symbol, rError()));
|
|
|
|
assertFalse(verifier(rSymbol, TypeError()));
|
|
|
|
}
|
|
|
|
TestContext();
|
2015-12-02 08:43:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
function TestStringify(expected, input) {
|
|
|
|
assertEquals(expected, JSON.stringify(input));
|
2016-05-20 07:56:49 +00:00
|
|
|
assertEquals(expected, JSON.stringify(input, (key, value) => value));
|
|
|
|
assertEquals(JSON.stringify(input, null, "="),
|
|
|
|
JSON.stringify(input, (key, value) => value, "="));
|
2015-12-02 08:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestStringify(undefined, Symbol("a"));
|
|
|
|
TestStringify('[{}]', [Object(Symbol())]);
|
|
|
|
var symbol_wrapper = Object(Symbol("a"))
|
|
|
|
TestStringify('{}', symbol_wrapper);
|
|
|
|
symbol_wrapper.a = 1;
|
|
|
|
TestStringify('{"a":1}', symbol_wrapper);
|