Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Apr 25, 2024
1 parent 832c27b commit 1da4a27
Show file tree
Hide file tree
Showing 50 changed files with 685 additions and 596 deletions.
26 changes: 19 additions & 7 deletions cli/src/debug/string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use boa_engine::{
js_str, js_string, object::ObjectInitializer, property::Attribute, string::JsStrVariant,
Context, JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
js_string, object::ObjectInitializer, property::Attribute, string::JsStrVariant, Context,
JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
};

fn storage(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Expand Down Expand Up @@ -61,21 +61,33 @@ fn summary(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsV
};

let summary = ObjectInitializer::new(context)
.property(js_str!("storage"), js_string!(storage), Attribute::all())
.property(js_str!("encoding"), js_string!(encoding), Attribute::all())
.property(js_string!("storage"), js_string!(storage), Attribute::all())
.property(
js_string!("encoding"),
js_string!(encoding),
Attribute::all(),
)
.build();

Ok(summary.into())
}

pub(super) fn create_string(context: &mut Context) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(storage), js_str!("storage"), 1)
.function(
NativeFunction::from_fn_ptr(storage),
js_string!("storage"),
1,
)
.function(
NativeFunction::from_fn_ptr(encoding),
js_str!("encoding"),
js_string!("encoding"),
1,
)
.function(
NativeFunction::from_fn_ptr(summary),
js_string!("summary"),
1,
)
.function(NativeFunction::from_fn_ptr(summary), js_str!("summary"), 1)
.build()
}
3 changes: 2 additions & 1 deletion core/engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
},
context::intrinsics::Intrinsics,
error::JsNativeError,
js_string,
object::JsObject,
property::{Attribute, PropertyNameKind},
realm::Realm,
Expand Down Expand Up @@ -49,7 +50,7 @@ impl IntrinsicObject for ArrayIterator {
.iterator_prototypes()
.iterator(),
)
.static_method(Self::next, js_str!("next"), 0)
.static_method(Self::next, js_string!("next"), 0)
.static_property(
JsSymbol::to_string_tag(),
js_str!("Array Iterator"),
Expand Down
84 changes: 42 additions & 42 deletions core/engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ impl IntrinsicObject for Array {

BuiltInBuilder::from_standard_constructor::<Self>(realm)
// Static Methods
.static_method(Self::from, js_str!("from"), 1)
.static_method(Self::is_array, js_str!("isArray"), 1)
.static_method(Self::of, js_str!("of"), 0)
.static_method(Self::from, js_string!("from"), 1)
.static_method(Self::is_array, js_string!("isArray"), 1)
.static_method(Self::of, js_string!("of"), 0)
.static_accessor(
JsSymbol::species(),
Some(get_species),
Expand All @@ -124,49 +124,49 @@ impl IntrinsicObject for Array {
0,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT,
)
.method(Self::at, js_str!("at"), 1)
.method(Self::concat, js_str!("concat"), 1)
.method(Self::copy_within, js_str!("copyWithin"), 2)
.method(Self::entries, js_str!("entries"), 0)
.method(Self::every, js_str!("every"), 1)
.method(Self::fill, js_str!("fill"), 1)
.method(Self::filter, js_str!("filter"), 1)
.method(Self::find, js_str!("find"), 1)
.method(Self::find_index, js_str!("findIndex"), 1)
.method(Self::find_last, js_str!("findLast"), 1)
.method(Self::find_last_index, js_str!("findLastIndex"), 1)
.method(Self::flat, js_str!("flat"), 0)
.method(Self::flat_map, js_str!("flatMap"), 1)
.method(Self::for_each, js_str!("forEach"), 1)
.method(Self::includes_value, js_str!("includes"), 1)
.method(Self::index_of, js_str!("indexOf"), 1)
.method(Self::join, js_str!("join"), 1)
.method(Self::keys, js_str!("keys"), 0)
.method(Self::last_index_of, js_str!("lastIndexOf"), 1)
.method(Self::map, js_str!("map"), 1)
.method(Self::pop, js_str!("pop"), 0)
.method(Self::push, js_str!("push"), 1)
.method(Self::reduce, js_str!("reduce"), 1)
.method(Self::reduce_right, js_str!("reduceRight"), 1)
.method(Self::reverse, js_str!("reverse"), 0)
.method(Self::shift, js_str!("shift"), 0)
.method(Self::slice, js_str!("slice"), 2)
.method(Self::some, js_str!("some"), 1)
.method(Self::sort, js_str!("sort"), 1)
.method(Self::splice, js_str!("splice"), 2)
.method(Self::to_locale_string, js_str!("toLocaleString"), 0)
.method(Self::to_reversed, js_str!("toReversed"), 0)
.method(Self::to_sorted, js_str!("toSorted"), 1)
.method(Self::to_spliced, js_str!("toSpliced"), 2)
.method(Self::unshift, js_str!("unshift"), 1)
.method(Self::with, js_str!("with"), 2)
.method(Self::at, js_string!("at"), 1)
.method(Self::concat, js_string!("concat"), 1)
.method(Self::copy_within, js_string!("copyWithin"), 2)
.method(Self::entries, js_string!("entries"), 0)
.method(Self::every, js_string!("every"), 1)
.method(Self::fill, js_string!("fill"), 1)
.method(Self::filter, js_string!("filter"), 1)
.method(Self::find, js_string!("find"), 1)
.method(Self::find_index, js_string!("findIndex"), 1)
.method(Self::find_last, js_string!("findLast"), 1)
.method(Self::find_last_index, js_string!("findLastIndex"), 1)
.method(Self::flat, js_string!("flat"), 0)
.method(Self::flat_map, js_string!("flatMap"), 1)
.method(Self::for_each, js_string!("forEach"), 1)
.method(Self::includes_value, js_string!("includes"), 1)
.method(Self::index_of, js_string!("indexOf"), 1)
.method(Self::join, js_string!("join"), 1)
.method(Self::keys, js_string!("keys"), 0)
.method(Self::last_index_of, js_string!("lastIndexOf"), 1)
.method(Self::map, js_string!("map"), 1)
.method(Self::pop, js_string!("pop"), 0)
.method(Self::push, js_string!("push"), 1)
.method(Self::reduce, js_string!("reduce"), 1)
.method(Self::reduce_right, js_string!("reduceRight"), 1)
.method(Self::reverse, js_string!("reverse"), 0)
.method(Self::shift, js_string!("shift"), 0)
.method(Self::slice, js_string!("slice"), 2)
.method(Self::some, js_string!("some"), 1)
.method(Self::sort, js_string!("sort"), 1)
.method(Self::splice, js_string!("splice"), 2)
.method(Self::to_locale_string, js_string!("toLocaleString"), 0)
.method(Self::to_reversed, js_string!("toReversed"), 0)
.method(Self::to_sorted, js_string!("toSorted"), 1)
.method(Self::to_spliced, js_string!("toSpliced"), 2)
.method(Self::unshift, js_string!("unshift"), 1)
.method(Self::with, js_string!("with"), 2)
.property(
js_str!("toString"),
js_string!("toString"),
to_string_function,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
js_str!("values"),
js_string!("values"),
values_function.clone(),
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl Array {
// 1. Let array be ? ToObject(this value).
let array = this.to_object(context)?;
// 2. Let func be ? Get(array, "join").
let func = array.get(js_str!("join"), context)?;
let func = array.get(js_string!("join"), context)?;
// 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%.
// 4. Return ? Call(func, array).
if let Some(func) = func.as_callable() {
Expand Down
18 changes: 10 additions & 8 deletions core/engine/src/builtins/async_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
use crate::{
builtins::{
generator::GeneratorContext, iterable::create_iter_result_object,
promise::if_abrupt_reject_promise, promise::PromiseCapability, Promise,
generator::GeneratorContext,
iterable::create_iter_result_object,
promise::{if_abrupt_reject_promise, PromiseCapability},
Promise,
},
context::intrinsics::Intrinsics,
error::JsNativeError,
js_string,
native_function::NativeFunction,
object::{FunctionObjectBuilder, JsObject, CONSTRUCTOR},
property::Attribute,
Expand All @@ -23,7 +26,6 @@ use crate::{
Context, JsArgs, JsData, JsError, JsResult, JsString,
};
use boa_gc::{Finalize, Trace};
use boa_macros::js_str;
use boa_profiler::Profiler;
use std::collections::VecDeque;

Expand Down Expand Up @@ -80,9 +82,9 @@ impl IntrinsicObject for AsyncGenerator {
.iterator_prototypes()
.async_iterator(),
)
.static_method(Self::next, js_str!("next"), 1)
.static_method(Self::r#return, js_str!("return"), 1)
.static_method(Self::throw, js_str!("throw"), 1)
.static_method(Self::next, js_string!("next"), 1)
.static_method(Self::r#return, js_string!("return"), 1)
.static_method(Self::throw, js_string!("throw"), 1)
.static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Expand Down Expand Up @@ -576,7 +578,7 @@ impl AsyncGenerator {
generator.clone(),
),
)
.name(js_str!(""))
.name(js_string!(""))
.length(1)
.build();

Expand Down Expand Up @@ -611,7 +613,7 @@ impl AsyncGenerator {
generator,
),
)
.name(js_str!(""))
.name(js_string!(""))
.length(1)
.build();

Expand Down
26 changes: 13 additions & 13 deletions core/engine/src/builtins/atomics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod futex;
use std::sync::atomic::Ordering;

use crate::{
builtins::BuiltInObject, context::intrinsics::Intrinsics, object::JsObject,
builtins::BuiltInObject, context::intrinsics::Intrinsics, js_string, object::JsObject,
property::Attribute, realm::Realm, string::common::StaticJsStrings, symbol::JsSymbol,
sys::time::Duration, value::IntegerOrInfinity, Context, JsArgs, JsNativeError, JsResult,
JsString, JsValue,
Expand Down Expand Up @@ -44,18 +44,18 @@ impl IntrinsicObject for Atomics {
Self::NAME,
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.static_method(Atomics::add, js_str!("add"), 3)
.static_method(Atomics::bit_and, js_str!("and"), 3)
.static_method(Atomics::compare_exchange, js_str!("compareExchange"), 4)
.static_method(Atomics::swap, js_str!("exchange"), 3)
.static_method(Atomics::is_lock_free, js_str!("isLockFree"), 1)
.static_method(Atomics::load, js_str!("load"), 2)
.static_method(Atomics::bit_or, js_str!("or"), 3)
.static_method(Atomics::store, js_str!("store"), 3)
.static_method(Atomics::sub, js_str!("sub"), 3)
.static_method(Atomics::wait, js_str!("wait"), 4)
.static_method(Atomics::notify, js_str!("notify"), 3)
.static_method(Atomics::bit_xor, js_str!("xor"), 3)
.static_method(Atomics::add, js_string!("add"), 3)
.static_method(Atomics::bit_and, js_string!("and"), 3)
.static_method(Atomics::compare_exchange, js_string!("compareExchange"), 4)
.static_method(Atomics::swap, js_string!("exchange"), 3)
.static_method(Atomics::is_lock_free, js_string!("isLockFree"), 1)
.static_method(Atomics::load, js_string!("load"), 2)
.static_method(Atomics::bit_or, js_string!("or"), 3)
.static_method(Atomics::store, js_string!("store"), 3)
.static_method(Atomics::sub, js_string!("sub"), 3)
.static_method(Atomics::wait, js_string!("wait"), 4)
.static_method(Atomics::notify, js_string!("notify"), 3)
.static_method(Atomics::bit_xor, js_string!("xor"), 3)
.build();
}

Expand Down
9 changes: 4 additions & 5 deletions core/engine/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::{
value::{IntegerOrInfinity, PreferredType},
Context, JsArgs, JsBigInt, JsResult, JsString, JsValue,
};
use boa_macros::js_str;
use boa_profiler::Profiler;
use num_bigint::ToBigInt;

Expand All @@ -43,10 +42,10 @@ impl IntrinsicObject for BigInt {
let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init");

BuiltInBuilder::from_standard_constructor::<Self>(realm)
.method(Self::to_string, js_str!("toString"), 0)
.method(Self::value_of, js_str!("valueOf"), 0)
.static_method(Self::as_int_n, js_str!("asIntN"), 2)
.static_method(Self::as_uint_n, js_str!("asUintN"), 2)
.method(Self::to_string, js_string!("toString"), 0)
.method(Self::value_of, js_string!("valueOf"), 0)
.static_method(Self::as_int_n, js_string!("asIntN"), 2)
.static_method(Self::as_uint_n, js_string!("asUintN"), 2)
.property(
JsSymbol::to_string_tag(),
Self::NAME,
Expand Down
5 changes: 2 additions & 3 deletions core/engine/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
string::common::StaticJsStrings,
Context, JsResult, JsString, JsValue,
};
use boa_macros::js_str;
use boa_profiler::Profiler;

use super::{BuiltInBuilder, BuiltInConstructor, IntrinsicObject};
Expand All @@ -36,8 +35,8 @@ impl IntrinsicObject for Boolean {
let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init");

BuiltInBuilder::from_standard_constructor::<Self>(realm)
.method(Self::to_string, js_str!("toString"), 0)
.method(Self::value_of, js_str!("valueOf"), 0)
.method(Self::to_string, js_string!("toString"), 0)
.method(Self::value_of, js_string!("valueOf"), 0)
.build();
}

Expand Down
52 changes: 28 additions & 24 deletions core/engine/src/builtins/dataview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{
Context, JsArgs, JsData, JsResult, JsString,
};
use boa_gc::{Finalize, Trace};
use boa_macros::js_str;
use bytemuck::{bytes_of, bytes_of_mut};

use super::{
Expand Down Expand Up @@ -111,39 +110,44 @@ impl IntrinsicObject for DataView {
.build();

BuiltInBuilder::from_standard_constructor::<Self>(realm)
.accessor(js_str!("buffer"), Some(get_buffer), None, flag_attributes)
.accessor(
js_str!("byteLength"),
js_string!("buffer"),
Some(get_buffer),
None,
flag_attributes,
)
.accessor(
js_string!("byteLength"),
Some(get_byte_length),
None,
flag_attributes,
)
.accessor(
js_str!("byteOffset"),
js_string!("byteOffset"),
Some(get_byte_offset),
None,
flag_attributes,
)
.method(Self::get_big_int64, js_str!("getBigInt64"), 1)
.method(Self::get_big_uint64, js_str!("getBigUint64"), 1)
.method(Self::get_float32, js_str!("getFloat32"), 1)
.method(Self::get_float64, js_str!("getFloat64"), 1)
.method(Self::get_int8, js_str!("getInt8"), 1)
.method(Self::get_int16, js_str!("getInt16"), 1)
.method(Self::get_int32, js_str!("getInt32"), 1)
.method(Self::get_uint8, js_str!("getUint8"), 1)
.method(Self::get_uint16, js_str!("getUint16"), 1)
.method(Self::get_uint32, js_str!("getUint32"), 1)
.method(Self::set_big_int64, js_str!("setBigInt64"), 2)
.method(Self::set_big_uint64, js_str!("setBigUint64"), 2)
.method(Self::set_float32, js_str!("setFloat32"), 2)
.method(Self::set_float64, js_str!("setFloat64"), 2)
.method(Self::set_int8, js_str!("setInt8"), 2)
.method(Self::set_int16, js_str!("setInt16"), 2)
.method(Self::set_int32, js_str!("setInt32"), 2)
.method(Self::set_uint8, js_str!("setUint8"), 2)
.method(Self::set_uint16, js_str!("setUint16"), 2)
.method(Self::set_uint32, js_str!("setUint32"), 2)
.method(Self::get_big_int64, js_string!("getBigInt64"), 1)
.method(Self::get_big_uint64, js_string!("getBigUint64"), 1)
.method(Self::get_float32, js_string!("getFloat32"), 1)
.method(Self::get_float64, js_string!("getFloat64"), 1)
.method(Self::get_int8, js_string!("getInt8"), 1)
.method(Self::get_int16, js_string!("getInt16"), 1)
.method(Self::get_int32, js_string!("getInt32"), 1)
.method(Self::get_uint8, js_string!("getUint8"), 1)
.method(Self::get_uint16, js_string!("getUint16"), 1)
.method(Self::get_uint32, js_string!("getUint32"), 1)
.method(Self::set_big_int64, js_string!("setBigInt64"), 2)
.method(Self::set_big_uint64, js_string!("setBigUint64"), 2)
.method(Self::set_float32, js_string!("setFloat32"), 2)
.method(Self::set_float64, js_string!("setFloat64"), 2)
.method(Self::set_int8, js_string!("setInt8"), 2)
.method(Self::set_int16, js_string!("setInt16"), 2)
.method(Self::set_int32, js_string!("setInt32"), 2)
.method(Self::set_uint8, js_string!("setUint8"), 2)
.method(Self::set_uint16, js_string!("setUint16"), 2)
.method(Self::set_uint32, js_string!("setUint32"), 2)
.property(
JsSymbol::to_string_tag(),
Self::NAME,
Expand Down
Loading

0 comments on commit 1da4a27

Please sign in to comment.