Commit f7bcb2c5 authored by Victor Gomes's avatar Victor Gomes Committed by Commit Bot

[test] Add receiver as argument in the interpreter tests

Fix the test-interpreter and test-interpreter-instrinsics by adding the receiver
as an argument instead of relying on an undefined receiver.

Change-Id: I7af3216b915581155bc320b27a5454c78d04f1f5
Bug: v8:10325
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2102568
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66723}
parent b0bae6c7
......@@ -20,34 +20,54 @@ namespace v8 {
namespace internal {
namespace interpreter {
MaybeHandle<Object> CallInterpreter(Isolate* isolate,
Handle<JSFunction> function);
template <class... A>
static MaybeHandle<Object> CallInterpreter(Isolate* isolate,
Handle<JSFunction> function,
A... args) {
Handle<Object> argv[] = {args...};
return Execution::Call(isolate, function,
isolate->factory()->undefined_value(), sizeof...(args),
argv);
Handle<Object> receiver, A... args) {
// Pad the array with an empty handle to ensure that argv size is at least 1.
// It avoids MSVC error C2466.
Handle<Object> argv[] = {args..., Handle<Object>()};
return Execution::Call(isolate, function, receiver, sizeof...(args), argv);
}
template <class... A>
class InterpreterCallable {
public:
virtual ~InterpreterCallable() = default;
FeedbackVector vector() const { return function_->feedback_vector(); }
protected:
InterpreterCallable(Isolate* isolate, Handle<JSFunction> function)
: isolate_(isolate), function_(function) {}
virtual ~InterpreterCallable() = default;
Isolate* isolate_;
Handle<JSFunction> function_;
};
template <class... A>
class InterpreterCallableUndefinedReceiver : public InterpreterCallable<A...> {
public:
InterpreterCallableUndefinedReceiver(Isolate* isolate,
Handle<JSFunction> function)
: InterpreterCallable<A...>(isolate, function) {}
MaybeHandle<Object> operator()(A... args) {
return CallInterpreter(isolate_, function_, args...);
return CallInterpreter(this->isolate_, this->function_,
this->isolate_->factory()->undefined_value(),
args...);
}
};
FeedbackVector vector() const { return function_->feedback_vector(); }
template <class... A>
class InterpreterCallableWithReceiver : public InterpreterCallable<A...> {
public:
InterpreterCallableWithReceiver(Isolate* isolate, Handle<JSFunction> function)
: InterpreterCallable<A...>(isolate, function) {}
private:
Isolate* isolate_;
Handle<JSFunction> function_;
MaybeHandle<Object> operator()(Handle<Object> receiver, A... args) {
return CallInterpreter(this->isolate_, this->function_, receiver, args...);
}
};
class InterpreterTester {
......@@ -68,8 +88,15 @@ class InterpreterTester {
virtual ~InterpreterTester();
template <class... A>
InterpreterCallable<A...> GetCallable() {
return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>());
InterpreterCallableUndefinedReceiver<A...> GetCallable() {
return InterpreterCallableUndefinedReceiver<A...>(
isolate_, GetBytecodeFunction<A...>());
}
template <class... A>
InterpreterCallableWithReceiver<A...> GetCallableWithReceiver() {
return InterpreterCallableWithReceiver<A...>(isolate_,
GetBytecodeFunction<A...>());
}
Local<Message> CheckThrowsReturnMessage();
......
......@@ -550,7 +550,7 @@ TEST(InterpreterStringAdd) {
}
}
TEST(InterpreterParameter1) {
TEST(InterpreterReceiverParameter) {
HandleAndZoneScope handles;
Isolate* isolate = handles.main_isolate();
Zone* zone = handles.main_zone();
......@@ -559,6 +559,24 @@ TEST(InterpreterParameter1) {
builder.LoadAccumulatorWithRegister(builder.Receiver()).Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
InterpreterTester tester(isolate, bytecode_array);
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> return_val = callable(object).ToHandleChecked();
CHECK(return_val.is_identical_to(object));
}
TEST(InterpreterParameter0) {
HandleAndZoneScope handles;
Isolate* isolate = handles.main_isolate();
Zone* zone = handles.main_zone();
BytecodeArrayBuilder builder(zone, 2, 0);
builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
auto callable = tester.GetCallable<Handle<Object>>();
......@@ -607,7 +625,7 @@ TEST(InterpreterParameter8) {
InterpreterTester tester(isolate, bytecode_array, metadata);
using H = Handle<Object>;
auto callable = tester.GetCallable<H, H, H, H, H, H, H, H>();
auto callable = tester.GetCallableWithReceiver<H, H, H, H, H, H, H>();
Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(1), handles.main_isolate());
Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), handles.main_isolate());
......@@ -890,7 +908,7 @@ TEST(InterpreterUnaryOpFeedback) {
{Token::Value::DEC, smi_one, smi_min, number, bigint, str}};
for (TestCase const& test_case : kTestCases) {
i::FeedbackVectorSpec feedback_spec(zone);
BytecodeArrayBuilder builder(zone, 5, 0, &feedback_spec);
BytecodeArrayBuilder builder(zone, 6, 0, &feedback_spec);
i::FeedbackSlot slot0 = feedback_spec.AddBinaryOpICSlot();
i::FeedbackSlot slot1 = feedback_spec.AddBinaryOpICSlot();
......@@ -901,15 +919,15 @@ TEST(InterpreterUnaryOpFeedback) {
Handle<i::FeedbackMetadata> metadata =
i::NewFeedbackMetadata(isolate, &feedback_spec);
builder.LoadAccumulatorWithRegister(builder.Receiver())
builder.LoadAccumulatorWithRegister(builder.Parameter(0))
.UnaryOperation(test_case.op, GetIndex(slot0))
.LoadAccumulatorWithRegister(builder.Parameter(0))
.UnaryOperation(test_case.op, GetIndex(slot1))
.LoadAccumulatorWithRegister(builder.Parameter(1))
.UnaryOperation(test_case.op, GetIndex(slot2))
.UnaryOperation(test_case.op, GetIndex(slot1))
.LoadAccumulatorWithRegister(builder.Parameter(2))
.UnaryOperation(test_case.op, GetIndex(slot3))
.UnaryOperation(test_case.op, GetIndex(slot2))
.LoadAccumulatorWithRegister(builder.Parameter(3))
.UnaryOperation(test_case.op, GetIndex(slot3))
.LoadAccumulatorWithRegister(builder.Parameter(4))
.UnaryOperation(test_case.op, GetIndex(slot4))
.Return();
......@@ -958,7 +976,7 @@ TEST(InterpreterBitwiseTypeFeedback) {
for (Token::Value op : kBitwiseBinaryOperators) {
i::FeedbackVectorSpec feedback_spec(zone);
BytecodeArrayBuilder builder(zone, 4, 0, &feedback_spec);
BytecodeArrayBuilder builder(zone, 5, 0, &feedback_spec);
i::FeedbackSlot slot0 = feedback_spec.AddBinaryOpICSlot();
i::FeedbackSlot slot1 = feedback_spec.AddBinaryOpICSlot();
......@@ -967,10 +985,10 @@ TEST(InterpreterBitwiseTypeFeedback) {
Handle<i::FeedbackMetadata> metadata =
i::NewFeedbackMetadata(isolate, &feedback_spec);
builder.LoadAccumulatorWithRegister(builder.Receiver())
.BinaryOperation(op, builder.Parameter(0), GetIndex(slot0))
.BinaryOperation(op, builder.Parameter(1), GetIndex(slot1))
.BinaryOperation(op, builder.Parameter(2), GetIndex(slot2))
builder.LoadAccumulatorWithRegister(builder.Parameter(0))
.BinaryOperation(op, builder.Parameter(1), GetIndex(slot0))
.BinaryOperation(op, builder.Parameter(2), GetIndex(slot1))
.BinaryOperation(op, builder.Parameter(3), GetIndex(slot2))
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
......@@ -1014,7 +1032,7 @@ TEST(InterpreterParameter1Assign) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> return_val =
callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate()))
......@@ -1149,7 +1167,7 @@ TEST(InterpreterLoadNamedProperty) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
// Test IC miss.
......@@ -1203,7 +1221,7 @@ TEST(InterpreterLoadKeyedProperty) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })");
// Test IC miss.
......@@ -1246,7 +1264,7 @@ TEST(InterpreterStoreNamedProperty) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
// Test IC miss.
Handle<Object> result;
......@@ -1311,7 +1329,7 @@ TEST(InterpreterStoreKeyedProperty) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
// Test IC miss.
Handle<Object> result;
......@@ -1371,7 +1389,7 @@ TEST(InterpreterCall) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject(
"new (function Obj() { this.func = function() { return 0x265; }})()");
......@@ -1393,7 +1411,7 @@ TEST(InterpreterCall) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject(
"new (function Obj() {"
......@@ -1427,7 +1445,7 @@ TEST(InterpreterCall) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject(
"new (function Obj() { "
......@@ -1476,7 +1494,7 @@ TEST(InterpreterCall) {
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<Handle<Object>>();
auto callable = tester.GetCallableWithReceiver<>();
Handle<Object> object = InterpreterTester::NewObject(
"new (function Obj() { "
......@@ -2207,8 +2225,8 @@ TEST(InterpreterCompareTypeOf) {
LiteralFlag literal_flag = kLiterals[l];
if (literal_flag == LiteralFlag::kOther) continue;
BytecodeArrayBuilder builder(zone, 1, 0);
builder.LoadAccumulatorWithRegister(builder.Receiver())
BytecodeArrayBuilder builder(zone, 2, 0);
builder.LoadAccumulatorWithRegister(builder.Parameter(0))
.CompareTypeOf(kLiterals[l])
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
......
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