v8/test/mjsunit/harmony/optional-catch-binding.js
Sathya Gunasekaran 779c080895 [ESNext] Implement optional catch binding
This is just a rebased version of
https://chromium-review.googlesource.com/c/v8/v8/+/571453 with
no functional changes

Bug: v8:6889
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ia082cc09ca527505b288ac88e68e0b74eae94765
Reviewed-on: https://chromium-review.googlesource.com/849423
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50417}
2018-01-08 18:09:34 +00:00

40 lines
710 B
JavaScript

// Copyright 2017 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-optional-catch-binding
let state = 'initial';
try {
throw new Error('caught');
state = 'unreachable';
} catch { // Note the lack of a binding
assertEquals(state, 'initial');
state = 'caught';
}
assertEquals(state, 'caught');
let sigil1 = {};
try {
throw sigil1;
} catch (e) {
assertEquals(e, sigil1);
}
let sigil2 = {};
let reached = false;
try {
try {
throw sigil1;
} catch {
reached = true;
} finally {
throw sigil2;
}
} catch (e) {
assertEquals(e, sigil2);
}
assertTrue(reached);