Skip to content

Commit

Permalink
Add static shape to all NativeErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed May 1, 2023
1 parent 2b19bb5 commit 34b540d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 62 deletions.
6 changes: 6 additions & 0 deletions boa_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,5 +692,11 @@ fn main() -> io::Result<()> {
.method(utf16!("toString"))
.build(file)?;

let attribute = Attribute::WRITABLE | Attribute::CONFIGURABLE;
BuiltInBuilderConstructor::new("NATIVE_ERROR")
.property(utf16!("name"), attribute)
.property(utf16!("message"), attribute)
.build(file)?;

Ok(())
}
21 changes: 12 additions & 9 deletions boa_engine/src/builtins/error/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use crate::{
},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::{Attribute, PropertyDescriptorBuilder},
property::PropertyDescriptorBuilder,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand All @@ -30,13 +30,16 @@ impl IntrinsicObject for AggregateError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
20 changes: 11 additions & 9 deletions boa_engine/src/builtins/error/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ use crate::{
builtins::{BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand All @@ -32,13 +31,16 @@ impl IntrinsicObject for EvalError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
20 changes: 11 additions & 9 deletions boa_engine/src/builtins/error/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use crate::{
builtins::{BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand All @@ -30,13 +29,16 @@ impl IntrinsicObject for RangeError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
20 changes: 11 additions & 9 deletions boa_engine/src/builtins/error/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use crate::{
builtins::{BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand All @@ -29,13 +28,16 @@ impl IntrinsicObject for ReferenceError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
20 changes: 11 additions & 9 deletions boa_engine/src/builtins/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ use crate::{
builtins::{BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand All @@ -32,13 +31,16 @@ impl IntrinsicObject for SyntaxError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
19 changes: 11 additions & 8 deletions boa_engine/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue, NativeFunction,
Context, JsArgs, JsResult, JsString, JsValue, NativeFunction,
};
use boa_profiler::Profiler;

Expand All @@ -40,13 +40,16 @@ impl IntrinsicObject for TypeError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
20 changes: 11 additions & 9 deletions boa_engine/src/builtins/error/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ use crate::{
builtins::{BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData},
property::Attribute,
realm::Realm,
string::utf16,
Context, JsArgs, JsResult, JsValue,
Context, JsArgs, JsResult, JsString, JsValue,
};
use boa_profiler::Profiler;

Expand All @@ -31,13 +30,16 @@ impl IntrinsicObject for UriError {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");

let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
BuiltInBuilder::from_standard_constructor::<Self>(realm)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(utf16!("name"), Self::NAME, attribute)
.property(utf16!("message"), "", attribute)
.build();
BuiltInBuilder::from_standard_constructor_static_shape::<Self>(
realm,
&boa_builtins::NATIVE_ERROR_CONSTRUCTOR_STATIC_SHAPE,
&boa_builtins::NATIVE_ERROR_PROTOTYPE_STATIC_SHAPE,
)
.prototype(realm.intrinsics().constructors().error().constructor())
.inherits(Some(realm.intrinsics().constructors().error().prototype()))
.property(Self::NAME)
.property(JsString::default())
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down

0 comments on commit 34b540d

Please sign in to comment.