1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: set ts=8 sts=2 et sw=2 tw=80:
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef vm_JSAtomState_h
8 #define vm_JSAtomState_h
9 
10 #include "gc/Barrier.h"
11 #include "gc/Rooting.h"
12 #include "js/ProtoKey.h"
13 #include "js/Symbol.h"
14 #include "vm/CommonPropertyNames.h"
15 
16 /* Various built-in or commonly-used names pinned on first context. */
17 struct JSAtomState {
18 #define PROPERTYNAME_FIELD(idpart, id, text) js::ImmutablePropertyNamePtr id;
19   FOR_EACH_COMMON_PROPERTYNAME(PROPERTYNAME_FIELD)
20 #undef PROPERTYNAME_FIELD
21 #define PROPERTYNAME_FIELD(name, clasp) js::ImmutablePropertyNamePtr name;
JS_FOR_EACH_PROTOTYPEJSAtomState22   JS_FOR_EACH_PROTOTYPE(PROPERTYNAME_FIELD)
23 #undef PROPERTYNAME_FIELD
24 #define PROPERTYNAME_FIELD(name) js::ImmutablePropertyNamePtr name;
25   JS_FOR_EACH_WELL_KNOWN_SYMBOL(PROPERTYNAME_FIELD)
26 #undef PROPERTYNAME_FIELD
27 #define PROPERTYNAME_FIELD(name) js::ImmutablePropertyNamePtr Symbol_##name;
28   JS_FOR_EACH_WELL_KNOWN_SYMBOL(PROPERTYNAME_FIELD)
29 #undef PROPERTYNAME_FIELD
30 
31   js::ImmutablePropertyNamePtr* wellKnownSymbolNames() {
32 #define FIRST_PROPERTYNAME_FIELD(name) return &name;
33     JS_FOR_EACH_WELL_KNOWN_SYMBOL(FIRST_PROPERTYNAME_FIELD)
34 #undef FIRST_PROPERTYNAME_FIELD
35   }
36 
wellKnownSymbolDescriptionsJSAtomState37   js::ImmutablePropertyNamePtr* wellKnownSymbolDescriptions() {
38 #define FIRST_PROPERTYNAME_FIELD(name) return &Symbol_##name;
39     JS_FOR_EACH_WELL_KNOWN_SYMBOL(FIRST_PROPERTYNAME_FIELD)
40 #undef FIRST_PROPERTYNAME_FIELD
41   }
42 };
43 
44 namespace js {
45 
46 #define NAME_OFFSET(name) offsetof(JSAtomState, name)
47 
AtomStateOffsetToName(const JSAtomState & atomState,size_t offset)48 inline HandlePropertyName AtomStateOffsetToName(const JSAtomState& atomState,
49                                                 size_t offset) {
50   return *reinterpret_cast<js::ImmutablePropertyNamePtr*>((char*)&atomState +
51                                                           offset);
52 }
53 
54 } /* namespace js */
55 
56 #endif /* vm_JSAtomState_h */
57