diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js')
-rw-r--r-- | js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js b/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js new file mode 100644 index 0000000000..541dbddf2f --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js @@ -0,0 +1,56 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2021 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-shadowrealm.prototype.evaluate +description: > + WrappedFunctionCreate should create a function derived from the caller realm +info: | + ShadowRealm.prototype.evaluate ( sourceText ) + ... + 4. Let callerRealm be the current Realm Record. + 5. Let evalRealm be O.[[ShadowRealm]]. + 6. Return ? PerformRealmEval(sourceText, callerRealm, evalRealm). + + PerformRealmEval ( sourceText, callerRealm, evalRealm ) + ... + 25. Return ? GetWrappedValue(callerRealm, result). + + GetWrappedValue ( callerRealm, value ) + ... + 2.b. Return ? WrappedFunctionCreate(callerRealm, value). + + WrappedFunctionCreate ( callerRealm, targetFunction ) + ... + 5. Set obj.[[Prototype]] to callerRealm.[[Intrinsics]].[[%Function.prototype%]]. +features: [ShadowRealm, cross-realm, Reflect] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +var other = $262.createRealm().global; +var OtherShadowRealm = other.ShadowRealm; +var OtherFunctionPrototype = other.Function.prototype; + +var yetAnother = $262.createRealm().global; +var YetAnotherShadowRealm = yetAnother.ShadowRealm; +var YetAnotherFunctionPrototype = yetAnother.Function.prototype; + +var realm = Reflect.construct(OtherShadowRealm, []); + +var checkArgWrapperFn = realm.evaluate('(x) => { return Object.getPrototypeOf(x) === Function.prototype }') +assert.sameValue(checkArgWrapperFn(() => {}), true, 'callable arguments passed into WrappedFunction should be wrapped in target realm'); + +var fn = realm.evaluate('() => { return () => { return 1 } }'); +assert.sameValue(Object.getPrototypeOf(fn), OtherFunctionPrototype, 'WrappedFunction should be derived from the caller realm'); +assert.sameValue(Object.getPrototypeOf(fn()), OtherFunctionPrototype, 'callable results from WrappedFunction should be wrapped in caller realm'); + +var fn = YetAnotherShadowRealm.prototype.evaluate.call(realm, '() => { return () => { return 1 } }'); +assert.sameValue(Object.getPrototypeOf(fn), YetAnotherFunctionPrototype, 'WrappedFunction should be derived from the caller realm'); +assert.sameValue(Object.getPrototypeOf(fn()), YetAnotherFunctionPrototype, 'callable results from WrappedFunction should be wrapped in caller realm'); + +reportCompare(0, 0); |