Skip to content

Commit

Permalink
Remove [[ClassFieldInitializerName]] from CodeBlock (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Jun 10, 2023
1 parent 0c790ac commit da4a331
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Eval {

// v. Let classFieldInitializerName be F.[[ClassFieldInitializerName]].
// vi. If classFieldInitializerName is not empty, set inClassFieldInitializer to true.
if function_object.class_field_initializer_name().is_some() {
if function_object.in_class_field_initializer() {
flags |= Flags::IN_CLASS_FIELD_INITIALIZER;
}

Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ impl Function {
}
}

/// Returns the `[[ClassFieldInitializerName]]` internal slot of the function.
pub(crate) fn class_field_initializer_name(&self) -> Option<Sym> {
/// Does this function have the `[[ClassFieldInitializerName]]` internal slot set to non-empty value.
pub(crate) fn in_class_field_initializer(&self) -> bool {
if let FunctionKind::Ordinary { code, .. } = &self.kind {
code.class_field_initializer_name
code.in_class_field_initializer()
} else {
None
false
}
}

Expand Down
15 changes: 9 additions & 6 deletions boa_engine/src/bytecompiler/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ impl ByteCompiler<'_, '_> {
field_compiler.pop_compile_environment();
field_compiler.emit_opcode(Opcode::Return);

let mut code = field_compiler.finish();
code.class_field_initializer_name = Some(Sym::EMPTY_STRING);
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = field_compiler.finish();
let code = Gc::new(code);
let index = self.functions.len() as u32;
self.functions.push(code);
Expand Down Expand Up @@ -298,8 +299,9 @@ impl ByteCompiler<'_, '_> {
field_compiler.pop_compile_environment();
field_compiler.emit_opcode(Opcode::Return);

let mut code = field_compiler.finish();
code.class_field_initializer_name = Some(Sym::EMPTY_STRING);
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = field_compiler.finish();
let code = Gc::new(code);
let index = self.functions.len() as u32;
self.functions.push(code);
Expand Down Expand Up @@ -339,8 +341,9 @@ impl ByteCompiler<'_, '_> {
field_compiler.pop_compile_environment();
field_compiler.emit_opcode(Opcode::Return);

let mut code = field_compiler.finish();
code.class_field_initializer_name = Some(Sym::EMPTY_STRING);
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = field_compiler.finish();
let code = Gc::new(code);
let index = self.functions.len() as u32;
self.functions.push(code);
Expand Down
5 changes: 0 additions & 5 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ pub struct ByteCompiler<'ctx, 'host> {
/// Compile time environments in this function.
pub(crate) compile_environments: Vec<Gc<GcRefCell<CompileTimeEnvironment>>>,

/// The `[[ClassFieldInitializerName]]` internal slot.
pub(crate) class_field_initializer_name: Option<Sym>,

/// The environment that is currently active.
pub(crate) current_environment: Gc<GcRefCell<CompileTimeEnvironment>>,

Expand Down Expand Up @@ -293,7 +290,6 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
this_mode: ThisMode::Global,
params: FormalParameterList::default(),
compile_environments: Vec::default(),
class_field_initializer_name: None,
code_block_flags,

literals_map: FxHashMap::default(),
Expand Down Expand Up @@ -1351,7 +1347,6 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
bindings: self.bindings.into_boxed_slice(),
functions: self.functions.into_boxed_slice(),
compile_environments: self.compile_environments.into_boxed_slice(),
class_field_initializer_name: self.class_field_initializer_name,
flags: Cell::new(self.code_block_flags),
}
}
Expand Down
15 changes: 10 additions & 5 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ bitflags! {
/// The `"arguments"` binding is the first binding.
const NEEDS_ARGUMENTS_OBJECT = 0b0001_0000;

/// The `[[ClassFieldInitializerName]]` internal slot.
const IN_CLASS_FIELD_INITIALIZER = 0b0010_0000;

/// Trace instruction execution to `stdout`.
#[cfg(feature = "trace")]
const TRACEABLE = 0b1000_0000;
Expand Down Expand Up @@ -127,10 +130,6 @@ pub struct CodeBlock {

/// Compile time environments in this function.
pub(crate) compile_environments: Box<[Gc<GcRefCell<CompileTimeEnvironment>>]>,

/// The `[[ClassFieldInitializerName]]` internal slot.
#[unsafe_ignore_trace]
pub(crate) class_field_initializer_name: Option<Sym>,
}

/// ---- `CodeBlock` public API ----
Expand All @@ -152,7 +151,6 @@ impl CodeBlock {
this_mode: ThisMode::Global,
params: FormalParameterList::default(),
compile_environments: Box::default(),
class_field_initializer_name: None,
}
}

Expand Down Expand Up @@ -208,6 +206,13 @@ impl CodeBlock {
.get()
.contains(CodeBlockFlags::NEEDS_ARGUMENTS_OBJECT)
}

/// Does this function have the `[[ClassFieldInitializerName]]` internal slot set to non-empty value.
pub(crate) fn in_class_field_initializer(&self) -> bool {
self.flags
.get()
.contains(CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER)
}
}

/// ---- `CodeBlock` private API ----
Expand Down

0 comments on commit da4a331

Please sign in to comment.