summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_7/TypedObject/size_and_alignment.js
blob: c01dc95729a72ebf49d8af08f4f487ff1a667870 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 578700;
var summary = 'Size and Alignment of TypedObjects types';
var actual = '';
var expect = '';


var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;


function runTests() {
  printBugNumber(BUGNUMBER);
  printStatus(summary);

  var typesAndAlignments = [
    {type: uint8, size: 1, alignment: 1},
    {type: uint8Clamped, size: 1, alignment: 1},
    {type: uint16, size: 2, alignment: 2},
    {type: uint32, size: 4, alignment: 4},

    {type: int8, size: 1, alignment: 1},
    {type: int16, size: 2, alignment: 2},
    {type: int32, size: 4, alignment: 4},

    {type: float32, size: 4, alignment: 4},
    {type: float64, size: 8, alignment: 8},

    {type: new StructType({a: uint8, b: uint16, c: uint8}), size: 6, alignment: 2},

    {type: new StructType({a: uint8, b: uint8, c: uint16}), size: 4, alignment: 2},

    {type: new ArrayType(uint8, 32), size: 32, alignment: 1},
    {type: new ArrayType(uint16, 16), size: 32, alignment: 2},
    {type: new ArrayType(uint32, 8), size: 32, alignment: 4},
  ];

  for (var i = 0; i < typesAndAlignments.length; i++) {
    var test = typesAndAlignments[i];
    print("Type:", test.type.toSource(),
          "Size:", test.type.byteLength,
          "Alignment:", test.type.byteAlignment);
    assertEq(test.type.byteLength, test.size);
    assertEq(test.type.byteAlignment, test.alignment);
  }

  if (typeof reportCompare === "function")
    reportCompare(true, true);
  print("Tests complete");
}

runTests();