Commit 70fbfb0c authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

api: Make Context a Data object

Context objects are allocated on the heap and thus should be Data
objects. This allows handling them through tracing in the GC through
the API.

Bug: chromium:1013149
Change-Id: Id3a7bfd57fab19a5669062ccf61c2f8588faf0bb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2627307Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72120}
parent 088205f0
......@@ -1343,6 +1343,11 @@ class V8_EXPORT Data {
*/
bool IsFunctionTemplate() const;
/**
* Returns true if this data is a |v8::Context|.
*/
bool IsContext() const;
private:
Data();
};
......@@ -10439,7 +10444,7 @@ class V8_EXPORT ExtensionConfiguration {
* A sandboxed execution context with its own set of built-in objects
* and functions.
*/
class V8_EXPORT Context {
class V8_EXPORT Context : public Data {
public:
/**
* Returns the global proxy object.
......@@ -10716,18 +10721,21 @@ class V8_EXPORT Context {
const BackupIncumbentScope* prev_ = nullptr;
};
V8_INLINE static Context* Cast(Data* data);
private:
friend class Value;
friend class Script;
friend class Object;
friend class Function;
static void CheckCast(Data* obj);
internal::Address* GetDataFromSnapshotOnce(size_t index);
Local<Value> SlowGetEmbedderData(int index);
void* SlowGetAlignedPointerFromEmbedderData(int index);
};
/**
* Multiple threads in V8 are allowed, but only one thread at a time is allowed
* to use any given V8 isolate, see the comments in the Isolate class. The
......@@ -11896,6 +11904,13 @@ BigInt* BigInt::Cast(v8::Data* data) {
return static_cast<BigInt*>(data);
}
Context* Context::Cast(v8::Data* data) {
#ifdef V8_ENABLE_CHECKS
CheckCast(data);
#endif
return static_cast<Context*>(data);
}
Date* Date::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
......
......@@ -1183,6 +1183,8 @@ bool Data::IsFunctionTemplate() const {
return Utils::OpenHandle(this)->IsFunctionTemplateInfo();
}
bool Data::IsContext() const { return Utils::OpenHandle(this)->IsContext(); }
void Context::Enter() {
i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate();
......@@ -3881,6 +3883,12 @@ void v8::BigInt::CheckCast(v8::Data* that) {
"Value is not a BigInt");
}
void v8::Context::CheckCast(v8::Data* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsContext(), "v8::Context::Cast",
"Value is not a Context");
}
void v8::Array::CheckCast(Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsJSArray(), "v8::Array::Cast", "Value is not an Array");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment