From 4664c915242cb66eef493dae27400f2e44399555 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Fri, 13 Oct 2023 17:52:49 +0200 Subject: [PATCH] Evaluate all parts of `class` in strict mode [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. --- boa_engine/src/bytecompiler/class.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/boa_engine/src/bytecompiler/class.rs b/boa_engine/src/bytecompiler/class.rs index 7ee875ad16c..a42f424f2b1 100644 --- a/boa_engine/src/bytecompiler/class.rs +++ b/boa_engine/src/bytecompiler/class.rs @@ -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 - + // - 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() { @@ -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); } }