forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweakmap-serialize.js
More file actions
44 lines (41 loc) · 1.15 KB
/
weakmap-serialize.js
File metadata and controls
44 lines (41 loc) · 1.15 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
/**
* 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 -serialize-after-init-file=%t -target=HBC %s | %FileCheck --match-full-lines %s
// RUN: %hermes -O -deserialize-file=%t -target=HBC %s | %FileCheck --match-full-lines %s
// REQUIRES: serializer
print("WeakMap");
// CHECK-LABEL: WeakMap
print(WeakMap.prototype)
// CHECK-NEXT: [object WeakMap]
print(WeakMap.length)
// CHECK-NEXT: 0
print(new WeakMap());
// CHECK-NEXT: [object WeakMap]
var x = {}
var y = {}
var m = new WeakMap(new Set([[x,2], [y,4]]));
print(m.get(x), m.get(y));
// CHECK-NEXT: 2 4
var iterable = {};
iterable[Symbol.iterator] = function() {
return {
next: function() {
return {value: [{}, 2], done: false};
},
return: function() {
print('returning');
},
};
};
var oldSet = WeakMap.prototype.set;
WeakMap.prototype.set = function() {
throw new Error('add error');
}
try { new WeakMap(iterable); } catch (e) { print('caught', e.message); }
// CHECK: returning
// CHECK: caught add error
WeakMap.prototype.set = oldSet;