Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global objects attributes #624

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ impl Array {

/// Initialise the `Array` object on the global object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand Down Expand Up @@ -1193,6 +1193,10 @@ impl Array {
// Static Methods
make_builtin_fn(Self::is_array, "isArray", &array, 1, interpreter);

(Self::NAME, array)
(
Self::NAME,
array,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
9 changes: 7 additions & 2 deletions boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
builtins::{
function::{make_builtin_fn, make_constructor_fn},
object::ObjectData,
property::Attribute,
value::{RcBigInt, Value},
},
exec::Interpreter,
Expand Down Expand Up @@ -200,7 +201,7 @@ impl BigInt {

/// Initialise the `BigInt` object on the global object.
#[inline]
pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -222,7 +223,11 @@ impl BigInt {
make_builtin_fn(Self::as_int_n, "asIntN", &bigint_object, 2, interpreter);
make_builtin_fn(Self::as_uint_n, "asUintN", &bigint_object, 2, interpreter);

(Self::NAME, bigint_object)
(
Self::NAME,
bigint_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}

Expand Down
11 changes: 7 additions & 4 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tests;

use super::function::{make_builtin_fn, make_constructor_fn};
use crate::{
builtins::{object::ObjectData, value::Value},
builtins::{object::ObjectData, property::Attribute, value::Value},
exec::Interpreter,
BoaProfiler, Result,
};
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Boolean {

/// Initialise the `Boolean` object on the global object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -115,7 +115,10 @@ impl Boolean {
true,
true,
);

(Self::NAME, boolean_object)
(
Self::NAME,
boolean_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
9 changes: 7 additions & 2 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod tests;
use crate::{
builtins::{
function::make_builtin_fn,
property::Attribute,
value::{display_obj, RcString, Value},
},
exec::Interpreter,
Expand Down Expand Up @@ -501,7 +502,7 @@ impl Console {

/// Initialise the `console` object on the global object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -527,6 +528,10 @@ impl Console {
make_builtin_fn(Self::dir, "dir", &console, 0, interpreter);
make_builtin_fn(Self::dir, "dirxml", &console, 0, interpreter);

(Self::NAME, console)
(
Self::NAME,
console,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
10 changes: 8 additions & 2 deletions boa/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
builtins::{
function::{make_builtin_fn, make_constructor_fn},
object::ObjectData,
property::Attribute,
value::PreferredType,
Value,
},
Expand Down Expand Up @@ -1242,7 +1243,7 @@ impl Date {

/// Initialise the `Date` object on the global object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand Down Expand Up @@ -1564,7 +1565,12 @@ impl Date {
make_builtin_fn(Self::now, "now", &date_time_object, 0, interpreter);
make_builtin_fn(Self::parse, "parse", &date_time_object, 1, interpreter);
make_builtin_fn(Self::utc, "UTC", &date_time_object, 7, interpreter);
(Self::NAME, date_time_object)

(
Self::NAME,
date_time_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}

Expand Down
10 changes: 7 additions & 3 deletions boa/src/builtins/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
builtins::{
function::{make_builtin_fn, make_constructor_fn},
object::ObjectData,
property::Attribute,
value::Value,
},
exec::Interpreter,
Expand Down Expand Up @@ -81,7 +82,7 @@ impl Error {

/// Initialise the global object with the `Error` object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -100,7 +101,10 @@ impl Error {
true,
true,
);

(Self::NAME, error_object)
(
Self::NAME,
error_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
12 changes: 8 additions & 4 deletions boa/src/builtins/error/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

use crate::{
builtins::{
function::make_builtin_fn, function::make_constructor_fn, object::ObjectData, value::Value,
function::make_builtin_fn, function::make_constructor_fn, object::ObjectData,
property::Attribute, value::Value,
},
exec::Interpreter,
profiler::BoaProfiler,
Expand Down Expand Up @@ -61,7 +62,7 @@ impl RangeError {

/// Initialise the global object with the `RangeError` object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -80,7 +81,10 @@ impl RangeError {
true,
true,
);

(Self::NAME, range_error_object)
(
Self::NAME,
range_error_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
11 changes: 8 additions & 3 deletions boa/src/builtins/error/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

use crate::{
builtins::{
function::make_builtin_fn, function::make_constructor_fn, object::ObjectData, value::Value,
function::make_builtin_fn, function::make_constructor_fn, object::ObjectData,
property::Attribute, value::Value,
},
exec::Interpreter,
profiler::BoaProfiler,
Expand Down Expand Up @@ -59,7 +60,7 @@ impl ReferenceError {
}

/// Initialise the global object with the `ReferenceError` object.
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -79,6 +80,10 @@ impl ReferenceError {
true,
);

(Self::NAME, reference_error_object)
(
Self::NAME,
reference_error_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
14 changes: 10 additions & 4 deletions boa/src/builtins/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

use crate::{
builtins::{
function::make_builtin_fn, function::make_constructor_fn, object::ObjectData, value::Value,
function::{make_builtin_fn, make_constructor_fn},
object::ObjectData,
property::Attribute,
value::Value,
},
exec::Interpreter,
profiler::BoaProfiler,
Expand Down Expand Up @@ -63,7 +66,7 @@ impl SyntaxError {

/// Initialise the global object with the `SyntaxError` object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -82,7 +85,10 @@ impl SyntaxError {
true,
true,
);

(Self::NAME, syntax_error_object)
(
Self::NAME,
syntax_error_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
13 changes: 10 additions & 3 deletions boa/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

use crate::{
builtins::{
function::make_builtin_fn, function::make_constructor_fn, object::ObjectData, value::Value,
function::{make_builtin_fn, make_constructor_fn},
object::ObjectData,
property::Attribute,
value::Value,
},
exec::Interpreter,
BoaProfiler, Result,
Expand Down Expand Up @@ -66,7 +69,7 @@ impl TypeError {

/// Initialise the global object with the `RangeError` object.
#[inline]
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

Expand All @@ -86,6 +89,10 @@ impl TypeError {
true,
);

(Self::NAME, type_error_object)
(
Self::NAME,
type_error_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
}
49 changes: 23 additions & 26 deletions boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ pub fn create_unmapped_arguments_object(arguments_list: &[Value]) -> Value {
let mut index: usize = 0;
while index < len {
let val = arguments_list.get(index).expect("Could not get argument");
let prop = Property::data_descriptor(

obj.insert_property(
index,
val.clone(),
Attribute::WRITABLE | Attribute::ENUMERABLE | Attribute::CONFIGURABLE,
);

obj.insert_property(index, prop);
index += 1;
}

Expand Down Expand Up @@ -234,29 +234,22 @@ pub fn make_constructor_fn(
let mut constructor =
Object::function(function, global.get_field("Function").get_field(PROTOTYPE));

let length = Property::data_descriptor(
length.into(),
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT,
);
constructor.insert_property("length", length);
constructor.insert_property("length", length, Attribute::default());

let name = Property::data_descriptor(
name.into(),
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT,
);
constructor.insert_property("name", name);
constructor.insert_property("name", name, Attribute::default());

let constructor = Value::from(constructor);

prototype
.as_object_mut()
.unwrap()
.insert_field("constructor", constructor.clone());
prototype.as_object_mut().unwrap().insert_property(
"constructor",
constructor.clone(),
Attribute::default(),
);

constructor
.as_object_mut()
.expect("constructor object")
.insert_field(PROTOTYPE, prototype);
.insert_property(PROTOTYPE, prototype, Attribute::default());

constructor
}
Expand Down Expand Up @@ -298,23 +291,27 @@ pub fn make_builtin_fn<N>(
.get_field("Function")
.get_field("prototype"),
);
function.insert_field("length", Value::from(length));
function.insert_property("length", Value::from(length), Attribute::default());

parent
.as_object_mut()
.unwrap()
.insert_field(name, Value::from(function));
parent.as_object_mut().unwrap().insert_property(
name,
Value::from(function),
Attribute::default(),
);
}

/// Initialise the `Function` object on the global object.
#[inline]
pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value) {
pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value, Attribute) {
let global = interpreter.global();
let _timer = BoaProfiler::global().start_event("function", "init");
let prototype = Value::new_object(Some(global));

let function_object =
make_constructor_fn("Function", 1, make_function, global, prototype, true, true);

("Function", function_object)
(
"Function",
function_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
}
Loading