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 / receiver-not-uint8array.js
blob53352ce4a50e4e66db4e222567a64c5caa1ca35f
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 throws if the receiver is not a Uint8Array
7 includes: [testTypedArray.js]
8 features: [uint8array-base64, TypedArray]
9 ---*/
11 var toBase64 = Uint8Array.prototype.toBase64;
13 var options = {};
14 Object.defineProperty(options, "alphabet", {
15   get: function() {
16     throw new Test262Error("options.alphabet accessed despite incompatible receiver");
17   }
18 });
20 testWithTypedArrayConstructors(function(TA) {
21   if (TA === Uint8Array) return;
22   var sample = new TA(2);
23   assert.throws(TypeError, function() {
24     Uint8Array.prototype.toBase64.call(sample, options);
25   });
26 });
28 assert.throws(TypeError, function() {
29   Uint8Array.prototype.toBase64.call([], options);
30 });
32 assert.throws(TypeError, function() {
33   toBase64(options);
34 });
36 reportCompare(0, 0);