From c8f6f85d61c3b50b3a725eca5763eac64e6034be Mon Sep 17 00:00:00 2001 From: Calli Date: Sat, 8 Oct 2022 16:57:05 +0000 Subject: [PATCH] Separate JsObjectType implementors to their own module (#2324) This Pull Request closes #2080. It moves all implementors of the `JsObjectType` trait into their own `js_object` module. This should simplify documentation and by doing a `pub(crate)` export in `object` little to no imports within the crate need to be changed, simplifying the usage of this module within the boa_engine crate. Documentation within the `object` module has been updated to reflect this change and in a way that it is shown on the home page of the documentation. --- .../src/object/{ => builtins}/jsarray.rs | 0 .../object/{ => builtins}/jsarraybuffer.rs | 0 .../src/object/{ => builtins}/jsdataview.rs | 2 +- .../src/object/{ => builtins}/jsfunction.rs | 0 boa_engine/src/object/{ => builtins}/jsmap.rs | 34 +++++++++---------- .../object/{ => builtins}/jsmap_iterator.rs | 0 .../src/object/{ => builtins}/jsproxy.rs | 3 +- boa_engine/src/object/{ => builtins}/jsset.rs | 2 +- .../object/{ => builtins}/jsset_iterator.rs | 0 .../src/object/{ => builtins}/jstypedarray.rs | 0 boa_engine/src/object/builtins/mod.rs | 23 +++++++++++++ boa_engine/src/object/mod.rs | 32 ++++++----------- boa_examples/src/bin/jsarray.rs | 2 +- boa_examples/src/bin/jsarraybuffer.rs | 2 +- boa_examples/src/bin/jsmap.rs | 2 +- boa_examples/src/bin/jsset.rs | 2 +- boa_examples/src/bin/jstypedarray.rs | 2 +- 17 files changed, 59 insertions(+), 47 deletions(-) rename boa_engine/src/object/{ => builtins}/jsarray.rs (100%) rename boa_engine/src/object/{ => builtins}/jsarraybuffer.rs (100%) rename boa_engine/src/object/{ => builtins}/jsdataview.rs (99%) rename boa_engine/src/object/{ => builtins}/jsfunction.rs (100%) rename boa_engine/src/object/{ => builtins}/jsmap.rs (95%) rename boa_engine/src/object/{ => builtins}/jsmap_iterator.rs (100%) rename boa_engine/src/object/{ => builtins}/jsproxy.rs (99%) rename boa_engine/src/object/{ => builtins}/jsset.rs (99%) rename boa_engine/src/object/{ => builtins}/jsset_iterator.rs (100%) rename boa_engine/src/object/{ => builtins}/jstypedarray.rs (100%) create mode 100644 boa_engine/src/object/builtins/mod.rs diff --git a/boa_engine/src/object/jsarray.rs b/boa_engine/src/object/builtins/jsarray.rs similarity index 100% rename from boa_engine/src/object/jsarray.rs rename to boa_engine/src/object/builtins/jsarray.rs diff --git a/boa_engine/src/object/jsarraybuffer.rs b/boa_engine/src/object/builtins/jsarraybuffer.rs similarity index 100% rename from boa_engine/src/object/jsarraybuffer.rs rename to boa_engine/src/object/builtins/jsarraybuffer.rs diff --git a/boa_engine/src/object/jsdataview.rs b/boa_engine/src/object/builtins/jsdataview.rs similarity index 99% rename from boa_engine/src/object/jsdataview.rs rename to boa_engine/src/object/builtins/jsdataview.rs index 2a321ce8f4..2f15fa3db8 100644 --- a/boa_engine/src/object/jsdataview.rs +++ b/boa_engine/src/object/builtins/jsdataview.rs @@ -17,7 +17,7 @@ use std::ops::Deref; /// # Examples /// ``` /// # use boa_engine::{ -/// # object::{JsArrayBuffer, JsDataView}, +/// # object::builtins::{JsArrayBuffer, JsDataView}, /// # Context, JsValue /// # }; /// diff --git a/boa_engine/src/object/jsfunction.rs b/boa_engine/src/object/builtins/jsfunction.rs similarity index 100% rename from boa_engine/src/object/jsfunction.rs rename to boa_engine/src/object/builtins/jsfunction.rs diff --git a/boa_engine/src/object/jsmap.rs b/boa_engine/src/object/builtins/jsmap.rs similarity index 95% rename from boa_engine/src/object/jsmap.rs rename to boa_engine/src/object/builtins/jsmap.rs index 885929c708..a689c87659 100644 --- a/boa_engine/src/object/jsmap.rs +++ b/boa_engine/src/object/builtins/jsmap.rs @@ -16,7 +16,7 @@ use std::ops::Deref; /// Create a `JsMap` and set a new entry /// ``` /// # use boa_engine::{ -/// # object::JsMap, +/// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -37,7 +37,7 @@ use std::ops::Deref; /// Create a `JsMap` from a `JsArray` /// ``` /// # use boa_engine::{ -/// # object::{JsArray, JsMap}, +/// # object::builtins::{JsArray, JsMap}, /// # Context, JsValue, /// # }; /// @@ -46,7 +46,7 @@ use std::ops::Deref; /// /// // Create an array of two `[key, value]` pairs /// let js_array = JsArray::new(context); -/// +/// /// // Create a `[key, value]` pair of JsValues /// let vec_one: Vec = vec![JsValue::new("first-key"), JsValue::new("first-value")]; /// @@ -72,7 +72,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -94,7 +94,7 @@ impl JsMap { /// # Examples /// ``` /// # use boa_engine::{ - /// # object::{JsArray, JsMap}, + /// # object::builtins::{JsArray, JsMap}, /// # Context, JsResult, JsValue, /// # }; /// @@ -103,7 +103,7 @@ impl JsMap { /// /// // Create an array of two `[key, value]` pairs /// let js_array = JsArray::new(context); - /// + /// /// // Create a `[key, value]` pair of JsValues and add it to the `JsArray` as a `JsArray` /// let vec_one: Vec = vec![JsValue::new("first-key"), JsValue::new("first-value")]; /// js_array.push(JsArray::from_iter(vec_one, context), context).unwrap(); @@ -136,7 +136,7 @@ impl JsMap { /// ``` /// # use boa_engine::{ /// # builtins::map::ordered_map::OrderedMap, - /// # object::{JsObject, ObjectData, JsMap}, + /// # object::{builtins::JsMap, JsObject, ObjectData}, /// # Context, JsValue, /// # }; /// @@ -147,7 +147,7 @@ impl JsMap { /// context.intrinsics().constructors().map().prototype(), /// ObjectData::map(OrderedMap::new()) /// ); - /// + /// /// // Create `JsMap` object with incoming object. /// let js_map = JsMap::from_object(some_object, context).unwrap(); /// @@ -156,7 +156,7 @@ impl JsMap { /// Invalid Example - returns a `TypeError` with the message "object is not a Map" /// ``` /// # use boa_engine::{ - /// # object::{JsObject, JsArray, JsMap}, + /// # object::{JsObject, builtins::{JsArray, JsMap}}, /// # Context, JsResult, JsValue, /// # }; /// @@ -166,7 +166,7 @@ impl JsMap { /// /// // Some object is an Array object, not a map object /// assert!(JsMap::from_object(some_object.into(), context).is_err()); - /// + /// /// ``` #[inline] pub fn from_object(object: JsObject, context: &mut Context) -> JsResult { @@ -210,7 +210,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -223,7 +223,7 @@ impl JsMap { /// /// assert_eq!(js_map.get("foo", context).unwrap(), "bar".into()); /// assert_eq!(js_map.get(2, context).unwrap(), 4.into()) - /// + /// /// ``` #[inline] pub fn set(&self, key: K, value: V, context: &mut Context) -> JsResult @@ -244,7 +244,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -270,7 +270,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -300,7 +300,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -327,7 +327,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// @@ -353,7 +353,7 @@ impl JsMap { /// /// ``` /// # use boa_engine::{ - /// # object::JsMap, + /// # object::builtins::JsMap, /// # Context, JsValue, /// # }; /// diff --git a/boa_engine/src/object/jsmap_iterator.rs b/boa_engine/src/object/builtins/jsmap_iterator.rs similarity index 100% rename from boa_engine/src/object/jsmap_iterator.rs rename to boa_engine/src/object/builtins/jsmap_iterator.rs diff --git a/boa_engine/src/object/jsproxy.rs b/boa_engine/src/object/builtins/jsproxy.rs similarity index 99% rename from boa_engine/src/object/jsproxy.rs rename to boa_engine/src/object/builtins/jsproxy.rs index ad9a65867d..760d68e720 100644 --- a/boa_engine/src/object/jsproxy.rs +++ b/boa_engine/src/object/builtins/jsproxy.rs @@ -2,10 +2,11 @@ use boa_gc::{Finalize, Trace}; use crate::{ builtins::{function::NativeFunctionSignature, Proxy}, + object::{FunctionBuilder, JsObject, JsObjectType, ObjectData}, Context, JsResult, JsValue, }; -use super::{FunctionBuilder, JsFunction, JsObject, JsObjectType, ObjectData}; +use super::JsFunction; /// JavaScript [`Proxy`][proxy] rust object. /// diff --git a/boa_engine/src/object/jsset.rs b/boa_engine/src/object/builtins/jsset.rs similarity index 99% rename from boa_engine/src/object/jsset.rs rename to boa_engine/src/object/builtins/jsset.rs index 4f521a6637..ce2e35b17c 100644 --- a/boa_engine/src/object/jsset.rs +++ b/boa_engine/src/object/builtins/jsset.rs @@ -8,7 +8,7 @@ use crate::{ Context, JsResult, JsValue, }; -// This is an wrapper for `JsSet` +/// JavaScript `Set` rust object. #[derive(Debug, Clone, Trace, Finalize)] pub struct JsSet { inner: JsObject, diff --git a/boa_engine/src/object/jsset_iterator.rs b/boa_engine/src/object/builtins/jsset_iterator.rs similarity index 100% rename from boa_engine/src/object/jsset_iterator.rs rename to boa_engine/src/object/builtins/jsset_iterator.rs diff --git a/boa_engine/src/object/jstypedarray.rs b/boa_engine/src/object/builtins/jstypedarray.rs similarity index 100% rename from boa_engine/src/object/jstypedarray.rs rename to boa_engine/src/object/builtins/jstypedarray.rs diff --git a/boa_engine/src/object/builtins/mod.rs b/boa_engine/src/object/builtins/mod.rs new file mode 100644 index 0000000000..5c1b24b3d2 --- /dev/null +++ b/boa_engine/src/object/builtins/mod.rs @@ -0,0 +1,23 @@ +//! Contains all the Rust representations of JavaScript objects. + +mod jsarray; +mod jsarraybuffer; +mod jsdataview; +mod jsfunction; +mod jsmap; +mod jsmap_iterator; +pub(crate) mod jsproxy; +mod jsset; +mod jsset_iterator; +mod jstypedarray; + +pub use jsarray::*; +pub use jsarraybuffer::*; +pub use jsdataview::*; +pub use jsfunction::*; +pub use jsmap::*; +pub use jsmap_iterator::*; +pub use jsproxy::{JsProxy, JsRevocableProxy}; +pub use jsset::*; +pub use jsset_iterator::*; +pub use jstypedarray::*; diff --git a/boa_engine/src/object/mod.rs b/boa_engine/src/object/mod.rs index 98d1545018..0535710028 100644 --- a/boa_engine/src/object/mod.rs +++ b/boa_engine/src/object/mod.rs @@ -1,6 +1,8 @@ -//! This module implements the Rust representation of a JavaScript object. +//! This module implements the Rust representation of a JavaScript object, see object::[builtins] for implementors. +//! +//! This module also provides helper objects for working with JavaScript objects. -pub use jsobject::{JsObject, RecursionLimiter, Ref, RefMut}; +pub use jsobject::{RecursionLimiter, Ref, RefMut}; pub use operations::IntegrityLevel; pub use property_map::*; @@ -63,30 +65,16 @@ use std::{ mod tests; pub(crate) mod internal_methods; -mod jsarray; -mod jsarraybuffer; -mod jsdataview; -mod jsfunction; -mod jsmap; -mod jsmap_iterator; + +pub mod builtins; mod jsobject; -mod jsproxy; -mod jsset; -mod jsset_iterator; -mod jstypedarray; mod operations; mod property_map; -pub use jsarray::*; -pub use jsarraybuffer::*; -pub use jsdataview::*; -pub use jsfunction::*; -pub use jsmap::*; -pub use jsmap_iterator::*; -pub use jsproxy::*; -pub use jsset::*; -pub use jsset_iterator::*; -pub use jstypedarray::*; +pub(crate) use builtins::*; + +pub use builtins::jsproxy::JsProxyBuilder; +pub use jsobject::*; pub(crate) trait JsObjectType: Into + Into + Deref diff --git a/boa_examples/src/bin/jsarray.rs b/boa_examples/src/bin/jsarray.rs index 2b369e109d..1159a57dbd 100644 --- a/boa_examples/src/bin/jsarray.rs +++ b/boa_examples/src/bin/jsarray.rs @@ -1,7 +1,7 @@ // This example shows how to manipulate a Javascript array using Rust code. use boa_engine::{ - object::{FunctionBuilder, JsArray}, + object::{builtins::JsArray, FunctionBuilder}, Context, JsResult, JsValue, }; diff --git a/boa_examples/src/bin/jsarraybuffer.rs b/boa_examples/src/bin/jsarraybuffer.rs index 24263308e6..f0c0d8306e 100644 --- a/boa_examples/src/bin/jsarraybuffer.rs +++ b/boa_examples/src/bin/jsarraybuffer.rs @@ -1,7 +1,7 @@ // This example shows how to manipulate a Javascript array using Rust code. use boa_engine::{ - object::{JsArrayBuffer, JsDataView, JsUint32Array, JsUint8Array}, + object::builtins::{JsArrayBuffer, JsDataView, JsUint32Array, JsUint8Array}, property::Attribute, Context, JsResult, JsValue, }; diff --git a/boa_examples/src/bin/jsmap.rs b/boa_examples/src/bin/jsmap.rs index df18bebb7d..928d8c6672 100644 --- a/boa_examples/src/bin/jsmap.rs +++ b/boa_examples/src/bin/jsmap.rs @@ -1,5 +1,5 @@ use boa_engine::{ - object::{JsArray, JsMap}, + object::{builtins::JsArray, builtins::JsMap}, Context, JsResult, JsValue, }; diff --git a/boa_examples/src/bin/jsset.rs b/boa_examples/src/bin/jsset.rs index 1300320dc2..b9cc0f424b 100644 --- a/boa_examples/src/bin/jsset.rs +++ b/boa_examples/src/bin/jsset.rs @@ -1,6 +1,6 @@ // This example shows how to manipulate a Javascript Set using Rust code. #![allow(clippy::bool_assert_comparison)] -use boa_engine::{object::JsSet, Context, JsValue}; +use boa_engine::{object::builtins::JsSet, Context, JsValue}; fn main() -> Result<(), JsValue> { // New `Context` for a new Javascript executor. diff --git a/boa_examples/src/bin/jstypedarray.rs b/boa_examples/src/bin/jstypedarray.rs index e10b788e5f..cf9f1cdfb0 100644 --- a/boa_examples/src/bin/jstypedarray.rs +++ b/boa_examples/src/bin/jstypedarray.rs @@ -1,7 +1,7 @@ // This example shows how to manipulate a Javascript array using Rust code. use boa_engine::{ - object::{FunctionBuilder, JsUint8Array}, + object::{builtins::JsUint8Array, FunctionBuilder}, property::Attribute, Context, JsResult, JsValue, };