Skip to content

Commit

Permalink
Rewrite initialization of builtins to use the BuiltIn trait
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 20, 2021
1 parent 9a915c3 commit e4ce309
Show file tree
Hide file tree
Showing 28 changed files with 186 additions and 184 deletions.
10 changes: 5 additions & 5 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ pub(crate) struct Array;
impl BuiltIn for Array {
const NAME: &'static str = "Array";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let symbol_iterator = WellKnownSymbols::iterator();
Expand Down Expand Up @@ -120,7 +120,7 @@ impl BuiltIn for Array {
.static_method(Self::of, "of", 0)
.build();

(Self::NAME, array.into(), Self::attribute())
array.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub struct BigInt;
impl BuiltIn for BigInt {
const NAME: &'static str = "BigInt";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let to_string_tag = WellKnownSymbols::to_string_tag();
Expand All @@ -59,7 +59,7 @@ impl BuiltIn for BigInt {
)
.build();

(Self::NAME, bigint_object.into(), Self::attribute())
bigint_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ impl BuiltIn for Boolean {
/// The name of the object.
const NAME: &'static str = "Boolean";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let boolean_object = ConstructorBuilder::with_standard_object(
Expand All @@ -46,7 +46,7 @@ impl BuiltIn for Boolean {
.method(Self::value_of, "valueOf", 0)
.build();

(Self::NAME, boolean_object.into(), Self::attribute())
boolean_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ pub(crate) struct Console {
impl BuiltIn for Console {
const NAME: &'static str = "console";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");
let console = ObjectInitializer::new(context)
.function(Self::assert, "assert", 0)
Expand All @@ -165,7 +165,7 @@ impl BuiltIn for Console {
.function(Self::dir, "dirxml", 0)
.build();

(Self::NAME, console.into(), Self::attribute())
console.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl Default for Date {
impl BuiltIn for Date {
const NAME: &'static str = "Date";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let date_object = ConstructorBuilder::new(context, Self::constructor)
Expand Down Expand Up @@ -157,7 +157,7 @@ impl BuiltIn for Date {
.static_method(Self::utc, "UTC", 7)
.build();

(Self::NAME, date_object.into(), Self::attribute())
date_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub(crate) struct EvalError;
impl BuiltIn for EvalError {
const NAME: &'static str = "EvalError";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let error_prototype = context.standard_objects().error_object().prototype();
Expand All @@ -50,7 +50,7 @@ impl BuiltIn for EvalError {
.property("message", "", attribute)
.build();

(Self::NAME, eval_error_object.into(), Self::attribute())
eval_error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ pub(crate) struct Error;
impl BuiltIn for Error {
const NAME: &'static str = "Error";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
Expand All @@ -63,7 +63,7 @@ impl BuiltIn for Error {
.method(Self::to_string, "toString", 0)
.build();

(Self::NAME, error_object.into(), Self::attribute())
error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub(crate) struct RangeError;
impl BuiltIn for RangeError {
const NAME: &'static str = "RangeError";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let error_prototype = context.standard_objects().error_object().prototype();
Expand All @@ -46,7 +46,7 @@ impl BuiltIn for RangeError {
.property("message", "", attribute)
.build();

(Self::NAME, range_error_object.into(), Self::attribute())
range_error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pub(crate) struct ReferenceError;
impl BuiltIn for ReferenceError {
const NAME: &'static str = "ReferenceError";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let error_prototype = context.standard_objects().error_object().prototype();
Expand All @@ -45,7 +45,7 @@ impl BuiltIn for ReferenceError {
.property("message", "", attribute)
.build();

(Self::NAME, reference_error_object.into(), Self::attribute())
reference_error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub(crate) struct SyntaxError;
impl BuiltIn for SyntaxError {
const NAME: &'static str = "SyntaxError";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let error_prototype = context.standard_objects().error_object().prototype();
Expand All @@ -48,7 +48,7 @@ impl BuiltIn for SyntaxError {
.property("message", "", attribute)
.build();

(Self::NAME, syntax_error_object.into(), Self::attribute())
syntax_error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub(crate) struct TypeError;
impl BuiltIn for TypeError {
const NAME: &'static str = "TypeError";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let error_prototype = context.standard_objects().error_object().prototype();
Expand All @@ -51,7 +51,7 @@ impl BuiltIn for TypeError {
.property("message", "", attribute)
.build();

(Self::NAME, type_error_object.into(), Self::attribute())
type_error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/error/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub(crate) struct UriError;
impl BuiltIn for UriError {
const NAME: &'static str = "URIError";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let error_prototype = context.standard_objects().error_object().prototype();
Expand All @@ -47,7 +47,7 @@ impl BuiltIn for UriError {
.property("message", "", attribute)
.build();

(Self::NAME, uri_error_object.into(), Self::attribute())
uri_error_object.into()
}
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ impl BuiltInFunctionObject {
impl BuiltIn for BuiltInFunctionObject {
const NAME: &'static str = "Function";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event("function", "init");

let function_prototype = context.standard_objects().function_object().prototype();
Expand All @@ -557,6 +557,6 @@ impl BuiltIn for BuiltInFunctionObject {
.method(Self::to_string, "toString", 0)
.build();

(Self::NAME, function_object.into(), Self::attribute())
function_object.into()
}
}
14 changes: 5 additions & 9 deletions boa/src/builtins/global_this/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ pub(crate) struct GlobalThis;
impl BuiltIn for GlobalThis {
const NAME: &'static str = "globalThis";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

(
Self::NAME,
context.global_object().into(),
Self::attribute(),
)
context.global_object().into()
}
}
10 changes: 5 additions & 5 deletions boa/src/builtins/infinity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ pub(crate) struct Infinity;
impl BuiltIn for Infinity {
const NAME: &'static str = "Infinity";

fn attribute() -> Attribute {
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT
}
const ATTRIBUTE: Attribute = Attribute::READONLY
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::PERMANENT);

fn init(_: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(_: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

(Self::NAME, f64::INFINITY.into(), Self::attribute())
f64::INFINITY.into()
}
}
10 changes: 5 additions & 5 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ pub(crate) struct Json;
impl BuiltIn for Json {
const NAME: &'static str = "JSON";

fn attribute() -> Attribute {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}
const ATTRIBUTE: Attribute = Attribute::WRITABLE
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);

fn init(context: &mut Context) -> (&'static str, JsValue, Attribute) {
fn init(context: &mut Context) -> JsValue {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let to_string_tag = WellKnownSymbols::to_string_tag();
Expand All @@ -54,7 +54,7 @@ impl BuiltIn for Json {
.property(to_string_tag, Self::NAME, attribute)
.build();

(Self::NAME, json_object.into(), Self::attribute())
json_object.into()
}
}

Expand Down
Loading

0 comments on commit e4ce309

Please sign in to comment.