Truly independent web browser
LibJS: Note the use of arguments in a strict arrow of a sloppy function
Shannon Booth5e62719a7e79
diff --git a/Libraries/LibJS/Parser/Rust/src/base.rs b/Libraries/LibJS/Parser/Rust/src/base.rsindex dc37fbd6753..c99b6e592d3 100644--- a/Libraries/LibJS/Parser/Rust/src/base.rs+++ b/Libraries/LibJS/Parser/Rust/src/base.rs@@ -212,7 +212,7 @@ pub(crate) struct FunctionState {pub arguments_other_uses: u32,pub reads_arguments_index: bool,pub may_write_parameters: bool,- pub in_class_of_sloppy_function: bool,+ pub arguments_of_sloppy_function: bool,pub is_arrow: bool,pub summary_ordinal: u32,}@@ -409,9 +409,9 @@ pub struct Parser<'a, 'k, U: Unit> {pub(crate) reads_arguments_index: bool,/// Whether something in the function may write a binding of the name of one of its parameters.pub(crate) may_write_parameters: bool,- /// Whether the code being parsed is in a class in a function that is not strict. The code of a class is strict, but- /// `arguments` in its heritage and computed keys is the arguments object of that function.- pub(crate) in_class_of_sloppy_function: bool,+ /// Whether the code being parsed is strict, but `arguments` in it may be that of a function around it that is not.+ /// That is so in the heritage and computed keys of a class, and in an arrow function with its own "use strict".+ pub(crate) arguments_of_sloppy_function: bool,/// Whether the closest function, counting static blocks, is an arrow function.pub(crate) in_arrow: bool,@@ -649,7 +649,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {arguments_other_uses: 0,reads_arguments_index: false,may_write_parameters: false,- in_class_of_sloppy_function: false,+ arguments_of_sloppy_function: false,in_arrow: false,private_declared: ZoneVec::new_in(zone),@@ -1993,7 +1993,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {arguments_other_uses: self.arguments_other_uses,reads_arguments_index: self.reads_arguments_index,may_write_parameters: self.may_write_parameters,- in_class_of_sloppy_function: self.in_class_of_sloppy_function,+ arguments_of_sloppy_function: self.arguments_of_sloppy_function,is_arrow: self.in_arrow,summary_ordinal: self.summary_ordinal,};@@ -2005,7 +2005,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {self.reads_arguments_index = false;self.may_write_parameters = false;self.in_arrow = flags & function_flag::ARROW != 0;- self.in_class_of_sloppy_function &= self.in_arrow;+ self.arguments_of_sloppy_function &= self.in_arrow;self.ctx = new_ctx;self.labels_base = self.labels.len() as u32;self.yield_pos = 0;@@ -2229,7 +2229,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {self.arguments_other_uses = state.arguments_other_uses + u32::from(arrow_might_need_arguments);self.reads_arguments_index = state.reads_arguments_index;self.may_write_parameters = state.may_write_parameters;- self.in_class_of_sloppy_function = state.in_class_of_sloppy_function;+ self.arguments_of_sloppy_function = state.arguments_of_sloppy_function;self.in_arrow = state.is_arrow;if retained {diff --git a/Libraries/LibJS/Parser/Rust/src/expr.rs b/Libraries/LibJS/Parser/Rust/src/expr.rsindex e0a59cf6830..9a71d856e15 100644--- a/Libraries/LibJS/Parser/Rust/src/expr.rs+++ b/Libraries/LibJS/Parser/Rust/src/expr.rs@@ -778,7 +778,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {// NB: A read of `arguments.length` or `arguments[key]` takes this back (see `note_arguments_read()`).self.arguments_other_uses += u32::from(name == N_ARGUMENTS);if name == N_ARGUMENTS- && (!self.strict || self.in_class_of_sloppy_function)+ && (!self.strict || self.arguments_of_sloppy_function)&& !self.is_declared_in_current_function(name){self.scopes.last_mut().unwrap().arguments_access = true;diff --git a/Libraries/LibJS/Parser/Rust/src/stmt.rs b/Libraries/LibJS/Parser/Rust/src/stmt.rsindex d2ad1f06998..78e09240d58 100644--- a/Libraries/LibJS/Parser/Rust/src/stmt.rs+++ b/Libraries/LibJS/Parser/Rust/src/stmt.rs@@ -1036,7 +1036,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {arguments_other_uses: 0,reads_arguments_index: false,may_write_parameters: false,- in_class_of_sloppy_function: self.in_class_of_sloppy_function,+ arguments_of_sloppy_function: self.arguments_of_sloppy_function,is_arrow: false,summary_ordinal: 0,}@@ -1241,6 +1241,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {}if use_strict {self.strict = true;+ self.arguments_of_sloppy_function |= is_arrow && !old_strict;}if self.duplicate_parameter != NONE && (self.strict || !simple || is_arrow || is_method) {self.fail(self.duplicate_parameter, "Duplicate parameter names not allowed");@@ -1314,8 +1315,8 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {let saved_class_start = core::mem::replace(&mut self.class_start, start);self.next();let old_strict = self.strict;- let was_in_class_of_sloppy_function = self.in_class_of_sloppy_function;- self.in_class_of_sloppy_function |= !old_strict;+ let was_arguments_of_sloppy_function = self.arguments_of_sloppy_function;+ self.arguments_of_sloppy_function |= !old_strict;self.strict = true;let mut name = NONE;if self.tok == T::Name && !(self.is_contextual(N_IMPLEMENTS)) {@@ -1359,7 +1360,7 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {self.scratch.push(element);}self.strict = old_strict;- self.in_class_of_sloppy_function = was_in_class_of_sloppy_function;+ self.arguments_of_sloppy_function = was_arguments_of_sloppy_function;self.class_start = saved_class_start;self.expect(T::RBrace);self.exit_class_body();diff --git a/Tests/LibJS/Runtime/arguments-object.js b/Tests/LibJS/Runtime/arguments-object.jsindex b67d65636d4..465f9326727 100644--- a/Tests/LibJS/Runtime/arguments-object.js+++ b/Tests/LibJS/Runtime/arguments-object.js@@ -433,3 +433,40 @@ test("mapped arguments object in the strict code of a class", () => {expect(arrowInKey("key")).toEqual(["constructor", "key"]);expect(withEnvironment("key")).toEqual(["constructor", "key"]);});++test("mapped arguments used only in an arrow function with a use strict directive", () => {+ function read(a) {+ return (() => {+ "use strict";+ return arguments[0];+ })();+ }+ expect(read(1)).toBe(1);++ function write(a) {+ (() => {+ "use strict";+ arguments[0] = 9;+ })();+ return a;+ }+ expect(write(1)).toBe(9);++ function writeParameter(a) {+ a = 5;+ return (() => {+ "use strict";+ return (() => [...arguments])();+ })();+ }+ expect(writeParameter(1, 2)).toEqual([5, 2]);++ function* generator(a) {+ yield (() => {+ "use strict";+ return delete arguments[0];+ })();+ yield a;+ }+ expect([...generator(1)]).toEqual([true, 1]);+});