Skip to content

Commit

Permalink
Merge a41760d into a7ebfc8
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Jul 27, 2021
2 parents a7ebfc8 + a41760d commit afdfe14
Show file tree
Hide file tree
Showing 60 changed files with 642 additions and 488 deletions.
3 changes: 2 additions & 1 deletion boa/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
gc::{Finalize, Trace},
object::{GcObject, ObjectData},
property::{Attribute, DataDescriptor},
string::Constants,
symbol::WellKnownSymbols,
BoaProfiler, Context, Result,
};
Expand Down Expand Up @@ -78,7 +79,7 @@ impl ArrayIterator {
}
let len = array_iterator
.array
.get_field("length", context)?
.get_field(Constants::length(), context)?
.as_number()
.ok_or_else(|| context.construct_type_error("Not an array"))?
as u32;
Expand Down
129 changes: 85 additions & 44 deletions boa/src/builtins/array/mod.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::Array;
use crate::builtins::Number;
use crate::string::Constants;
use crate::{forward, Context, Value};

#[test]
Expand Down Expand Up @@ -1539,6 +1540,6 @@ fn array_length_is_not_enumerable() {
let context = Context::new();

let array = Array::new_array(&context);
let desc = array.get_property("length").unwrap();
let desc = array.get_property(Constants::length()).unwrap();
assert!(!desc.enumerable());
}
12 changes: 3 additions & 9 deletions boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
//! [spec]: https://tc39.es/ecma262/#sec-bigint-objects
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData},
property::Attribute,
symbol::WellKnownSymbols,
BoaProfiler, Context, JsBigInt, Result, Value,
};
use crate::{BoaProfiler, Context, JsBigInt, Result, Value, builtins::BuiltIn, object::{ConstructorBuilder, ObjectData}, property::Attribute, string::Constants, symbol::WellKnownSymbols};
#[cfg(test)]
mod tests;

Expand All @@ -45,8 +39,8 @@ impl BuiltIn for BigInt {
)
.name(Self::NAME)
.length(Self::LENGTH)
.method(Self::to_string, "toString", 1)
.method(Self::value_of, "valueOf", 0)
.method(Self::to_string, Constants::to_string(), 1)
.method(Self::value_of, Constants::value_of(), 0)
.static_method(Self::as_int_n, "asIntN", 2)
.static_method(Self::as_uint_n, "asUintN", 2)
.callable(true)
Expand Down
9 changes: 5 additions & 4 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ mod tests;

use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData, PROTOTYPE},
object::{ConstructorBuilder, ObjectData},
property::Attribute,
string::Constants,
BoaProfiler, Context, Result, Value,
};

Expand All @@ -41,8 +42,8 @@ impl BuiltIn for Boolean {
)
.name(Self::NAME)
.length(Self::LENGTH)
.method(Self::to_string, "toString", 0)
.method(Self::value_of, "valueOf", 0)
.method(Self::to_string, Constants::to_string(), 0)
.method(Self::value_of, Constants::value_of(), 0)
.build();

