Skip to content

Commit

Permalink
Merge 2619f06 into 0c0257f
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jun 30, 2021
2 parents 0c0257f + 2619f06 commit 036a20f
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 104 deletions.
6 changes: 3 additions & 3 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
builtins::BuiltIn,
object::ObjectInitializer,
property::Attribute,
value::{display::display_obj, RcString, Value},
value::{display::display_obj, JsString, Value},
BoaProfiler, Context, Result,
};
use rustc_hash::FxHashMap;
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
6 changes: 3 additions & 3 deletions boa/src/builtins/object/for_in_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::value::RcString;
use crate::value::JsString;
use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object},
gc::{Finalize, Trace},
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
4 changes: 2 additions & 2 deletions boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
object::{ConstructorBuilder, FunctionBuilder, GcObject, ObjectData, PROTOTYPE},
property::{Attribute, DataDescriptor},
symbol::WellKnownSymbols,
value::{RcString, Value},
value::{JsString, Value},
BoaProfiler, Context, Result,
};
use regress::Regex;
Expand Down Expand Up @@ -630,7 +630,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
12 changes: 6 additions & 6 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
object::{ConstructorBuilder, Object, ObjectData},
property::Attribute,
symbol::WellKnownSymbols,
value::{RcString, Value},
value::{JsString, Value},
BoaProfiler, Context, Result,
};
use regress::Regex;
Expand All @@ -31,7 +31,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 +169,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 +201,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 +907,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
6 changes: 4 additions & 2 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
},
Parser,
},
value::{RcString, Value},
value::{JsString, Value},
BoaProfiler, Executable, Result,
};

Expand Down Expand Up @@ -302,7 +302,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 Expand Up @@ -639,6 +639,8 @@ impl Context {
#[allow(clippy::unit_arg, clippy::drop_copy)]
#[inline]
pub fn eval<T: AsRef<[u8]>>(&mut self, src: T) -> Result<Value> {
println!("Size of JsString: {}", std::mem::size_of::<JsString>(),);
println!("Size of Value: {}", std::mem::size_of::<Value>(),);
let main_timer = BoaProfiler::global().start_event("Main", "Main");
let src_bytes: &[u8] = src.as_ref();

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, value::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
20 changes: 10 additions & 10 deletions boa/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
gc::{Finalize, Trace},
property::{AccessorDescriptor, Attribute, DataDescriptor, PropertyDescriptor, PropertyKey},
symbol::RcSymbol,
value::{RcBigInt, RcString, Value},
value::{JsString, RcBigInt, Value},
BoaProfiler, Context,
};
use rustc_hash::FxHashMap;
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},
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
8 changes: 4 additions & 4 deletions boa/src/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod rcsymbol;

use crate::{
gc::{Finalize, Trace},
value::RcString,
value::JsString,
};
use std::{
cell::Cell,
Expand Down Expand Up @@ -247,18 +247,18 @@ impl WellKnownSymbols {
#[derive(Debug, Finalize, Trace, Clone, Eq, PartialOrd, Ord)]
pub struct Symbol {
pub(crate) hash: u64,
pub(crate) description: Option<RcString>,
pub(crate) description: Option<JsString>,
}

impl Symbol {
/// Create a new symbol with a specified hash and description.
fn with_hash(hash: u64, description: Option<RcString>) -> Self {
fn with_hash(hash: u64, description: Option<JsString>) -> Self {
Self { hash, description }
}

/// Create a new symbol.
#[inline]
pub fn new(description: Option<RcString>) -> Self {
pub fn new(description: Option<JsString>) -> Self {
let hash = SYMBOL_HASH_COUNT.with(|count| {
let hash = count.get();
count.set(hash + 1);
Expand Down
4 changes: 2 additions & 2 deletions boa/src/value/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl From<char> for Value {
}
}

impl From<RcString> for Value {
impl From<JsString> for Value {
#[inline]
fn from(value: RcString) -> Self {
fn from(value: JsString) -> Self {
Value::String(value)
}
}
Expand Down

0 comments on commit 036a20f

Please sign in to comment.