-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proxied-observes-boundary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (C) 2021 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-shadowrealm.prototype.evaluate | ||
description: > | ||
Proxying a wrapped function and invoking it still performs boundary checks | ||
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 wrapped = r.evaluate(`() => { return 1; };`); | ||
|
||
const secretObj = {x: 2}; | ||
|
||
let received; | ||
|
||
const proxiedWrapped = new Proxy(wrapped, { | ||
apply(target, _, args) { | ||
assert.sameValue(target, wrapped); | ||
received = args; | ||
|
||
// Object can't be sent to the other Realm | ||
return target({x: 1}); | ||
} | ||
}); | ||
|
||
assert.throws( | ||
TypeError, | ||
() => proxiedWrapped(secretObj), | ||
'Proxying a wrapped function and invoking it still performs boundary checks' | ||
); | ||
|
||
assert.sameValue(received[0], secretObj, 'proxy still calls the handler trap'); | ||
assert.sameValue(received.length, 1); |