| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var GlobalObject = global.Object; | 14 var GlobalObject = global.Object; |
| 15 var GlobalSymbol = global.Symbol; | 15 var GlobalSymbol = global.Symbol; |
| 16 var hasInstanceSymbol = utils.ImportNow("has_instance_symbol"); | 16 var hasInstanceSymbol = utils.ImportNow("has_instance_symbol"); |
| 17 var isConcatSpreadableSymbol = | 17 var isConcatSpreadableSymbol = |
| 18 utils.ImportNow("is_concat_spreadable_symbol"); | 18 utils.ImportNow("is_concat_spreadable_symbol"); |
| 19 var isRegExpSymbol = utils.ImportNow("is_regexp_symbol"); | 19 var isRegExpSymbol = utils.ImportNow("is_regexp_symbol"); |
| 20 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 20 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
| 21 var ObjectGetOwnPropertyKeys; | 21 var ObjectGetOwnPropertyKeys; |
| 22 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); | 22 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); |
| 23 var ToString; | |
| 24 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 23 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 25 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); | 24 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); |
| 26 | 25 |
| 27 utils.Import(function(from) { | 26 utils.Import(function(from) { |
| 28 ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys; | 27 ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys; |
| 29 ToString = from.ToString; | |
| 30 }); | 28 }); |
| 31 | 29 |
| 32 // ------------------------------------------------------------------- | 30 // ------------------------------------------------------------------- |
| 33 | 31 |
| 34 function SymbolConstructor(x) { | |
| 35 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol"); | |
| 36 // NOTE: Passing in a Symbol value will throw on ToString(). | |
| 37 return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x)); | |
| 38 } | |
| 39 | |
| 40 | |
| 41 // 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) | 32 // 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) |
| 42 function SymbolToPrimitive(hint) { | 33 function SymbolToPrimitive(hint) { |
| 43 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { | 34 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { |
| 44 throw MakeTypeError(kIncompatibleMethodReceiver, | 35 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 45 "Symbol.prototype [ @@toPrimitive ]", this); | 36 "Symbol.prototype [ @@toPrimitive ]", this); |
| 46 } | 37 } |
| 47 return %_ValueOf(this); | 38 return %_ValueOf(this); |
| 48 } | 39 } |
| 49 | 40 |
| 50 | 41 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 function ObjectGetOwnPropertySymbols(obj) { | 79 function ObjectGetOwnPropertySymbols(obj) { |
| 89 obj = TO_OBJECT(obj); | 80 obj = TO_OBJECT(obj); |
| 90 | 81 |
| 91 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | 82 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
| 92 | 83 |
| 93 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); | 84 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); |
| 94 } | 85 } |
| 95 | 86 |
| 96 // ------------------------------------------------------------------- | 87 // ------------------------------------------------------------------- |
| 97 | 88 |
| 98 %SetCode(GlobalSymbol, SymbolConstructor); | |
| 99 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); | 89 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); |
| 100 | 90 |
| 101 utils.InstallConstants(GlobalSymbol, [ | 91 utils.InstallConstants(GlobalSymbol, [ |
| 102 // TODO(rossberg): expose when implemented. | 92 // TODO(rossberg): expose when implemented. |
| 103 // "hasInstance", hasInstanceSymbol, | 93 // "hasInstance", hasInstanceSymbol, |
| 104 // "isConcatSpreadable", isConcatSpreadableSymbol, | 94 // "isConcatSpreadable", isConcatSpreadableSymbol, |
| 105 // "isRegExp", isRegExpSymbol, | 95 // "isRegExp", isRegExpSymbol, |
| 106 "iterator", iteratorSymbol, | 96 "iterator", iteratorSymbol, |
| 107 "toPrimitive", toPrimitiveSymbol, | 97 "toPrimitive", toPrimitiveSymbol, |
| 108 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- | 98 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- |
| (...skipping 26 matching lines...) Expand all Loading... |
| 135 ]); | 125 ]); |
| 136 | 126 |
| 137 // ------------------------------------------------------------------- | 127 // ------------------------------------------------------------------- |
| 138 // Exports | 128 // Exports |
| 139 | 129 |
| 140 utils.Export(function(to) { | 130 utils.Export(function(to) { |
| 141 to.SymbolToString = SymbolToString; | 131 to.SymbolToString = SymbolToString; |
| 142 }) | 132 }) |
| 143 | 133 |
| 144 }) | 134 }) |
| OLD | NEW |