From f71d5e29cb1b55b9b2c90e438dbbcc31b13026c5 Mon Sep 17 00:00:00 2001 From: legendecas Date: Fri, 18 Mar 2022 00:51:34 +0800 Subject: [PATCH] Add test for throwing WrappedFunctionCreate --- .../throws-typeerror-on-revoked-proxy.js | 40 +++++++++++ .../throws-typeerror-wrap-throwing.js | 70 +++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 test/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js create mode 100644 test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-wrap-throwing.js diff --git a/test/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js b/test/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js new file mode 100644 index 0000000000..b05d708a78 --- /dev/null +++ b/test/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Chengzhong Wu. 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: > + WrappedFunctionCreate throws a TypeError the target is a revoked proxy. + +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + 1. Let target be F.[[WrappedTargetFunction]]. + 2. Assert: IsCallable(target) is true. + 3. Let callerRealm be F.[[Realm]]. + 4. NOTE: Any exception objects produced after this point are associated with callerRealm. + 5. Let targetRealm be ? GetFunctionRealm(target). + ... + + GetFunctionRealm ( obj ) + ... + 3. If obj is a Proxy exotic object, then + a. If obj.[[ProxyHandler]] is null, throw a TypeError exception. + ... + +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(); + +const fn = r.evaluate(` +globalThis.revocable = Proxy.revocable(() => {}, {}); + +globalThis.revocable.proxy; +`); +r.evaluate('revocable.revoke()'); +assert.throws(TypeError, () => fn()); diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-wrap-throwing.js b/test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-wrap-throwing.js new file mode 100644 index 0000000000..4f1dacf0eb --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-wrap-throwing.js @@ -0,0 +1,70 @@ +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-wrappedfunctioncreate +description: > + WrappedFunctionCreate throws a TypeError if the accessing target's property may throw. + +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + ... + 7. Let result be CopyNameAndLength(wrapped, Target). + ... + + CopyNameAndLength ( F: a function object, Target: a function object, optional prefix: a String, optional argCount: a Number, ) + ... + 3. Let targetHasLength be ? HasOwnProperty(Target, "length"). + 4. If targetHasLength is true, then + a. Let targetLen be ? Get(Target, "length"). + ... + 6. Let targetName be ? Get(Target, "name"). + +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.throws(TypeError, () => r.evaluate(` +const revocable = Proxy.revocable(() => {}, {}); +revocable.revoke(); + +revocable.proxy; +`), 'TypeError on wrapping a revoked callable proxy'); + +assert.throws(TypeError, () => r.evaluate(` +const fn = () => {}; +Object.defineProperty(fn, 'name', { + get() { + throw new Error(); + }, +}); + +fn; +`), 'TypeError on wrapping a fn with throwing name accessor'); + +assert.throws(TypeError, () => r.evaluate(` +const fn = () => {}; +Object.defineProperty(fn, 'length', { + get() { + throw new Error(); + }, +}); + +fn; +`), 'TypeError on wrapping a fn with throwing length accessor'); + +assert.throws(TypeError, () => r.evaluate(` +const proxy = new Proxy(() => {}, { + getOwnPropertyDescriptor(target, key) { + throw new Error(); + }, +}); + +proxy; +`), 'TypeError on wrapping a callable proxy with throwing getOwnPropertyDescriptor trap');