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 / setFromBase64 / string-coercion.js
blob7c479a78cdf7fc40d92f74ac21a556a343acb078
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.setfrombase64
6 description: Uint8Array.prototype.setFromBase64 throws if its first 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   var target = new Uint8Array(10);
20   target.setFromBase64(throwyToString);
21 });
22 assert.sameValue(toStringCalls, 0);
25 var optionAccesses = 0;
26 var touchyOptions = {};
27 Object.defineProperty(touchyOptions, "alphabet", {
28   get: function() {
29     optionAccesses += 1;
30     throw new Test262Error("alphabet accessed");
31   }
32 });
33 Object.defineProperty(touchyOptions, "lastChunkHandling", {
34   get: function() {
35     optionAccesses += 1;
36     throw new Test262Error("lastChunkHandling accessed");
37   }
38 });
39 assert.throws(TypeError, function() {
40   var target = new Uint8Array(10);
41   target.setFromBase64(throwyToString, touchyOptions);
42 });
43 assert.sameValue(toStringCalls, 0);
44 assert.sameValue(optionAccesses, 0);
46 reportCompare(0, 0);