Commit 473d747d authored by Qingyan Li's avatar Qingyan Li Committed by Commit Bot

[snapshot]: Fix missing Cast in {Private, Signature, AccessorSignature}

R=yangguo@chromium.org

Bug: v8:7306
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I40037ebb66a856b52454c50d17b4c8a51aab7a84
Reviewed-on: https://chromium-review.googlesource.com/866215
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50618}
parent 3a4f3b73
......@@ -120,6 +120,7 @@ Peter Rybin <peter.rybin@gmail.com>
Peter Varga <pvarga@inf.u-szeged.hu>
Peter Wong <peter.wm.wong@gmail.com>
Paul Lind <plind44@gmail.com>
Qingyan Li <qingyan.liqy@alibaba-inc.com>
Qiuyi Zhang <qiuyi.zqy@alibaba-inc.com>
Rafal Krypa <rafal@krypa.net>
Refael Ackermann <refack@gmail.com>
......
......@@ -2913,8 +2913,12 @@ class V8_EXPORT Private : public Data {
*/
static Local<Private> ForApi(Isolate* isolate, Local<String> name);
V8_INLINE static Private* Cast(Data* data);
private:
Private();
static void CheckCast(Data* that);
};
......@@ -5899,8 +5903,12 @@ class V8_EXPORT Signature : public Data {
Isolate* isolate,
Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
V8_INLINE static Signature* Cast(Data* data);
private:
Signature();
static void CheckCast(Data* that);
};
......@@ -5914,8 +5922,12 @@ class V8_EXPORT AccessorSignature : public Data {
Isolate* isolate,
Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
V8_INLINE static AccessorSignature* Cast(Data* data);
private:
AccessorSignature();
static void CheckCast(Data* that);
};
......@@ -9488,6 +9500,20 @@ ObjectTemplate* ObjectTemplate::Cast(Data* data) {
return reinterpret_cast<ObjectTemplate*>(data);
}
Signature* Signature::Cast(Data* data) {
#ifdef V8_ENABLE_CHECKS
CheckCast(data);
#endif
return reinterpret_cast<Signature*>(data);
}
AccessorSignature* AccessorSignature::Cast(Data* data) {
#ifdef V8_ENABLE_CHECKS
CheckCast(data);
#endif
return reinterpret_cast<AccessorSignature*>(data);
}
Local<Value> Object::GetInternalField(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
......@@ -9706,6 +9732,14 @@ Symbol* Symbol::Cast(v8::Value* value) {
}
Private* Private::Cast(Data* data) {
#ifdef V8_ENABLE_CHECKS
CheckCast(data);
#endif
return reinterpret_cast<Private*>(data);
}
Number* Number::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
......
......@@ -3818,6 +3818,15 @@ void v8::Symbol::CheckCast(v8::Value* that) {
}
void v8::Private::CheckCast(v8::Data* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsSymbol() &&
i::Handle<i::Symbol>::cast(obj)->is_private(),
"v8::Private::Cast",
"Could not convert to private");
}
void v8::Number::CheckCast(v8::Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsNumber(),
......@@ -6559,6 +6568,18 @@ void v8::FunctionTemplate::CheckCast(Data* that) {
"Could not convert to function template");
}
void v8::Signature::CheckCast(Data* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::Signature::Cast",
"Could not convert to signature");
}
void v8::AccessorSignature::CheckCast(Data* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::AccessorSignature::Cast",
"Could not convert to accessor signature");
}
MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) {
PREPARE_FOR_EXECUTION(context, FunctionTemplate, GetFunction, Function);
auto self = Utils::OpenHandle(this);
......
......@@ -2808,6 +2808,16 @@ TEST(SnapshotCreatorAddData) {
v8::ObjectTemplate::New(isolate);
object_template->SetInternalFieldCount(3);
v8::Local<v8::Private> private_symbol =
v8::Private::ForApi(isolate, v8_str("private_symbol"));
v8::Local<v8::Signature> signature =
v8::Signature::New(isolate, v8::FunctionTemplate::New(isolate));
v8::Local<v8::AccessorSignature> accessor_signature =
v8::AccessorSignature::New(isolate,
v8::FunctionTemplate::New(isolate));
CHECK_EQ(0u, creator.AddData(context, object));
CHECK_EQ(1u, creator.AddData(context, v8_str("context-dependent")));
CHECK_EQ(2u, creator.AddData(context, persistent_number_1.Get(isolate)));
......@@ -2819,6 +2829,9 @@ TEST(SnapshotCreatorAddData) {
CHECK_EQ(1u, creator.AddData(eternal_number.Get(isolate)));
CHECK_EQ(2u, creator.AddData(object_template));
CHECK_EQ(3u, creator.AddData(v8::FunctionTemplate::New(isolate)));
CHECK_EQ(4u, creator.AddData(private_symbol));
CHECK_EQ(5u, creator.AddData(signature));
CHECK_EQ(6u, creator.AddData(accessor_signature));
}
blob =
......@@ -2889,7 +2902,19 @@ TEST(SnapshotCreatorAddData) {
CHECK(
isolate->GetDataFromSnapshotOnce<v8::FunctionTemplate>(3).IsEmpty());
CHECK(isolate->GetDataFromSnapshotOnce<v8::Value>(4).IsEmpty());
isolate->GetDataFromSnapshotOnce<v8::Private>(4).ToLocalChecked();
CHECK(
isolate->GetDataFromSnapshotOnce<v8::Private>(4).IsEmpty());
isolate->GetDataFromSnapshotOnce<v8::Signature>(5).ToLocalChecked();
CHECK(isolate->GetDataFromSnapshotOnce<v8::Signature>(5).IsEmpty());
isolate->GetDataFromSnapshotOnce<v8::AccessorSignature>(6)
.ToLocalChecked();
CHECK(
isolate->GetDataFromSnapshotOnce<v8::AccessorSignature>(6).IsEmpty());
CHECK(isolate->GetDataFromSnapshotOnce<v8::Value>(7).IsEmpty());
}
isolate->Dispose();
}
......
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