Skip to content

Commit

Permalink
Merge 937abfd into ad972f7
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Jun 30, 2021
2 parents ad972f7 + 937abfd commit 7a64912
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 184 deletions.
8 changes: 4 additions & 4 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::{
builtins::BuiltIn,
object::ObjectInitializer,
property::Attribute,
value::{display::display_obj, RcString, Value},
BoaProfiler, Context, Result,
value::{display::display_obj, Value},
BoaProfiler, Context, JsString, Result,
};
use rustc_hash::FxHashMap;
use std::time::SystemTime;
Expand Down Expand Up @@ -137,8 +137,8 @@ pub fn formatter(data: &[Value], context: &mut Context) -> Result<String> {
/// This is the internal console object state.
#[derive(Debug, Default)]
pub(crate) struct Console {
count_map: FxHashMap<RcString, u32>,
timer_map: FxHashMap<RcString, u128>,
count_map: FxHashMap<JsString, u32>,
timer_map: FxHashMap<JsString, u128>,
groups: Vec<String>,
}

Expand Down
3 changes: 2 additions & 1 deletion boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use crate::{
builtins::BuiltIn,
object::Object,
object::ObjectInitializer,
property::{Attribute, DataDescriptor, PropertyKey},
symbol::WellKnownSymbols,
value::IntegerOrInfinity,
BoaProfiler, Context, Result, Value,
};
use crate::{object::Object, symbol::WellKnownSymbols};
use serde::Serialize;
use serde_json::{self, ser::PrettyFormatter, Serializer, Value as JSONValue};

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/object/for_in_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::value::RcString;
use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object},
gc::{Finalize, Trace},
object::{GcObject, ObjectData},
property::PropertyKey,
property::{Attribute, DataDescriptor},
BoaProfiler, Context, Result, Value,
symbol::WellKnownSymbols,
BoaProfiler, Context, JsString, Result, Value,
};
use crate::{property::PropertyKey, symbol::WellKnownSymbols};
use rustc_hash::FxHashSet;
use std::collections::VecDeque;

Expand All @@ -20,8 +20,8 @@ use std::collections::VecDeque;
#[derive(Debug, Clone, Finalize, Trace)]
pub struct ForInIterator {
object: Value,
visited_keys: FxHashSet<RcString>,
remaining_keys: VecDeque<RcString>,
visited_keys: FxHashSet<JsString>,
remaining_keys: VecDeque<JsString>,
object_was_visited: bool,
}

Expand Down
5 changes: 2 additions & 3 deletions boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use crate::{
object::{ConstructorBuilder, FunctionBuilder, GcObject, ObjectData, PROTOTYPE},
property::{Attribute, DataDescriptor},
symbol::WellKnownSymbols,
value::{RcString, Value},
BoaProfiler, Context, Result,
BoaProfiler, Context, JsString, Result, Value,
};
use regress::Regex;

