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
14var GlobalSymbol = global.Symbol;
15var hasInstanceSymbol = utils.ImportNow("has_instance_symbol");
16var isConcatSpreadableSymbol =
17    utils.ImportNow("is_concat_spreadable_symbol");
18var iteratorSymbol = utils.ImportNow("iterator_symbol");
19var matchSymbol = utils.ImportNow("match_symbol");
20var replaceSymbol = utils.ImportNow("replace_symbol");
21var searchSymbol = utils.ImportNow("search_symbol");
22var speciesSymbol = utils.ImportNow("species_symbol");
23var splitSymbol = utils.ImportNow("split_symbol");
24var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol");
25var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
26var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
27
28// -------------------------------------------------------------------
29
30function 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
42function SymbolKeyFor(symbol) {
43  if (!IS_SYMBOL(symbol)) throw %make_type_error(kSymbolKeyFor, symbol);
44  return %SymbolRegistry().keyFor[symbol];
45}
46
47// -------------------------------------------------------------------
48
49utils.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
63utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [
64  "for", SymbolFor,
65  "keyFor", SymbolKeyFor
66]);
67
68})
69