tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

options-maxbytelength-compared-before-object-creation.js (1173B)


      1 // Copyright (C) 2024 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-arraybuffer-length
      6 description: >
      7  The byteLength argument is validated before OrdinaryCreateFromConstructor.
      8 info: |
      9  ArrayBuffer ( length [ , options ] )
     10 
     11  ...
     12  4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
     13 
     14  AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )
     15 
     16  ...
     17  3. If allocatingResizableBuffer is true, then
     18    a. If byteLength > maxByteLength, throw a RangeError exception.
     19  ...
     20  4. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBuffer.prototype%", slots).
     21  ...
     22 
     23 features: [resizable-arraybuffer, Reflect.construct]
     24 ---*/
     25 
     26 let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", {
     27  get() {
     28    throw new Test262Error();
     29  }
     30 });
     31 
     32 assert.throws(RangeError, function() {
     33  let byteLength = 10;
     34  let options = {
     35    maxByteLength: 0,
     36  };
     37 
     38  // Throws a RangeError, because `byteLength` is larger than `options.maxByteLength`.
     39  Reflect.construct(ArrayBuffer, [byteLength, options], newTarget);
     40 });
     41 
     42 reportCompare(0, 0);