tor-browser

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

custom-proto-access-resizes-buffer-invalid-by-offset.js (1258B)


      1 // Copyright (C) 2021 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-dataview-buffer-byteoffset-bytelength
      5 description: >
      6  The view's offset cannot exceed the underlying buffer's byte length if it is
      7  modified during retrieval of the NewTarget's prototype.
      8 features: [resizable-arraybuffer]
      9 ---*/
     10 
     11 // If the host chooses to throw as allowed by the specification, the observed
     12 // behavior will be identical to the case where `ArrayBuffer.prototype.resize`
     13 // has not been implemented. The following assertion prevents this test from
     14 // passing in runtimes which have not implemented the method.
     15 assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
     16 
     17 var buffer = new ArrayBuffer(3, {maxByteLength: 3});
     18 var expectedError;
     19 
     20 var newTarget = function() {}.bind(null);
     21 Object.defineProperty(newTarget, 'prototype', {
     22  get: function() {
     23    try {
     24      buffer.resize(1);
     25      expectedError = RangeError;
     26    } catch (error) {
     27      expectedError = null;
     28    }
     29  }
     30 });
     31 var error = null;
     32 
     33 try {
     34  Reflect.construct(DataView, [buffer, 2], newTarget);
     35 } catch (caught) {
     36  error = caught.constructor;
     37 }
     38 
     39 assert.sameValue(error, expectedError);
     40 
     41 reportCompare(0, 0);