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

Unified Diff: src/symbol.js

Issue 203243004: Implement ES6 symbol registry and predefined symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Test parameter types Created 6 years, 9 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
Index: src/symbol.js
diff --git a/src/symbol.js b/src/symbol.js
index 8cb19271835f609b269af987a6cbeae8723b4048..b0f2fcb83a822cf49f243f12d31e23dca479f61f 100644
--- a/src/symbol.js
+++ b/src/symbol.js
@@ -63,6 +63,46 @@ function SymbolValueOf() {
}
+function SymbolRegistry() {
Michael Starzinger 2014/03/19 10:15:25 nit: This naming makes it look like this is the im
rossberg 2014/03/20 10:40:13 Done.
+ var registry = %SymbolRegistry();
+ if (!('hook' in registry)) {
+ registry.hook = {__proto__: null};
+ registry.for = {__proto__: null};
+ registry.keyFor = {__proto__: null};
+ }
+ return registry;
+}
+
+
+function SymbolHook(key) {
Michael Starzinger 2014/03/19 10:15:25 nit: Likewise for GetSymbolHook here.
rossberg 2014/03/20 10:40:13 Renamed to InternalSymbol.
+ var registry = SymbolRegistry();
+ if (!(key in registry.for)) {
+ registry.hook[key] = %CreateSymbol(key);
+ }
+ return registry.hook[key];
+}
+
+
+function SymbolFor(key) {
+ key = TO_STRING_INLINE(key);
+ var registry = SymbolRegistry();
+ if (!(key in registry.for)) {
+ var symbol = %CreateSymbol(key);
+ registry.for[key] = symbol;
+ registry.keyFor[symbol] = key;
+ }
+ return registry.for[key];
+}
+
+
+function SymbolKeyFor(symbol) {
Michael Starzinger 2014/03/19 10:15:25 Is it specified what "Symbol.keyFor(Symbol.create)
rossberg 2014/03/20 10:40:13 Simply undefined, since it's not in the (public) r
+ if (!IS_SYMBOL(symbol)) {
+ throw MakeTypeError("not_a_symbol", ["Symbol.keyFor", symbol]);
sof 2014/03/19 09:06:47 Looks like 'symbol' (%1) isn't used in the not_a_s
rossberg 2014/03/20 10:40:13 Done.
+ }
+ return SymbolRegistry().keyFor[symbol];
+}
+
+
// ES6 19.1.2.8
function ObjectGetOwnPropertySymbols(obj) {
if (!IS_SPEC_OBJECT(obj)) {
@@ -78,12 +118,36 @@ function ObjectGetOwnPropertySymbols(obj) {
//-------------------------------------------------------------------
+var symbolCreate = SymbolHook("@@create");
sof 2014/03/19 09:06:47 Just trying to understand.. where is the implicit
rossberg 2014/03/20 10:40:13 Hm, I'm not sure what you are asking. The well-kno
sof 2014/03/20 10:49:06 ok, good - thought not. But the lookup in Internal
rossberg 2014/03/20 11:05:20 Because that's a bug. :) Thanks for pointing out!
+var symbolHasInstance = SymbolHook("@@hasInstance");
+var symbolIsConcatSpreadable = SymbolHook("@@isConcatSpreadable");
+var symbolIsRegExp = SymbolHook("@@isRegExp");
+var symbolIterator = SymbolHook("@@iterator");
+var symbolToStringTag = SymbolHook("@@toStringTag");
+var symbolUnscopables = SymbolHook("@@unscopables");
+
+
+//-------------------------------------------------------------------
+
function SetUpSymbol() {
%CheckIsBootstrapping();
%SetCode($Symbol, SymbolConstructor);
%FunctionSetPrototype($Symbol, new $Object());
+ %SetProperty($Symbol, "create", symbolCreate, DONT_ENUM);
+ %SetProperty($Symbol, "hasInstance", symbolHasInstance, DONT_ENUM);
+ %SetProperty($Symbol, "isConcatSpreadable",
+ symbolIsConcatSpreadable, DONT_ENUM);
+ %SetProperty($Symbol, "isRegExp", symbolIsRegExp, DONT_ENUM);
+ %SetProperty($Symbol, "iterator", symbolIterator, DONT_ENUM);
+ %SetProperty($Symbol, "toStringTag", symbolToStringTag, DONT_ENUM);
+ %SetProperty($Symbol, "unscopables", symbolUnscopables, DONT_ENUM);
+ InstallFunctions($Symbol, DONT_ENUM, $Array(
+ "for", SymbolFor,
+ "keyFor", SymbolKeyFor
+ ));
+
%SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
InstallFunctions($Symbol.prototype, DONT_ENUM, $Array(
"toString", SymbolToString,

Powered by Google App Engine
This is Rietveld 408576698