Bug 1885337 - Part 3: Import tests from test262 PR. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / prs / 3994 / built-ins / Uint8Array / fromBase64 / string-coercion.js
blob57292f8a9848b5804491998b79909215edf0976e
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.frombase64
6 description: Uint8Array.fromBase64 throws if its argument is not a string
7 features: [uint8array-base64, TypedArray]
8 ---*/
10 var toStringCalls = 0;
11 var throwyToString = {
12   toString: function() {
13     toStringCalls += 1;
14     throw new Test262Error("toString called");
15   }
18 assert.throws(TypeError, function() {
19   Uint8Array.fromBase64(throwyToString);
20 });
21 assert.sameValue(toStringCalls, 0);
24 var optionAccesses = 0;
25 var touchyOptions = {};
26 Object.defineProperty(touchyOptions, "alphabet", {
27   get: function() {
28     optionAccesses += 1;
29     throw new Test262Error("alphabet accessed");
30   }
31 });
32 Object.defineProperty(touchyOptions, "lastChunkHandling", {
33   get: function() {
34     optionAccesses += 1;
35     throw new Test262Error("lastChunkHandling accessed");
36   }
37 });
38 assert.throws(TypeError, function() {
39   Uint8Array.fromBase64(throwyToString, touchyOptions);
40 });
41 assert.sameValue(toStringCalls, 0);
42 assert.sameValue(optionAccesses, 0);
44 reportCompare(0, 0);