Browse Source

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.
pull/2329/head
Calli 2 years ago
parent
commit
c8f6f85d61
  1. 0
      boa_engine/src/object/builtins/jsarray.rs
  2. 0
      boa_engine/src/object/builtins/jsarraybuffer.rs
  3. 2
      boa_engine/src/object/builtins/jsdataview.rs
  4. 0
      boa_engine/src/object/builtins/jsfunction.rs
  5. 34
      boa_engine/src/object/builtins/jsmap.rs
  6. 0
      boa_engine/src/object/builtins/jsmap_iterator.rs
  7. 3
      boa_engine/src/object/builtins/jsproxy.rs
  8. 2
      boa_engine/src/object/builtins/jsset.rs
  9. 0
      boa_engine/src/object/builtins/jsset_iterator.rs
  10. 0
      boa_engine/src/object/builtins/jstypedarray.rs
  11. 23
      boa_engine/src/object/builtins/mod.rs
  12. 32
      boa_engine/src/object/mod.rs
  13. 2
      boa_examples/src/bin/jsarray.rs
  14. 2
      boa_examples/src/bin/jsarraybuffer.rs
  15. 2
      boa_examples/src/bin/jsmap.rs
  16. 2
      boa_examples/src/bin/jsset.rs
  17. 2
      boa_examples/src/bin/jstypedarray.rs

0
boa_engine/src/object/jsarray.rs → boa_engine/src/object/builtins/jsarray.rs

0
boa_engine/src/object/jsarraybuffer.rs → boa_engine/src/object/builtins/jsarraybuffer.rs

2
boa_engine/src/object/jsdataview.rs → boa_engine/src/object/builtins/jsdataview.rs

@ -17,7 +17,7 @@ use std::ops::Deref;
/// # Examples /// # Examples
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::{JsArrayBuffer, JsDataView}, /// # object::builtins::{JsArrayBuffer, JsDataView},
/// # Context, JsValue /// # Context, JsValue
/// # }; /// # };
/// ///

0
boa_engine/src/object/jsfunction.rs → boa_engine/src/object/builtins/jsfunction.rs

34
boa_engine/src/object/jsmap.rs → boa_engine/src/object/builtins/jsmap.rs

