OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 if (expected.IsBool()) { | 44 if (expected.IsBool()) { |
45 if (actual.IsBool()) { | 45 if (actual.IsBool()) { |
46 return expected.raw() == actual.raw(); | 46 return expected.raw() == actual.raw(); |
47 } | 47 } |
48 return false; | 48 return false; |
49 } | 49 } |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 | |
54 static uint8_t* malloc_allocator(uint8_t* ptr, | 53 static uint8_t* malloc_allocator(uint8_t* ptr, |
55 intptr_t old_size, | 54 intptr_t old_size, |
56 intptr_t new_size) { | 55 intptr_t new_size) { |
57 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); | 56 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); |
58 } | 57 } |
59 | 58 |
60 | |
61 static void malloc_deallocator(uint8_t* ptr) { | 59 static void malloc_deallocator(uint8_t* ptr) { |
62 free(ptr); | 60 free(ptr); |
63 } | 61 } |
64 | 62 |
65 | |
66 static uint8_t* zone_allocator(uint8_t* ptr, | 63 static uint8_t* zone_allocator(uint8_t* ptr, |
67 intptr_t old_size, | 64 intptr_t old_size, |
68 intptr_t new_size) { | 65 intptr_t new_size) { |
69 Zone* zone = Thread::Current()->zone(); | 66 Zone* zone = Thread::Current()->zone(); |
70 return zone->Realloc<uint8_t>(ptr, old_size, new_size); | 67 return zone->Realloc<uint8_t>(ptr, old_size, new_size); |
71 } | 68 } |
72 | 69 |
73 | |
74 static void zone_deallocator(uint8_t* ptr) {} | 70 static void zone_deallocator(uint8_t* ptr) {} |
75 | 71 |
76 | |
77 // Compare two Dart_CObject object graphs rooted in first and | 72 // Compare two Dart_CObject object graphs rooted in first and |
78 // second. The second graph will be destroyed by this operation no matter | 73 // second. The second graph will be destroyed by this operation no matter |
79 // whether the graphs are equal or not. | 74 // whether the graphs are equal or not. |
80 static void CompareDartCObjects(Dart_CObject* first, Dart_CObject* second) { | 75 static void CompareDartCObjects(Dart_CObject* first, Dart_CObject* second) { |
81 // Return immediately if entering a cycle. | 76 // Return immediately if entering a cycle. |
82 if (second->type == Dart_CObject_kNumberOfTypes) return; | 77 if (second->type == Dart_CObject_kNumberOfTypes) return; |
83 | 78 |
84 EXPECT_NE(first, second); | 79 EXPECT_NE(first, second); |
85 EXPECT_EQ(first->type, second->type); | 80 EXPECT_EQ(first->type, second->type); |
86 switch (first->type) { | 81 switch (first->type) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 124 } |
130 break; | 125 break; |
131 case Dart_CObject_kCapability: | 126 case Dart_CObject_kCapability: |
132 EXPECT_EQ(first->value.as_capability.id, second->value.as_capability.id); | 127 EXPECT_EQ(first->value.as_capability.id, second->value.as_capability.id); |
133 break; | 128 break; |
134 default: | 129 default: |
135 EXPECT(false); | 130 EXPECT(false); |
136 } | 131 } |
137 } | 132 } |
138 | 133 |
139 | |
140 static void CheckEncodeDecodeMessage(Dart_CObject* root) { | 134 static void CheckEncodeDecodeMessage(Dart_CObject* root) { |
141 // Encode and decode the message. | 135 // Encode and decode the message. |
142 uint8_t* buffer = NULL; | 136 uint8_t* buffer = NULL; |
143 ApiMessageWriter writer(&buffer, &malloc_allocator); | 137 ApiMessageWriter writer(&buffer, &malloc_allocator); |
144 writer.WriteCMessage(root); | 138 writer.WriteCMessage(root); |
145 | 139 |
146 ApiMessageReader api_reader(buffer, writer.BytesWritten()); | 140 ApiMessageReader api_reader(buffer, writer.BytesWritten()); |
147 Dart_CObject* new_root = api_reader.ReadMessage(); | 141 Dart_CObject* new_root = api_reader.ReadMessage(); |
148 | 142 |
149 // Check that the two messages are the same. | 143 // Check that the two messages are the same. |
150 CompareDartCObjects(root, new_root); | 144 CompareDartCObjects(root, new_root); |
151 | 145 |
152 free(buffer); | 146 free(buffer); |
153 } | 147 } |
154 | 148 |
155 | |
156 static void ExpectEncodeFail(Dart_CObject* root) { | 149 static void ExpectEncodeFail(Dart_CObject* root) { |
157 uint8_t* buffer = NULL; | 150 uint8_t* buffer = NULL; |
158 ApiMessageWriter writer(&buffer, &malloc_allocator); | 151 ApiMessageWriter writer(&buffer, &malloc_allocator); |
159 const bool result = writer.WriteCMessage(root); | 152 const bool result = writer.WriteCMessage(root); |
160 EXPECT_EQ(false, result); | 153 EXPECT_EQ(false, result); |
161 free(buffer); | 154 free(buffer); |
162 } | 155 } |
163 | 156 |
164 | |
165 TEST_CASE(SerializeNull) { | 157 TEST_CASE(SerializeNull) { |
166 StackZone zone(thread); | 158 StackZone zone(thread); |
167 | 159 |
168 // Write snapshot with object content. | 160 // Write snapshot with object content. |
169 const Object& null_object = Object::Handle(); | 161 const Object& null_object = Object::Handle(); |
170 uint8_t* buffer; | 162 uint8_t* buffer; |
171 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 163 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
172 writer.WriteMessage(null_object); | 164 writer.WriteMessage(null_object); |
173 intptr_t buffer_len = writer.BytesWritten(); | 165 intptr_t buffer_len = writer.BytesWritten(); |
174 | 166 |
175 // Read object back from the snapshot. | 167 // Read object back from the snapshot. |
176 MessageSnapshotReader reader(buffer, buffer_len, thread); | 168 MessageSnapshotReader reader(buffer, buffer_len, thread); |
177 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 169 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
178 EXPECT(Equals(null_object, serialized_object)); | 170 EXPECT(Equals(null_object, serialized_object)); |
179 | 171 |
180 // Read object back from the snapshot into a C structure. | 172 // Read object back from the snapshot into a C structure. |
181 ApiNativeScope scope; | 173 ApiNativeScope scope; |
182 ApiMessageReader api_reader(buffer, buffer_len); | 174 ApiMessageReader api_reader(buffer, buffer_len); |
183 Dart_CObject* root = api_reader.ReadMessage(); | 175 Dart_CObject* root = api_reader.ReadMessage(); |
184 EXPECT_NOTNULL(root); | 176 EXPECT_NOTNULL(root); |
185 EXPECT_EQ(Dart_CObject_kNull, root->type); | 177 EXPECT_EQ(Dart_CObject_kNull, root->type); |
186 CheckEncodeDecodeMessage(root); | 178 CheckEncodeDecodeMessage(root); |
187 } | 179 } |
188 | 180 |
189 | |
190 TEST_CASE(SerializeSmi1) { | 181 TEST_CASE(SerializeSmi1) { |
191 StackZone zone(thread); | 182 StackZone zone(thread); |
192 | 183 |
193 // Write snapshot with object content. | 184 // Write snapshot with object content. |
194 const Smi& smi = Smi::Handle(Smi::New(124)); | 185 const Smi& smi = Smi::Handle(Smi::New(124)); |
195 uint8_t* buffer; | 186 uint8_t* buffer; |
196 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 187 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
197 writer.WriteMessage(smi); | 188 writer.WriteMessage(smi); |
198 intptr_t buffer_len = writer.BytesWritten(); | 189 intptr_t buffer_len = writer.BytesWritten(); |
199 | 190 |
200 // Read object back from the snapshot. | 191 // Read object back from the snapshot. |
201 MessageSnapshotReader reader(buffer, buffer_len, thread); | 192 MessageSnapshotReader reader(buffer, buffer_len, thread); |
202 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 193 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
203 EXPECT(Equals(smi, serialized_object)); | 194 EXPECT(Equals(smi, serialized_object)); |
204 | 195 |
205 // Read object back from the snapshot into a C structure. | 196 // Read object back from the snapshot into a C structure. |
206 ApiNativeScope scope; | 197 ApiNativeScope scope; |
207 ApiMessageReader api_reader(buffer, buffer_len); | 198 ApiMessageReader api_reader(buffer, buffer_len); |
208 Dart_CObject* root = api_reader.ReadMessage(); | 199 Dart_CObject* root = api_reader.ReadMessage(); |
209 EXPECT_NOTNULL(root); | 200 EXPECT_NOTNULL(root); |
210 EXPECT_EQ(Dart_CObject_kInt32, root->type); | 201 EXPECT_EQ(Dart_CObject_kInt32, root->type); |
211 EXPECT_EQ(smi.Value(), root->value.as_int32); | 202 EXPECT_EQ(smi.Value(), root->value.as_int32); |
212 CheckEncodeDecodeMessage(root); | 203 CheckEncodeDecodeMessage(root); |
213 } | 204 } |
214 | 205 |
215 | |
216 TEST_CASE(SerializeSmi2) { | 206 TEST_CASE(SerializeSmi2) { |
217 StackZone zone(thread); | 207 StackZone zone(thread); |
218 | 208 |
219 // Write snapshot with object content. | 209 // Write snapshot with object content. |
220 const Smi& smi = Smi::Handle(Smi::New(-1)); | 210 const Smi& smi = Smi::Handle(Smi::New(-1)); |
221 uint8_t* buffer; | 211 uint8_t* buffer; |
222 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 212 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
223 writer.WriteMessage(smi); | 213 writer.WriteMessage(smi); |
224 intptr_t buffer_len = writer.BytesWritten(); | 214 intptr_t buffer_len = writer.BytesWritten(); |
225 | 215 |
226 // Read object back from the snapshot. | 216 // Read object back from the snapshot. |
227 MessageSnapshotReader reader(buffer, buffer_len, thread); | 217 MessageSnapshotReader reader(buffer, buffer_len, thread); |
228 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 218 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
229 EXPECT(Equals(smi, serialized_object)); | 219 EXPECT(Equals(smi, serialized_object)); |
230 | 220 |
231 // Read object back from the snapshot into a C structure. | 221 // Read object back from the snapshot into a C structure. |
232 ApiNativeScope scope; | 222 ApiNativeScope scope; |
233 ApiMessageReader api_reader(buffer, buffer_len); | 223 ApiMessageReader api_reader(buffer, buffer_len); |
234 Dart_CObject* root = api_reader.ReadMessage(); | 224 Dart_CObject* root = api_reader.ReadMessage(); |
235 EXPECT_NOTNULL(root); | 225 EXPECT_NOTNULL(root); |
236 EXPECT_EQ(Dart_CObject_kInt32, root->type); | 226 EXPECT_EQ(Dart_CObject_kInt32, root->type); |
237 EXPECT_EQ(smi.Value(), root->value.as_int32); | 227 EXPECT_EQ(smi.Value(), root->value.as_int32); |
238 CheckEncodeDecodeMessage(root); | 228 CheckEncodeDecodeMessage(root); |
239 } | 229 } |
240 | 230 |
241 | |
242 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { | 231 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { |
243 // Write snapshot with object content. | 232 // Write snapshot with object content. |
244 uint8_t* buffer; | 233 uint8_t* buffer; |
245 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 234 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
246 writer.WriteMessage(mint); | 235 writer.WriteMessage(mint); |
247 intptr_t buffer_len = writer.BytesWritten(); | 236 intptr_t buffer_len = writer.BytesWritten(); |
248 | 237 |
249 { | 238 { |
250 // Switch to a regular zone, where VM handle allocation is allowed. | 239 // Switch to a regular zone, where VM handle allocation is allowed. |
251 Thread* thread = Thread::Current(); | 240 Thread* thread = Thread::Current(); |
252 StackZone zone(thread); | 241 StackZone zone(thread); |
253 // Read object back from the snapshot. | 242 // Read object back from the snapshot. |
254 MessageSnapshotReader reader(buffer, buffer_len, thread); | 243 MessageSnapshotReader reader(buffer, buffer_len, thread); |
255 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 244 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
256 EXPECT(serialized_object.IsMint()); | 245 EXPECT(serialized_object.IsMint()); |
257 } | 246 } |
258 | 247 |
259 // Read object back from the snapshot into a C structure. | 248 // Read object back from the snapshot into a C structure. |
260 ApiMessageReader api_reader(buffer, buffer_len); | 249 ApiMessageReader api_reader(buffer, buffer_len); |
261 Dart_CObject* root = api_reader.ReadMessage(); | 250 Dart_CObject* root = api_reader.ReadMessage(); |
262 EXPECT_NOTNULL(root); | 251 EXPECT_NOTNULL(root); |
263 CheckEncodeDecodeMessage(root); | 252 CheckEncodeDecodeMessage(root); |
264 return root; | 253 return root; |
265 } | 254 } |
266 | 255 |
267 | |
268 void CheckMint(int64_t value) { | 256 void CheckMint(int64_t value) { |
269 ApiNativeScope scope; | 257 ApiNativeScope scope; |
270 StackZone zone(Thread::Current()); | 258 StackZone zone(Thread::Current()); |
271 | 259 |
272 Mint& mint = Mint::Handle(); | 260 Mint& mint = Mint::Handle(); |
273 mint ^= Integer::New(value); | 261 mint ^= Integer::New(value); |
274 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint); | 262 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint); |
275 // On 64-bit platforms mints always require 64-bits as the smi range | 263 // On 64-bit platforms mints always require 64-bits as the smi range |
276 // here covers most of the 64-bit range. On 32-bit platforms the smi | 264 // here covers most of the 64-bit range. On 32-bit platforms the smi |
277 // range covers most of the 32-bit range and values outside that | 265 // range covers most of the 32-bit range and values outside that |
278 // range are also represented as mints. | 266 // range are also represented as mints. |
279 #if defined(ARCH_IS_64_BIT) | 267 #if defined(ARCH_IS_64_BIT) |
280 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); | 268 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); |
281 EXPECT_EQ(value, mint_cobject->value.as_int64); | 269 EXPECT_EQ(value, mint_cobject->value.as_int64); |
282 #else | 270 #else |
283 if (kMinInt32 < value && value < kMaxInt32) { | 271 if (kMinInt32 < value && value < kMaxInt32) { |
284 EXPECT_EQ(Dart_CObject_kInt32, mint_cobject->type); | 272 EXPECT_EQ(Dart_CObject_kInt32, mint_cobject->type); |
285 EXPECT_EQ(value, mint_cobject->value.as_int32); | 273 EXPECT_EQ(value, mint_cobject->value.as_int32); |
286 } else { | 274 } else { |
287 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); | 275 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); |
288 EXPECT_EQ(value, mint_cobject->value.as_int64); | 276 EXPECT_EQ(value, mint_cobject->value.as_int64); |
289 } | 277 } |
290 #endif | 278 #endif |
291 } | 279 } |
292 | 280 |
293 | |
294 TEST_CASE(SerializeMints) { | 281 TEST_CASE(SerializeMints) { |
295 // Min positive mint. | 282 // Min positive mint. |
296 CheckMint(Smi::kMaxValue + 1); | 283 CheckMint(Smi::kMaxValue + 1); |
297 // Min positive mint + 1. | 284 // Min positive mint + 1. |
298 CheckMint(Smi::kMaxValue + 2); | 285 CheckMint(Smi::kMaxValue + 2); |
299 // Max negative mint. | 286 // Max negative mint. |
300 CheckMint(Smi::kMinValue - 1); | 287 CheckMint(Smi::kMinValue - 1); |
301 // Max negative mint - 1. | 288 // Max negative mint - 1. |
302 CheckMint(Smi::kMinValue - 2); | 289 CheckMint(Smi::kMinValue - 2); |
303 // Max positive mint. | 290 // Max positive mint. |
304 CheckMint(kMaxInt64); | 291 CheckMint(kMaxInt64); |
305 // Max positive mint - 1. | 292 // Max positive mint - 1. |
306 CheckMint(kMaxInt64 - 1); | 293 CheckMint(kMaxInt64 - 1); |
307 // Min negative mint. | 294 // Min negative mint. |
308 CheckMint(kMinInt64); | 295 CheckMint(kMinInt64); |
309 // Min negative mint + 1. | 296 // Min negative mint + 1. |
310 CheckMint(kMinInt64 + 1); | 297 CheckMint(kMinInt64 + 1); |
311 } | 298 } |
312 | 299 |
313 | |
314 TEST_CASE(SerializeDouble) { | 300 TEST_CASE(SerializeDouble) { |
315 StackZone zone(thread); | 301 StackZone zone(thread); |
316 | 302 |
317 // Write snapshot with object content. | 303 // Write snapshot with object content. |
318 const Double& dbl = Double::Handle(Double::New(101.29)); | 304 const Double& dbl = Double::Handle(Double::New(101.29)); |
319 uint8_t* buffer; | 305 uint8_t* buffer; |
320 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 306 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
321 writer.WriteMessage(dbl); | 307 writer.WriteMessage(dbl); |
322 intptr_t buffer_len = writer.BytesWritten(); | 308 intptr_t buffer_len = writer.BytesWritten(); |
323 | 309 |
324 // Read object back from the snapshot. | 310 // Read object back from the snapshot. |
325 MessageSnapshotReader reader(buffer, buffer_len, thread); | 311 MessageSnapshotReader reader(buffer, buffer_len, thread); |
326 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 312 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
327 EXPECT(Equals(dbl, serialized_object)); | 313 EXPECT(Equals(dbl, serialized_object)); |
328 | 314 |
329 // Read object back from the snapshot into a C structure. | 315 // Read object back from the snapshot into a C structure. |
330 ApiNativeScope scope; | 316 ApiNativeScope scope; |
331 ApiMessageReader api_reader(buffer, buffer_len); | 317 ApiMessageReader api_reader(buffer, buffer_len); |
332 Dart_CObject* root = api_reader.ReadMessage(); | 318 Dart_CObject* root = api_reader.ReadMessage(); |
333 EXPECT_NOTNULL(root); | 319 EXPECT_NOTNULL(root); |
334 EXPECT_EQ(Dart_CObject_kDouble, root->type); | 320 EXPECT_EQ(Dart_CObject_kDouble, root->type); |
335 EXPECT_EQ(dbl.value(), root->value.as_double); | 321 EXPECT_EQ(dbl.value(), root->value.as_double); |
336 CheckEncodeDecodeMessage(root); | 322 CheckEncodeDecodeMessage(root); |
337 } | 323 } |
338 | 324 |
339 | |
340 TEST_CASE(SerializeTrue) { | 325 TEST_CASE(SerializeTrue) { |
341 StackZone zone(thread); | 326 StackZone zone(thread); |
342 | 327 |
343 // Write snapshot with true object. | 328 // Write snapshot with true object. |
344 const Bool& bl = Bool::True(); | 329 const Bool& bl = Bool::True(); |
345 uint8_t* buffer; | 330 uint8_t* buffer; |
346 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 331 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
347 writer.WriteMessage(bl); | 332 writer.WriteMessage(bl); |
348 intptr_t buffer_len = writer.BytesWritten(); | 333 intptr_t buffer_len = writer.BytesWritten(); |
349 | 334 |
350 // Read object back from the snapshot. | 335 // Read object back from the snapshot. |
351 MessageSnapshotReader reader(buffer, buffer_len, thread); | 336 MessageSnapshotReader reader(buffer, buffer_len, thread); |
352 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 337 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
353 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); | 338 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); |
354 | 339 |
355 EXPECT(Equals(bl, serialized_object)); | 340 EXPECT(Equals(bl, serialized_object)); |
356 | 341 |
357 // Read object back from the snapshot into a C structure. | 342 // Read object back from the snapshot into a C structure. |
358 ApiNativeScope scope; | 343 ApiNativeScope scope; |
359 ApiMessageReader api_reader(buffer, buffer_len); | 344 ApiMessageReader api_reader(buffer, buffer_len); |
360 Dart_CObject* root = api_reader.ReadMessage(); | 345 Dart_CObject* root = api_reader.ReadMessage(); |
361 EXPECT_NOTNULL(root); | 346 EXPECT_NOTNULL(root); |
362 EXPECT_EQ(Dart_CObject_kBool, root->type); | 347 EXPECT_EQ(Dart_CObject_kBool, root->type); |
363 EXPECT_EQ(true, root->value.as_bool); | 348 EXPECT_EQ(true, root->value.as_bool); |
364 CheckEncodeDecodeMessage(root); | 349 CheckEncodeDecodeMessage(root); |
365 } | 350 } |
366 | 351 |
367 | |
368 TEST_CASE(SerializeFalse) { | 352 TEST_CASE(SerializeFalse) { |
369 StackZone zone(thread); | 353 StackZone zone(thread); |
370 | 354 |
371 // Write snapshot with false object. | 355 // Write snapshot with false object. |
372 const Bool& bl = Bool::False(); | 356 const Bool& bl = Bool::False(); |
373 uint8_t* buffer; | 357 uint8_t* buffer; |
374 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 358 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
375 writer.WriteMessage(bl); | 359 writer.WriteMessage(bl); |
376 intptr_t buffer_len = writer.BytesWritten(); | 360 intptr_t buffer_len = writer.BytesWritten(); |
377 | 361 |
378 // Read object back from the snapshot. | 362 // Read object back from the snapshot. |
379 MessageSnapshotReader reader(buffer, buffer_len, thread); | 363 MessageSnapshotReader reader(buffer, buffer_len, thread); |
380 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 364 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
381 EXPECT(Equals(bl, serialized_object)); | 365 EXPECT(Equals(bl, serialized_object)); |
382 | 366 |
383 // Read object back from the snapshot into a C structure. | 367 // Read object back from the snapshot into a C structure. |
384 ApiNativeScope scope; | 368 ApiNativeScope scope; |
385 ApiMessageReader api_reader(buffer, buffer_len); | 369 ApiMessageReader api_reader(buffer, buffer_len); |
386 Dart_CObject* root = api_reader.ReadMessage(); | 370 Dart_CObject* root = api_reader.ReadMessage(); |
387 EXPECT_NOTNULL(root); | 371 EXPECT_NOTNULL(root); |
388 EXPECT_EQ(Dart_CObject_kBool, root->type); | 372 EXPECT_EQ(Dart_CObject_kBool, root->type); |
389 EXPECT_EQ(false, root->value.as_bool); | 373 EXPECT_EQ(false, root->value.as_bool); |
390 CheckEncodeDecodeMessage(root); | 374 CheckEncodeDecodeMessage(root); |
391 } | 375 } |
392 | 376 |
393 | |
394 TEST_CASE(SerializeCapability) { | 377 TEST_CASE(SerializeCapability) { |
395 // Write snapshot with object content. | 378 // Write snapshot with object content. |
396 const Capability& capability = Capability::Handle(Capability::New(12345)); | 379 const Capability& capability = Capability::Handle(Capability::New(12345)); |
397 uint8_t* buffer; | 380 uint8_t* buffer; |
398 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 381 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
399 writer.WriteMessage(capability); | 382 writer.WriteMessage(capability); |
400 intptr_t buffer_len = writer.BytesWritten(); | 383 intptr_t buffer_len = writer.BytesWritten(); |
401 | 384 |
402 // Read object back from the snapshot. | 385 // Read object back from the snapshot. |
403 MessageSnapshotReader reader(buffer, buffer_len, thread); | 386 MessageSnapshotReader reader(buffer, buffer_len, thread); |
404 Capability& obj = Capability::Handle(); | 387 Capability& obj = Capability::Handle(); |
405 obj ^= reader.ReadObject(); | 388 obj ^= reader.ReadObject(); |
406 | 389 |
407 EXPECT_STREQ(12345, obj.Id()); | 390 EXPECT_STREQ(12345, obj.Id()); |
408 | 391 |
409 // Read object back from the snapshot into a C structure. | 392 // Read object back from the snapshot into a C structure. |
410 ApiNativeScope scope; | 393 ApiNativeScope scope; |
411 ApiMessageReader api_reader(buffer, buffer_len); | 394 ApiMessageReader api_reader(buffer, buffer_len); |
412 Dart_CObject* root = api_reader.ReadMessage(); | 395 Dart_CObject* root = api_reader.ReadMessage(); |
413 EXPECT_NOTNULL(root); | 396 EXPECT_NOTNULL(root); |
414 EXPECT_EQ(Dart_CObject_kCapability, root->type); | 397 EXPECT_EQ(Dart_CObject_kCapability, root->type); |
415 int64_t id = root->value.as_capability.id; | 398 int64_t id = root->value.as_capability.id; |
416 EXPECT_EQ(12345, id); | 399 EXPECT_EQ(12345, id); |
417 CheckEncodeDecodeMessage(root); | 400 CheckEncodeDecodeMessage(root); |
418 } | 401 } |
419 | 402 |
420 | |
421 TEST_CASE(SerializeBigint) { | 403 TEST_CASE(SerializeBigint) { |
422 // Write snapshot with object content. | 404 // Write snapshot with object content. |
423 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; | 405 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; |
424 const String& str = String::Handle(String::New(cstr)); | 406 const String& str = String::Handle(String::New(cstr)); |
425 Bigint& bigint = Bigint::Handle(); | 407 Bigint& bigint = Bigint::Handle(); |
426 bigint ^= Integer::NewCanonical(str); | 408 bigint ^= Integer::NewCanonical(str); |
427 uint8_t* buffer; | 409 uint8_t* buffer; |
428 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 410 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
429 writer.WriteMessage(bigint); | 411 writer.WriteMessage(bigint); |
430 intptr_t buffer_len = writer.BytesWritten(); | 412 intptr_t buffer_len = writer.BytesWritten(); |
(...skipping 11 matching lines...) Expand all Loading... |
442 ApiMessageReader api_reader(buffer, buffer_len); | 424 ApiMessageReader api_reader(buffer, buffer_len); |
443 Dart_CObject* root = api_reader.ReadMessage(); | 425 Dart_CObject* root = api_reader.ReadMessage(); |
444 EXPECT_NOTNULL(root); | 426 EXPECT_NOTNULL(root); |
445 EXPECT_EQ(Dart_CObject_kBigint, root->type); | 427 EXPECT_EQ(Dart_CObject_kBigint, root->type); |
446 char* hex_value = TestCase::BigintToHexValue(root); | 428 char* hex_value = TestCase::BigintToHexValue(root); |
447 EXPECT_STREQ(cstr, hex_value); | 429 EXPECT_STREQ(cstr, hex_value); |
448 free(hex_value); | 430 free(hex_value); |
449 CheckEncodeDecodeMessage(root); | 431 CheckEncodeDecodeMessage(root); |
450 } | 432 } |
451 | 433 |
452 | |
453 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { | 434 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
454 // Write snapshot with object content. | 435 // Write snapshot with object content. |
455 uint8_t* buffer; | 436 uint8_t* buffer; |
456 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 437 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
457 writer.WriteMessage(bigint); | 438 writer.WriteMessage(bigint); |
458 intptr_t buffer_len = writer.BytesWritten(); | 439 intptr_t buffer_len = writer.BytesWritten(); |
459 | 440 |
460 { | 441 { |
461 // Switch to a regular zone, where VM handle allocation is allowed. | 442 // Switch to a regular zone, where VM handle allocation is allowed. |
462 Thread* thread = Thread::Current(); | 443 Thread* thread = Thread::Current(); |
463 StackZone zone(thread); | 444 StackZone zone(thread); |
464 // Read object back from the snapshot. | 445 // Read object back from the snapshot. |
465 MessageSnapshotReader reader(buffer, buffer_len, thread); | 446 MessageSnapshotReader reader(buffer, buffer_len, thread); |
466 Bigint& serialized_bigint = Bigint::Handle(); | 447 Bigint& serialized_bigint = Bigint::Handle(); |
467 serialized_bigint ^= reader.ReadObject(); | 448 serialized_bigint ^= reader.ReadObject(); |
468 const char* str1 = bigint.ToHexCString(thread->zone()); | 449 const char* str1 = bigint.ToHexCString(thread->zone()); |
469 const char* str2 = serialized_bigint.ToHexCString(thread->zone()); | 450 const char* str2 = serialized_bigint.ToHexCString(thread->zone()); |
470 EXPECT_STREQ(str1, str2); | 451 EXPECT_STREQ(str1, str2); |
471 } | 452 } |
472 | 453 |
473 // Read object back from the snapshot into a C structure. | 454 // Read object back from the snapshot into a C structure. |
474 ApiMessageReader api_reader(buffer, buffer_len); | 455 ApiMessageReader api_reader(buffer, buffer_len); |
475 Dart_CObject* root = api_reader.ReadMessage(); | 456 Dart_CObject* root = api_reader.ReadMessage(); |
476 // Bigint not supported. | 457 // Bigint not supported. |
477 EXPECT_NOTNULL(root); | 458 EXPECT_NOTNULL(root); |
478 CheckEncodeDecodeMessage(root); | 459 CheckEncodeDecodeMessage(root); |
479 return root; | 460 return root; |
480 } | 461 } |
481 | 462 |
482 | |
483 void CheckBigint(const char* bigint_value) { | 463 void CheckBigint(const char* bigint_value) { |
484 ApiNativeScope scope; | 464 ApiNativeScope scope; |
485 StackZone zone(Thread::Current()); | 465 StackZone zone(Thread::Current()); |
486 Bigint& bigint = Bigint::Handle(); | 466 Bigint& bigint = Bigint::Handle(); |
487 bigint ^= Bigint::NewFromCString(bigint_value); | 467 bigint ^= Bigint::NewFromCString(bigint_value); |
488 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); | 468 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); |
489 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); | 469 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); |
490 char* hex_value = TestCase::BigintToHexValue(bigint_cobject); | 470 char* hex_value = TestCase::BigintToHexValue(bigint_cobject); |
491 EXPECT_STREQ(bigint_value, hex_value); | 471 EXPECT_STREQ(bigint_value, hex_value); |
492 free(hex_value); | 472 free(hex_value); |
493 } | 473 } |
494 | 474 |
495 | |
496 TEST_CASE(SerializeBigint2) { | 475 TEST_CASE(SerializeBigint2) { |
497 CheckBigint("0x0"); | 476 CheckBigint("0x0"); |
498 CheckBigint("0x1"); | 477 CheckBigint("0x1"); |
499 CheckBigint("-0x1"); | 478 CheckBigint("-0x1"); |
500 CheckBigint("0x11111111111111111111"); | 479 CheckBigint("0x11111111111111111111"); |
501 CheckBigint("-0x11111111111111111111"); | 480 CheckBigint("-0x11111111111111111111"); |
502 CheckBigint("0x9876543210987654321098765432109876543210"); | 481 CheckBigint("0x9876543210987654321098765432109876543210"); |
503 CheckBigint("-0x9876543210987654321098765432109876543210"); | 482 CheckBigint("-0x9876543210987654321098765432109876543210"); |
504 } | 483 } |
505 | 484 |
(...skipping 28 matching lines...) Expand all Loading... |
534 EXPECT(Object::code_class() == reader.ReadObject()); | 513 EXPECT(Object::code_class() == reader.ReadObject()); |
535 EXPECT(Object::instructions_class() == reader.ReadObject()); | 514 EXPECT(Object::instructions_class() == reader.ReadObject()); |
536 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); | 515 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); |
537 EXPECT(Object::exception_handlers_class() == reader.ReadObject()); | 516 EXPECT(Object::exception_handlers_class() == reader.ReadObject()); |
538 EXPECT(Object::context_class() == reader.ReadObject()); | 517 EXPECT(Object::context_class() == reader.ReadObject()); |
539 EXPECT(Object::context_scope_class() == reader.ReadObject()); | 518 EXPECT(Object::context_scope_class() == reader.ReadObject()); |
540 | 519 |
541 free(buffer); | 520 free(buffer); |
542 } | 521 } |
543 | 522 |
544 | |
545 static void TestString(const char* cstr) { | 523 static void TestString(const char* cstr) { |
546 Thread* thread = Thread::Current(); | 524 Thread* thread = Thread::Current(); |
547 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); | 525 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); |
548 // Write snapshot with object content. | 526 // Write snapshot with object content. |
549 String& str = String::Handle(String::New(cstr)); | 527 String& str = String::Handle(String::New(cstr)); |
550 uint8_t* buffer; | 528 uint8_t* buffer; |
551 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 529 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
552 writer.WriteMessage(str); | 530 writer.WriteMessage(str); |
553 intptr_t buffer_len = writer.BytesWritten(); | 531 intptr_t buffer_len = writer.BytesWritten(); |
554 | 532 |
555 // Read object back from the snapshot. | 533 // Read object back from the snapshot. |
556 MessageSnapshotReader reader(buffer, buffer_len, thread); | 534 MessageSnapshotReader reader(buffer, buffer_len, thread); |
557 String& serialized_str = String::Handle(); | 535 String& serialized_str = String::Handle(); |
558 serialized_str ^= reader.ReadObject(); | 536 serialized_str ^= reader.ReadObject(); |
559 EXPECT(str.Equals(serialized_str)); | 537 EXPECT(str.Equals(serialized_str)); |
560 | 538 |
561 // Read object back from the snapshot into a C structure. | 539 // Read object back from the snapshot into a C structure. |
562 ApiNativeScope scope; | 540 ApiNativeScope scope; |
563 ApiMessageReader api_reader(buffer, buffer_len); | 541 ApiMessageReader api_reader(buffer, buffer_len); |
564 Dart_CObject* root = api_reader.ReadMessage(); | 542 Dart_CObject* root = api_reader.ReadMessage(); |
565 EXPECT_EQ(Dart_CObject_kString, root->type); | 543 EXPECT_EQ(Dart_CObject_kString, root->type); |
566 EXPECT_STREQ(cstr, root->value.as_string); | 544 EXPECT_STREQ(cstr, root->value.as_string); |
567 CheckEncodeDecodeMessage(root); | 545 CheckEncodeDecodeMessage(root); |
568 } | 546 } |
569 | 547 |
570 | |
571 TEST_CASE(SerializeString) { | 548 TEST_CASE(SerializeString) { |
572 TestString("This string shall be serialized"); | 549 TestString("This string shall be serialized"); |
573 TestString("æøå"); // This file is UTF-8 encoded. | 550 TestString("æøå"); // This file is UTF-8 encoded. |
574 const char* data = | 551 const char* data = |
575 "\x01" | 552 "\x01" |
576 "\x7F" | 553 "\x7F" |
577 "\xC2\x80" // U+0080 | 554 "\xC2\x80" // U+0080 |
578 "\xDF\xBF" // U+07FF | 555 "\xDF\xBF" // U+07FF |
579 "\xE0\xA0\x80" // U+0800 | 556 "\xE0\xA0\x80" // U+0800 |
580 "\xEF\xBF\xBF"; // U+FFFF | 557 "\xEF\xBF\xBF"; // U+FFFF |
581 | 558 |
582 TestString(data); | 559 TestString(data); |
583 // TODO(sgjesse): Add tests with non-BMP characters. | 560 // TODO(sgjesse): Add tests with non-BMP characters. |
584 } | 561 } |
585 | 562 |
586 | |
587 TEST_CASE(SerializeArray) { | 563 TEST_CASE(SerializeArray) { |
588 // Write snapshot with object content. | 564 // Write snapshot with object content. |
589 const int kArrayLength = 10; | 565 const int kArrayLength = 10; |
590 Array& array = Array::Handle(Array::New(kArrayLength)); | 566 Array& array = Array::Handle(Array::New(kArrayLength)); |
591 Smi& smi = Smi::Handle(); | 567 Smi& smi = Smi::Handle(); |
592 for (int i = 0; i < kArrayLength; i++) { | 568 for (int i = 0; i < kArrayLength; i++) { |
593 smi ^= Smi::New(i); | 569 smi ^= Smi::New(i); |
594 array.SetAt(i, smi); | 570 array.SetAt(i, smi); |
595 } | 571 } |
596 uint8_t* buffer; | 572 uint8_t* buffer; |
(...skipping 14 matching lines...) Expand all Loading... |
611 EXPECT_EQ(Dart_CObject_kArray, root->type); | 587 EXPECT_EQ(Dart_CObject_kArray, root->type); |
612 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 588 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
613 for (int i = 0; i < kArrayLength; i++) { | 589 for (int i = 0; i < kArrayLength; i++) { |
614 Dart_CObject* element = root->value.as_array.values[i]; | 590 Dart_CObject* element = root->value.as_array.values[i]; |
615 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 591 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
616 EXPECT_EQ(i, element->value.as_int32); | 592 EXPECT_EQ(i, element->value.as_int32); |
617 } | 593 } |
618 CheckEncodeDecodeMessage(root); | 594 CheckEncodeDecodeMessage(root); |
619 } | 595 } |
620 | 596 |
621 | |
622 TEST_CASE(FailSerializeLargeArray) { | 597 TEST_CASE(FailSerializeLargeArray) { |
623 Dart_CObject root; | 598 Dart_CObject root; |
624 root.type = Dart_CObject_kArray; | 599 root.type = Dart_CObject_kArray; |
625 root.value.as_array.length = Array::kMaxElements + 1; | 600 root.value.as_array.length = Array::kMaxElements + 1; |
626 root.value.as_array.values = NULL; | 601 root.value.as_array.values = NULL; |
627 ExpectEncodeFail(&root); | 602 ExpectEncodeFail(&root); |
628 } | 603 } |
629 | 604 |
630 | |
631 TEST_CASE(FailSerializeLargeNestedArray) { | 605 TEST_CASE(FailSerializeLargeNestedArray) { |
632 Dart_CObject parent; | 606 Dart_CObject parent; |
633 Dart_CObject child; | 607 Dart_CObject child; |
634 Dart_CObject* values[1] = {&child}; | 608 Dart_CObject* values[1] = {&child}; |
635 | 609 |
636 parent.type = Dart_CObject_kArray; | 610 parent.type = Dart_CObject_kArray; |
637 parent.value.as_array.length = 1; | 611 parent.value.as_array.length = 1; |
638 parent.value.as_array.values = values; | 612 parent.value.as_array.values = values; |
639 child.type = Dart_CObject_kArray; | 613 child.type = Dart_CObject_kArray; |
640 child.value.as_array.length = Array::kMaxElements + 1; | 614 child.value.as_array.length = Array::kMaxElements + 1; |
641 ExpectEncodeFail(&parent); | 615 ExpectEncodeFail(&parent); |
642 } | 616 } |
643 | 617 |
644 | |
645 TEST_CASE(FailSerializeLargeTypedDataInt8) { | 618 TEST_CASE(FailSerializeLargeTypedDataInt8) { |
646 Dart_CObject root; | 619 Dart_CObject root; |
647 root.type = Dart_CObject_kTypedData; | 620 root.type = Dart_CObject_kTypedData; |
648 root.value.as_typed_data.type = Dart_TypedData_kInt8; | 621 root.value.as_typed_data.type = Dart_TypedData_kInt8; |
649 root.value.as_typed_data.length = | 622 root.value.as_typed_data.length = |
650 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; | 623 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; |
651 ExpectEncodeFail(&root); | 624 ExpectEncodeFail(&root); |
652 } | 625 } |
653 | 626 |
654 | |
655 TEST_CASE(FailSerializeLargeTypedDataUint8) { | 627 TEST_CASE(FailSerializeLargeTypedDataUint8) { |
656 Dart_CObject root; | 628 Dart_CObject root; |
657 root.type = Dart_CObject_kTypedData; | 629 root.type = Dart_CObject_kTypedData; |
658 root.value.as_typed_data.type = Dart_TypedData_kUint8; | 630 root.value.as_typed_data.type = Dart_TypedData_kUint8; |
659 root.value.as_typed_data.length = | 631 root.value.as_typed_data.length = |
660 TypedData::MaxElements(kTypedDataUint8ArrayCid) + 1; | 632 TypedData::MaxElements(kTypedDataUint8ArrayCid) + 1; |
661 ExpectEncodeFail(&root); | 633 ExpectEncodeFail(&root); |
662 } | 634 } |
663 | 635 |
664 | |
665 TEST_CASE(FailSerializeLargeExternalTypedData) { | 636 TEST_CASE(FailSerializeLargeExternalTypedData) { |
666 Dart_CObject root; | 637 Dart_CObject root; |
667 root.type = Dart_CObject_kExternalTypedData; | 638 root.type = Dart_CObject_kExternalTypedData; |
668 root.value.as_typed_data.length = | 639 root.value.as_typed_data.length = |
669 ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1; | 640 ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1; |
670 ExpectEncodeFail(&root); | 641 ExpectEncodeFail(&root); |
671 } | 642 } |
672 | 643 |
673 | |
674 TEST_CASE(SerializeEmptyArray) { | 644 TEST_CASE(SerializeEmptyArray) { |
675 // Write snapshot with object content. | 645 // Write snapshot with object content. |
676 const int kArrayLength = 0; | 646 const int kArrayLength = 0; |
677 Array& array = Array::Handle(Array::New(kArrayLength)); | 647 Array& array = Array::Handle(Array::New(kArrayLength)); |
678 uint8_t* buffer; | 648 uint8_t* buffer; |
679 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 649 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
680 writer.WriteMessage(array); | 650 writer.WriteMessage(array); |
681 intptr_t buffer_len = writer.BytesWritten(); | 651 intptr_t buffer_len = writer.BytesWritten(); |
682 | 652 |
683 // Read object back from the snapshot. | 653 // Read object back from the snapshot. |
684 MessageSnapshotReader reader(buffer, buffer_len, thread); | 654 MessageSnapshotReader reader(buffer, buffer_len, thread); |
685 Array& serialized_array = Array::Handle(); | 655 Array& serialized_array = Array::Handle(); |
686 serialized_array ^= reader.ReadObject(); | 656 serialized_array ^= reader.ReadObject(); |
687 EXPECT(array.CanonicalizeEquals(serialized_array)); | 657 EXPECT(array.CanonicalizeEquals(serialized_array)); |
688 | 658 |
689 // Read object back from the snapshot into a C structure. | 659 // Read object back from the snapshot into a C structure. |
690 ApiNativeScope scope; | 660 ApiNativeScope scope; |
691 ApiMessageReader api_reader(buffer, buffer_len); | 661 ApiMessageReader api_reader(buffer, buffer_len); |
692 Dart_CObject* root = api_reader.ReadMessage(); | 662 Dart_CObject* root = api_reader.ReadMessage(); |
693 EXPECT_EQ(Dart_CObject_kArray, root->type); | 663 EXPECT_EQ(Dart_CObject_kArray, root->type); |
694 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 664 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
695 EXPECT(root->value.as_array.values == NULL); | 665 EXPECT(root->value.as_array.values == NULL); |
696 CheckEncodeDecodeMessage(root); | 666 CheckEncodeDecodeMessage(root); |
697 } | 667 } |
698 | 668 |
699 | |
700 TEST_CASE(SerializeByteArray) { | 669 TEST_CASE(SerializeByteArray) { |
701 // Write snapshot with object content. | 670 // Write snapshot with object content. |
702 const int kTypedDataLength = 256; | 671 const int kTypedDataLength = 256; |
703 TypedData& typed_data = TypedData::Handle( | 672 TypedData& typed_data = TypedData::Handle( |
704 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); | 673 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
705 for (int i = 0; i < kTypedDataLength; i++) { | 674 for (int i = 0; i < kTypedDataLength; i++) { |
706 typed_data.SetUint8(i, i); | 675 typed_data.SetUint8(i, i); |
707 } | 676 } |
708 uint8_t* buffer; | 677 uint8_t* buffer; |
709 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 678 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
(...skipping 11 matching lines...) Expand all Loading... |
721 ApiMessageReader api_reader(buffer, buffer_len); | 690 ApiMessageReader api_reader(buffer, buffer_len); |
722 Dart_CObject* root = api_reader.ReadMessage(); | 691 Dart_CObject* root = api_reader.ReadMessage(); |
723 EXPECT_EQ(Dart_CObject_kTypedData, root->type); | 692 EXPECT_EQ(Dart_CObject_kTypedData, root->type); |
724 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); | 693 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
725 for (int i = 0; i < kTypedDataLength; i++) { | 694 for (int i = 0; i < kTypedDataLength; i++) { |
726 EXPECT(root->value.as_typed_data.values[i] == i); | 695 EXPECT(root->value.as_typed_data.values[i] == i); |
727 } | 696 } |
728 CheckEncodeDecodeMessage(root); | 697 CheckEncodeDecodeMessage(root); |
729 } | 698 } |
730 | 699 |
731 | |
732 #define TEST_TYPED_ARRAY(darttype, ctype) \ | 700 #define TEST_TYPED_ARRAY(darttype, ctype) \ |
733 { \ | 701 { \ |
734 StackZone zone(thread); \ | 702 StackZone zone(thread); \ |
735 const int kArrayLength = 127; \ | 703 const int kArrayLength = 127; \ |
736 TypedData& array = TypedData::Handle( \ | 704 TypedData& array = TypedData::Handle( \ |
737 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ | 705 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ |
738 intptr_t scale = array.ElementSizeInBytes(); \ | 706 intptr_t scale = array.ElementSizeInBytes(); \ |
739 for (int i = 0; i < kArrayLength; i++) { \ | 707 for (int i = 0; i < kArrayLength; i++) { \ |
740 array.Set##darttype((i * scale), i); \ | 708 array.Set##darttype((i * scale), i); \ |
741 } \ | 709 } \ |
742 uint8_t* buffer; \ | 710 uint8_t* buffer; \ |
743 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); \ | 711 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); \ |
744 writer.WriteMessage(array); \ | 712 writer.WriteMessage(array); \ |
745 intptr_t buffer_len = writer.BytesWritten(); \ | 713 intptr_t buffer_len = writer.BytesWritten(); \ |
746 MessageSnapshotReader reader(buffer, buffer_len, thread); \ | 714 MessageSnapshotReader reader(buffer, buffer_len, thread); \ |
747 TypedData& serialized_array = TypedData::Handle(); \ | 715 TypedData& serialized_array = TypedData::Handle(); \ |
748 serialized_array ^= reader.ReadObject(); \ | 716 serialized_array ^= reader.ReadObject(); \ |
749 for (int i = 0; i < kArrayLength; i++) { \ | 717 for (int i = 0; i < kArrayLength; i++) { \ |
750 EXPECT_EQ(static_cast<ctype>(i), \ | 718 EXPECT_EQ(static_cast<ctype>(i), \ |
751 serialized_array.Get##darttype(i* scale)); \ | 719 serialized_array.Get##darttype(i* scale)); \ |
752 } \ | 720 } \ |
753 } | 721 } |
754 | 722 |
755 | |
756 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ | 723 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ |
757 { \ | 724 { \ |
758 StackZone zone(thread); \ | 725 StackZone zone(thread); \ |
759 ctype data[] = {0, 11, 22, 33, 44, 55, 66, 77}; \ | 726 ctype data[] = {0, 11, 22, 33, 44, 55, 66, 77}; \ |
760 intptr_t length = ARRAY_SIZE(data); \ | 727 intptr_t length = ARRAY_SIZE(data); \ |
761 ExternalTypedData& array = ExternalTypedData::Handle( \ | 728 ExternalTypedData& array = ExternalTypedData::Handle( \ |
762 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ | 729 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ |
763 reinterpret_cast<uint8_t*>(data), length)); \ | 730 reinterpret_cast<uint8_t*>(data), length)); \ |
764 intptr_t scale = array.ElementSizeInBytes(); \ | 731 intptr_t scale = array.ElementSizeInBytes(); \ |
765 uint8_t* buffer; \ | 732 uint8_t* buffer; \ |
766 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); \ | 733 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); \ |
767 writer.WriteMessage(array); \ | 734 writer.WriteMessage(array); \ |
768 intptr_t buffer_len = writer.BytesWritten(); \ | 735 intptr_t buffer_len = writer.BytesWritten(); \ |
769 MessageSnapshotReader reader(buffer, buffer_len, thread); \ | 736 MessageSnapshotReader reader(buffer, buffer_len, thread); \ |
770 TypedData& serialized_array = TypedData::Handle(); \ | 737 TypedData& serialized_array = TypedData::Handle(); \ |
771 serialized_array ^= reader.ReadObject(); \ | 738 serialized_array ^= reader.ReadObject(); \ |
772 for (int i = 0; i < length; i++) { \ | 739 for (int i = 0; i < length; i++) { \ |
773 EXPECT_EQ(static_cast<ctype>(data[i]), \ | 740 EXPECT_EQ(static_cast<ctype>(data[i]), \ |
774 serialized_array.Get##darttype(i* scale)); \ | 741 serialized_array.Get##darttype(i* scale)); \ |
775 } \ | 742 } \ |
776 } | 743 } |
777 | 744 |
778 | |
779 TEST_CASE(SerializeTypedArray) { | 745 TEST_CASE(SerializeTypedArray) { |
780 TEST_TYPED_ARRAY(Int8, int8_t); | 746 TEST_TYPED_ARRAY(Int8, int8_t); |
781 TEST_TYPED_ARRAY(Uint8, uint8_t); | 747 TEST_TYPED_ARRAY(Uint8, uint8_t); |
782 TEST_TYPED_ARRAY(Int16, int16_t); | 748 TEST_TYPED_ARRAY(Int16, int16_t); |
783 TEST_TYPED_ARRAY(Uint16, uint16_t); | 749 TEST_TYPED_ARRAY(Uint16, uint16_t); |
784 TEST_TYPED_ARRAY(Int32, int32_t); | 750 TEST_TYPED_ARRAY(Int32, int32_t); |
785 TEST_TYPED_ARRAY(Uint32, uint32_t); | 751 TEST_TYPED_ARRAY(Uint32, uint32_t); |
786 TEST_TYPED_ARRAY(Int64, int64_t); | 752 TEST_TYPED_ARRAY(Int64, int64_t); |
787 TEST_TYPED_ARRAY(Uint64, uint64_t); | 753 TEST_TYPED_ARRAY(Uint64, uint64_t); |
788 TEST_TYPED_ARRAY(Float32, float); | 754 TEST_TYPED_ARRAY(Float32, float); |
789 TEST_TYPED_ARRAY(Float64, double); | 755 TEST_TYPED_ARRAY(Float64, double); |
790 } | 756 } |
791 | 757 |
792 | |
793 TEST_CASE(SerializeExternalTypedArray) { | 758 TEST_CASE(SerializeExternalTypedArray) { |
794 TEST_EXTERNAL_TYPED_ARRAY(Int8, int8_t); | 759 TEST_EXTERNAL_TYPED_ARRAY(Int8, int8_t); |
795 TEST_EXTERNAL_TYPED_ARRAY(Uint8, uint8_t); | 760 TEST_EXTERNAL_TYPED_ARRAY(Uint8, uint8_t); |
796 TEST_EXTERNAL_TYPED_ARRAY(Int16, int16_t); | 761 TEST_EXTERNAL_TYPED_ARRAY(Int16, int16_t); |
797 TEST_EXTERNAL_TYPED_ARRAY(Uint16, uint16_t); | 762 TEST_EXTERNAL_TYPED_ARRAY(Uint16, uint16_t); |
798 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t); | 763 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t); |
799 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t); | 764 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t); |
800 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t); | 765 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t); |
801 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t); | 766 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t); |
802 TEST_EXTERNAL_TYPED_ARRAY(Float32, float); | 767 TEST_EXTERNAL_TYPED_ARRAY(Float32, float); |
803 TEST_EXTERNAL_TYPED_ARRAY(Float64, double); | 768 TEST_EXTERNAL_TYPED_ARRAY(Float64, double); |
804 } | 769 } |
805 | 770 |
806 | |
807 TEST_CASE(SerializeEmptyByteArray) { | 771 TEST_CASE(SerializeEmptyByteArray) { |
808 // Write snapshot with object content. | 772 // Write snapshot with object content. |
809 const int kTypedDataLength = 0; | 773 const int kTypedDataLength = 0; |
810 TypedData& typed_data = TypedData::Handle( | 774 TypedData& typed_data = TypedData::Handle( |
811 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); | 775 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
812 uint8_t* buffer; | 776 uint8_t* buffer; |
813 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 777 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
814 writer.WriteMessage(typed_data); | 778 writer.WriteMessage(typed_data); |
815 intptr_t buffer_len = writer.BytesWritten(); | 779 intptr_t buffer_len = writer.BytesWritten(); |
816 | 780 |
817 // Read object back from the snapshot. | 781 // Read object back from the snapshot. |
818 MessageSnapshotReader reader(buffer, buffer_len, thread); | 782 MessageSnapshotReader reader(buffer, buffer_len, thread); |
819 TypedData& serialized_typed_data = TypedData::Handle(); | 783 TypedData& serialized_typed_data = TypedData::Handle(); |
820 serialized_typed_data ^= reader.ReadObject(); | 784 serialized_typed_data ^= reader.ReadObject(); |
821 EXPECT(serialized_typed_data.IsTypedData()); | 785 EXPECT(serialized_typed_data.IsTypedData()); |
822 | 786 |
823 // Read object back from the snapshot into a C structure. | 787 // Read object back from the snapshot into a C structure. |
824 ApiNativeScope scope; | 788 ApiNativeScope scope; |
825 ApiMessageReader api_reader(buffer, buffer_len); | 789 ApiMessageReader api_reader(buffer, buffer_len); |
826 Dart_CObject* root = api_reader.ReadMessage(); | 790 Dart_CObject* root = api_reader.ReadMessage(); |
827 EXPECT_EQ(Dart_CObject_kTypedData, root->type); | 791 EXPECT_EQ(Dart_CObject_kTypedData, root->type); |
828 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); | 792 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); |
829 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); | 793 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
830 EXPECT(root->value.as_typed_data.values == NULL); | 794 EXPECT(root->value.as_typed_data.values == NULL); |
831 CheckEncodeDecodeMessage(root); | 795 CheckEncodeDecodeMessage(root); |
832 } | 796 } |
833 | 797 |
834 | |
835 class TestSnapshotWriter : public SnapshotWriter { | 798 class TestSnapshotWriter : public SnapshotWriter { |
836 public: | 799 public: |
837 static const intptr_t kInitialSize = 64 * KB; | 800 static const intptr_t kInitialSize = 64 * KB; |
838 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 801 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
839 : SnapshotWriter(Thread::Current(), | 802 : SnapshotWriter(Thread::Current(), |
840 Snapshot::kScript, | 803 Snapshot::kScript, |
841 buffer, | 804 buffer, |
842 alloc, | 805 alloc, |
843 NULL, | 806 NULL, |
844 kInitialSize, | 807 kInitialSize, |
845 &forward_list_, | 808 &forward_list_, |
846 true /* can_send_any_object */), | 809 true /* can_send_any_object */), |
847 forward_list_(thread(), kMaxPredefinedObjectIds) { | 810 forward_list_(thread(), kMaxPredefinedObjectIds) { |
848 ASSERT(buffer != NULL); | 811 ASSERT(buffer != NULL); |
849 ASSERT(alloc != NULL); | 812 ASSERT(alloc != NULL); |
850 } | 813 } |
851 ~TestSnapshotWriter() {} | 814 ~TestSnapshotWriter() {} |
852 | 815 |
853 // Writes just a script object | 816 // Writes just a script object |
854 void WriteScript(const Script& script) { WriteObject(script.raw()); } | 817 void WriteScript(const Script& script) { WriteObject(script.raw()); } |
855 | 818 |
856 private: | 819 private: |
857 ForwardList forward_list_; | 820 ForwardList forward_list_; |
858 | 821 |
859 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); | 822 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); |
860 }; | 823 }; |
861 | 824 |
862 | |
863 static void GenerateSourceAndCheck(const Script& script) { | 825 static void GenerateSourceAndCheck(const Script& script) { |
864 // Check if we are able to generate the source from the token stream. | 826 // Check if we are able to generate the source from the token stream. |
865 // Rescan this source and compare the token stream to see if they are | 827 // Rescan this source and compare the token stream to see if they are |
866 // the same. | 828 // the same. |
867 Zone* zone = Thread::Current()->zone(); | 829 Zone* zone = Thread::Current()->zone(); |
868 const TokenStream& expected_tokens = | 830 const TokenStream& expected_tokens = |
869 TokenStream::Handle(zone, script.tokens()); | 831 TokenStream::Handle(zone, script.tokens()); |
870 TokenStream::Iterator expected_iterator(zone, expected_tokens, | 832 TokenStream::Iterator expected_iterator(zone, expected_tokens, |
871 TokenPosition::kMinSource, | 833 TokenPosition::kMinSource, |
872 TokenStream::Iterator::kAllTokens); | 834 TokenStream::Iterator::kAllTokens); |
(...skipping 15 matching lines...) Expand all Loading... |
888 expected_literal ^= expected_iterator.CurrentLiteral(); | 850 expected_literal ^= expected_iterator.CurrentLiteral(); |
889 actual_literal ^= reconstructed_iterator.CurrentLiteral(); | 851 actual_literal ^= reconstructed_iterator.CurrentLiteral(); |
890 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString()); | 852 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString()); |
891 expected_iterator.Advance(); | 853 expected_iterator.Advance(); |
892 reconstructed_iterator.Advance(); | 854 reconstructed_iterator.Advance(); |
893 expected_kind = expected_iterator.CurrentTokenKind(); | 855 expected_kind = expected_iterator.CurrentTokenKind(); |
894 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); | 856 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); |
895 } | 857 } |
896 } | 858 } |
897 | 859 |
898 | |
899 TEST_CASE(SerializeScript) { | 860 TEST_CASE(SerializeScript) { |
900 const char* kScriptChars = | 861 const char* kScriptChars = |
901 "class A {\n" | 862 "class A {\n" |
902 " static bar() { return 42; }\n" | 863 " static bar() { return 42; }\n" |
903 " static fly() { return 5; }\n" | 864 " static fly() { return 5; }\n" |
904 " static s1() { return 'this is a string in the source'; }\n" | 865 " static s1() { return 'this is a string in the source'; }\n" |
905 " static s2() { return 'this is a \"string\" in the source'; }\n" | 866 " static s2() { return 'this is a \"string\" in the source'; }\n" |
906 " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" | 867 " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" |
907 " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" | 868 " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" |
908 " static ms1() {\n" | 869 " static ms1() {\n" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 } | 955 } |
995 | 956 |
996 // Check if we are able to generate the source from the token stream. | 957 // Check if we are able to generate the source from the token stream. |
997 // Rescan this source and compare the token stream to see if they are | 958 // Rescan this source and compare the token stream to see if they are |
998 // the same. | 959 // the same. |
999 GenerateSourceAndCheck(serialized_script); | 960 GenerateSourceAndCheck(serialized_script); |
1000 | 961 |
1001 free(buffer); | 962 free(buffer); |
1002 } | 963 } |
1003 | 964 |
1004 | |
1005 #if !defined(PRODUCT) // Uses mirrors. | 965 #if !defined(PRODUCT) // Uses mirrors. |
1006 VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { | 966 VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { |
1007 const char* kScriptChars = | 967 const char* kScriptChars = |
1008 "\n" | 968 "\n" |
1009 "import 'dart:mirrors';" | 969 "import 'dart:mirrors';" |
1010 "import 'dart:isolate';" | 970 "import 'dart:isolate';" |
1011 "void main() {" | 971 "void main() {" |
1012 " if (reflectClass(MyException).superclass.reflectedType != " | 972 " if (reflectClass(MyException).superclass.reflectedType != " |
1013 " IsolateSpawnException) {" | 973 " IsolateSpawnException) {" |
1014 " throw new Exception('Canonicalization failure');" | 974 " throw new Exception('Canonicalization failure');" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 1061 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
1102 EXPECT_VALID(result); | 1062 EXPECT_VALID(result); |
1103 Dart_ExitScope(); | 1063 Dart_ExitScope(); |
1104 Dart_ShutdownIsolate(); | 1064 Dart_ShutdownIsolate(); |
1105 } | 1065 } |
1106 free(script_snapshot); | 1066 free(script_snapshot); |
1107 free(full_snapshot); | 1067 free(full_snapshot); |
1108 } | 1068 } |
1109 #endif | 1069 #endif |
1110 | 1070 |
1111 | |
1112 VM_UNIT_TEST_CASE(ScriptSnapshotsUpdateSubclasses) { | 1071 VM_UNIT_TEST_CASE(ScriptSnapshotsUpdateSubclasses) { |
1113 const char* kScriptChars = | 1072 const char* kScriptChars = |
1114 "class _DebugDuration extends Duration {\n" | 1073 "class _DebugDuration extends Duration {\n" |
1115 " const _DebugDuration() : super(milliseconds: 42);\n" | 1074 " const _DebugDuration() : super(milliseconds: 42);\n" |
1116 "}\n" | 1075 "}\n" |
1117 "foo(x, y) {\n" | 1076 "foo(x, y) {\n" |
1118 " for (var i = 0; i < 1000000; i++) {\n" | 1077 " for (var i = 0; i < 1000000; i++) {\n" |
1119 " if (x != y) {\n" | 1078 " if (x != y) {\n" |
1120 " throw 'Boom!';\n" | 1079 " throw 'Boom!';\n" |
1121 " }\n" | 1080 " }\n" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 } | 1174 } |
1216 free(script_snapshot); | 1175 free(script_snapshot); |
1217 free(full_snapshot); | 1176 free(full_snapshot); |
1218 | 1177 |
1219 FLAG_max_polymorphic_checks = saved_max_polymorphic_checks; | 1178 FLAG_max_polymorphic_checks = saved_max_polymorphic_checks; |
1220 #if !defined(PRODUCT) | 1179 #if !defined(PRODUCT) |
1221 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; | 1180 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
1222 #endif | 1181 #endif |
1223 } | 1182 } |
1224 | 1183 |
1225 | |
1226 static void IterateScripts(const Library& lib) { | 1184 static void IterateScripts(const Library& lib) { |
1227 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); | 1185 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); |
1228 Script& script = Script::Handle(); | 1186 Script& script = Script::Handle(); |
1229 String& uri = String::Handle(); | 1187 String& uri = String::Handle(); |
1230 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { | 1188 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { |
1231 script ^= lib_scripts.At(i); | 1189 script ^= lib_scripts.At(i); |
1232 EXPECT(!script.IsNull()); | 1190 EXPECT(!script.IsNull()); |
1233 uri = script.url(); | 1191 uri = script.url(); |
1234 OS::Print("Generating source for part: %s\n", uri.ToCString()); | 1192 OS::Print("Generating source for part: %s\n", uri.ToCString()); |
1235 GenerateSourceAndCheck(script); | 1193 GenerateSourceAndCheck(script); |
(...skipping 17 matching lines...) Expand all Loading... |
1253 EXPECT(!lib.IsNull()); | 1211 EXPECT(!lib.IsNull()); |
1254 uri = lib.url(); | 1212 uri = lib.url(); |
1255 OS::Print("Generating source for library: %s\n", uri.ToCString()); | 1213 OS::Print("Generating source for library: %s\n", uri.ToCString()); |
1256 IterateScripts(lib); | 1214 IterateScripts(lib); |
1257 } | 1215 } |
1258 | 1216 |
1259 MallocHooks::set_stack_trace_collection_enabled( | 1217 MallocHooks::set_stack_trace_collection_enabled( |
1260 stack_trace_collection_enabled); | 1218 stack_trace_collection_enabled); |
1261 } | 1219 } |
1262 | 1220 |
1263 | |
1264 VM_UNIT_TEST_CASE(FullSnapshot) { | 1221 VM_UNIT_TEST_CASE(FullSnapshot) { |
1265 const char* kScriptChars = | 1222 const char* kScriptChars = |
1266 "class Fields {\n" | 1223 "class Fields {\n" |
1267 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" | 1224 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" |
1268 " int fld1;\n" | 1225 " int fld1;\n" |
1269 " final int fld2;\n" | 1226 " final int fld2;\n" |
1270 " final int bigint_fld = 0xfffffffffff;\n" | 1227 " final int bigint_fld = 0xfffffffffff;\n" |
1271 " static int fld3;\n" | 1228 " static int fld3;\n" |
1272 " static const int smi_sfld = 10;\n" | 1229 " static const int smi_sfld = 10;\n" |
1273 " static const int bigint_sfld = 0xfffffffffff;\n" | 1230 " static const int bigint_sfld = 0xfffffffffff;\n" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 // Invoke a function which returns an object. | 1284 // Invoke a function which returns an object. |
1328 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); | 1285 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); |
1329 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1286 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1330 EXPECT_VALID(result); | 1287 EXPECT_VALID(result); |
1331 Dart_ExitScope(); | 1288 Dart_ExitScope(); |
1332 } | 1289 } |
1333 Dart_ShutdownIsolate(); | 1290 Dart_ShutdownIsolate(); |
1334 free(isolate_snapshot_data_buffer); | 1291 free(isolate_snapshot_data_buffer); |
1335 } | 1292 } |
1336 | 1293 |
1337 | |
1338 VM_UNIT_TEST_CASE(FullSnapshot1) { | 1294 VM_UNIT_TEST_CASE(FullSnapshot1) { |
1339 // This buffer has to be static for this to compile with Visual Studio. | 1295 // This buffer has to be static for this to compile with Visual Studio. |
1340 // If it is not static compilation of this file with Visual Studio takes | 1296 // If it is not static compilation of this file with Visual Studio takes |
1341 // more than 30 minutes! | 1297 // more than 30 minutes! |
1342 static const char kFullSnapshotScriptChars[] = { | 1298 static const char kFullSnapshotScriptChars[] = { |
1343 #include "snapshot_test.dat" | 1299 #include "snapshot_test.dat" |
1344 }; | 1300 }; |
1345 const char* kScriptChars = kFullSnapshotScriptChars; | 1301 const char* kScriptChars = kFullSnapshotScriptChars; |
1346 | 1302 |
1347 uint8_t* isolate_snapshot_data_buffer; | 1303 uint8_t* isolate_snapshot_data_buffer; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 // Print the error. It is probably an unhandled exception. | 1349 // Print the error. It is probably an unhandled exception. |
1394 fprintf(stderr, "%s\n", Dart_GetError(result)); | 1350 fprintf(stderr, "%s\n", Dart_GetError(result)); |
1395 } | 1351 } |
1396 EXPECT_VALID(result); | 1352 EXPECT_VALID(result); |
1397 Dart_ExitScope(); | 1353 Dart_ExitScope(); |
1398 } | 1354 } |
1399 Dart_ShutdownIsolate(); | 1355 Dart_ShutdownIsolate(); |
1400 free(isolate_snapshot_data_buffer); | 1356 free(isolate_snapshot_data_buffer); |
1401 } | 1357 } |
1402 | 1358 |
1403 | |
1404 #ifndef PRODUCT | 1359 #ifndef PRODUCT |
1405 | 1360 |
1406 | |
1407 VM_UNIT_TEST_CASE(ScriptSnapshot) { | 1361 VM_UNIT_TEST_CASE(ScriptSnapshot) { |
1408 const char* kLibScriptChars = | 1362 const char* kLibScriptChars = |
1409 "library dart_import_lib;" | 1363 "library dart_import_lib;" |
1410 "class LibFields {" | 1364 "class LibFields {" |
1411 " LibFields(int i, int j) : fld1 = i, fld2 = j {}" | 1365 " LibFields(int i, int j) : fld1 = i, fld2 = j {}" |
1412 " int fld1;" | 1366 " int fld1;" |
1413 " final int fld2;" | 1367 " final int fld2;" |
1414 "}"; | 1368 "}"; |
1415 const char* kScriptChars = | 1369 const char* kScriptChars = |
1416 "class TestTrace implements StackTrace {" | 1370 "class TestTrace implements StackTrace {" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); | 1485 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); |
1532 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1486 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1533 EXPECT_VALID(result); | 1487 EXPECT_VALID(result); |
1534 Dart_ExitScope(); | 1488 Dart_ExitScope(); |
1535 Dart_ShutdownIsolate(); | 1489 Dart_ShutdownIsolate(); |
1536 } | 1490 } |
1537 free(full_snapshot); | 1491 free(full_snapshot); |
1538 free(script_snapshot); | 1492 free(script_snapshot); |
1539 } | 1493 } |
1540 | 1494 |
1541 | |
1542 VM_UNIT_TEST_CASE(ScriptSnapshot1) { | 1495 VM_UNIT_TEST_CASE(ScriptSnapshot1) { |
1543 const char* kScriptChars = | 1496 const char* kScriptChars = |
1544 "class _SimpleNumEnumerable<T extends num> {" | 1497 "class _SimpleNumEnumerable<T extends num> {" |
1545 "final Iterable<T> _source;" | 1498 "final Iterable<T> _source;" |
1546 "const _SimpleNumEnumerable(this._source) : super();" | 1499 "const _SimpleNumEnumerable(this._source) : super();" |
1547 "}"; | 1500 "}"; |
1548 | 1501 |
1549 Dart_Handle result; | 1502 Dart_Handle result; |
1550 uint8_t* buffer; | 1503 uint8_t* buffer; |
1551 intptr_t size; | 1504 intptr_t size; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 EXPECT_VALID(result); | 1557 EXPECT_VALID(result); |
1605 Dart_ExitScope(); | 1558 Dart_ExitScope(); |
1606 } | 1559 } |
1607 | 1560 |
1608 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; | 1561 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
1609 Dart_ShutdownIsolate(); | 1562 Dart_ShutdownIsolate(); |
1610 free(full_snapshot); | 1563 free(full_snapshot); |
1611 free(script_snapshot); | 1564 free(script_snapshot); |
1612 } | 1565 } |
1613 | 1566 |
1614 | |
1615 VM_UNIT_TEST_CASE(ScriptSnapshot2) { | 1567 VM_UNIT_TEST_CASE(ScriptSnapshot2) { |
1616 // The snapshot of this library is always created in production mode, but | 1568 // The snapshot of this library is always created in production mode, but |
1617 // loaded and executed in both production and checked modes. | 1569 // loaded and executed in both production and checked modes. |
1618 // This test verifies that type information is still contained in the snapshot | 1570 // This test verifies that type information is still contained in the snapshot |
1619 // although it was created in production mode and that type errors and | 1571 // although it was created in production mode and that type errors and |
1620 // compilation errors (for const fields) are correctly reported according to | 1572 // compilation errors (for const fields) are correctly reported according to |
1621 // the execution mode. | 1573 // the execution mode. |
1622 const char* kLibScriptChars = | 1574 const char* kLibScriptChars = |
1623 "library dart_import_lib;" | 1575 "library dart_import_lib;" |
1624 "const String s = 1.0;" | 1576 "const String s = 1.0;" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 // Invoke the test_b function. | 1672 // Invoke the test_b function. |
1721 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL); | 1673 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL); |
1722 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); | 1674 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); |
1723 Dart_ExitScope(); | 1675 Dart_ExitScope(); |
1724 } | 1676 } |
1725 Dart_ShutdownIsolate(); | 1677 Dart_ShutdownIsolate(); |
1726 free(full_snapshot); | 1678 free(full_snapshot); |
1727 free(script_snapshot); | 1679 free(script_snapshot); |
1728 } | 1680 } |
1729 | 1681 |
1730 | |
1731 VM_UNIT_TEST_CASE(MismatchedSnapshotKinds) { | 1682 VM_UNIT_TEST_CASE(MismatchedSnapshotKinds) { |
1732 const char* kScriptChars = "main() { print('Hello, world!'); }"; | 1683 const char* kScriptChars = "main() { print('Hello, world!'); }"; |
1733 Dart_Handle result; | 1684 Dart_Handle result; |
1734 | 1685 |
1735 uint8_t* buffer; | 1686 uint8_t* buffer; |
1736 intptr_t size; | 1687 intptr_t size; |
1737 intptr_t vm_isolate_snapshot_size; | 1688 intptr_t vm_isolate_snapshot_size; |
1738 uint8_t* isolate_snapshot = NULL; | 1689 uint8_t* isolate_snapshot = NULL; |
1739 intptr_t isolate_snapshot_size; | 1690 intptr_t isolate_snapshot_size; |
1740 uint8_t* full_snapshot = NULL; | 1691 uint8_t* full_snapshot = NULL; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 "Dart_LoadScriptFromSnapshot expects parameter" | 1755 "Dart_LoadScriptFromSnapshot expects parameter" |
1805 " 'buffer' to be a script type snapshot."); | 1756 " 'buffer' to be a script type snapshot."); |
1806 | 1757 |
1807 Dart_ExitScope(); | 1758 Dart_ExitScope(); |
1808 } | 1759 } |
1809 Dart_ShutdownIsolate(); | 1760 Dart_ShutdownIsolate(); |
1810 free(full_snapshot); | 1761 free(full_snapshot); |
1811 free(script_snapshot); | 1762 free(script_snapshot); |
1812 } | 1763 } |
1813 | 1764 |
1814 | |
1815 #endif // !PRODUCT | 1765 #endif // !PRODUCT |
1816 | 1766 |
1817 | |
1818 TEST_CASE(IntArrayMessage) { | 1767 TEST_CASE(IntArrayMessage) { |
1819 StackZone zone(Thread::Current()); | 1768 StackZone zone(Thread::Current()); |
1820 uint8_t* buffer = NULL; | 1769 uint8_t* buffer = NULL; |
1821 ApiMessageWriter writer(&buffer, &zone_allocator); | 1770 ApiMessageWriter writer(&buffer, &zone_allocator); |
1822 | 1771 |
1823 static const int kArrayLength = 2; | 1772 static const int kArrayLength = 2; |
1824 intptr_t data[kArrayLength] = {1, 2}; | 1773 intptr_t data[kArrayLength] = {1, 2}; |
1825 int len = kArrayLength; | 1774 int len = kArrayLength; |
1826 writer.WriteMessage(len, data); | 1775 writer.WriteMessage(len, data); |
1827 | 1776 |
1828 // Read object back from the snapshot into a C structure. | 1777 // Read object back from the snapshot into a C structure. |
1829 ApiNativeScope scope; | 1778 ApiNativeScope scope; |
1830 ApiMessageReader api_reader(buffer, writer.BytesWritten()); | 1779 ApiMessageReader api_reader(buffer, writer.BytesWritten()); |
1831 Dart_CObject* root = api_reader.ReadMessage(); | 1780 Dart_CObject* root = api_reader.ReadMessage(); |
1832 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1781 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1833 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1782 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1834 for (int i = 0; i < kArrayLength; i++) { | 1783 for (int i = 0; i < kArrayLength; i++) { |
1835 Dart_CObject* element = root->value.as_array.values[i]; | 1784 Dart_CObject* element = root->value.as_array.values[i]; |
1836 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 1785 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
1837 EXPECT_EQ(i + 1, element->value.as_int32); | 1786 EXPECT_EQ(i + 1, element->value.as_int32); |
1838 } | 1787 } |
1839 CheckEncodeDecodeMessage(root); | 1788 CheckEncodeDecodeMessage(root); |
1840 } | 1789 } |
1841 | 1790 |
1842 | |
1843 // Helper function to call a top level Dart function and serialize the result. | 1791 // Helper function to call a top level Dart function and serialize the result. |
1844 static uint8_t* GetSerialized(Dart_Handle lib, | 1792 static uint8_t* GetSerialized(Dart_Handle lib, |
1845 const char* dart_function, | 1793 const char* dart_function, |
1846 intptr_t* buffer_len) { | 1794 intptr_t* buffer_len) { |
1847 Dart_Handle result; | 1795 Dart_Handle result; |
1848 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); | 1796 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); |
1849 EXPECT_VALID(result); | 1797 EXPECT_VALID(result); |
1850 Object& obj = Object::Handle(Api::UnwrapHandle(result)); | 1798 Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
1851 | 1799 |
1852 // Serialize the object into a message. | 1800 // Serialize the object into a message. |
1853 uint8_t* buffer; | 1801 uint8_t* buffer; |
1854 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, false); | 1802 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, false); |
1855 writer.WriteMessage(obj); | 1803 writer.WriteMessage(obj); |
1856 *buffer_len = writer.BytesWritten(); | 1804 *buffer_len = writer.BytesWritten(); |
1857 return buffer; | 1805 return buffer; |
1858 } | 1806 } |
1859 | 1807 |
1860 | |
1861 // Helper function to deserialize the result into a Dart_CObject structure. | 1808 // Helper function to deserialize the result into a Dart_CObject structure. |
1862 static Dart_CObject* GetDeserialized(uint8_t* buffer, intptr_t buffer_len) { | 1809 static Dart_CObject* GetDeserialized(uint8_t* buffer, intptr_t buffer_len) { |
1863 // Read object back from the snapshot into a C structure. | 1810 // Read object back from the snapshot into a C structure. |
1864 ApiMessageReader api_reader(buffer, buffer_len); | 1811 ApiMessageReader api_reader(buffer, buffer_len); |
1865 return api_reader.ReadMessage(); | 1812 return api_reader.ReadMessage(); |
1866 } | 1813 } |
1867 | 1814 |
1868 | |
1869 static void CheckString(Dart_Handle dart_string, const char* expected) { | 1815 static void CheckString(Dart_Handle dart_string, const char* expected) { |
1870 StackZone zone(Thread::Current()); | 1816 StackZone zone(Thread::Current()); |
1871 String& str = String::Handle(); | 1817 String& str = String::Handle(); |
1872 str ^= Api::UnwrapHandle(dart_string); | 1818 str ^= Api::UnwrapHandle(dart_string); |
1873 uint8_t* buffer; | 1819 uint8_t* buffer; |
1874 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, false); | 1820 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, false); |
1875 writer.WriteMessage(str); | 1821 writer.WriteMessage(str); |
1876 intptr_t buffer_len = writer.BytesWritten(); | 1822 intptr_t buffer_len = writer.BytesWritten(); |
1877 | 1823 |
1878 // Read object back from the snapshot into a C structure. | 1824 // Read object back from the snapshot into a C structure. |
1879 ApiNativeScope scope; | 1825 ApiNativeScope scope; |
1880 ApiMessageReader api_reader(buffer, buffer_len); | 1826 ApiMessageReader api_reader(buffer, buffer_len); |
1881 Dart_CObject* root = api_reader.ReadMessage(); | 1827 Dart_CObject* root = api_reader.ReadMessage(); |
1882 EXPECT_NOTNULL(root); | 1828 EXPECT_NOTNULL(root); |
1883 EXPECT_EQ(Dart_CObject_kString, root->type); | 1829 EXPECT_EQ(Dart_CObject_kString, root->type); |
1884 EXPECT_STREQ(expected, root->value.as_string); | 1830 EXPECT_STREQ(expected, root->value.as_string); |
1885 CheckEncodeDecodeMessage(root); | 1831 CheckEncodeDecodeMessage(root); |
1886 } | 1832 } |
1887 | 1833 |
1888 | |
1889 static void CheckStringInvalid(Dart_Handle dart_string) { | 1834 static void CheckStringInvalid(Dart_Handle dart_string) { |
1890 StackZone zone(Thread::Current()); | 1835 StackZone zone(Thread::Current()); |
1891 String& str = String::Handle(); | 1836 String& str = String::Handle(); |
1892 str ^= Api::UnwrapHandle(dart_string); | 1837 str ^= Api::UnwrapHandle(dart_string); |
1893 uint8_t* buffer; | 1838 uint8_t* buffer; |
1894 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, false); | 1839 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, false); |
1895 writer.WriteMessage(str); | 1840 writer.WriteMessage(str); |
1896 intptr_t buffer_len = writer.BytesWritten(); | 1841 intptr_t buffer_len = writer.BytesWritten(); |
1897 | 1842 |
1898 // Read object back from the snapshot into a C structure. | 1843 // Read object back from the snapshot into a C structure. |
1899 ApiNativeScope scope; | 1844 ApiNativeScope scope; |
1900 ApiMessageReader api_reader(buffer, buffer_len); | 1845 ApiMessageReader api_reader(buffer, buffer_len); |
1901 Dart_CObject* root = api_reader.ReadMessage(); | 1846 Dart_CObject* root = api_reader.ReadMessage(); |
1902 EXPECT_NOTNULL(root); | 1847 EXPECT_NOTNULL(root); |
1903 EXPECT_EQ(Dart_CObject_kUnsupported, root->type); | 1848 EXPECT_EQ(Dart_CObject_kUnsupported, root->type); |
1904 } | 1849 } |
1905 | 1850 |
1906 | |
1907 VM_UNIT_TEST_CASE(DartGeneratedMessages) { | 1851 VM_UNIT_TEST_CASE(DartGeneratedMessages) { |
1908 static const char* kCustomIsolateScriptChars = | 1852 static const char* kCustomIsolateScriptChars = |
1909 "getSmi() {\n" | 1853 "getSmi() {\n" |
1910 " return 42;\n" | 1854 " return 42;\n" |
1911 "}\n" | 1855 "}\n" |
1912 "getBigint() {\n" | 1856 "getBigint() {\n" |
1913 " return -0x424242424242424242424242424242424242;\n" | 1857 " return -0x424242424242424242424242424242424242;\n" |
1914 "}\n" | 1858 "}\n" |
1915 "getAsciiString() {\n" | 1859 "getAsciiString() {\n" |
1916 " return \"Hello, world!\";\n" | 1860 " return \"Hello, world!\";\n" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 "\xf0\xa0\x80\x80"); | 1988 "\xf0\xa0\x80\x80"); |
2045 CheckStringInvalid(lead_surrogate_string_result); | 1989 CheckStringInvalid(lead_surrogate_string_result); |
2046 CheckStringInvalid(trail_surrogate_string_result); | 1990 CheckStringInvalid(trail_surrogate_string_result); |
2047 CheckStringInvalid(crappy_string_result); | 1991 CheckStringInvalid(crappy_string_result); |
2048 CheckStringInvalid(surrogates_string_result); | 1992 CheckStringInvalid(surrogates_string_result); |
2049 } | 1993 } |
2050 Dart_ExitScope(); | 1994 Dart_ExitScope(); |
2051 Dart_ShutdownIsolate(); | 1995 Dart_ShutdownIsolate(); |
2052 } | 1996 } |
2053 | 1997 |
2054 | |
2055 VM_UNIT_TEST_CASE(DartGeneratedListMessages) { | 1998 VM_UNIT_TEST_CASE(DartGeneratedListMessages) { |
2056 const int kArrayLength = 10; | 1999 const int kArrayLength = 10; |
2057 static const char* kScriptChars = | 2000 static const char* kScriptChars = |
2058 "final int kArrayLength = 10;\n" | 2001 "final int kArrayLength = 10;\n" |
2059 "getList() {\n" | 2002 "getList() {\n" |
2060 " return new List(kArrayLength);\n" | 2003 " return new List(kArrayLength);\n" |
2061 "}\n" | 2004 "}\n" |
2062 "getIntList() {\n" | 2005 "getIntList() {\n" |
2063 " var list = new List<int>(kArrayLength);\n" | 2006 " var list = new List<int>(kArrayLength);\n" |
2064 " for (var i = 0; i < kArrayLength; i++) list[i] = i;\n" | 2007 " for (var i = 0; i < kArrayLength; i++) list[i] = i;\n" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 if (i > 3) { | 2098 if (i > 3) { |
2156 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); | 2099 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); |
2157 } | 2100 } |
2158 } | 2101 } |
2159 } | 2102 } |
2160 } | 2103 } |
2161 Dart_ExitScope(); | 2104 Dart_ExitScope(); |
2162 Dart_ShutdownIsolate(); | 2105 Dart_ShutdownIsolate(); |
2163 } | 2106 } |
2164 | 2107 |
2165 | |
2166 VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { | 2108 VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { |
2167 const int kArrayLength = 10; | 2109 const int kArrayLength = 10; |
2168 static const char* kScriptChars = | 2110 static const char* kScriptChars = |
2169 "final int kArrayLength = 10;\n" | 2111 "final int kArrayLength = 10;\n" |
2170 "getList() {\n" | 2112 "getList() {\n" |
2171 " return [null, null, null, null, null, null, null, null, null, null];\n" | 2113 " return [null, null, null, null, null, null, null, null, null, null];\n" |
2172 "}\n" | 2114 "}\n" |
2173 "getIntList() {\n" | 2115 "getIntList() {\n" |
2174 " return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n" | 2116 " return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n" |
2175 "}\n" | 2117 "}\n" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2376 e = element->value.as_array.values[i]; | 2318 e = element->value.as_array.values[i]; |
2377 EXPECT_EQ(Dart_CObject_kInt32, e->type); | 2319 EXPECT_EQ(Dart_CObject_kInt32, e->type); |
2378 EXPECT_EQ(i + 1, e->value.as_int32); | 2320 EXPECT_EQ(i + 1, e->value.as_int32); |
2379 } | 2321 } |
2380 } | 2322 } |
2381 } | 2323 } |
2382 Dart_ExitScope(); | 2324 Dart_ExitScope(); |
2383 Dart_ShutdownIsolate(); | 2325 Dart_ShutdownIsolate(); |
2384 } | 2326 } |
2385 | 2327 |
2386 | |
2387 VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { | 2328 VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
2388 const int kArrayLength = 10; | 2329 const int kArrayLength = 10; |
2389 static const char* kScriptChars = | 2330 static const char* kScriptChars = |
2390 "import 'dart:typed_data';\n" | 2331 "import 'dart:typed_data';\n" |
2391 "final int kArrayLength = 10;\n" | 2332 "final int kArrayLength = 10;\n" |
2392 "getStringList() {\n" | 2333 "getStringList() {\n" |
2393 " var s = 'Hello, world!';\n" | 2334 " var s = 'Hello, world!';\n" |
2394 " var list = new List<String>(kArrayLength);\n" | 2335 " var list = new List<String>(kArrayLength);\n" |
2395 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n" | 2336 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n" |
2396 " return list;\n" | 2337 " return list;\n" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2596 Dart_CObject* element = root->value.as_array.values[i]; | 2537 Dart_CObject* element = root->value.as_array.values[i]; |
2597 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2538 EXPECT_EQ(Dart_CObject_kArray, element->type); |
2598 EXPECT_EQ(root, element); | 2539 EXPECT_EQ(root, element); |
2599 } | 2540 } |
2600 } | 2541 } |
2601 } | 2542 } |
2602 Dart_ExitScope(); | 2543 Dart_ExitScope(); |
2603 Dart_ShutdownIsolate(); | 2544 Dart_ShutdownIsolate(); |
2604 } | 2545 } |
2605 | 2546 |
2606 | |
2607 VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { | 2547 VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
2608 const int kArrayLength = 10; | 2548 const int kArrayLength = 10; |
2609 static const char* kScriptChars = | 2549 static const char* kScriptChars = |
2610 "import 'dart:typed_data';\n" | 2550 "import 'dart:typed_data';\n" |
2611 "final int kArrayLength = 10;\n" | 2551 "final int kArrayLength = 10;\n" |
2612 "getStringList() {\n" | 2552 "getStringList() {\n" |
2613 " var s = 'Hello, world!';\n" | 2553 " var s = 'Hello, world!';\n" |
2614 " var list = [s, s, s, s, s, s, s, s, s, s];\n" | 2554 " var list = [s, s, s, s, s, s, s, s, s, s];\n" |
2615 " return list;\n" | 2555 " return list;\n" |
2616 "}\n" | 2556 "}\n" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2823 Dart_CObject* element = root->value.as_array.values[i]; | 2763 Dart_CObject* element = root->value.as_array.values[i]; |
2824 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2764 EXPECT_EQ(Dart_CObject_kArray, element->type); |
2825 EXPECT_EQ(root, element); | 2765 EXPECT_EQ(root, element); |
2826 } | 2766 } |
2827 } | 2767 } |
2828 } | 2768 } |
2829 Dart_ExitScope(); | 2769 Dart_ExitScope(); |
2830 Dart_ShutdownIsolate(); | 2770 Dart_ShutdownIsolate(); |
2831 } | 2771 } |
2832 | 2772 |
2833 | |
2834 static void CheckTypedData(Dart_CObject* object, | 2773 static void CheckTypedData(Dart_CObject* object, |
2835 Dart_TypedData_Type typed_data_type, | 2774 Dart_TypedData_Type typed_data_type, |
2836 int len) { | 2775 int len) { |
2837 EXPECT_EQ(Dart_CObject_kTypedData, object->type); | 2776 EXPECT_EQ(Dart_CObject_kTypedData, object->type); |
2838 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); | 2777 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); |
2839 EXPECT_EQ(len, object->value.as_typed_data.length); | 2778 EXPECT_EQ(len, object->value.as_typed_data.length); |
2840 } | 2779 } |
2841 | 2780 |
2842 VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { | 2781 VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { |
2843 static const char* kScriptChars = | 2782 static const char* kScriptChars = |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3018 root->value.as_array.values[i]->value.as_typed_data.values); | 2957 root->value.as_array.values[i]->value.as_typed_data.values); |
3019 i++; | 2958 i++; |
3020 } | 2959 } |
3021 EXPECT_EQ(i, root->value.as_array.length); | 2960 EXPECT_EQ(i, root->value.as_array.length); |
3022 } | 2961 } |
3023 } | 2962 } |
3024 Dart_ExitScope(); | 2963 Dart_ExitScope(); |
3025 Dart_ShutdownIsolate(); | 2964 Dart_ShutdownIsolate(); |
3026 } | 2965 } |
3027 | 2966 |
3028 | |
3029 VM_UNIT_TEST_CASE(PostCObject) { | 2967 VM_UNIT_TEST_CASE(PostCObject) { |
3030 // Create a native port for posting from C to Dart | 2968 // Create a native port for posting from C to Dart |
3031 TestIsolateScope __test_isolate__; | 2969 TestIsolateScope __test_isolate__; |
3032 const char* kScriptChars = | 2970 const char* kScriptChars = |
3033 "import 'dart:isolate';\n" | 2971 "import 'dart:isolate';\n" |
3034 "main() {\n" | 2972 "main() {\n" |
3035 " var messageCount = 0;\n" | 2973 " var messageCount = 0;\n" |
3036 " var exception = '';\n" | 2974 " var exception = '';\n" |
3037 " var port = new RawReceivePort();\n" | 2975 " var port = new RawReceivePort();\n" |
3038 " var sendPort = port.sendPort;\n" | 2976 " var sendPort = port.sendPort;\n" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3114 | 3052 |
3115 result = Dart_RunLoop(); | 3053 result = Dart_RunLoop(); |
3116 EXPECT(Dart_IsError(result)); | 3054 EXPECT(Dart_IsError(result)); |
3117 EXPECT(Dart_ErrorHasException(result)); | 3055 EXPECT(Dart_ErrorHasException(result)); |
3118 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 3056 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
3119 Dart_GetError(result)); | 3057 Dart_GetError(result)); |
3120 | 3058 |
3121 Dart_ExitScope(); | 3059 Dart_ExitScope(); |
3122 } | 3060 } |
3123 | 3061 |
3124 | |
3125 TEST_CASE(OmittedObjectEncodingLength) { | 3062 TEST_CASE(OmittedObjectEncodingLength) { |
3126 StackZone zone(Thread::Current()); | 3063 StackZone zone(Thread::Current()); |
3127 uint8_t* buffer; | 3064 uint8_t* buffer; |
3128 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 3065 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
3129 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3066 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3130 // For performance, we'd like single-byte headers when ids are omitted. | 3067 // For performance, we'd like single-byte headers when ids are omitted. |
3131 // If this starts failing, consider renumbering the snapshot ids. | 3068 // If this starts failing, consider renumbering the snapshot ids. |
3132 EXPECT_EQ(1, writer.BytesWritten()); | 3069 EXPECT_EQ(1, writer.BytesWritten()); |
3133 } | 3070 } |
3134 | 3071 |
3135 } // namespace dart | 3072 } // namespace dart |
OLD | NEW |