Skip to content

Commit

Permalink
Merge 935ac2a into 4ae939a
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Jun 16, 2020
2 parents 4ae939a + 935ac2a commit 0813346
Show file tree
Hide file tree
Showing 25 changed files with 460 additions and 434 deletions.
9 changes: 5 additions & 4 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
builtins::{
object::{ObjectData, INSTANCE_PROTOTYPE, PROTOTYPE},
property::Property,
value::{same_value_zero, ResultValue, Value, ValueData},
value::{same_value_zero, ResultValue, Value},
},
exec::Interpreter,
BoaProfiler,
Expand Down Expand Up @@ -305,12 +305,13 @@ impl Array {
String::from(",")
} else {
ctx.to_string(args.get(0).expect("Could not get argument"))?
.to_string()
};

let mut elem_strs: Vec<String> = Vec::new();
let mut elem_strs = Vec::new();
let length = i32::from(&this.get_field("length"));
for n in 0..length {
let elem_str: String = ctx.to_string(&this.get_field(n.to_string()))?;
let elem_str = ctx.to_string(&this.get_field(n.to_string()))?.to_string();
elem_strs.push(elem_str);
}

Expand Down Expand Up @@ -353,7 +354,7 @@ impl Array {
// 4.
let join = ctx.call(&method, this, &arguments)?;

let string = if let ValueData::String(ref s) = join.data() {
let string = if let Value::String(ref s) = join {
Value::from(s.as_str())
} else {
Value::from("")
Expand Down
8 changes: 4 additions & 4 deletions boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
builtins::{
function::{make_builtin_fn, make_constructor_fn},
object::ObjectData,
value::{ResultValue, Value, ValueData},
value::{ResultValue, Value},
},
exec::Interpreter,
BoaProfiler,
Expand Down Expand Up @@ -62,14 +62,14 @@ impl BigInt {
/// [spec]: https://tc39.es/ecma262/#sec-thisbigintvalue
#[inline]
fn this_bigint_value(value: &Value, ctx: &mut Interpreter) -> Result<Self, Value> {
match value.data() {
match value {
// 1. If Type(value) is BigInt, return value.
ValueData::BigInt(ref bigint) => return Ok(bigint.clone()),
Value::BigInt(ref bigint) => return Ok(bigint.clone()),

// 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then
// a. Assert: Type(value.[[BigIntData]]) is BigInt.
// b. Return value.[[BigIntData]].
ValueData::Object(ref object) => {
Value::Object(ref object) => {
if let ObjectData::BigInt(ref bigint) = object.borrow().data {
return Ok(bigint.clone());
}
Expand Down
8 changes: 4 additions & 4 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::function::{make_builtin_fn, make_constructor_fn};
use crate::{
builtins::{
object::ObjectData,
value::{ResultValue, Value, ValueData},
value::{ResultValue, Value},
},
exec::Interpreter,
BoaProfiler,
Expand All @@ -40,9 +40,9 @@ impl Boolean {
///
/// [spec]: https://tc39.es/ecma262/#sec-thisbooleanvalue
fn this_boolean_value(value: &Value, ctx: &mut Interpreter) -> Result<bool, Value> {
match value.data() {
ValueData::Boolean(boolean) => return Ok(*boolean),
ValueData::Object(ref object) => {
match value {
Value::Boolean(boolean) => return Ok(*boolean),
Value::Object(ref object) => {
let object = object.borrow();
if let Some(boolean) = object.as_boolean() {
return Ok(boolean);
Expand Down
20 changes: 10 additions & 10 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::{
function::make_builtin_fn,
object::InternalState,
value::{display_obj, ResultValue, Value},
value::{display_obj, RcString, ResultValue, Value},
},
exec::Interpreter,
BoaProfiler,
Expand All @@ -31,8 +31,8 @@ use std::time::SystemTime;
/// This is the internal console object state.
#[derive(Debug, Default)]
pub struct ConsoleState {
count_map: FxHashMap<String, u32>,
timer_map: FxHashMap<String, u128>,
count_map: FxHashMap<RcString, u32>,
timer_map: FxHashMap<RcString, u128>,
groups: Vec<String>,
}

Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn formatter(data: &[Value], ctx: &mut Interpreter) -> Result<String, Value>
let target = ctx.to_string(&data.get(0).cloned().unwrap_or_default())?;
match data.len() {
0 => Ok(String::new()),
1 => Ok(target),
1 => Ok(target.to_string()),
_ => {
let mut formatted = String::new();
let mut arg_index = 1;
Expand Down Expand Up @@ -315,7 +315,7 @@ pub fn warn(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultVa
pub fn count(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
let label = match args.get(0) {
Some(value) => ctx.to_string(value)?,
None => "default".to_owned(),
None => "default".into(),
};

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand All @@ -342,7 +342,7 @@ pub fn count(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultV
pub fn count_reset(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
let label = match args.get(0) {
Some(value) => ctx.to_string(value)?,
None => "default".to_owned(),
None => "default".into(),
};

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -375,7 +375,7 @@ fn system_time_in_ms() -> u128 {
pub fn time(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
let label = match args.get(0) {
Some(value) => ctx.to_string(value)?,
None => "default".to_owned(),
None => "default".into(),
};

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -406,7 +406,7 @@ pub fn time(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultVa
pub fn time_log(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
let label = match args.get(0) {
Some(value) => ctx.to_string(value)?,
None => "default".to_owned(),
None => "default".into(),
};

this.with_internal_state_mut(|state: &mut ConsoleState| {
Expand Down Expand Up @@ -441,11 +441,11 @@ pub fn time_log(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> Resu
pub fn time_end(this: &mut Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
let label = match args.get(0) {
Some(value) => ctx.to_string(value)?,
None => "default".to_owned(),
None => "default".into(),
};

this.with_internal_state_mut(|state: &mut ConsoleState| {
if let Some(t) = state.timer_map.remove(&label) {
if let Some(t) = state.timer_map.remove(label.as_str()) {
let time = system_time_in_ms();
logger(
LogMessage::Info(format!("{}: {} ms - timer removed", label, time - t)),
Expand Down
5 changes: 3 additions & 2 deletions boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
array::Array,
object::{Object, ObjectData, INSTANCE_PROTOTYPE, PROTOTYPE},
property::Property,
value::{ResultValue, Value},
value::{RcString, ResultValue, Value},
},
environment::function_environment_record::BindingStatus,
environment::lexical_environment::{new_function_environment, Environment},
Expand Down Expand Up @@ -377,7 +377,8 @@ pub fn create_unmapped_arguments_object(arguments_list: &[Value]) -> Value {
.writable(true)
.configurable(true);

obj.properties_mut().insert(index.to_string(), prop);
obj.properties_mut()
.insert(RcString::from(index.to_string()), prop);
index += 1;
}

Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Json {
Property::default().value(ctx.call(
replacer,
&mut this_arg,
&[Value::string(key), val.clone()],
&[Value::from(key.clone()), val.clone()],
)?),
);
}
Expand Down
28 changes: 14 additions & 14 deletions boa/src/builtins/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{
object::ObjectData,
};
use crate::{
builtins::value::{ResultValue, Value, ValueData},
builtins::value::{ResultValue, Value},
exec::Interpreter,
BoaProfiler,
};
Expand Down Expand Up @@ -57,10 +57,10 @@ impl Number {
///
/// [spec]: https://tc39.es/ecma262/#sec-thisnumbervalue
fn this_number_value(value: &Value, ctx: &mut Interpreter) -> Result<f64, Value> {
match *value.data() {
ValueData::Integer(integer) => return Ok(f64::from(integer)),
ValueData::Rational(rational) => return Ok(rational),
ValueData::Object(ref object) => {
match *value {
Value::Integer(integer) => return Ok(f64::from(integer)),
Value::Rational(rational) => return Ok(rational),
Value::Object(ref object) => {
if let Some(number) = object.borrow().as_number() {
return Ok(number);
}
Expand Down Expand Up @@ -431,7 +431,7 @@ impl Number {
) -> ResultValue {
if let (Some(val), r) = (args.get(0), args.get(1)) {
let mut radix = if let Some(rx) = r {
if let ValueData::Integer(i) = rx.data() {
if let Value::Integer(i) = rx {
*i as u32
} else {
// Handling a second argument that isn't an integer but was provided so cannot be defaulted.
Expand All @@ -442,8 +442,8 @@ impl Number {
0
};

match val.data() {
ValueData::String(s) => {
match val {
Value::String(s) => {
// Attempt to infer radix from given string.

if radix == 0 {
Expand All @@ -466,8 +466,8 @@ impl Number {
Ok(Value::from(f64::NAN))
}
}
ValueData::Integer(i) => Ok(Value::integer(*i)),
ValueData::Rational(f) => Ok(Value::integer(*f as i32)),
Value::Integer(i) => Ok(Value::integer(*i)),
Value::Rational(f) => Ok(Value::integer(*f as i32)),
_ => {
// Wrong argument type to parseInt.
Ok(Value::from(f64::NAN))
Expand Down Expand Up @@ -500,8 +500,8 @@ impl Number {
_ctx: &mut Interpreter,
) -> ResultValue {
if let Some(val) = args.get(0) {
match val.data() {
ValueData::String(s) => {
match val {
Value::String(s) => {
if let Ok(i) = s.parse::<i32>() {
// Attempt to parse an integer first so that it can be stored as an integer
// to improve performance
Expand All @@ -513,8 +513,8 @@ impl Number {
Ok(Value::from(f64::NAN))
}
}
ValueData::Integer(i) => Ok(Value::integer(*i)),
ValueData::Rational(f) => Ok(Value::rational(*f)),
Value::Integer(i) => Ok(Value::integer(*i)),
Value::Rational(f) => Ok(Value::rational(*f)),
_ => {
// Wrong argument type to parseFloat.
Ok(Value::from(f64::NAN))
Expand Down
55 changes: 27 additions & 28 deletions boa/src/builtins/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
use crate::builtins::{
object::{Object, INSTANCE_PROTOTYPE, PROTOTYPE},
property::Property,
value::{same_value, Value, ValueData},
value::{same_value, RcString, Value},
};
use crate::BoaProfiler;
use std::borrow::Borrow;
use std::ops::Deref;

impl Object {
Expand All @@ -29,8 +28,8 @@ impl Object {
if !parent.is_null() {
// the parent value variant should be an object
// In the unlikely event it isn't return false
return match *parent {
ValueData::Object(ref obj) => (*obj).deref().borrow().has_property(val),
return match parent {
Value::Object(ref obj) => (*obj).deref().borrow().has_property(val),
_ => false,
};
}
Expand All @@ -48,9 +47,8 @@ impl Object {
/// [spec]: https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-isextensible
#[inline]
pub fn is_extensible(&self) -> bool {
let val = self.get_internal_slot("extensible");
match *val.deref().borrow() {
ValueData::Boolean(b) => b,
match self.get_internal_slot("extensible") {
Value::Boolean(b) => b,
_ => false,
}
}
Expand Down Expand Up @@ -293,8 +291,8 @@ impl Object {

debug_assert!(Property::is_property_key(prop));
// Prop could either be a String or Symbol
match *(*prop) {
ValueData::String(ref st) => {
match *prop {
Value::String(ref st) => {
self.properties()
.get(st)
.map_or_else(Property::default, |v| {
Expand All @@ -312,23 +310,24 @@ impl Object {
d
})
}
ValueData::Symbol(ref symbol) => self
.symbol_properties()
.get(&symbol.hash())
.map_or_else(Property::default, |v| {
let mut d = Property::default();
if v.is_data_descriptor() {
d.value = v.value.clone();
d.writable = v.writable;
} else {
debug_assert!(v.is_accessor_descriptor());
d.get = v.get.clone();
d.set = v.set.clone();
}
d.enumerable = v.enumerable;
d.configurable = v.configurable;
d
}),
Value::Symbol(ref symbol) => {
self.symbol_properties()
.get(&symbol.hash())
.map_or_else(Property::default, |v| {
let mut d = Property::default();
if v.is_data_descriptor() {
d.value = v.value.clone();
d.writable = v.writable;
} else {
debug_assert!(v.is_accessor_descriptor());
d.get = v.get.clone();
d.set = v.set.clone();
}
d.enumerable = v.enumerable;
d.configurable = v.configurable;
d
})
}
_ => Property::default(),
}
}
Expand Down Expand Up @@ -402,7 +401,7 @@ impl Object {
#[inline]
pub(crate) fn insert_property<N>(&mut self, name: N, p: Property)
where
N: Into<String>,
N: Into<RcString>,
{
self.properties.insert(name.into(), p);
}
Expand All @@ -420,7 +419,7 @@ impl Object {
#[inline]
pub(crate) fn insert_field<N>(&mut self, name: N, value: Value) -> Option<Property>
where
N: Into<String>,
N: Into<RcString>,
{
self.properties.insert(
name.into(),
Expand Down
Loading

0 comments on commit 0813346

Please sign in to comment.