(Self::NAME, boolean_object.into(), Self::attribute())
Expand All @@ -69,7 +70,7 @@ impl Boolean {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand Down
9 changes: 5 additions & 4 deletions boa/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ mod tests;
use crate::{
builtins::BuiltIn,
gc::{empty_trace, Finalize, Trace},
object::{ConstructorBuilder, ObjectData, PROTOTYPE},
object::{ConstructorBuilder, ObjectData},
property::Attribute,
string::Constants,
value::{PreferredType, Value},
BoaProfiler, Context, Result,
};
Expand Down Expand Up @@ -181,10 +182,10 @@ impl BuiltIn for Date {
.method(getter_method!(to_iso_string), "toISOString", 0)
.method(getter_method!(to_json), "toJSON", 0)
// Locale strings
.method(getter_method!(to_string), "toString", 0)
.method(getter_method!(to_string), Constants::to_string(), 0)
.method(getter_method!(to_time_string), "toTimeString", 0)
.method(getter_method!(to_utc_string), "toUTCString", 0)
.method(getter_method!(value_of), "valueOf", 0)
.method(getter_method!(value_of), Constants::value_of(), 0)
.static_method(Self::now, "now", 0)
.static_method(Self::parse, "parse", 1)
.static_method(Self::utc, "UTC", 7)
Expand Down Expand Up @@ -376,7 +377,7 @@ impl Date {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/date/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::zero_prefixed_literal)]

use crate::{forward, forward_val, object::ObjectData, Context, Value};
use crate::{Context, Value, forward, forward_val, object::ObjectData, string::Constants};
use chrono::prelude::*;

// NOTE: Javascript Uses 0-based months, where chrono uses 1-based months. Many of the assertions look wrong because of
Expand Down Expand Up @@ -61,7 +61,7 @@ fn date_this_time_value() {
)
.expect_err("Expected error");
let message_property = &error
.get_property("message")
.get_property(Constants::message())
.expect("Expected 'message' property")
.as_data_descriptor()
.unwrap()
Expand Down
15 changes: 10 additions & 5 deletions boa/src/builtins/error/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
//! [spec]: https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-evalerror
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError
use crate::object::PROTOTYPE;
use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData},
profiler::BoaProfiler,
property::Attribute,
string::Constants,
Context, Result, Value,
};

