|
1 | 1 | describe("Test WeakRef ", function () {
|
2 |
| - |
3 |
| - it("Test if WeakRef gets cleared after gc", function () { |
4 |
| - |
| 2 | + it("Test if WeakRef gets cleared after gc", function (done) { |
5 | 3 | __log("TEST: TestWeakRefGetsClearedAfterGC");
|
6 |
| - |
| 4 | + |
7 | 5 | var wr = new WeakRef({ someProp: 12345 });
|
8 |
| - |
| 6 | + |
9 | 7 | var val = wr.get().someProp;
|
10 | 8 | expect(val).toBe(12345);
|
11 |
| - |
12 | 9 | gc();
|
13 |
| - |
14 |
| - var val = wr.get(); |
15 |
| - expect(val).toBe(null); |
16 |
| - }); |
17 |
| - |
18 |
| - it("Test if WeakRef gets cleared after clear", function () { |
19 |
| - |
20 |
| - __log("TEST: TestWeakRefGetsClearedAfterClear"); |
21 |
| - |
22 |
| - var wr = new WeakRef({ someProp: 54321 }); |
23 |
| - |
24 |
| - var val = wr.get().someProp; |
25 |
| - expect(val).toBe(54321); |
26 |
| - |
27 |
| - wr.clear(); |
28 |
| - |
29 |
| - var val = wr.get(); |
30 |
| - expect(val).toBe(null); |
| 10 | + |
| 11 | + setTimeout(() => { |
| 12 | + gc(); |
| 13 | + var val = wr.get(); |
| 14 | + expect(val).toBe(undefined); |
| 15 | + done(); |
| 16 | + }); |
31 | 17 | });
|
32 |
| - |
33 |
| - it("Test if WeakRef can create multiple instances", function () { |
34 |
| - |
| 18 | + |
| 19 | + it("Test if WeakRef can create multiple instances", function (done) { |
35 | 20 | __log("TEST: TestWeakRefCanCreateMultipleInstances");
|
36 |
| - |
37 |
| - var target = { someProp: 54321 }; |
38 |
| - |
39 |
| - var wr1 = new WeakRef(target); |
40 |
| - var wr2 = new WeakRef(target); |
41 |
| - |
42 |
| - target = null; |
43 |
| - |
44 |
| - wr1.clear(); |
45 |
| - |
46 |
| - var val = wr1.get(); |
47 |
| - expect(val).toBe(null); |
48 |
| - |
49 |
| - val = wr2.get().someProp; |
50 |
| - expect(val).toBe(54321); |
51 |
| - }); |
52 |
| - |
53 |
| - it("Test if WeakRef can create multiple instances 2", function () { |
54 | 21 |
|
55 |
| - __log("TEST: TestWeakRefCanCreateMultipleInstances2"); |
56 |
| - |
57 | 22 | var target = { someProp: 54321 };
|
58 |
| - |
| 23 | + |
59 | 24 | var wr1 = new WeakRef(target);
|
60 | 25 | var wr2 = new WeakRef(target);
|
61 |
| - |
| 26 | + |
62 | 27 | target = null;
|
63 |
| - gc(); |
64 |
| - |
65 |
| - var val1 = wr1.get(); |
66 |
| - expect(val1).toBe(null); |
67 |
| - |
68 |
| - var val2 = wr2.get(); |
69 |
| - expect(val2).toBe(null); |
| 28 | + setTimeout(() => { |
| 29 | + gc(); |
| 30 | + |
| 31 | + var val1 = wr1.get(); |
| 32 | + expect(val1).toBe(undefined); |
| 33 | + |
| 34 | + var val2 = wr2.get(); |
| 35 | + expect(val2).toBe(undefined); |
| 36 | + done(); |
| 37 | + }); |
70 | 38 | });
|
71 |
| - |
| 39 | + |
72 | 40 | it("Test if WeakRef throws exception when constructed with wrong number of parameters", function () {
|
73 |
| - |
74 |
| - __log("TEST: TestWeakRefThrowsExceptionWhenConstructedWithWrongNumberOfParameters"); |
75 |
| - |
| 41 | + __log( |
| 42 | + "TEST: TestWeakRefThrowsExceptionWhenConstructedWithWrongNumberOfParameters" |
| 43 | + ); |
| 44 | + |
76 | 45 | var exceptionCaught = false;
|
77 |
| - try |
78 |
| - { |
| 46 | + try { |
79 | 47 | new WeakRef();
|
80 |
| - } |
81 |
| - catch (e) |
82 |
| - { |
| 48 | + } catch (e) { |
83 | 49 | exceptionCaught = true;
|
84 | 50 | }
|
85 | 51 | expect(exceptionCaught).toBe(true);
|
86 |
| - |
| 52 | + |
87 | 53 | exceptionCaught = false;
|
88 |
| - try |
89 |
| - { |
| 54 | + try { |
90 | 55 | new WeakRef(1, 2);
|
91 |
| - } |
92 |
| - catch (e) |
93 |
| - { |
| 56 | + } catch (e) { |
94 | 57 | exceptionCaught = true;
|
95 | 58 | }
|
96 | 59 | expect(exceptionCaught).toBe(true);
|
97 |
| - |
98 | 60 | });
|
99 | 61 |
|
100 | 62 | it("Test if WeakRef throws exception when constructed with non object", function () {
|
101 |
| - |
102 | 63 | __log("TEST: TestWeakRefThrowsExceptionWhenConstructedWithNonObject");
|
103 |
| - |
| 64 | + |
104 | 65 | var exceptionCaught = false;
|
105 |
| - try |
106 |
| - { |
| 66 | + try { |
107 | 67 | new WeakRef(1);
|
108 |
| - } |
109 |
| - catch (e) |
110 |
| - { |
| 68 | + } catch (e) { |
111 | 69 | exceptionCaught = true;
|
112 | 70 | }
|
113 | 71 | expect(exceptionCaught).toBe(true);
|
114 |
| - |
| 72 | + |
115 | 73 | exceptionCaught = false;
|
116 |
| - try |
117 |
| - { |
| 74 | + try { |
118 | 75 | new WeakRef(false);
|
119 |
| - } |
120 |
| - catch (e) |
121 |
| - { |
| 76 | + } catch (e) { |
122 | 77 | exceptionCaught = true;
|
123 | 78 | }
|
124 | 79 | expect(exceptionCaught).toBe(true);
|
125 | 80 |
|
126 | 81 | exceptionCaught = false;
|
127 |
| - try |
128 |
| - { |
| 82 | + try { |
129 | 83 | new WeakRef(null);
|
130 |
| - } |
131 |
| - catch (e) |
132 |
| - { |
| 84 | + } catch (e) { |
133 | 85 | exceptionCaught = true;
|
134 | 86 | }
|
135 | 87 | expect(exceptionCaught).toBe(true);
|
136 | 88 |
|
137 | 89 | exceptionCaught = false;
|
138 |
| - try |
139 |
| - { |
| 90 | + try { |
140 | 91 | new WeakRef(undefined);
|
141 |
| - } |
142 |
| - catch (e) |
143 |
| - { |
| 92 | + } catch (e) { |
144 | 93 | exceptionCaught = true;
|
145 | 94 | }
|
146 | 95 | expect(exceptionCaught).toBe(true);
|
147 | 96 | });
|
148 | 97 | });
|
149 |
| - |
0 commit comments