Commit a19f41db authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[compiler] Make fast API test functions more robust

This CL adds handling of unexpected argument types to the functions
provided by d8.test.fast_c_api.

Bug: chromium:1196598
Change-Id: I7c62280f168817b73e89fdb7457ee9054b51a318
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2808948Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73852}
parent efe39d2b
......@@ -51,24 +51,24 @@ class FastCApiObject {
HandleScope handle_scope(isolate);
double sum = 0;
if (args.Length() > 1) {
if (args.Length() > 1 && args[1]->IsInt32()) {
sum += args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
}
if (args.Length() > 2) {
if (args.Length() > 2 && args[2]->IsUint32()) {
sum += args[2]->Uint32Value(isolate->GetCurrentContext()).FromJust();
}
if (args.Length() > 3) {
if (args.Length() > 3 && args[3]->IsNumber()) {
sum += args[3]->IntegerValue(isolate->GetCurrentContext()).FromJust();
}
if (args.Length() > 4) {
if (args.Length() > 4 && args[4]->IsNumber()) {
sum += args[4]->IntegerValue(isolate->GetCurrentContext()).FromJust();
}
if (args.Length() > 5) {
if (args.Length() > 5 && args[5]->IsNumber()) {
sum += args[5]->NumberValue(isolate->GetCurrentContext()).FromJust();
} else {
sum += std::numeric_limits<double>::quiet_NaN();
}
if (args.Length() > 6) {
if (args.Length() > 6 && args[6]->IsNumber()) {
sum += args[6]->NumberValue(isolate->GetCurrentContext()).FromJust();
} else {
sum += std::numeric_limits<double>::quiet_NaN();
......@@ -101,10 +101,10 @@ class FastCApiObject {
HandleScope handle_scope(isolate);
double sum = 0;
if (args.Length() > 1) {
if (args.Length() > 1 && args[1]->IsInt32()) {
sum += args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
}
if (args.Length() > 2) {
if (args.Length() > 2 && args[2]->IsUint32()) {
sum += args[2]->Uint32Value(isolate->GetCurrentContext()).FromJust();
}
......
......@@ -132,6 +132,19 @@ fast_c_api.reset_counts();
assertEquals(Math.round(-42 + 3.14), add_32bit_int_mismatch(false, -42, 3.14));
assertEquals(1, fast_c_api.fast_call_count());
// Test that passing arguments non-convertible to number falls down the slow path.
fast_c_api.reset_counts();
assertEquals(0, add_32bit_int_mismatch(false, -4294967296, Symbol()));
assertEquals(1, fast_c_api.slow_call_count());
assertEquals(0, fast_c_api.fast_call_count());
assertUnoptimized(add_32bit_int_mismatch);
// Optimize again.
%PrepareFunctionForOptimization(add_32bit_int_mismatch);
%OptimizeFunctionOnNextCall(add_32bit_int_mismatch);
assertEquals(add_32bit_int_result, add_32bit_int_mismatch(false, -42, 45));
assertOptimized(add_32bit_int_mismatch);
// Test that passing too few argument falls down the slow path,
// because it's an argument type mismatch (undefined vs. int).
fast_c_api.reset_counts();
......
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