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 (1343B)


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