Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 function SymbolValueOf() { | 57 function SymbolValueOf() { |
| 58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { | 58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { |
| 59 throw MakeTypeError( | 59 throw MakeTypeError( |
| 60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); | 60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); |
| 61 } | 61 } |
| 62 return %_ValueOf(this); | 62 return %_ValueOf(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 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.
| |
| 67 var registry = %SymbolRegistry(); | |
| 68 if (!('hook' in registry)) { | |
| 69 registry.hook = {__proto__: null}; | |
| 70 registry.for = {__proto__: null}; | |
| 71 registry.keyFor = {__proto__: null}; | |
| 72 } | |
| 73 return registry; | |
| 74 } | |
| 75 | |
| 76 | |
| 77 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.
| |
| 78 var registry = SymbolRegistry(); | |
| 79 if (!(key in registry.for)) { | |
| 80 registry.hook[key] = %CreateSymbol(key); | |
| 81 } | |
| 82 return registry.hook[key]; | |
| 83 } | |
| 84 | |
| 85 | |
| 86 function SymbolFor(key) { | |
| 87 key = TO_STRING_INLINE(key); | |
| 88 var registry = SymbolRegistry(); | |
| 89 if (!(key in registry.for)) { | |
| 90 var symbol = %CreateSymbol(key); | |
| 91 registry.for[key] = symbol; | |
| 92 registry.keyFor[symbol] = key; | |
| 93 } | |
| 94 return registry.for[key]; | |
| 95 } | |
| 96 | |
| 97 | |
| 98 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
| |
| 99 if (!IS_SYMBOL(symbol)) { | |
| 100 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.
| |
| 101 } | |
| 102 return SymbolRegistry().keyFor[symbol]; | |
| 103 } | |
| 104 | |
| 105 | |
| 66 // ES6 19.1.2.8 | 106 // ES6 19.1.2.8 |
| 67 function ObjectGetOwnPropertySymbols(obj) { | 107 function ObjectGetOwnPropertySymbols(obj) { |
| 68 if (!IS_SPEC_OBJECT(obj)) { | 108 if (!IS_SPEC_OBJECT(obj)) { |
| 69 throw MakeTypeError("called_on_non_object", | 109 throw MakeTypeError("called_on_non_object", |
| 70 ["Object.getOwnPropertySymbols"]); | 110 ["Object.getOwnPropertySymbols"]); |
| 71 } | 111 } |
| 72 | 112 |
| 73 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | 113 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
| 74 | 114 |
| 75 return ObjectGetOwnPropertyKeys(obj, true); | 115 return ObjectGetOwnPropertyKeys(obj, true); |
| 76 } | 116 } |
| 77 | 117 |
| 78 | 118 |
| 79 //------------------------------------------------------------------- | 119 //------------------------------------------------------------------- |
| 80 | 120 |
| 121 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!
| |
| 122 var symbolHasInstance = SymbolHook("@@hasInstance"); | |
| 123 var symbolIsConcatSpreadable = SymbolHook("@@isConcatSpreadable"); | |
| 124 var symbolIsRegExp = SymbolHook("@@isRegExp"); | |
| 125 var symbolIterator = SymbolHook("@@iterator"); | |
| 126 var symbolToStringTag = SymbolHook("@@toStringTag"); | |
| 127 var symbolUnscopables = SymbolHook("@@unscopables"); | |
| 128 | |
| 129 | |
| 130 //------------------------------------------------------------------- | |
| 131 | |
| 81 function SetUpSymbol() { | 132 function SetUpSymbol() { |
| 82 %CheckIsBootstrapping(); | 133 %CheckIsBootstrapping(); |
| 83 | 134 |
| 84 %SetCode($Symbol, SymbolConstructor); | 135 %SetCode($Symbol, SymbolConstructor); |
| 85 %FunctionSetPrototype($Symbol, new $Object()); | 136 %FunctionSetPrototype($Symbol, new $Object()); |
| 86 | 137 |
| 138 %SetProperty($Symbol, "create", symbolCreate, DONT_ENUM); | |
| 139 %SetProperty($Symbol, "hasInstance", symbolHasInstance, DONT_ENUM); | |
| 140 %SetProperty($Symbol, "isConcatSpreadable", | |
| 141 symbolIsConcatSpreadable, DONT_ENUM); | |
| 142 %SetProperty($Symbol, "isRegExp", symbolIsRegExp, DONT_ENUM); | |
| 143 %SetProperty($Symbol, "iterator", symbolIterator, DONT_ENUM); | |
| 144 %SetProperty($Symbol, "toStringTag", symbolToStringTag, DONT_ENUM); | |
| 145 %SetProperty($Symbol, "unscopables", symbolUnscopables, DONT_ENUM); | |
| 146 InstallFunctions($Symbol, DONT_ENUM, $Array( | |
| 147 "for", SymbolFor, | |
| 148 "keyFor", SymbolKeyFor | |
| 149 )); | |
| 150 | |
| 87 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); | 151 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); |
| 88 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( | 152 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( |
| 89 "toString", SymbolToString, | 153 "toString", SymbolToString, |
| 90 "valueOf", SymbolValueOf | 154 "valueOf", SymbolValueOf |
| 91 )); | 155 )); |
| 92 } | 156 } |
| 93 | 157 |
| 94 SetUpSymbol(); | 158 SetUpSymbol(); |
| 95 | 159 |
| 96 | 160 |
| 97 function ExtendObject() { | 161 function ExtendObject() { |
| 98 %CheckIsBootstrapping(); | 162 %CheckIsBootstrapping(); |
| 99 | 163 |
| 100 InstallFunctions($Object, DONT_ENUM, $Array( | 164 InstallFunctions($Object, DONT_ENUM, $Array( |
| 101 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols | 165 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols |
| 102 )); | 166 )); |
| 103 } | 167 } |
| 104 | 168 |
| 105 ExtendObject(); | 169 ExtendObject(); |
| OLD | NEW |