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

Evaluate all parts of class in strict mode #3383

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions boa_engine/src/bytecompiler/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ impl ByteCompiler<'_, '_> {
/// A class declaration binds the resulting class object to it's identifier.
/// A class expression leaves the resulting class object on the stack for following operations.
pub(crate) fn compile_class(&mut self, class: &Class, expression: bool) {
// 11.2.2 Strict Mode Code - <https://tc39.es/ecma262/#sec-strict-mode-code>
// - All parts of a ClassDeclaration or a ClassExpression are strict mode code.
let strict = self.strict();
self.code_block_flags |= CodeBlockFlags::STRICT;

let class_name = class.name().map_or(Sym::EMPTY_STRING, Identifier::sym);

let old_lex_env = match class.name() {
Expand Down Expand Up @@ -593,5 +598,8 @@ impl ByteCompiler<'_, '_> {
if !expression {
self.emit_binding(BindingOpcode::InitVar, class_name.into());
}

// NOTE: Reset strict mode to before class declaration/expression evalutation.
self.code_block_flags.set(CodeBlockFlags::STRICT, strict);
}
}