Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Separate JsObjectType implementors to their own module #2324

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::ops::Deref;
/// # Examples
/// ```
/// # use boa_engine::{
/// # object::{JsArrayBuffer, JsDataView},
/// # object::builtins::{JsArrayBuffer, JsDataView},
/// # Context, JsValue
/// # };
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/// # };
///
Expand All @@ -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,
/// # };
///
Expand All @@ -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<JsValue> = vec![JsValue::new("first-key"), JsValue::new("first-value")];
///
Expand All @@ -72,7 +72,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand All @@ -94,7 +94,7 @@ impl JsMap {
/// # Examples
/// ```
/// # use boa_engine::{
/// # object::{JsArray, JsMap},
/// # object::builtins::{JsArray, JsMap},
/// # Context, JsResult, JsValue,
/// # };
///
Expand All @@ -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<JsValue> = vec![JsValue::new("first-key"), JsValue::new("first-value")];
/// js_array.push(JsArray::from_iter(vec_one, context), context).unwrap();
Expand Down Expand Up @@ -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,
/// # };
///
Expand All @@ -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();
///
Expand All @@ -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,
/// # };
///
Expand All @@ -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<Self> {
Expand Down Expand Up @@ -210,7 +210,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand All @@ -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<K, V>(&self, key: K, value: V, context: &mut Context) -> JsResult<JsValue>
Expand All @@ -244,7 +244,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand All @@ -270,7 +270,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand Down Expand Up @@ -300,7 +300,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand All @@ -327,7 +327,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand All @@ -353,7 +353,7 @@ impl JsMap {
///
/// ```
/// # use boa_engine::{
/// # object::JsMap,
/// # object::builtins::JsMap,
/// # Context, JsValue,
/// # };
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions boa_engine/src/object/builtins/mod.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 22 deletions boa_engine/src/object/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -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<JsValue> + Into<JsObject> + Deref<Target = JsObject>
Expand Down
2 changes: 1 addition & 1 deletion boa_examples/src/bin/jsarray.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion boa_examples/src/bin/jsarraybuffer.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion boa_examples/src/bin/jsmap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use boa_engine::{
object::{JsArray, JsMap},
object::{builtins::JsArray, builtins::JsMap},
Context, JsResult, JsValue,
};

Expand Down
2 changes: 1 addition & 1 deletion boa_examples/src/bin/jsset.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion boa_examples/src/bin/jstypedarray.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down