Skip to content

Commit

Permalink
Rename RcSymbol to JsString
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jun 30, 2021
1 parent ad972f7 commit 35b423b
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 141 deletions.
12 changes: 6 additions & 6 deletions boa/src/builtins/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, FunctionBuilder},
property::Attribute,
symbol::{RcSymbol, WellKnownSymbols},
symbol::{JsSymbol, WellKnownSymbols},
value::Value,
BoaProfiler, Context, Result,
};
Expand Down Expand Up @@ -130,10 +130,10 @@ impl Symbol {
_ => None,
};

Ok(context.construct_symbol(description).into())
Ok(JsSymbol::new(description).into())
}

fn this_symbol_value(value: &Value, context: &mut Context) -> Result<RcSymbol> {
fn this_symbol_value(value: &Value, context: &mut Context) -> Result<JsSymbol> {
match value {
Value::Symbol(ref symbol) => return Ok(symbol.clone()),
Value::Object(ref object) => {
Expand Down Expand Up @@ -161,8 +161,7 @@ impl Symbol {
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
let symbol = Self::this_symbol_value(this, context)?;
let description = symbol.description().unwrap_or("");
Ok(Value::from(format!("Symbol({})", description)))
Ok(symbol.to_string().into())
}

/// `get Symbol.prototype.description`
Expand All @@ -180,7 +179,8 @@ impl Symbol {
_: &[Value],
context: &mut Context,
) -> Result<Value> {
if let Some(ref description) = Self::this_symbol_value(this, context)?.description {
let symbol = Self::this_symbol_value(this, context)?;
if let Some(ref description) = symbol.description() {
Ok(description.clone().into())
} else {
Ok(Value::undefined())
Expand Down
10 changes: 1 addition & 9 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
object::{FunctionBuilder, GcObject, Object, PROTOTYPE},
property::{Attribute, DataDescriptor, PropertyKey},
realm::Realm,
symbol::{RcSymbol, Symbol},
syntax::{
ast::{
node::{
Expand All @@ -22,8 +21,7 @@ use crate::{
},
Parser,
},
value::{RcString, Value},
BoaProfiler, Executable, Result,
BoaProfiler, Executable, Result, Value,
};

#[cfg(feature = "console")]
Expand Down Expand Up @@ -300,12 +298,6 @@ impl Context {
builtins::init(self);
}

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

/// Construct an empty object.
#[inline]
pub fn construct_object(&self) -> GcObject {
Expand Down
2 changes: 1 addition & 1 deletion boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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, symbol::JsSymbol, 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::{value::RcString, JsSymbol};
use std::{collections::hash_map, iter::FusedIterator};

impl Object {
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Object {
pub struct Iter<'a> {
indexed_properties: hash_map::Iter<'a, u32, PropertyDescriptor>,
string_properties: hash_map::Iter<'a, RcString, PropertyDescriptor>,
symbol_properties: hash_map::Iter<'a, RcSymbol, PropertyDescriptor>,
symbol_properties: hash_map::Iter<'a, JsSymbol, PropertyDescriptor>,
}

impl<'a> Iterator for Iter<'a> {
Expand Down Expand Up @@ -180,10 +180,10 @@ impl FusedIterator for Values<'_> {}

/// An iterator over the `Symbol` property entries of an `Object`
#[derive(Debug, Clone)]
pub struct SymbolProperties<'a>(hash_map::Iter<'a, RcSymbol, PropertyDescriptor>);
pub struct SymbolProperties<'a>(hash_map::Iter<'a, JsSymbol, PropertyDescriptor>);

impl<'a> Iterator for SymbolProperties<'a> {
type Item = (&'a RcSymbol, &'a PropertyDescriptor);
type Item = (&'a JsSymbol, &'a PropertyDescriptor);

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

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

impl<'a> Iterator for SymbolPropertyKeys<'a> {
type Item = &'a RcSymbol;
type Item = &'a JsSymbol;

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

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

impl<'a> Iterator for SymbolPropertyValues<'a> {
type Item = &'a PropertyDescriptor;
Expand Down
9 changes: 4 additions & 5 deletions boa/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use crate::{
context::StandardConstructor,
gc::{Finalize, Trace},
property::{AccessorDescriptor, Attribute, DataDescriptor, PropertyDescriptor, PropertyKey},
symbol::RcSymbol,
value::{RcBigInt, RcString, Value},
BoaProfiler, Context,
BoaProfiler, Context, JsSymbol,
};
use rustc_hash::FxHashMap;
use std::{
Expand Down Expand Up @@ -71,7 +70,7 @@ pub struct Object {
/// Properties
string_properties: FxHashMap<RcString, PropertyDescriptor>,
/// Symbol Properties
symbol_properties: FxHashMap<RcSymbol, PropertyDescriptor>,
symbol_properties: FxHashMap<JsSymbol, PropertyDescriptor>,
/// Instance prototype `__proto__`.
prototype: Value,
/// Whether it can have new properties added to it.
Expand All @@ -95,7 +94,7 @@ pub enum ObjectData {
String(RcString),
StringIterator(StringIterator),
Number(f64),
Symbol(RcSymbol),
Symbol(JsSymbol),
Error,
Ordinary,
Date(Date),
Expand Down Expand Up @@ -431,7 +430,7 @@ impl Object {
}

#[inline]
pub fn as_symbol(&self) -> Option<RcSymbol> {
pub fn as_symbol(&self) -> Option<JsSymbol> {
match self.data {
ObjectData::Symbol(ref symbol) => Some(symbol.clone()),
_ => None,
Expand Down
8 changes: 4 additions & 4 deletions boa/src/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use crate::{
gc::{Finalize, Trace},
object::GcObject,
symbol::RcSymbol,
value::{RcString, Value},
JsSymbol,
};
use std::{convert::TryFrom, fmt};

Expand Down Expand Up @@ -307,7 +307,7 @@ impl PropertyDescriptor {
#[derive(Trace, Finalize, Debug, Clone)]
pub enum PropertyKey {
String(RcString),
Symbol(RcSymbol),
Symbol(JsSymbol),
Index(u32),
}

Expand Down Expand Up @@ -355,9 +355,9 @@ impl From<Box<str>> for PropertyKey {
}
}

impl From<RcSymbol> for PropertyKey {
impl From<JsSymbol> for PropertyKey {
#[inline]
fn from(symbol: RcSymbol) -> PropertyKey {
fn from(symbol: JsSymbol) -> PropertyKey {
PropertyKey::Symbol(symbol)
}
}
Expand Down
Loading

0 comments on commit 35b423b

Please sign in to comment.