11cb0ef41Sopenharmony_ci// Copyright 2021 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#ifndef INCLUDE_V8_EMBEDDER_STATE_SCOPE_H_ 61cb0ef41Sopenharmony_ci#define INCLUDE_V8_EMBEDDER_STATE_SCOPE_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <memory> 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "v8-context.h" // NOLINT(build/include_directory) 111cb0ef41Sopenharmony_ci#include "v8-internal.h" // NOLINT(build/include_directory) 121cb0ef41Sopenharmony_ci#include "v8-local-handle.h" // NOLINT(build/include_directory) 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace v8 { 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cinamespace internal { 171cb0ef41Sopenharmony_ciclass EmbedderState; 181cb0ef41Sopenharmony_ci} // namespace internal 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci// A StateTag represents a possible state of the embedder. 211cb0ef41Sopenharmony_cienum class EmbedderStateTag : uint8_t { 221cb0ef41Sopenharmony_ci // reserved 231cb0ef41Sopenharmony_ci EMPTY = 0, 241cb0ef41Sopenharmony_ci OTHER = 1, 251cb0ef41Sopenharmony_ci // embedder can define any state after 261cb0ef41Sopenharmony_ci}; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci// A stack-allocated class that manages an embedder state on the isolate. 291cb0ef41Sopenharmony_ci// After an EmbedderState scope has been created, a new embedder state will be 301cb0ef41Sopenharmony_ci// pushed on the isolate stack. 311cb0ef41Sopenharmony_ciclass V8_EXPORT EmbedderStateScope { 321cb0ef41Sopenharmony_ci public: 331cb0ef41Sopenharmony_ci EmbedderStateScope(Isolate* isolate, Local<v8::Context> context, 341cb0ef41Sopenharmony_ci EmbedderStateTag tag); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci ~EmbedderStateScope(); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci private: 391cb0ef41Sopenharmony_ci // Declaring operator new and delete as deleted is not spec compliant. 401cb0ef41Sopenharmony_ci // Therefore declare them private instead to disable dynamic alloc 411cb0ef41Sopenharmony_ci void* operator new(size_t size); 421cb0ef41Sopenharmony_ci void* operator new[](size_t size); 431cb0ef41Sopenharmony_ci void operator delete(void*, size_t); 441cb0ef41Sopenharmony_ci void operator delete[](void*, size_t); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci std::unique_ptr<internal::EmbedderState> embedder_state_; 471cb0ef41Sopenharmony_ci}; 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci} // namespace v8 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci#endif // INCLUDE_V8_EMBEDDER_STATE_SCOPE_H_ 52