Commit 10c137a2 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[fastcall] Migrate IsLeafTemplateForApiObject to Local<Value>

This CL makes the object passed as argument to IsLeafTemplateForApiObject
be received as a handle instead of a raw C++ pointer. From the codegen
point of view, the memory representation is the same, so this doesn't
change its semantics.

Bug: chromium:1052746
Change-Id: Ibc116aa4d577ba95f30d1014f15f34ef3fbb1a35
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2851884Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74220}
parent c1b0fed9
...@@ -425,7 +425,7 @@ struct TypeInfoHelper { ...@@ -425,7 +425,7 @@ struct TypeInfoHelper {
V(float, kFloat32) \ V(float, kFloat32) \
V(double, kFloat64) \ V(double, kFloat64) \
V(ApiObject, kApiObject) \ V(ApiObject, kApiObject) \
V(v8::Value*, kV8Value) V(v8::Local<v8::Value>, kV8Value)
// ApiObject was a temporary solution to wrap the pointer to the v8::Value. // ApiObject was a temporary solution to wrap the pointer to the v8::Value.
// Please use v8::Value* in new code, as ApiObject will be deprecated soon. // Please use v8::Value* in new code, as ApiObject will be deprecated soon.
......
...@@ -6597,7 +6597,7 @@ class V8_EXPORT FunctionTemplate : public Template { ...@@ -6597,7 +6597,7 @@ class V8_EXPORT FunctionTemplate : public Template {
* *
* This is an experimental feature and may still change significantly. * This is an experimental feature and may still change significantly.
*/ */
bool IsLeafTemplateForApiObject(Value* value) const; bool IsLeafTemplateForApiObject(v8::Local<v8::Value> value) const;
V8_INLINE static FunctionTemplate* Cast(Data* data); V8_INLINE static FunctionTemplate* Cast(Data* data);
......
...@@ -6438,10 +6438,11 @@ bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { ...@@ -6438,10 +6438,11 @@ bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
return false; return false;
} }
bool FunctionTemplate::IsLeafTemplateForApiObject(v8::Value* value) const { bool FunctionTemplate::IsLeafTemplateForApiObject(
v8::Local<v8::Value> value) const {
i::DisallowGarbageCollection no_gc; i::DisallowGarbageCollection no_gc;
i::Object object = *Utils::OpenHandle(value); i::Object object = *Utils::OpenHandle(*value);
auto self = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
return self->IsLeafTemplateForApiObject(object); return self->IsLeafTemplateForApiObject(object);
......
...@@ -37,13 +37,13 @@ namespace { ...@@ -37,13 +37,13 @@ namespace {
class FastCApiObject { class FastCApiObject {
public: public:
static double AddAllFastCallback(v8::Value* receiver, bool should_fallback, static double AddAllFastCallback(Local<Value> receiver, bool should_fallback,
int32_t arg_i32, uint32_t arg_u32, int32_t arg_i32, uint32_t arg_u32,
int64_t arg_i64, uint64_t arg_u64, int64_t arg_i64, uint64_t arg_u64,
float arg_f32, double arg_f64, float arg_f32, double arg_f64,
FastApiCallbackOptions& options) { FastApiCallbackOptions& options) {
CHECK(receiver->IsObject()); CHECK(receiver->IsObject());
FastCApiObject* self = UnwrapObject(Object::Cast(receiver)); FastCApiObject* self = UnwrapObject(receiver.As<Object>());
CHECK_SELF_OR_FALLBACK(0); CHECK_SELF_OR_FALLBACK(0);
self->fast_call_count_++; self->fast_call_count_++;
...@@ -59,7 +59,7 @@ class FastCApiObject { ...@@ -59,7 +59,7 @@ class FastCApiObject {
static void AddAllSlowCallback(const FunctionCallbackInfo<Value>& args) { static void AddAllSlowCallback(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
self->slow_call_count_++; self->slow_call_count_++;
...@@ -92,11 +92,12 @@ class FastCApiObject { ...@@ -92,11 +92,12 @@ class FastCApiObject {
args.GetReturnValue().Set(Number::New(isolate, sum)); args.GetReturnValue().Set(Number::New(isolate, sum));
} }
static int Add32BitIntFastCallback(v8::Value* receiver, bool should_fallback, static int Add32BitIntFastCallback(v8::Local<v8::Value> receiver,
int32_t arg_i32, uint32_t arg_u32, bool should_fallback, int32_t arg_i32,
uint32_t arg_u32,
FastApiCallbackOptions& options) { FastApiCallbackOptions& options) {
CHECK(receiver->IsObject()); CHECK(receiver->IsObject());
FastCApiObject* self = UnwrapObject(Object::Cast(receiver)); FastCApiObject* self = UnwrapObject(receiver.As<Object>());
CHECK_SELF_OR_FALLBACK(0); CHECK_SELF_OR_FALLBACK(0);
self->fast_call_count_++; self->fast_call_count_++;
...@@ -110,7 +111,7 @@ class FastCApiObject { ...@@ -110,7 +111,7 @@ class FastCApiObject {
static void Add32BitIntSlowCallback(const FunctionCallbackInfo<Value>& args) { static void Add32BitIntSlowCallback(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
self->slow_call_count_++; self->slow_call_count_++;
...@@ -127,11 +128,12 @@ class FastCApiObject { ...@@ -127,11 +128,12 @@ class FastCApiObject {
args.GetReturnValue().Set(Number::New(isolate, sum)); args.GetReturnValue().Set(Number::New(isolate, sum));
} }
static bool IsFastCApiObjectFastCallback(v8::Value* receiver, static bool IsFastCApiObjectFastCallback(v8::Local<v8::Value> receiver,
bool should_fallback, v8::Value* arg, bool should_fallback,
v8::Local<v8::Value> arg,
FastApiCallbackOptions& options) { FastApiCallbackOptions& options) {
CHECK(receiver->IsObject()); CHECK(receiver->IsObject());
FastCApiObject* self = UnwrapObject(Object::Cast(receiver)); FastCApiObject* self = UnwrapObject(receiver.As<Object>());
CHECK_SELF_OR_FALLBACK(false); CHECK_SELF_OR_FALLBACK(false);
self->fast_call_count_++; self->fast_call_count_++;
...@@ -143,12 +145,12 @@ class FastCApiObject { ...@@ -143,12 +145,12 @@ class FastCApiObject {
if (!arg->IsObject()) { if (!arg->IsObject()) {
return false; return false;
} }
Object* object = Object::Cast(arg); Local<Object> object = arg.As<Object>();
if (!IsValidApiObject(object)) return false; if (!IsValidApiObject(object)) return false;
internal::Isolate* i_isolate = internal::Isolate* i_isolate =
internal::IsolateFromNeverReadOnlySpaceObject( internal::IsolateFromNeverReadOnlySpaceObject(
*reinterpret_cast<internal::Address*>(object)); *reinterpret_cast<internal::Address*>(*object));
CHECK_NOT_NULL(i_isolate); CHECK_NOT_NULL(i_isolate);
Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
...@@ -160,7 +162,7 @@ class FastCApiObject { ...@@ -160,7 +162,7 @@ class FastCApiObject {
const FunctionCallbackInfo<Value>& args) { const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
self->slow_call_count_++; self->slow_call_count_++;
...@@ -173,7 +175,7 @@ class FastCApiObject { ...@@ -173,7 +175,7 @@ class FastCApiObject {
return; return;
} }
if (args[1]->IsObject()) { if (args[1]->IsObject()) {
Object* object = Object::Cast(*args[1]); Local<Object> object = args[1].As<Object>();
if (!IsValidApiObject(object)) { if (!IsValidApiObject(object)) {
result = false; result = false;
} else { } else {
...@@ -187,25 +189,25 @@ class FastCApiObject { ...@@ -187,25 +189,25 @@ class FastCApiObject {
} }
static void FastCallCount(const FunctionCallbackInfo<Value>& args) { static void FastCallCount(const FunctionCallbackInfo<Value>& args) {
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
args.GetReturnValue().Set( args.GetReturnValue().Set(
Number::New(args.GetIsolate(), self->fast_call_count())); Number::New(args.GetIsolate(), self->fast_call_count()));
} }
static void SlowCallCount(const FunctionCallbackInfo<Value>& args) { static void SlowCallCount(const FunctionCallbackInfo<Value>& args) {
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
args.GetReturnValue().Set( args.GetReturnValue().Set(
Number::New(args.GetIsolate(), self->slow_call_count())); Number::New(args.GetIsolate(), self->slow_call_count()));
} }
static void ResetCounts(const FunctionCallbackInfo<Value>& args) { static void ResetCounts(const FunctionCallbackInfo<Value>& args) {
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
self->reset_counts(); self->reset_counts();
args.GetReturnValue().Set(Undefined(args.GetIsolate())); args.GetReturnValue().Set(Undefined(args.GetIsolate()));
} }
static void SupportsFPParams(const FunctionCallbackInfo<Value>& args) { static void SupportsFPParams(const FunctionCallbackInfo<Value>& args) {
FastCApiObject* self = UnwrapObject(*args.This()); FastCApiObject* self = UnwrapObject(args.This());
CHECK_SELF_OR_THROW(); CHECK_SELF_OR_THROW();
args.GetReturnValue().Set(self->supports_fp_params_); args.GetReturnValue().Set(self->supports_fp_params_);
} }
...@@ -220,13 +222,13 @@ class FastCApiObject { ...@@ -220,13 +222,13 @@ class FastCApiObject {
static const int kV8WrapperObjectIndex = 1; static const int kV8WrapperObjectIndex = 1;
private: private:
static bool IsValidApiObject(Object* object) { static bool IsValidApiObject(Local<Object> object) {
i::Address addr = *reinterpret_cast<i::Address*>(object); i::Address addr = *reinterpret_cast<i::Address*>(*object);
auto instance_type = i::Internals::GetInstanceType(addr); auto instance_type = i::Internals::GetInstanceType(addr);
return (instance_type == i::Internals::kJSApiObjectType || return (instance_type == i::Internals::kJSApiObjectType ||
instance_type == i::Internals::kJSSpecialApiObjectType); instance_type == i::Internals::kJSSpecialApiObjectType);
} }
static FastCApiObject* UnwrapObject(Object* object) { static FastCApiObject* UnwrapObject(Local<Object> object) {
if (!IsValidApiObject(object)) { if (!IsValidApiObject(object)) {
return nullptr; return nullptr;
} }
......
...@@ -20802,18 +20802,14 @@ THREADED_TEST(CheckIsLeafTemplateForApiObject) { ...@@ -20802,18 +20802,14 @@ THREADED_TEST(CheckIsLeafTemplateForApiObject) {
printf("Testing positive ...\n"); printf("Testing positive ...\n");
CompileRun("var obj = new f();"); CompileRun("var obj = new f();");
CHECK(templ->IsLeafTemplateForApiObject( CHECK(templ->IsLeafTemplateForApiObject(
*context->Global() context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked()));
->Get(context.local(), v8_str("obj"))
.ToLocalChecked()));
printf("Testing negative ...\n"); printf("Testing negative ...\n");
CompileRun( CompileRun(
"var obj = {};" "var obj = {};"
"obj.__proto__ = new f();"); "obj.__proto__ = new f();");
CHECK(!templ->IsLeafTemplateForApiObject( CHECK(!templ->IsLeafTemplateForApiObject(
*context->Global() context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked()));
->Get(context.local(), v8_str("obj"))
.ToLocalChecked()));
printf("Testing positive with modified prototype chain ...\n"); printf("Testing positive with modified prototype chain ...\n");
CompileRun( CompileRun(
...@@ -20822,9 +20818,7 @@ THREADED_TEST(CheckIsLeafTemplateForApiObject) { ...@@ -20822,9 +20818,7 @@ THREADED_TEST(CheckIsLeafTemplateForApiObject) {
"pro.__proto__ = obj.__proto__;" "pro.__proto__ = obj.__proto__;"
"obj.__proto__ = pro;"); "obj.__proto__ = pro;");
CHECK(templ->IsLeafTemplateForApiObject( CHECK(templ->IsLeafTemplateForApiObject(
*context->Global() context->Global()->Get(context.local(), v8_str("obj")).ToLocalChecked()));
->Get(context.local(), v8_str("obj"))
.ToLocalChecked()));
Local<FunctionTemplate> child_templ = Local<FunctionTemplate> child_templ =
FunctionTemplate::New(context->GetIsolate()); FunctionTemplate::New(context->GetIsolate());
...@@ -20835,9 +20829,9 @@ THREADED_TEST(CheckIsLeafTemplateForApiObject) { ...@@ -20835,9 +20829,9 @@ THREADED_TEST(CheckIsLeafTemplateForApiObject) {
.ToLocalChecked(); .ToLocalChecked();
printf("Testing positive for child ...\n"); printf("Testing positive for child ...\n");
CHECK(child_templ->IsLeafTemplateForApiObject(*instance)); CHECK(child_templ->IsLeafTemplateForApiObject(instance));
printf("Testing negative for parent ...\n"); printf("Testing negative for parent ...\n");
CHECK(!templ->IsLeafTemplateForApiObject(*instance)); CHECK(!templ->IsLeafTemplateForApiObject(instance));
} }
TEST(TryFinallyMessage) { TEST(TryFinallyMessage) {
...@@ -27678,7 +27672,7 @@ namespace { ...@@ -27678,7 +27672,7 @@ namespace {
template <typename Value, typename Impl, typename Ret> template <typename Value, typename Impl, typename Ret>
struct BasicApiChecker { struct BasicApiChecker {
static Ret FastCallback(v8::Value* receiver, Value argument, static Ret FastCallback(v8::Local<v8::Value> receiver, Value argument,
v8::FastApiCallbackOptions& options) { v8::FastApiCallbackOptions& options) {
// TODO(mslekova): Refactor the data checking. // TODO(mslekova): Refactor the data checking.
v8::Value* data = &(options.data); v8::Value* data = &(options.data);
...@@ -27686,7 +27680,8 @@ struct BasicApiChecker { ...@@ -27686,7 +27680,8 @@ struct BasicApiChecker {
CHECK_EQ(v8::Number::Cast(data)->Value(), 42.0); CHECK_EQ(v8::Number::Cast(data)->Value(), 42.0);
return Impl::FastCallback(receiver, argument, options); return Impl::FastCallback(receiver, argument, options);
} }
static Ret FastCallbackNoFallback(v8::Value* receiver, Value argument) { static Ret FastCallbackNoFallback(v8::Local<v8::Value> receiver,
Value argument) {
v8::FastApiCallbackOptions options = {false, {0}}; v8::FastApiCallbackOptions options = {false, {0}};
return Impl::FastCallback(receiver, argument, options); return Impl::FastCallback(receiver, argument, options);
} }
...@@ -27727,9 +27722,9 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>, void> { ...@@ -27727,9 +27722,9 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>, void> {
write_to_fallback_(write_to_fallback), write_to_fallback_(write_to_fallback),
args_count_(args_count) {} args_count_(args_count) {}
static void FastCallback(v8::Value* receiver, T argument, static void FastCallback(v8::Local<v8::Value> receiver, T argument,
v8::FastApiCallbackOptions& options) { v8::FastApiCallbackOptions& options) {
v8::Object* receiver_obj = v8::Object::Cast(receiver); v8::Object* receiver_obj = v8::Object::Cast(*receiver);
if (!IsValidUnwrapObject(receiver_obj)) { if (!IsValidUnwrapObject(receiver_obj)) {
options.fallback = 1; options.fallback = 1;
return; return;
...@@ -27777,15 +27772,16 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>, void> { ...@@ -27777,15 +27772,16 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>, void> {
}; };
struct UnexpectedObjectChecker struct UnexpectedObjectChecker
: BasicApiChecker<v8::Value*, UnexpectedObjectChecker, void> { : BasicApiChecker<v8::Local<v8::Value>, UnexpectedObjectChecker, void> {
static void FastCallback(v8::Value* receiver, v8::Value* argument, static void FastCallback(v8::Local<v8::Value> receiver,
v8::Local<v8::Value> argument,
v8::FastApiCallbackOptions& options) { v8::FastApiCallbackOptions& options) {
v8::Object* receiver_obj = v8::Object::Cast(receiver); v8::Object* receiver_obj = v8::Object::Cast(*receiver);
UnexpectedObjectChecker* receiver_ptr = UnexpectedObjectChecker* receiver_ptr =
GetInternalField<UnexpectedObjectChecker>(receiver_obj); GetInternalField<UnexpectedObjectChecker>(receiver_obj);
receiver_ptr->SetCallFast(); receiver_ptr->SetCallFast();
if (argument->IsObject()) { if (argument->IsObject()) {
v8::Object* argument_obj = v8::Object::Cast(argument); v8::Object* argument_obj = v8::Object::Cast(*argument);
CHECK(!IsValidUnwrapObject(argument_obj)); CHECK(!IsValidUnwrapObject(argument_obj));
} }
} }
...@@ -27806,18 +27802,20 @@ struct EmbedderType { ...@@ -27806,18 +27802,20 @@ struct EmbedderType {
int data; int data;
}; };
struct ApiObjectChecker : BasicApiChecker<v8::Value*, ApiObjectChecker, void> { struct ApiObjectChecker
: BasicApiChecker<v8::Local<v8::Value>, ApiObjectChecker, void> {
ApiObjectChecker(v8::FunctionTemplate* ctor, int data) ApiObjectChecker(v8::FunctionTemplate* ctor, int data)
: ctor_(ctor), initial_data_(data) {} : ctor_(ctor), initial_data_(data) {}
static void FastCallback(v8::Value* receiver, v8::Value* argument, static void FastCallback(v8::Local<v8::Value> receiver,
v8::Local<v8::Value> argument,
v8::FastApiCallbackOptions& options) { v8::FastApiCallbackOptions& options) {
v8::Object* receiver_obj = v8::Object::Cast(receiver); v8::Object* receiver_obj = v8::Object::Cast(*receiver);
ApiObjectChecker* receiver_ptr = ApiObjectChecker* receiver_ptr =
GetInternalField<ApiObjectChecker>(receiver_obj); GetInternalField<ApiObjectChecker>(receiver_obj);
receiver_ptr->SetCallFast(); receiver_ptr->SetCallFast();
v8::Object* argument_obj = v8::Object::Cast(argument); v8::Object* argument_obj = v8::Object::Cast(*argument);
EmbedderType* argument_ptr = GetInternalField<EmbedderType>(argument_obj); EmbedderType* argument_ptr = GetInternalField<EmbedderType>(argument_obj);
CHECK(receiver_ptr->ctor_->IsLeafTemplateForApiObject(argument)); CHECK(receiver_ptr->ctor_->IsLeafTemplateForApiObject(argument));
...@@ -27830,7 +27828,7 @@ struct ApiObjectChecker : BasicApiChecker<v8::Value*, ApiObjectChecker, void> { ...@@ -27830,7 +27828,7 @@ struct ApiObjectChecker : BasicApiChecker<v8::Value*, ApiObjectChecker, void> {
receiver_ptr->SetCallSlow(); receiver_ptr->SetCallSlow();
CHECK(info[0]->IsObject()); CHECK(info[0]->IsObject());
v8::Object* argument_obj = v8::Object::Cast(*info[0]); v8::Local<v8::Object> argument_obj = info[0].As<v8::Object>();
CHECK(receiver_ptr->ctor_->IsLeafTemplateForApiObject(argument_obj)); CHECK(receiver_ptr->ctor_->IsLeafTemplateForApiObject(argument_obj));
} }
...@@ -27997,9 +27995,9 @@ void CheckApiObjectArg() { ...@@ -27997,9 +27995,9 @@ void CheckApiObjectArg() {
template <typename T> template <typename T>
struct ReturnValueChecker : BasicApiChecker<T, ReturnValueChecker<T>, T> { struct ReturnValueChecker : BasicApiChecker<T, ReturnValueChecker<T>, T> {
static T FastCallback(v8::Value* receiver, T arg, static T FastCallback(v8::Local<v8::Value> receiver, T arg,
v8::FastApiCallbackOptions& options) { v8::FastApiCallbackOptions& options) {
v8::Object* receiver_obj = v8::Object::Cast(receiver); v8::Object* receiver_obj = v8::Object::Cast(*receiver);
ReturnValueChecker<T>* receiver_ptr = ReturnValueChecker<T>* receiver_ptr =
GetInternalField<ReturnValueChecker<T>>(receiver_obj); GetInternalField<ReturnValueChecker<T>>(receiver_obj);
receiver_ptr->SetCallFast(); receiver_ptr->SetCallFast();
...@@ -4070,11 +4070,11 @@ UNINITIALIZED_TEST(DetailedSourcePositionAPI_Inlining) { ...@@ -4070,11 +4070,11 @@ UNINITIALIZED_TEST(DetailedSourcePositionAPI_Inlining) {
namespace { namespace {
struct FastApiReceiver { struct FastApiReceiver {
static void FastCallback(v8::Value* receiver, int argument, static void FastCallback(v8::Local<v8::Value> receiver, int argument,
v8::FastApiCallbackOptions& options) { v8::FastApiCallbackOptions& options) {
// TODO(mslekova): The fallback is not used by the test. Replace this // TODO(mslekova): The fallback is not used by the test. Replace this
// with a CHECK. // with a CHECK.
v8::Object* receiver_obj = v8::Object::Cast(receiver); v8::Object* receiver_obj = v8::Object::Cast(*receiver);
if (!IsValidUnwrapObject(receiver_obj)) { if (!IsValidUnwrapObject(receiver_obj)) {
options.fallback = 1; options.fallback = 1;
return; return;
......
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