diff --git a/Cargo.lock b/Cargo.lock index c20e3a35ad9..51d726ea262 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,6 +112,7 @@ dependencies = [ name = "boa_interner" version = "0.13.0" dependencies = [ + "gc", "serde", "string-interner", ] @@ -1273,9 +1274,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.75" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79" +checksum = "edde269018d33d7146dd074e5f7da6fef9b0a957507454c867caa0852c560a9a" dependencies = [ "itoa 1.0.1", "ryu", diff --git a/boa/Cargo.toml b/boa/Cargo.toml index 0d485a506aa..686311fbf71 100644 --- a/boa/Cargo.toml +++ b/boa/Cargo.toml @@ -23,7 +23,7 @@ boa_unicode = { path = "../boa_unicode", version = "0.13.0" } boa_interner = { path = "../boa_interner", version = "0.13.0" } gc = { version = "0.4.1", features = ["derive"] } serde = { version = "1.0.134", features = ["derive", "rc"] } -serde_json = "1.0.75" +serde_json = "1.0.76" rand = "0.8.4" num-traits = "0.2.14" regress = "0.4.1" diff --git a/boa/benches/full.rs b/boa/benches/full.rs index efa7c25a159..197094c5c72 100644 --- a/boa/benches/full.rs +++ b/boa/benches/full.rs @@ -1,7 +1,6 @@ //! Benchmarks of the whole execution engine in Boa. -use boa::{realm::Realm, syntax::Parser, Context}; -use boa_interner::Interner; +use boa::{realm::Realm, Context}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] @@ -21,9 +20,9 @@ macro_rules! full_benchmarks { $( { static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js")); - let mut interner = Interner::new(); + let mut context = Context::default(); c.bench_function(concat!($id, " (Parser)"), move |b| { - b.iter(|| Parser::new(black_box(CODE.as_bytes()), false).parse_all(&mut interner)) + b.iter(|| context.parse(black_box(CODE))) }); } )* @@ -32,11 +31,11 @@ macro_rules! full_benchmarks { $( { static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js")); - let mut interner = Interner::new(); - let statement_list = Parser::new(CODE.as_bytes(), false).parse_all( &mut interner).expect("parsing failed"); + let mut context = Context::default(); + let statement_list = context.parse(CODE).expect("parsing failed"); c.bench_function(concat!($id, " (Compiler)"), move |b| { b.iter(|| { - Context::compile(black_box(&statement_list)); + context.compile(black_box(&statement_list)) }) }); } @@ -46,13 +45,12 @@ macro_rules! full_benchmarks { $( { static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js")); - let mut interner = Interner::new(); - let statement_list = Parser::new(CODE.as_bytes(), false).parse_all(&mut interner).expect("parsing failed"); - let mut context = Context::new(interner); - let code_block = Context::compile(&statement_list); + let mut context = Context::default(); + let statement_list = context.parse(CODE).expect("parsing failed"); + let code_block = context.compile(&statement_list); c.bench_function(concat!($id, " (Execution)"), move |b| { b.iter(|| { - context.execute(black_box(code_block.clone())).unwrap(); + context.execute(black_box(code_block.clone())).unwrap() }) }); } diff --git a/boa/src/builtins/array/tests.rs b/boa/src/builtins/array/tests.rs index 9d4d683ba0a..2374fb13635 100644 --- a/boa/src/builtins/array/tests.rs +++ b/boa/src/builtins/array/tests.rs @@ -117,7 +117,6 @@ fn of() { assert_eq!(context.eval("a.length").unwrap(), JsValue::new(3)); } -#[ignore] #[test] fn concat() { let mut context = Context::default(); diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index 861fef63506..cb569baa1cd 100644 --- a/boa/src/builtins/console/mod.rs +++ b/boa/src/builtins/console/mod.rs @@ -304,7 +304,12 @@ impl Console { let mut prev_frame = context.vm.frame.as_ref(); while let Some(frame) = prev_frame { - stack_trace.push(frame.code.name.to_string()); + stack_trace.push( + context + .interner() + .resolve_expect(frame.code.name) + .to_owned(), + ); prev_frame = frame.prev.as_ref(); } diff --git a/boa/src/builtins/dataview/mod.rs b/boa/src/builtins/dataview/mod.rs index 37207e6494f..e57d77efa43 100644 --- a/boa/src/builtins/dataview/mod.rs +++ b/boa/src/builtins/dataview/mod.rs @@ -1,6 +1,7 @@ use crate::{ builtins::{array_buffer::SharedMemoryOrder, typed_array::TypedArrayName, BuiltIn, JsArgs}, context::StandardObjects, + gc::{Finalize, Trace}, object::{ internal_methods::get_prototype_from_constructor, ConstructorBuilder, FunctionBuilder, JsObject, ObjectData, @@ -10,7 +11,6 @@ use crate::{ value::JsValue, Context, JsResult, }; -use gc::{Finalize, Trace}; #[derive(Debug, Clone, Trace, Finalize)] pub struct DataView { diff --git a/boa/src/builtins/function/arguments.rs b/boa/src/builtins/function/arguments.rs index 7ef1e56c768..c74b63303ad 100644 --- a/boa/src/builtins/function/arguments.rs +++ b/boa/src/builtins/function/arguments.rs @@ -1,14 +1,13 @@ use crate::{ builtins::Array, environment::lexical_environment::Environment, + gc::{Finalize, Trace}, object::{FunctionBuilder, JsObject, ObjectData}, property::PropertyDescriptor, symbol::{self, WellKnownSymbols}, syntax::ast::node::FormalParameter, Context, JsValue, }; - -use gc::{Finalize, Trace}; use rustc_hash::FxHashSet; #[derive(Debug, Clone, Trace, Finalize)] @@ -171,9 +170,9 @@ impl Arguments { // a. Let name be parameterNames[index]. for (index, parameter_name_vec) in formals.iter().map(|fp| fp.names()).enumerate().rev() { - for parameter_name in parameter_name_vec.iter().cloned() { + for parameter_name in parameter_name_vec.iter().copied() { // b. If name is not an element of mappedNames, then - if !mapped_names.contains(parameter_name) { + if !mapped_names.contains(¶meter_name) { // i. Add name as an element of the list mappedNames. mapped_names.insert(parameter_name); // ii. If index < len, then @@ -189,7 +188,7 @@ impl Arguments { // 1. Let getterClosure be a new Abstract Closure with no parameters that captures // name and env and performs the following steps when called: |_, _, captures, context| { - captures.0.get_binding_value(&captures.1, false, context) + captures.0.get_binding_value(captures.1, false, context) }, (env.clone(), parameter_name.to_owned()), ) @@ -212,7 +211,7 @@ impl Arguments { // a. Return env.SetMutableBinding(name, value, false). captures .0 - .set_mutable_binding(&captures.1, value, false, context) + .set_mutable_binding(captures.1, value, false, context) .map(|_| JsValue::Undefined) // Ok(JsValue::Undefined) }, diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index ebc110bd460..255dbf14ffa 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -11,39 +11,29 @@ //! [spec]: https://tc39.es/ecma262/#sec-function-objects //! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function -use std::{ - any::Any, - borrow::Cow, - fmt, - ops::{Deref, DerefMut}, -}; - -use dyn_clone::DynClone; -use gc::{Gc, GcCell}; - +use super::JsArgs; use crate::{ builtins::BuiltIn, context::StandardObjects, environment::lexical_environment::Environment, - gc::{Finalize, Trace}, - object::JsObject, - object::{internal_methods::get_prototype_from_constructor, NativeObject, ObjectData}, - property::Attribute, - property::PropertyDescriptor, - BoaProfiler, Context, JsResult, JsValue, -}; -use crate::{object::Object, symbol::WellKnownSymbols}; -use crate::{ - object::{ConstructorBuilder, FunctionBuilder}, - property::PropertyKey, - JsString, -}; -use crate::{ - object::{Ref, RefMut}, + gc::{self, Finalize, Gc, Trace}, + object::{ + internal_methods::get_prototype_from_constructor, JsObject, NativeObject, Object, + ObjectData, + }, + object::{ConstructorBuilder, FunctionBuilder, Ref, RefMut}, + property::{Attribute, PropertyDescriptor, PropertyKey}, + symbol::WellKnownSymbols, value::IntegerOrInfinity, + BoaProfiler, Context, JsResult, JsString, JsValue, +}; +use dyn_clone::DynClone; +use std::{ + any::Any, + borrow::Cow, + fmt, + ops::{Deref, DerefMut}, }; - -use super::JsArgs; pub(crate) mod arguments; #[cfg(test)] @@ -136,7 +126,7 @@ impl ConstructorKind { /// with `Any::downcast_ref` and `Any::downcast_mut` to recover the original /// type. #[derive(Clone, Debug, Trace, Finalize)] -pub struct Captures(Gc>>); +pub struct Captures(Gc>>); impl Captures { /// Creates a new capture context. @@ -144,7 +134,7 @@ impl Captures { where T: NativeObject, { - Self(Gc::new(GcCell::new(Box::new(captures)))) + Self(Gc::new(gc::Cell::new(Box::new(captures)))) } /// Casts `Captures` to `Any` @@ -152,7 +142,7 @@ impl Captures { /// # Panics /// /// Panics if it's already borrowed as `&mut Any` - pub fn as_any(&self) -> gc::GcCellRef<'_, dyn Any> { + pub fn as_any(&self) -> gc::Ref<'_, dyn Any> { Ref::map(self.0.borrow(), |data| data.deref().as_any()) } @@ -161,7 +151,7 @@ impl Captures { /// # Panics /// /// Panics if it's already borrowed as `&mut Any` - pub fn as_mut_any(&self) -> gc::GcCellRefMut<'_, Box, dyn Any> { + pub fn as_mut_any(&self) -> gc::RefMut<'_, Box, dyn Any> { RefMut::map(self.0.borrow_mut(), |data| data.deref_mut().as_mut_any()) } } diff --git a/boa/src/builtins/map/map_iterator.rs b/boa/src/builtins/map/map_iterator.rs index 340ff75a292..b7cbb1ab63e 100644 --- a/boa/src/builtins/map/map_iterator.rs +++ b/boa/src/builtins/map/map_iterator.rs @@ -1,13 +1,13 @@ +use super::ordered_map::MapLock; use crate::{ builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue}, + gc::{Finalize, Trace}, object::{JsObject, ObjectData}, property::{PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, }; -use gc::{Finalize, Trace}; -use super::ordered_map::MapLock; /// The Map Iterator object represents an iteration over a map. It implements the iterator protocol. /// /// More information: diff --git a/boa/src/builtins/set/set_iterator.rs b/boa/src/builtins/set/set_iterator.rs index 3720423143d..c82ac608ca3 100644 --- a/boa/src/builtins/set/set_iterator.rs +++ b/boa/src/builtins/set/set_iterator.rs @@ -1,13 +1,11 @@ use crate::{ - builtins::Array, - builtins::JsValue, - builtins::{function::make_builtin_fn, iterable::create_iter_result_object}, + builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue}, + gc::{Finalize, Trace}, object::{JsObject, ObjectData}, property::{PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, BoaProfiler, Context, JsResult, }; -use gc::{Finalize, Trace}; /// The Set Iterator object represents an iteration over a set. It implements the iterator protocol. /// diff --git a/boa/src/bytecompiler.rs b/boa/src/bytecompiler.rs index 1aa6e62dfe7..67e299ecc64 100644 --- a/boa/src/bytecompiler.rs +++ b/boa/src/bytecompiler.rs @@ -1,7 +1,6 @@ -use gc::Gc; - use crate::{ builtins::function::ThisMode, + gc::Gc, syntax::ast::{ node::{ declaration::{BindingPatternTypeArray, BindingPatternTypeObject, DeclarationPattern}, @@ -16,7 +15,9 @@ use crate::{ vm::{CodeBlock, Opcode}, JsBigInt, JsString, JsValue, }; -use std::{collections::HashMap, mem::size_of}; +use boa_interner::{Interner, Sym}; +use rustc_hash::FxHashMap; +use std::mem::size_of; #[derive(Debug, Clone, PartialEq, Eq, Hash)] enum Literal { @@ -32,7 +33,7 @@ struct Label { #[derive(Debug, Clone)] struct JumpControlInfo { - label: Option>, + label: Option, start_address: u32, kind: JumpControlInfoKind, breaks: Vec