Skip to content
Merged
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
4 changes: 2 additions & 2 deletions core/engine/src/builtins/function/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl UnmappedArguments {
pub(crate) struct MappedArguments {
#[unsafe_ignore_trace]
binding_indices: Vec<Option<u32>>,
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
}

impl JsData for MappedArguments {
Expand Down Expand Up @@ -215,7 +215,7 @@ impl MappedArguments {
func: &JsObject,
binding_indices: &[Option<u32>],
arguments_list: &[JsValue],
env: &Gc<DeclarativeEnvironment>,
env: &Gc<'static, DeclarativeEnvironment>,
context: &Context,
) -> JsObject {
// 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers.
Expand Down
9 changes: 6 additions & 3 deletions core/engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ unsafe impl Trace for ClassFieldDefinition {
#[derive(Debug, Trace, Finalize)]
pub struct OrdinaryFunction {
/// The code block containing the compiled function.
pub(crate) code: Gc<CodeBlock>,
pub(crate) code: Gc<'static, CodeBlock>,

/// The `[[Environment]]` internal slot.
pub(crate) environments: EnvironmentStack,
Expand Down Expand Up @@ -210,7 +210,7 @@ impl JsData for OrdinaryFunction {

impl OrdinaryFunction {
pub(crate) fn new(
code: Gc<CodeBlock>,
code: Gc<'static, CodeBlock>,
environments: EnvironmentStack,
script_or_module: Option<ActiveRunnable>,
realm: Realm,
Expand All @@ -233,7 +233,10 @@ impl OrdinaryFunction {
}

/// Push a private environment to the function.
pub(crate) fn push_private_environment(&mut self, environment: Gc<PrivateEnvironment>) {
pub(crate) fn push_private_environment(
&mut self,
environment: Gc<'static, PrivateEnvironment>,
) {
self.environments.push_private(environment);
}

Expand Down
8 changes: 4 additions & 4 deletions core/engine/src/builtins/promise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl Promise {
#[unsafe_ignore_trace]
already_called: Rc<Cell<bool>>,
index: usize,
values: Gc<GcRefCell<Vec<JsValue>>>,
values: Gc<'static, GcRefCell<Vec<JsValue>>>,
capability_resolve: JsFunction,
#[unsafe_ignore_trace]
remaining_elements_count: Rc<Cell<i32>>,
Expand Down Expand Up @@ -861,7 +861,7 @@ impl Promise {
#[unsafe_ignore_trace]
already_called: Rc<Cell<bool>>,
index: usize,
values: Gc<GcRefCell<Vec<JsValue>>>,
values: Gc<'static, GcRefCell<Vec<JsValue>>>,
capability: JsFunction,
#[unsafe_ignore_trace]
remaining_elements: Rc<Cell<i32>>,
Expand Down Expand Up @@ -1222,7 +1222,7 @@ impl Promise {
variant: KeyedVariant,
#[unsafe_ignore_trace]
keys: Rc<RefCell<Vec<PropertyKey>>>,
values: Gc<GcRefCell<Vec<JsValue>>>,
values: Gc<'static, GcRefCell<Vec<JsValue>>>,
capability: JsFunction,
#[unsafe_ignore_trace]
remaining_elements: Rc<Cell<i32>>,
Expand Down Expand Up @@ -1538,7 +1538,7 @@ impl Promise {
#[unsafe_ignore_trace]
already_called: Rc<Cell<bool>>,
index: usize,
errors: Gc<GcRefCell<Vec<JsValue>>>,
errors: Gc<'static, GcRefCell<Vec<JsValue>>>,
capability_reject: JsFunction,
#[unsafe_ignore_trace]
remaining_elements_count: Rc<Cell<i32>>,
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/bytecompiler/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use thin_vec::ThinVec;
// Static class elements that are initialized at a later time in the class creation.
enum StaticElement {
// A static class block with it's function code.
StaticBlock(Gc<CodeBlock>),
StaticBlock(Gc<'static, CodeBlock>),

// A static class field with it's function code, an optional name index and the information if the function is an anonymous function.
StaticField {
code: Gc<CodeBlock>,
code: Gc<'static, CodeBlock>,
name_index: StaticFieldName,
is_anonymous_function: bool,
},
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/bytecompiler/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl FunctionCompiler {
scopes: &FunctionScopes,
contains_direct_eval: bool,
interner: &mut Interner,
) -> Gc<CodeBlock> {
) -> Gc<'static, CodeBlock> {
self.strict = self.strict || body.strict();

let length = parameters.length();
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl<'ctx> ByteCompiler<'ctx> {

#[inline]
#[must_use]
pub(crate) fn push_function_to_constants(&mut self, function: Gc<CodeBlock>) -> u32 {
pub(crate) fn push_function_to_constants(&mut self, function: Gc<'static, CodeBlock>) -> u32 {
let index = self.constants.len() as u32;
self.constants.push(Constant::Function(function));
index
Expand Down
39 changes: 22 additions & 17 deletions core/engine/src/environments/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) use self::{
#[derive(Clone, Debug, Trace, Finalize)]
pub(crate) struct EnvironmentNode {
env: Environment,
parent: Option<Gc<EnvironmentNode>>,
parent: Option<Gc<'static, EnvironmentNode>>,
}

/// The environment stack holds all environments at runtime.
Expand All @@ -42,32 +42,32 @@ pub(crate) struct EnvironmentNode {
#[derive(Clone, Debug, Trace, Finalize)]
pub(crate) struct EnvironmentStack {
/// The tip (most recently pushed) environment in the chain.
tip: Option<Gc<EnvironmentNode>>,
tip: Option<Gc<'static, EnvironmentNode>>,

/// Number of environments in the chain (not counting global).
#[unsafe_ignore_trace]
depth: u32,

private_stack: ThinVec<Gc<PrivateEnvironment>>,
private_stack: ThinVec<Gc<'static, PrivateEnvironment>>,
}

/// Saved environment state for `pop_to_global` / `restore_from_saved`.
/// Used by indirect `eval` and `Function.prototype.toString` recompilation.
pub(crate) struct SavedEnvironments {
tip: Option<Gc<EnvironmentNode>>,
tip: Option<Gc<'static, EnvironmentNode>>,
depth: u32,
}

/// A runtime environment.
#[derive(Clone, Debug, Trace, Finalize)]
pub(crate) enum Environment {
Declarative(Gc<DeclarativeEnvironment>),
Declarative(Gc<'static, DeclarativeEnvironment>),
Object(JsObject),
}

impl Environment {
/// Returns the declarative environment if it is one.
pub(crate) const fn as_declarative(&self) -> Option<&Gc<DeclarativeEnvironment>> {
pub(crate) const fn as_declarative(&self) -> Option<&Gc<'static, DeclarativeEnvironment>> {
match self {
Self::Declarative(env) => Some(env),
Self::Object(_) => None,
Expand All @@ -86,7 +86,9 @@ impl EnvironmentStack {
}

/// Gets the next outer function environment.
pub(crate) fn outer_function_environment(&self) -> Option<(Gc<DeclarativeEnvironment>, Scope)> {
pub(crate) fn outer_function_environment(
&self,
) -> Option<(Gc<'static, DeclarativeEnvironment>, Scope)> {
for (env, _) in self.iter_from_tip() {
if let Some(decl) = env.as_declarative()
&& let Some(function_env) = decl.kind().as_function()
Expand Down Expand Up @@ -170,7 +172,7 @@ impl EnvironmentStack {
/// [spec]: https://tc39.es/ecma262/#sec-getthisenvironment
pub(crate) fn get_this_environment<'a>(
&'a self,
global: &'a Gc<DeclarativeEnvironment>,
global: &'a Gc<'static, DeclarativeEnvironment>,
) -> &'a DeclarativeEnvironmentKind {
for (env, _) in self.iter_from_tip() {
if let Some(decl) = env.as_declarative().filter(|decl| decl.has_this_binding()) {
Expand Down Expand Up @@ -211,7 +213,7 @@ impl EnvironmentStack {
pub(crate) fn push_lexical(
&mut self,
bindings_count: u32,
global: &Gc<DeclarativeEnvironment>,
global: &Gc<'static, DeclarativeEnvironment>,
) -> u32 {
let (poisoned, with) = self.compute_poisoned_with(global);

Expand All @@ -233,7 +235,7 @@ impl EnvironmentStack {
&mut self,
scope: Scope,
function_slots: FunctionSlots,
global: &Gc<DeclarativeEnvironment>,
global: &Gc<'static, DeclarativeEnvironment>,
) {
let num_bindings = scope.num_bindings_non_local();

Expand Down Expand Up @@ -278,8 +280,8 @@ impl EnvironmentStack {
/// Get the most outer environment.
pub(crate) fn current_declarative_ref<'a>(
&'a self,
global: &'a Gc<DeclarativeEnvironment>,
) -> Option<&'a Gc<DeclarativeEnvironment>> {
global: &'a Gc<'static, DeclarativeEnvironment>,
) -> Option<&'a Gc<'static, DeclarativeEnvironment>> {
if let Some(env) = self.last() {
env.as_declarative()
} else {
Expand All @@ -289,7 +291,10 @@ impl EnvironmentStack {

/// Mark that there may be added bindings from the current environment to the next function
/// environment.
pub(crate) fn poison_until_last_function(&mut self, global: &Gc<DeclarativeEnvironment>) {
pub(crate) fn poison_until_last_function(
&mut self,
global: &Gc<'static, DeclarativeEnvironment>,
) {
for (env, _) in self.iter_from_tip() {
if let Some(decl) = env.as_declarative() {
decl.poison();
Expand All @@ -312,7 +317,7 @@ impl EnvironmentStack {
environment: BindingLocatorScope,
binding_index: u32,
value: JsValue,
global: &Gc<DeclarativeEnvironment>,
global: &Gc<'static, DeclarativeEnvironment>,
) {
let env = match environment {
BindingLocatorScope::GlobalObject | BindingLocatorScope::GlobalDeclarative => global,
Expand All @@ -335,7 +340,7 @@ impl EnvironmentStack {
environment: BindingLocatorScope,
binding_index: u32,
value: JsValue,
global: &Gc<DeclarativeEnvironment>,
global: &Gc<'static, DeclarativeEnvironment>,
) {
let env = match environment {
BindingLocatorScope::GlobalObject | BindingLocatorScope::GlobalDeclarative => global,
Expand All @@ -350,7 +355,7 @@ impl EnvironmentStack {
}

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

Expand Down Expand Up @@ -413,7 +418,7 @@ impl EnvironmentStack {
}

/// Compute the `(poisoned, with)` flags for a new environment.
fn compute_poisoned_with(&self, global: &Gc<DeclarativeEnvironment>) -> (bool, bool) {
fn compute_poisoned_with(&self, global: &Gc<'static, DeclarativeEnvironment>) -> (bool, bool) {
let with = if let Some(env) = self.last() {
env.as_declarative().is_none()
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl ModuleRequest {
/// [spec]: https://tc39.es/ecma262/#sec-abstract-module-records
#[derive(Clone, Trace, Finalize)]
pub struct Module {
inner: Gc<ModuleRepr>,
inner: Gc<'static, ModuleRepr>,
}

impl std::fmt::Debug for Module {
Expand Down Expand Up @@ -382,7 +382,7 @@ impl Module {
}

/// Gets the declarative environment of this `Module`.
pub(crate) fn environment(&self) -> Option<Gc<DeclarativeEnvironment>> {
pub(crate) fn environment(&self) -> Option<Gc<'static, DeclarativeEnvironment>> {
match self.kind() {
ModuleKind::SourceText(src) => src.environment(),
ModuleKind::Synthetic(syn) => syn.environment(),
Expand Down Expand Up @@ -808,7 +808,7 @@ fn into_js_module() {
use std::cell::RefCell;
use std::rc::Rc;

type ResultType = Gc<GcRefCell<JsValue>>;
type ResultType = Gc<'static, GcRefCell<JsValue>>;

let loader = Rc::new(MapModuleLoader::default());
let mut context = Context::builder()
Expand Down
16 changes: 8 additions & 8 deletions core/engine/src/module/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,33 @@ enum ModuleStatus {
ancestor_index: usize,
},
PreLinked {
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
context: SourceTextContext,
ancestor_index: usize,
},
Linked {
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
context: SourceTextContext,
ancestor_index: usize,
},
Evaluating {
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
context: SourceTextContext,
top_level_capability: Option<PromiseCapability>,
cycle_root: Module,
ancestor_index: usize,
async_evaluation_order: Option<usize>,
},
EvaluatingAsync {
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
context: SourceTextContext,
top_level_capability: Option<PromiseCapability>,
cycle_root: Module,
async_evaluation_order: usize,
pending_async_dependencies: usize,
},
Evaluated {
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
top_level_capability: Option<PromiseCapability>,
cycle_root: Module,
error: Option<JsError>,
Expand Down Expand Up @@ -196,7 +196,7 @@ impl ModuleStatus {
}

/// Gets the declarative environment from the module status.
fn environment(&self) -> Option<Gc<DeclarativeEnvironment>> {
fn environment(&self) -> Option<Gc<'static, DeclarativeEnvironment>> {
match self {
ModuleStatus::Unlinked { .. } | ModuleStatus::Linking { .. } => None,
ModuleStatus::PreLinked { environment, .. }
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ModuleStatus {
#[derive(Clone, Trace, Finalize)]
#[boa_gc(unsafe_no_drop)]
struct SourceTextContext {
codeblock: Gc<CodeBlock>,
codeblock: Gc<'static, CodeBlock>,
environments: EnvironmentStack,
realm: Realm,
}
Expand Down Expand Up @@ -2031,7 +2031,7 @@ impl SourceTextModule {
}

/// Gets the declarative environment of this module.
pub(crate) fn environment(&self) -> Option<Gc<DeclarativeEnvironment>> {
pub(crate) fn environment(&self) -> Option<Gc<'static, DeclarativeEnvironment>> {
self.status.borrow().environment()
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/engine/src/module/synthetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
/// **Undefined Behaviour**.
#[derive(Clone, Trace, Finalize)]
pub struct SyntheticModuleInitializer {
inner: Gc<dyn TraceableCallback>,
inner: Gc<'static, dyn TraceableCallback>,
}

impl std::fmt::Debug for SyntheticModuleInitializer {
Expand Down Expand Up @@ -147,11 +147,11 @@ enum ModuleStatus {
#[default]
Unlinked,
Linked {
environment: Gc<DeclarativeEnvironment>,
eval_context: (EnvironmentStack, Gc<CodeBlock>),
environment: Gc<'static, DeclarativeEnvironment>,
eval_context: (EnvironmentStack, Gc<'static, CodeBlock>),
},
Evaluated {
environment: Gc<DeclarativeEnvironment>,
environment: Gc<'static, DeclarativeEnvironment>,
promise: JsPromise,
},
}
Expand Down Expand Up @@ -450,7 +450,7 @@ impl SyntheticModule {
Ok(promise)
}

pub(crate) fn environment(&self) -> Option<Gc<DeclarativeEnvironment>> {
pub(crate) fn environment(&self) -> Option<Gc<'static, DeclarativeEnvironment>> {
match &*self.state.borrow() {
ModuleStatus::Unlinked => None,
ModuleStatus::Linked { environment, .. }
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/native_function/continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
/// **Undefined Behaviour**.
#[derive(Clone, Trace, Finalize)]
pub(crate) struct NativeCoroutine {
inner: Gc<dyn TraceableCoroutine>,
inner: Gc<'static, dyn TraceableCoroutine>,
}

impl std::fmt::Debug for NativeCoroutine {
Expand Down
Loading