Expand Down Expand Up @@ -630,7 +629,7 @@ impl RegExp {
///
/// [spec]: https://tc39.es/ecma262/#sec-regexp.prototype-@@match
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@match
pub(crate) fn r#match(this: &Value, arg: RcString, context: &mut Context) -> Result<Value> {
pub(crate) fn r#match(this: &Value, arg: JsString, context: &mut Context) -> Result<Value> {
let (matcher, flags) = if let Some(object) = this.as_object() {
let object = object.borrow();
if let Some(regex) = object.as_regexp() {
Expand Down
13 changes: 6 additions & 7 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use crate::{
object::{ConstructorBuilder, Object, ObjectData},
property::Attribute,
symbol::WellKnownSymbols,
value::{RcString, Value},
BoaProfiler, Context, Result,
BoaProfiler, Context, JsString, Result, Value,
};
use regress::Regex;
use std::{
Expand All @@ -31,7 +30,7 @@ use std::{
string::String as StdString,
};

pub(crate) fn code_point_at(string: RcString, position: i32) -> Option<(u32, u8, bool)> {
pub(crate) fn code_point_at(string: JsString, position: i32) -> Option<(u32, u8, bool)> {
let size = string.encode_utf16().count() as i32;
if position < 0 || position >= size {
return None;
Expand Down Expand Up @@ -169,7 +168,7 @@ impl String {
.clone()
}
Some(ref value) => value.to_string(context)?,
None => RcString::default(),
None => JsString::default(),
};

if new_target.is_undefined() {
Expand Down Expand Up @@ -201,7 +200,7 @@ impl String {
Ok(this)
}

fn this_string_value(this: &Value, context: &mut Context) -> Result<RcString> {
fn this_string_value(this: &Value, context: &mut Context) -> Result<JsString> {
match this {
Value::String(ref string) => return Ok(string.clone()),
Value::Object(ref object) => {
Expand Down Expand Up @@ -907,9 +906,9 @@ impl String {
/// Performs the actual string padding for padStart/End.
/// <https://tc39.es/ecma262/#sec-stringpad/>
fn string_pad(
primitive: RcString,
primitive: JsString,
max_length: i32,
fill_string: Option<RcString>,
fill_string: Option<JsString>,
at_start: bool,
) -> Value {
let primitive_length = primitive.len() as i32;
Expand Down
5 changes: 2 additions & 3 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use crate::{
},
Parser,
},
value::{RcString, Value},
BoaProfiler, Executable, Result,
BoaProfiler, Executable, JsString, Result, Value,
};

#[cfg(feature = "console")]
Expand Down Expand Up @@ -302,7 +301,7 @@ impl Context {

/// Construct a new `Symbol` with an optional description.
#[inline]
pub fn construct_symbol(&mut self, description: Option<RcString>) -> RcSymbol {
pub fn construct_symbol(&mut self, description: Option<JsString>) -> RcSymbol {
RcSymbol::from(Symbol::new(description))
}

Expand Down
3 changes: 2 additions & 1 deletion boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub mod object;
pub mod profiler;
pub mod property;
pub mod realm;
pub mod string;
pub mod symbol;
// syntax module has a lot of acronyms
#[allow(clippy::upper_case_acronyms)]
Expand All @@ -69,7 +70,7 @@ pub(crate) use crate::{exec::Executable, profiler::BoaProfiler};

// Export things to root level
#[doc(inline)]
pub use crate::{context::Context, value::Value};
pub use crate::{context::Context, string::JsString, value::Value};

use crate::syntax::{
ast::node::StatementList,
Expand Down
14 changes: 7 additions & 7 deletions boa/src/object/iter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Object, PropertyDescriptor, PropertyKey};
use crate::{symbol::RcSymbol, value::RcString};
use crate::{symbol::RcSymbol, JsString};
use std::{collections::hash_map, iter::FusedIterator};

impl Object {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Object {
#[derive(Debug, Clone)]
pub struct Iter<'a> {
indexed_properties: hash_map::Iter<'a, u32, PropertyDescriptor>,
string_properties: hash_map::Iter<'a, RcString, PropertyDescriptor>,
string_properties: hash_map::Iter<'a, JsString, PropertyDescriptor>,
symbol_properties: hash_map::Iter<'a, RcSymbol, PropertyDescriptor>,
}

Expand Down Expand Up @@ -342,10 +342,10 @@ impl FusedIterator for IndexPropertyValues<'_> {}

/// An iterator over the `String` property entries of an `Object`
#[derive(Debug, Clone)]
pub struct StringProperties<'a>(hash_map::Iter<'a, RcString, PropertyDescriptor>);
pub struct StringProperties<'a>(hash_map::Iter<'a, JsString, PropertyDescriptor>);

impl<'a> Iterator for StringProperties<'a> {
type Item = (&'a RcString, &'a PropertyDescriptor);
type Item = (&'a JsString, &'a PropertyDescriptor);

#[inline]
fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -369,10 +369,10 @@ impl FusedIterator for StringProperties<'_> {}

/// An iterator over the string keys (`RcString`) of an `Object`.
#[derive(Debug, Clone)]
pub struct StringPropertyKeys<'a>(hash_map::Keys<'a, RcString, PropertyDescriptor>);
pub struct StringPropertyKeys<'a>(hash_map::Keys<'a, JsString, PropertyDescriptor>);

impl<'a> Iterator for StringPropertyKeys<'a> {
type Item = &'a RcString;
type Item = &'a JsString;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -396,7 +396,7 @@ impl FusedIterator for StringPropertyKeys<'_> {}

/// An iterator over the string values (`Property`) of an `Object`.
#[derive(Debug, Clone)]
pub struct StringPropertyValues<'a>(hash_map::Values<'a, RcString, PropertyDescriptor>);
pub struct StringPropertyValues<'a>(hash_map::Values<'a, JsString, PropertyDescriptor>);

impl<'a> Iterator for StringPropertyValues<'a> {
type Item = &'a PropertyDescriptor;
Expand Down
22 changes: 11 additions & 11 deletions boa/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{
gc::{Finalize, Trace},
property::{AccessorDescriptor, Attribute, DataDescriptor, PropertyDescriptor, PropertyKey},
symbol::RcSymbol,
value::{RcBigInt, RcString, Value},
BoaProfiler, Context,
value::{RcBigInt, Value},
BoaProfiler, Context, JsString,
};
use rustc_hash::FxHashMap;
use std::{
Expand Down Expand Up @@ -69,7 +69,7 @@ pub struct Object {
pub data: ObjectData,
indexed_properties: FxHashMap<u32, PropertyDescriptor>,
/// Properties
string_properties: FxHashMap<RcString, PropertyDescriptor>,
string_properties: FxHashMap<JsString, PropertyDescriptor>,
/// Symbol Properties
symbol_properties: FxHashMap<RcSymbol, PropertyDescriptor>,
/// Instance prototype `__proto__`.
Expand All @@ -92,7 +92,7 @@ pub enum ObjectData {
Function(Function),
Set(OrderedSet<Value>),
SetIterator(SetIterator),
String(RcString),
String(JsString),
StringIterator(StringIterator),
Number(f64),
Symbol(RcSymbol),
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Object {
#[inline]
pub fn string<S>(value: S) -> Self
where
S: Into<RcString>,
S: Into<JsString>,
{
Self {
data: ObjectData::String(value.into()),
Expand Down Expand Up @@ -403,7 +403,7 @@ impl Object {
}

#[inline]
pub fn as_string(&self) -> Option<RcString> {
pub fn as_string(&self) -> Option<JsString> {
match self.data {
ObjectData::String(ref string) => Some(string.clone()),
_ => None,
Expand Down Expand Up @@ -618,13 +618,13 @@ impl Object {
#[derive(Debug, Clone)]
pub struct FunctionBinding {
binding: PropertyKey,
name: RcString,
name: JsString,
}

impl From<&str> for FunctionBinding {
#[inline]
fn from(name: &str) -> Self {
let name: RcString = name.into();
let name: JsString = name.into();

Self {
binding: name.clone().into(),
Expand All @@ -636,7 +636,7 @@ impl From<&str> for FunctionBinding {
impl From<String> for FunctionBinding {
#[inline]
fn from(name: String) -> Self {
let name: RcString = name.into();
let name: JsString = name.into();

Self {
binding: name.clone().into(),
Expand All @@ -645,9 +645,9 @@ impl From<String> for FunctionBinding {
}
}

impl From<RcString> for FunctionBinding {
impl From<JsString> for FunctionBinding {
#[inline]
fn from(name: RcString) -> Self {
fn from(name: JsString) -> Self {
Self {
binding: name.clone().into(),
name,
Expand Down
14 changes: 7 additions & 7 deletions boa/src/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
gc::{Finalize, Trace},
object::GcObject,
symbol::RcSymbol,
value::{RcString, Value},
JsString, Value,
};
use std::{convert::TryFrom, fmt};

Expand Down Expand Up @@ -306,14 +306,14 @@ impl PropertyDescriptor {
/// [spec]: https://tc39.es/ecma262/#sec-ispropertykey
#[derive(Trace, Finalize, Debug, Clone)]
pub enum PropertyKey {
String(RcString),
String(JsString),
Symbol(RcSymbol),
Index(u32),
}

impl From<RcString> for PropertyKey {
impl From<JsString> for PropertyKey {
#[inline]
fn from(string: RcString) -> PropertyKey {
fn from(string: JsString) -> PropertyKey {
if let Ok(index) = string.parse() {
PropertyKey::Index(index)
} else {
Expand Down Expand Up @@ -430,7 +430,7 @@ impl From<usize> for PropertyKey {
if let Ok(index) = u32::try_from(value) {
PropertyKey::Index(index)
} else {
PropertyKey::String(RcString::from(value.to_string()))
PropertyKey::String(JsString::from(value.to_string()))
}
}
}
Expand All @@ -440,7 +440,7 @@ impl From<isize> for PropertyKey {
if let Ok(index) = u32::try_from(value) {
PropertyKey::Index(index)
} else {
PropertyKey::String(RcString::from(value.to_string()))
PropertyKey::String(JsString::from(value.to_string()))
}
}
}
Expand All @@ -450,7 +450,7 @@ impl From<i32> for PropertyKey {
if let Ok(index) = u32::try_from(value) {
PropertyKey::Index(index)
} else {
PropertyKey::String(RcString::from(value.to_string()))
PropertyKey::String(JsString::from(value.to_string()))
}
}
}
Expand Down
Loading

0 comments on commit 7a64912

Please sign in to comment.