mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
[explicit-resource-management]Add exception handling to sync ERM
This CL adds exception handling to the implementation of sync explicit management proposal. Bug: v8:13559 Change-Id: I2f4ffea432057b753634c2af4801f9dc48edac43 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5405985 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Rezvan Mahdavi Hezaveh <rezvan@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/main@{#93620}
This commit is contained in:
parent
c2ae5ed5e9
commit
27b6e4500f
136
test/staging/explicit-resource-management/exception-handling.js
Normal file
136
test/staging/explicit-resource-management/exception-handling.js
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
// Copyright (C) 2024 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test exception handling.
|
||||||
|
features: [explicit-resource-management]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// User code throws -----------------------------
|
||||||
|
function TestUserCodeThrowsBeforeUsingStatements() {
|
||||||
|
{
|
||||||
|
throw new Test262Error('User code is throwing!');
|
||||||
|
using x = {
|
||||||
|
value: 1,
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
Test262Error, () => TestUserCodeThrowsBeforeUsingStatements(),
|
||||||
|
'User code is throwing!');
|
||||||
|
|
||||||
|
function TestUserCodeThrowsAfterUsingStatements() {
|
||||||
|
{
|
||||||
|
using x = {
|
||||||
|
value: 1,
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
throw new Test262Error('User code is throwing!');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(
|
||||||
|
Test262Error, () => TestUserCodeThrowsAfterUsingStatements(),
|
||||||
|
'User code is throwing!');
|
||||||
|
|
||||||
|
// Dispose method throws -----------------------------
|
||||||
|
function TestDisposeMethodThrows() {
|
||||||
|
{
|
||||||
|
using x = {
|
||||||
|
value: 1,
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
throw new Test262Error('Symbol.dispose is throwing!');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(
|
||||||
|
Test262Error, () => TestDisposeMethodThrows(),
|
||||||
|
'Symbol.dispose is throwing!');
|
||||||
|
|
||||||
|
// Dispose method is not a function -----------------------------
|
||||||
|
function TestDisposeMethodNotAFunction() {
|
||||||
|
using x = 42;
|
||||||
|
};
|
||||||
|
assert.throws(
|
||||||
|
TypeError, () => TestDisposeMethodNotAFunction(),
|
||||||
|
'Symbol.Dispose is not a function');
|
||||||
|
|
||||||
|
// A suppressed error from an error in try block and an error in disposal
|
||||||
|
// -----------------------------
|
||||||
|
let userCodeError = new Test262Error('User code is throwing!');
|
||||||
|
let disposeError = new Test262Error('Symbol.dispose is throwing!');
|
||||||
|
|
||||||
|
function TestDisposeMethodAndUserCodeThrow() {
|
||||||
|
{
|
||||||
|
using x = {
|
||||||
|
value: 1,
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
throw disposeError;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
throw userCodeError;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
SuppressedError, () => TestDisposeMethodAndUserCodeThrow(),
|
||||||
|
'An error was suppressed during disposal');
|
||||||
|
|
||||||
|
function RunTestDisposeMethodAndUserCodeThrow() {
|
||||||
|
try {
|
||||||
|
TestDisposeMethodAndUserCodeThrow();
|
||||||
|
} catch (error) {
|
||||||
|
assert(
|
||||||
|
error instanceof SuppressedError,
|
||||||
|
'error is an instanceof SuppressedError');
|
||||||
|
assert.sameValue(error.error, disposeError, 'error.error');
|
||||||
|
assert.sameValue(error.suppressed, userCodeError, 'error.suppressed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RunTestDisposeMethodAndUserCodeThrow();
|
||||||
|
|
||||||
|
// A suppressed error from two errors in disposal -----------------------------
|
||||||
|
let firstDisposeError =
|
||||||
|
new Test262Error('The first Symbol.dispose is throwing!');
|
||||||
|
let secondDisposeError =
|
||||||
|
new Test262Error('The second Symbol.dispose is throwing!');
|
||||||
|
|
||||||
|
function TestTwoDisposeMethodsThrow() {
|
||||||
|
{
|
||||||
|
using x = {
|
||||||
|
value: 1,
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
throw firstDisposeError;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
using y = {
|
||||||
|
value: 1,
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
throw secondDisposeError;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
SuppressedError, () => TestTwoDisposeMethodsThrow(),
|
||||||
|
'An error was suppressed during disposal');
|
||||||
|
|
||||||
|
function RunTestTwoDisposeMethodsThrow() {
|
||||||
|
try {
|
||||||
|
TestTwoDisposeMethodsThrow();
|
||||||
|
} catch (error) {
|
||||||
|
assert(
|
||||||
|
error instanceof SuppressedError,
|
||||||
|
'error is an instanceof SuppressedError');
|
||||||
|
assert.sameValue(error.error, firstDisposeError, 'error.error');
|
||||||
|
assert.sameValue(error.suppressed, secondDisposeError, 'error.suppressed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RunTestTwoDisposeMethodsThrow();
|
Loading…
x
Reference in New Issue
Block a user