Add test for shadow realms wrapped function behavior on throw

This commit is contained in:
Joseph Griego 2021-12-14 11:56:52 -05:00 committed by Rick Waldron
parent af00d69c39
commit 04cd6da021
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
// Copyright (C) 2021 Igalia SL. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-wrapped-function-exotic-objects-call-thisargument-argumentslist
description: >
WrappedFunction throws a TypeError if the wrapped function throws.
features: [ShadowRealm]
---*/
assert.sameValue(
typeof ShadowRealm.prototype.evaluate,
'function',
'This test must fail if ShadowRealm.prototype.evaluate is not a function'
);
const r = new ShadowRealm();
assert.sameValue(
r.evaluate(`(f) => {
try {
f();
} catch (e) {
if (e instanceof TypeError) {
return 'ok';
} else {
return e.toString();
}
}
return 'normal exit';
}`)(() => { throw Error("ahh"); }),
'ok',
'WrappedFunction throws TypeError (from the calling realm) if the wrapped callable throws any exception'
);
assert.throws(
TypeError,
() => r.evaluate('() => { throw new Error("ahh"); }')(),
'WrappedFunction throws TypeError if the wrapped callable throws any exception'
);