Skip to content

Truly independent web browser

LibJS: Expose promises, iterators and native functions to Rust

Shannon Booth769e4a50b372
diff --git a/Libraries/LibJS/Rust/src/api.rs b/Libraries/LibJS/Rust/src/api.rs
index 1fb763d45f2..4b307273159 100644
--- a/Libraries/LibJS/Rust/src/api.rs
+++ b/Libraries/LibJS/Rust/src/api.rs
@@ -13,6 +13,7 @@ pub use crate::embedding::host::host_object::{HostObject, host_class_of, host_da
pub use crate::gc::class::ExternalMemorySize;
pub use crate::gc::embedder_cell::{EmbedderCell, EmbedderClass, EmbedderValue};
pub use crate::gc::foreign::ForeignCellSlot;
+pub use crate::gc::gc_ref_cell::GcRefCell;
pub use crate::gc::root::{MarkedVec, Root};
pub use crate::gc::visitor::{Trace, Visitor};
pub use crate::gc::weak::GcWeak;
@@ -23,10 +24,11 @@ pub use crate::layout::host_class::JSHostClass;
pub use crate::layout::value::Value;
pub use crate::layout_forward::{RawNativeFunctionPointer, RawNativeFunctionResult};
pub use crate::raw_native;
-pub use crate::runtime::abstract_operations::{call, get_function_realm};
+pub use crate::runtime::abstract_operations::{call, construct, get_function_realm};
pub use crate::runtime::array::Array;
pub use crate::runtime::array_buffer::{
- ArrayBuffer, DataBlock, Order as ArrayBufferOrder, Shared as ArrayBufferShared,
+ ArrayBuffer, DataBlock, Order as ArrayBufferOrder, Shared as ArrayBufferShared, clone_array_buffer,
+ detach_array_buffer,
};
pub use crate::runtime::completion::{Must, Throw, ThrowCompletionOr};
pub use crate::runtime::data_view::{
@@ -36,10 +38,15 @@ pub use crate::runtime::data_view::{
pub use crate::runtime::error::ErrorKind;
pub use crate::runtime::error_types::ErrorType;
pub use crate::runtime::intrinsics::Intrinsics;
-pub use crate::runtime::iterator::{create_iterator_result_object, get_iterator_from_method_impl, iterator_step_value};
-pub use crate::runtime::native_function::RawNativeFunction;
+pub use crate::runtime::iterator::{
+ IteratorHint, IteratorRecord, create_iterator_result_object, get_iterator, get_iterator_from_method_impl,
+ iterator_complete, iterator_next, iterator_step_value, iterator_value,
+};
+pub use crate::runtime::native_function::{NativeFunction, RawNativeFunction};
pub use crate::runtime::object::Object;
pub use crate::runtime::primitive_string::PrimitiveString;
+pub use crate::runtime::promise::{Promise, PromiseState, RejectionOperation};
+pub use crate::runtime::promise_capability::{PromiseCapability, new_promise_capability};
pub use crate::runtime::property_attributes::{Attribute, PropertyAttributes};
pub use crate::runtime::property_key::PropertyKey;
pub use crate::runtime::realm::Realm;
@@ -47,7 +54,7 @@ pub use crate::runtime::typed_array::{
Kind as TypedArrayKind, TypedArrayBase, TypedArrayWithBufferWitness, create_typed_array_on_buffer,
is_typed_array_out_of_bounds, make_typed_array_with_buffer_witness_record, typed_array_byte_length,
};
-pub use crate::runtime::value::number_to_string;
+pub use crate::runtime::value::{number_to_string, same_value};
pub use crate::utf16::{Utf16Display, to_well_formed};
/// Derives Trace for a type of the embedder, which marks the type `#[gc(crate = libjs_rust)]`.
pub use libjs_runtime_macros::Trace;
diff --git a/Libraries/LibJS/Rust/src/gc/embedder_cell.rs b/Libraries/LibJS/Rust/src/gc/embedder_cell.rs
index 2d75d3bb72a..4dca984def9 100644
--- a/Libraries/LibJS/Rust/src/gc/embedder_cell.rs
+++ b/Libraries/LibJS/Rust/src/gc/embedder_cell.rs
@@ -75,8 +75,9 @@ unsafe impl<T: Trace> Trace for EmbedderCell<T> {
/// }
/// ```
///
-/// LibGC traces the cells of the class, and destroys those whose value has a destructor. It does not finalize them,
-/// and counts memory they own outside the heap only for a class that new_with_external_memory_size() creates.
+/// LibGC traces the cells of the class, and destroys those whose value has a destructor. It finalizes them only for a
+/// class that with_finalize() gives a finalize entry, and counts memory they own outside the heap only for a class that
+/// new_with_external_memory_size() creates.
pub struct EmbedderClass<T: 'static> {
class: Class,
_value: PhantomData<fn() -> T>,
@@ -99,6 +100,13 @@ impl<T: Trace + 'static> EmbedderClass<T> {
pub const fn class(&'static self) -> &'static Class {
&self.class
}
+
+ /// The class with a finalize entry, which LibGC calls with each dead cell of the class while every cell that dies
+ /// in the collection is still intact, before it destroys any. The entry must not allocate.
+ pub const fn with_finalize(mut self, finalize: unsafe extern "C" fn(cell: *mut c_void)) -> Self {
+ self.class.type_info.finalize = Some(finalize);
+ self
+ }
}
impl<T: Trace + ExternalMemorySize + 'static> EmbedderClass<T> {