v8/test/mjsunit/es6/default-parameters-destructuring.js
Shu-yu Guo 1b450a1752 Remove per-parameter position var scope
The spec was normatively changed to simplify var scopes for parameter
expressions. Previously there was a per-parameter var scope in sloppy
mode so direct evals could introduce vars that did not escape the
parameter position. That semantics is complex both for the programmer
and implementation and has resulted in bugs in the past. Furthermore, it
has never been fully interoperable (with Safari in particular). The spec
was instead changed to be simpler: to have a single var scope for
sloppy evals in parameters that encloses the parameter scope and body
scope.

This simplification lets us remove expression-scope-reparenter.

Drive-by removal of stale reference to PatternRewriter.

Bug: v8:7532
Change-Id: Iade5594abe0009f7f3f6a1adad18628b17e1e779
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1962471
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65517}
2019-12-19 10:38:00 +00:00

111 lines
4.1 KiB
JavaScript

// Copyright 2015 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.
(function TestSloppyEvalScoping() {
var x = 1;
function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; }
assertEquals(2, f41({}));
assertEquals(2, f41({a: 0}));
function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; }
assertEquals(2, f42({}));
assertEquals(2, f42({a: 0}));
function f43({a: w = eval("var x = 2")}, z = x) { return z; }
assertEquals(2, f43({}));
assertEquals(1, f43({a: 0}));
function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; }
assertEquals(2, f44({}));
assertEquals(1, f44({a: 0}));
function f5({a = eval("var x = 2"), b = x}) { return b; }
assertEquals(2, f5({}));
assertEquals(1, f5({a: 0}));
function f6({a = eval("var x = 2"), b = eval("x")}) { return b; }
assertEquals(2, f6({}));
assertEquals(1, f6({a: 0}));
function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; }
assertEquals(2, f71({}));
assertEquals(2, f71({a: 0}));
function f72({[eval("var x = 2; 'a'")]: w, b = eval("x")}) { return b; }
assertEquals(2, f72({}));
assertEquals(2, f72({a: 0}));
function f73({a: w = eval("var x = 2"), b = x}) { return b; }
assertEquals(2, f73({}));
assertEquals(1, f73({a: 0}));
function f74({a: w = eval("var x = 2"), b = eval("x")}) { return b; }
assertEquals(2, f74({}));
assertEquals(1, f74({a: 0}));
var g41 = ({[eval("var x = 2; 'a'")]: w}, z = x) => { return z; };
assertEquals(2, g41({}));
assertEquals(2, g41({a: 0}));
var g42 = ({[eval("var x = 2; 'a'")]: w}, z = eval("x")) => { return z; };
assertEquals(2, g42({}));
assertEquals(2, g42({a: 0}));
var g43 = ({a: w = eval("var x = 2")}, z = x) => { return z; };
assertEquals(2, g43({}));
assertEquals(1, g43({a: 0}));
var g44 = ({a: w = eval("var x = 2")}, z = eval("x")) => { return z; };
assertEquals(2, g44({}));
assertEquals(1, g44({a: 0}));
var g5 = ({a = eval("var x = 2"), b = x}) => { return b; };
assertEquals(2, g5({}));
assertEquals(1, g5({a: 0}));
var g6 = ({a = eval("var x = 2"), b = eval("x")}) => { return b; };
assertEquals(2, g6({}));
assertEquals(1, g6({a: 0}));
var g71 = ({[eval("var x = 2; 'a'")]: w, b = x}) => { return b; };
assertEquals(2, g71({}));
assertEquals(2, g71({a: 0}));
var g72 = ({[eval("var x = 2; 'a'")]: w, b = eval("x")}) => { return b; };
assertEquals(2, g72({}));
assertEquals(2, g72({a: 0}));
var g73 = ({a: w = eval("var x = 2"), b = x}) => { return b; };
assertEquals(2, g73({}));
assertEquals(1, g73({a: 0}));
var g74 = ({a: w = eval("var x = 2"), b = eval("x")}) => { return b; };
assertEquals(2, g74({}));
assertEquals(1, g74({a: 0}));
})();
(function TestStrictEvalScoping() {
'use strict';
var x = 1;
function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; }
assertEquals(1, f41({}));
assertEquals(1, f41({a: 0}));
function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; }
assertEquals(1, f42({}));
assertEquals(1, f42({a: 0}));
function f43({a: w = eval("var x = 2")}, z = x) { return z; }
assertEquals(1, f43({}));
assertEquals(1, f43({a: 0}));
function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; }
assertEquals(1, f44({}));
assertEquals(1, f44({a: 0}));
function f5({a = eval("var x = 2"), b = x}) { return b; }
assertEquals(1, f5({}));
assertEquals(1, f5({a: 0}));
function f6({a = eval("var x = 2"), b = eval("x")}) { return b; }
assertEquals(1, f6({}));
assertEquals(1, f6({a: 0}));
function f71({[eval("var x = 2; 'a'")]: w, b = x}) { return b; }
assertEquals(1, f71({}));
assertEquals(1, f71({a: 0}));
function f72({[eval("var x = 2; 'a'")]: w, b = eval("x")}) { return b; }
assertEquals(1, f72({}));
assertEquals(1, f72({a: 0}));
function f73({a: w = eval("var x = 2"), b = x}) { return b; }
assertEquals(1, f73({}));
assertEquals(1, f73({a: 0}));
function f74({a: w = eval("var x = 2"), b = eval("x")}) { return b; }
assertEquals(1, f74({}));
assertEquals(1, f74({a: 0}));
})();