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