11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#if !V8_ENABLE_WEBASSEMBLY
61cb0ef41Sopenharmony_ci#error This header should only be included if WebAssembly is enabled.
71cb0ef41Sopenharmony_ci#endif  // !V8_ENABLE_WEBASSEMBLY
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#ifndef V8_WASM_C_API_H_
101cb0ef41Sopenharmony_ci#define V8_WASM_C_API_H_
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#include "include/v8-isolate.h"
131cb0ef41Sopenharmony_ci#include "include/v8-local-handle.h"
141cb0ef41Sopenharmony_ci#include "src/common/globals.h"
151cb0ef41Sopenharmony_ci#include "src/handles/handles.h"
161cb0ef41Sopenharmony_ci#include "third_party/wasm-api/wasm.hh"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cinamespace v8 {
191cb0ef41Sopenharmony_cinamespace internal {
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciclass JSWeakMap;
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci}  // namespace internal
241cb0ef41Sopenharmony_ci}  // namespace v8
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cinamespace wasm {
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciclass StoreImpl {
291cb0ef41Sopenharmony_ci public:
301cb0ef41Sopenharmony_ci  ~StoreImpl();
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  v8::Isolate* isolate() const { return isolate_; }
331cb0ef41Sopenharmony_ci  i::Isolate* i_isolate() const {
341cb0ef41Sopenharmony_ci    return reinterpret_cast<i::Isolate*>(isolate_);
351cb0ef41Sopenharmony_ci  }
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  v8::Local<v8::Context> context() const { return context_.Get(isolate_); }
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  static StoreImpl* get(i::Isolate* isolate) {
401cb0ef41Sopenharmony_ci    return static_cast<StoreImpl*>(
411cb0ef41Sopenharmony_ci        reinterpret_cast<v8::Isolate*>(isolate)->GetData(0));
421cb0ef41Sopenharmony_ci  }
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  void SetHostInfo(i::Handle<i::Object> object, void* info,
451cb0ef41Sopenharmony_ci                   void (*finalizer)(void*));
461cb0ef41Sopenharmony_ci  void* GetHostInfo(i::Handle<i::Object> key);
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci private:
491cb0ef41Sopenharmony_ci  friend own<Store> Store::make(Engine*);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  StoreImpl() = default;
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  v8::Isolate::CreateParams create_params_;
541cb0ef41Sopenharmony_ci  v8::Isolate* isolate_ = nullptr;
551cb0ef41Sopenharmony_ci  v8::Eternal<v8::Context> context_;
561cb0ef41Sopenharmony_ci  i::Handle<i::JSWeakMap> host_info_map_;
571cb0ef41Sopenharmony_ci};
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci}  // namespace wasm
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci#endif  // V8_WASM_C_API_H_
62