@ -16,7 +16,7 @@ use std::ops::Deref;
/// Create a `JsMap` and set a new entry /// Create a `JsMap` and set a new entry
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -37,7 +37,7 @@ use std::ops::Deref;
/// Create a `JsMap` from a `JsArray` /// Create a `JsMap` from a `JsArray`
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::{JsArray, JsMap}, /// # object::builtins::{JsArray, JsMap},
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -46,7 +46,7 @@ use std::ops::Deref;
/// ///
/// // Create an array of two `[key, value]` pairs /// // Create an array of two `[key, value]` pairs
/// let js_array = JsArray::new(context); /// let js_array = JsArray::new(context);
/// ///
/// // Create a `[key, value]` pair of JsValues /// // Create a `[key, value]` pair of JsValues
/// let vec_one: Vec<JsValue> = vec![JsValue::new("first-key"), JsValue::new("first-value")]; /// let vec_one: Vec<JsValue> = vec![JsValue::new("first-key"), JsValue::new("first-value")];
/// ///
@ -72,7 +72,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -94,7 +94,7 @@ impl JsMap {
/// # Examples /// # Examples
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::{JsArray, JsMap}, /// # object::builtins::{JsArray, JsMap},
/// # Context, JsResult, JsValue, /// # Context, JsResult, JsValue,
/// # }; /// # };
/// ///
@ -103,7 +103,7 @@ impl JsMap {
/// ///
/// // Create an array of two `[key, value]` pairs /// // Create an array of two `[key, value]` pairs
/// let js_array = JsArray::new(context); /// let js_array = JsArray::new(context);
/// ///
/// // Create a `[key, value]` pair of JsValues and add it to the `JsArray` as a `JsArray` /// // Create a `[key, value]` pair of JsValues and add it to the `JsArray` as a `JsArray`
/// let vec_one: Vec<JsValue> = vec![JsValue::new("first-key"), JsValue::new("first-value")]; /// let vec_one: Vec<JsValue> = vec![JsValue::new("first-key"), JsValue::new("first-value")];
/// js_array.push(JsArray::from_iter(vec_one, context), context).unwrap(); /// js_array.push(JsArray::from_iter(vec_one, context), context).unwrap();
@ -136,7 +136,7 @@ impl JsMap {
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # builtins::map::ordered_map::OrderedMap, /// # builtins::map::ordered_map::OrderedMap,
/// # object::{JsObject, ObjectData, JsMap}, /// # object::{builtins::JsMap, JsObject, ObjectData},
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -147,7 +147,7 @@ impl JsMap {
/// context.intrinsics().constructors().map().prototype(), /// context.intrinsics().constructors().map().prototype(),
/// ObjectData::map(OrderedMap::new()) /// ObjectData::map(OrderedMap::new())
/// ); /// );
/// ///
/// // Create `JsMap` object with incoming object. /// // Create `JsMap` object with incoming object.
/// let js_map = JsMap::from_object(some_object, context).unwrap(); /// 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" /// Invalid Example - returns a `TypeError` with the message "object is not a Map"
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::{JsObject, JsArray, JsMap}, /// # object::{JsObject, builtins::{JsArray, JsMap}},
/// # Context, JsResult, JsValue, /// # Context, JsResult, JsValue,
/// # }; /// # };
/// ///
@ -166,7 +166,7 @@ impl JsMap {
/// ///
/// // Some object is an Array object, not a map object /// // Some object is an Array object, not a map object
/// assert!(JsMap::from_object(some_object.into(), context).is_err()); /// assert!(JsMap::from_object(some_object.into(), context).is_err());
/// ///
/// ``` /// ```
#[inline] #[inline]
pub fn from_object(object: JsObject, context: &mut Context) -> JsResult<Self> { pub fn from_object(object: JsObject, context: &mut Context) -> JsResult<Self> {
@ -210,7 +210,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -223,7 +223,7 @@ impl JsMap {
/// ///
/// assert_eq!(js_map.get("foo", context).unwrap(), "bar".into()); /// assert_eq!(js_map.get("foo", context).unwrap(), "bar".into());
/// assert_eq!(js_map.get(2, context).unwrap(), 4.into()) /// assert_eq!(js_map.get(2, context).unwrap(), 4.into())
/// ///
/// ``` /// ```
#[inline] #[inline]
pub fn set<K, V>(&self, key: K, value: V, context: &mut Context) -> JsResult<JsValue> pub fn set<K, V>(&self, key: K, value: V, context: &mut Context) -> JsResult<JsValue>
@ -244,7 +244,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -270,7 +270,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -300,7 +300,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -327,7 +327,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///
@ -353,7 +353,7 @@ impl JsMap {
/// ///
/// ``` /// ```
/// # use boa_engine::{ /// # use boa_engine::{
/// # object::JsMap, /// # object::builtins::JsMap,
/// # Context, JsValue, /// # Context, JsValue,
/// # }; /// # };
/// ///

0
boa_engine/src/object/jsmap_iterator.rs → boa_engine/src/object/builtins/jsmap_iterator.rs

3
boa_engine/src/object/jsproxy.rs → boa_engine/src/object/builtins/jsproxy.rs

@ -2,10 +2,11 @@ use boa_gc::{Finalize, Trace};
use crate::{ use crate::{
builtins::{function::NativeFunctionSignature, Proxy}, builtins::{function::NativeFunctionSignature, Proxy},
object::{FunctionBuilder, JsObject, JsObjectType, ObjectData},
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
use super::{FunctionBuilder, JsFunction, JsObject, JsObjectType, ObjectData}; use super::JsFunction;
/// JavaScript [`Proxy`][proxy] rust object. /// JavaScript [`Proxy`][proxy] rust object.
/// ///

2
boa_engine/src/object/jsset.rs → boa_engine/src/object/builtins/jsset.rs

@ -8,7 +8,7 @@ use crate::{
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };
// This is an wrapper for `JsSet` /// JavaScript `Set` rust object.
#[derive(Debug, Clone, Trace, Finalize)] #[derive(Debug, Clone, Trace, Finalize)]
pub struct JsSet { pub struct JsSet {
inner: JsObject, inner: JsObject,

0
boa_engine/src/object/jsset_iterator.rs → boa_engine/src/object/builtins/jsset_iterator.rs

0
boa_engine/src/object/jstypedarray.rs → boa_engine/src/object/builtins/jstypedarray.rs

23
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::*;

32
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 operations::IntegrityLevel;
pub use property_map::*; pub use property_map::*;
@ -63,30 +65,16 @@ use std::{
mod tests; mod tests;
pub(crate) mod internal_methods; pub(crate) mod internal_methods;
mod jsarray;
mod jsarraybuffer; pub mod builtins;
mod jsdataview;
mod jsfunction;
mod jsmap;
mod jsmap_iterator;
mod jsobject; mod jsobject;
mod jsproxy;
mod jsset;
mod jsset_iterator;
mod jstypedarray;
mod operations; mod operations;
mod property_map; mod property_map;
pub use jsarray::*; pub(crate) use builtins::*;
pub use jsarraybuffer::*;
pub use jsdataview::*; pub use builtins::jsproxy::JsProxyBuilder;
pub use jsfunction::*; pub use jsobject::*;
pub use jsmap::*;
pub use jsmap_iterator::*;
pub use jsproxy::*;
pub use jsset::*;
pub use jsset_iterator::*;
pub use jstypedarray::*;
pub(crate) trait JsObjectType: pub(crate) trait JsObjectType:
Into<JsValue> + Into<JsObject> + Deref<Target = JsObject> Into<JsValue> + Into<JsObject> + Deref<Target = JsObject>

2
boa_examples/src/bin/jsarray.rs

@ -1,7 +1,7 @@
// This example shows how to manipulate a Javascript array using Rust code. // This example shows how to manipulate a Javascript array using Rust code.
use boa_engine::{ use boa_engine::{
object::{FunctionBuilder, JsArray}, object::{builtins::JsArray, FunctionBuilder},
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };

2
boa_examples/src/bin/jsarraybuffer.rs

@ -1,7 +1,7 @@
// This example shows how to manipulate a Javascript array using Rust code. // This example shows how to manipulate a Javascript array using Rust code.
use boa_engine::{ use boa_engine::{
object::{JsArrayBuffer, JsDataView, JsUint32Array, JsUint8Array}, object::builtins::{JsArrayBuffer, JsDataView, JsUint32Array, JsUint8Array},
property::Attribute, property::Attribute,
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };

2
boa_examples/src/bin/jsmap.rs

@ -1,5 +1,5 @@
use boa_engine::{ use boa_engine::{
object::{JsArray, JsMap}, object::{builtins::JsArray, builtins::JsMap},
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };

2
boa_examples/src/bin/jsset.rs

@ -1,6 +1,6 @@
// This example shows how to manipulate a Javascript Set using Rust code. // This example shows how to manipulate a Javascript Set using Rust code.
#![allow(clippy::bool_assert_comparison)] #![allow(clippy::bool_assert_comparison)]
use boa_engine::{object::JsSet, Context, JsValue}; use boa_engine::{object::builtins::JsSet, Context, JsValue};
fn main() -> Result<(), JsValue> { fn main() -> Result<(), JsValue> {
// New `Context` for a new Javascript executor. // New `Context` for a new Javascript executor.

2
boa_examples/src/bin/jstypedarray.rs

@ -1,7 +1,7 @@
// This example shows how to manipulate a Javascript array using Rust code. // This example shows how to manipulate a Javascript array using Rust code.
use boa_engine::{ use boa_engine::{
object::{FunctionBuilder, JsUint8Array}, object::{builtins::JsUint8Array, FunctionBuilder},
property::Attribute, property::Attribute,
Context, JsResult, JsValue, Context, JsResult, JsValue,
}; };

Loading…
Cancel
Save