Skip to content

Commit 8e6d34e

Browse files
LeuisKenandycall
authored andcommitted
feat: add drop for vector value ref
1 parent 3af71e6 commit 8e6d34e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

bridge/rusty_webf_sys/src/vector_value_ref.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
*/
44
use std::ffi::*;
55
use crate::*;
6+
use crate::memory_utils::safe_free_cpp_ptr;
67

78
#[repr(C)]
89
pub struct VectorValueRef<T> {
910
pub size: i64,
1011
pub data: *const RustValue<T>
1112
}
13+
14+
impl<T> Drop for VectorValueRef<T> {
15+
fn drop(&mut self) {
16+
safe_free_cpp_ptr::<T>(self.data as *const T)
17+
}
18+
}

bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.cc.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void <%= className %>PublicMethods::Set<%= _.startCase(prop.name).replace(/ /g,
5555
<% } else { %>
5656
<%= arg.name %>_p->set<%=_.upperFirst(prop.name)%>(<%= arg.name %>-><%=_.snakeCase(prop.name)%>);
5757
<% } %>
58-
58+
5959
<% }) %>
6060

6161
<% } %>
@@ -72,7 +72,7 @@ void <%= className %>PublicMethods::Set<%= _.startCase(prop.name).replace(/ /g,
7272
<% } else if (isVectorType(method.returnType)) { %>
7373
auto vector_value = <%= _.snakeCase(className) %>-><%= method.name %>(<%= generatePublicParametersName(method.args) %>shared_exception_state->exception_state);
7474
auto vector_size = vector_value.size();
75-
WebFValue<<%= getPointerType(method.returnType.value) %>, WebFPublicMethods>* return_elements = (WebFValue<<%= getPointerType(method.returnType.value) %>, WebFPublicMethods>*)malloc(sizeof(WebFValue<<%= getPointerType(method.returnType.value) %>, WebFPublicMethods>) * vector_size);
75+
WebFValue<<%= getPointerType(method.returnType.value) %>, WebFPublicMethods>* return_elements = (WebFValue<<%= getPointerType(method.returnType.value) %>, WebFPublicMethods>*)dart_malloc(sizeof(WebFValue<<%= getPointerType(method.returnType.value) %>, WebFPublicMethods>) * vector_size);
7676
for (int i = 0; i < vector_size; i++) {
7777
<%= getPointerType(method.returnType.value) %>* entry = vector_value[i];
7878
WebFValueStatus* status_block = entry->KeepAlive();

webf/example/rust_builder/rust/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::c_void;
22
use webf_sys::event::Event;
33
use webf_sys::executing_context::ExecutingContextRustMethods;
4-
use webf_sys::{initialize_webf_api, AddEventListenerOptions, EventTargetMethods, NativeLibraryMetaData, NativeValue, RustValue};
4+
use webf_sys::{initialize_webf_api, performance, AddEventListenerOptions, EventTargetMethods, NativeLibraryMetaData, NativeValue, PerformanceMarkOptions, RustValue};
55
use webf_sys::element::Element;
66
use webf_sys::node::NodeMethods;
77

@@ -16,6 +16,23 @@ pub extern "C" fn init_webf_app(handle: RustValue<ExecutingContextRustMethods>,
1616

1717
let div_element = document.create_element("div", &exception_state).unwrap();
1818

19+
let performance = context.performance();
20+
let exception_state = context.create_exception_state();
21+
let now = performance.now(&exception_state).unwrap();
22+
let options = PerformanceMarkOptions {
23+
detail: NativeValue::new_null(),
24+
start_time: now as f64,
25+
};
26+
27+
performance.mark("abc", &options, &exception_state).unwrap();
28+
performance.mark("efg", &options, &exception_state).unwrap();
29+
30+
let entries = performance.get_entries(&exception_state).unwrap();
31+
let has_abc = entries.iter().any(|entry| entry.name() == "abc");
32+
let has_efg = entries.iter().any(|entry| entry.name() == "efg");
33+
assert!(has_abc);
34+
assert!(has_efg);
35+
1936
let event_listener_options = AddEventListenerOptions {
2037
passive: 0,
2138
once: 0,

0 commit comments

Comments
 (0)