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