| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Expects following symbols to be set in the bootstrapper during genesis: | 5 // Expects following symbols to be set in the bootstrapper during genesis: |
| 6 // - symbolHasInstance | 6 // - symbolHasInstance |
| 7 // - symbolIsConcatSpreadable | 7 // - symbolIsConcatSpreadable |
| 8 // - symbolIsRegExp | 8 // - symbolIsRegExp |
| 9 // - symbolIterator | 9 // - symbolIterator |
| 10 // - symbolToStringTag | 10 // - symbolToStringTag |
| 11 // - symbolUnscopables | 11 // - symbolUnscopables |
| 12 | 12 |
| 13 var $symbolToString; | 13 var $symbolToString; |
| 14 | 14 |
| 15 (function(global, utils) { | 15 (function(global, utils) { |
| 16 | 16 |
| 17 "use strict"; | 17 "use strict"; |
| 18 | 18 |
| 19 %CheckIsBootstrapping(); | 19 %CheckIsBootstrapping(); |
| 20 | 20 |
| 21 // ------------------------------------------------------------------- |
| 22 // Imports |
| 23 |
| 21 var GlobalObject = global.Object; | 24 var GlobalObject = global.Object; |
| 22 var GlobalSymbol = global.Symbol; | 25 var GlobalSymbol = global.Symbol; |
| 23 | 26 |
| 27 var ObjectGetOwnPropertyKeys; |
| 28 |
| 29 utils.Import(function(from) { |
| 30 ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys; |
| 31 }); |
| 32 |
| 24 // ------------------------------------------------------------------- | 33 // ------------------------------------------------------------------- |
| 25 | 34 |
| 26 function SymbolConstructor(x) { | 35 function SymbolConstructor(x) { |
| 27 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol"); | 36 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol"); |
| 28 // NOTE: Passing in a Symbol value will throw on ToString(). | 37 // NOTE: Passing in a Symbol value will throw on ToString(). |
| 29 return %CreateSymbol(IS_UNDEFINED(x) ? x : $toString(x)); | 38 return %CreateSymbol(IS_UNDEFINED(x) ? x : $toString(x)); |
| 30 } | 39 } |
| 31 | 40 |
| 32 | 41 |
| 33 function SymbolToString() { | 42 function SymbolToString() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return %SymbolRegistry().keyFor[symbol]; | 75 return %SymbolRegistry().keyFor[symbol]; |
| 67 } | 76 } |
| 68 | 77 |
| 69 | 78 |
| 70 // ES6 19.1.2.8 | 79 // ES6 19.1.2.8 |
| 71 function ObjectGetOwnPropertySymbols(obj) { | 80 function ObjectGetOwnPropertySymbols(obj) { |
| 72 obj = $toObject(obj); | 81 obj = $toObject(obj); |
| 73 | 82 |
| 74 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | 83 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
| 75 | 84 |
| 76 return $objectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); | 85 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); |
| 77 } | 86 } |
| 78 | 87 |
| 79 //------------------------------------------------------------------- | 88 //------------------------------------------------------------------- |
| 80 | 89 |
| 81 %SetCode(GlobalSymbol, SymbolConstructor); | 90 %SetCode(GlobalSymbol, SymbolConstructor); |
| 82 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); | 91 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); |
| 83 | 92 |
| 84 $installConstants(GlobalSymbol, [ | 93 utils.InstallConstants(GlobalSymbol, [ |
| 85 // TODO(rossberg): expose when implemented. | 94 // TODO(rossberg): expose when implemented. |
| 86 // "hasInstance", symbolHasInstance, | 95 // "hasInstance", symbolHasInstance, |
| 87 // "isConcatSpreadable", symbolIsConcatSpreadable, | 96 // "isConcatSpreadable", symbolIsConcatSpreadable, |
| 88 // "isRegExp", symbolIsRegExp, | 97 // "isRegExp", symbolIsRegExp, |
| 89 "iterator", symbolIterator, | 98 "iterator", symbolIterator, |
| 90 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- | 99 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- |
| 91 // Move here when shipping | 100 // Move here when shipping |
| 92 // "toStringTag", symbolToStringTag, | 101 // "toStringTag", symbolToStringTag, |
| 93 "unscopables", symbolUnscopables | 102 "unscopables", symbolUnscopables |
| 94 ]); | 103 ]); |
| 95 | 104 |
| 96 $installFunctions(GlobalSymbol, DONT_ENUM, [ | 105 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [ |
| 97 "for", SymbolFor, | 106 "for", SymbolFor, |
| 98 "keyFor", SymbolKeyFor | 107 "keyFor", SymbolKeyFor |
| 99 ]); | 108 ]); |
| 100 | 109 |
| 101 %AddNamedProperty( | 110 %AddNamedProperty( |
| 102 GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM); | 111 GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM); |
| 103 %AddNamedProperty( | 112 %AddNamedProperty( |
| 104 GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY); | 113 GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY); |
| 105 | 114 |
| 106 $installFunctions(GlobalSymbol.prototype, DONT_ENUM, [ | 115 utils.InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, [ |
| 107 "toString", SymbolToString, | 116 "toString", SymbolToString, |
| 108 "valueOf", SymbolValueOf | 117 "valueOf", SymbolValueOf |
| 109 ]); | 118 ]); |
| 110 | 119 |
| 111 $installFunctions(GlobalObject, DONT_ENUM, [ | 120 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ |
| 112 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols | 121 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols |
| 113 ]); | 122 ]); |
| 114 | 123 |
| 115 $symbolToString = SymbolToString; | 124 $symbolToString = SymbolToString; |
| 116 | 125 |
| 117 }) | 126 }) |
| OLD | NEW |