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 GetSymbolRegistry() { | |
| 67 var registry = %SymbolRegistry(); | |
| 68 if (!('internal' in registry)) { | |
|
arv (Not doing code reviews)
2014/03/22 17:15:49
Maybe this could have been
if (IS_UNDEFINED(regi
rossberg
2014/03/24 10:25:53
Done.
| |
| 69 registry.internal = {__proto__: null}; | |
| 70 registry.for = {__proto__: null}; | |
| 71 registry.keyFor = {__proto__: null}; | |
| 72 } | |
| 73 return registry; | |
| 74 } | |
| 75 | |
| 76 | |
| 77 function InternalSymbol(key) { | |
| 78 var registry = GetSymbolRegistry(); | |
| 79 if (!(key in registry.internal)) { | |
| 80 registry.internal[key] = %CreateSymbol(key); | |
| 81 } | |
| 82 return registry.internal[key]; | |
| 83 } | |
| 84 | |
| 85 | |
| 86 function SymbolFor(key) { | |
| 87 key = TO_STRING_INLINE(key); | |
| 88 var registry = GetSymbolRegistry(); | |
| 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) { | |
| 99 if (!IS_SYMBOL(symbol)) { | |
| 100 throw MakeTypeError("not_a_symbol", [symbol]); | |
| 101 } | |
| 102 return GetSymbolRegistry().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 = InternalSymbol("@@create"); | |
|
arv (Not doing code reviews)
2014/03/22 17:15:49
Doesn't '@' in a property name cause the object to
rossberg
2014/03/24 10:25:53
Objects should be completely ignorant to symbol de
arv (Not doing code reviews)
2014/03/24 15:18:57
You use the key on line 80. If we have a non ident
rossberg
2014/03/24 15:37:56
You're right. The dot will have the same effect, t
| |
| 122 var symbolHasInstance = InternalSymbol("@@hasInstance"); | |
| 123 var symbolIsConcatSpreadable = InternalSymbol("@@isConcatSpreadable"); | |
| 124 var symbolIsRegExp = InternalSymbol("@@isRegExp"); | |
| 125 var symbolIterator = InternalSymbol("@@iterator"); | |
| 126 var symbolToStringTag = InternalSymbol("@@toStringTag"); | |
| 127 var symbolUnscopables = InternalSymbol("@@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); | |
|
arv (Not doing code reviews)
2014/03/22 17:15:49
Also, non writable, non configurable.
http://peop
rossberg
2014/03/24 10:25:53
Done.
| |
| 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 |