v8/test/mjsunit/harmony/shadowrealm-wrapped-function.js
legendecas 62155dbd3c [ShadowRealm] ShadowRealm.prototype.evaluate and WrappedFunction
Bootstrap ShadowRealm.prototype.evaluate, WrappedFunction
and WrappedFunction.[[Call]].

Bug: v8:11989
Change-Id: Id380acb71cd5719e783c8f5d741cc4ccf2a93e78
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3432729
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Chengzhong Wu <legendecas@gmail.com>
Cr-Commit-Position: refs/heads/main@{#79293}
2022-02-25 19:16:17 +00:00

31 lines
894 B
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");