1 // Copyright 2019 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 #if !V8_ENABLE_WEBASSEMBLY
6 #error This header should only be included if WebAssembly is enabled.
7 #endif  // !V8_ENABLE_WEBASSEMBLY
8 
9 #ifndef V8_WASM_C_API_H_
10 #define V8_WASM_C_API_H_
11 
12 #include "include/v8-isolate.h"
13 #include "include/v8-local-handle.h"
14 #include "src/common/globals.h"
15 #include "src/handles/handles.h"
16 #include "third_party/wasm-api/wasm.hh"
17 
18 namespace v8 {
19 namespace internal {
20 
21 class JSWeakMap;
22 
23 }  // namespace internal
24 }  // namespace v8
25 
26 namespace wasm {
27 
28 class StoreImpl {
29  public:
30   ~StoreImpl();
31 
isolate()32   v8::Isolate* isolate() const { return isolate_; }
i_isolate()33   i::Isolate* i_isolate() const {
34     return reinterpret_cast<i::Isolate*>(isolate_);
35   }
36 
context()37   v8::Local<v8::Context> context() const { return context_.Get(isolate_); }
38 
get(i::Isolate * isolate)39   static StoreImpl* get(i::Isolate* isolate) {
40     return static_cast<StoreImpl*>(
41         reinterpret_cast<v8::Isolate*>(isolate)->GetData(0));
42   }
43 
44   void SetHostInfo(i::Handle<i::Object> object, void* info,
45                    void (*finalizer)(void*));
46   void* GetHostInfo(i::Handle<i::Object> key);
47 
48  private:
49   friend own<Store> Store::make(Engine*);
50 
51   StoreImpl() = default;
52 
53   v8::Isolate::CreateParams create_params_;
54   v8::Isolate* isolate_ = nullptr;
55   v8::Eternal<v8::Context> context_;
56   i::Handle<i::JSWeakMap> host_info_map_;
57 };
58 
59 }  // namespace wasm
60 
61 #endif  // V8_WASM_C_API_H_
62