feat: Add support for Fast calls with Uint8Array (#1039)

This commit updates "v8/" submodule to "10.4-ui8-fast-api" branch
with a floated patch that adds support for Uint8Arrays in Fast API.

It's a temporary solution and the patch will be removed when
"10.6-lkgr" branch is released for "v8"
This commit is contained in:
Bartek Iwańczuk 2022-07-27 01:11:11 +02:00 committed by GitHub
parent b178f1faa0
commit 3f6f53e00d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 1 deletions

View File

@ -78,6 +78,7 @@ pub enum SequenceType {
pub enum CType {
Void = 0,
Bool,
Uint8,
Int32,
Uint32,
Int64,

View File

@ -7227,6 +7227,85 @@ fn test_fast_calls_arraybuffer() {
assert_eq!("fast", unsafe { WHO });
}
#[test]
fn test_fast_calls_typedarray() {
static mut WHO: &str = "none";
fn fast_fn(
_recv: v8::Local<v8::Object>,
data: *const fast_api::FastApiTypedArray<u8>,
) -> u32 {
unsafe { WHO = "fast" };
let first = unsafe { &*data }.get(0);
let second = unsafe { &*data }.get(1);
let third = unsafe { &*data }.get(2);
assert_eq!(first, 4);
assert_eq!(second, 5);
assert_eq!(third, 6);
let sum = first + second + third;
sum.into()
}
pub struct FastTest;
impl fast_api::FastFunction for FastTest {
fn args(&self) -> &'static [fast_api::Type] {
&[
fast_api::Type::V8Value,
fast_api::Type::TypedArray(fast_api::CType::Uint8),
]
}
fn return_type(&self) -> fast_api::CType {
fast_api::CType::Uint32
}
fn function(&self) -> *const c_void {
fast_fn as _
}
}
fn slow_fn(
scope: &mut v8::HandleScope,
_: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue,
) {
unsafe { WHO = "slow" };
rv.set(v8::Boolean::new(scope, false).into());
}
let _setup_guard = setup();
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let global = context.global(scope);
let template =
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
let name = v8::String::new(scope, "func").unwrap();
let value = template.get_function(scope).unwrap();
global.set(scope, name.into(), value.into()).unwrap();
let source = r#"
function f(data) { return func(data); }
%PrepareFunctionForOptimization(f);
const arr = new Uint8Array([4, 5, 6]);
f(arr);
"#;
eval(scope, source).unwrap();
assert_eq!("slow", unsafe { WHO });
let source = r#"
%OptimizeFunctionOnNextCall(f);
const result = f(arr);
if (result != 15) {
throw new Error("wrong result");
}
"#;
eval(scope, source).unwrap();
assert_eq!("fast", unsafe { WHO });
}
#[test]
fn test_fast_calls_reciever() {
const V8_WRAPPER_TYPE_INDEX: i32 = 0;

2
v8

@ -1 +1 @@
Subproject commit 8d0f7db90d8cbb4ee9ddf05ecceccbb0ecc549b7
Subproject commit 3b3876818b61044b7ab4009d07be16a9fd864102