forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraybuffer-usercode.js
More file actions
59 lines (48 loc) · 1.36 KB
/
arraybuffer-usercode.js
File metadata and controls
59 lines (48 loc) · 1.36 KB
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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -O -target=HBC -serializevm-path=%t %s
// RUN: %hermes -O -deserialize-file=%t -target=HBC %s | %FileCheck --match-full-lines %s
// REQUIRES: serializer
/// @name Normal cases
/// @{
var buffer = new ArrayBuffer(4);
// Used for checking the contents of the buffer
var check = new Int8Array(buffer);
// Write some values into it
for (var i = 0; i < check.length; i++) {
check[i] = i;
}
serializeVM(function () {
print(buffer);
// CHECK: [object ArrayBuffer]
print(buffer.byteLength);
// CHECK-NEXT: 4
for (var i = 0; i < check.length; i++) {
print(check[i]);
}
// CHECK-NEXT:0
// CHECK-NEXT:1
// CHECK-NEXT:2
// CHECK-NEXT:3
// See if we can still add to it.
for (var i = 0; i < check.length; i++) {
check[i] += 1;
}
for (var i = 0; i < check.length; i++) {
print(check[i]);
}
// CHECK-NEXT:1
// CHECK-NEXT:2
// CHECK-NEXT:3
// CHECK-NEXT:4
try { ArrayBuffer.prototype.byteLength; } catch (e) { print('caught', e.name); }
// CHECK-NEXT: caught TypeError
var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength');
print(desc.enumerable, desc.configurable);
// CHECK-NEXT: false true
/// @}
})