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 GlobalSymbol = global.Symbol; | 14 var GlobalSymbol = global.Symbol; |
15 var hasInstanceSymbol = utils.ImportNow("has_instance_symbol"); | 15 var hasInstanceSymbol = utils.ImportNow("has_instance_symbol"); |
16 var isConcatSpreadableSymbol = | 16 var isConcatSpreadableSymbol = |
17 utils.ImportNow("is_concat_spreadable_symbol"); | 17 utils.ImportNow("is_concat_spreadable_symbol"); |
18 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 18 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
19 var MakeTypeError; | |
20 var matchSymbol = utils.ImportNow("match_symbol"); | 19 var matchSymbol = utils.ImportNow("match_symbol"); |
21 var replaceSymbol = utils.ImportNow("replace_symbol"); | 20 var replaceSymbol = utils.ImportNow("replace_symbol"); |
22 var searchSymbol = utils.ImportNow("search_symbol"); | 21 var searchSymbol = utils.ImportNow("search_symbol"); |
23 var speciesSymbol = utils.ImportNow("species_symbol"); | 22 var speciesSymbol = utils.ImportNow("species_symbol"); |
24 var splitSymbol = utils.ImportNow("split_symbol"); | 23 var splitSymbol = utils.ImportNow("split_symbol"); |
25 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); | 24 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); |
26 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 25 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
27 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); | 26 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); |
28 | 27 |
29 utils.Import(function(from) { | |
30 MakeTypeError = from.MakeTypeError; | |
31 }); | |
32 | |
33 // ------------------------------------------------------------------- | 28 // ------------------------------------------------------------------- |
34 | 29 |
35 function SymbolFor(key) { | 30 function SymbolFor(key) { |
36 key = TO_STRING(key); | 31 key = TO_STRING(key); |
37 var registry = %SymbolRegistry(); | 32 var registry = %SymbolRegistry(); |
38 if (IS_UNDEFINED(registry.for[key])) { | 33 if (IS_UNDEFINED(registry.for[key])) { |
39 var symbol = %CreateSymbol(key); | 34 var symbol = %CreateSymbol(key); |
40 registry.for[key] = symbol; | 35 registry.for[key] = symbol; |
41 registry.keyFor[symbol] = key; | 36 registry.keyFor[symbol] = key; |
42 } | 37 } |
43 return registry.for[key]; | 38 return registry.for[key]; |
44 } | 39 } |
45 | 40 |
46 | 41 |
47 function SymbolKeyFor(symbol) { | 42 function SymbolKeyFor(symbol) { |
48 if (!IS_SYMBOL(symbol)) throw MakeTypeError(kSymbolKeyFor, symbol); | 43 if (!IS_SYMBOL(symbol)) throw %make_type_error(kSymbolKeyFor, symbol); |
49 return %SymbolRegistry().keyFor[symbol]; | 44 return %SymbolRegistry().keyFor[symbol]; |
50 } | 45 } |
51 | 46 |
52 // ------------------------------------------------------------------- | 47 // ------------------------------------------------------------------- |
53 | 48 |
54 utils.InstallConstants(GlobalSymbol, [ | 49 utils.InstallConstants(GlobalSymbol, [ |
55 "hasInstance", hasInstanceSymbol, | 50 "hasInstance", hasInstanceSymbol, |
56 "isConcatSpreadable", isConcatSpreadableSymbol, | 51 "isConcatSpreadable", isConcatSpreadableSymbol, |
57 "iterator", iteratorSymbol, | 52 "iterator", iteratorSymbol, |
58 "match", matchSymbol, | 53 "match", matchSymbol, |
59 "replace", replaceSymbol, | 54 "replace", replaceSymbol, |
60 "search", searchSymbol, | 55 "search", searchSymbol, |
61 "species", speciesSymbol, | 56 "species", speciesSymbol, |
62 "split", splitSymbol, | 57 "split", splitSymbol, |
63 "toPrimitive", toPrimitiveSymbol, | 58 "toPrimitive", toPrimitiveSymbol, |
64 "toStringTag", toStringTagSymbol, | 59 "toStringTag", toStringTagSymbol, |
65 "unscopables", unscopablesSymbol, | 60 "unscopables", unscopablesSymbol, |
66 ]); | 61 ]); |
67 | 62 |
68 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [ | 63 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [ |
69 "for", SymbolFor, | 64 "for", SymbolFor, |
70 "keyFor", SymbolKeyFor | 65 "keyFor", SymbolKeyFor |
71 ]); | 66 ]); |
72 | 67 |
73 }) | 68 }) |
OLD | NEW |