Skip to content
Draft
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
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ futures-concurrency = "7.6.3"
dynify = "0.1.2"
futures-channel = "0.3.31"
aligned-vec = "0.6.4"
imbl = { version = "6.1.0" }

# ICU4X

Expand Down Expand Up @@ -254,3 +255,7 @@ style = { level = "warn", priority = -1 }
complexity = { level = "warn", priority = -1 }
perf = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }

[profile.samply]
inherits = "release"
debug = true
1 change: 1 addition & 0 deletions core/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ futures-concurrency.workspace = true
temporal_rs = { workspace = true, optional = true }
timezone_provider = { workspace = true, optional = true }
iana-time-zone = { version = "0.1.64", optional = true }
imbl.workspace = true

[target.'cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
web-time = { workspace = true, optional = true }
Expand Down
3 changes: 2 additions & 1 deletion core/engine/src/builtins/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use boa_ast::{
};
use boa_gc::Gc;
use boa_parser::{Parser, Source};
use imbl::Vector;

use super::{BuiltInBuilder, IntrinsicObject};

Expand Down Expand Up @@ -93,7 +94,7 @@ impl Eval {
#[derive(Debug)]
enum EnvStackAction {
Truncate(usize),
Restore(Vec<Environment>),
Restore(Vector<Environment>),
}

// 1. Assert: If direct is false, then strictCaller is also false.
Expand Down
5 changes: 3 additions & 2 deletions core/engine/src/builtins/function/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
use boa_ast::{function::FormalParameterList, operations::bound_names, scope::Scope};
use boa_gc::{Finalize, Gc, Trace};
use boa_interner::Interner;
use imbl::Vector;
use rustc_hash::FxHashMap;
use thin_vec::{ThinVec, thin_vec};

Expand All @@ -30,7 +31,7 @@ impl UnmappedArguments {
///
/// [spec]: https://tc39.es/ecma262/#sec-createunmappedargumentsobject
#[allow(clippy::new_ret_no_self)]
pub(crate) fn new(arguments_list: &[JsValue], context: &mut Context) -> JsObject {
pub(crate) fn new(arguments_list: Vector<JsValue>, context: &mut Context) -> JsObject {
// 1. Let len be the number of elements in argumentsList.
let len = arguments_list.len();

Expand Down Expand Up @@ -214,7 +215,7 @@ impl MappedArguments {
pub(crate) fn new(
func: &JsObject,
binding_indices: &[Option<u32>],
arguments_list: &[JsValue],
arguments_list: Vector<JsValue>,
env: &Gc<DeclarativeEnvironment>,
context: &Context,
) -> JsObject {
Expand Down
13 changes: 2 additions & 11 deletions core/engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,8 @@ impl Context {
/// The stack trace is returned ordered with the most recent frames first.
#[inline]
pub fn stack_trace(&self) -> impl Iterator<Item = &CallFrame> {
// Create a list containing the previous frames plus the current frame.
let frames: Vec<_> = self
.vm
.frames
.iter()
.chain(std::iter::once(&self.vm.frame))
.collect();

// The first frame is always a dummy frame (see `Vm` implementation for more details),
// so skip the dummy frame and return the reversed list so that the most recent frames are first.
frames.into_iter().skip(1).rev()
// Yield the current frame first, followed by the previous frames (skipping the dummy) in reverse order.
std::iter::once(&self.vm.frame).chain(self.vm.frames.iter().skip(1).rev())
}

/// Replaces the currently active realm with `realm`, and returns the old realm.
Expand Down
29 changes: 15 additions & 14 deletions core/engine/src/environments/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
};
use boa_ast::scope::{BindingLocator, BindingLocatorScope, Scope};
use boa_gc::{Finalize, Gc, Trace};
use imbl::Vector;

mod declarative;
mod private;
Expand All @@ -23,9 +24,9 @@ pub(crate) use self::{
/// because they must be preserved for function calls.
#[derive(Clone, Debug, Trace, Finalize)]
pub(crate) struct EnvironmentStack {
stack: Vec<Environment>,
stack: Vector<Environment>,
global: Gc<DeclarativeEnvironment>,
private_stack: Vec<Gc<PrivateEnvironment>>,
private_stack: Vector<Gc<PrivateEnvironment>>,
}

/// A runtime environment.
Expand Down Expand Up @@ -53,9 +54,9 @@ impl EnvironmentStack {
DeclarativeEnvironmentKind::Global(_)
));
Self {
stack: Vec::new(),
stack: Vector::new(),
global,
private_stack: Vec::new(),
private_stack: Vector::new(),
}
}

Expand Down Expand Up @@ -89,8 +90,8 @@ impl EnvironmentStack {
}

/// Pop all current environments except the global environment.
pub(crate) fn pop_to_global(&mut self) -> Vec<Environment> {
let mut envs = Vec::new();
pub(crate) fn pop_to_global(&mut self) -> Vector<Environment> {
let mut envs = Vector::new();
std::mem::swap(&mut envs, &mut self.stack);
envs
}
Expand All @@ -106,7 +107,7 @@ impl EnvironmentStack {
}

/// Extend the current environment stack with the given environments.
pub(crate) fn extend(&mut self, other: Vec<Environment>) {
pub(crate) fn extend(&mut self, other: Vector<Environment>) {
self.stack.extend(other);
}

Expand Down Expand Up @@ -151,7 +152,7 @@ impl EnvironmentStack {

/// Push a new object environment on the environments stack.
pub(crate) fn push_object(&mut self, object: JsObject) {
self.stack.push(Environment::Object(object));
self.stack.push_back(Environment::Object(object));
}

/// Push a lexical environment on the environments stack and return it's index.
Expand All @@ -175,7 +176,7 @@ impl EnvironmentStack {

let index = self.stack.len() as u32;

self.stack.push(Environment::Declarative(Gc::new(
self.stack.push_back(Environment::Declarative(Gc::new(
DeclarativeEnvironment::new(DeclarativeEnvironmentKind::Lexical(
LexicalEnvironment::new(bindings_count, poisoned, with),
)),
Expand Down Expand Up @@ -205,7 +206,7 @@ impl EnvironmentStack {
(environment.poisoned(), with || environment.with())
};

self.stack.push(Environment::Declarative(Gc::new(
self.stack.push_back(Environment::Declarative(Gc::new(
DeclarativeEnvironment::new(DeclarativeEnvironmentKind::Function(
FunctionEnvironment::new(num_bindings, poisoned, with, function_slots, scope),
)),
Expand All @@ -215,7 +216,7 @@ impl EnvironmentStack {
/// Push a module environment on the environments stack.
pub(crate) fn push_module(&mut self, scope: Scope) {
let num_bindings = scope.num_bindings_non_local();
self.stack.push(Environment::Declarative(Gc::new(
self.stack.push_back(Environment::Declarative(Gc::new(
DeclarativeEnvironment::new(DeclarativeEnvironmentKind::Module(
ModuleEnvironment::new(num_bindings, scope),
)),
Expand All @@ -226,7 +227,7 @@ impl EnvironmentStack {
#[track_caller]
pub(crate) fn pop(&mut self) {
debug_assert!(!self.stack.is_empty());
self.stack.pop();
self.stack.pop_back();
}

/// Get the most outer environment.
Expand Down Expand Up @@ -309,12 +310,12 @@ impl EnvironmentStack {

/// Push a private environment to the private environment stack.
pub(crate) fn push_private(&mut self, environment: Gc<PrivateEnvironment>) {
self.private_stack.push(environment);
self.private_stack.push_back(environment);
}

/// Pop a private environment from the private environment stack.
pub(crate) fn pop_private(&mut self) {
self.private_stack.pop();
self.private_stack.pop_back();
}

/// `ResolvePrivateIdentifier ( privEnv, identifier )`
Expand Down
10 changes: 7 additions & 3 deletions core/engine/src/native_function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,13 @@ pub(crate) fn native_function_call(
context.vm.native_active_function = Some(this_function_object);

let result = if constructor.is_some() {
function.call(&JsValue::undefined(), &args, context)
function.call(
&JsValue::undefined(),
&args.into_iter().collect::<Vec<_>>(),
context,
)
} else {
function.call(&this, &args, context)
function.call(&this, &args.into_iter().collect::<Vec<_>>(), context)
}
.map_err(|err| err.inject_realm(context.realm().clone()));

Expand Down Expand Up @@ -425,7 +429,7 @@ fn native_function_construct(
let _this = context.vm.stack.pop();

let result = function
.call(&new_target, &args, context)
.call(&new_target, &args.into_iter().collect::<Vec<_>>(), context)
.map_err(|err| err.inject_realm(context.realm().clone()))
.and_then(|v| match v.variant() {
JsVariant::Object(o) => Ok(o.clone()),
Expand Down
10 changes: 5 additions & 5 deletions core/engine/src/vm/call_frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use boa_ast::Position;
use boa_ast::scope::BindingLocator;
use boa_gc::{Finalize, Gc, Trace};
use boa_string::JsString;
use thin_vec::ThinVec;
use imbl::Vector;

bitflags::bitflags! {
/// Flags associated with a [`CallFrame`].
Expand Down Expand Up @@ -53,12 +53,12 @@ pub struct CallFrame {
pub(crate) env_fp: u32,

// Iterators and their `[[Done]]` flags that must be closed when an abrupt completion is thrown.
pub(crate) iterators: ThinVec<IteratorRecord>,
pub(crate) iterators: Vector<IteratorRecord>,

// The stack of bindings being updated.
// SAFETY: Nothing in `BindingLocator` requires tracing, so this is safe.
#[unsafe_ignore_trace]
pub(crate) binding_stack: Vec<BindingLocator>,
pub(crate) binding_stack: Vector<BindingLocator>,

/// How many iterations a loop has done.
pub(crate) loop_iteration_count: u64,
Expand Down Expand Up @@ -122,8 +122,8 @@ impl CallFrame {
rp: 0,
env_fp: 0,
argument_count: 0,
iterators: ThinVec::new(),
binding_stack: Vec::new(),
iterators: Vector::new(),
binding_stack: Vector::new(),
code_block,
loop_iteration_count: 0,
active_runnable,
Expand Down
Loading
Loading