v8/test/mjsunit/regress/regress-v8-12671.js
jameslahm 515c3887ed [parser] binding arguments var declaration in inner_scope
when has_simple_parameters_ is false in DeclareArguments

- According to https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-functiondeclarationinstantiation
step 28, arguments var declaration in function should be binding to
arguments parameterBindings when has_simple_parameters_ is false.
- According to https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-funct>
step 18, we should set arguments_ is nullptr if "arguments" is an element of lexicalNames
only when has_simple_parameters is true.

Bug: v8:12671
Change-Id: I542f80e2c8653ae05b65feb0036e4ade2e653a53
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3499251
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79382}
2022-03-07 09:33:52 +00:00

75 lines
2.9 KiB
JavaScript

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// spec:
// https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html
// #sec-functiondeclarationinstantiation
// This regession focus on checking [var declared "arguments" should bind to
// "arguments exotic object" when has_simple_parameters_ is false and
// inner_scope has var declared "arguments"]
// according to ES#sec-functiondeclarationinstantiation step 8,
// hasParameterExpressions is false, and according to step 15-18,
// argumentsObjectNeeded is true, according to step 27,
// var declared arguments should bind to arguments exotic object
function no_parameters_and_non_lexical_arguments() {
assertEquals(typeof arguments, 'object');
var arguments;
}
no_parameters_and_non_lexical_arguments()
// according to ES#sec-functiondeclarationinstantiation step 8,
// hasParameterExpressions is false, and according to step 15-18,
// argumentsObjectNeeded is true, according to step 28,
// var declared arguments should bind to arguments exotic object
function destructuring_parameters_and_non_lexical_arguments([_]) {
assertEquals(typeof arguments, 'object');
var arguments;
}
destructuring_parameters_and_non_lexical_arguments([])
// according to ES#sec-functiondeclarationinstantiation step 8,
// hasParameterExpressions is false, and according to step 15-18,
// argumentsObjectNeeded is true, according to step 28,
// var declared arguments should bind to arguments exotic object
function rest_parameters_and_non_lexical_arguments(..._) {
assertEquals(typeof arguments, 'object');
var arguments;
}
rest_parameters_and_non_lexical_arguments()
// according to ES#sec-functiondeclarationinstantiation step 8,
// hasParameterExpressions is true, and according to step 15-18,
// argumentsObjectNeeded is true, according to step 28,
// var declared arguments should bind to arguments exotic object
function initializer_parameters_and_non_lexical_arguments(_ = 0) {
assertEquals(typeof arguments, 'object');
var arguments;
}
initializer_parameters_and_non_lexical_arguments()
// according to ES#sec-functiondeclarationinstantiation step 8,
// hasParameterExpressions is true, and according to step 15-18,
// and argumentsObjectNeeded is true, according to step 34, should
// throw because access to let declared arguments
function initializer_parameters_and_lexical_arguments(_ = 0) {
return typeof arguments;
let arguments;
}
assertThrows(initializer_parameters_and_lexical_arguments);
// according to ES#sec-functiondeclarationinstantiation step 8,
// hasParameterExpressions is false, and according to step 15-18,
// argumentsObjectNeeded is false, according to step 34,
// should throw because access to let declared arguments
function simple_parameters_and_lexical_arguments(_) {
return typeof arguments;
let arguments;
}
assertThrows(simple_parameters_and_lexical_arguments);