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

[Merged by Bors] - Cleanup intrinsics and move to realm #2555

Closed
wants to merge 5 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
5 changes: 4 additions & 1 deletion boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ fn main() -> Result<(), io::Error> {
let args = Opt::parse();

let queue = Jobs::default();
let mut context = ContextBuilder::new().job_queue(&queue).build();
let mut context = ContextBuilder::new()
.job_queue(&queue)
.build()
.expect("cannot fail with default global object");

// Trace Output
context.set_trace(args.trace);
Expand Down
6 changes: 4 additions & 2 deletions boa_engine/benches/full.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Benchmarks of the whole execution engine in Boa.

use boa_engine::{realm::Realm, Context, Source};
use boa_engine::{context::DefaultHooks, realm::Realm, Context, Source};
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

Expand All @@ -12,7 +12,9 @@ use std::hint::black_box;
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

fn create_realm(c: &mut Criterion) {
c.bench_function("Create Realm", move |b| b.iter(|| Realm::create(None)));
c.bench_function("Create Realm", move |b| {
b.iter(|| Realm::create(&DefaultHooks))
});
}

macro_rules! full_benchmarks {
Expand Down
62 changes: 26 additions & 36 deletions boa_engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
//! [spec]: https://tc39.es/ecma262/#sec-array-iterator-objects

use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue},
builtins::{
iterable::create_iter_result_object, Array, BuiltInBuilder, IntrinsicObject, JsValue,
},
context::intrinsics::Intrinsics,
error::JsNativeError,
object::{JsObject, ObjectData},
property::{PropertyDescriptor, PropertyNameKind},
property::{Attribute, PropertyNameKind},
symbol::JsSymbol,
Context, JsResult,
};
Expand All @@ -31,9 +34,27 @@ pub struct ArrayIterator {
done: bool,
}

impl ArrayIterator {
pub(crate) const NAME: &'static str = "ArrayIterator";
impl IntrinsicObject for ArrayIterator {
fn init(intrinsics: &Intrinsics) {
let _timer = Profiler::global().start_event("ArrayIterator", "init");

BuiltInBuilder::with_intrinsic::<Self>(intrinsics)
.prototype(intrinsics.objects().iterator_prototypes().iterator())
.static_method(Self::next, "next", 0)
.static_property(
JsSymbol::to_string_tag(),
"Array Iterator",
Attribute::CONFIGURABLE,
)
.build();
}

fn get(intrinsics: &Intrinsics) -> JsObject {
intrinsics.objects().iterator_prototypes().array()
}
}

impl ArrayIterator {
fn new(array: JsObject, kind: PropertyNameKind) -> Self {
Self {
array,
Expand All @@ -57,11 +78,7 @@ impl ArrayIterator {
context: &Context<'_>,
) -> JsValue {
let array_iterator = JsObject::from_proto_and_data(
context
.intrinsics()
.objects()
.iterator_prototypes()
.array_iterator(),
context.intrinsics().objects().iterator_prototypes().array(),
ObjectData::array_iterator(Self::new(array, kind)),
);
array_iterator.into()
Expand Down Expand Up @@ -130,31 +147,4 @@ impl ArrayIterator {
}
}
}

/// Create the `%ArrayIteratorPrototype%` object
///
/// More information:
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event(Self::NAME, "init");

// Create prototype
let array_iterator =
JsObject::from_proto_and_data(iterator_prototype, ObjectData::ordinary());
make_builtin_fn(Self::next, "next", &array_iterator, 0, context);

let to_string_tag = JsSymbol::to_string_tag();
let to_string_tag_property = PropertyDescriptor::builder()
.value("Array Iterator")
.writable(false)
.enumerable(false)
.configurable(true);
array_iterator.insert(to_string_tag, to_string_tag_property);
array_iterator
}
}
Loading