tor-browser

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

toindex-bytelength.js (2521B)


      1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-dataview-buffer-byteoffset-bytelength
      6 description: >
      7  ToIndex conversions on byteLength
      8 info: |
      9  24.2.2.1 DataView ( buffer, byteOffset, byteLength )
     10 
     11  ...
     12  8. If byteLength is either not present or undefined, then
     13    a. Let viewByteLength be bufferByteLength - offset.
     14  9. Else,
     15    a. Let viewByteLength be ? ToIndex(byteLength).
     16    b. If offset + viewByteLength > bufferByteLength, throw a RangeError
     17    exception.
     18  ...
     19 
     20  ToIndex( value )
     21 
     22  1. If value is undefined, then
     23    a. Let index be 0.
     24  2. Else,
     25    a. Let integerIndex be ? ToInteger(value).
     26    b. If integerIndex < 0, throw a RangeError exception.
     27    c. Let index be ! ToLength(integerIndex).
     28    d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception.
     29  3. Return index.
     30 ---*/
     31 
     32 var obj1 = {
     33  valueOf: function() {
     34    return 3;
     35  }
     36 };
     37 
     38 var obj2 = {
     39  toString: function() {
     40    return 4;
     41  }
     42 };
     43 
     44 var sample;
     45 var ab = new ArrayBuffer(42);
     46 
     47 sample = new DataView(ab, 0, -0);
     48 assert.sameValue(sample.byteLength, 0, "-0");
     49 
     50 sample = new DataView(ab, 0, obj1);
     51 assert.sameValue(sample.byteLength, 3, "object's valueOf");
     52 
     53 sample = new DataView(ab, 0, obj2);
     54 assert.sameValue(sample.byteLength, 4, "object's toString");
     55 
     56 sample = new DataView(ab, 0, "");
     57 assert.sameValue(sample.byteLength, 0, "the Empty string");
     58 
     59 sample = new DataView(ab, 0, "0");
     60 assert.sameValue(sample.byteLength, 0, "string '0'");
     61 
     62 sample = new DataView(ab, 0, "1");
     63 assert.sameValue(sample.byteLength, 1, "string '1'");
     64 
     65 sample = new DataView(ab, 0, true);
     66 assert.sameValue(sample.byteLength, 1, "true");
     67 
     68 sample = new DataView(ab, 0, false);
     69 assert.sameValue(sample.byteLength, 0, "false");
     70 
     71 sample = new DataView(ab, 0, NaN);
     72 assert.sameValue(sample.byteLength, 0, "NaN");
     73 
     74 sample = new DataView(ab, 0, null);
     75 assert.sameValue(sample.byteLength, 0, "null");
     76 
     77 sample = new DataView(ab, 0, 0.1);
     78 assert.sameValue(sample.byteLength, 0, "0.1");
     79 
     80 sample = new DataView(ab, 0, 0.9);
     81 assert.sameValue(sample.byteLength, 0, "0.9");
     82 
     83 sample = new DataView(ab, 0, 1.1);
     84 assert.sameValue(sample.byteLength, 1, "1.1");
     85 
     86 sample = new DataView(ab, 0, 1.9);
     87 assert.sameValue(sample.byteLength, 1, "1.9");
     88 
     89 sample = new DataView(ab, 0, -0.1);
     90 assert.sameValue(sample.byteLength, 0, "-0.1");
     91 
     92 sample = new DataView(ab, 0, -0.99999);
     93 assert.sameValue(sample.byteLength, 0, "-0.99999");
     94 
     95 reportCompare(0, 0);