Expand Down Expand Up @@ -44,8 +44,8 @@ impl BuiltIn for EvalError {
.name(Self::NAME)
.length(Self::LENGTH)
.inherit(error_prototype.into())
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(Constants::name(), Self::NAME, attribute)
.property(Constants::message(), "", attribute)
.build();

(Self::NAME, eval_error_object.into(), Self::attribute())
Expand All @@ -65,7 +65,7 @@ impl EvalError {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand All @@ -76,7 +76,12 @@ impl EvalError {
let this = Value::from(obj);
if let Some(message) = args.get(0) {
if !message.is_undefined() {
this.set_field("message", message.to_string(context)?, false, context)?;
this.set_field(
Constants::message(),
message.to_string(context)?,
false,
context,
)?;
}
}

Expand Down
17 changes: 9 additions & 8 deletions boa/src/builtins/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData, PROTOTYPE},
object::{ConstructorBuilder, ObjectData},
profiler::BoaProfiler,
property::Attribute,
string::Constants,
Context, Result, Value,
};

Expand Down Expand Up @@ -57,9 +58,9 @@ impl BuiltIn for Error {
)
.name(Self::NAME)
.length(Self::LENGTH)
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.method(Self::to_string, "toString", 0)
.property(Constants::name(), Self::NAME, attribute)
.property(Constants::message(), "", attribute)
.method(Self::to_string, Constants::to_string(), 0)
.build();

(Self::NAME, error_object.into(), Self::attribute())
Expand All @@ -81,7 +82,7 @@ impl Error {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand All @@ -92,7 +93,7 @@ impl Error {
let this = Value::from(obj);
if let Some(message) = args.get(0) {
if !message.is_undefined() {
this.set_field("message", message.to_string(context)?, false, context)?;
this.set_field(Constants::message(), message.to_string(context)?, false, context)?;
}
}

Expand All @@ -117,7 +118,7 @@ impl Error {
if !this.is_object() {
return context.throw_type_error("'this' is not an Object");
}
let name = this.get_field("name", context)?;
let name = this.get_field(Constants::name(), context)?;
let name_to_string;
let name = if name.is_undefined() {
"Error"
Expand All @@ -126,7 +127,7 @@ impl Error {
name_to_string.as_str()
};

let message = this.get_field("message", context)?;
let message = this.get_field(Constants::message(), context)?;
let message_to_string;
let message = if message.is_undefined() {
""
Expand Down
16 changes: 5 additions & 11 deletions boa/src/builtins/error/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
//! [spec]: https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError
use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData, PROTOTYPE},
profiler::BoaProfiler,
property::Attribute,
Context, Result, Value,
};
use crate::{Context, Result, Value, builtins::BuiltIn, object::{ConstructorBuilder, ObjectData}, profiler::BoaProfiler, property::Attribute, string::Constants};

/// JavaScript `RangeError` implementation.
#[derive(Debug, Clone, Copy)]
Expand All @@ -41,8 +35,8 @@ impl BuiltIn for RangeError {
.name(Self::NAME)
.length(Self::LENGTH)
.inherit(error_prototype.into())
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(Constants::name(), Self::NAME, attribute)
.property(Constants::message(), "", attribute)
.build();

(Self::NAME, range_error_object.into(), Self::attribute())
Expand All @@ -62,7 +56,7 @@ impl RangeError {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand All @@ -73,7 +67,7 @@ impl RangeError {
let this = Value::from(obj);
if let Some(message) = args.get(0) {
if !message.is_undefined() {
this.set_field("message", message.to_string(context)?, false, context)?;
this.set_field(Constants::message(), message.to_string(context)?, false, context)?;
}
}

Expand Down
16 changes: 5 additions & 11 deletions boa/src/builtins/error/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
//! [spec]: https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-referenceerror
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData, PROTOTYPE},
profiler::BoaProfiler,
property::Attribute,
Context, Result, Value,
};
use crate::{Context, Result, Value, builtins::BuiltIn, object::{ConstructorBuilder, ObjectData}, profiler::BoaProfiler, property::Attribute, string::Constants};

#[derive(Debug, Clone, Copy)]
pub(crate) struct ReferenceError;
Expand All @@ -40,8 +34,8 @@ impl BuiltIn for ReferenceError {
.name(Self::NAME)
.length(Self::LENGTH)
.inherit(error_prototype.into())
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(Constants::name(), Self::NAME, attribute)
.property(Constants::message(), "", attribute)
.build();

(Self::NAME, reference_error_object.into(), Self::attribute())
Expand All @@ -61,7 +55,7 @@ impl ReferenceError {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand All @@ -72,7 +66,7 @@ impl ReferenceError {
let this = Value::from(obj);
if let Some(message) = args.get(0) {
if !message.is_undefined() {
this.set_field("message", message.to_string(context)?, false, context)?;
this.set_field(Constants::message(), message.to_string(context)?, false, context)?;
}
}

Expand Down
16 changes: 11 additions & 5 deletions boa/src/builtins/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
use crate::{
builtins::BuiltIn,
object::{ConstructorBuilder, ObjectData, PROTOTYPE},
object::{ConstructorBuilder, ObjectData},
profiler::BoaProfiler,
property::Attribute,
string::Constants,
Context, Result, Value,
};

Expand Down Expand Up @@ -43,8 +44,8 @@ impl BuiltIn for SyntaxError {
.name(Self::NAME)
.length(Self::LENGTH)
.inherit(error_prototype.into())
.property("name", Self::NAME, attribute)
.property("message", "", attribute)
.property(Constants::name(), Self::NAME, attribute)
.property(Constants::message(), "", attribute)
.build();

(Self::NAME, syntax_error_object.into(), Self::attribute())
Expand All @@ -64,7 +65,7 @@ impl SyntaxError {
let prototype = new_target
.as_object()
.and_then(|obj| {
obj.__get__(&PROTOTYPE.into(), obj.clone().into(), context)
obj.__get__(&Constants::prototype().into(), obj.clone().into(), context)
.map(|o| o.as_object())
.transpose()
})
Expand All @@ -75,7 +76,12 @@ impl SyntaxError {
let this = Value::from(obj);
if let Some(message) = args.get(0) {
if !message.is_undefined() {
this.set_field("message", message.to_string(context)?, false, context)?;
this.set_field(
Constants::message(),
message.to_string(context)?,
false,
context,
)?;
}
}

Expand Down
Loading

0 comments on commit afdfe14

Please sign in to comment.