v8/test/mjsunit/regress/regress-4693.js
adamk 8aeb6080e1 Sloppy mode webcompat: allow conflicting function declarations in blocks
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}
2016-01-23 00:40:53 +00:00

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);