c-api.h 1.42 KB
Newer Older
1 2 3 4
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7 8
#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif  // !V8_ENABLE_WEBASSEMBLY

9 10 11
#ifndef V8_WASM_C_API_H_
#define V8_WASM_C_API_H_

12
#include "include/v8.h"
13
#include "src/common/globals.h"
14
#include "src/handles/handles.h"
15 16
#include "third_party/wasm-api/wasm.hh"

17 18 19 20 21 22 23 24
namespace v8 {
namespace internal {

class JSWeakMap;

}  // namespace internal
}  // namespace v8

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
namespace wasm {

class StoreImpl {
 public:
  ~StoreImpl();

  v8::Isolate* isolate() const { return isolate_; }
  i::Isolate* i_isolate() const {
    return reinterpret_cast<i::Isolate*>(isolate_);
  }

  v8::Local<v8::Context> context() const { return context_.Get(isolate_); }

  static StoreImpl* get(i::Isolate* isolate) {
    return static_cast<StoreImpl*>(
        reinterpret_cast<v8::Isolate*>(isolate)->GetData(0));
  }

43 44 45 46
  void SetHostInfo(i::Handle<i::Object> object, void* info,
                   void (*finalizer)(void*));
  void* GetHostInfo(i::Handle<i::Object> key);

47
 private:
48
  friend own<Store> Store::make(Engine*);
49

50
  StoreImpl() = default;
51 52 53 54

  v8::Isolate::CreateParams create_params_;
  v8::Isolate* isolate_ = nullptr;
  v8::Eternal<v8::Context> context_;
55
  i::Handle<i::JSWeakMap> host_info_map_;
56 57 58 59 60
};

}  // namespace wasm

#endif  // V8_WASM_C_API_H_