Commit 226fa8da authored by Gus Caplan's avatar Gus Caplan Committed by Commit Bot

[api] expose dynamic fast call api constructor

This allows fast call callbacks to be created in cases where C++
templates cannot be used, for example C or Rust.

Bug: chromium:1052746
Change-Id: I90122444297f6c00428cd7345e0c0c7eca010716
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2235914Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Gus Caplan <me@gus.host>
Cr-Commit-Position: refs/heads/master@{#68239}
parent 66faa842
......@@ -379,6 +379,11 @@ class V8_EXPORT CFunction {
return ArgUnwrap<F*>::Make(func);
}
template <typename F>
static CFunction Make(F* func, const CFunctionInfo* type_info) {
return CFunction(reinterpret_cast<const void*>(func), type_info);
}
private:
const void* address_;
const CFunctionInfo* type_info_;
......
......@@ -27270,6 +27270,44 @@ void CallWithMoreArguments() {
// Passing too many arguments should just ignore the extra ones.
CHECK_EQ(checker.result, ApiNumberChecker<int32_t>::kFastCalled);
}
class TestCFunctionInfo : public v8::CFunctionInfo {
const v8::CTypeInfo& ReturnInfo() const override {
static v8::CTypeInfo return_info =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kVoid);
return return_info;
}
unsigned int ArgumentCount() const override { return 2; }
const v8::CTypeInfo& ArgumentInfo(unsigned int index) const override {
static v8::CTypeInfo type_info0 =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kUnwrappedApiObject);
static v8::CTypeInfo type_info1 =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kBool);
switch (index) {
case 0:
return type_info0;
case 1:
return type_info1;
default:
UNREACHABLE();
}
}
};
void CheckDynamicTypeInfo() {
LocalContext env;
static TestCFunctionInfo type_info;
v8::CFunction c_func =
v8::CFunction::Make(ApiNumberChecker<bool>::CheckArgFast, &type_info);
CHECK_EQ(c_func.ArgumentCount(), 2);
CHECK_EQ(c_func.ArgumentInfo(0).GetType(),
v8::CTypeInfo::Type::kUnwrappedApiObject);
CHECK_EQ(c_func.ArgumentInfo(1).GetType(), v8::CTypeInfo::Type::kBool);
CHECK_EQ(c_func.ReturnInfo().GetType(), v8::CTypeInfo::Type::kVoid);
}
} // namespace
namespace v8 {
......@@ -27386,6 +27424,8 @@ TEST(FastApiCalls) {
CallWithLessArguments();
CallWithMoreArguments();
CheckDynamicTypeInfo();
// TODO(mslekova): Add corner cases for 64-bit values.
// TODO(mslekova): Add main cases for float and double.
// TODO(mslekova): Restructure the tests so that the fast optimized calls
......
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