From 04cd6da021461653b2fb1076392b6e13ffb9b1d7 Mon Sep 17 00:00:00 2001 From: Joseph Griego Date: Tue, 14 Dec 2021 11:56:52 -0500 Subject: [PATCH] Add test for shadow realms wrapped function behavior on throw --- ...on-throws-typeerror-on-exceptional-exit.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-exceptional-exit.js diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-exceptional-exit.js b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-exceptional-exit.js new file mode 100644 index 0000000000..cc4d0933a1 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-exceptional-exit.js @@ -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' +);