#ifndef V8_SANDBOX_TRUSTED_POINTER_SCOPE_H_
#define V8_SANDBOX_TRUSTED_POINTER_SCOPE_H_
#include "src/sandbox/isolate.h"
namespace v8::internal {
class DisallowJavascriptExecution;
#ifdef V8_ENABLE_SANDBOX
struct TrustedPointerTableEntry;
class TrustedPointerPublishingScope {
public:
TrustedPointerPublishingScope(Isolate* isolate,
const DisallowJavascriptExecution& no_js);
~TrustedPointerPublishingScope();
void MarkSuccess() { state_ = State::kSuccess; }
void MarkFailure() { state_ = State::kFailure; }
void TrackPointer(TrustedPointerTableEntry* entry);
private:
enum class State : uint8_t { kInProgress, kSuccess, kFailure };
enum class Storage : uint8_t { kEmpty, kSingleton, kVector };
State state_{State::kInProgress};
Storage storage_{Storage::kEmpty};
union {
TrustedPointerTableEntry* singleton_{nullptr};
std::vector<TrustedPointerTableEntry*>* vector_;
};
Isolate* isolate_;
};
class DisableTrustedPointerPublishingScope {
public:
explicit DisableTrustedPointerPublishingScope(Isolate* isolate);
~DisableTrustedPointerPublishingScope();
private:
Isolate* isolate_;
TrustedPointerPublishingScope* saved_{nullptr};
};
#else
class TrustedPointerPublishingScope {
public:
TrustedPointerPublishingScope(Isolate* isolate,
const DisallowJavascriptExecution& no_js) {}
void MarkSuccess() {}
void MarkFailure() {}
};
class DisableTrustedPointerPublishingScope {
public:
explicit DisableTrustedPointerPublishingScope(Isolate* isolate) {}
};
#endif
}
#endif