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  *
4  * Copyright 2021 Mozilla Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef wasm_type_decls_h
20 #define wasm_type_decls_h
21 
22 #include "NamespaceImports.h"
23 #include "gc/Barrier.h"
24 #include "js/GCVector.h"
25 #include "js/HashTable.h"
26 #include "js/RootingAPI.h"
27 #include "js/UniquePtr.h"
28 #include "js/Utility.h"
29 #include "js/Vector.h"
30 
31 namespace js {
32 
33 using JSFunctionVector = GCVector<JSFunction*, 0, SystemAllocPolicy>;
34 
35 class WasmMemoryObject;
36 using GCPtrWasmMemoryObject = GCPtr<WasmMemoryObject*>;
37 using RootedWasmMemoryObject = Rooted<WasmMemoryObject*>;
38 using HandleWasmMemoryObject = Handle<WasmMemoryObject*>;
39 using MutableHandleWasmMemoryObject = MutableHandle<WasmMemoryObject*>;
40 
41 class WasmModuleObject;
42 using RootedWasmModuleObject = Rooted<WasmModuleObject*>;
43 using HandleWasmModuleObject = Handle<WasmModuleObject*>;
44 using MutableHandleWasmModuleObject = MutableHandle<WasmModuleObject*>;
45 
46 class WasmInstanceObject;
47 using WasmInstanceObjectVector = GCVector<WasmInstanceObject*>;
48 using RootedWasmInstanceObject = Rooted<WasmInstanceObject*>;
49 using HandleWasmInstanceObject = Handle<WasmInstanceObject*>;
50 using MutableHandleWasmInstanceObject = MutableHandle<WasmInstanceObject*>;
51 
52 class WasmTableObject;
53 using WasmTableObjectVector = GCVector<WasmTableObject*, 0, SystemAllocPolicy>;
54 using RootedWasmTableObject = Rooted<WasmTableObject*>;
55 using HandleWasmTableObject = Handle<WasmTableObject*>;
56 using MutableHandleWasmTableObject = MutableHandle<WasmTableObject*>;
57 
58 class WasmGlobalObject;
59 using WasmGlobalObjectVector =
60     GCVector<WasmGlobalObject*, 0, SystemAllocPolicy>;
61 using RootedWasmGlobalObject = Rooted<WasmGlobalObject*>;
62 
63 class WasmExceptionObject;
64 using WasmExceptionObjectVector =
65     GCVector<WasmExceptionObject*, 0, SystemAllocPolicy>;
66 using RootedWasmExceptionObject = Rooted<WasmExceptionObject*>;
67 
68 class WasmRuntimeExceptionObject;
69 using RootedWasmRuntimeExceptionObject = Rooted<WasmRuntimeExceptionObject*>;
70 
71 namespace wasm {
72 
73 struct ModuleEnvironment;
74 class Decoder;
75 class Instance;
76 
77 // Uint32Vector has initial size 8 on the basis that the dominant use cases
78 // (line numbers and control stacks) tend to have a small but nonzero number
79 // of elements.
80 using Uint32Vector = Vector<uint32_t, 8, SystemAllocPolicy>;
81 
82 using Bytes = Vector<uint8_t, 0, SystemAllocPolicy>;
83 using UniqueBytes = UniquePtr<Bytes>;
84 using UniqueConstBytes = UniquePtr<const Bytes>;
85 using UTF8Bytes = Vector<char, 0, SystemAllocPolicy>;
86 using InstanceVector = Vector<Instance*, 0, SystemAllocPolicy>;
87 using UniqueCharsVector = Vector<UniqueChars, 0, SystemAllocPolicy>;
88 using RenumberMap =
89     HashMap<uint32_t, uint32_t, DefaultHasher<uint32_t>, SystemAllocPolicy>;
90 
91 }  // namespace wasm
92 }  // namespace js
93 
94 #endif  // wasm_type_decls_h
95