Bug 1885337 - Part 3: Import tests from test262 PR. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / prs / 3994 / built-ins / Uint8Array / prototype / toBase64 / detached-buffer.js
blob0904454743bffc03274c69a415383c95df9b90e4
1 // |reftest| shell-option(--enable-uint8array-base64) skip-if(!Uint8Array.fromBase64||!xulRuntime.shell) -- uint8array-base64 is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 Kevin Gibbons. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-uint8array.prototype.tobase64
6 description: Uint8Array.prototype.toBase64 checks for detachedness after side-effects are finished
7 includes: [detachArrayBuffer.js]
8 features: [uint8array-base64, TypedArray]
9 ---*/
11 var array = new Uint8Array(2);
12 var getterCalls = 0;
13 var receiverDetachingOptions = {};
14 Object.defineProperty(receiverDetachingOptions, "alphabet", {
15   get: function() {
16     getterCalls += 1;
17     $DETACHBUFFER(array.buffer);
18     return "base64";
19   }
20 });
21 assert.throws(TypeError, function() {
22   array.toBase64(receiverDetachingOptions);
23 });
24 assert.sameValue(getterCalls, 1);
27 var detached = new Uint8Array(2);
28 $DETACHBUFFER(detached.buffer);
29 var getterCalls = 0;
30 var sideEffectingOptions = {};
31 Object.defineProperty(sideEffectingOptions, "alphabet", {
32   get: function() {
33     getterCalls += 1;
34     return "base64";
35   }
36 });
37 assert.throws(TypeError, function() {
38   detached.toBase64(sideEffectingOptions);
39 });
40 assert.sameValue(getterCalls, 1);
42 reportCompare(0, 0);