Revision 00fcdc8ddaa1c1d9bf75d26be79e84f669314ee5 authored by Domenic Denicola on 20 October 2016, 18:20:23 UTC, committed by Domenic Denicola on 20 October 2016, 18:20:23 UTC
1 parent b093db8
Raw File
ArrayBuffer_properties.html
<!DOCTYPE html>
<meta charset="utf-8">
<title>Typed Arrays Test: ArrayBuffer properties</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://www.khronos.org/registry/typedarray/specs/latest/#5">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>

test(function () {
  var intLen = 8;
  var abuffer = new ArrayBuffer(intLen);

  //byteLength
  test(function () {
    var len = abuffer.byteLength;
    abuffer.byteLength = len + 1;
    assert_equals(len, intLen, "the byteLength of ArrayBuffer");
    assert_equals(abuffer.byteLength, len, "the byteLength of ArrayBuffer");
  }, "Check if the byteLength is fixed at construction time and readonly");

  //slice()
  test(function () {
    var b = abuffer.slice(2);
    assert_true(b instanceof ArrayBuffer, "Returns a new ArrayBuffer");
    assert_equals(b.byteLength, intLen-2, "The byteLength of ArrayBuffer");
  }, "Check if the new ArrayBuffer contains all bytes from begin to the end of this ArrayBuffer when the end is unspecified");

  test(function () {
    var b = abuffer.slice(2, 6);
    assert_true(b instanceof ArrayBuffer, "Returns a new ArrayBuffer");
    assert_equals(b.byteLength, 4, "The byteLength of ArrayBuffer");
  }, "Check if the new ArrayBuffer contains the bytes from begin to the end of this ArrayBuffer when the end is specified");

  test(function () {
    b = abuffer.slice(2, 10);
    assert_equals(b.byteLength, 6, "The byteLength of ArrayBuffer");
  }, "Check if the slice range specified by the begin and end values is clamped to the valid index range for the current array");

  test(function () {
    var b = abuffer.slice(2, -1);
    assert_equals(b.byteLength, 5, "The byteLength of ArrayBuffer");
    b = abuffer.slice(-2, -1);
    assert_equals(b.byteLength, 1, "The byteLength of ArrayBuffer");
  }, "Check if it refers to an index from the end of the array when either begin or end is negative");

  test(function () {
    var b = abuffer.slice(4, 2);
    assert_equals(b.byteLength, 0, "The byteLength of ArrayBuffer");
    b = abuffer.slice(-1, -2);
    assert_equals(b.byteLength, 0, "The byteLength of ArrayBuffer");
  }, "Check if the length is clamped to zero when the computed length of the new ArrayBuffer is negative");

  //static isView()
  test(function () {
    var int8a = new Int8Array(8);
    assert_true(ArrayBuffer.isView(int8a), "The return value of ArrayBufferView.isView");
  }, "Check if the isView returns true when the value is an object implementing the ArrayBufferView interface");

  test(function () {
    var arr = new Array(8);
    assert_false(ArrayBuffer.isView(arr), "The return value of ArrayBufferView.isView");
  }, "Check if the isView returns false when the value is an object not implementing the ArrayBufferView interface");
});

</script>
back to top