8aeb6080e1
The web appears to depend on being able to redeclare functions-in-blocks in sloppy mode (examples seen so far tend to redeclare identical functions, most likely accidentally). This patch opens a minimal hole: two same-named function declarations in the same scope are allowed, only in sloppy mode. BUG=v8:4693, chromium:579395 LOG=y Review URL: https://codereview.chromium.org/1622723003 Cr-Commit-Position: refs/heads/master@{#33478}
30 lines
738 B
JavaScript
30 lines
738 B
JavaScript
// Copyright 2016 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.
|
|
//
|
|
// Flags: --harmony-sloppy-function
|
|
|
|
// In sloppy mode we allow function redeclarations within blocks for webcompat.
|
|
(function() {
|
|
assertEquals(undefined, f); // Annex B
|
|
if (true) {
|
|
assertEquals(2, f());
|
|
function f() { return 1 }
|
|
assertEquals(2, f());
|
|
function f() { return 2 }
|
|
assertEquals(2, f());
|
|
}
|
|
assertEquals(2, f()); // Annex B
|
|
})();
|
|
|
|
// Should still fail in strict mode
|
|
assertThrows(`
|
|
(function() {
|
|
"use strict";
|
|
if (true) {
|
|
function f() { return 1 }
|
|
function f() { return 2 }
|
|
}
|
|
})();
|
|
`, SyntaxError);
|