nodejs/deps/v8/test/mjsunit/harmony/shadowrealm-wrapped-function.js
Michaël Zasso f226350fcb deps: update V8 to 11.3.244.4
PR-URL: https://github.com/nodejs/node/pull/47251
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2023-03-31 14:15:23 +00:00

54 lines
1.5 KiB
JavaScript

// Copyright 2022 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-shadow-realm
var shadowRealm = new ShadowRealm();
// create a proxy on the wrapped value
var wrapped = shadowRealm.evaluate('() => 1');
assertEquals(wrapped(), 1);
var proxy = new Proxy(wrapped, {
call: function(target, thisArg, args) {
assertEquals(target, wrapped);
return target();
},
});
assertEquals(proxy(), 1);
// create a revocable proxy on the wrapped value
var revocable = Proxy.revocable(wrapped, {
call: function(target, thisArg, args) {
assertEquals(target, wrapped);
return target();
},
});
var proxy = revocable.proxy;
assertEquals(proxy(), 1);
revocable.revoke();
assertThrows(() => proxy(), TypeError, "Cannot perform 'apply' on a proxy that has been revoked");
// no-side-effects inspection on thrown error
var wrapped = shadowRealm.evaluate(`() => {
throw new Error('foo');
}`);
assertThrows(() => wrapped(), TypeError, "WrappedFunction threw (Error: foo)");
// no-side-effects inspection on thrown error
var wrapped = shadowRealm.evaluate(`
globalThis.messageAccessed = false;
() => {
const err = new Error('foo');
Object.defineProperty(err, 'message', {
get: function() {
globalThis.messageAccessed = true;
return 'bar';
},
});
throw err;
}
`);
assertThrows(() => wrapped(), TypeError, "WrappedFunction threw (Error)");
assertFalse(shadowRealm.evaluate('globalThis.messageAccessed'));