summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/SharedArrayBuffer/toindex-length.js
blob: 6b861c78c4dd6256431aee97ff3a0ca946cf2727 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// Copyright (C) 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-sharedarraybuffer-length
description: >
  The `length` parameter is converted to a value numeric index value.
info: |
  SharedArrayBuffer( length )

  1. If NewTarget is undefined, throw a TypeError exception.
  2. Let byteLength be ? ToIndex(length).
  3. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength).

  ToIndex( value )

  1. If value is undefined, then
    a. Let index be 0.
  2. Else,
    a. Let integerIndex be ? ToInteger(value).
    b. If integerIndex < 0, throw a RangeError exception.
    c. Let index be ! ToLength(integerIndex).
    d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception.
  3. Return index.
features: [SharedArrayBuffer]
---*/

var obj1 = {
  valueOf: function() {
    return 42;
  }
};

var obj2 = {
  toString: function() {
    return 42;
  }
};

var buffer;

buffer = new SharedArrayBuffer(obj1);
assert.sameValue(buffer.byteLength, 42, "object's valueOf");

buffer = new SharedArrayBuffer(obj2);
assert.sameValue(buffer.byteLength, 42, "object's toString");

buffer = new SharedArrayBuffer("");
assert.sameValue(buffer.byteLength, 0, "the Empty string");

buffer = new SharedArrayBuffer("0");
assert.sameValue(buffer.byteLength, 0, "string '0'");

buffer = new SharedArrayBuffer("1");
assert.sameValue(buffer.byteLength, 1, "string '1'");

buffer = new SharedArrayBuffer(true);
assert.sameValue(buffer.byteLength, 1, "true");

buffer = new SharedArrayBuffer(false);
assert.sameValue(buffer.byteLength, 0, "false");

buffer = new SharedArrayBuffer(NaN);
assert.sameValue(buffer.byteLength, 0, "NaN");

buffer = new SharedArrayBuffer(null);
assert.sameValue(buffer.byteLength, 0, "null");

buffer = new SharedArrayBuffer(undefined);
assert.sameValue(buffer.byteLength, 0, "undefined");

buffer = new SharedArrayBuffer(0.1);
assert.sameValue(buffer.byteLength, 0, "0.1");

buffer = new SharedArrayBuffer(0.9);
assert.sameValue(buffer.byteLength, 0, "0.9");

buffer = new SharedArrayBuffer(1.1);
assert.sameValue(buffer.byteLength, 1, "1.1");

buffer = new SharedArrayBuffer(1.9);
assert.sameValue(buffer.byteLength, 1, "1.9");

buffer = new SharedArrayBuffer(-0.1);
assert.sameValue(buffer.byteLength, 0, "-0.1");

buffer = new SharedArrayBuffer(-0.99999);
assert.sameValue(buffer.byteLength, 0, "-0.99999");

reportCompare(0, 0);