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 "vm/dart_api_impl.h" |
5 #include "bin/builtin.h" | 6 #include "bin/builtin.h" |
6 #include "vm/compiler.h" | |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
12 #include "platform/text_buffer.h" | 12 #include "platform/text_buffer.h" |
13 #include "platform/utils.h" | 13 #include "platform/utils.h" |
14 #include "vm/class_finalizer.h" | 14 #include "vm/class_finalizer.h" |
15 #include "vm/dart_api_impl.h" | 15 #include "vm/compiler.h" |
16 #include "vm/dart_api_state.h" | 16 #include "vm/dart_api_state.h" |
17 #include "vm/lockers.h" | 17 #include "vm/lockers.h" |
18 #include "vm/timeline.h" | 18 #include "vm/timeline.h" |
19 #include "vm/unit_test.h" | 19 #include "vm/unit_test.h" |
20 #include "vm/verifier.h" | 20 #include "vm/verifier.h" |
21 | 21 |
22 namespace dart { | 22 namespace dart { |
23 | 23 |
24 DECLARE_FLAG(bool, verify_acquired_data); | 24 DECLARE_FLAG(bool, verify_acquired_data); |
25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); | 25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); | 58 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); |
59 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); | 59 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); |
60 EXPECT_VALID(Dart_ErrorGetException(exception)); | 60 EXPECT_VALID(Dart_ErrorGetException(exception)); |
61 | 61 |
62 EXPECT(Dart_IsError(Dart_ErrorGetStackTrace(instance))); | 62 EXPECT(Dart_IsError(Dart_ErrorGetStackTrace(instance))); |
63 EXPECT(Dart_IsError(Dart_ErrorGetStackTrace(error))); | 63 EXPECT(Dart_IsError(Dart_ErrorGetStackTrace(error))); |
64 EXPECT_VALID(Dart_ErrorGetStackTrace(exception)); | 64 EXPECT_VALID(Dart_ErrorGetStackTrace(exception)); |
65 } | 65 } |
66 | 66 |
67 | |
68 TEST_CASE(StackTraceInfo) { | 67 TEST_CASE(StackTraceInfo) { |
69 const char* kScriptChars = | 68 const char* kScriptChars = |
70 "bar() => throw new Error();\n" | 69 "bar() => throw new Error();\n" |
71 "foo() => bar();\n" | 70 "foo() => bar();\n" |
72 "testMain() => foo();\n"; | 71 "testMain() => foo();\n"; |
73 | 72 |
74 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 73 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
75 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 74 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
76 | 75 |
77 EXPECT(Dart_IsError(error)); | 76 EXPECT(Dart_IsError(error)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 EXPECT_EQ(3, line_number); | 127 EXPECT_EQ(3, line_number); |
129 EXPECT_EQ(15, column_number); | 128 EXPECT_EQ(15, column_number); |
130 | 129 |
131 // Out-of-bounds frames. | 130 // Out-of-bounds frames. |
132 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 131 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
133 EXPECT(Dart_IsError(result)); | 132 EXPECT(Dart_IsError(result)); |
134 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 133 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
135 EXPECT(Dart_IsError(result)); | 134 EXPECT(Dart_IsError(result)); |
136 } | 135 } |
137 | 136 |
138 | |
139 TEST_CASE(DeepStackTraceInfo) { | 137 TEST_CASE(DeepStackTraceInfo) { |
140 const char* kScriptChars = | 138 const char* kScriptChars = |
141 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" | 139 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" |
142 "testMain() => foo(50);\n"; | 140 "testMain() => foo(50);\n"; |
143 | 141 |
144 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 142 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
145 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 143 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
146 | 144 |
147 EXPECT(Dart_IsError(error)); | 145 EXPECT(Dart_IsError(error)); |
148 | 146 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_EQ(2, line_number); | 205 EXPECT_EQ(2, line_number); |
208 EXPECT_EQ(15, column_number); | 206 EXPECT_EQ(15, column_number); |
209 | 207 |
210 // Out-of-bounds frames. | 208 // Out-of-bounds frames. |
211 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 209 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
212 EXPECT(Dart_IsError(result)); | 210 EXPECT(Dart_IsError(result)); |
213 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 211 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
214 EXPECT(Dart_IsError(result)); | 212 EXPECT(Dart_IsError(result)); |
215 } | 213 } |
216 | 214 |
217 | |
218 TEST_CASE(StackOverflowStackTraceInfo) { | 215 TEST_CASE(StackOverflowStackTraceInfo) { |
219 const char* kScriptChars = | 216 const char* kScriptChars = |
220 "class C {\n" | 217 "class C {\n" |
221 " static foo() => foo();\n" | 218 " static foo() => foo();\n" |
222 "}\n" | 219 "}\n" |
223 "testMain() => C.foo();\n"; | 220 "testMain() => C.foo();\n"; |
224 | 221 |
225 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 222 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
226 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 223 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
227 | 224 |
(...skipping 28 matching lines...) Expand all Loading... |
256 EXPECT_EQ(2, line_number); | 253 EXPECT_EQ(2, line_number); |
257 EXPECT_EQ(13, column_number); | 254 EXPECT_EQ(13, column_number); |
258 | 255 |
259 // Out-of-bounds frames. | 256 // Out-of-bounds frames. |
260 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 257 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
261 EXPECT(Dart_IsError(result)); | 258 EXPECT(Dart_IsError(result)); |
262 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 259 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
263 EXPECT(Dart_IsError(result)); | 260 EXPECT(Dart_IsError(result)); |
264 } | 261 } |
265 | 262 |
266 | |
267 TEST_CASE(OutOfMemoryStackTraceInfo) { | 263 TEST_CASE(OutOfMemoryStackTraceInfo) { |
268 const char* kScriptChars = | 264 const char* kScriptChars = |
269 "var number_of_ints = 134000000;\n" | 265 "var number_of_ints = 134000000;\n" |
270 "testMain() {\n" | 266 "testMain() {\n" |
271 " new List<int>(number_of_ints)\n" | 267 " new List<int>(number_of_ints)\n" |
272 "}\n"; | 268 "}\n"; |
273 | 269 |
274 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 270 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
275 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 271 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
276 | 272 |
277 EXPECT(Dart_IsError(error)); | 273 EXPECT(Dart_IsError(error)); |
278 | 274 |
279 Dart_StackTrace stacktrace; | 275 Dart_StackTrace stacktrace; |
280 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); | 276 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); |
281 EXPECT(Dart_IsError(result)); // No StackTrace for OutOfMemory. | 277 EXPECT(Dart_IsError(result)); // No StackTrace for OutOfMemory. |
282 } | 278 } |
283 | 279 |
284 | |
285 void CurrentStackTraceNative(Dart_NativeArguments args) { | 280 void CurrentStackTraceNative(Dart_NativeArguments args) { |
286 Dart_EnterScope(); | 281 Dart_EnterScope(); |
287 | 282 |
288 Dart_StackTrace stacktrace; | 283 Dart_StackTrace stacktrace; |
289 Dart_Handle result = Dart_GetStackTrace(&stacktrace); | 284 Dart_Handle result = Dart_GetStackTrace(&stacktrace); |
290 EXPECT_VALID(result); | 285 EXPECT_VALID(result); |
291 | 286 |
292 intptr_t frame_count = 0; | 287 intptr_t frame_count = 0; |
293 result = Dart_StackTraceLength(stacktrace, &frame_count); | 288 result = Dart_StackTraceLength(stacktrace, &frame_count); |
294 EXPECT_VALID(result); | 289 EXPECT_VALID(result); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Out-of-bounds frames. | 357 // Out-of-bounds frames. |
363 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 358 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
364 EXPECT(Dart_IsError(result)); | 359 EXPECT(Dart_IsError(result)); |
365 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 360 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
366 EXPECT(Dart_IsError(result)); | 361 EXPECT(Dart_IsError(result)); |
367 | 362 |
368 Dart_SetReturnValue(args, Dart_NewInteger(42)); | 363 Dart_SetReturnValue(args, Dart_NewInteger(42)); |
369 Dart_ExitScope(); | 364 Dart_ExitScope(); |
370 } | 365 } |
371 | 366 |
372 | |
373 static Dart_NativeFunction CurrentStackTraceNativeLookup( | 367 static Dart_NativeFunction CurrentStackTraceNativeLookup( |
374 Dart_Handle name, | 368 Dart_Handle name, |
375 int argument_count, | 369 int argument_count, |
376 bool* auto_setup_scope) { | 370 bool* auto_setup_scope) { |
377 ASSERT(auto_setup_scope != NULL); | 371 ASSERT(auto_setup_scope != NULL); |
378 *auto_setup_scope = true; | 372 *auto_setup_scope = true; |
379 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); | 373 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); |
380 } | 374 } |
381 | 375 |
382 | |
383 TEST_CASE(CurrentStackTraceInfo) { | 376 TEST_CASE(CurrentStackTraceInfo) { |
384 const char* kScriptChars = | 377 const char* kScriptChars = |
385 "inspectStack() native 'CurrentStackTraceNatve';\n" | 378 "inspectStack() native 'CurrentStackTraceNatve';\n" |
386 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" | 379 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" |
387 "testMain() => foo(50);\n"; | 380 "testMain() => foo(50);\n"; |
388 | 381 |
389 Dart_Handle lib = | 382 Dart_Handle lib = |
390 TestCase::LoadTestScript(kScriptChars, &CurrentStackTraceNativeLookup); | 383 TestCase::LoadTestScript(kScriptChars, &CurrentStackTraceNativeLookup); |
391 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 384 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
392 EXPECT_VALID(result); | 385 EXPECT_VALID(result); |
393 EXPECT(Dart_IsInteger(result)); | 386 EXPECT(Dart_IsInteger(result)); |
394 int64_t value = 0; | 387 int64_t value = 0; |
395 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 388 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
396 EXPECT_EQ(42, value); | 389 EXPECT_EQ(42, value); |
397 } | 390 } |
398 | 391 |
399 | |
400 #endif // !PRODUCT | 392 #endif // !PRODUCT |
401 | 393 |
402 | |
403 TEST_CASE(ErrorHandleTypes) { | 394 TEST_CASE(ErrorHandleTypes) { |
404 const String& compile_message = String::Handle(String::New("CompileError")); | 395 const String& compile_message = String::Handle(String::New("CompileError")); |
405 const String& fatal_message = String::Handle(String::New("FatalError")); | 396 const String& fatal_message = String::Handle(String::New("FatalError")); |
406 | 397 |
407 Dart_Handle not_error = NewString("NotError"); | 398 Dart_Handle not_error = NewString("NotError"); |
408 Dart_Handle api_error = Api::NewError("Api%s", "Error"); | 399 Dart_Handle api_error = Api::NewError("Api%s", "Error"); |
409 Dart_Handle exception_error = | 400 Dart_Handle exception_error = |
410 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); | 401 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
411 Dart_Handle compile_error = | 402 Dart_Handle compile_error = |
412 Api::NewHandle(thread, LanguageError::New(compile_message)); | 403 Api::NewHandle(thread, LanguageError::New(compile_message)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 EXPECT(Dart_IsFatalError(fatal_error)); | 435 EXPECT(Dart_IsFatalError(fatal_error)); |
445 | 436 |
446 EXPECT_STREQ("", Dart_GetError(not_error)); | 437 EXPECT_STREQ("", Dart_GetError(not_error)); |
447 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); | 438 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); |
448 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", | 439 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", |
449 Dart_GetError(exception_error)); | 440 Dart_GetError(exception_error)); |
450 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); | 441 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); |
451 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); | 442 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); |
452 } | 443 } |
453 | 444 |
454 | |
455 TEST_CASE(UnhandleExceptionError) { | 445 TEST_CASE(UnhandleExceptionError) { |
456 const char* exception_cstr = ""; | 446 const char* exception_cstr = ""; |
457 | 447 |
458 // Test with an API Error. | 448 // Test with an API Error. |
459 const char* kApiError = "Api Error Exception Test."; | 449 const char* kApiError = "Api Error Exception Test."; |
460 Dart_Handle api_error = Api::NewHandle( | 450 Dart_Handle api_error = Api::NewHandle( |
461 thread, ApiError::New(String::Handle(String::New(kApiError)))); | 451 thread, ApiError::New(String::Handle(String::New(kApiError)))); |
462 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); | 452 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); |
463 EXPECT(!Dart_IsApiError(exception_error)); | 453 EXPECT(!Dart_IsApiError(exception_error)); |
464 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 454 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
(...skipping 29 matching lines...) Expand all Loading... |
494 Dart_Handle obj = Api::NewHandle(thread, String::New(kRegularString)); | 484 Dart_Handle obj = Api::NewHandle(thread, String::New(kRegularString)); |
495 exception_error = Dart_NewUnhandledExceptionError(obj); | 485 exception_error = Dart_NewUnhandledExceptionError(obj); |
496 EXPECT(!Dart_IsApiError(exception_error)); | 486 EXPECT(!Dart_IsApiError(exception_error)); |
497 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 487 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
498 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 488 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
499 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 489 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
500 &exception_cstr)); | 490 &exception_cstr)); |
501 EXPECT_STREQ(kRegularString, exception_cstr); | 491 EXPECT_STREQ(kRegularString, exception_cstr); |
502 } | 492 } |
503 | 493 |
504 | |
505 // Should we propagate the error via Dart_SetReturnValue? | 494 // Should we propagate the error via Dart_SetReturnValue? |
506 static bool use_set_return = false; | 495 static bool use_set_return = false; |
507 | 496 |
508 // Should we propagate the error via Dart_ThrowException? | 497 // Should we propagate the error via Dart_ThrowException? |
509 static bool use_throw_exception = false; | 498 static bool use_throw_exception = false; |
510 | 499 |
511 | |
512 void PropagateErrorNative(Dart_NativeArguments args) { | 500 void PropagateErrorNative(Dart_NativeArguments args) { |
513 Dart_Handle closure = Dart_GetNativeArgument(args, 0); | 501 Dart_Handle closure = Dart_GetNativeArgument(args, 0); |
514 EXPECT(Dart_IsClosure(closure)); | 502 EXPECT(Dart_IsClosure(closure)); |
515 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); | 503 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); |
516 EXPECT(Dart_IsError(result)); | 504 EXPECT(Dart_IsError(result)); |
517 if (use_set_return) { | 505 if (use_set_return) { |
518 Dart_SetReturnValue(args, result); | 506 Dart_SetReturnValue(args, result); |
519 } else if (use_throw_exception) { | 507 } else if (use_throw_exception) { |
520 result = Dart_ThrowException(result); | 508 result = Dart_ThrowException(result); |
521 EXPECT_VALID(result); // We do not expect to reach here. | 509 EXPECT_VALID(result); // We do not expect to reach here. |
522 UNREACHABLE(); | 510 UNREACHABLE(); |
523 } else { | 511 } else { |
524 result = Dart_PropagateError(result); | 512 result = Dart_PropagateError(result); |
525 EXPECT_VALID(result); // We do not expect to reach here. | 513 EXPECT_VALID(result); // We do not expect to reach here. |
526 UNREACHABLE(); | 514 UNREACHABLE(); |
527 } | 515 } |
528 } | 516 } |
529 | 517 |
530 | |
531 static Dart_NativeFunction PropagateError_native_lookup( | 518 static Dart_NativeFunction PropagateError_native_lookup( |
532 Dart_Handle name, | 519 Dart_Handle name, |
533 int argument_count, | 520 int argument_count, |
534 bool* auto_setup_scope) { | 521 bool* auto_setup_scope) { |
535 ASSERT(auto_setup_scope != NULL); | 522 ASSERT(auto_setup_scope != NULL); |
536 *auto_setup_scope = true; | 523 *auto_setup_scope = true; |
537 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); | 524 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); |
538 } | 525 } |
539 | 526 |
540 | |
541 TEST_CASE(Dart_PropagateError) { | 527 TEST_CASE(Dart_PropagateError) { |
542 const char* kScriptChars = | 528 const char* kScriptChars = |
543 "raiseCompileError() {\n" | 529 "raiseCompileError() {\n" |
544 " return missing_semicolon\n" | 530 " return missing_semicolon\n" |
545 "}\n" | 531 "}\n" |
546 "\n" | 532 "\n" |
547 "void throwException() {\n" | 533 "void throwException() {\n" |
548 " throw new Exception('myException');\n" | 534 " throw new Exception('myException');\n" |
549 "}\n" | 535 "}\n" |
550 "\n" | 536 "\n" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); | 580 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); |
595 EXPECT(Dart_IsError(result)); | 581 EXPECT(Dart_IsError(result)); |
596 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); | 582 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); |
597 | 583 |
598 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); | 584 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); |
599 EXPECT(Dart_IsError(result)); | 585 EXPECT(Dart_IsError(result)); |
600 EXPECT(Dart_ErrorHasException(result)); | 586 EXPECT(Dart_ErrorHasException(result)); |
601 EXPECT_SUBSTRING("myException", Dart_GetError(result)); | 587 EXPECT_SUBSTRING("myException", Dart_GetError(result)); |
602 } | 588 } |
603 | 589 |
604 | |
605 TEST_CASE(Dart_Error) { | 590 TEST_CASE(Dart_Error) { |
606 Dart_Handle error = Api::NewError("An %s", "error"); | 591 Dart_Handle error = Api::NewError("An %s", "error"); |
607 EXPECT(Dart_IsError(error)); | 592 EXPECT(Dart_IsError(error)); |
608 EXPECT_STREQ("An error", Dart_GetError(error)); | 593 EXPECT_STREQ("An error", Dart_GetError(error)); |
609 } | 594 } |
610 | 595 |
611 | |
612 TEST_CASE(Null) { | 596 TEST_CASE(Null) { |
613 Dart_Handle null = Dart_Null(); | 597 Dart_Handle null = Dart_Null(); |
614 EXPECT_VALID(null); | 598 EXPECT_VALID(null); |
615 EXPECT(Dart_IsNull(null)); | 599 EXPECT(Dart_IsNull(null)); |
616 | 600 |
617 Dart_Handle str = NewString("test"); | 601 Dart_Handle str = NewString("test"); |
618 EXPECT_VALID(str); | 602 EXPECT_VALID(str); |
619 EXPECT(!Dart_IsNull(str)); | 603 EXPECT(!Dart_IsNull(str)); |
620 } | 604 } |
621 | 605 |
622 | |
623 TEST_CASE(EmptyString) { | 606 TEST_CASE(EmptyString) { |
624 Dart_Handle empty = Dart_EmptyString(); | 607 Dart_Handle empty = Dart_EmptyString(); |
625 EXPECT_VALID(empty); | 608 EXPECT_VALID(empty); |
626 EXPECT(!Dart_IsNull(empty)); | 609 EXPECT(!Dart_IsNull(empty)); |
627 } | 610 } |
628 | 611 |
629 | |
630 TEST_CASE(IdentityEquals) { | 612 TEST_CASE(IdentityEquals) { |
631 Dart_Handle five = Dart_NewInteger(5); | 613 Dart_Handle five = Dart_NewInteger(5); |
632 Dart_Handle five_again = Dart_NewInteger(5); | 614 Dart_Handle five_again = Dart_NewInteger(5); |
633 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); | 615 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); |
634 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); | 616 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); |
635 Dart_Handle abc = NewString("abc"); | 617 Dart_Handle abc = NewString("abc"); |
636 Dart_Handle abc_again = NewString("abc"); | 618 Dart_Handle abc_again = NewString("abc"); |
637 Dart_Handle xyz = NewString("xyz"); | 619 Dart_Handle xyz = NewString("xyz"); |
638 Dart_Handle dart_core = NewString("dart:core"); | 620 Dart_Handle dart_core = NewString("dart:core"); |
639 Dart_Handle dart_mirrors = NewString("dart:mirrors"); | 621 Dart_Handle dart_mirrors = NewString("dart:mirrors"); |
(...skipping 30 matching lines...) Expand all Loading... |
670 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 652 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
671 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 653 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
672 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 654 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
673 | 655 |
674 // Mix instance and non-instance. | 656 // Mix instance and non-instance. |
675 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 657 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
676 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 658 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
677 } | 659 } |
678 } | 660 } |
679 | 661 |
680 | |
681 TEST_CASE(IdentityHash) { | 662 TEST_CASE(IdentityHash) { |
682 Dart_Handle five = Dart_NewInteger(5); | 663 Dart_Handle five = Dart_NewInteger(5); |
683 Dart_Handle five_again = Dart_NewInteger(5); | 664 Dart_Handle five_again = Dart_NewInteger(5); |
684 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); | 665 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); |
685 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); | 666 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); |
686 Dart_Handle abc = NewString("abc"); | 667 Dart_Handle abc = NewString("abc"); |
687 // Dart_Handle abc_again = NewString("abc"); | 668 // Dart_Handle abc_again = NewString("abc"); |
688 Dart_Handle xyz = NewString("xyz"); | 669 Dart_Handle xyz = NewString("xyz"); |
689 Dart_Handle dart_core = NewString("dart:core"); | 670 Dart_Handle dart_core = NewString("dart:core"); |
690 Dart_Handle dart_mirrors = NewString("dart:mirrors"); | 671 Dart_Handle dart_mirrors = NewString("dart:mirrors"); |
(...skipping 20 matching lines...) Expand all Loading... |
711 CHECK_API_SCOPE(thread); | 692 CHECK_API_SCOPE(thread); |
712 HANDLESCOPE(thread); | 693 HANDLESCOPE(thread); |
713 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 694 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
714 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 695 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
715 | 696 |
716 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); | 697 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); |
717 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); | 698 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); |
718 } | 699 } |
719 } | 700 } |
720 | 701 |
721 | |
722 TEST_CASE(ObjectEquals) { | 702 TEST_CASE(ObjectEquals) { |
723 bool equal = false; | 703 bool equal = false; |
724 Dart_Handle five = NewString("5"); | 704 Dart_Handle five = NewString("5"); |
725 Dart_Handle five_again = NewString("5"); | 705 Dart_Handle five_again = NewString("5"); |
726 Dart_Handle seven = NewString("7"); | 706 Dart_Handle seven = NewString("7"); |
727 | 707 |
728 // Same objects. | 708 // Same objects. |
729 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); | 709 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
730 EXPECT(equal); | 710 EXPECT(equal); |
731 | 711 |
732 // Equal objects. | 712 // Equal objects. |
733 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); | 713 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); |
734 EXPECT(equal); | 714 EXPECT(equal); |
735 | 715 |
736 // Different objects. | 716 // Different objects. |
737 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); | 717 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); |
738 EXPECT(!equal); | 718 EXPECT(!equal); |
739 | 719 |
740 // Case where identity is not equality. | 720 // Case where identity is not equality. |
741 Dart_Handle nan = Dart_NewDouble(NAN); | 721 Dart_Handle nan = Dart_NewDouble(NAN); |
742 EXPECT_VALID(Dart_ObjectEquals(nan, nan, &equal)); | 722 EXPECT_VALID(Dart_ObjectEquals(nan, nan, &equal)); |
743 EXPECT(!equal); | 723 EXPECT(!equal); |
744 } | 724 } |
745 | 725 |
746 | |
747 TEST_CASE(InstanceValues) { | 726 TEST_CASE(InstanceValues) { |
748 EXPECT(Dart_IsInstance(NewString("test"))); | 727 EXPECT(Dart_IsInstance(NewString("test"))); |
749 EXPECT(Dart_IsInstance(Dart_True())); | 728 EXPECT(Dart_IsInstance(Dart_True())); |
750 | 729 |
751 // By convention, our Is*() functions exclude null. | 730 // By convention, our Is*() functions exclude null. |
752 EXPECT(!Dart_IsInstance(Dart_Null())); | 731 EXPECT(!Dart_IsInstance(Dart_Null())); |
753 } | 732 } |
754 | 733 |
755 | |
756 TEST_CASE(InstanceGetType) { | 734 TEST_CASE(InstanceGetType) { |
757 Zone* zone = thread->zone(); | 735 Zone* zone = thread->zone(); |
758 // Get the handle from a valid instance handle. | 736 // Get the handle from a valid instance handle. |
759 Dart_Handle type = Dart_InstanceGetType(Dart_Null()); | 737 Dart_Handle type = Dart_InstanceGetType(Dart_Null()); |
760 EXPECT_VALID(type); | 738 EXPECT_VALID(type); |
761 EXPECT(Dart_IsType(type)); | 739 EXPECT(Dart_IsType(type)); |
762 const Type& null_type_obj = Api::UnwrapTypeHandle(zone, type); | 740 const Type& null_type_obj = Api::UnwrapTypeHandle(zone, type); |
763 EXPECT(null_type_obj.raw() == Type::NullType()); | 741 EXPECT(null_type_obj.raw() == Type::NullType()); |
764 | 742 |
765 Dart_Handle instance = Dart_True(); | 743 Dart_Handle instance = Dart_True(); |
(...skipping 22 matching lines...) Expand all Loading... |
788 | 766 |
789 // Get the handle from a non-instance handle. | 767 // Get the handle from a non-instance handle. |
790 Dart_Handle dart_core = NewString("dart:core"); | 768 Dart_Handle dart_core = NewString("dart:core"); |
791 Dart_Handle obj = Dart_LookupLibrary(dart_core); | 769 Dart_Handle obj = Dart_LookupLibrary(dart_core); |
792 Dart_Handle type_type = Dart_InstanceGetType(obj); | 770 Dart_Handle type_type = Dart_InstanceGetType(obj); |
793 EXPECT_ERROR(type_type, | 771 EXPECT_ERROR(type_type, |
794 "Dart_InstanceGetType expects argument 'instance' to be of " | 772 "Dart_InstanceGetType expects argument 'instance' to be of " |
795 "type Instance."); | 773 "type Instance."); |
796 } | 774 } |
797 | 775 |
798 | |
799 TEST_CASE(BooleanValues) { | 776 TEST_CASE(BooleanValues) { |
800 Dart_Handle str = NewString("test"); | 777 Dart_Handle str = NewString("test"); |
801 EXPECT(!Dart_IsBoolean(str)); | 778 EXPECT(!Dart_IsBoolean(str)); |
802 | 779 |
803 bool value = false; | 780 bool value = false; |
804 Dart_Handle result = Dart_BooleanValue(str, &value); | 781 Dart_Handle result = Dart_BooleanValue(str, &value); |
805 EXPECT(Dart_IsError(result)); | 782 EXPECT(Dart_IsError(result)); |
806 | 783 |
807 Dart_Handle val1 = Dart_NewBoolean(true); | 784 Dart_Handle val1 = Dart_NewBoolean(true); |
808 EXPECT(Dart_IsBoolean(val1)); | 785 EXPECT(Dart_IsBoolean(val1)); |
809 | 786 |
810 result = Dart_BooleanValue(val1, &value); | 787 result = Dart_BooleanValue(val1, &value); |
811 EXPECT_VALID(result); | 788 EXPECT_VALID(result); |
812 EXPECT(value); | 789 EXPECT(value); |
813 | 790 |
814 Dart_Handle val2 = Dart_NewBoolean(false); | 791 Dart_Handle val2 = Dart_NewBoolean(false); |
815 EXPECT(Dart_IsBoolean(val2)); | 792 EXPECT(Dart_IsBoolean(val2)); |
816 | 793 |
817 result = Dart_BooleanValue(val2, &value); | 794 result = Dart_BooleanValue(val2, &value); |
818 EXPECT_VALID(result); | 795 EXPECT_VALID(result); |
819 EXPECT(!value); | 796 EXPECT(!value); |
820 } | 797 } |
821 | 798 |
822 | |
823 TEST_CASE(BooleanConstants) { | 799 TEST_CASE(BooleanConstants) { |
824 Dart_Handle true_handle = Dart_True(); | 800 Dart_Handle true_handle = Dart_True(); |
825 EXPECT_VALID(true_handle); | 801 EXPECT_VALID(true_handle); |
826 EXPECT(Dart_IsBoolean(true_handle)); | 802 EXPECT(Dart_IsBoolean(true_handle)); |
827 | 803 |
828 bool value = false; | 804 bool value = false; |
829 Dart_Handle result = Dart_BooleanValue(true_handle, &value); | 805 Dart_Handle result = Dart_BooleanValue(true_handle, &value); |
830 EXPECT_VALID(result); | 806 EXPECT_VALID(result); |
831 EXPECT(value); | 807 EXPECT(value); |
832 | 808 |
833 Dart_Handle false_handle = Dart_False(); | 809 Dart_Handle false_handle = Dart_False(); |
834 EXPECT_VALID(false_handle); | 810 EXPECT_VALID(false_handle); |
835 EXPECT(Dart_IsBoolean(false_handle)); | 811 EXPECT(Dart_IsBoolean(false_handle)); |
836 | 812 |
837 result = Dart_BooleanValue(false_handle, &value); | 813 result = Dart_BooleanValue(false_handle, &value); |
838 EXPECT_VALID(result); | 814 EXPECT_VALID(result); |
839 EXPECT(!value); | 815 EXPECT(!value); |
840 } | 816 } |
841 | 817 |
842 | |
843 TEST_CASE(DoubleValues) { | 818 TEST_CASE(DoubleValues) { |
844 const double kDoubleVal1 = 201.29; | 819 const double kDoubleVal1 = 201.29; |
845 const double kDoubleVal2 = 101.19; | 820 const double kDoubleVal2 = 101.19; |
846 Dart_Handle val1 = Dart_NewDouble(kDoubleVal1); | 821 Dart_Handle val1 = Dart_NewDouble(kDoubleVal1); |
847 EXPECT(Dart_IsDouble(val1)); | 822 EXPECT(Dart_IsDouble(val1)); |
848 Dart_Handle val2 = Dart_NewDouble(kDoubleVal2); | 823 Dart_Handle val2 = Dart_NewDouble(kDoubleVal2); |
849 EXPECT(Dart_IsDouble(val2)); | 824 EXPECT(Dart_IsDouble(val2)); |
850 double out1, out2; | 825 double out1, out2; |
851 Dart_Handle result = Dart_DoubleValue(val1, &out1); | 826 Dart_Handle result = Dart_DoubleValue(val1, &out1); |
852 EXPECT_VALID(result); | 827 EXPECT_VALID(result); |
853 EXPECT_EQ(kDoubleVal1, out1); | 828 EXPECT_EQ(kDoubleVal1, out1); |
854 result = Dart_DoubleValue(val2, &out2); | 829 result = Dart_DoubleValue(val2, &out2); |
855 EXPECT_VALID(result); | 830 EXPECT_VALID(result); |
856 EXPECT_EQ(kDoubleVal2, out2); | 831 EXPECT_EQ(kDoubleVal2, out2); |
857 } | 832 } |
858 | 833 |
859 | |
860 TEST_CASE(NumberValues) { | 834 TEST_CASE(NumberValues) { |
861 // TODO(antonm): add various kinds of ints (smi, mint, bigint). | 835 // TODO(antonm): add various kinds of ints (smi, mint, bigint). |
862 const char* kScriptChars = | 836 const char* kScriptChars = |
863 "int getInt() { return 1; }\n" | 837 "int getInt() { return 1; }\n" |
864 "double getDouble() { return 1.0; }\n" | 838 "double getDouble() { return 1.0; }\n" |
865 "bool getBool() { return false; }\n" | 839 "bool getBool() { return false; }\n" |
866 "getNull() { return null; }\n"; | 840 "getNull() { return null; }\n"; |
867 Dart_Handle result; | 841 Dart_Handle result; |
868 // Create a test library and Load up a test script in it. | 842 // Create a test library and Load up a test script in it. |
869 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 843 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
(...skipping 12 matching lines...) Expand all Loading... |
882 result = Dart_Invoke(lib, NewString("getBool"), 0, NULL); | 856 result = Dart_Invoke(lib, NewString("getBool"), 0, NULL); |
883 EXPECT_VALID(result); | 857 EXPECT_VALID(result); |
884 EXPECT(!Dart_IsNumber(result)); | 858 EXPECT(!Dart_IsNumber(result)); |
885 | 859 |
886 // Check null case. | 860 // Check null case. |
887 result = Dart_Invoke(lib, NewString("getNull"), 0, NULL); | 861 result = Dart_Invoke(lib, NewString("getNull"), 0, NULL); |
888 EXPECT_VALID(result); | 862 EXPECT_VALID(result); |
889 EXPECT(!Dart_IsNumber(result)); | 863 EXPECT(!Dart_IsNumber(result)); |
890 } | 864 } |
891 | 865 |
892 | |
893 TEST_CASE(IntegerValues) { | 866 TEST_CASE(IntegerValues) { |
894 const int64_t kIntegerVal1 = 100; | 867 const int64_t kIntegerVal1 = 100; |
895 const int64_t kIntegerVal2 = 0xffffffff; | 868 const int64_t kIntegerVal2 = 0xffffffff; |
896 const char* kIntegerVal3 = "0x123456789123456789123456789"; | 869 const char* kIntegerVal3 = "0x123456789123456789123456789"; |
897 const uint64_t kIntegerVal4 = 0xffffffffffffffff; | 870 const uint64_t kIntegerVal4 = 0xffffffffffffffff; |
898 | 871 |
899 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); | 872 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); |
900 EXPECT(Dart_IsInteger(val1)); | 873 EXPECT(Dart_IsInteger(val1)); |
901 bool fits = false; | 874 bool fits = false; |
902 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); | 875 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 EXPECT_VALID(result); | 909 EXPECT_VALID(result); |
937 EXPECT_EQ(kIntegerVal4, out4); | 910 EXPECT_EQ(kIntegerVal4, out4); |
938 | 911 |
939 Dart_Handle val5 = Dart_NewInteger(-1); | 912 Dart_Handle val5 = Dart_NewInteger(-1); |
940 EXPECT_VALID(val5); | 913 EXPECT_VALID(val5); |
941 uint64_t out5 = 0; | 914 uint64_t out5 = 0; |
942 result = Dart_IntegerToUint64(val5, &out5); | 915 result = Dart_IntegerToUint64(val5, &out5); |
943 EXPECT(Dart_IsError(result)); | 916 EXPECT(Dart_IsError(result)); |
944 } | 917 } |
945 | 918 |
946 | |
947 TEST_CASE(IntegerFitsIntoInt64) { | 919 TEST_CASE(IntegerFitsIntoInt64) { |
948 Dart_Handle max = Dart_NewInteger(kMaxInt64); | 920 Dart_Handle max = Dart_NewInteger(kMaxInt64); |
949 EXPECT(Dart_IsInteger(max)); | 921 EXPECT(Dart_IsInteger(max)); |
950 bool fits = false; | 922 bool fits = false; |
951 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); | 923 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); |
952 EXPECT_VALID(result); | 924 EXPECT_VALID(result); |
953 EXPECT(fits); | 925 EXPECT(fits); |
954 | 926 |
955 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); | 927 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); |
956 EXPECT(Dart_IsInteger(above_max)); | 928 EXPECT(Dart_IsInteger(above_max)); |
(...skipping 10 matching lines...) Expand all Loading... |
967 EXPECT(fits); | 939 EXPECT(fits); |
968 | 940 |
969 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001"); | 941 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001"); |
970 EXPECT(Dart_IsInteger(below_min)); | 942 EXPECT(Dart_IsInteger(below_min)); |
971 fits = true; | 943 fits = true; |
972 result = Dart_IntegerFitsIntoInt64(below_min, &fits); | 944 result = Dart_IntegerFitsIntoInt64(below_min, &fits); |
973 EXPECT_VALID(result); | 945 EXPECT_VALID(result); |
974 EXPECT(!fits); | 946 EXPECT(!fits); |
975 } | 947 } |
976 | 948 |
977 | |
978 TEST_CASE(IntegerFitsIntoUint64) { | 949 TEST_CASE(IntegerFitsIntoUint64) { |
979 Dart_Handle max = Dart_NewIntegerFromUint64(kMaxUint64); | 950 Dart_Handle max = Dart_NewIntegerFromUint64(kMaxUint64); |
980 EXPECT(Dart_IsInteger(max)); | 951 EXPECT(Dart_IsInteger(max)); |
981 bool fits = false; | 952 bool fits = false; |
982 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits); | 953 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits); |
983 EXPECT_VALID(result); | 954 EXPECT_VALID(result); |
984 EXPECT(fits); | 955 EXPECT(fits); |
985 | 956 |
986 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000"); | 957 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000"); |
987 EXPECT(Dart_IsInteger(above_max)); | 958 EXPECT(Dart_IsInteger(above_max)); |
(...skipping 10 matching lines...) Expand all Loading... |
998 EXPECT(fits); | 969 EXPECT(fits); |
999 | 970 |
1000 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-1"); | 971 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-1"); |
1001 EXPECT(Dart_IsInteger(below_min)); | 972 EXPECT(Dart_IsInteger(below_min)); |
1002 fits = true; | 973 fits = true; |
1003 result = Dart_IntegerFitsIntoUint64(below_min, &fits); | 974 result = Dart_IntegerFitsIntoUint64(below_min, &fits); |
1004 EXPECT_VALID(result); | 975 EXPECT_VALID(result); |
1005 EXPECT(!fits); | 976 EXPECT(!fits); |
1006 } | 977 } |
1007 | 978 |
1008 | |
1009 TEST_CASE(ArrayValues) { | 979 TEST_CASE(ArrayValues) { |
1010 EXPECT(!Dart_IsList(Dart_Null())); | 980 EXPECT(!Dart_IsList(Dart_Null())); |
1011 const int kArrayLength = 10; | 981 const int kArrayLength = 10; |
1012 Dart_Handle str = NewString("test"); | 982 Dart_Handle str = NewString("test"); |
1013 EXPECT(!Dart_IsList(str)); | 983 EXPECT(!Dart_IsList(str)); |
1014 Dart_Handle val = Dart_NewList(kArrayLength); | 984 Dart_Handle val = Dart_NewList(kArrayLength); |
1015 EXPECT(Dart_IsList(val)); | 985 EXPECT(Dart_IsList(val)); |
1016 intptr_t len = 0; | 986 intptr_t len = 0; |
1017 Dart_Handle result = Dart_ListLength(val, &len); | 987 Dart_Handle result = Dart_ListLength(val, &len); |
1018 EXPECT_VALID(result); | 988 EXPECT_VALID(result); |
(...skipping 16 matching lines...) Expand all Loading... |
1035 for (int i = 0; i < kArrayLength; i++) { | 1005 for (int i = 0; i < kArrayLength; i++) { |
1036 result = Dart_ListGetAt(val, i); | 1006 result = Dart_ListGetAt(val, i); |
1037 EXPECT_VALID(result); | 1007 EXPECT_VALID(result); |
1038 int64_t value; | 1008 int64_t value; |
1039 result = Dart_IntegerToInt64(result, &value); | 1009 result = Dart_IntegerToInt64(result, &value); |
1040 EXPECT_VALID(result); | 1010 EXPECT_VALID(result); |
1041 EXPECT_EQ(i, value); | 1011 EXPECT_EQ(i, value); |
1042 } | 1012 } |
1043 } | 1013 } |
1044 | 1014 |
1045 | |
1046 TEST_CASE(IsString) { | 1015 TEST_CASE(IsString) { |
1047 uint8_t latin1[] = {'o', 'n', 'e', 0xC2, 0xA2}; | 1016 uint8_t latin1[] = {'o', 'n', 'e', 0xC2, 0xA2}; |
1048 | 1017 |
1049 Dart_Handle latin1str = Dart_NewStringFromUTF8(latin1, ARRAY_SIZE(latin1)); | 1018 Dart_Handle latin1str = Dart_NewStringFromUTF8(latin1, ARRAY_SIZE(latin1)); |
1050 EXPECT_VALID(latin1str); | 1019 EXPECT_VALID(latin1str); |
1051 EXPECT(Dart_IsString(latin1str)); | 1020 EXPECT(Dart_IsString(latin1str)); |
1052 EXPECT(Dart_IsStringLatin1(latin1str)); | 1021 EXPECT(Dart_IsStringLatin1(latin1str)); |
1053 EXPECT(!Dart_IsExternalString(latin1str)); | 1022 EXPECT(!Dart_IsExternalString(latin1str)); |
1054 intptr_t len = -1; | 1023 intptr_t len = -1; |
1055 EXPECT_VALID(Dart_StringLength(latin1str, &len)); | 1024 EXPECT_VALID(Dart_StringLength(latin1str, &len)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 EXPECT_EQ(data16, peer); | 1083 EXPECT_EQ(data16, peer); |
1115 | 1084 |
1116 int32_t data32[] = {'f', 'o', 'u', 'r', 0x10FFFF}; | 1085 int32_t data32[] = {'f', 'o', 'u', 'r', 0x10FFFF}; |
1117 | 1086 |
1118 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); | 1087 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); |
1119 EXPECT_VALID(str32); | 1088 EXPECT_VALID(str32); |
1120 EXPECT(Dart_IsString(str32)); | 1089 EXPECT(Dart_IsString(str32)); |
1121 EXPECT(!Dart_IsExternalString(str32)); | 1090 EXPECT(!Dart_IsExternalString(str32)); |
1122 } | 1091 } |
1123 | 1092 |
1124 | |
1125 TEST_CASE(NewString) { | 1093 TEST_CASE(NewString) { |
1126 const char* ascii = "string"; | 1094 const char* ascii = "string"; |
1127 Dart_Handle ascii_str = NewString(ascii); | 1095 Dart_Handle ascii_str = NewString(ascii); |
1128 EXPECT_VALID(ascii_str); | 1096 EXPECT_VALID(ascii_str); |
1129 EXPECT(Dart_IsString(ascii_str)); | 1097 EXPECT(Dart_IsString(ascii_str)); |
1130 | 1098 |
1131 const char* null = NULL; | 1099 const char* null = NULL; |
1132 Dart_Handle null_str = NewString(null); | 1100 Dart_Handle null_str = NewString(null); |
1133 EXPECT(Dart_IsError(null_str)); | 1101 EXPECT(Dart_IsError(null_str)); |
1134 | 1102 |
1135 uint8_t data[] = {0xE4, 0xBA, 0x8c}; // U+4E8C. | 1103 uint8_t data[] = {0xE4, 0xBA, 0x8c}; // U+4E8C. |
1136 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | 1104 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); |
1137 EXPECT_VALID(utf8_str); | 1105 EXPECT_VALID(utf8_str); |
1138 EXPECT(Dart_IsString(utf8_str)); | 1106 EXPECT(Dart_IsString(utf8_str)); |
1139 | 1107 |
1140 uint8_t invalid[] = {0xE4, 0xBA}; // underflow. | 1108 uint8_t invalid[] = {0xE4, 0xBA}; // underflow. |
1141 Dart_Handle invalid_str = | 1109 Dart_Handle invalid_str = |
1142 Dart_NewStringFromUTF8(invalid, ARRAY_SIZE(invalid)); | 1110 Dart_NewStringFromUTF8(invalid, ARRAY_SIZE(invalid)); |
1143 EXPECT(Dart_IsError(invalid_str)); | 1111 EXPECT(Dart_IsError(invalid_str)); |
1144 } | 1112 } |
1145 | 1113 |
1146 | |
1147 TEST_CASE(MalformedStringToUTF8) { | 1114 TEST_CASE(MalformedStringToUTF8) { |
1148 // 1D11E = treble clef | 1115 // 1D11E = treble clef |
1149 // [0] should be high surrogate D834 | 1116 // [0] should be high surrogate D834 |
1150 // [1] should be low surrogate DD1E | 1117 // [1] should be low surrogate DD1E |
1151 // Strings are allowed to have individual or out of order surrogates, even | 1118 // Strings are allowed to have individual or out of order surrogates, even |
1152 // if that doesn't make sense as renderable characters. | 1119 // if that doesn't make sense as renderable characters. |
1153 const char* kScriptChars = | 1120 const char* kScriptChars = |
1154 "String lowSurrogate() {" | 1121 "String lowSurrogate() {" |
1155 " return '\\u{1D11E}'[1];" | 1122 " return '\\u{1D11E}'[1];" |
1156 "}" | 1123 "}" |
(...skipping 25 matching lines...) Expand all Loading... |
1182 result = Dart_StringToUTF8(reversed, &utf8_encoded_reversed, | 1149 result = Dart_StringToUTF8(reversed, &utf8_encoded_reversed, |
1183 &utf8_length_reversed); | 1150 &utf8_length_reversed); |
1184 EXPECT_VALID(result); | 1151 EXPECT_VALID(result); |
1185 EXPECT_EQ(6, utf8_length_reversed); | 1152 EXPECT_EQ(6, utf8_length_reversed); |
1186 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; | 1153 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; |
1187 for (int i = 0; i < 6; i++) { | 1154 for (int i = 0; i < 6; i++) { |
1188 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); | 1155 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); |
1189 } | 1156 } |
1190 } | 1157 } |
1191 | 1158 |
1192 | |
1193 // Helper class to ensure new gen GC is triggered without any side effects. | 1159 // Helper class to ensure new gen GC is triggered without any side effects. |
1194 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger | 1160 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger |
1195 // an old gen collection if there is a promotion failure and this could | 1161 // an old gen collection if there is a promotion failure and this could |
1196 // perturb the test. | 1162 // perturb the test. |
1197 class GCTestHelper : public AllStatic { | 1163 class GCTestHelper : public AllStatic { |
1198 public: | 1164 public: |
1199 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { | 1165 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { |
1200 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); | 1166 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); |
1201 Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks); | 1167 Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks); |
1202 } | 1168 } |
1203 | 1169 |
1204 static void WaitForGCTasks() { | 1170 static void WaitForGCTasks() { |
1205 Thread* thread = Thread::Current(); | 1171 Thread* thread = Thread::Current(); |
1206 PageSpace* old_space = thread->isolate()->heap()->old_space(); | 1172 PageSpace* old_space = thread->isolate()->heap()->old_space(); |
1207 MonitorLocker ml(old_space->tasks_lock()); | 1173 MonitorLocker ml(old_space->tasks_lock()); |
1208 while (old_space->tasks() > 0) { | 1174 while (old_space->tasks() > 0) { |
1209 ml.WaitWithSafepointCheck(thread); | 1175 ml.WaitWithSafepointCheck(thread); |
1210 } | 1176 } |
1211 } | 1177 } |
1212 }; | 1178 }; |
1213 | 1179 |
1214 | |
1215 static void ExternalStringCallbackFinalizer(void* peer) { | 1180 static void ExternalStringCallbackFinalizer(void* peer) { |
1216 *static_cast<int*>(peer) *= 2; | 1181 *static_cast<int*>(peer) *= 2; |
1217 } | 1182 } |
1218 | 1183 |
1219 | |
1220 TEST_CASE(ExternalStringCallback) { | 1184 TEST_CASE(ExternalStringCallback) { |
1221 int peer8 = 40; | 1185 int peer8 = 40; |
1222 int peer16 = 41; | 1186 int peer16 = 41; |
1223 | 1187 |
1224 { | 1188 { |
1225 Dart_EnterScope(); | 1189 Dart_EnterScope(); |
1226 | 1190 |
1227 uint8_t data8[] = {'h', 'e', 'l', 'l', 'o'}; | 1191 uint8_t data8[] = {'h', 'e', 'l', 'l', 'o'}; |
1228 Dart_Handle obj8 = Dart_NewExternalLatin1String( | 1192 Dart_Handle obj8 = Dart_NewExternalLatin1String( |
1229 data8, ARRAY_SIZE(data8), &peer8, ExternalStringCallbackFinalizer); | 1193 data8, ARRAY_SIZE(data8), &peer8, ExternalStringCallbackFinalizer); |
(...skipping 15 matching lines...) Expand all Loading... |
1245 GCTestHelper::WaitForGCTasks(); | 1209 GCTestHelper::WaitForGCTasks(); |
1246 EXPECT_EQ(40, peer8); | 1210 EXPECT_EQ(40, peer8); |
1247 EXPECT_EQ(41, peer16); | 1211 EXPECT_EQ(41, peer16); |
1248 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1212 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
1249 GCTestHelper::WaitForGCTasks(); | 1213 GCTestHelper::WaitForGCTasks(); |
1250 EXPECT_EQ(80, peer8); | 1214 EXPECT_EQ(80, peer8); |
1251 EXPECT_EQ(82, peer16); | 1215 EXPECT_EQ(82, peer16); |
1252 } | 1216 } |
1253 } | 1217 } |
1254 | 1218 |
1255 | |
1256 TEST_CASE(ExternalStringPretenure) { | 1219 TEST_CASE(ExternalStringPretenure) { |
1257 { | 1220 { |
1258 Dart_EnterScope(); | 1221 Dart_EnterScope(); |
1259 static const uint8_t big_data8[16 * MB] = { | 1222 static const uint8_t big_data8[16 * MB] = { |
1260 0, | 1223 0, |
1261 }; | 1224 }; |
1262 Dart_Handle big8 = Dart_NewExternalLatin1String( | 1225 Dart_Handle big8 = Dart_NewExternalLatin1String( |
1263 big_data8, ARRAY_SIZE(big_data8), NULL, NULL); | 1226 big_data8, ARRAY_SIZE(big_data8), NULL, NULL); |
1264 EXPECT_VALID(big8); | 1227 EXPECT_VALID(big8); |
1265 static const uint16_t big_data16[16 * MB / 2] = { | 1228 static const uint16_t big_data16[16 * MB / 2] = { |
(...skipping 19 matching lines...) Expand all Loading... |
1285 EXPECT(handle.IsOld()); | 1248 EXPECT(handle.IsOld()); |
1286 handle ^= Api::UnwrapHandle(small8); | 1249 handle ^= Api::UnwrapHandle(small8); |
1287 EXPECT(handle.IsNew()); | 1250 EXPECT(handle.IsNew()); |
1288 handle ^= Api::UnwrapHandle(small16); | 1251 handle ^= Api::UnwrapHandle(small16); |
1289 EXPECT(handle.IsNew()); | 1252 EXPECT(handle.IsNew()); |
1290 } | 1253 } |
1291 Dart_ExitScope(); | 1254 Dart_ExitScope(); |
1292 } | 1255 } |
1293 } | 1256 } |
1294 | 1257 |
1295 | |
1296 TEST_CASE(ExternalTypedDataPretenure) { | 1258 TEST_CASE(ExternalTypedDataPretenure) { |
1297 { | 1259 { |
1298 Dart_EnterScope(); | 1260 Dart_EnterScope(); |
1299 static const int kBigLength = 16 * MB / 8; | 1261 static const int kBigLength = 16 * MB / 8; |
1300 int64_t* big_data = new int64_t[kBigLength](); | 1262 int64_t* big_data = new int64_t[kBigLength](); |
1301 Dart_Handle big = | 1263 Dart_Handle big = |
1302 Dart_NewExternalTypedData(Dart_TypedData_kInt64, big_data, kBigLength); | 1264 Dart_NewExternalTypedData(Dart_TypedData_kInt64, big_data, kBigLength); |
1303 EXPECT_VALID(big); | 1265 EXPECT_VALID(big); |
1304 static const int kSmallLength = 16 * KB / 8; | 1266 static const int kSmallLength = 16 * KB / 8; |
1305 int64_t* small_data = new int64_t[kSmallLength](); | 1267 int64_t* small_data = new int64_t[kSmallLength](); |
1306 Dart_Handle small = Dart_NewExternalTypedData(Dart_TypedData_kInt64, | 1268 Dart_Handle small = Dart_NewExternalTypedData(Dart_TypedData_kInt64, |
1307 small_data, kSmallLength); | 1269 small_data, kSmallLength); |
1308 EXPECT_VALID(small); | 1270 EXPECT_VALID(small); |
1309 { | 1271 { |
1310 CHECK_API_SCOPE(thread); | 1272 CHECK_API_SCOPE(thread); |
1311 HANDLESCOPE(thread); | 1273 HANDLESCOPE(thread); |
1312 ExternalTypedData& handle = ExternalTypedData::Handle(); | 1274 ExternalTypedData& handle = ExternalTypedData::Handle(); |
1313 handle ^= Api::UnwrapHandle(big); | 1275 handle ^= Api::UnwrapHandle(big); |
1314 EXPECT(handle.IsOld()); | 1276 EXPECT(handle.IsOld()); |
1315 handle ^= Api::UnwrapHandle(small); | 1277 handle ^= Api::UnwrapHandle(small); |
1316 EXPECT(handle.IsNew()); | 1278 EXPECT(handle.IsNew()); |
1317 } | 1279 } |
1318 Dart_ExitScope(); | 1280 Dart_ExitScope(); |
1319 delete[] big_data; | 1281 delete[] big_data; |
1320 delete[] small_data; | 1282 delete[] small_data; |
1321 } | 1283 } |
1322 } | 1284 } |
1323 | 1285 |
1324 | |
1325 TEST_CASE(ListAccess) { | 1286 TEST_CASE(ListAccess) { |
1326 const char* kScriptChars = | 1287 const char* kScriptChars = |
1327 "List testMain() {" | 1288 "List testMain() {" |
1328 " List a = new List();" | 1289 " List a = new List();" |
1329 " a.add(10);" | 1290 " a.add(10);" |
1330 " a.add(20);" | 1291 " a.add(20);" |
1331 " a.add(30);" | 1292 " a.add(30);" |
1332 " return a;" | 1293 " return a;" |
1333 "}" | 1294 "}" |
1334 "" | 1295 "" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 | 1426 |
1466 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3); | 1427 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3); |
1467 EXPECT(Dart_IsError(result)); | 1428 EXPECT(Dart_IsError(result)); |
1468 EXPECT(Dart_IsUnhandledExceptionError(result)); | 1429 EXPECT(Dart_IsUnhandledExceptionError(result)); |
1469 | 1430 |
1470 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42)); | 1431 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42)); |
1471 EXPECT(Dart_IsError(result)); | 1432 EXPECT(Dart_IsError(result)); |
1472 EXPECT(Dart_IsUnhandledExceptionError(result)); | 1433 EXPECT(Dart_IsUnhandledExceptionError(result)); |
1473 } | 1434 } |
1474 | 1435 |
1475 | |
1476 TEST_CASE(MapAccess) { | 1436 TEST_CASE(MapAccess) { |
1477 EXPECT(!Dart_IsMap(Dart_Null())); | 1437 EXPECT(!Dart_IsMap(Dart_Null())); |
1478 const char* kScriptChars = | 1438 const char* kScriptChars = |
1479 "Map testMain() {" | 1439 "Map testMain() {" |
1480 " return {" | 1440 " return {" |
1481 " 'a' : 1," | 1441 " 'a' : 1," |
1482 " 'b' : null," | 1442 " 'b' : null," |
1483 " };" | 1443 " };" |
1484 "}"; | 1444 "}"; |
1485 Dart_Handle result; | 1445 Dart_Handle result; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 | 1518 |
1559 result = Dart_ListGetAt(keys, 1); | 1519 result = Dart_ListGetAt(keys, 1); |
1560 EXPECT(Dart_IsString(result)); | 1520 EXPECT(Dart_IsString(result)); |
1561 equals = false; | 1521 equals = false; |
1562 EXPECT_VALID(Dart_ObjectEquals(result, b, &equals)); | 1522 EXPECT_VALID(Dart_ObjectEquals(result, b, &equals)); |
1563 EXPECT(equals); | 1523 EXPECT(equals); |
1564 | 1524 |
1565 EXPECT(Dart_IsError(Dart_MapKeys(a))); | 1525 EXPECT(Dart_IsError(Dart_MapKeys(a))); |
1566 } | 1526 } |
1567 | 1527 |
1568 | |
1569 TEST_CASE(IsFuture) { | 1528 TEST_CASE(IsFuture) { |
1570 const char* kScriptChars = | 1529 const char* kScriptChars = |
1571 "import 'dart:async';" | 1530 "import 'dart:async';" |
1572 "Future testMain() {" | 1531 "Future testMain() {" |
1573 " return new Completer().future;" | 1532 " return new Completer().future;" |
1574 "}"; | 1533 "}"; |
1575 Dart_Handle result; | 1534 Dart_Handle result; |
1576 | 1535 |
1577 // Create a test library and Load up a test script in it. | 1536 // Create a test library and Load up a test script in it. |
1578 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1537 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1579 | 1538 |
1580 // Invoke a function which returns an object of type Future. | 1539 // Invoke a function which returns an object of type Future. |
1581 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 1540 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
1582 EXPECT_VALID(result); | 1541 EXPECT_VALID(result); |
1583 EXPECT(Dart_IsFuture(result)); | 1542 EXPECT(Dart_IsFuture(result)); |
1584 | 1543 |
1585 EXPECT(!Dart_IsFuture(lib)); // Non-instance. | 1544 EXPECT(!Dart_IsFuture(lib)); // Non-instance. |
1586 Dart_Handle anInteger = Dart_NewInteger(0); | 1545 Dart_Handle anInteger = Dart_NewInteger(0); |
1587 EXPECT(!Dart_IsFuture(anInteger)); | 1546 EXPECT(!Dart_IsFuture(anInteger)); |
1588 Dart_Handle aString = NewString("I am not a Future"); | 1547 Dart_Handle aString = NewString("I am not a Future"); |
1589 EXPECT(!Dart_IsFuture(aString)); | 1548 EXPECT(!Dart_IsFuture(aString)); |
1590 Dart_Handle null = Dart_Null(); | 1549 Dart_Handle null = Dart_Null(); |
1591 EXPECT(!Dart_IsFuture(null)); | 1550 EXPECT(!Dart_IsFuture(null)); |
1592 } | 1551 } |
1593 | 1552 |
1594 | |
1595 TEST_CASE(TypedDataViewListGetAsBytes) { | 1553 TEST_CASE(TypedDataViewListGetAsBytes) { |
1596 const int kSize = 1000; | 1554 const int kSize = 1000; |
1597 | 1555 |
1598 const char* kScriptChars = | 1556 const char* kScriptChars = |
1599 "import 'dart:typed_data';\n" | 1557 "import 'dart:typed_data';\n" |
1600 "List main(int size) {\n" | 1558 "List main(int size) {\n" |
1601 " var a = new Int8List(size);\n" | 1559 " var a = new Int8List(size);\n" |
1602 " var view = new Int8List.view(a.buffer, 0, size);\n" | 1560 " var view = new Int8List.view(a.buffer, 0, size);\n" |
1603 " return view;\n" | 1561 " return view;\n" |
1604 "}\n"; | 1562 "}\n"; |
(...skipping 12 matching lines...) Expand all Loading... |
1617 EXPECT_VALID(Dart_ListGetAsBytes(view_obj, 0, data, kSize)); | 1575 EXPECT_VALID(Dart_ListGetAsBytes(view_obj, 0, data, kSize)); |
1618 for (intptr_t i = 0; i < kSize; ++i) { | 1576 for (intptr_t i = 0; i < kSize; ++i) { |
1619 EXPECT_EQ(i & 0xff, data[i]); | 1577 EXPECT_EQ(i & 0xff, data[i]); |
1620 } | 1578 } |
1621 | 1579 |
1622 Dart_Handle result = Dart_ListGetAsBytes(view_obj, 0, data, kSize + 1); | 1580 Dart_Handle result = Dart_ListGetAsBytes(view_obj, 0, data, kSize + 1); |
1623 EXPECT(Dart_IsError(result)); | 1581 EXPECT(Dart_IsError(result)); |
1624 delete[] data; | 1582 delete[] data; |
1625 } | 1583 } |
1626 | 1584 |
1627 | |
1628 TEST_CASE(TypedDataViewListIsTypedData) { | 1585 TEST_CASE(TypedDataViewListIsTypedData) { |
1629 const int kSize = 1000; | 1586 const int kSize = 1000; |
1630 | 1587 |
1631 const char* kScriptChars = | 1588 const char* kScriptChars = |
1632 "import 'dart:typed_data';\n" | 1589 "import 'dart:typed_data';\n" |
1633 "List main(int size) {\n" | 1590 "List main(int size) {\n" |
1634 " var a = new Int8List(size);\n" | 1591 " var a = new Int8List(size);\n" |
1635 " var view = new Int8List.view(a.buffer, 0, size);\n" | 1592 " var view = new Int8List.view(a.buffer, 0, size);\n" |
1636 " return view;\n" | 1593 " return view;\n" |
1637 "}\n"; | 1594 "}\n"; |
1638 // Create a test library and Load up a test script in it. | 1595 // Create a test library and Load up a test script in it. |
1639 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1596 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1640 | 1597 |
1641 // Create a typed data view object. | 1598 // Create a typed data view object. |
1642 Dart_Handle dart_args[1]; | 1599 Dart_Handle dart_args[1]; |
1643 dart_args[0] = Dart_NewInteger(kSize); | 1600 dart_args[0] = Dart_NewInteger(kSize); |
1644 Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args); | 1601 Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args); |
1645 EXPECT_VALID(view_obj); | 1602 EXPECT_VALID(view_obj); |
1646 // Test that the API considers it a TypedData object. | 1603 // Test that the API considers it a TypedData object. |
1647 EXPECT(Dart_IsTypedData(view_obj)); | 1604 EXPECT(Dart_IsTypedData(view_obj)); |
1648 } | 1605 } |
1649 | 1606 |
1650 | |
1651 TEST_CASE(TypedDataAccess) { | 1607 TEST_CASE(TypedDataAccess) { |
1652 EXPECT_EQ(Dart_TypedData_kInvalid, Dart_GetTypeOfTypedData(Dart_True())); | 1608 EXPECT_EQ(Dart_TypedData_kInvalid, Dart_GetTypeOfTypedData(Dart_True())); |
1653 EXPECT_EQ(Dart_TypedData_kInvalid, | 1609 EXPECT_EQ(Dart_TypedData_kInvalid, |
1654 Dart_GetTypeOfExternalTypedData(Dart_False())); | 1610 Dart_GetTypeOfExternalTypedData(Dart_False())); |
1655 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1611 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
1656 EXPECT_VALID(byte_array1); | 1612 EXPECT_VALID(byte_array1); |
1657 EXPECT_EQ(Dart_TypedData_kUint8, Dart_GetTypeOfTypedData(byte_array1)); | 1613 EXPECT_EQ(Dart_TypedData_kUint8, Dart_GetTypeOfTypedData(byte_array1)); |
1658 EXPECT_EQ(Dart_TypedData_kInvalid, | 1614 EXPECT_EQ(Dart_TypedData_kInvalid, |
1659 Dart_GetTypeOfExternalTypedData(byte_array1)); | 1615 Dart_GetTypeOfExternalTypedData(byte_array1)); |
1660 EXPECT(Dart_IsList(byte_array1)); | 1616 EXPECT(Dart_IsList(byte_array1)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 Dart_ListGetAsBytes(byte_array1, 0, data, 10); | 1670 Dart_ListGetAsBytes(byte_array1, 0, data, 10); |
1715 for (intptr_t i = 0; i < 10; ++i) { | 1671 for (intptr_t i = 0; i < 10; ++i) { |
1716 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 1672 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
1717 EXPECT_VALID(integer_obj); | 1673 EXPECT_VALID(integer_obj); |
1718 int64_t int64_t_value = -1; | 1674 int64_t int64_t_value = -1; |
1719 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 1675 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
1720 EXPECT_EQ(10 - i, int64_t_value); | 1676 EXPECT_EQ(10 - i, int64_t_value); |
1721 } | 1677 } |
1722 } | 1678 } |
1723 | 1679 |
1724 | |
1725 TEST_CASE(ByteBufferAccess) { | 1680 TEST_CASE(ByteBufferAccess) { |
1726 EXPECT(!Dart_IsByteBuffer(Dart_True())); | 1681 EXPECT(!Dart_IsByteBuffer(Dart_True())); |
1727 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1682 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
1728 EXPECT_VALID(byte_array); | 1683 EXPECT_VALID(byte_array); |
1729 // Set through the List API. | 1684 // Set through the List API. |
1730 for (intptr_t i = 0; i < 10; ++i) { | 1685 for (intptr_t i = 0; i < 10; ++i) { |
1731 EXPECT_VALID(Dart_ListSetAt(byte_array, i, Dart_NewInteger(i + 1))); | 1686 EXPECT_VALID(Dart_ListSetAt(byte_array, i, Dart_NewInteger(i + 1))); |
1732 } | 1687 } |
1733 Dart_Handle byte_buffer = Dart_NewByteBuffer(byte_array); | 1688 Dart_Handle byte_buffer = Dart_NewByteBuffer(byte_array); |
1734 EXPECT_VALID(byte_buffer); | 1689 EXPECT_VALID(byte_buffer); |
(...skipping 23 matching lines...) Expand all Loading... |
1758 result = Dart_NewByteBuffer(Dart_True()); | 1713 result = Dart_NewByteBuffer(Dart_True()); |
1759 EXPECT(Dart_IsError(result)); | 1714 EXPECT(Dart_IsError(result)); |
1760 result = Dart_NewByteBuffer(byte_buffer); | 1715 result = Dart_NewByteBuffer(byte_buffer); |
1761 EXPECT(Dart_IsError(result)); | 1716 EXPECT(Dart_IsError(result)); |
1762 result = Dart_GetDataFromByteBuffer(Dart_False()); | 1717 result = Dart_GetDataFromByteBuffer(Dart_False()); |
1763 EXPECT(Dart_IsError(result)); | 1718 EXPECT(Dart_IsError(result)); |
1764 result = Dart_GetDataFromByteBuffer(byte_array); | 1719 result = Dart_GetDataFromByteBuffer(byte_array); |
1765 EXPECT(Dart_IsError(result)); | 1720 EXPECT(Dart_IsError(result)); |
1766 } | 1721 } |
1767 | 1722 |
1768 | |
1769 static int kLength = 16; | 1723 static int kLength = 16; |
1770 | 1724 |
1771 static void ByteDataNativeFunction(Dart_NativeArguments args) { | 1725 static void ByteDataNativeFunction(Dart_NativeArguments args) { |
1772 Dart_EnterScope(); | 1726 Dart_EnterScope(); |
1773 Dart_Handle byte_data = Dart_NewTypedData(Dart_TypedData_kByteData, kLength); | 1727 Dart_Handle byte_data = Dart_NewTypedData(Dart_TypedData_kByteData, kLength); |
1774 EXPECT_VALID(byte_data); | 1728 EXPECT_VALID(byte_data); |
1775 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data)); | 1729 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data)); |
1776 Dart_SetReturnValue(args, byte_data); | 1730 Dart_SetReturnValue(args, byte_data); |
1777 Dart_ExitScope(); | 1731 Dart_ExitScope(); |
1778 } | 1732 } |
1779 | 1733 |
1780 | |
1781 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, | 1734 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, |
1782 int arg_count, | 1735 int arg_count, |
1783 bool* auto_setup_scope) { | 1736 bool* auto_setup_scope) { |
1784 ASSERT(auto_setup_scope != NULL); | 1737 ASSERT(auto_setup_scope != NULL); |
1785 *auto_setup_scope = true; | 1738 *auto_setup_scope = true; |
1786 return &ByteDataNativeFunction; | 1739 return &ByteDataNativeFunction; |
1787 } | 1740 } |
1788 | 1741 |
1789 | |
1790 TEST_CASE(ByteDataAccess) { | 1742 TEST_CASE(ByteDataAccess) { |
1791 const char* kScriptChars = | 1743 const char* kScriptChars = |
1792 "import 'dart:typed_data';\n" | 1744 "import 'dart:typed_data';\n" |
1793 "class Expect {\n" | 1745 "class Expect {\n" |
1794 " static equals(a, b) {\n" | 1746 " static equals(a, b) {\n" |
1795 " if (a != b) {\n" | 1747 " if (a != b) {\n" |
1796 " throw 'not equal. expected: $a, got: $b';\n" | 1748 " throw 'not equal. expected: $a, got: $b';\n" |
1797 " }\n" | 1749 " }\n" |
1798 " }\n" | 1750 " }\n" |
1799 "}\n" | 1751 "}\n" |
(...skipping 15 matching lines...) Expand all Loading... |
1815 | 1767 |
1816 Dart_Handle result = | 1768 Dart_Handle result = |
1817 Dart_SetNativeResolver(lib, &ByteDataNativeResolver, NULL); | 1769 Dart_SetNativeResolver(lib, &ByteDataNativeResolver, NULL); |
1818 EXPECT_VALID(result); | 1770 EXPECT_VALID(result); |
1819 | 1771 |
1820 // Invoke 'main' function. | 1772 // Invoke 'main' function. |
1821 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1773 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1822 EXPECT_VALID(result); | 1774 EXPECT_VALID(result); |
1823 } | 1775 } |
1824 | 1776 |
1825 | |
1826 static const intptr_t kExtLength = 16; | 1777 static const intptr_t kExtLength = 16; |
1827 static int8_t data[kExtLength] = { | 1778 static int8_t data[kExtLength] = { |
1828 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, | 1779 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, |
1829 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, | 1780 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, |
1830 }; | 1781 }; |
1831 | 1782 |
1832 static void ExternalByteDataNativeFunction(Dart_NativeArguments args) { | 1783 static void ExternalByteDataNativeFunction(Dart_NativeArguments args) { |
1833 Dart_EnterScope(); | 1784 Dart_EnterScope(); |
1834 Dart_Handle external_byte_data = | 1785 Dart_Handle external_byte_data = |
1835 Dart_NewExternalTypedData(Dart_TypedData_kByteData, data, 16); | 1786 Dart_NewExternalTypedData(Dart_TypedData_kByteData, data, 16); |
1836 EXPECT_VALID(external_byte_data); | 1787 EXPECT_VALID(external_byte_data); |
1837 EXPECT_EQ(Dart_TypedData_kByteData, | 1788 EXPECT_EQ(Dart_TypedData_kByteData, |
1838 Dart_GetTypeOfTypedData(external_byte_data)); | 1789 Dart_GetTypeOfTypedData(external_byte_data)); |
1839 Dart_SetReturnValue(args, external_byte_data); | 1790 Dart_SetReturnValue(args, external_byte_data); |
1840 Dart_ExitScope(); | 1791 Dart_ExitScope(); |
1841 } | 1792 } |
1842 | 1793 |
1843 | |
1844 static Dart_NativeFunction ExternalByteDataNativeResolver( | 1794 static Dart_NativeFunction ExternalByteDataNativeResolver( |
1845 Dart_Handle name, | 1795 Dart_Handle name, |
1846 int arg_count, | 1796 int arg_count, |
1847 bool* auto_setup_scope) { | 1797 bool* auto_setup_scope) { |
1848 ASSERT(auto_setup_scope != NULL); | 1798 ASSERT(auto_setup_scope != NULL); |
1849 *auto_setup_scope = true; | 1799 *auto_setup_scope = true; |
1850 return &ExternalByteDataNativeFunction; | 1800 return &ExternalByteDataNativeFunction; |
1851 } | 1801 } |
1852 | 1802 |
1853 | |
1854 TEST_CASE(ExternalByteDataAccess) { | 1803 TEST_CASE(ExternalByteDataAccess) { |
1855 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the | 1804 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the |
1856 // appropriate getter instead of the host endian format used now. | 1805 // appropriate getter instead of the host endian format used now. |
1857 const char* kScriptChars = | 1806 const char* kScriptChars = |
1858 "import 'dart:typed_data';\n" | 1807 "import 'dart:typed_data';\n" |
1859 "class Expect {\n" | 1808 "class Expect {\n" |
1860 " static equals(a, b) {\n" | 1809 " static equals(a, b) {\n" |
1861 " if (a != b) {\n" | 1810 " if (a != b) {\n" |
1862 " throw 'not equal. expected: $a, got: $b';\n" | 1811 " throw 'not equal. expected: $a, got: $b';\n" |
1863 " }\n" | 1812 " }\n" |
(...skipping 26 matching lines...) Expand all Loading... |
1890 // Invoke 'main' function. | 1839 // Invoke 'main' function. |
1891 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1840 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1892 EXPECT_VALID(result); | 1841 EXPECT_VALID(result); |
1893 | 1842 |
1894 for (intptr_t i = 0; i < kExtLength; i += 2) { | 1843 for (intptr_t i = 0; i < kExtLength; i += 2) { |
1895 EXPECT_EQ(0x24, data[i]); | 1844 EXPECT_EQ(0x24, data[i]); |
1896 EXPECT_EQ(0x28, data[i + 1]); | 1845 EXPECT_EQ(0x28, data[i + 1]); |
1897 } | 1846 } |
1898 } | 1847 } |
1899 | 1848 |
1900 | |
1901 #ifndef PRODUCT | 1849 #ifndef PRODUCT |
1902 | 1850 |
1903 | |
1904 static const intptr_t kOptExtLength = 16; | 1851 static const intptr_t kOptExtLength = 16; |
1905 static int8_t opt_data[kOptExtLength] = { | 1852 static int8_t opt_data[kOptExtLength] = { |
1906 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | 1853 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
1907 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | 1854 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
1908 }; | 1855 }; |
1909 | 1856 |
1910 static void OptExternalByteDataNativeFunction(Dart_NativeArguments args) { | 1857 static void OptExternalByteDataNativeFunction(Dart_NativeArguments args) { |
1911 Dart_EnterScope(); | 1858 Dart_EnterScope(); |
1912 Dart_Handle external_byte_data = | 1859 Dart_Handle external_byte_data = |
1913 Dart_NewExternalTypedData(Dart_TypedData_kByteData, opt_data, 16); | 1860 Dart_NewExternalTypedData(Dart_TypedData_kByteData, opt_data, 16); |
1914 EXPECT_VALID(external_byte_data); | 1861 EXPECT_VALID(external_byte_data); |
1915 EXPECT_EQ(Dart_TypedData_kByteData, | 1862 EXPECT_EQ(Dart_TypedData_kByteData, |
1916 Dart_GetTypeOfTypedData(external_byte_data)); | 1863 Dart_GetTypeOfTypedData(external_byte_data)); |
1917 Dart_SetReturnValue(args, external_byte_data); | 1864 Dart_SetReturnValue(args, external_byte_data); |
1918 Dart_ExitScope(); | 1865 Dart_ExitScope(); |
1919 } | 1866 } |
1920 | 1867 |
1921 | |
1922 static Dart_NativeFunction OptExternalByteDataNativeResolver( | 1868 static Dart_NativeFunction OptExternalByteDataNativeResolver( |
1923 Dart_Handle name, | 1869 Dart_Handle name, |
1924 int arg_count, | 1870 int arg_count, |
1925 bool* auto_setup_scope) { | 1871 bool* auto_setup_scope) { |
1926 ASSERT(auto_setup_scope != NULL); | 1872 ASSERT(auto_setup_scope != NULL); |
1927 *auto_setup_scope = true; | 1873 *auto_setup_scope = true; |
1928 return &OptExternalByteDataNativeFunction; | 1874 return &OptExternalByteDataNativeFunction; |
1929 } | 1875 } |
1930 | 1876 |
1931 | |
1932 TEST_CASE(OptimizedExternalByteDataAccess) { | 1877 TEST_CASE(OptimizedExternalByteDataAccess) { |
1933 const char* kScriptChars = | 1878 const char* kScriptChars = |
1934 "import 'dart:typed_data';\n" | 1879 "import 'dart:typed_data';\n" |
1935 "class Expect {\n" | 1880 "class Expect {\n" |
1936 " static equals(a, b) {\n" | 1881 " static equals(a, b) {\n" |
1937 " if (a != b) {\n" | 1882 " if (a != b) {\n" |
1938 " throw 'not equal. expected: $a, got: $b';\n" | 1883 " throw 'not equal. expected: $a, got: $b';\n" |
1939 " }\n" | 1884 " }\n" |
1940 " }\n" | 1885 " }\n" |
1941 "}\n" | 1886 "}\n" |
(...skipping 21 matching lines...) Expand all Loading... |
1963 EXPECT_VALID(result); | 1908 EXPECT_VALID(result); |
1964 | 1909 |
1965 // Invoke 'main' function. | 1910 // Invoke 'main' function. |
1966 int old_oct = FLAG_optimization_counter_threshold; | 1911 int old_oct = FLAG_optimization_counter_threshold; |
1967 FLAG_optimization_counter_threshold = 5; | 1912 FLAG_optimization_counter_threshold = 5; |
1968 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1913 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1969 EXPECT_VALID(result); | 1914 EXPECT_VALID(result); |
1970 FLAG_optimization_counter_threshold = old_oct; | 1915 FLAG_optimization_counter_threshold = old_oct; |
1971 } | 1916 } |
1972 | 1917 |
1973 | |
1974 #endif // !PRODUCT | 1918 #endif // !PRODUCT |
1975 | 1919 |
1976 | |
1977 static void TestTypedDataDirectAccess() { | 1920 static void TestTypedDataDirectAccess() { |
1978 Dart_Handle str = Dart_NewStringFromCString("junk"); | 1921 Dart_Handle str = Dart_NewStringFromCString("junk"); |
1979 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1922 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
1980 EXPECT_VALID(byte_array); | 1923 EXPECT_VALID(byte_array); |
1981 Dart_Handle result; | 1924 Dart_Handle result; |
1982 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL); | 1925 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL); |
1983 EXPECT_ERROR(result, | 1926 EXPECT_ERROR(result, |
1984 "Dart_TypedDataAcquireData expects argument 'type'" | 1927 "Dart_TypedDataAcquireData expects argument 'type'" |
1985 " to be non-null."); | 1928 " to be non-null."); |
1986 Dart_TypedData_Type type; | 1929 Dart_TypedData_Type type; |
(...skipping 19 matching lines...) Expand all Loading... |
2006 result = Dart_TypedDataReleaseData(Dart_Null()); | 1949 result = Dart_TypedDataReleaseData(Dart_Null()); |
2007 EXPECT_ERROR(result, | 1950 EXPECT_ERROR(result, |
2008 "Dart_TypedDataReleaseData expects argument 'object'" | 1951 "Dart_TypedDataReleaseData expects argument 'object'" |
2009 " to be non-null."); | 1952 " to be non-null."); |
2010 result = Dart_TypedDataReleaseData(str); | 1953 result = Dart_TypedDataReleaseData(str); |
2011 EXPECT_ERROR(result, | 1954 EXPECT_ERROR(result, |
2012 "Dart_TypedDataReleaseData expects argument 'object'" | 1955 "Dart_TypedDataReleaseData expects argument 'object'" |
2013 " to be of type 'TypedData'."); | 1956 " to be of type 'TypedData'."); |
2014 } | 1957 } |
2015 | 1958 |
2016 | |
2017 TEST_CASE(TypedDataDirectAccessUnverified) { | 1959 TEST_CASE(TypedDataDirectAccessUnverified) { |
2018 FLAG_verify_acquired_data = false; | 1960 FLAG_verify_acquired_data = false; |
2019 TestTypedDataDirectAccess(); | 1961 TestTypedDataDirectAccess(); |
2020 } | 1962 } |
2021 | 1963 |
2022 | |
2023 TEST_CASE(TypedDataDirectAccessVerified) { | 1964 TEST_CASE(TypedDataDirectAccessVerified) { |
2024 FLAG_verify_acquired_data = true; | 1965 FLAG_verify_acquired_data = true; |
2025 TestTypedDataDirectAccess(); | 1966 TestTypedDataDirectAccess(); |
2026 } | 1967 } |
2027 | 1968 |
2028 | |
2029 static void TestDirectAccess(Dart_Handle lib, | 1969 static void TestDirectAccess(Dart_Handle lib, |
2030 Dart_Handle array, | 1970 Dart_Handle array, |
2031 Dart_TypedData_Type expected_type, | 1971 Dart_TypedData_Type expected_type, |
2032 bool is_external) { | 1972 bool is_external) { |
2033 Dart_Handle result; | 1973 Dart_Handle result; |
2034 | 1974 |
2035 // Invoke the dart function that sets initial values. | 1975 // Invoke the dart function that sets initial values. |
2036 Dart_Handle dart_args[1]; | 1976 Dart_Handle dart_args[1]; |
2037 dart_args[0] = array; | 1977 dart_args[0] = array; |
2038 result = Dart_Invoke(lib, NewString("setMain"), 1, dart_args); | 1978 result = Dart_Invoke(lib, NewString("setMain"), 1, dart_args); |
(...skipping 30 matching lines...) Expand all Loading... |
2069 | 2009 |
2070 // Release direct access to the typed data object. | 2010 // Release direct access to the typed data object. |
2071 result = Dart_TypedDataReleaseData(array); | 2011 result = Dart_TypedDataReleaseData(array); |
2072 EXPECT_VALID(result); | 2012 EXPECT_VALID(result); |
2073 | 2013 |
2074 // Invoke the dart function in order to check the modified values. | 2014 // Invoke the dart function in order to check the modified values. |
2075 result = Dart_Invoke(lib, NewString("testMain"), 1, dart_args); | 2015 result = Dart_Invoke(lib, NewString("testMain"), 1, dart_args); |
2076 EXPECT_VALID(result); | 2016 EXPECT_VALID(result); |
2077 } | 2017 } |
2078 | 2018 |
2079 | |
2080 static void TestTypedDataDirectAccess1() { | 2019 static void TestTypedDataDirectAccess1() { |
2081 const char* kScriptChars = | 2020 const char* kScriptChars = |
2082 "import 'dart:typed_data';\n" | 2021 "import 'dart:typed_data';\n" |
2083 "class Expect {\n" | 2022 "class Expect {\n" |
2084 " static equals(a, b) {\n" | 2023 " static equals(a, b) {\n" |
2085 " if (a != b) {\n" | 2024 " if (a != b) {\n" |
2086 " throw new Exception('not equal. expected: $a, got: $b');\n" | 2025 " throw new Exception('not equal. expected: $a, got: $b');\n" |
2087 " }\n" | 2026 " }\n" |
2088 " }\n" | 2027 " }\n" |
2089 "}\n" | 2028 "}\n" |
(...skipping 24 matching lines...) Expand all Loading... |
2114 // Test with an external typed data object. | 2053 // Test with an external typed data object. |
2115 uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 2054 uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
2116 intptr_t data_length = ARRAY_SIZE(data); | 2055 intptr_t data_length = ARRAY_SIZE(data); |
2117 Dart_Handle ext_list_access_test_obj; | 2056 Dart_Handle ext_list_access_test_obj; |
2118 ext_list_access_test_obj = | 2057 ext_list_access_test_obj = |
2119 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, data_length); | 2058 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, data_length); |
2120 EXPECT_VALID(ext_list_access_test_obj); | 2059 EXPECT_VALID(ext_list_access_test_obj); |
2121 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8, true); | 2060 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8, true); |
2122 } | 2061 } |
2123 | 2062 |
2124 | |
2125 TEST_CASE(TypedDataDirectAccess1Unverified) { | 2063 TEST_CASE(TypedDataDirectAccess1Unverified) { |
2126 FLAG_verify_acquired_data = false; | 2064 FLAG_verify_acquired_data = false; |
2127 TestTypedDataDirectAccess1(); | 2065 TestTypedDataDirectAccess1(); |
2128 } | 2066 } |
2129 | 2067 |
2130 | |
2131 TEST_CASE(TypedDataDirectAccess1Verified) { | 2068 TEST_CASE(TypedDataDirectAccess1Verified) { |
2132 FLAG_verify_acquired_data = true; | 2069 FLAG_verify_acquired_data = true; |
2133 TestTypedDataDirectAccess1(); | 2070 TestTypedDataDirectAccess1(); |
2134 } | 2071 } |
2135 | 2072 |
2136 | |
2137 static void TestTypedDataViewDirectAccess() { | 2073 static void TestTypedDataViewDirectAccess() { |
2138 const char* kScriptChars = | 2074 const char* kScriptChars = |
2139 "import 'dart:typed_data';\n" | 2075 "import 'dart:typed_data';\n" |
2140 "class Expect {\n" | 2076 "class Expect {\n" |
2141 " static equals(a, b) {\n" | 2077 " static equals(a, b) {\n" |
2142 " if (a != b) {\n" | 2078 " if (a != b) {\n" |
2143 " throw 'not equal. expected: $a, got: $b';\n" | 2079 " throw 'not equal. expected: $a, got: $b';\n" |
2144 " }\n" | 2080 " }\n" |
2145 " }\n" | 2081 " }\n" |
2146 "}\n" | 2082 "}\n" |
(...skipping 18 matching lines...) Expand all Loading... |
2165 // Create a test library and Load up a test script in it. | 2101 // Create a test library and Load up a test script in it. |
2166 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2102 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2167 | 2103 |
2168 // Test with a typed data view object. | 2104 // Test with a typed data view object. |
2169 Dart_Handle list_access_test_obj; | 2105 Dart_Handle list_access_test_obj; |
2170 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2106 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2171 EXPECT_VALID(list_access_test_obj); | 2107 EXPECT_VALID(list_access_test_obj); |
2172 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false); | 2108 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false); |
2173 } | 2109 } |
2174 | 2110 |
2175 | |
2176 TEST_CASE(TypedDataViewDirectAccessUnverified) { | 2111 TEST_CASE(TypedDataViewDirectAccessUnverified) { |
2177 FLAG_verify_acquired_data = false; | 2112 FLAG_verify_acquired_data = false; |
2178 TestTypedDataViewDirectAccess(); | 2113 TestTypedDataViewDirectAccess(); |
2179 } | 2114 } |
2180 | 2115 |
2181 | |
2182 TEST_CASE(TypedDataViewDirectAccessVerified) { | 2116 TEST_CASE(TypedDataViewDirectAccessVerified) { |
2183 FLAG_verify_acquired_data = true; | 2117 FLAG_verify_acquired_data = true; |
2184 TestTypedDataViewDirectAccess(); | 2118 TestTypedDataViewDirectAccess(); |
2185 } | 2119 } |
2186 | 2120 |
2187 | |
2188 static void TestByteDataDirectAccess() { | 2121 static void TestByteDataDirectAccess() { |
2189 const char* kScriptChars = | 2122 const char* kScriptChars = |
2190 "import 'dart:typed_data';\n" | 2123 "import 'dart:typed_data';\n" |
2191 "class Expect {\n" | 2124 "class Expect {\n" |
2192 " static equals(a, b) {\n" | 2125 " static equals(a, b) {\n" |
2193 " if (a != b) {\n" | 2126 " if (a != b) {\n" |
2194 " throw 'not equal. expected: $a, got: $b';\n" | 2127 " throw 'not equal. expected: $a, got: $b';\n" |
2195 " }\n" | 2128 " }\n" |
2196 " }\n" | 2129 " }\n" |
2197 "}\n" | 2130 "}\n" |
(...skipping 18 matching lines...) Expand all Loading... |
2216 // Create a test library and Load up a test script in it. | 2149 // Create a test library and Load up a test script in it. |
2217 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2150 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2218 | 2151 |
2219 // Test with a typed data view object. | 2152 // Test with a typed data view object. |
2220 Dart_Handle list_access_test_obj; | 2153 Dart_Handle list_access_test_obj; |
2221 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2154 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2222 EXPECT_VALID(list_access_test_obj); | 2155 EXPECT_VALID(list_access_test_obj); |
2223 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData, false); | 2156 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData, false); |
2224 } | 2157 } |
2225 | 2158 |
2226 | |
2227 TEST_CASE(ByteDataDirectAccessUnverified) { | 2159 TEST_CASE(ByteDataDirectAccessUnverified) { |
2228 FLAG_verify_acquired_data = false; | 2160 FLAG_verify_acquired_data = false; |
2229 TestByteDataDirectAccess(); | 2161 TestByteDataDirectAccess(); |
2230 } | 2162 } |
2231 | 2163 |
2232 | |
2233 TEST_CASE(ByteDataDirectAccessVerified) { | 2164 TEST_CASE(ByteDataDirectAccessVerified) { |
2234 FLAG_verify_acquired_data = true; | 2165 FLAG_verify_acquired_data = true; |
2235 TestByteDataDirectAccess(); | 2166 TestByteDataDirectAccess(); |
2236 } | 2167 } |
2237 | 2168 |
2238 | |
2239 static void ExternalTypedDataAccessTests(Dart_Handle obj, | 2169 static void ExternalTypedDataAccessTests(Dart_Handle obj, |
2240 Dart_TypedData_Type expected_type, | 2170 Dart_TypedData_Type expected_type, |
2241 uint8_t data[], | 2171 uint8_t data[], |
2242 intptr_t data_length) { | 2172 intptr_t data_length) { |
2243 EXPECT_VALID(obj); | 2173 EXPECT_VALID(obj); |
2244 EXPECT_EQ(expected_type, Dart_GetTypeOfExternalTypedData(obj)); | 2174 EXPECT_EQ(expected_type, Dart_GetTypeOfExternalTypedData(obj)); |
2245 EXPECT(Dart_IsList(obj)); | 2175 EXPECT(Dart_IsList(obj)); |
2246 | 2176 |
2247 void* raw_data = NULL; | 2177 void* raw_data = NULL; |
2248 intptr_t len; | 2178 intptr_t len; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 Dart_Handle value = Dart_NewInteger(33 * i); | 2215 Dart_Handle value = Dart_NewInteger(33 * i); |
2286 EXPECT_VALID(value); | 2216 EXPECT_VALID(value); |
2287 EXPECT_VALID(Dart_ListSetAt(obj, i, value)); | 2217 EXPECT_VALID(Dart_ListSetAt(obj, i, value)); |
2288 } | 2218 } |
2289 // Read them back through the underlying array. | 2219 // Read them back through the underlying array. |
2290 for (intptr_t i = 0; i < data_length; ++i) { | 2220 for (intptr_t i = 0; i < data_length; ++i) { |
2291 EXPECT_EQ(33 * i, data[i]); | 2221 EXPECT_EQ(33 * i, data[i]); |
2292 } | 2222 } |
2293 } | 2223 } |
2294 | 2224 |
2295 | |
2296 TEST_CASE(ExternalTypedDataAccess) { | 2225 TEST_CASE(ExternalTypedDataAccess) { |
2297 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; | 2226 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; |
2298 intptr_t data_length = ARRAY_SIZE(data); | 2227 intptr_t data_length = ARRAY_SIZE(data); |
2299 | 2228 |
2300 Dart_Handle obj = | 2229 Dart_Handle obj = |
2301 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, data_length); | 2230 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, data_length); |
2302 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8, data, data_length); | 2231 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8, data, data_length); |
2303 } | 2232 } |
2304 | 2233 |
2305 | |
2306 TEST_CASE(ExternalClampedTypedDataAccess) { | 2234 TEST_CASE(ExternalClampedTypedDataAccess) { |
2307 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; | 2235 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; |
2308 intptr_t data_length = ARRAY_SIZE(data); | 2236 intptr_t data_length = ARRAY_SIZE(data); |
2309 | 2237 |
2310 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8Clamped, | 2238 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8Clamped, |
2311 data, data_length); | 2239 data, data_length); |
2312 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8Clamped, data, | 2240 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8Clamped, data, |
2313 data_length); | 2241 data_length); |
2314 } | 2242 } |
2315 | 2243 |
2316 | |
2317 TEST_CASE(ExternalUint8ClampedArrayAccess) { | 2244 TEST_CASE(ExternalUint8ClampedArrayAccess) { |
2318 const char* kScriptChars = | 2245 const char* kScriptChars = |
2319 "testClamped(List a) {\n" | 2246 "testClamped(List a) {\n" |
2320 " if (a[1] != 11) return false;\n" | 2247 " if (a[1] != 11) return false;\n" |
2321 " a[1] = 3;\n" | 2248 " a[1] = 3;\n" |
2322 " if (a[1] != 3) return false;\n" | 2249 " if (a[1] != 3) return false;\n" |
2323 " a[1] = -12;\n" | 2250 " a[1] = -12;\n" |
2324 " if (a[1] != 0) return false;\n" | 2251 " if (a[1] != 0) return false;\n" |
2325 " a[1] = 1200;\n" | 2252 " a[1] = 1200;\n" |
2326 " if (a[1] != 255) return false;\n" | 2253 " if (a[1] != 255) return false;\n" |
(...skipping 14 matching lines...) Expand all Loading... |
2341 | 2268 |
2342 // Check that result is true. | 2269 // Check that result is true. |
2343 EXPECT_VALID(result); | 2270 EXPECT_VALID(result); |
2344 EXPECT(Dart_IsBoolean(result)); | 2271 EXPECT(Dart_IsBoolean(result)); |
2345 bool value = false; | 2272 bool value = false; |
2346 result = Dart_BooleanValue(result, &value); | 2273 result = Dart_BooleanValue(result, &value); |
2347 EXPECT_VALID(result); | 2274 EXPECT_VALID(result); |
2348 EXPECT(value); | 2275 EXPECT(value); |
2349 } | 2276 } |
2350 | 2277 |
2351 | |
2352 static void NopCallback(void* isolate_callback_data, | 2278 static void NopCallback(void* isolate_callback_data, |
2353 Dart_WeakPersistentHandle handle, | 2279 Dart_WeakPersistentHandle handle, |
2354 void* peer) {} | 2280 void* peer) {} |
2355 | 2281 |
2356 | |
2357 static void UnreachedCallback(void* isolate_callback_data, | 2282 static void UnreachedCallback(void* isolate_callback_data, |
2358 Dart_WeakPersistentHandle handle, | 2283 Dart_WeakPersistentHandle handle, |
2359 void* peer) { | 2284 void* peer) { |
2360 UNREACHABLE(); | 2285 UNREACHABLE(); |
2361 } | 2286 } |
2362 | 2287 |
2363 | |
2364 static void ExternalTypedDataFinalizer(void* isolate_callback_data, | 2288 static void ExternalTypedDataFinalizer(void* isolate_callback_data, |
2365 Dart_WeakPersistentHandle handle, | 2289 Dart_WeakPersistentHandle handle, |
2366 void* peer) { | 2290 void* peer) { |
2367 *static_cast<int*>(peer) = 42; | 2291 *static_cast<int*>(peer) = 42; |
2368 } | 2292 } |
2369 | 2293 |
2370 | |
2371 TEST_CASE(ExternalTypedDataCallback) { | 2294 TEST_CASE(ExternalTypedDataCallback) { |
2372 int peer = 0; | 2295 int peer = 0; |
2373 { | 2296 { |
2374 Dart_EnterScope(); | 2297 Dart_EnterScope(); |
2375 uint8_t data[] = {1, 2, 3, 4}; | 2298 uint8_t data[] = {1, 2, 3, 4}; |
2376 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, | 2299 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, |
2377 ARRAY_SIZE(data)); | 2300 ARRAY_SIZE(data)); |
2378 Dart_NewWeakPersistentHandle(obj, &peer, sizeof(data), | 2301 Dart_NewWeakPersistentHandle(obj, &peer, sizeof(data), |
2379 ExternalTypedDataFinalizer); | 2302 ExternalTypedDataFinalizer); |
2380 EXPECT_VALID(obj); | 2303 EXPECT_VALID(obj); |
2381 Dart_ExitScope(); | 2304 Dart_ExitScope(); |
2382 } | 2305 } |
2383 { | 2306 { |
2384 TransitionNativeToVM transition(thread); | 2307 TransitionNativeToVM transition(thread); |
2385 EXPECT(peer == 0); | 2308 EXPECT(peer == 0); |
2386 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2309 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2387 GCTestHelper::WaitForGCTasks(); | 2310 GCTestHelper::WaitForGCTasks(); |
2388 EXPECT(peer == 0); | 2311 EXPECT(peer == 0); |
2389 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2312 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
2390 GCTestHelper::WaitForGCTasks(); | 2313 GCTestHelper::WaitForGCTasks(); |
2391 EXPECT(peer == 42); | 2314 EXPECT(peer == 42); |
2392 } | 2315 } |
2393 } | 2316 } |
2394 | 2317 |
2395 | |
2396 static void SlowFinalizer(void* isolate_callback_data, | 2318 static void SlowFinalizer(void* isolate_callback_data, |
2397 Dart_WeakPersistentHandle handle, | 2319 Dart_WeakPersistentHandle handle, |
2398 void* peer) { | 2320 void* peer) { |
2399 OS::Sleep(10); | 2321 OS::Sleep(10); |
2400 intptr_t* count = reinterpret_cast<intptr_t*>(peer); | 2322 intptr_t* count = reinterpret_cast<intptr_t*>(peer); |
2401 (*count)++; | 2323 (*count)++; |
2402 } | 2324 } |
2403 | 2325 |
2404 | |
2405 TEST_CASE(SlowFinalizer) { | 2326 TEST_CASE(SlowFinalizer) { |
2406 intptr_t count = 0; | 2327 intptr_t count = 0; |
2407 for (intptr_t i = 0; i < 10; i++) { | 2328 for (intptr_t i = 0; i < 10; i++) { |
2408 Dart_EnterScope(); | 2329 Dart_EnterScope(); |
2409 Dart_Handle str1 = Dart_NewStringFromCString("Live fast"); | 2330 Dart_Handle str1 = Dart_NewStringFromCString("Live fast"); |
2410 Dart_NewWeakPersistentHandle(str1, &count, 0, SlowFinalizer); | 2331 Dart_NewWeakPersistentHandle(str1, &count, 0, SlowFinalizer); |
2411 Dart_Handle str2 = Dart_NewStringFromCString("Die young"); | 2332 Dart_Handle str2 = Dart_NewStringFromCString("Die young"); |
2412 Dart_NewWeakPersistentHandle(str2, &count, 0, SlowFinalizer); | 2333 Dart_NewWeakPersistentHandle(str2, &count, 0, SlowFinalizer); |
2413 Dart_ExitScope(); | 2334 Dart_ExitScope(); |
2414 | 2335 |
2415 { | 2336 { |
2416 TransitionNativeToVM transition(thread); | 2337 TransitionNativeToVM transition(thread); |
2417 Isolate::Current()->heap()->CollectAllGarbage(); | 2338 Isolate::Current()->heap()->CollectAllGarbage(); |
2418 } | 2339 } |
2419 } | 2340 } |
2420 | 2341 |
2421 { | 2342 { |
2422 TransitionNativeToVM transition(thread); | 2343 TransitionNativeToVM transition(thread); |
2423 GCTestHelper::WaitForGCTasks(); | 2344 GCTestHelper::WaitForGCTasks(); |
2424 } | 2345 } |
2425 | 2346 |
2426 EXPECT_EQ(20, count); | 2347 EXPECT_EQ(20, count); |
2427 } | 2348 } |
2428 | 2349 |
2429 | |
2430 static void CheckFloat32x4Data(Dart_Handle obj) { | 2350 static void CheckFloat32x4Data(Dart_Handle obj) { |
2431 void* raw_data = NULL; | 2351 void* raw_data = NULL; |
2432 intptr_t len; | 2352 intptr_t len; |
2433 Dart_TypedData_Type type; | 2353 Dart_TypedData_Type type; |
2434 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); | 2354 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); |
2435 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); | 2355 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); |
2436 EXPECT_EQ(len, 10); | 2356 EXPECT_EQ(len, 10); |
2437 float* float_data = reinterpret_cast<float*>(raw_data); | 2357 float* float_data = reinterpret_cast<float*>(raw_data); |
2438 for (int i = 0; i < len * 4; i++) { | 2358 for (int i = 0; i < len * 4; i++) { |
2439 EXPECT_EQ(0.0, float_data[i]); | 2359 EXPECT_EQ(0.0, float_data[i]); |
2440 } | 2360 } |
2441 EXPECT_VALID(Dart_TypedDataReleaseData(obj)); | 2361 EXPECT_VALID(Dart_TypedDataReleaseData(obj)); |
2442 } | 2362 } |
2443 | 2363 |
2444 | |
2445 TEST_CASE(Float32x4List) { | 2364 TEST_CASE(Float32x4List) { |
2446 const char* kScriptChars = | 2365 const char* kScriptChars = |
2447 "import 'dart:typed_data';\n" | 2366 "import 'dart:typed_data';\n" |
2448 "Float32x4List float32x4() {\n" | 2367 "Float32x4List float32x4() {\n" |
2449 " return new Float32x4List(10);\n" | 2368 " return new Float32x4List(10);\n" |
2450 "}\n"; | 2369 "}\n"; |
2451 // Create a test library and Load up a test script in it. | 2370 // Create a test library and Load up a test script in it. |
2452 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2371 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2453 | 2372 |
2454 Dart_Handle obj = Dart_Invoke(lib, NewString("float32x4"), 0, NULL); | 2373 Dart_Handle obj = Dart_Invoke(lib, NewString("float32x4"), 0, NULL); |
(...skipping 21 matching lines...) Expand all Loading... |
2476 } | 2395 } |
2477 Dart_ExitScope(); | 2396 Dart_ExitScope(); |
2478 { | 2397 { |
2479 TransitionNativeToVM transition(thread); | 2398 TransitionNativeToVM transition(thread); |
2480 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2399 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
2481 GCTestHelper::WaitForGCTasks(); | 2400 GCTestHelper::WaitForGCTasks(); |
2482 EXPECT(peer == 42); | 2401 EXPECT(peer == 42); |
2483 } | 2402 } |
2484 } | 2403 } |
2485 | 2404 |
2486 | |
2487 // Unit test for entering a scope, creating a local handle and exiting | 2405 // Unit test for entering a scope, creating a local handle and exiting |
2488 // the scope. | 2406 // the scope. |
2489 VM_UNIT_TEST_CASE(EnterExitScope) { | 2407 VM_UNIT_TEST_CASE(EnterExitScope) { |
2490 TestIsolateScope __test_isolate__; | 2408 TestIsolateScope __test_isolate__; |
2491 | 2409 |
2492 Thread* thread = Thread::Current(); | 2410 Thread* thread = Thread::Current(); |
2493 EXPECT(thread != NULL); | 2411 EXPECT(thread != NULL); |
2494 ApiLocalScope* scope = thread->api_top_scope(); | 2412 ApiLocalScope* scope = thread->api_top_scope(); |
2495 Dart_EnterScope(); | 2413 Dart_EnterScope(); |
2496 { | 2414 { |
2497 EXPECT(thread->api_top_scope() != NULL); | 2415 EXPECT(thread->api_top_scope() != NULL); |
2498 HANDLESCOPE(thread); | 2416 HANDLESCOPE(thread); |
2499 const String& str1 = String::Handle(String::New("Test String")); | 2417 const String& str1 = String::Handle(String::New("Test String")); |
2500 Dart_Handle ref = Api::NewHandle(thread, str1.raw()); | 2418 Dart_Handle ref = Api::NewHandle(thread, str1.raw()); |
2501 String& str2 = String::Handle(); | 2419 String& str2 = String::Handle(); |
2502 str2 ^= Api::UnwrapHandle(ref); | 2420 str2 ^= Api::UnwrapHandle(ref); |
2503 EXPECT(str1.Equals(str2)); | 2421 EXPECT(str1.Equals(str2)); |
2504 } | 2422 } |
2505 Dart_ExitScope(); | 2423 Dart_ExitScope(); |
2506 EXPECT(scope == thread->api_top_scope()); | 2424 EXPECT(scope == thread->api_top_scope()); |
2507 } | 2425 } |
2508 | 2426 |
2509 | |
2510 // Unit test for creating and deleting persistent handles. | 2427 // Unit test for creating and deleting persistent handles. |
2511 VM_UNIT_TEST_CASE(PersistentHandles) { | 2428 VM_UNIT_TEST_CASE(PersistentHandles) { |
2512 const char* kTestString1 = "Test String1"; | 2429 const char* kTestString1 = "Test String1"; |
2513 const char* kTestString2 = "Test String2"; | 2430 const char* kTestString2 = "Test String2"; |
2514 TestCase::CreateTestIsolate(); | 2431 TestCase::CreateTestIsolate(); |
2515 Thread* thread = Thread::Current(); | 2432 Thread* thread = Thread::Current(); |
2516 Isolate* isolate = thread->isolate(); | 2433 Isolate* isolate = thread->isolate(); |
2517 EXPECT(isolate != NULL); | 2434 EXPECT(isolate != NULL); |
2518 ApiState* state = isolate->api_state(); | 2435 ApiState* state = isolate->api_state(); |
2519 EXPECT(state != NULL); | 2436 EXPECT(state != NULL); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 String& str = String::Handle(); | 2484 String& str = String::Handle(); |
2568 str ^= PersistentHandle::Cast(handles[i])->raw(); | 2485 str ^= PersistentHandle::Cast(handles[i])->raw(); |
2569 EXPECT(str.Equals(kTestString2)); | 2486 EXPECT(str.Equals(kTestString2)); |
2570 } | 2487 } |
2571 } | 2488 } |
2572 EXPECT(scope == thread->api_top_scope()); | 2489 EXPECT(scope == thread->api_top_scope()); |
2573 EXPECT_EQ(2001, state->CountPersistentHandles()); | 2490 EXPECT_EQ(2001, state->CountPersistentHandles()); |
2574 Dart_ShutdownIsolate(); | 2491 Dart_ShutdownIsolate(); |
2575 } | 2492 } |
2576 | 2493 |
2577 | |
2578 // Test that we are able to create a persistent handle from a | 2494 // Test that we are able to create a persistent handle from a |
2579 // persistent handle. | 2495 // persistent handle. |
2580 VM_UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { | 2496 VM_UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { |
2581 TestIsolateScope __test_isolate__; | 2497 TestIsolateScope __test_isolate__; |
2582 | 2498 |
2583 Isolate* isolate = Isolate::Current(); | 2499 Isolate* isolate = Isolate::Current(); |
2584 EXPECT(isolate != NULL); | 2500 EXPECT(isolate != NULL); |
2585 ApiState* state = isolate->api_state(); | 2501 ApiState* state = isolate->api_state(); |
2586 EXPECT(state != NULL); | 2502 EXPECT(state != NULL); |
2587 Thread* thread = Thread::Current(); | 2503 Thread* thread = Thread::Current(); |
(...skipping 11 matching lines...) Expand all Loading... |
2599 | 2515 |
2600 // Make sure that the value transferred. | 2516 // Make sure that the value transferred. |
2601 Dart_Handle obj4 = Dart_HandleFromPersistent(obj3); | 2517 Dart_Handle obj4 = Dart_HandleFromPersistent(obj3); |
2602 EXPECT(Dart_IsBoolean(obj4)); | 2518 EXPECT(Dart_IsBoolean(obj4)); |
2603 bool value = false; | 2519 bool value = false; |
2604 Dart_Handle result = Dart_BooleanValue(obj4, &value); | 2520 Dart_Handle result = Dart_BooleanValue(obj4, &value); |
2605 EXPECT_VALID(result); | 2521 EXPECT_VALID(result); |
2606 EXPECT(value); | 2522 EXPECT(value); |
2607 } | 2523 } |
2608 | 2524 |
2609 | |
2610 // Test that we can assign to a persistent handle. | 2525 // Test that we can assign to a persistent handle. |
2611 VM_UNIT_TEST_CASE(AssignToPersistentHandle) { | 2526 VM_UNIT_TEST_CASE(AssignToPersistentHandle) { |
2612 const char* kTestString1 = "Test String1"; | 2527 const char* kTestString1 = "Test String1"; |
2613 const char* kTestString2 = "Test String2"; | 2528 const char* kTestString2 = "Test String2"; |
2614 TestIsolateScope __test_isolate__; | 2529 TestIsolateScope __test_isolate__; |
2615 | 2530 |
2616 Thread* T = Thread::Current(); | 2531 Thread* T = Thread::Current(); |
2617 CHECK_API_SCOPE(T); | 2532 CHECK_API_SCOPE(T); |
2618 HANDLESCOPE(T); | 2533 HANDLESCOPE(T); |
2619 Isolate* isolate = T->isolate(); | 2534 Isolate* isolate = T->isolate(); |
(...skipping 13 matching lines...) Expand all Loading... |
2633 Dart_Handle ref2 = Api::NewHandle(T, String::New(kTestString2)); | 2548 Dart_Handle ref2 = Api::NewHandle(T, String::New(kTestString2)); |
2634 Dart_SetPersistentHandle(obj, ref2); | 2549 Dart_SetPersistentHandle(obj, ref2); |
2635 str ^= PersistentHandle::Cast(obj)->raw(); | 2550 str ^= PersistentHandle::Cast(obj)->raw(); |
2636 EXPECT(str.Equals(kTestString2)); | 2551 EXPECT(str.Equals(kTestString2)); |
2637 | 2552 |
2638 // Now assign Null to the persistent handle and check. | 2553 // Now assign Null to the persistent handle and check. |
2639 Dart_SetPersistentHandle(obj, Dart_Null()); | 2554 Dart_SetPersistentHandle(obj, Dart_Null()); |
2640 EXPECT(Dart_IsNull(obj)); | 2555 EXPECT(Dart_IsNull(obj)); |
2641 } | 2556 } |
2642 | 2557 |
2643 | |
2644 static Dart_Handle AsHandle(Dart_PersistentHandle weak) { | 2558 static Dart_Handle AsHandle(Dart_PersistentHandle weak) { |
2645 return Dart_HandleFromPersistent(weak); | 2559 return Dart_HandleFromPersistent(weak); |
2646 } | 2560 } |
2647 | 2561 |
2648 | |
2649 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { | 2562 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { |
2650 return Dart_HandleFromWeakPersistent(weak); | 2563 return Dart_HandleFromWeakPersistent(weak); |
2651 } | 2564 } |
2652 | 2565 |
2653 | |
2654 static Dart_WeakPersistentHandle weak_new_ref = NULL; | 2566 static Dart_WeakPersistentHandle weak_new_ref = NULL; |
2655 static Dart_WeakPersistentHandle weak_old_ref = NULL; | 2567 static Dart_WeakPersistentHandle weak_old_ref = NULL; |
2656 | 2568 |
2657 | |
2658 static void WeakPersistentHandleCallback(void* isolate_callback_data, | 2569 static void WeakPersistentHandleCallback(void* isolate_callback_data, |
2659 Dart_WeakPersistentHandle handle, | 2570 Dart_WeakPersistentHandle handle, |
2660 void* peer) { | 2571 void* peer) { |
2661 if (handle == weak_new_ref) { | 2572 if (handle == weak_new_ref) { |
2662 weak_new_ref = NULL; | 2573 weak_new_ref = NULL; |
2663 } else if (handle == weak_old_ref) { | 2574 } else if (handle == weak_old_ref) { |
2664 weak_old_ref = NULL; | 2575 weak_old_ref = NULL; |
2665 } | 2576 } |
2666 } | 2577 } |
2667 | 2578 |
2668 | |
2669 TEST_CASE(WeakPersistentHandle) { | 2579 TEST_CASE(WeakPersistentHandle) { |
2670 Dart_Handle local_new_ref = Dart_Null(); | 2580 Dart_Handle local_new_ref = Dart_Null(); |
2671 weak_new_ref = Dart_NewWeakPersistentHandle(local_new_ref, NULL, 0, | 2581 weak_new_ref = Dart_NewWeakPersistentHandle(local_new_ref, NULL, 0, |
2672 WeakPersistentHandleCallback); | 2582 WeakPersistentHandleCallback); |
2673 | 2583 |
2674 Dart_Handle local_old_ref = Dart_Null(); | 2584 Dart_Handle local_old_ref = Dart_Null(); |
2675 weak_old_ref = Dart_NewWeakPersistentHandle(local_old_ref, NULL, 0, | 2585 weak_old_ref = Dart_NewWeakPersistentHandle(local_old_ref, NULL, 0, |
2676 WeakPersistentHandleCallback); | 2586 WeakPersistentHandleCallback); |
2677 | 2587 |
2678 { | 2588 { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2779 } | 2689 } |
2780 | 2690 |
2781 { | 2691 { |
2782 TransitionNativeToVM transition(thread); | 2692 TransitionNativeToVM transition(thread); |
2783 // Garbage collect one last time to revisit deleted handles. | 2693 // Garbage collect one last time to revisit deleted handles. |
2784 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2694 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
2785 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2695 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2786 } | 2696 } |
2787 } | 2697 } |
2788 | 2698 |
2789 | |
2790 TEST_CASE(WeakPersistentHandleErrors) { | 2699 TEST_CASE(WeakPersistentHandleErrors) { |
2791 Dart_EnterScope(); | 2700 Dart_EnterScope(); |
2792 | 2701 |
2793 // NULL callback. | 2702 // NULL callback. |
2794 Dart_Handle obj1 = NewString("new string"); | 2703 Dart_Handle obj1 = NewString("new string"); |
2795 EXPECT_VALID(obj1); | 2704 EXPECT_VALID(obj1); |
2796 Dart_WeakPersistentHandle ref1 = | 2705 Dart_WeakPersistentHandle ref1 = |
2797 Dart_NewWeakPersistentHandle(obj1, NULL, 0, NULL); | 2706 Dart_NewWeakPersistentHandle(obj1, NULL, 0, NULL); |
2798 EXPECT_EQ(ref1, static_cast<void*>(NULL)); | 2707 EXPECT_EQ(ref1, static_cast<void*>(NULL)); |
2799 | 2708 |
2800 // Immediate object. | 2709 // Immediate object. |
2801 Dart_Handle obj2 = Dart_NewInteger(0); | 2710 Dart_Handle obj2 = Dart_NewInteger(0); |
2802 EXPECT_VALID(obj2); | 2711 EXPECT_VALID(obj2); |
2803 Dart_WeakPersistentHandle ref2 = | 2712 Dart_WeakPersistentHandle ref2 = |
2804 Dart_NewWeakPersistentHandle(obj2, NULL, 0, WeakPersistentHandleCallback); | 2713 Dart_NewWeakPersistentHandle(obj2, NULL, 0, WeakPersistentHandleCallback); |
2805 EXPECT_EQ(ref2, static_cast<void*>(NULL)); | 2714 EXPECT_EQ(ref2, static_cast<void*>(NULL)); |
2806 | 2715 |
2807 Dart_ExitScope(); | 2716 Dart_ExitScope(); |
2808 } | 2717 } |
2809 | 2718 |
2810 | |
2811 static void WeakPersistentHandlePeerFinalizer(void* isolate_callback_data, | 2719 static void WeakPersistentHandlePeerFinalizer(void* isolate_callback_data, |
2812 Dart_WeakPersistentHandle handle, | 2720 Dart_WeakPersistentHandle handle, |
2813 void* peer) { | 2721 void* peer) { |
2814 *static_cast<int*>(peer) = 42; | 2722 *static_cast<int*>(peer) = 42; |
2815 } | 2723 } |
2816 | 2724 |
2817 | |
2818 TEST_CASE(WeakPersistentHandleCallback) { | 2725 TEST_CASE(WeakPersistentHandleCallback) { |
2819 Dart_WeakPersistentHandle weak_ref = NULL; | 2726 Dart_WeakPersistentHandle weak_ref = NULL; |
2820 int peer = 0; | 2727 int peer = 0; |
2821 { | 2728 { |
2822 Dart_EnterScope(); | 2729 Dart_EnterScope(); |
2823 Dart_Handle obj = NewString("new string"); | 2730 Dart_Handle obj = NewString("new string"); |
2824 EXPECT_VALID(obj); | 2731 EXPECT_VALID(obj); |
2825 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2732 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
2826 WeakPersistentHandlePeerFinalizer); | 2733 WeakPersistentHandlePeerFinalizer); |
2827 EXPECT_VALID(AsHandle(weak_ref)); | 2734 EXPECT_VALID(AsHandle(weak_ref)); |
2828 EXPECT(peer == 0); | 2735 EXPECT(peer == 0); |
2829 Dart_ExitScope(); | 2736 Dart_ExitScope(); |
2830 } | 2737 } |
2831 { | 2738 { |
2832 TransitionNativeToVM transition(thread); | 2739 TransitionNativeToVM transition(thread); |
2833 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2740 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2834 EXPECT(peer == 0); | 2741 EXPECT(peer == 0); |
2835 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2742 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
2836 GCTestHelper::WaitForGCTasks(); | 2743 GCTestHelper::WaitForGCTasks(); |
2837 EXPECT(peer == 42); | 2744 EXPECT(peer == 42); |
2838 } | 2745 } |
2839 } | 2746 } |
2840 | 2747 |
2841 | |
2842 TEST_CASE(WeakPersistentHandleNoCallback) { | 2748 TEST_CASE(WeakPersistentHandleNoCallback) { |
2843 Dart_WeakPersistentHandle weak_ref = NULL; | 2749 Dart_WeakPersistentHandle weak_ref = NULL; |
2844 int peer = 0; | 2750 int peer = 0; |
2845 { | 2751 { |
2846 Dart_EnterScope(); | 2752 Dart_EnterScope(); |
2847 Dart_Handle obj = NewString("new string"); | 2753 Dart_Handle obj = NewString("new string"); |
2848 EXPECT_VALID(obj); | 2754 EXPECT_VALID(obj); |
2849 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2755 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
2850 WeakPersistentHandlePeerFinalizer); | 2756 WeakPersistentHandlePeerFinalizer); |
2851 Dart_ExitScope(); | 2757 Dart_ExitScope(); |
2852 } | 2758 } |
2853 // A finalizer is not invoked on a deleted handle. Therefore, the | 2759 // A finalizer is not invoked on a deleted handle. Therefore, the |
2854 // peer value should not change after the referent is collected. | 2760 // peer value should not change after the referent is collected. |
2855 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2761 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2856 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); | 2762 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); |
2857 EXPECT(peer == 0); | 2763 EXPECT(peer == 0); |
2858 { | 2764 { |
2859 TransitionNativeToVM transition(thread); | 2765 TransitionNativeToVM transition(thread); |
2860 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2766 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2861 EXPECT(peer == 0); | 2767 EXPECT(peer == 0); |
2862 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2768 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
2863 GCTestHelper::WaitForGCTasks(); | 2769 GCTestHelper::WaitForGCTasks(); |
2864 EXPECT(peer == 0); | 2770 EXPECT(peer == 0); |
2865 } | 2771 } |
2866 } | 2772 } |
2867 | 2773 |
2868 | |
2869 VM_UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { | 2774 VM_UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { |
2870 TestCase::CreateTestIsolate(); | 2775 TestCase::CreateTestIsolate(); |
2871 Dart_EnterScope(); | 2776 Dart_EnterScope(); |
2872 Dart_Handle ref = Dart_True(); | 2777 Dart_Handle ref = Dart_True(); |
2873 int peer = 1234; | 2778 int peer = 1234; |
2874 Dart_NewWeakPersistentHandle(ref, &peer, 0, | 2779 Dart_NewWeakPersistentHandle(ref, &peer, 0, |
2875 WeakPersistentHandlePeerFinalizer); | 2780 WeakPersistentHandlePeerFinalizer); |
2876 Dart_ExitScope(); | 2781 Dart_ExitScope(); |
2877 Dart_ShutdownIsolate(); | 2782 Dart_ShutdownIsolate(); |
2878 EXPECT(peer == 42); | 2783 EXPECT(peer == 42); |
2879 } | 2784 } |
2880 | 2785 |
2881 | |
2882 TEST_CASE(WeakPersistentHandleExternalAllocationSize) { | 2786 TEST_CASE(WeakPersistentHandleExternalAllocationSize) { |
2883 Heap* heap = Isolate::Current()->heap(); | 2787 Heap* heap = Isolate::Current()->heap(); |
2884 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2788 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
2885 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2789 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
2886 Dart_WeakPersistentHandle weak1 = NULL; | 2790 Dart_WeakPersistentHandle weak1 = NULL; |
2887 static const intptr_t kWeak1ExternalSize = 1 * KB; | 2791 static const intptr_t kWeak1ExternalSize = 1 * KB; |
2888 { | 2792 { |
2889 Dart_EnterScope(); | 2793 Dart_EnterScope(); |
2890 Dart_Handle obj = NewString("weakly referenced string"); | 2794 Dart_Handle obj = NewString("weakly referenced string"); |
2891 EXPECT_VALID(obj); | 2795 EXPECT_VALID(obj); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2924 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2828 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
2925 Dart_DeletePersistentHandle(strong_ref); | 2829 Dart_DeletePersistentHandle(strong_ref); |
2926 { | 2830 { |
2927 TransitionNativeToVM transition(thread); | 2831 TransitionNativeToVM transition(thread); |
2928 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2832 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2929 GCTestHelper::WaitForGCTasks(); | 2833 GCTestHelper::WaitForGCTasks(); |
2930 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2834 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
2931 } | 2835 } |
2932 } | 2836 } |
2933 | 2837 |
2934 | |
2935 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { | 2838 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { |
2936 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2839 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2937 Heap* heap = Isolate::Current()->heap(); | 2840 Heap* heap = Isolate::Current()->heap(); |
2938 Dart_WeakPersistentHandle weak1 = NULL; | 2841 Dart_WeakPersistentHandle weak1 = NULL; |
2939 // Large enough to exceed any new space limit. Not actually allocated. | 2842 // Large enough to exceed any new space limit. Not actually allocated. |
2940 const intptr_t kWeak1ExternalSize = 500 * MB; | 2843 const intptr_t kWeak1ExternalSize = 500 * MB; |
2941 { | 2844 { |
2942 Dart_EnterScope(); | 2845 Dart_EnterScope(); |
2943 Dart_Handle obj = NewString("weakly referenced string"); | 2846 Dart_Handle obj = NewString("weakly referenced string"); |
2944 EXPECT_VALID(obj); | 2847 EXPECT_VALID(obj); |
(...skipping 23 matching lines...) Expand all Loading... |
2968 } | 2871 } |
2969 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2872 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
2970 { | 2873 { |
2971 TransitionNativeToVM transition(thread); | 2874 TransitionNativeToVM transition(thread); |
2972 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2875 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2973 GCTestHelper::WaitForGCTasks(); | 2876 GCTestHelper::WaitForGCTasks(); |
2974 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2877 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
2975 } | 2878 } |
2976 } | 2879 } |
2977 | 2880 |
2978 | |
2979 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { | 2881 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { |
2980 // Check that external allocation in old space can trigger GC. | 2882 // Check that external allocation in old space can trigger GC. |
2981 Isolate* isolate = Isolate::Current(); | 2883 Isolate* isolate = Isolate::Current(); |
2982 Dart_EnterScope(); | 2884 Dart_EnterScope(); |
2983 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); | 2885 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); |
2984 EXPECT_VALID(live); | 2886 EXPECT_VALID(live); |
2985 Dart_WeakPersistentHandle weak = NULL; | 2887 Dart_WeakPersistentHandle weak = NULL; |
2986 EXPECT_EQ(0, isolate->heap()->ExternalInWords(Heap::kOld)); | 2888 EXPECT_EQ(0, isolate->heap()->ExternalInWords(Heap::kOld)); |
2987 const intptr_t kSmallExternalSize = 1 * KB; | 2889 const intptr_t kSmallExternalSize = 1 * KB; |
2988 { | 2890 { |
2989 Dart_EnterScope(); | 2891 Dart_EnterScope(); |
2990 Dart_Handle dead = Api::NewHandle(thread, String::New("dead", Heap::kOld)); | 2892 Dart_Handle dead = Api::NewHandle(thread, String::New("dead", Heap::kOld)); |
2991 EXPECT_VALID(dead); | 2893 EXPECT_VALID(dead); |
2992 weak = Dart_NewWeakPersistentHandle(dead, NULL, kSmallExternalSize, | 2894 weak = Dart_NewWeakPersistentHandle(dead, NULL, kSmallExternalSize, |
2993 NopCallback); | 2895 NopCallback); |
2994 EXPECT_VALID(AsHandle(weak)); | 2896 EXPECT_VALID(AsHandle(weak)); |
2995 Dart_ExitScope(); | 2897 Dart_ExitScope(); |
2996 } | 2898 } |
2997 EXPECT_EQ(kSmallExternalSize, | 2899 EXPECT_EQ(kSmallExternalSize, |
2998 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); | 2900 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); |
2999 // Large enough to trigger GC in old space. Not actually allocated. | 2901 // Large enough to trigger GC in old space. Not actually allocated. |
3000 const intptr_t kHugeExternalSize = (kWordSize == 4) ? 513 * MB : 1025 * MB; | 2902 const intptr_t kHugeExternalSize = (kWordSize == 4) ? 513 * MB : 1025 * MB; |
3001 Dart_NewWeakPersistentHandle(live, NULL, kHugeExternalSize, NopCallback); | 2903 Dart_NewWeakPersistentHandle(live, NULL, kHugeExternalSize, NopCallback); |
3002 // Expect small garbage to be collected. | 2904 // Expect small garbage to be collected. |
3003 EXPECT_EQ(kHugeExternalSize, | 2905 EXPECT_EQ(kHugeExternalSize, |
3004 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); | 2906 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); |
3005 Dart_ExitScope(); | 2907 Dart_ExitScope(); |
3006 } | 2908 } |
3007 | 2909 |
3008 | |
3009 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { | 2910 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { |
3010 Heap* heap = Isolate::Current()->heap(); | 2911 Heap* heap = Isolate::Current()->heap(); |
3011 Dart_WeakPersistentHandle weak1 = NULL; | 2912 Dart_WeakPersistentHandle weak1 = NULL; |
3012 static const intptr_t kWeak1ExternalSize = 1 * KB; | 2913 static const intptr_t kWeak1ExternalSize = 1 * KB; |
3013 Dart_WeakPersistentHandle weak2 = NULL; | 2914 Dart_WeakPersistentHandle weak2 = NULL; |
3014 static const intptr_t kWeak2ExternalSize = 2 * KB; | 2915 static const intptr_t kWeak2ExternalSize = 2 * KB; |
3015 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); | 2916 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); |
3016 { | 2917 { |
3017 Dart_EnterScope(); | 2918 Dart_EnterScope(); |
3018 Dart_Handle dart_true = Dart_True(); // VM heap object. | 2919 Dart_Handle dart_true = Dart_True(); // VM heap object. |
(...skipping 15 matching lines...) Expand all Loading... |
3034 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2935 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
3035 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2936 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
3036 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); | 2937 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); |
3037 { | 2938 { |
3038 TransitionNativeToVM transition(thread); | 2939 TransitionNativeToVM transition(thread); |
3039 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2940 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3040 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); | 2941 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); |
3041 } | 2942 } |
3042 } | 2943 } |
3043 | 2944 |
3044 | |
3045 static Dart_WeakPersistentHandle weak1 = NULL; | 2945 static Dart_WeakPersistentHandle weak1 = NULL; |
3046 static Dart_WeakPersistentHandle weak2 = NULL; | 2946 static Dart_WeakPersistentHandle weak2 = NULL; |
3047 static Dart_WeakPersistentHandle weak3 = NULL; | 2947 static Dart_WeakPersistentHandle weak3 = NULL; |
3048 | 2948 |
3049 | |
3050 static void ImplicitReferencesCallback(void* isolate_callback_data, | 2949 static void ImplicitReferencesCallback(void* isolate_callback_data, |
3051 Dart_WeakPersistentHandle handle, | 2950 Dart_WeakPersistentHandle handle, |
3052 void* peer) { | 2951 void* peer) { |
3053 if (handle == weak1) { | 2952 if (handle == weak1) { |
3054 weak1 = NULL; | 2953 weak1 = NULL; |
3055 } else if (handle == weak2) { | 2954 } else if (handle == weak2) { |
3056 weak2 = NULL; | 2955 weak2 = NULL; |
3057 } else if (handle == weak3) { | 2956 } else if (handle == weak3) { |
3058 weak3 = NULL; | 2957 weak3 = NULL; |
3059 } | 2958 } |
3060 } | 2959 } |
3061 | 2960 |
3062 | |
3063 TEST_CASE(ImplicitReferencesOldSpace) { | 2961 TEST_CASE(ImplicitReferencesOldSpace) { |
3064 Dart_PersistentHandle strong = NULL; | 2962 Dart_PersistentHandle strong = NULL; |
3065 Dart_WeakPersistentHandle strong_weak = NULL; | 2963 Dart_WeakPersistentHandle strong_weak = NULL; |
3066 | 2964 |
3067 Dart_EnterScope(); | 2965 Dart_EnterScope(); |
3068 { | 2966 { |
3069 CHECK_API_SCOPE(thread); | 2967 CHECK_API_SCOPE(thread); |
3070 HANDLESCOPE(thread); | 2968 HANDLESCOPE(thread); |
3071 | 2969 |
3072 Dart_Handle local = | 2970 Dart_Handle local = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3118 Dart_EnterScope(); | 3016 Dart_EnterScope(); |
3119 // New space collection should not affect old space objects | 3017 // New space collection should not affect old space objects |
3120 EXPECT_VALID(AsHandle(strong_weak)); | 3018 EXPECT_VALID(AsHandle(strong_weak)); |
3121 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 3019 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
3122 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3020 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
3123 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3021 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
3124 Dart_ExitScope(); | 3022 Dart_ExitScope(); |
3125 } | 3023 } |
3126 } | 3024 } |
3127 | 3025 |
3128 | |
3129 TEST_CASE(ImplicitReferencesNewSpace) { | 3026 TEST_CASE(ImplicitReferencesNewSpace) { |
3130 Dart_PersistentHandle strong = NULL; | 3027 Dart_PersistentHandle strong = NULL; |
3131 Dart_WeakPersistentHandle strong_weak = NULL; | 3028 Dart_WeakPersistentHandle strong_weak = NULL; |
3132 | 3029 |
3133 | |
3134 Dart_EnterScope(); | 3030 Dart_EnterScope(); |
3135 { | 3031 { |
3136 CHECK_API_SCOPE(thread); | 3032 CHECK_API_SCOPE(thread); |
3137 HANDLESCOPE(thread); | 3033 HANDLESCOPE(thread); |
3138 | 3034 |
3139 Dart_Handle local = | 3035 Dart_Handle local = |
3140 Api::NewHandle(thread, String::New("strongly reachable", Heap::kOld)); | 3036 Api::NewHandle(thread, String::New("strongly reachable", Heap::kOld)); |
3141 strong = Dart_NewPersistentHandle(local); | 3037 strong = Dart_NewPersistentHandle(local); |
3142 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3038 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
3143 | 3039 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3184 { | 3080 { |
3185 Dart_EnterScope(); | 3081 Dart_EnterScope(); |
3186 // Old space collection should not affect old space objects. | 3082 // Old space collection should not affect old space objects. |
3187 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 3083 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
3188 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3084 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
3189 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3085 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
3190 Dart_ExitScope(); | 3086 Dart_ExitScope(); |
3191 } | 3087 } |
3192 } | 3088 } |
3193 | 3089 |
3194 | |
3195 static int global_prologue_callback_status; | 3090 static int global_prologue_callback_status; |
3196 | 3091 |
3197 | |
3198 static void PrologueCallbackTimes2() { | 3092 static void PrologueCallbackTimes2() { |
3199 global_prologue_callback_status *= 2; | 3093 global_prologue_callback_status *= 2; |
3200 } | 3094 } |
3201 | 3095 |
3202 | |
3203 static void PrologueCallbackTimes3() { | 3096 static void PrologueCallbackTimes3() { |
3204 global_prologue_callback_status *= 3; | 3097 global_prologue_callback_status *= 3; |
3205 } | 3098 } |
3206 | 3099 |
3207 | |
3208 static int global_epilogue_callback_status; | 3100 static int global_epilogue_callback_status; |
3209 | 3101 |
3210 | |
3211 static void EpilogueCallbackNOP() {} | 3102 static void EpilogueCallbackNOP() {} |
3212 | 3103 |
3213 | |
3214 static void EpilogueCallbackTimes4() { | 3104 static void EpilogueCallbackTimes4() { |
3215 global_epilogue_callback_status *= 4; | 3105 global_epilogue_callback_status *= 4; |
3216 } | 3106 } |
3217 | 3107 |
3218 | |
3219 static void EpilogueCallbackTimes5() { | 3108 static void EpilogueCallbackTimes5() { |
3220 global_epilogue_callback_status *= 5; | 3109 global_epilogue_callback_status *= 5; |
3221 } | 3110 } |
3222 | 3111 |
3223 | |
3224 TEST_CASE(SetGarbageCollectionCallbacks) { | 3112 TEST_CASE(SetGarbageCollectionCallbacks) { |
3225 // GC callback addition testing. | 3113 // GC callback addition testing. |
3226 | 3114 |
3227 // Add GC callbacks. | 3115 // Add GC callbacks. |
3228 EXPECT_VALID( | 3116 EXPECT_VALID( |
3229 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); | 3117 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); |
3230 | 3118 |
3231 // Add the same callbacks again. This is an error. | 3119 // Add the same callbacks again. This is an error. |
3232 EXPECT(Dart_IsError( | 3120 EXPECT(Dart_IsError( |
3233 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4))); | 3121 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4))); |
3234 | 3122 |
3235 // Add another callback. This is an error. | 3123 // Add another callback. This is an error. |
3236 EXPECT(Dart_IsError( | 3124 EXPECT(Dart_IsError( |
3237 Dart_SetGcCallbacks(&PrologueCallbackTimes3, &EpilogueCallbackTimes5))); | 3125 Dart_SetGcCallbacks(&PrologueCallbackTimes3, &EpilogueCallbackTimes5))); |
3238 | 3126 |
3239 // GC callback removal testing. | 3127 // GC callback removal testing. |
3240 | 3128 |
3241 // Remove GC callbacks. | 3129 // Remove GC callbacks. |
3242 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | 3130 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); |
3243 | 3131 |
3244 // Remove GC callbacks whennone exist. This is an error. | 3132 // Remove GC callbacks whennone exist. This is an error. |
3245 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, NULL))); | 3133 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, NULL))); |
3246 | 3134 |
3247 EXPECT_VALID( | 3135 EXPECT_VALID( |
3248 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); | 3136 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); |
3249 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); | 3137 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); |
3250 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); | 3138 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); |
3251 } | 3139 } |
3252 | 3140 |
3253 | |
3254 TEST_CASE(SingleGarbageCollectionCallback) { | 3141 TEST_CASE(SingleGarbageCollectionCallback) { |
3255 // Add a prologue callback. | 3142 // Add a prologue callback. |
3256 EXPECT_VALID( | 3143 EXPECT_VALID( |
3257 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackNOP)); | 3144 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackNOP)); |
3258 | 3145 |
3259 { | 3146 { |
3260 TransitionNativeToVM transition(thread); | 3147 TransitionNativeToVM transition(thread); |
3261 | 3148 |
3262 // Garbage collect new space ignoring callbacks. This should not | 3149 // Garbage collect new space ignoring callbacks. This should not |
3263 // invoke the prologue callback. No status values should change. | 3150 // invoke the prologue callback. No status values should change. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3352 // Garbage collect old space. No callbacks should be invoked. No | 3239 // Garbage collect old space. No callbacks should be invoked. No |
3353 // status values should change. | 3240 // status values should change. |
3354 global_prologue_callback_status = 3; | 3241 global_prologue_callback_status = 3; |
3355 global_epilogue_callback_status = 7; | 3242 global_epilogue_callback_status = 7; |
3356 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3243 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3357 EXPECT_EQ(3, global_prologue_callback_status); | 3244 EXPECT_EQ(3, global_prologue_callback_status); |
3358 EXPECT_EQ(7, global_epilogue_callback_status); | 3245 EXPECT_EQ(7, global_epilogue_callback_status); |
3359 } | 3246 } |
3360 } | 3247 } |
3361 | 3248 |
3362 | |
3363 // Unit test for creating multiple scopes and local handles within them. | 3249 // Unit test for creating multiple scopes and local handles within them. |
3364 // Ensure that the local handles get all cleaned out when exiting the | 3250 // Ensure that the local handles get all cleaned out when exiting the |
3365 // scope. | 3251 // scope. |
3366 VM_UNIT_TEST_CASE(LocalHandles) { | 3252 VM_UNIT_TEST_CASE(LocalHandles) { |
3367 TestCase::CreateTestIsolate(); | 3253 TestCase::CreateTestIsolate(); |
3368 Thread* thread = Thread::Current(); | 3254 Thread* thread = Thread::Current(); |
3369 Isolate* isolate = thread->isolate(); | 3255 Isolate* isolate = thread->isolate(); |
3370 EXPECT(isolate != NULL); | 3256 EXPECT(isolate != NULL); |
3371 ApiLocalScope* scope = thread->api_top_scope(); | 3257 ApiLocalScope* scope = thread->api_top_scope(); |
3372 Dart_Handle handles[300]; | 3258 Dart_Handle handles[300]; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3416 Dart_ExitScope(); | 3302 Dart_ExitScope(); |
3417 } | 3303 } |
3418 EXPECT_EQ(100, thread->CountLocalHandles()); | 3304 EXPECT_EQ(100, thread->CountLocalHandles()); |
3419 Dart_ExitScope(); | 3305 Dart_ExitScope(); |
3420 } | 3306 } |
3421 EXPECT_EQ(0, thread->CountLocalHandles()); | 3307 EXPECT_EQ(0, thread->CountLocalHandles()); |
3422 EXPECT(scope == thread->api_top_scope()); | 3308 EXPECT(scope == thread->api_top_scope()); |
3423 Dart_ShutdownIsolate(); | 3309 Dart_ShutdownIsolate(); |
3424 } | 3310 } |
3425 | 3311 |
3426 | |
3427 // Unit test for creating multiple scopes and allocating objects in the | 3312 // Unit test for creating multiple scopes and allocating objects in the |
3428 // zone for the scope. Ensure that the memory is freed when the scope | 3313 // zone for the scope. Ensure that the memory is freed when the scope |
3429 // exits. | 3314 // exits. |
3430 VM_UNIT_TEST_CASE(LocalZoneMemory) { | 3315 VM_UNIT_TEST_CASE(LocalZoneMemory) { |
3431 TestCase::CreateTestIsolate(); | 3316 TestCase::CreateTestIsolate(); |
3432 Thread* thread = Thread::Current(); | 3317 Thread* thread = Thread::Current(); |
3433 EXPECT(thread != NULL); | 3318 EXPECT(thread != NULL); |
3434 ApiLocalScope* scope = thread->api_top_scope(); | 3319 ApiLocalScope* scope = thread->api_top_scope(); |
3435 { | 3320 { |
3436 // Start a new scope and allocate some memory. | 3321 // Start a new scope and allocate some memory. |
(...skipping 24 matching lines...) Expand all Loading... |
3461 Dart_ExitScope(); | 3346 Dart_ExitScope(); |
3462 } | 3347 } |
3463 EXPECT_EQ(1600, thread->ZoneSizeInBytes()); | 3348 EXPECT_EQ(1600, thread->ZoneSizeInBytes()); |
3464 Dart_ExitScope(); | 3349 Dart_ExitScope(); |
3465 } | 3350 } |
3466 EXPECT_EQ(0, thread->ZoneSizeInBytes()); | 3351 EXPECT_EQ(0, thread->ZoneSizeInBytes()); |
3467 EXPECT(scope == thread->api_top_scope()); | 3352 EXPECT(scope == thread->api_top_scope()); |
3468 Dart_ShutdownIsolate(); | 3353 Dart_ShutdownIsolate(); |
3469 } | 3354 } |
3470 | 3355 |
3471 | |
3472 VM_UNIT_TEST_CASE(Isolates) { | 3356 VM_UNIT_TEST_CASE(Isolates) { |
3473 // This test currently assumes that the Dart_Isolate type is an opaque | 3357 // This test currently assumes that the Dart_Isolate type is an opaque |
3474 // representation of Isolate*. | 3358 // representation of Isolate*. |
3475 Dart_Isolate iso_1 = TestCase::CreateTestIsolate(); | 3359 Dart_Isolate iso_1 = TestCase::CreateTestIsolate(); |
3476 EXPECT_EQ(iso_1, Api::CastIsolate(Isolate::Current())); | 3360 EXPECT_EQ(iso_1, Api::CastIsolate(Isolate::Current())); |
3477 Dart_Isolate isolate = Dart_CurrentIsolate(); | 3361 Dart_Isolate isolate = Dart_CurrentIsolate(); |
3478 EXPECT_EQ(iso_1, isolate); | 3362 EXPECT_EQ(iso_1, isolate); |
3479 Dart_ExitIsolate(); | 3363 Dart_ExitIsolate(); |
3480 EXPECT(NULL == Dart_CurrentIsolate()); | 3364 EXPECT(NULL == Dart_CurrentIsolate()); |
3481 Dart_Isolate iso_2 = TestCase::CreateTestIsolate(); | 3365 Dart_Isolate iso_2 = TestCase::CreateTestIsolate(); |
3482 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); | 3366 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); |
3483 Dart_ExitIsolate(); | 3367 Dart_ExitIsolate(); |
3484 EXPECT(NULL == Dart_CurrentIsolate()); | 3368 EXPECT(NULL == Dart_CurrentIsolate()); |
3485 Dart_EnterIsolate(iso_2); | 3369 Dart_EnterIsolate(iso_2); |
3486 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); | 3370 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); |
3487 Dart_ShutdownIsolate(); | 3371 Dart_ShutdownIsolate(); |
3488 EXPECT(NULL == Dart_CurrentIsolate()); | 3372 EXPECT(NULL == Dart_CurrentIsolate()); |
3489 Dart_EnterIsolate(iso_1); | 3373 Dart_EnterIsolate(iso_1); |
3490 EXPECT_EQ(iso_1, Dart_CurrentIsolate()); | 3374 EXPECT_EQ(iso_1, Dart_CurrentIsolate()); |
3491 Dart_ShutdownIsolate(); | 3375 Dart_ShutdownIsolate(); |
3492 EXPECT(NULL == Dart_CurrentIsolate()); | 3376 EXPECT(NULL == Dart_CurrentIsolate()); |
3493 } | 3377 } |
3494 | 3378 |
3495 | |
3496 VM_UNIT_TEST_CASE(CurrentIsolateData) { | 3379 VM_UNIT_TEST_CASE(CurrentIsolateData) { |
3497 intptr_t mydata = 12345; | 3380 intptr_t mydata = 12345; |
3498 char* err; | 3381 char* err; |
3499 Dart_Isolate isolate = | 3382 Dart_Isolate isolate = |
3500 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 3383 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
3501 bin::core_isolate_snapshot_instructions, NULL, | 3384 bin::core_isolate_snapshot_instructions, NULL, |
3502 reinterpret_cast<void*>(mydata), &err); | 3385 reinterpret_cast<void*>(mydata), &err); |
3503 EXPECT(isolate != NULL); | 3386 EXPECT(isolate != NULL); |
3504 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); | 3387 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); |
3505 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); | 3388 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); |
3506 Dart_ShutdownIsolate(); | 3389 Dart_ShutdownIsolate(); |
3507 } | 3390 } |
3508 | 3391 |
3509 | |
3510 VM_UNIT_TEST_CASE(IsolateSetCheckedMode) { | 3392 VM_UNIT_TEST_CASE(IsolateSetCheckedMode) { |
3511 const char* kScriptChars = | 3393 const char* kScriptChars = |
3512 "int bad1() {\n" | 3394 "int bad1() {\n" |
3513 " int foo = 'string';\n" | 3395 " int foo = 'string';\n" |
3514 " return foo;\n" | 3396 " return foo;\n" |
3515 "}\n" | 3397 "}\n" |
3516 "\n" | 3398 "\n" |
3517 "int good1() {\n" | 3399 "int good1() {\n" |
3518 " int five = 5;\n" | 3400 " int five = 5;\n" |
3519 " return five;" | 3401 " return five;" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 EXPECT_VALID(result); | 3438 EXPECT_VALID(result); |
3557 Dart_ExitScope(); | 3439 Dart_ExitScope(); |
3558 } | 3440 } |
3559 | 3441 |
3560 EXPECT(isolate != NULL); | 3442 EXPECT(isolate != NULL); |
3561 | 3443 |
3562 // Shutdown the isolate. | 3444 // Shutdown the isolate. |
3563 Dart_ShutdownIsolate(); | 3445 Dart_ShutdownIsolate(); |
3564 } | 3446 } |
3565 | 3447 |
3566 | |
3567 TEST_CASE(DebugName) { | 3448 TEST_CASE(DebugName) { |
3568 Dart_Handle debug_name = Dart_DebugName(); | 3449 Dart_Handle debug_name = Dart_DebugName(); |
3569 EXPECT_VALID(debug_name); | 3450 EXPECT_VALID(debug_name); |
3570 EXPECT(Dart_IsString(debug_name)); | 3451 EXPECT(Dart_IsString(debug_name)); |
3571 } | 3452 } |
3572 | 3453 |
3573 | |
3574 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {} | 3454 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {} |
3575 | 3455 |
3576 | |
3577 VM_UNIT_TEST_CASE(SetMessageCallbacks) { | 3456 VM_UNIT_TEST_CASE(SetMessageCallbacks) { |
3578 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); | 3457 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); |
3579 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); | 3458 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); |
3580 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 3459 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
3581 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); | 3460 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); |
3582 Dart_ShutdownIsolate(); | 3461 Dart_ShutdownIsolate(); |
3583 } | 3462 } |
3584 | 3463 |
3585 | |
3586 TEST_CASE(SetStickyError) { | 3464 TEST_CASE(SetStickyError) { |
3587 const char* kScriptChars = "main() => throw 'HI';"; | 3465 const char* kScriptChars = "main() => throw 'HI';"; |
3588 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3466 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3589 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 3467 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
3590 EXPECT(Dart_IsError(retobj)); | 3468 EXPECT(Dart_IsError(retobj)); |
3591 EXPECT(Dart_IsUnhandledExceptionError(retobj)); | 3469 EXPECT(Dart_IsUnhandledExceptionError(retobj)); |
3592 EXPECT(!Dart_HasStickyError()); | 3470 EXPECT(!Dart_HasStickyError()); |
3593 EXPECT(Dart_GetStickyError() == Dart_Null()); | 3471 EXPECT(Dart_GetStickyError() == Dart_Null()); |
3594 Dart_SetStickyError(retobj); | 3472 Dart_SetStickyError(retobj); |
3595 EXPECT(Dart_HasStickyError()); | 3473 EXPECT(Dart_HasStickyError()); |
3596 EXPECT(Dart_GetStickyError() != Dart_Null()); | 3474 EXPECT(Dart_GetStickyError() != Dart_Null()); |
3597 Dart_SetStickyError(Dart_Null()); | 3475 Dart_SetStickyError(Dart_Null()); |
3598 EXPECT(!Dart_HasStickyError()); | 3476 EXPECT(!Dart_HasStickyError()); |
3599 EXPECT(Dart_GetStickyError() == Dart_Null()); | 3477 EXPECT(Dart_GetStickyError() == Dart_Null()); |
3600 } | 3478 } |
3601 | 3479 |
3602 | |
3603 TEST_CASE(TypeGetNonParamtericTypes) { | 3480 TEST_CASE(TypeGetNonParamtericTypes) { |
3604 const char* kScriptChars = | 3481 const char* kScriptChars = |
3605 "class MyClass0 {\n" | 3482 "class MyClass0 {\n" |
3606 "}\n" | 3483 "}\n" |
3607 "\n" | 3484 "\n" |
3608 "class MyClass1 implements MyInterface1 {\n" | 3485 "class MyClass1 implements MyInterface1 {\n" |
3609 "}\n" | 3486 "}\n" |
3610 "\n" | 3487 "\n" |
3611 "class MyClass2 implements MyInterface0, MyInterface1 {\n" | 3488 "class MyClass2 implements MyInterface0, MyInterface1 {\n" |
3612 "}\n" | 3489 "}\n" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3684 EXPECT(!instanceOf); | 3561 EXPECT(!instanceOf); |
3685 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type3, &instanceOf)); | 3562 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type3, &instanceOf)); |
3686 EXPECT(instanceOf); | 3563 EXPECT(instanceOf); |
3687 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type4, &instanceOf)); | 3564 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type4, &instanceOf)); |
3688 EXPECT(instanceOf); | 3565 EXPECT(instanceOf); |
3689 type2_obj = Dart_Invoke(lib, NewString("getMyClass2Type"), 0, NULL); | 3566 type2_obj = Dart_Invoke(lib, NewString("getMyClass2Type"), 0, NULL); |
3690 EXPECT_VALID(type2_obj); | 3567 EXPECT_VALID(type2_obj); |
3691 EXPECT(Dart_IdentityEquals(type2, type2_obj)); | 3568 EXPECT(Dart_IdentityEquals(type2, type2_obj)); |
3692 } | 3569 } |
3693 | 3570 |
3694 | |
3695 TEST_CASE(TypeGetParameterizedTypes) { | 3571 TEST_CASE(TypeGetParameterizedTypes) { |
3696 const char* kScriptChars = | 3572 const char* kScriptChars = |
3697 "class MyClass0<A, B> {\n" | 3573 "class MyClass0<A, B> {\n" |
3698 "}\n" | 3574 "}\n" |
3699 "\n" | 3575 "\n" |
3700 "class MyClass1<A, C> {\n" | 3576 "class MyClass1<A, C> {\n" |
3701 "}\n" | 3577 "}\n" |
3702 "MyClass0 getMyClass0() {\n" | 3578 "MyClass0 getMyClass0() {\n" |
3703 " return new MyClass0<int, double>();\n" | 3579 " return new MyClass0<int, double>();\n" |
3704 "}\n" | 3580 "}\n" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3788 // MyClass1<List<int>, List<double>> type. | 3664 // MyClass1<List<int>, List<double>> type. |
3789 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1"), 0, NULL); | 3665 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1"), 0, NULL); |
3790 EXPECT_VALID(type1_obj); | 3666 EXPECT_VALID(type1_obj); |
3791 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceOf)); | 3667 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceOf)); |
3792 EXPECT(instanceOf); | 3668 EXPECT(instanceOf); |
3793 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1Type"), 0, NULL); | 3669 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1Type"), 0, NULL); |
3794 EXPECT_VALID(type1_obj); | 3670 EXPECT_VALID(type1_obj); |
3795 EXPECT(!Dart_IdentityEquals(type1_obj, myclass1_type)); | 3671 EXPECT(!Dart_IdentityEquals(type1_obj, myclass1_type)); |
3796 } | 3672 } |
3797 | 3673 |
3798 | |
3799 static void TestFieldOk(Dart_Handle container, | 3674 static void TestFieldOk(Dart_Handle container, |
3800 Dart_Handle name, | 3675 Dart_Handle name, |
3801 bool final, | 3676 bool final, |
3802 const char* initial_value) { | 3677 const char* initial_value) { |
3803 Dart_Handle result; | 3678 Dart_Handle result; |
3804 | 3679 |
3805 // Make sure we have the right initial value. | 3680 // Make sure we have the right initial value. |
3806 result = Dart_GetField(container, name); | 3681 result = Dart_GetField(container, name); |
3807 EXPECT_VALID(result); | 3682 EXPECT_VALID(result); |
3808 const char* value = ""; | 3683 const char* value = ""; |
(...skipping 17 matching lines...) Expand all Loading... |
3826 result = Dart_GetField(container, name); | 3701 result = Dart_GetField(container, name); |
3827 EXPECT_VALID(result); | 3702 EXPECT_VALID(result); |
3828 EXPECT_VALID(Dart_StringToCString(result, &value)); | 3703 EXPECT_VALID(Dart_StringToCString(result, &value)); |
3829 if (final) { | 3704 if (final) { |
3830 EXPECT_STREQ(initial_value, value); | 3705 EXPECT_STREQ(initial_value, value); |
3831 } else { | 3706 } else { |
3832 EXPECT_STREQ(buffer, value); | 3707 EXPECT_STREQ(buffer, value); |
3833 } | 3708 } |
3834 } | 3709 } |
3835 | 3710 |
3836 | |
3837 static void TestFieldNotFound(Dart_Handle container, Dart_Handle name) { | 3711 static void TestFieldNotFound(Dart_Handle container, Dart_Handle name) { |
3838 EXPECT(Dart_IsError(Dart_GetField(container, name))); | 3712 EXPECT(Dart_IsError(Dart_GetField(container, name))); |
3839 EXPECT(Dart_IsError(Dart_SetField(container, name, Dart_Null()))); | 3713 EXPECT(Dart_IsError(Dart_SetField(container, name, Dart_Null()))); |
3840 } | 3714 } |
3841 | 3715 |
3842 | |
3843 TEST_CASE(FieldAccess) { | 3716 TEST_CASE(FieldAccess) { |
3844 const char* kScriptChars = | 3717 const char* kScriptChars = |
3845 "class BaseFields {\n" | 3718 "class BaseFields {\n" |
3846 " BaseFields()\n" | 3719 " BaseFields()\n" |
3847 " : this.inherited_fld = 'inherited' {\n" | 3720 " : this.inherited_fld = 'inherited' {\n" |
3848 " }\n" | 3721 " }\n" |
3849 " var inherited_fld;\n" | 3722 " var inherited_fld;\n" |
3850 " static var non_inherited_fld;\n" | 3723 " static var non_inherited_fld;\n" |
3851 "}\n" | 3724 "}\n" |
3852 "\n" | 3725 "\n" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4084 TestFieldNotFound(instance, name); | 3957 TestFieldNotFound(instance, name); |
4085 TestFieldOk(lib, name, false, "imported getset"); | 3958 TestFieldOk(lib, name, false, "imported getset"); |
4086 | 3959 |
4087 // Hidden imported top-level get/set field. Not found at any level. | 3960 // Hidden imported top-level get/set field. Not found at any level. |
4088 name = NewString("_imported_getset_fld"); | 3961 name = NewString("_imported_getset_fld"); |
4089 TestFieldNotFound(type, name); | 3962 TestFieldNotFound(type, name); |
4090 TestFieldNotFound(instance, name); | 3963 TestFieldNotFound(instance, name); |
4091 TestFieldNotFound(lib, name); | 3964 TestFieldNotFound(lib, name); |
4092 } | 3965 } |
4093 | 3966 |
4094 | |
4095 TEST_CASE(SetField_FunnyValue) { | 3967 TEST_CASE(SetField_FunnyValue) { |
4096 const char* kScriptChars = "var top;\n"; | 3968 const char* kScriptChars = "var top;\n"; |
4097 | 3969 |
4098 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3970 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4099 Dart_Handle name = NewString("top"); | 3971 Dart_Handle name = NewString("top"); |
4100 bool value; | 3972 bool value; |
4101 | 3973 |
4102 // Test that you can set the field to a good value. | 3974 // Test that you can set the field to a good value. |
4103 EXPECT_VALID(Dart_SetField(lib, name, Dart_True())); | 3975 EXPECT_VALID(Dart_SetField(lib, name, Dart_True())); |
4104 Dart_Handle result = Dart_GetField(lib, name); | 3976 Dart_Handle result = Dart_GetField(lib, name); |
(...skipping 13 matching lines...) Expand all Loading... |
4118 EXPECT(Dart_IsError(result)); | 3990 EXPECT(Dart_IsError(result)); |
4119 EXPECT_STREQ("Dart_SetField expects argument 'value' to be of type Instance.", | 3991 EXPECT_STREQ("Dart_SetField expects argument 'value' to be of type Instance.", |
4120 Dart_GetError(result)); | 3992 Dart_GetError(result)); |
4121 | 3993 |
4122 // Pass an error handle. The error is contagious. | 3994 // Pass an error handle. The error is contagious. |
4123 result = Dart_SetField(lib, name, Api::NewError("myerror")); | 3995 result = Dart_SetField(lib, name, Api::NewError("myerror")); |
4124 EXPECT(Dart_IsError(result)); | 3996 EXPECT(Dart_IsError(result)); |
4125 EXPECT_STREQ("myerror", Dart_GetError(result)); | 3997 EXPECT_STREQ("myerror", Dart_GetError(result)); |
4126 } | 3998 } |
4127 | 3999 |
4128 | |
4129 void NativeFieldLookup(Dart_NativeArguments args) { | 4000 void NativeFieldLookup(Dart_NativeArguments args) { |
4130 UNREACHABLE(); | 4001 UNREACHABLE(); |
4131 } | 4002 } |
4132 | 4003 |
4133 | |
4134 static Dart_NativeFunction native_field_lookup(Dart_Handle name, | 4004 static Dart_NativeFunction native_field_lookup(Dart_Handle name, |
4135 int argument_count, | 4005 int argument_count, |
4136 bool* auto_setup_scope) { | 4006 bool* auto_setup_scope) { |
4137 ASSERT(auto_setup_scope != NULL); | 4007 ASSERT(auto_setup_scope != NULL); |
4138 *auto_setup_scope = false; | 4008 *auto_setup_scope = false; |
4139 return reinterpret_cast<Dart_NativeFunction>(&NativeFieldLookup); | 4009 return reinterpret_cast<Dart_NativeFunction>(&NativeFieldLookup); |
4140 } | 4010 } |
4141 | 4011 |
4142 | |
4143 TEST_CASE(InjectNativeFields1) { | 4012 TEST_CASE(InjectNativeFields1) { |
4144 const char* kScriptChars = | 4013 const char* kScriptChars = |
4145 "class NativeFields extends NativeFieldsWrapper {\n" | 4014 "class NativeFields extends NativeFieldsWrapper {\n" |
4146 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4015 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4147 " int fld1;\n" | 4016 " int fld1;\n" |
4148 " final int fld2;\n" | 4017 " final int fld2;\n" |
4149 " static int fld3;\n" | 4018 " static int fld3;\n" |
4150 " static const int fld4 = 10;\n" | 4019 " static const int fld4 = 10;\n" |
4151 "}\n" | 4020 "}\n" |
4152 "NativeFields testMain() {\n" | 4021 "NativeFields testMain() {\n" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4184 // (1 + 2) * kWordSize + size of object header. | 4053 // (1 + 2) * kWordSize + size of object header. |
4185 // We check to make sure the instance size computed by the VM matches | 4054 // We check to make sure the instance size computed by the VM matches |
4186 // our expectations. | 4055 // our expectations. |
4187 intptr_t header_size = sizeof(RawObject); | 4056 intptr_t header_size = sizeof(RawObject); |
4188 EXPECT_EQ( | 4057 EXPECT_EQ( |
4189 Utils::RoundUp(((1 + 2) * kWordSize) + header_size, kObjectAlignment), | 4058 Utils::RoundUp(((1 + 2) * kWordSize) + header_size, kObjectAlignment), |
4190 cls.instance_size()); | 4059 cls.instance_size()); |
4191 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); | 4060 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); |
4192 } | 4061 } |
4193 | 4062 |
4194 | |
4195 TEST_CASE(InjectNativeFields2) { | 4063 TEST_CASE(InjectNativeFields2) { |
4196 const char* kScriptChars = | 4064 const char* kScriptChars = |
4197 "class NativeFields extends NativeFieldsWrapper {\n" | 4065 "class NativeFields extends NativeFieldsWrapper {\n" |
4198 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4066 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4199 " int fld1;\n" | 4067 " int fld1;\n" |
4200 " final int fld2;\n" | 4068 " final int fld2;\n" |
4201 " static int fld3;\n" | 4069 " static int fld3;\n" |
4202 " static const int fld4 = 10;\n" | 4070 " static const int fld4 = 10;\n" |
4203 "}\n" | 4071 "}\n" |
4204 "NativeFields testMain() {\n" | 4072 "NativeFields testMain() {\n" |
4205 " NativeFields obj = new NativeFields(10, 20);\n" | 4073 " NativeFields obj = new NativeFields(10, 20);\n" |
4206 " return obj;\n" | 4074 " return obj;\n" |
4207 "}\n"; | 4075 "}\n"; |
4208 Dart_Handle result; | 4076 Dart_Handle result; |
4209 // Create a test library and Load up a test script in it. | 4077 // Create a test library and Load up a test script in it. |
4210 Dart_Handle lib = | 4078 Dart_Handle lib = |
4211 TestCase::LoadTestScript(kScriptChars, NULL, USER_TEST_URI, false); | 4079 TestCase::LoadTestScript(kScriptChars, NULL, USER_TEST_URI, false); |
4212 | 4080 |
4213 // Invoke a function which returns an object of type NativeFields. | 4081 // Invoke a function which returns an object of type NativeFields. |
4214 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4082 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4215 | 4083 |
4216 // We expect this to fail as class "NativeFields" extends | 4084 // We expect this to fail as class "NativeFields" extends |
4217 // "NativeFieldsWrapper" and there is no definition of it either | 4085 // "NativeFieldsWrapper" and there is no definition of it either |
4218 // in the dart code or through the native field injection mechanism. | 4086 // in the dart code or through the native field injection mechanism. |
4219 EXPECT(Dart_IsError(result)); | 4087 EXPECT(Dart_IsError(result)); |
4220 } | 4088 } |
4221 | 4089 |
4222 | |
4223 TEST_CASE(InjectNativeFields3) { | 4090 TEST_CASE(InjectNativeFields3) { |
4224 const char* kScriptChars = | 4091 const char* kScriptChars = |
4225 "import 'dart:nativewrappers';" | 4092 "import 'dart:nativewrappers';" |
4226 "class NativeFields extends NativeFieldWrapperClass2 {\n" | 4093 "class NativeFields extends NativeFieldWrapperClass2 {\n" |
4227 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4094 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4228 " int fld1;\n" | 4095 " int fld1;\n" |
4229 " final int fld2;\n" | 4096 " final int fld2;\n" |
4230 " static int fld3;\n" | 4097 " static int fld3;\n" |
4231 " static const int fld4 = 10;\n" | 4098 " static const int fld4 = 10;\n" |
4232 "}\n" | 4099 "}\n" |
(...skipping 21 matching lines...) Expand all Loading... |
4254 // (1 + 2) * kWordSize + size of object header. | 4121 // (1 + 2) * kWordSize + size of object header. |
4255 // We check to make sure the instance size computed by the VM matches | 4122 // We check to make sure the instance size computed by the VM matches |
4256 // our expectations. | 4123 // our expectations. |
4257 intptr_t header_size = sizeof(RawObject); | 4124 intptr_t header_size = sizeof(RawObject); |
4258 EXPECT_EQ( | 4125 EXPECT_EQ( |
4259 Utils::RoundUp(((1 + 2) * kWordSize) + header_size, kObjectAlignment), | 4126 Utils::RoundUp(((1 + 2) * kWordSize) + header_size, kObjectAlignment), |
4260 cls.instance_size()); | 4127 cls.instance_size()); |
4261 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); | 4128 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); |
4262 } | 4129 } |
4263 | 4130 |
4264 | |
4265 TEST_CASE(InjectNativeFields4) { | 4131 TEST_CASE(InjectNativeFields4) { |
4266 const char* kScriptChars = | 4132 const char* kScriptChars = |
4267 "import 'dart:nativewrappers';" | 4133 "import 'dart:nativewrappers';" |
4268 "class NativeFields extends NativeFieldWrapperClass2 {\n" | 4134 "class NativeFields extends NativeFieldWrapperClass2 {\n" |
4269 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4135 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4270 " int fld1;\n" | 4136 " int fld1;\n" |
4271 " final int fld2;\n" | 4137 " final int fld2;\n" |
4272 " static int fld3;\n" | 4138 " static int fld3;\n" |
4273 " static const int fld4 = 10;\n" | 4139 " static const int fld4 = 10;\n" |
4274 "}\n" | 4140 "}\n" |
(...skipping 15 matching lines...) Expand all Loading... |
4290 EXPECT(Dart_IsError(result)); | 4156 EXPECT(Dart_IsError(result)); |
4291 Dart_Handle expected_error = DartUtils::NewError( | 4157 Dart_Handle expected_error = DartUtils::NewError( |
4292 "'dart:test-lib': Error: line 1 pos 36: " | 4158 "'dart:test-lib': Error: line 1 pos 36: " |
4293 "class 'NativeFields' is trying to extend a native fields class, " | 4159 "class 'NativeFields' is trying to extend a native fields class, " |
4294 "but library '%s' has no native resolvers", | 4160 "but library '%s' has no native resolvers", |
4295 TestCase::url()); | 4161 TestCase::url()); |
4296 EXPECT_SUBSTRING(Dart_GetError(expected_error), Dart_GetError(result)); | 4162 EXPECT_SUBSTRING(Dart_GetError(expected_error), Dart_GetError(result)); |
4297 #endif | 4163 #endif |
4298 } | 4164 } |
4299 | 4165 |
4300 | |
4301 static const int kTestNumNativeFields = 2; | 4166 static const int kTestNumNativeFields = 2; |
4302 static const intptr_t kNativeField1Value = 30; | 4167 static const intptr_t kNativeField1Value = 30; |
4303 static const intptr_t kNativeField2Value = 40; | 4168 static const intptr_t kNativeField2Value = 40; |
4304 | 4169 |
4305 void TestNativeFieldsAccess_init(Dart_NativeArguments args) { | 4170 void TestNativeFieldsAccess_init(Dart_NativeArguments args) { |
4306 Dart_Handle receiver = Dart_GetNativeArgument(args, 0); | 4171 Dart_Handle receiver = Dart_GetNativeArgument(args, 0); |
4307 Dart_SetNativeInstanceField(receiver, 0, kNativeField1Value); | 4172 Dart_SetNativeInstanceField(receiver, 0, kNativeField1Value); |
4308 Dart_SetNativeInstanceField(receiver, 1, kNativeField2Value); | 4173 Dart_SetNativeInstanceField(receiver, 1, kNativeField2Value); |
4309 } | 4174 } |
4310 | 4175 |
4311 | |
4312 void TestNativeFieldsAccess_access(Dart_NativeArguments args) { | 4176 void TestNativeFieldsAccess_access(Dart_NativeArguments args) { |
4313 intptr_t field_values[kTestNumNativeFields]; | 4177 intptr_t field_values[kTestNumNativeFields]; |
4314 Dart_Handle result = Dart_GetNativeFieldsOfArgument( | 4178 Dart_Handle result = Dart_GetNativeFieldsOfArgument( |
4315 args, 0, kTestNumNativeFields, field_values); | 4179 args, 0, kTestNumNativeFields, field_values); |
4316 EXPECT_VALID(result); | 4180 EXPECT_VALID(result); |
4317 EXPECT_EQ(kNativeField1Value, field_values[0]); | 4181 EXPECT_EQ(kNativeField1Value, field_values[0]); |
4318 EXPECT_EQ(kNativeField2Value, field_values[1]); | 4182 EXPECT_EQ(kNativeField2Value, field_values[1]); |
4319 result = Dart_GetNativeFieldsOfArgument(args, 1, kTestNumNativeFields, | 4183 result = Dart_GetNativeFieldsOfArgument(args, 1, kTestNumNativeFields, |
4320 field_values); | 4184 field_values); |
4321 EXPECT_VALID(result); | 4185 EXPECT_VALID(result); |
4322 EXPECT_EQ(0, field_values[0]); | 4186 EXPECT_EQ(0, field_values[0]); |
4323 EXPECT_EQ(0, field_values[1]); | 4187 EXPECT_EQ(0, field_values[1]); |
4324 } | 4188 } |
4325 | 4189 |
4326 | |
4327 static Dart_NativeFunction TestNativeFieldsAccess_lookup(Dart_Handle name, | 4190 static Dart_NativeFunction TestNativeFieldsAccess_lookup(Dart_Handle name, |
4328 int argument_count, | 4191 int argument_count, |
4329 bool* auto_scope) { | 4192 bool* auto_scope) { |
4330 ASSERT(auto_scope != NULL); | 4193 ASSERT(auto_scope != NULL); |
4331 *auto_scope = true; | 4194 *auto_scope = true; |
4332 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 4195 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
4333 if (!obj.IsString()) { | 4196 if (!obj.IsString()) { |
4334 return NULL; | 4197 return NULL; |
4335 } | 4198 } |
4336 const char* function_name = obj.ToCString(); | 4199 const char* function_name = obj.ToCString(); |
4337 ASSERT(function_name != NULL); | 4200 ASSERT(function_name != NULL); |
4338 if (!strcmp(function_name, "TestNativeFieldsAccess_init")) { | 4201 if (!strcmp(function_name, "TestNativeFieldsAccess_init")) { |
4339 return reinterpret_cast<Dart_NativeFunction>(&TestNativeFieldsAccess_init); | 4202 return reinterpret_cast<Dart_NativeFunction>(&TestNativeFieldsAccess_init); |
4340 } else if (!strcmp(function_name, "TestNativeFieldsAccess_access")) { | 4203 } else if (!strcmp(function_name, "TestNativeFieldsAccess_access")) { |
4341 return reinterpret_cast<Dart_NativeFunction>( | 4204 return reinterpret_cast<Dart_NativeFunction>( |
4342 &TestNativeFieldsAccess_access); | 4205 &TestNativeFieldsAccess_access); |
4343 } else { | 4206 } else { |
4344 return NULL; | 4207 return NULL; |
4345 } | 4208 } |
4346 } | 4209 } |
4347 | 4210 |
4348 | |
4349 TEST_CASE(TestNativeFieldsAccess) { | 4211 TEST_CASE(TestNativeFieldsAccess) { |
4350 const char* kScriptChars = | 4212 const char* kScriptChars = |
4351 "import 'dart:nativewrappers';" | 4213 "import 'dart:nativewrappers';" |
4352 "class NativeFields extends NativeFieldWrapperClass2 {\n" | 4214 "class NativeFields extends NativeFieldWrapperClass2 {\n" |
4353 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4215 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4354 " int fld1;\n" | 4216 " int fld1;\n" |
4355 " final int fld2;\n" | 4217 " final int fld2;\n" |
4356 " static int fld3;\n" | 4218 " static int fld3;\n" |
4357 " static const int fld4 = 10;\n" | 4219 " static const int fld4 = 10;\n" |
4358 " int initNativeFlds() native 'TestNativeFieldsAccess_init';\n" | 4220 " int initNativeFlds() native 'TestNativeFieldsAccess_init';\n" |
4359 " int accessNativeFlds(int i) native 'TestNativeFieldsAccess_access';\n" | 4221 " int accessNativeFlds(int i) native 'TestNativeFieldsAccess_access';\n" |
4360 "}\n" | 4222 "}\n" |
4361 "NativeFields testMain() {\n" | 4223 "NativeFields testMain() {\n" |
4362 " NativeFields obj = new NativeFields(10, 20);\n" | 4224 " NativeFields obj = new NativeFields(10, 20);\n" |
4363 " obj.initNativeFlds();\n" | 4225 " obj.initNativeFlds();\n" |
4364 " obj.accessNativeFlds(null);\n" | 4226 " obj.accessNativeFlds(null);\n" |
4365 " return obj;\n" | 4227 " return obj;\n" |
4366 "}\n"; | 4228 "}\n"; |
4367 | 4229 |
4368 // Load up a test script in the test library. | 4230 // Load up a test script in the test library. |
4369 Dart_Handle lib = | 4231 Dart_Handle lib = |
4370 TestCase::LoadTestScript(kScriptChars, TestNativeFieldsAccess_lookup); | 4232 TestCase::LoadTestScript(kScriptChars, TestNativeFieldsAccess_lookup); |
4371 | 4233 |
4372 // Invoke a function which returns an object of type NativeFields. | 4234 // Invoke a function which returns an object of type NativeFields. |
4373 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4235 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4374 EXPECT_VALID(result); | 4236 EXPECT_VALID(result); |
4375 } | 4237 } |
4376 | 4238 |
4377 | |
4378 TEST_CASE(InjectNativeFieldsSuperClass) { | 4239 TEST_CASE(InjectNativeFieldsSuperClass) { |
4379 const char* kScriptChars = | 4240 const char* kScriptChars = |
4380 "import 'dart:nativewrappers';" | 4241 "import 'dart:nativewrappers';" |
4381 "class NativeFieldsSuper extends NativeFieldWrapperClass1 {\n" | 4242 "class NativeFieldsSuper extends NativeFieldWrapperClass1 {\n" |
4382 " NativeFieldsSuper() : fld1 = 42 {}\n" | 4243 " NativeFieldsSuper() : fld1 = 42 {}\n" |
4383 " int fld1;\n" | 4244 " int fld1;\n" |
4384 "}\n" | 4245 "}\n" |
4385 "class NativeFields extends NativeFieldsSuper {\n" | 4246 "class NativeFields extends NativeFieldsSuper {\n" |
4386 " fld() => fld1;\n" | 4247 " fld() => fld1;\n" |
4387 "}\n" | 4248 "}\n" |
4388 "int testMain() {\n" | 4249 "int testMain() {\n" |
4389 " NativeFields obj = new NativeFields();\n" | 4250 " NativeFields obj = new NativeFields();\n" |
4390 " return obj.fld();\n" | 4251 " return obj.fld();\n" |
4391 "}\n"; | 4252 "}\n"; |
4392 Dart_Handle result; | 4253 Dart_Handle result; |
4393 // Load up a test script in the test library. | 4254 // Load up a test script in the test library. |
4394 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); | 4255 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); |
4395 | 4256 |
4396 // Invoke a function which returns an object of type NativeFields. | 4257 // Invoke a function which returns an object of type NativeFields. |
4397 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4258 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4398 | 4259 |
4399 EXPECT_VALID(result); | 4260 EXPECT_VALID(result); |
4400 EXPECT(Dart_IsInteger(result)); | 4261 EXPECT(Dart_IsInteger(result)); |
4401 int64_t value = 0; | 4262 int64_t value = 0; |
4402 result = Dart_IntegerToInt64(result, &value); | 4263 result = Dart_IntegerToInt64(result, &value); |
4403 EXPECT_VALID(result); | 4264 EXPECT_VALID(result); |
4404 EXPECT_EQ(42, value); | 4265 EXPECT_EQ(42, value); |
4405 } | 4266 } |
4406 | 4267 |
4407 | |
4408 static void TestNativeFields(Dart_Handle retobj) { | 4268 static void TestNativeFields(Dart_Handle retobj) { |
4409 // Access and set various instance fields of the object. | 4269 // Access and set various instance fields of the object. |
4410 Dart_Handle result = Dart_GetField(retobj, NewString("fld3")); | 4270 Dart_Handle result = Dart_GetField(retobj, NewString("fld3")); |
4411 EXPECT(Dart_IsError(result)); | 4271 EXPECT(Dart_IsError(result)); |
4412 result = Dart_GetField(retobj, NewString("fld0")); | 4272 result = Dart_GetField(retobj, NewString("fld0")); |
4413 EXPECT_VALID(result); | 4273 EXPECT_VALID(result); |
4414 EXPECT(Dart_IsNull(result)); | 4274 EXPECT(Dart_IsNull(result)); |
4415 result = Dart_GetField(retobj, NewString("fld1")); | 4275 result = Dart_GetField(retobj, NewString("fld1")); |
4416 EXPECT_VALID(result); | 4276 EXPECT_VALID(result); |
4417 int64_t value = 0; | 4277 int64_t value = 0; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4473 result = Dart_GetField(retobj, NewString("fld1")); | 4333 result = Dart_GetField(retobj, NewString("fld1")); |
4474 EXPECT_VALID(result); | 4334 EXPECT_VALID(result); |
4475 result = Dart_IntegerToInt64(result, &value); | 4335 result = Dart_IntegerToInt64(result, &value); |
4476 EXPECT_EQ(40, value); | 4336 EXPECT_EQ(40, value); |
4477 result = Dart_GetField(retobj, NewString("fld2")); | 4337 result = Dart_GetField(retobj, NewString("fld2")); |
4478 EXPECT_VALID(result); | 4338 EXPECT_VALID(result); |
4479 result = Dart_IntegerToInt64(result, &value); | 4339 result = Dart_IntegerToInt64(result, &value); |
4480 EXPECT_EQ(20, value); | 4340 EXPECT_EQ(20, value); |
4481 } | 4341 } |
4482 | 4342 |
4483 | |
4484 TEST_CASE(NativeFieldAccess) { | 4343 TEST_CASE(NativeFieldAccess) { |
4485 const char* kScriptChars = | 4344 const char* kScriptChars = |
4486 "class NativeFields extends NativeFieldsWrapper {\n" | 4345 "class NativeFields extends NativeFieldsWrapper {\n" |
4487 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4346 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4488 " int fld0;\n" | 4347 " int fld0;\n" |
4489 " int fld1;\n" | 4348 " int fld1;\n" |
4490 " final int fld2;\n" | 4349 " final int fld2;\n" |
4491 " static int fld3;\n" | 4350 " static int fld3;\n" |
4492 " static const int fld4 = 10;\n" | 4351 " static const int fld4 = 10;\n" |
4493 "}\n" | 4352 "}\n" |
(...skipping 29 matching lines...) Expand all Loading... |
4523 | 4382 |
4524 result = Dart_GetNativeInstanceField(error, 0, &field_value); | 4383 result = Dart_GetNativeInstanceField(error, 0, &field_value); |
4525 EXPECT(Dart_IsError(result)); | 4384 EXPECT(Dart_IsError(result)); |
4526 EXPECT_STREQ("myerror", Dart_GetError(result)); | 4385 EXPECT_STREQ("myerror", Dart_GetError(result)); |
4527 | 4386 |
4528 result = Dart_SetNativeInstanceField(error, 0, 1); | 4387 result = Dart_SetNativeInstanceField(error, 0, 1); |
4529 EXPECT(Dart_IsError(result)); | 4388 EXPECT(Dart_IsError(result)); |
4530 EXPECT_STREQ("myerror", Dart_GetError(result)); | 4389 EXPECT_STREQ("myerror", Dart_GetError(result)); |
4531 } | 4390 } |
4532 | 4391 |
4533 | |
4534 TEST_CASE(ImplicitNativeFieldAccess) { | 4392 TEST_CASE(ImplicitNativeFieldAccess) { |
4535 const char* kScriptChars = | 4393 const char* kScriptChars = |
4536 "import 'dart:nativewrappers';" | 4394 "import 'dart:nativewrappers';" |
4537 "class NativeFields extends NativeFieldWrapperClass4 {\n" | 4395 "class NativeFields extends NativeFieldWrapperClass4 {\n" |
4538 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4396 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4539 " int fld0;\n" | 4397 " int fld0;\n" |
4540 " int fld1;\n" | 4398 " int fld1;\n" |
4541 " final int fld2;\n" | 4399 " final int fld2;\n" |
4542 " static int fld3;\n" | 4400 " static int fld3;\n" |
4543 " static const int fld4 = 10;\n" | 4401 " static const int fld4 = 10;\n" |
4544 "}\n" | 4402 "}\n" |
4545 "NativeFields testMain() {\n" | 4403 "NativeFields testMain() {\n" |
4546 " NativeFields obj = new NativeFields(10, 20);\n" | 4404 " NativeFields obj = new NativeFields(10, 20);\n" |
4547 " return obj;\n" | 4405 " return obj;\n" |
4548 "}\n"; | 4406 "}\n"; |
4549 // Load up a test script in the test library. | 4407 // Load up a test script in the test library. |
4550 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); | 4408 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); |
4551 | 4409 |
4552 // Invoke a function which returns an object of type NativeFields. | 4410 // Invoke a function which returns an object of type NativeFields. |
4553 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4411 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4554 EXPECT_VALID(retobj); | 4412 EXPECT_VALID(retobj); |
4555 | 4413 |
4556 // Now access and set various instance fields of the returned object. | 4414 // Now access and set various instance fields of the returned object. |
4557 TestNativeFields(retobj); | 4415 TestNativeFields(retobj); |
4558 } | 4416 } |
4559 | 4417 |
4560 | |
4561 TEST_CASE(NegativeNativeFieldAccess) { | 4418 TEST_CASE(NegativeNativeFieldAccess) { |
4562 const char* kScriptChars = | 4419 const char* kScriptChars = |
4563 "class NativeFields {\n" | 4420 "class NativeFields {\n" |
4564 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4421 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4565 " int fld1;\n" | 4422 " int fld1;\n" |
4566 " final int fld2;\n" | 4423 " final int fld2;\n" |
4567 " static int fld3;\n" | 4424 " static int fld3;\n" |
4568 " static const int fld4 = 10;\n" | 4425 " static const int fld4 = 10;\n" |
4569 "}\n" | 4426 "}\n" |
4570 "NativeFields testMain1() {\n" | 4427 "NativeFields testMain1() {\n" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4622 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); | 4479 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); |
4623 EXPECT(Dart_IsError(result)); | 4480 EXPECT(Dart_IsError(result)); |
4624 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); | 4481 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); |
4625 EXPECT(Dart_IsError(result)); | 4482 EXPECT(Dart_IsError(result)); |
4626 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); | 4483 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); |
4627 EXPECT(Dart_IsError(result)); | 4484 EXPECT(Dart_IsError(result)); |
4628 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); | 4485 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); |
4629 EXPECT(Dart_IsError(result)); | 4486 EXPECT(Dart_IsError(result)); |
4630 } | 4487 } |
4631 | 4488 |
4632 | |
4633 TEST_CASE(NegativeNativeFieldInIsolateMessage) { | 4489 TEST_CASE(NegativeNativeFieldInIsolateMessage) { |
4634 const char* kScriptChars = | 4490 const char* kScriptChars = |
4635 "import 'dart:isolate';\n" | 4491 "import 'dart:isolate';\n" |
4636 "import 'dart:nativewrappers';\n" | 4492 "import 'dart:nativewrappers';\n" |
4637 "echo(msg) {\n" | 4493 "echo(msg) {\n" |
4638 " var data = msg[0];\n" | 4494 " var data = msg[0];\n" |
4639 " var reply = msg[1];\n" | 4495 " var reply = msg[1];\n" |
4640 " reply.send('echoing ${data(1)}}');\n" | 4496 " reply.send('echoing ${data(1)}}');\n" |
4641 "}\n" | 4497 "}\n" |
4642 "class Test extends NativeFieldWrapperClass2 {\n" | 4498 "class Test extends NativeFieldWrapperClass2 {\n" |
(...skipping 17 matching lines...) Expand all Loading... |
4660 // Create a test library and Load up a test script in it. | 4516 // Create a test library and Load up a test script in it. |
4661 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4517 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4662 | 4518 |
4663 // Invoke 'main' which should spawn an isolate and try to send an | 4519 // Invoke 'main' which should spawn an isolate and try to send an |
4664 // object with native fields over to the spawned isolate. This | 4520 // object with native fields over to the spawned isolate. This |
4665 // should result in an unhandled exception which is checked. | 4521 // should result in an unhandled exception which is checked. |
4666 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 4522 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
4667 EXPECT(Dart_IsError(retobj)); | 4523 EXPECT(Dart_IsError(retobj)); |
4668 } | 4524 } |
4669 | 4525 |
4670 | |
4671 TEST_CASE(GetStaticField_RunsInitializer) { | 4526 TEST_CASE(GetStaticField_RunsInitializer) { |
4672 const char* kScriptChars = | 4527 const char* kScriptChars = |
4673 "class TestClass {\n" | 4528 "class TestClass {\n" |
4674 " static const int fld1 = 7;\n" | 4529 " static const int fld1 = 7;\n" |
4675 " static int fld2 = 11;\n" | 4530 " static int fld2 = 11;\n" |
4676 " static void testMain() {\n" | 4531 " static void testMain() {\n" |
4677 " }\n" | 4532 " }\n" |
4678 "}\n"; | 4533 "}\n"; |
4679 Dart_Handle result; | 4534 Dart_Handle result; |
4680 // Create a test library and Load up a test script in it. | 4535 // Create a test library and Load up a test script in it. |
(...skipping 21 matching lines...) Expand all Loading... |
4702 result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13)); | 4557 result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13)); |
4703 EXPECT_VALID(result); | 4558 EXPECT_VALID(result); |
4704 | 4559 |
4705 // We now get the new value for fld2, not the initializer | 4560 // We now get the new value for fld2, not the initializer |
4706 result = Dart_GetField(type, NewString("fld2")); | 4561 result = Dart_GetField(type, NewString("fld2")); |
4707 EXPECT_VALID(result); | 4562 EXPECT_VALID(result); |
4708 result = Dart_IntegerToInt64(result, &value); | 4563 result = Dart_IntegerToInt64(result, &value); |
4709 EXPECT_EQ(13, value); | 4564 EXPECT_EQ(13, value); |
4710 } | 4565 } |
4711 | 4566 |
4712 | |
4713 TEST_CASE(GetField_CheckIsolate) { | 4567 TEST_CASE(GetField_CheckIsolate) { |
4714 const char* kScriptChars = | 4568 const char* kScriptChars = |
4715 "class TestClass {\n" | 4569 "class TestClass {\n" |
4716 " static int fld2 = 11;\n" | 4570 " static int fld2 = 11;\n" |
4717 " static void testMain() {\n" | 4571 " static void testMain() {\n" |
4718 " }\n" | 4572 " }\n" |
4719 "}\n"; | 4573 "}\n"; |
4720 Dart_Handle result; | 4574 Dart_Handle result; |
4721 int64_t value = 0; | 4575 int64_t value = 0; |
4722 | 4576 |
4723 // Create a test library and Load up a test script in it. | 4577 // Create a test library and Load up a test script in it. |
4724 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4578 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4725 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL); | 4579 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL); |
4726 EXPECT_VALID(type); | 4580 EXPECT_VALID(type); |
4727 | 4581 |
4728 result = Dart_GetField(type, NewString("fld2")); | 4582 result = Dart_GetField(type, NewString("fld2")); |
4729 EXPECT_VALID(result); | 4583 EXPECT_VALID(result); |
4730 result = Dart_IntegerToInt64(result, &value); | 4584 result = Dart_IntegerToInt64(result, &value); |
4731 EXPECT_EQ(11, value); | 4585 EXPECT_EQ(11, value); |
4732 } | 4586 } |
4733 | 4587 |
4734 | |
4735 TEST_CASE(SetField_CheckIsolate) { | 4588 TEST_CASE(SetField_CheckIsolate) { |
4736 const char* kScriptChars = | 4589 const char* kScriptChars = |
4737 "class TestClass {\n" | 4590 "class TestClass {\n" |
4738 " static int fld2 = 11;\n" | 4591 " static int fld2 = 11;\n" |
4739 " static void testMain() {\n" | 4592 " static void testMain() {\n" |
4740 " }\n" | 4593 " }\n" |
4741 "}\n"; | 4594 "}\n"; |
4742 Dart_Handle result; | 4595 Dart_Handle result; |
4743 int64_t value = 0; | 4596 int64_t value = 0; |
4744 | 4597 |
4745 // Create a test library and Load up a test script in it. | 4598 // Create a test library and Load up a test script in it. |
4746 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4599 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4747 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL); | 4600 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL); |
4748 EXPECT_VALID(type); | 4601 EXPECT_VALID(type); |
4749 | 4602 |
4750 result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13)); | 4603 result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13)); |
4751 EXPECT_VALID(result); | 4604 EXPECT_VALID(result); |
4752 | 4605 |
4753 result = Dart_GetField(type, NewString("fld2")); | 4606 result = Dart_GetField(type, NewString("fld2")); |
4754 EXPECT_VALID(result); | 4607 EXPECT_VALID(result); |
4755 result = Dart_IntegerToInt64(result, &value); | 4608 result = Dart_IntegerToInt64(result, &value); |
4756 EXPECT_EQ(13, value); | 4609 EXPECT_EQ(13, value); |
4757 } | 4610 } |
4758 | 4611 |
4759 | |
4760 TEST_CASE(New) { | 4612 TEST_CASE(New) { |
4761 const char* kScriptChars = | 4613 const char* kScriptChars = |
4762 "class MyClass {\n" | 4614 "class MyClass {\n" |
4763 " MyClass() : foo = 7 {}\n" | 4615 " MyClass() : foo = 7 {}\n" |
4764 " MyClass.named(value) : foo = value {}\n" | 4616 " MyClass.named(value) : foo = value {}\n" |
4765 " MyClass._hidden(value) : foo = -value {}\n" | 4617 " MyClass._hidden(value) : foo = -value {}\n" |
4766 " MyClass.exception(value) : foo = value {\n" | 4618 " MyClass.exception(value) : foo = value {\n" |
4767 " throw 'ConstructorDeath';\n" | 4619 " throw 'ConstructorDeath';\n" |
4768 " }\n" | 4620 " }\n" |
4769 " factory MyClass.multiply(value) {\n" | 4621 " factory MyClass.multiply(value) {\n" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4981 result = Dart_New(intf, Dart_Null(), 0, NULL); | 4833 result = Dart_New(intf, Dart_Null(), 0, NULL); |
4982 EXPECT_ERROR(result, "Dart_New: could not find constructor 'MyInterface.'."); | 4834 EXPECT_ERROR(result, "Dart_New: could not find constructor 'MyInterface.'."); |
4983 | 4835 |
4984 // Invoke abstract constructor that is present in the interface. | 4836 // Invoke abstract constructor that is present in the interface. |
4985 result = Dart_New(intf, NewString("notfound"), 1, args); | 4837 result = Dart_New(intf, NewString("notfound"), 1, args); |
4986 EXPECT_VALID(result); | 4838 EXPECT_VALID(result); |
4987 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); | 4839 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
4988 EXPECT(!instanceOf); | 4840 EXPECT(!instanceOf); |
4989 } | 4841 } |
4990 | 4842 |
4991 | |
4992 TEST_CASE(New_Issue2971) { | 4843 TEST_CASE(New_Issue2971) { |
4993 // Issue 2971: We were unable to use Dart_New to construct an | 4844 // Issue 2971: We were unable to use Dart_New to construct an |
4994 // instance of List, due to problems implementing interface | 4845 // instance of List, due to problems implementing interface |
4995 // factories. | 4846 // factories. |
4996 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); | 4847 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); |
4997 EXPECT_VALID(core_lib); | 4848 EXPECT_VALID(core_lib); |
4998 Dart_Handle list_type = Dart_GetType(core_lib, NewString("List"), 0, NULL); | 4849 Dart_Handle list_type = Dart_GetType(core_lib, NewString("List"), 0, NULL); |
4999 EXPECT_VALID(list_type); | 4850 EXPECT_VALID(list_type); |
5000 | 4851 |
5001 const int kNumArgs = 1; | 4852 const int kNumArgs = 1; |
5002 Dart_Handle args[kNumArgs]; | 4853 Dart_Handle args[kNumArgs]; |
5003 args[0] = Dart_NewInteger(1); | 4854 args[0] = Dart_NewInteger(1); |
5004 Dart_Handle list_obj = Dart_New(list_type, Dart_Null(), kNumArgs, args); | 4855 Dart_Handle list_obj = Dart_New(list_type, Dart_Null(), kNumArgs, args); |
5005 EXPECT_VALID(list_obj); | 4856 EXPECT_VALID(list_obj); |
5006 EXPECT(Dart_IsList(list_obj)); | 4857 EXPECT(Dart_IsList(list_obj)); |
5007 } | 4858 } |
5008 | 4859 |
5009 | |
5010 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { | 4860 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { |
5011 EXPECT(Dart_IsLibrary(lib)); | 4861 EXPECT(Dart_IsLibrary(lib)); |
5012 Thread* thread = Thread::Current(); | 4862 Thread* thread = Thread::Current(); |
5013 const Library& library_obj = Api::UnwrapLibraryHandle(thread->zone(), lib); | 4863 const Library& library_obj = Api::UnwrapLibraryHandle(thread->zone(), lib); |
5014 const String& name = String::Handle(String::New(str)); | 4864 const String& name = String::Handle(String::New(str)); |
5015 return Api::NewHandle(thread, library_obj.PrivateName(name)); | 4865 return Api::NewHandle(thread, library_obj.PrivateName(name)); |
5016 } | 4866 } |
5017 | 4867 |
5018 | |
5019 TEST_CASE(Invoke) { | 4868 TEST_CASE(Invoke) { |
5020 const char* kScriptChars = | 4869 const char* kScriptChars = |
5021 "class BaseMethods {\n" | 4870 "class BaseMethods {\n" |
5022 " inheritedMethod(arg) => 'inherited $arg';\n" | 4871 " inheritedMethod(arg) => 'inherited $arg';\n" |
5023 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" | 4872 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" |
5024 "}\n" | 4873 "}\n" |
5025 "\n" | 4874 "\n" |
5026 "class Methods extends BaseMethods {\n" | 4875 "class Methods extends BaseMethods {\n" |
5027 " instanceMethod(arg) => 'instance $arg';\n" | 4876 " instanceMethod(arg) => 'instance $arg';\n" |
5028 " _instanceMethod(arg) => 'hidden instance $arg';\n" | 4877 " _instanceMethod(arg) => 'hidden instance $arg';\n" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5128 // Hidden top-level method. | 4977 // Hidden top-level method. |
5129 name = NewString("_topMethod"); | 4978 name = NewString("_topMethod"); |
5130 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args))); | 4979 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args))); |
5131 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 4980 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
5132 result = Dart_Invoke(lib, name, 1, args); | 4981 result = Dart_Invoke(lib, name, 1, args); |
5133 EXPECT_VALID(result); | 4982 EXPECT_VALID(result); |
5134 result = Dart_StringToCString(result, &str); | 4983 result = Dart_StringToCString(result, &str); |
5135 EXPECT_STREQ("hidden top !!!", str); | 4984 EXPECT_STREQ("hidden top !!!", str); |
5136 } | 4985 } |
5137 | 4986 |
5138 | |
5139 TEST_CASE(Invoke_PrivateStatic) { | 4987 TEST_CASE(Invoke_PrivateStatic) { |
5140 const char* kScriptChars = | 4988 const char* kScriptChars = |
5141 "class Methods {\n" | 4989 "class Methods {\n" |
5142 " static _staticMethod(arg) => 'hidden static $arg';\n" | 4990 " static _staticMethod(arg) => 'hidden static $arg';\n" |
5143 "}\n" | 4991 "}\n" |
5144 "\n"; | 4992 "\n"; |
5145 | 4993 |
5146 // Shared setup. | 4994 // Shared setup. |
5147 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4995 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
5148 Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL); | 4996 Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL); |
5149 Dart_Handle result; | 4997 Dart_Handle result; |
5150 EXPECT_VALID(type); | 4998 EXPECT_VALID(type); |
5151 Dart_Handle name = NewString("_staticMethod"); | 4999 Dart_Handle name = NewString("_staticMethod"); |
5152 EXPECT_VALID(name); | 5000 EXPECT_VALID(name); |
5153 | 5001 |
5154 Dart_Handle args[1]; | 5002 Dart_Handle args[1]; |
5155 args[0] = NewString("!!!"); | 5003 args[0] = NewString("!!!"); |
5156 result = Dart_Invoke(type, name, 1, args); | 5004 result = Dart_Invoke(type, name, 1, args); |
5157 EXPECT_VALID(result); | 5005 EXPECT_VALID(result); |
5158 | 5006 |
5159 const char* str = NULL; | 5007 const char* str = NULL; |
5160 result = Dart_StringToCString(result, &str); | 5008 result = Dart_StringToCString(result, &str); |
5161 EXPECT_STREQ("hidden static !!!", str); | 5009 EXPECT_STREQ("hidden static !!!", str); |
5162 } | 5010 } |
5163 | 5011 |
5164 | |
5165 TEST_CASE(Invoke_FunnyArgs) { | 5012 TEST_CASE(Invoke_FunnyArgs) { |
5166 const char* kScriptChars = "test(arg) => 'hello $arg';\n"; | 5013 const char* kScriptChars = "test(arg) => 'hello $arg';\n"; |
5167 | 5014 |
5168 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5015 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
5169 Dart_Handle func_name = NewString("test"); | 5016 Dart_Handle func_name = NewString("test"); |
5170 Dart_Handle args[1]; | 5017 Dart_Handle args[1]; |
5171 const char* str; | 5018 const char* str; |
5172 | 5019 |
5173 // Make sure that valid args yield valid results. | 5020 // Make sure that valid args yield valid results. |
5174 args[0] = NewString("!!!"); | 5021 args[0] = NewString("!!!"); |
(...skipping 26 matching lines...) Expand all Loading... |
5201 EXPECT_STREQ("Dart_Invoke expects arguments[0] to be an Instance handle.", | 5048 EXPECT_STREQ("Dart_Invoke expects arguments[0] to be an Instance handle.", |
5202 Dart_GetError(result)); | 5049 Dart_GetError(result)); |
5203 | 5050 |
5204 // Pass an error handle as a parameter. The error is propagated. | 5051 // Pass an error handle as a parameter. The error is propagated. |
5205 args[0] = Api::NewError("myerror"); | 5052 args[0] = Api::NewError("myerror"); |
5206 result = Dart_Invoke(lib, func_name, 1, args); | 5053 result = Dart_Invoke(lib, func_name, 1, args); |
5207 EXPECT(Dart_IsError(result)); | 5054 EXPECT(Dart_IsError(result)); |
5208 EXPECT_STREQ("myerror", Dart_GetError(result)); | 5055 EXPECT_STREQ("myerror", Dart_GetError(result)); |
5209 } | 5056 } |
5210 | 5057 |
5211 | |
5212 TEST_CASE(Invoke_Null) { | 5058 TEST_CASE(Invoke_Null) { |
5213 Dart_Handle result = Dart_Invoke(Dart_Null(), NewString("toString"), 0, NULL); | 5059 Dart_Handle result = Dart_Invoke(Dart_Null(), NewString("toString"), 0, NULL); |
5214 EXPECT_VALID(result); | 5060 EXPECT_VALID(result); |
5215 EXPECT(Dart_IsString(result)); | 5061 EXPECT(Dart_IsString(result)); |
5216 | 5062 |
5217 const char* value = ""; | 5063 const char* value = ""; |
5218 EXPECT_VALID(Dart_StringToCString(result, &value)); | 5064 EXPECT_VALID(Dart_StringToCString(result, &value)); |
5219 EXPECT_STREQ("null", value); | 5065 EXPECT_STREQ("null", value); |
5220 | 5066 |
5221 Dart_Handle function_name = NewString("NoNoNo"); | 5067 Dart_Handle function_name = NewString("NoNoNo"); |
5222 result = Dart_Invoke(Dart_Null(), function_name, 0, NULL); | 5068 result = Dart_Invoke(Dart_Null(), function_name, 0, NULL); |
5223 EXPECT(Dart_IsError(result)); | 5069 EXPECT(Dart_IsError(result)); |
5224 EXPECT(Dart_ErrorHasException(result)); | 5070 EXPECT(Dart_ErrorHasException(result)); |
5225 } | 5071 } |
5226 | 5072 |
5227 | |
5228 TEST_CASE(InvokeNoSuchMethod) { | 5073 TEST_CASE(InvokeNoSuchMethod) { |
5229 const char* kScriptChars = | 5074 const char* kScriptChars = |
5230 "import 'dart:_internal' as _internal;\n" | 5075 "import 'dart:_internal' as _internal;\n" |
5231 "class Expect {\n" | 5076 "class Expect {\n" |
5232 " static equals(a, b) {\n" | 5077 " static equals(a, b) {\n" |
5233 " if (a != b) {\n" | 5078 " if (a != b) {\n" |
5234 " throw 'not equal. expected: $a, got: $b';\n" | 5079 " throw 'not equal. expected: $a, got: $b';\n" |
5235 " }\n" | 5080 " }\n" |
5236 " }\n" | 5081 " }\n" |
5237 "}\n" | 5082 "}\n" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5282 result = Dart_Invoke(instance, NewString("method"), 0, NULL); | 5127 result = Dart_Invoke(instance, NewString("method"), 0, NULL); |
5283 EXPECT_VALID(result); | 5128 EXPECT_VALID(result); |
5284 | 5129 |
5285 result = Dart_GetField(type, NewString("fld1")); | 5130 result = Dart_GetField(type, NewString("fld1")); |
5286 EXPECT_VALID(result); | 5131 EXPECT_VALID(result); |
5287 int64_t value = 0; | 5132 int64_t value = 0; |
5288 result = Dart_IntegerToInt64(result, &value); | 5133 result = Dart_IntegerToInt64(result, &value); |
5289 EXPECT_EQ(3, value); | 5134 EXPECT_EQ(3, value); |
5290 } | 5135 } |
5291 | 5136 |
5292 | |
5293 TEST_CASE(Invoke_CrossLibrary) { | 5137 TEST_CASE(Invoke_CrossLibrary) { |
5294 const char* kLibrary1Chars = | 5138 const char* kLibrary1Chars = |
5295 "library library1_name;\n" | 5139 "library library1_name;\n" |
5296 "void local() {}\n" | 5140 "void local() {}\n" |
5297 "void _local() {}\n"; | 5141 "void _local() {}\n"; |
5298 const char* kLibrary2Chars = | 5142 const char* kLibrary2Chars = |
5299 "library library2_name;\n" | 5143 "library library2_name;\n" |
5300 "void imported() {}\n" | 5144 "void imported() {}\n" |
5301 "void _imported() {}\n"; | 5145 "void _imported() {}\n"; |
5302 | 5146 |
(...skipping 18 matching lines...) Expand all Loading... |
5321 // We can invoke both private and non-private local functions. | 5165 // We can invoke both private and non-private local functions. |
5322 EXPECT_VALID(Dart_Invoke(lib1, NewString("local"), 0, NULL)); | 5166 EXPECT_VALID(Dart_Invoke(lib1, NewString("local"), 0, NULL)); |
5323 EXPECT_VALID(Dart_Invoke(lib1, NewString("_local"), 0, NULL)); | 5167 EXPECT_VALID(Dart_Invoke(lib1, NewString("_local"), 0, NULL)); |
5324 | 5168 |
5325 // We can only invoke non-private imported functions. | 5169 // We can only invoke non-private imported functions. |
5326 EXPECT_VALID(Dart_Invoke(lib1, NewString("imported"), 0, NULL)); | 5170 EXPECT_VALID(Dart_Invoke(lib1, NewString("imported"), 0, NULL)); |
5327 EXPECT_ERROR(Dart_Invoke(lib1, NewString("_imported"), 0, NULL), | 5171 EXPECT_ERROR(Dart_Invoke(lib1, NewString("_imported"), 0, NULL), |
5328 "did not find top-level function '_imported'"); | 5172 "did not find top-level function '_imported'"); |
5329 } | 5173 } |
5330 | 5174 |
5331 | |
5332 TEST_CASE(InvokeClosure) { | 5175 TEST_CASE(InvokeClosure) { |
5333 const char* kScriptChars = | 5176 const char* kScriptChars = |
5334 "class InvokeClosure {\n" | 5177 "class InvokeClosure {\n" |
5335 " InvokeClosure(int i, int j) : fld1 = i, fld2 = j {}\n" | 5178 " InvokeClosure(int i, int j) : fld1 = i, fld2 = j {}\n" |
5336 " Function method1(int i) {\n" | 5179 " Function method1(int i) {\n" |
5337 " f(int j) => j + i + fld1 + fld2 + fld4; \n" | 5180 " f(int j) => j + i + fld1 + fld2 + fld4; \n" |
5338 " return f;\n" | 5181 " return f;\n" |
5339 " }\n" | 5182 " }\n" |
5340 " static Function method2(int i) {\n" | 5183 " static Function method2(int i) {\n" |
5341 " n(int j) => true + i + fld4; \n" | 5184 " n(int j) => true + i + fld4; \n" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5388 EXPECT(Dart_IsClosure(retobj)); | 5231 EXPECT(Dart_IsClosure(retobj)); |
5389 EXPECT(!Dart_IsClosure(NewString("abcdef"))); | 5232 EXPECT(!Dart_IsClosure(NewString("abcdef"))); |
5390 | 5233 |
5391 // Now invoke the closure and check the result (should be an exception). | 5234 // Now invoke the closure and check the result (should be an exception). |
5392 dart_arguments[0] = Dart_NewInteger(1); | 5235 dart_arguments[0] = Dart_NewInteger(1); |
5393 result = Dart_InvokeClosure(retobj, 1, dart_arguments); | 5236 result = Dart_InvokeClosure(retobj, 1, dart_arguments); |
5394 EXPECT(Dart_IsError(result)); | 5237 EXPECT(Dart_IsError(result)); |
5395 EXPECT(Dart_ErrorHasException(result)); | 5238 EXPECT(Dart_ErrorHasException(result)); |
5396 } | 5239 } |
5397 | 5240 |
5398 | |
5399 void ExceptionNative(Dart_NativeArguments args) { | 5241 void ExceptionNative(Dart_NativeArguments args) { |
5400 Dart_EnterScope(); | 5242 Dart_EnterScope(); |
5401 Dart_ThrowException(NewString("Hello from ExceptionNative!")); | 5243 Dart_ThrowException(NewString("Hello from ExceptionNative!")); |
5402 UNREACHABLE(); | 5244 UNREACHABLE(); |
5403 } | 5245 } |
5404 | 5246 |
5405 | |
5406 static Dart_NativeFunction native_lookup(Dart_Handle name, | 5247 static Dart_NativeFunction native_lookup(Dart_Handle name, |
5407 int argument_count, | 5248 int argument_count, |
5408 bool* auto_setup_scope) { | 5249 bool* auto_setup_scope) { |
5409 ASSERT(auto_setup_scope != NULL); | 5250 ASSERT(auto_setup_scope != NULL); |
5410 *auto_setup_scope = true; | 5251 *auto_setup_scope = true; |
5411 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); | 5252 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); |
5412 } | 5253 } |
5413 | 5254 |
5414 | |
5415 TEST_CASE(ThrowException) { | 5255 TEST_CASE(ThrowException) { |
5416 const char* kScriptChars = "int test() native \"ThrowException_native\";"; | 5256 const char* kScriptChars = "int test() native \"ThrowException_native\";"; |
5417 Dart_Handle result; | 5257 Dart_Handle result; |
5418 intptr_t size = thread->ZoneSizeInBytes(); | 5258 intptr_t size = thread->ZoneSizeInBytes(); |
5419 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 5259 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
5420 | 5260 |
5421 // Load up a test script which extends the native wrapper class. | 5261 // Load up a test script which extends the native wrapper class. |
5422 Dart_Handle lib = TestCase::LoadTestScript( | 5262 Dart_Handle lib = TestCase::LoadTestScript( |
5423 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | 5263 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
5424 | 5264 |
5425 // Throwing an exception here should result in an error. | 5265 // Throwing an exception here should result in an error. |
5426 result = Dart_ThrowException(NewString("This doesn't work")); | 5266 result = Dart_ThrowException(NewString("This doesn't work")); |
5427 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); | 5267 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); |
5428 EXPECT(!Dart_ErrorHasException(result)); | 5268 EXPECT(!Dart_ErrorHasException(result)); |
5429 | 5269 |
5430 // Invoke 'test' and check for an uncaught exception. | 5270 // Invoke 'test' and check for an uncaught exception. |
5431 result = Dart_Invoke(lib, NewString("test"), 0, NULL); | 5271 result = Dart_Invoke(lib, NewString("test"), 0, NULL); |
5432 EXPECT_ERROR(result, "Hello from ExceptionNative!"); | 5272 EXPECT_ERROR(result, "Hello from ExceptionNative!"); |
5433 EXPECT(Dart_ErrorHasException(result)); | 5273 EXPECT(Dart_ErrorHasException(result)); |
5434 | 5274 |
5435 Dart_ExitScope(); // Exit the Dart API scope. | 5275 Dart_ExitScope(); // Exit the Dart API scope. |
5436 EXPECT_EQ(size, thread->ZoneSizeInBytes()); | 5276 EXPECT_EQ(size, thread->ZoneSizeInBytes()); |
5437 } | 5277 } |
5438 | 5278 |
5439 | |
5440 static intptr_t kNativeArgumentNativeField1Value = 30; | 5279 static intptr_t kNativeArgumentNativeField1Value = 30; |
5441 static intptr_t kNativeArgumentNativeField2Value = 40; | 5280 static intptr_t kNativeArgumentNativeField2Value = 40; |
5442 static intptr_t native_arg_str_peer = 100; | 5281 static intptr_t native_arg_str_peer = 100; |
5443 static void NativeArgumentCreate(Dart_NativeArguments args) { | 5282 static void NativeArgumentCreate(Dart_NativeArguments args) { |
5444 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 5283 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
5445 Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL); | 5284 Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL); |
5446 EXPECT_VALID(type); | 5285 EXPECT_VALID(type); |
5447 | 5286 |
5448 // Allocate without a constructor. | 5287 // Allocate without a constructor. |
5449 const int num_native_fields = 2; | 5288 const int num_native_fields = 2; |
5450 const intptr_t native_fields[] = {kNativeArgumentNativeField1Value, | 5289 const intptr_t native_fields[] = {kNativeArgumentNativeField1Value, |
5451 kNativeArgumentNativeField2Value}; | 5290 kNativeArgumentNativeField2Value}; |
5452 // Allocate and Setup native fields. | 5291 // Allocate and Setup native fields. |
5453 Dart_Handle obj = | 5292 Dart_Handle obj = |
5454 Dart_AllocateWithNativeFields(type, num_native_fields, native_fields); | 5293 Dart_AllocateWithNativeFields(type, num_native_fields, native_fields); |
5455 EXPECT_VALID(obj); | 5294 EXPECT_VALID(obj); |
5456 | 5295 |
5457 kNativeArgumentNativeField1Value *= 2; | 5296 kNativeArgumentNativeField1Value *= 2; |
5458 kNativeArgumentNativeField2Value *= 2; | 5297 kNativeArgumentNativeField2Value *= 2; |
5459 Dart_SetReturnValue(args, obj); | 5298 Dart_SetReturnValue(args, obj); |
5460 } | 5299 } |
5461 | 5300 |
5462 | |
5463 static void NativeArgumentAccess(Dart_NativeArguments args) { | 5301 static void NativeArgumentAccess(Dart_NativeArguments args) { |
5464 const int kNumNativeFields = 2; | 5302 const int kNumNativeFields = 2; |
5465 | 5303 |
5466 // Test different argument types with a valid descriptor set. | 5304 // Test different argument types with a valid descriptor set. |
5467 { | 5305 { |
5468 const char* cstr = NULL; | 5306 const char* cstr = NULL; |
5469 intptr_t native_fields1[kNumNativeFields]; | 5307 intptr_t native_fields1[kNumNativeFields]; |
5470 intptr_t native_fields2[kNumNativeFields]; | 5308 intptr_t native_fields2[kNumNativeFields]; |
5471 const Dart_NativeArgument_Descriptor arg_descriptors[9] = { | 5309 const Dart_NativeArgument_Descriptor arg_descriptors[9] = { |
5472 {Dart_NativeArgument_kNativeFields, 0}, | 5310 {Dart_NativeArgument_kNativeFields, 0}, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5552 }; | 5390 }; |
5553 Dart_NativeArgument_Value arg_values[8]; | 5391 Dart_NativeArgument_Value arg_values[8]; |
5554 Dart_Handle result = | 5392 Dart_Handle result = |
5555 Dart_GetNativeArguments(args, 8, arg_descriptors, arg_values); | 5393 Dart_GetNativeArguments(args, 8, arg_descriptors, arg_values); |
5556 EXPECT(Dart_IsError(result)); | 5394 EXPECT(Dart_IsError(result)); |
5557 } | 5395 } |
5558 | 5396 |
5559 Dart_SetIntegerReturnValue(args, 0); | 5397 Dart_SetIntegerReturnValue(args, 0); |
5560 } | 5398 } |
5561 | 5399 |
5562 | |
5563 static Dart_NativeFunction native_args_lookup(Dart_Handle name, | 5400 static Dart_NativeFunction native_args_lookup(Dart_Handle name, |
5564 int argument_count, | 5401 int argument_count, |
5565 bool* auto_scope_setup) { | 5402 bool* auto_scope_setup) { |
5566 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 5403 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
5567 if (!obj.IsString()) { | 5404 if (!obj.IsString()) { |
5568 return NULL; | 5405 return NULL; |
5569 } | 5406 } |
5570 ASSERT(auto_scope_setup != NULL); | 5407 ASSERT(auto_scope_setup != NULL); |
5571 *auto_scope_setup = true; | 5408 *auto_scope_setup = true; |
5572 const char* function_name = obj.ToCString(); | 5409 const char* function_name = obj.ToCString(); |
5573 ASSERT(function_name != NULL); | 5410 ASSERT(function_name != NULL); |
5574 if (!strcmp(function_name, "NativeArgument_Create")) { | 5411 if (!strcmp(function_name, "NativeArgument_Create")) { |
5575 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCreate); | 5412 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCreate); |
5576 } else if (!strcmp(function_name, "NativeArgument_Access")) { | 5413 } else if (!strcmp(function_name, "NativeArgument_Access")) { |
5577 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentAccess); | 5414 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentAccess); |
5578 } | 5415 } |
5579 return NULL; | 5416 return NULL; |
5580 } | 5417 } |
5581 | 5418 |
5582 | |
5583 TEST_CASE(GetNativeArguments) { | 5419 TEST_CASE(GetNativeArguments) { |
5584 const bool saved_flag = FLAG_support_externalizable_strings; | 5420 const bool saved_flag = FLAG_support_externalizable_strings; |
5585 FLAG_support_externalizable_strings = true; | 5421 FLAG_support_externalizable_strings = true; |
5586 | 5422 |
5587 const char* kScriptChars = | 5423 const char* kScriptChars = |
5588 "import 'dart:nativewrappers';" | 5424 "import 'dart:nativewrappers';" |
5589 "class MyObject extends NativeFieldWrapperClass2 {" | 5425 "class MyObject extends NativeFieldWrapperClass2 {" |
5590 " static MyObject createObject() native 'NativeArgument_Create';" | 5426 " static MyObject createObject() native 'NativeArgument_Create';" |
5591 " int accessFields(int arg1," | 5427 " int accessFields(int arg1," |
5592 " int arg2," | 5428 " int arg2," |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5624 | 5460 |
5625 Dart_Handle args[1]; | 5461 Dart_Handle args[1]; |
5626 args[0] = extstr; | 5462 args[0] = extstr; |
5627 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, args); | 5463 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, args); |
5628 EXPECT_VALID(result); | 5464 EXPECT_VALID(result); |
5629 EXPECT(Dart_IsInteger(result)); | 5465 EXPECT(Dart_IsInteger(result)); |
5630 | 5466 |
5631 FLAG_support_externalizable_strings = saved_flag; | 5467 FLAG_support_externalizable_strings = saved_flag; |
5632 } | 5468 } |
5633 | 5469 |
5634 | |
5635 static void NativeArgumentCounter(Dart_NativeArguments args) { | 5470 static void NativeArgumentCounter(Dart_NativeArguments args) { |
5636 Dart_EnterScope(); | 5471 Dart_EnterScope(); |
5637 int count = Dart_GetNativeArgumentCount(args); | 5472 int count = Dart_GetNativeArgumentCount(args); |
5638 Dart_SetReturnValue(args, Dart_NewInteger(count)); | 5473 Dart_SetReturnValue(args, Dart_NewInteger(count)); |
5639 Dart_ExitScope(); | 5474 Dart_ExitScope(); |
5640 } | 5475 } |
5641 | 5476 |
5642 | |
5643 static Dart_NativeFunction gnac_lookup(Dart_Handle name, | 5477 static Dart_NativeFunction gnac_lookup(Dart_Handle name, |
5644 int argument_count, | 5478 int argument_count, |
5645 bool* auto_setup_scope) { | 5479 bool* auto_setup_scope) { |
5646 ASSERT(auto_setup_scope != NULL); | 5480 ASSERT(auto_setup_scope != NULL); |
5647 *auto_setup_scope = true; | 5481 *auto_setup_scope = true; |
5648 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); | 5482 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); |
5649 } | 5483 } |
5650 | 5484 |
5651 | |
5652 TEST_CASE(GetNativeArgumentCount) { | 5485 TEST_CASE(GetNativeArgumentCount) { |
5653 const char* kScriptChars = | 5486 const char* kScriptChars = |
5654 "class MyObject {" | 5487 "class MyObject {" |
5655 " int method1(int i, int j) native 'Name_Does_Not_Matter';" | 5488 " int method1(int i, int j) native 'Name_Does_Not_Matter';" |
5656 "}" | 5489 "}" |
5657 "testMain() {" | 5490 "testMain() {" |
5658 " MyObject obj = new MyObject();" | 5491 " MyObject obj = new MyObject();" |
5659 " return obj.method1(77, 125);" | 5492 " return obj.method1(77, 125);" |
5660 "}"; | 5493 "}"; |
5661 | 5494 |
5662 Dart_Handle lib = TestCase::LoadTestScript( | 5495 Dart_Handle lib = TestCase::LoadTestScript( |
5663 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); | 5496 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); |
5664 | 5497 |
5665 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 5498 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
5666 EXPECT_VALID(result); | 5499 EXPECT_VALID(result); |
5667 EXPECT(Dart_IsInteger(result)); | 5500 EXPECT(Dart_IsInteger(result)); |
5668 | 5501 |
5669 int64_t value = 0; | 5502 int64_t value = 0; |
5670 result = Dart_IntegerToInt64(result, &value); | 5503 result = Dart_IntegerToInt64(result, &value); |
5671 EXPECT_VALID(result); | 5504 EXPECT_VALID(result); |
5672 EXPECT_EQ(3, value); | 5505 EXPECT_EQ(3, value); |
5673 } | 5506 } |
5674 | 5507 |
5675 | |
5676 TEST_CASE(GetType) { | 5508 TEST_CASE(GetType) { |
5677 const char* kScriptChars = | 5509 const char* kScriptChars = |
5678 "library testlib;\n" | 5510 "library testlib;\n" |
5679 "class Class {\n" | 5511 "class Class {\n" |
5680 " static var name = 'Class';\n" | 5512 " static var name = 'Class';\n" |
5681 "}\n" | 5513 "}\n" |
5682 "\n" | 5514 "\n" |
5683 "class _Class {\n" | 5515 "class _Class {\n" |
5684 " static var name = '_Class';\n" | 5516 " static var name = '_Class';\n" |
5685 "}\n"; | 5517 "}\n"; |
(...skipping 28 matching lines...) Expand all Loading... |
5714 type = Dart_GetType(Api::NewError("myerror"), NewString("Class"), 0, NULL); | 5546 type = Dart_GetType(Api::NewError("myerror"), NewString("Class"), 0, NULL); |
5715 EXPECT(Dart_IsError(type)); | 5547 EXPECT(Dart_IsError(type)); |
5716 EXPECT_STREQ("myerror", Dart_GetError(type)); | 5548 EXPECT_STREQ("myerror", Dart_GetError(type)); |
5717 | 5549 |
5718 // Lookup a type using an error class name. The error propagates. | 5550 // Lookup a type using an error class name. The error propagates. |
5719 type = Dart_GetType(lib, Api::NewError("myerror"), 0, NULL); | 5551 type = Dart_GetType(lib, Api::NewError("myerror"), 0, NULL); |
5720 EXPECT(Dart_IsError(type)); | 5552 EXPECT(Dart_IsError(type)); |
5721 EXPECT_STREQ("myerror", Dart_GetError(type)); | 5553 EXPECT_STREQ("myerror", Dart_GetError(type)); |
5722 } | 5554 } |
5723 | 5555 |
5724 | |
5725 TEST_CASE(InstanceOf) { | 5556 TEST_CASE(InstanceOf) { |
5726 const char* kScriptChars = | 5557 const char* kScriptChars = |
5727 "class OtherClass {\n" | 5558 "class OtherClass {\n" |
5728 " static returnNull() { return null; }\n" | 5559 " static returnNull() { return null; }\n" |
5729 "}\n" | 5560 "}\n" |
5730 "class InstanceOfTest {\n" | 5561 "class InstanceOfTest {\n" |
5731 " InstanceOfTest() {}\n" | 5562 " InstanceOfTest() {}\n" |
5732 " static InstanceOfTest testMain() {\n" | 5563 " static InstanceOfTest testMain() {\n" |
5733 " return new InstanceOfTest();\n" | 5564 " return new InstanceOfTest();\n" |
5734 " }\n" | 5565 " }\n" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5780 | 5611 |
5781 result = Dart_ObjectIsType(null, otherType, &is_instance); | 5612 result = Dart_ObjectIsType(null, otherType, &is_instance); |
5782 EXPECT_VALID(result); | 5613 EXPECT_VALID(result); |
5783 EXPECT(!is_instance); | 5614 EXPECT(!is_instance); |
5784 | 5615 |
5785 // Check that error is returned if null is passed as a class argument. | 5616 // Check that error is returned if null is passed as a class argument. |
5786 result = Dart_ObjectIsType(null, null, &is_instance); | 5617 result = Dart_ObjectIsType(null, null, &is_instance); |
5787 EXPECT(Dart_IsError(result)); | 5618 EXPECT(Dart_IsError(result)); |
5788 } | 5619 } |
5789 | 5620 |
5790 | |
5791 static Dart_Handle library_handler(Dart_LibraryTag tag, | 5621 static Dart_Handle library_handler(Dart_LibraryTag tag, |
5792 Dart_Handle library, | 5622 Dart_Handle library, |
5793 Dart_Handle url) { | 5623 Dart_Handle url) { |
5794 if (tag == Dart_kCanonicalizeUrl) { | 5624 if (tag == Dart_kCanonicalizeUrl) { |
5795 return url; | 5625 return url; |
5796 } | 5626 } |
5797 return Api::Success(); | 5627 return Api::Success(); |
5798 } | 5628 } |
5799 | 5629 |
5800 | |
5801 TEST_CASE(LoadScript) { | 5630 TEST_CASE(LoadScript) { |
5802 const char* kScriptChars = | 5631 const char* kScriptChars = |
5803 "main() {" | 5632 "main() {" |
5804 " return 12345;" | 5633 " return 12345;" |
5805 "}"; | 5634 "}"; |
5806 Dart_Handle url = NewString(TestCase::url()); | 5635 Dart_Handle url = NewString(TestCase::url()); |
5807 Dart_Handle source = NewString(kScriptChars); | 5636 Dart_Handle source = NewString(kScriptChars); |
5808 Dart_Handle error = Dart_NewApiError("incoming error"); | 5637 Dart_Handle error = Dart_NewApiError("incoming error"); |
5809 Dart_Handle result; | 5638 Dart_Handle result; |
5810 | 5639 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5864 | 5693 |
5865 // Further calls to LoadScript are errors. | 5694 // Further calls to LoadScript are errors. |
5866 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5695 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
5867 EXPECT(Dart_IsError(result)); | 5696 EXPECT(Dart_IsError(result)); |
5868 EXPECT_STREQ( | 5697 EXPECT_STREQ( |
5869 "Dart_LoadScript: " | 5698 "Dart_LoadScript: " |
5870 "A script has already been loaded from 'test-lib'.", | 5699 "A script has already been loaded from 'test-lib'.", |
5871 Dart_GetError(result)); | 5700 Dart_GetError(result)); |
5872 } | 5701 } |
5873 | 5702 |
5874 | |
5875 TEST_CASE(RootLibrary) { | 5703 TEST_CASE(RootLibrary) { |
5876 const char* kScriptChars = | 5704 const char* kScriptChars = |
5877 "library testlib;" | 5705 "library testlib;" |
5878 "main() {" | 5706 "main() {" |
5879 " return 12345;" | 5707 " return 12345;" |
5880 "}"; | 5708 "}"; |
5881 | 5709 |
5882 Dart_Handle root_lib = Dart_RootLibrary(); | 5710 Dart_Handle root_lib = Dart_RootLibrary(); |
5883 EXPECT_VALID(root_lib); | 5711 EXPECT_VALID(root_lib); |
5884 EXPECT(Dart_IsNull(root_lib)); | 5712 EXPECT(Dart_IsNull(root_lib)); |
(...skipping 11 matching lines...) Expand all Loading... |
5896 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); | 5724 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); |
5897 EXPECT_STREQ("testlib", name_cstr); | 5725 EXPECT_STREQ("testlib", name_cstr); |
5898 | 5726 |
5899 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); | 5727 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); |
5900 EXPECT_VALID(lib_uri); | 5728 EXPECT_VALID(lib_uri); |
5901 EXPECT(!Dart_IsNull(lib_uri)); | 5729 EXPECT(!Dart_IsNull(lib_uri)); |
5902 const char* uri_cstr = ""; | 5730 const char* uri_cstr = ""; |
5903 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); | 5731 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); |
5904 EXPECT_STREQ(TestCase::url(), uri_cstr); | 5732 EXPECT_STREQ(TestCase::url(), uri_cstr); |
5905 | 5733 |
5906 | |
5907 Dart_Handle core_uri = Dart_NewStringFromCString("dart:core"); | 5734 Dart_Handle core_uri = Dart_NewStringFromCString("dart:core"); |
5908 Dart_Handle core_lib = Dart_LookupLibrary(core_uri); | 5735 Dart_Handle core_lib = Dart_LookupLibrary(core_uri); |
5909 EXPECT_VALID(core_lib); | 5736 EXPECT_VALID(core_lib); |
5910 EXPECT(Dart_IsLibrary(core_lib)); | 5737 EXPECT(Dart_IsLibrary(core_lib)); |
5911 | 5738 |
5912 Dart_Handle result = Dart_SetRootLibrary(core_uri); // Not a library. | 5739 Dart_Handle result = Dart_SetRootLibrary(core_uri); // Not a library. |
5913 EXPECT(Dart_IsError(result)); | 5740 EXPECT(Dart_IsError(result)); |
5914 root_lib = Dart_RootLibrary(); | 5741 root_lib = Dart_RootLibrary(); |
5915 lib_uri = Dart_LibraryUrl(root_lib); | 5742 lib_uri = Dart_LibraryUrl(root_lib); |
5916 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); | 5743 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); |
5917 EXPECT_STREQ(TestCase::url(), uri_cstr); // Root library didn't change. | 5744 EXPECT_STREQ(TestCase::url(), uri_cstr); // Root library didn't change. |
5918 | 5745 |
5919 result = Dart_SetRootLibrary(core_lib); | 5746 result = Dart_SetRootLibrary(core_lib); |
5920 EXPECT_VALID(result); | 5747 EXPECT_VALID(result); |
5921 root_lib = Dart_RootLibrary(); | 5748 root_lib = Dart_RootLibrary(); |
5922 lib_uri = Dart_LibraryUrl(root_lib); | 5749 lib_uri = Dart_LibraryUrl(root_lib); |
5923 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); | 5750 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); |
5924 EXPECT_STREQ("dart:core", uri_cstr); // Root library did change. | 5751 EXPECT_STREQ("dart:core", uri_cstr); // Root library did change. |
5925 | 5752 |
5926 result = Dart_SetRootLibrary(Dart_Null()); | 5753 result = Dart_SetRootLibrary(Dart_Null()); |
5927 EXPECT_VALID(result); | 5754 EXPECT_VALID(result); |
5928 root_lib = Dart_RootLibrary(); | 5755 root_lib = Dart_RootLibrary(); |
5929 EXPECT(Dart_IsNull(root_lib)); // Root library did change. | 5756 EXPECT(Dart_IsNull(root_lib)); // Root library did change. |
5930 } | 5757 } |
5931 | 5758 |
5932 | |
5933 static int index = 0; | 5759 static int index = 0; |
5934 | 5760 |
5935 | |
5936 static Dart_Handle import_library_handler(Dart_LibraryTag tag, | 5761 static Dart_Handle import_library_handler(Dart_LibraryTag tag, |
5937 Dart_Handle library, | 5762 Dart_Handle library, |
5938 Dart_Handle url) { | 5763 Dart_Handle url) { |
5939 if (tag == Dart_kCanonicalizeUrl) { | 5764 if (tag == Dart_kCanonicalizeUrl) { |
5940 return url; | 5765 return url; |
5941 } | 5766 } |
5942 EXPECT(Dart_IsString(url)); | 5767 EXPECT(Dart_IsString(url)); |
5943 const char* cstr = NULL; | 5768 const char* cstr = NULL; |
5944 EXPECT_VALID(Dart_StringToCString(url, &cstr)); | 5769 EXPECT_VALID(Dart_StringToCString(url, &cstr)); |
5945 switch (index) { | 5770 switch (index) { |
(...skipping 13 matching lines...) Expand all Loading... |
5959 EXPECT_STREQ("winnerwinner", cstr); | 5784 EXPECT_STREQ("winnerwinner", cstr); |
5960 break; | 5785 break; |
5961 default: | 5786 default: |
5962 EXPECT(false); | 5787 EXPECT(false); |
5963 return Api::NewError("invalid callback"); | 5788 return Api::NewError("invalid callback"); |
5964 } | 5789 } |
5965 index += 1; | 5790 index += 1; |
5966 return Api::Success(); | 5791 return Api::Success(); |
5967 } | 5792 } |
5968 | 5793 |
5969 | |
5970 TEST_CASE(LoadScript_CompileError) { | 5794 TEST_CASE(LoadScript_CompileError) { |
5971 const char* kScriptChars = ")"; | 5795 const char* kScriptChars = ")"; |
5972 Dart_Handle url = NewString(TestCase::url()); | 5796 Dart_Handle url = NewString(TestCase::url()); |
5973 Dart_Handle source = NewString(kScriptChars); | 5797 Dart_Handle source = NewString(kScriptChars); |
5974 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 5798 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
5975 EXPECT_VALID(result); | 5799 EXPECT_VALID(result); |
5976 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5800 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
5977 EXPECT(Dart_IsError(result)); | 5801 EXPECT(Dart_IsError(result)); |
5978 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 5802 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
5979 } | 5803 } |
5980 | 5804 |
5981 | |
5982 TEST_CASE(LookupLibrary) { | 5805 TEST_CASE(LookupLibrary) { |
5983 const char* kScriptChars = | 5806 const char* kScriptChars = |
5984 "import 'library1_dart';" | 5807 "import 'library1_dart';" |
5985 "main() {}"; | 5808 "main() {}"; |
5986 const char* kLibrary1Chars = | 5809 const char* kLibrary1Chars = |
5987 "library library1_dart;" | 5810 "library library1_dart;" |
5988 "import 'library2_dart';"; | 5811 "import 'library2_dart';"; |
5989 | 5812 |
5990 // Create a test library and Load up a test script in it. | 5813 // Create a test library and Load up a test script in it. |
5991 Dart_Handle url = NewString(TestCase::url()); | 5814 Dart_Handle url = NewString(TestCase::url()); |
(...skipping 26 matching lines...) Expand all Loading... |
6018 EXPECT(Dart_IsError(result)); | 5841 EXPECT(Dart_IsError(result)); |
6019 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5842 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6020 | 5843 |
6021 url = NewString("noodles.dart"); | 5844 url = NewString("noodles.dart"); |
6022 result = Dart_LookupLibrary(url); | 5845 result = Dart_LookupLibrary(url); |
6023 EXPECT(Dart_IsError(result)); | 5846 EXPECT(Dart_IsError(result)); |
6024 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", | 5847 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", |
6025 Dart_GetError(result)); | 5848 Dart_GetError(result)); |
6026 } | 5849 } |
6027 | 5850 |
6028 | |
6029 TEST_CASE(LibraryName) { | 5851 TEST_CASE(LibraryName) { |
6030 const char* kLibrary1Chars = "library library1_name;"; | 5852 const char* kLibrary1Chars = "library library1_name;"; |
6031 Dart_Handle url = NewString("library1_url"); | 5853 Dart_Handle url = NewString("library1_url"); |
6032 Dart_Handle source = NewString(kLibrary1Chars); | 5854 Dart_Handle source = NewString(kLibrary1Chars); |
6033 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 5855 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6034 Dart_Handle error = Dart_NewApiError("incoming error"); | 5856 Dart_Handle error = Dart_NewApiError("incoming error"); |
6035 EXPECT_VALID(lib); | 5857 EXPECT_VALID(lib); |
6036 | 5858 |
6037 Dart_Handle result = Dart_LibraryName(Dart_Null()); | 5859 Dart_Handle result = Dart_LibraryName(Dart_Null()); |
6038 EXPECT(Dart_IsError(result)); | 5860 EXPECT(Dart_IsError(result)); |
(...skipping 11 matching lines...) Expand all Loading... |
6050 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5872 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6051 | 5873 |
6052 result = Dart_LibraryName(lib); | 5874 result = Dart_LibraryName(lib); |
6053 EXPECT_VALID(result); | 5875 EXPECT_VALID(result); |
6054 EXPECT(Dart_IsString(result)); | 5876 EXPECT(Dart_IsString(result)); |
6055 const char* cstr = NULL; | 5877 const char* cstr = NULL; |
6056 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 5878 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
6057 EXPECT_STREQ("library1_name", cstr); | 5879 EXPECT_STREQ("library1_name", cstr); |
6058 } | 5880 } |
6059 | 5881 |
6060 | |
6061 #ifndef PRODUCT | 5882 #ifndef PRODUCT |
6062 | 5883 |
6063 | |
6064 TEST_CASE(LibraryId) { | 5884 TEST_CASE(LibraryId) { |
6065 const char* kLibrary1Chars = "library library1_name;"; | 5885 const char* kLibrary1Chars = "library library1_name;"; |
6066 Dart_Handle url = NewString("library1_url"); | 5886 Dart_Handle url = NewString("library1_url"); |
6067 Dart_Handle source = NewString(kLibrary1Chars); | 5887 Dart_Handle source = NewString(kLibrary1Chars); |
6068 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 5888 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6069 Dart_Handle error = Dart_NewApiError("incoming error"); | 5889 Dart_Handle error = Dart_NewApiError("incoming error"); |
6070 EXPECT_VALID(lib); | 5890 EXPECT_VALID(lib); |
6071 intptr_t libraryId = -1; | 5891 intptr_t libraryId = -1; |
6072 | 5892 |
6073 Dart_Handle result = Dart_LibraryId(Dart_Null(), &libraryId); | 5893 Dart_Handle result = Dart_LibraryId(Dart_Null(), &libraryId); |
(...skipping 15 matching lines...) Expand all Loading... |
6089 EXPECT_VALID(result); | 5909 EXPECT_VALID(result); |
6090 Dart_Handle libFromId = Dart_GetLibraryFromId(libraryId); | 5910 Dart_Handle libFromId = Dart_GetLibraryFromId(libraryId); |
6091 EXPECT(Dart_IsLibrary(libFromId)); | 5911 EXPECT(Dart_IsLibrary(libFromId)); |
6092 result = Dart_LibraryName(libFromId); | 5912 result = Dart_LibraryName(libFromId); |
6093 EXPECT(Dart_IsString(result)); | 5913 EXPECT(Dart_IsString(result)); |
6094 const char* cstr = NULL; | 5914 const char* cstr = NULL; |
6095 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 5915 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
6096 EXPECT_STREQ("library1_name", cstr); | 5916 EXPECT_STREQ("library1_name", cstr); |
6097 } | 5917 } |
6098 | 5918 |
6099 | |
6100 #endif // !PRODUCT | 5919 #endif // !PRODUCT |
6101 | 5920 |
6102 | |
6103 TEST_CASE(LibraryUrl) { | 5921 TEST_CASE(LibraryUrl) { |
6104 const char* kLibrary1Chars = "library library1_name;"; | 5922 const char* kLibrary1Chars = "library library1_name;"; |
6105 Dart_Handle url = NewString("library1_url"); | 5923 Dart_Handle url = NewString("library1_url"); |
6106 Dart_Handle source = NewString(kLibrary1Chars); | 5924 Dart_Handle source = NewString(kLibrary1Chars); |
6107 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 5925 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6108 Dart_Handle error = Dart_NewApiError("incoming error"); | 5926 Dart_Handle error = Dart_NewApiError("incoming error"); |
6109 EXPECT_VALID(lib); | 5927 EXPECT_VALID(lib); |
6110 | 5928 |
6111 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); | 5929 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); |
6112 EXPECT(Dart_IsError(result)); | 5930 EXPECT(Dart_IsError(result)); |
(...skipping 11 matching lines...) Expand all Loading... |
6124 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5942 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6125 | 5943 |
6126 result = Dart_LibraryUrl(lib); | 5944 result = Dart_LibraryUrl(lib); |
6127 EXPECT_VALID(result); | 5945 EXPECT_VALID(result); |
6128 EXPECT(Dart_IsString(result)); | 5946 EXPECT(Dart_IsString(result)); |
6129 const char* cstr = NULL; | 5947 const char* cstr = NULL; |
6130 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 5948 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
6131 EXPECT_STREQ("library1_url", cstr); | 5949 EXPECT_STREQ("library1_url", cstr); |
6132 } | 5950 } |
6133 | 5951 |
6134 | |
6135 TEST_CASE(LibraryGetClassNames) { | 5952 TEST_CASE(LibraryGetClassNames) { |
6136 const char* kLibraryChars = | 5953 const char* kLibraryChars = |
6137 "library library_name;\n" | 5954 "library library_name;\n" |
6138 "\n" | 5955 "\n" |
6139 "class A {}\n" | 5956 "class A {}\n" |
6140 "class B {}\n" | 5957 "class B {}\n" |
6141 "abstract class C {}\n" | 5958 "abstract class C {}\n" |
6142 "class _A {}\n" | 5959 "class _A {}\n" |
6143 "class _B {}\n" | 5960 "class _B {}\n" |
6144 "abstract class _C {}\n" | 5961 "abstract class _C {}\n" |
(...skipping 18 matching lines...) Expand all Loading... |
6163 args[0] = list; | 5980 args[0] = list; |
6164 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); | 5981 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
6165 | 5982 |
6166 Dart_Handle list_string = Dart_ToString(list); | 5983 Dart_Handle list_string = Dart_ToString(list); |
6167 EXPECT_VALID(list_string); | 5984 EXPECT_VALID(list_string); |
6168 const char* list_cstr = ""; | 5985 const char* list_cstr = ""; |
6169 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 5986 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
6170 EXPECT_STREQ("[A, B, C, _A, _B, _C]", list_cstr); | 5987 EXPECT_STREQ("[A, B, C, _A, _B, _C]", list_cstr); |
6171 } | 5988 } |
6172 | 5989 |
6173 | |
6174 TEST_CASE(GetFunctionNames) { | 5990 TEST_CASE(GetFunctionNames) { |
6175 const char* kLibraryChars = | 5991 const char* kLibraryChars = |
6176 "library library_name;\n" | 5992 "library library_name;\n" |
6177 "\n" | 5993 "\n" |
6178 "void A() {}\n" | 5994 "void A() {}\n" |
6179 "get B => 11;\n" | 5995 "get B => 11;\n" |
6180 "set C(x) { }\n" | 5996 "set C(x) { }\n" |
6181 "var D;\n" | 5997 "var D;\n" |
6182 "void _A() {}\n" | 5998 "void _A() {}\n" |
6183 "get _B => 11;\n" | 5999 "get _B => 11;\n" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6235 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); | 6051 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
6236 | 6052 |
6237 // Check list contents. | 6053 // Check list contents. |
6238 list_string = Dart_ToString(list); | 6054 list_string = Dart_ToString(list); |
6239 EXPECT_VALID(list_string); | 6055 EXPECT_VALID(list_string); |
6240 list_cstr = ""; | 6056 list_cstr = ""; |
6241 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 6057 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
6242 EXPECT_STREQ("[A2, B2, C2=, MyClass, _A2, _B2, _C2=]", list_cstr); | 6058 EXPECT_STREQ("[A2, B2, C2=, MyClass, _A2, _B2, _C2=]", list_cstr); |
6243 } | 6059 } |
6244 | 6060 |
6245 | |
6246 TEST_CASE(LibraryImportLibrary) { | 6061 TEST_CASE(LibraryImportLibrary) { |
6247 const char* kLibrary1Chars = "library library1_name;"; | 6062 const char* kLibrary1Chars = "library library1_name;"; |
6248 const char* kLibrary2Chars = "library library2_name;"; | 6063 const char* kLibrary2Chars = "library library2_name;"; |
6249 Dart_Handle error = Dart_NewApiError("incoming error"); | 6064 Dart_Handle error = Dart_NewApiError("incoming error"); |
6250 Dart_Handle result; | 6065 Dart_Handle result; |
6251 | 6066 |
6252 Dart_Handle url = NewString("library1_url"); | 6067 Dart_Handle url = NewString("library1_url"); |
6253 Dart_Handle source = NewString(kLibrary1Chars); | 6068 Dart_Handle source = NewString(kLibrary1Chars); |
6254 Dart_Handle lib1 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6069 Dart_Handle lib1 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6255 EXPECT_VALID(lib1); | 6070 EXPECT_VALID(lib1); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6290 Dart_GetError(result)); | 6105 Dart_GetError(result)); |
6291 | 6106 |
6292 result = Dart_LibraryImportLibrary(lib1, error, Dart_Null()); | 6107 result = Dart_LibraryImportLibrary(lib1, error, Dart_Null()); |
6293 EXPECT(Dart_IsError(result)); | 6108 EXPECT(Dart_IsError(result)); |
6294 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6109 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6295 | 6110 |
6296 result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); | 6111 result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); |
6297 EXPECT_VALID(result); | 6112 EXPECT_VALID(result); |
6298 } | 6113 } |
6299 | 6114 |
6300 | |
6301 TEST_CASE(ImportLibraryWithPrefix) { | 6115 TEST_CASE(ImportLibraryWithPrefix) { |
6302 const char* kLibrary1Chars = | 6116 const char* kLibrary1Chars = |
6303 "library library1_name;" | 6117 "library library1_name;" |
6304 "int bar() => 42;"; | 6118 "int bar() => 42;"; |
6305 Dart_Handle url1 = NewString("library1_url"); | 6119 Dart_Handle url1 = NewString("library1_url"); |
6306 Dart_Handle source1 = NewString(kLibrary1Chars); | 6120 Dart_Handle source1 = NewString(kLibrary1Chars); |
6307 Dart_Handle lib1 = Dart_LoadLibrary(url1, Dart_Null(), source1, 0, 0); | 6121 Dart_Handle lib1 = Dart_LoadLibrary(url1, Dart_Null(), source1, 0, 0); |
6308 EXPECT_VALID(lib1); | 6122 EXPECT_VALID(lib1); |
6309 EXPECT(Dart_IsLibrary(lib1)); | 6123 EXPECT(Dart_IsLibrary(lib1)); |
6310 | 6124 |
(...skipping 21 matching lines...) Expand all Loading... |
6332 // Check that lib1 is available under the prefix in lib2. | 6146 // Check that lib1 is available under the prefix in lib2. |
6333 method_name = NewString("foobar"); | 6147 method_name = NewString("foobar"); |
6334 result = Dart_Invoke(lib2, method_name, 0, NULL); | 6148 result = Dart_Invoke(lib2, method_name, 0, NULL); |
6335 EXPECT_VALID(result); | 6149 EXPECT_VALID(result); |
6336 EXPECT(Dart_IsInteger(result)); | 6150 EXPECT(Dart_IsInteger(result)); |
6337 int64_t value = 0; | 6151 int64_t value = 0; |
6338 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6152 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
6339 EXPECT_EQ(42, value); | 6153 EXPECT_EQ(42, value); |
6340 } | 6154 } |
6341 | 6155 |
6342 | |
6343 TEST_CASE(LoadLibrary) { | 6156 TEST_CASE(LoadLibrary) { |
6344 const char* kLibrary1Chars = "library library1_name;"; | 6157 const char* kLibrary1Chars = "library library1_name;"; |
6345 Dart_Handle error = Dart_NewApiError("incoming error"); | 6158 Dart_Handle error = Dart_NewApiError("incoming error"); |
6346 Dart_Handle result; | 6159 Dart_Handle result; |
6347 | 6160 |
6348 Dart_Handle url = NewString("library1_url"); | 6161 Dart_Handle url = NewString("library1_url"); |
6349 Dart_Handle source = NewString(kLibrary1Chars); | 6162 Dart_Handle source = NewString(kLibrary1Chars); |
6350 | 6163 |
6351 result = Dart_LoadLibrary(Dart_Null(), Dart_Null(), source, 0, 0); | 6164 result = Dart_LoadLibrary(Dart_Null(), Dart_Null(), source, 0, 0); |
6352 EXPECT(Dart_IsError(result)); | 6165 EXPECT(Dart_IsError(result)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6393 EXPECT(Dart_IsLibrary(result)); | 6206 EXPECT(Dart_IsLibrary(result)); |
6394 | 6207 |
6395 // Duplicate library load fails. | 6208 // Duplicate library load fails. |
6396 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6209 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6397 EXPECT(Dart_IsError(result)); | 6210 EXPECT(Dart_IsError(result)); |
6398 EXPECT_STREQ( | 6211 EXPECT_STREQ( |
6399 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", | 6212 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", |
6400 Dart_GetError(result)); | 6213 Dart_GetError(result)); |
6401 } | 6214 } |
6402 | 6215 |
6403 | |
6404 TEST_CASE(LoadLibrary_CompileError) { | 6216 TEST_CASE(LoadLibrary_CompileError) { |
6405 const char* kLibrary1Chars = | 6217 const char* kLibrary1Chars = |
6406 "library library1_name;" | 6218 "library library1_name;" |
6407 ")"; | 6219 ")"; |
6408 Dart_Handle url = NewString("library1_url"); | 6220 Dart_Handle url = NewString("library1_url"); |
6409 Dart_Handle source = NewString(kLibrary1Chars); | 6221 Dart_Handle source = NewString(kLibrary1Chars); |
6410 Dart_Handle result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6222 Dart_Handle result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6411 EXPECT(Dart_IsError(result)); | 6223 EXPECT(Dart_IsError(result)); |
6412 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 6224 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
6413 } | 6225 } |
6414 | 6226 |
6415 | |
6416 TEST_CASE(LoadSource) { | 6227 TEST_CASE(LoadSource) { |
6417 const char* kLibrary1Chars = "library library1_name;"; | 6228 const char* kLibrary1Chars = "library library1_name;"; |
6418 const char* kSourceChars = "part of library1_name;\n// Something innocuous"; | 6229 const char* kSourceChars = "part of library1_name;\n// Something innocuous"; |
6419 const char* kBadSourceChars = ")"; | 6230 const char* kBadSourceChars = ")"; |
6420 Dart_Handle error = Dart_NewApiError("incoming error"); | 6231 Dart_Handle error = Dart_NewApiError("incoming error"); |
6421 Dart_Handle result; | 6232 Dart_Handle result; |
6422 | 6233 |
6423 // Load up a library. | 6234 // Load up a library. |
6424 Dart_Handle url = NewString("library1_url"); | 6235 Dart_Handle url = NewString("library1_url"); |
6425 Dart_Handle source = NewString(kLibrary1Chars); | 6236 Dart_Handle source = NewString(kLibrary1Chars); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6495 EXPECT_VALID(result); | 6306 EXPECT_VALID(result); |
6496 EXPECT(Dart_IsLibrary(result)); | 6307 EXPECT(Dart_IsLibrary(result)); |
6497 EXPECT(Dart_IdentityEquals(lib, result)); | 6308 EXPECT(Dart_IdentityEquals(lib, result)); |
6498 | 6309 |
6499 // Language errors are detected. | 6310 // Language errors are detected. |
6500 source = NewString(kBadSourceChars); | 6311 source = NewString(kBadSourceChars); |
6501 result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); | 6312 result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); |
6502 EXPECT(Dart_IsError(result)); | 6313 EXPECT(Dart_IsError(result)); |
6503 } | 6314 } |
6504 | 6315 |
6505 | |
6506 TEST_CASE(LoadSource_LateLoad) { | 6316 TEST_CASE(LoadSource_LateLoad) { |
6507 const char* kLibrary1Chars = | 6317 const char* kLibrary1Chars = |
6508 "library library1_name;\n" | 6318 "library library1_name;\n" |
6509 "class OldClass {\n" | 6319 "class OldClass {\n" |
6510 " foo() => 'foo';\n" | 6320 " foo() => 'foo';\n" |
6511 "}\n"; | 6321 "}\n"; |
6512 const char* kSourceChars = | 6322 const char* kSourceChars = |
6513 "part of library1_name;\n" | 6323 "part of library1_name;\n" |
6514 "class NewClass extends OldClass{\n" | 6324 "class NewClass extends OldClass{\n" |
6515 " bar() => 'bar';\n" | 6325 " bar() => 'bar';\n" |
(...skipping 29 matching lines...) Expand all Loading... |
6545 EXPECT_VALID(type); | 6355 EXPECT_VALID(type); |
6546 recv = Dart_New(type, Dart_Null(), 0, NULL); | 6356 recv = Dart_New(type, Dart_Null(), 0, NULL); |
6547 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); | 6357 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); |
6548 EXPECT_VALID(result); | 6358 EXPECT_VALID(result); |
6549 EXPECT(Dart_IsString(result)); | 6359 EXPECT(Dart_IsString(result)); |
6550 result_cstr = ""; | 6360 result_cstr = ""; |
6551 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 6361 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
6552 EXPECT_STREQ("bar", result_cstr); | 6362 EXPECT_STREQ("bar", result_cstr); |
6553 } | 6363 } |
6554 | 6364 |
6555 | |
6556 TEST_CASE(LoadPatch) { | 6365 TEST_CASE(LoadPatch) { |
6557 const char* kLibrary1Chars = "library library1_name;"; | 6366 const char* kLibrary1Chars = "library library1_name;"; |
6558 const char* kSourceChars = | 6367 const char* kSourceChars = |
6559 "part of library1_name;\n" | 6368 "part of library1_name;\n" |
6560 "external int foo();"; | 6369 "external int foo();"; |
6561 const char* kPatchChars = "@patch int foo() => 42;"; | 6370 const char* kPatchChars = "@patch int foo() => 42;"; |
6562 | 6371 |
6563 // Load up a library. | 6372 // Load up a library. |
6564 Dart_Handle url = NewString("library1_url"); | 6373 Dart_Handle url = NewString("library1_url"); |
6565 Dart_Handle source = NewString(kLibrary1Chars); | 6374 Dart_Handle source = NewString(kLibrary1Chars); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6696 EXPECT_VALID(result); | 6505 EXPECT_VALID(result); |
6697 EXPECT(Dart_IsInteger(result)); | 6506 EXPECT(Dart_IsInteger(result)); |
6698 int64_t value = 0; | 6507 int64_t value = 0; |
6699 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6508 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
6700 EXPECT_EQ(200, value); | 6509 EXPECT_EQ(200, value); |
6701 } | 6510 } |
6702 | 6511 |
6703 FLAG_ignore_patch_signature_mismatch = old_flag_value; | 6512 FLAG_ignore_patch_signature_mismatch = old_flag_value; |
6704 } | 6513 } |
6705 | 6514 |
6706 | |
6707 static void PatchNativeFunction(Dart_NativeArguments args) { | 6515 static void PatchNativeFunction(Dart_NativeArguments args) { |
6708 Dart_EnterScope(); | 6516 Dart_EnterScope(); |
6709 Dart_SetReturnValue(args, Dart_Null()); | 6517 Dart_SetReturnValue(args, Dart_Null()); |
6710 Dart_ExitScope(); | 6518 Dart_ExitScope(); |
6711 } | 6519 } |
6712 | 6520 |
6713 | |
6714 static Dart_NativeFunction PatchNativeResolver(Dart_Handle name, | 6521 static Dart_NativeFunction PatchNativeResolver(Dart_Handle name, |
6715 int arg_count, | 6522 int arg_count, |
6716 bool* auto_setup_scope) { | 6523 bool* auto_setup_scope) { |
6717 ASSERT(auto_setup_scope != NULL); | 6524 ASSERT(auto_setup_scope != NULL); |
6718 *auto_setup_scope = false; | 6525 *auto_setup_scope = false; |
6719 return &PatchNativeFunction; | 6526 return &PatchNativeFunction; |
6720 } | 6527 } |
6721 | 6528 |
6722 | |
6723 TEST_CASE(ParsePatchLibrary) { | 6529 TEST_CASE(ParsePatchLibrary) { |
6724 const char* kLibraryChars = | 6530 const char* kLibraryChars = |
6725 "library patched_library;\n" | 6531 "library patched_library;\n" |
6726 "class A {\n" | 6532 "class A {\n" |
6727 " final fvalue;\n" | 6533 " final fvalue;\n" |
6728 " var _f;\n" | 6534 " var _f;\n" |
6729 " callFunc(x, y) => x(y);\n" | 6535 " callFunc(x, y) => x(y);\n" |
6730 " external void method(var value);\n" | 6536 " external void method(var value);\n" |
6731 " get field => _field;\n" | 6537 " get field => _field;\n" |
6732 "}\n" | 6538 "}\n" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6883 EXPECT_VALID(result); | 6689 EXPECT_VALID(result); |
6884 EXPECT(Dart_IsInteger(result)); | 6690 EXPECT(Dart_IsInteger(result)); |
6885 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6691 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
6886 EXPECT_EQ(8, value); | 6692 EXPECT_EQ(8, value); |
6887 | 6693 |
6888 // Make sure all source files show up in the patched library. | 6694 // Make sure all source files show up in the patched library. |
6889 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); | 6695 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); |
6890 EXPECT_EQ(4, lib_scripts.Length()); | 6696 EXPECT_EQ(4, lib_scripts.Length()); |
6891 } | 6697 } |
6892 | 6698 |
6893 | |
6894 static void MyNativeFunction1(Dart_NativeArguments args) { | 6699 static void MyNativeFunction1(Dart_NativeArguments args) { |
6895 Dart_EnterScope(); | 6700 Dart_EnterScope(); |
6896 Dart_SetReturnValue(args, Dart_NewInteger(654321)); | 6701 Dart_SetReturnValue(args, Dart_NewInteger(654321)); |
6897 Dart_ExitScope(); | 6702 Dart_ExitScope(); |
6898 } | 6703 } |
6899 | 6704 |
6900 | |
6901 static void MyNativeFunction2(Dart_NativeArguments args) { | 6705 static void MyNativeFunction2(Dart_NativeArguments args) { |
6902 Dart_EnterScope(); | 6706 Dart_EnterScope(); |
6903 Dart_SetReturnValue(args, Dart_NewInteger(123456)); | 6707 Dart_SetReturnValue(args, Dart_NewInteger(123456)); |
6904 Dart_ExitScope(); | 6708 Dart_ExitScope(); |
6905 } | 6709 } |
6906 | 6710 |
6907 | |
6908 static Dart_NativeFunction MyNativeResolver1(Dart_Handle name, | 6711 static Dart_NativeFunction MyNativeResolver1(Dart_Handle name, |
6909 int arg_count, | 6712 int arg_count, |
6910 bool* auto_setup_scope) { | 6713 bool* auto_setup_scope) { |
6911 ASSERT(auto_setup_scope != NULL); | 6714 ASSERT(auto_setup_scope != NULL); |
6912 *auto_setup_scope = false; | 6715 *auto_setup_scope = false; |
6913 return &MyNativeFunction1; | 6716 return &MyNativeFunction1; |
6914 } | 6717 } |
6915 | 6718 |
6916 | |
6917 static Dart_NativeFunction MyNativeResolver2(Dart_Handle name, | 6719 static Dart_NativeFunction MyNativeResolver2(Dart_Handle name, |
6918 int arg_count, | 6720 int arg_count, |
6919 bool* auto_setup_scope) { | 6721 bool* auto_setup_scope) { |
6920 ASSERT(auto_setup_scope != NULL); | 6722 ASSERT(auto_setup_scope != NULL); |
6921 *auto_setup_scope = false; | 6723 *auto_setup_scope = false; |
6922 return &MyNativeFunction2; | 6724 return &MyNativeFunction2; |
6923 } | 6725 } |
6924 | 6726 |
6925 | |
6926 TEST_CASE(SetNativeResolver) { | 6727 TEST_CASE(SetNativeResolver) { |
6927 const char* kScriptChars = | 6728 const char* kScriptChars = |
6928 "class Test {" | 6729 "class Test {" |
6929 " static foo() native \"SomeNativeFunction\";\n" | 6730 " static foo() native \"SomeNativeFunction\";\n" |
6930 " static bar() native \"SomeNativeFunction2\";\n" | 6731 " static bar() native \"SomeNativeFunction2\";\n" |
6931 " static baz() native \"SomeNativeFunction3\";\n" | 6732 " static baz() native \"SomeNativeFunction3\";\n" |
6932 "}"; | 6733 "}"; |
6933 Dart_Handle error = Dart_NewApiError("incoming error"); | 6734 Dart_Handle error = Dart_NewApiError("incoming error"); |
6934 Dart_Handle result; | 6735 Dart_Handle result; |
6935 | 6736 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6996 | 6797 |
6997 // A NULL resolver is okay, but resolution will fail. | 6798 // A NULL resolver is okay, but resolution will fail. |
6998 result = Dart_SetNativeResolver(lib, NULL, NULL); | 6799 result = Dart_SetNativeResolver(lib, NULL, NULL); |
6999 EXPECT_VALID(result); | 6800 EXPECT_VALID(result); |
7000 | 6801 |
7001 EXPECT_ERROR(Dart_Invoke(type, NewString("baz"), 0, NULL), | 6802 EXPECT_ERROR(Dart_Invoke(type, NewString("baz"), 0, NULL), |
7002 "native function 'SomeNativeFunction3' (0 arguments) " | 6803 "native function 'SomeNativeFunction3' (0 arguments) " |
7003 "cannot be found"); | 6804 "cannot be found"); |
7004 } | 6805 } |
7005 | 6806 |
7006 | |
7007 // Test that an imported name does not clash with the same name defined | 6807 // Test that an imported name does not clash with the same name defined |
7008 // in the importing library. | 6808 // in the importing library. |
7009 TEST_CASE(ImportLibrary2) { | 6809 TEST_CASE(ImportLibrary2) { |
7010 const char* kScriptChars = | 6810 const char* kScriptChars = |
7011 "import 'library1_dart';\n" | 6811 "import 'library1_dart';\n" |
7012 "var foo;\n" | 6812 "var foo;\n" |
7013 "main() { foo = 0; }\n"; | 6813 "main() { foo = 0; }\n"; |
7014 const char* kLibrary1Chars = | 6814 const char* kLibrary1Chars = |
7015 "library library1_dart;\n" | 6815 "library library1_dart;\n" |
7016 "import 'library2_dart';\n" | 6816 "import 'library2_dart';\n" |
(...skipping 17 matching lines...) Expand all Loading... |
7034 url = NewString("library2_dart"); | 6834 url = NewString("library2_dart"); |
7035 source = NewString(kLibrary2Chars); | 6835 source = NewString(kLibrary2Chars); |
7036 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6836 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7037 | 6837 |
7038 Dart_FinalizeLoading(false); | 6838 Dart_FinalizeLoading(false); |
7039 | 6839 |
7040 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 6840 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7041 EXPECT_VALID(result); | 6841 EXPECT_VALID(result); |
7042 } | 6842 } |
7043 | 6843 |
7044 | |
7045 // Test that if the same name is imported from two libraries, it is | 6844 // Test that if the same name is imported from two libraries, it is |
7046 // an error if that name is referenced. | 6845 // an error if that name is referenced. |
7047 TEST_CASE(ImportLibrary3) { | 6846 TEST_CASE(ImportLibrary3) { |
7048 const char* kScriptChars = | 6847 const char* kScriptChars = |
7049 "import 'library2_dart';\n" | 6848 "import 'library2_dart';\n" |
7050 "import 'library1_dart';\n" | 6849 "import 'library1_dart';\n" |
7051 "var foo_top = 10; // foo has dup def. So should be an error.\n" | 6850 "var foo_top = 10; // foo has dup def. So should be an error.\n" |
7052 "main() { foo = 0; }\n"; | 6851 "main() { foo = 0; }\n"; |
7053 const char* kLibrary1Chars = | 6852 const char* kLibrary1Chars = |
7054 "library library1_dart;\n" | 6853 "library library1_dart;\n" |
(...skipping 19 matching lines...) Expand all Loading... |
7074 source = NewString(kLibrary1Chars); | 6873 source = NewString(kLibrary1Chars); |
7075 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6874 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7076 result = Dart_FinalizeLoading(false); | 6875 result = Dart_FinalizeLoading(false); |
7077 EXPECT_VALID(result); | 6876 EXPECT_VALID(result); |
7078 | 6877 |
7079 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 6878 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7080 EXPECT(Dart_IsError(result)); | 6879 EXPECT(Dart_IsError(result)); |
7081 EXPECT_SUBSTRING("NoSuchMethodError", Dart_GetError(result)); | 6880 EXPECT_SUBSTRING("NoSuchMethodError", Dart_GetError(result)); |
7082 } | 6881 } |
7083 | 6882 |
7084 | |
7085 // Test that if the same name is imported from two libraries, it is | 6883 // Test that if the same name is imported from two libraries, it is |
7086 // not an error if that name is not used. | 6884 // not an error if that name is not used. |
7087 TEST_CASE(ImportLibrary4) { | 6885 TEST_CASE(ImportLibrary4) { |
7088 const char* kScriptChars = | 6886 const char* kScriptChars = |
7089 "import 'library2_dart';\n" | 6887 "import 'library2_dart';\n" |
7090 "import 'library1_dart';\n" | 6888 "import 'library1_dart';\n" |
7091 "main() { }\n"; | 6889 "main() { }\n"; |
7092 const char* kLibrary1Chars = | 6890 const char* kLibrary1Chars = |
7093 "library library1_dart;\n" | 6891 "library library1_dart;\n" |
7094 "var foo;"; | 6892 "var foo;"; |
(...skipping 16 matching lines...) Expand all Loading... |
7111 | 6909 |
7112 url = NewString("library1_dart"); | 6910 url = NewString("library1_dart"); |
7113 source = NewString(kLibrary1Chars); | 6911 source = NewString(kLibrary1Chars); |
7114 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6912 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7115 Dart_FinalizeLoading(false); | 6913 Dart_FinalizeLoading(false); |
7116 | 6914 |
7117 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 6915 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7118 EXPECT_VALID(result); | 6916 EXPECT_VALID(result); |
7119 } | 6917 } |
7120 | 6918 |
7121 | |
7122 TEST_CASE(ImportLibrary5) { | 6919 TEST_CASE(ImportLibrary5) { |
7123 const char* kScriptChars = | 6920 const char* kScriptChars = |
7124 "import 'lib.dart';\n" | 6921 "import 'lib.dart';\n" |
7125 "abstract class Y {\n" | 6922 "abstract class Y {\n" |
7126 " void set handler(void callback(List<int> x));\n" | 6923 " void set handler(void callback(List<int> x));\n" |
7127 "}\n" | 6924 "}\n" |
7128 "void main() {}\n"; | 6925 "void main() {}\n"; |
7129 const char* kLibraryChars = | 6926 const char* kLibraryChars = |
7130 "library lib.dart;\n" | 6927 "library lib.dart;\n" |
7131 "abstract class X {\n" | 6928 "abstract class X {\n" |
(...skipping 10 matching lines...) Expand all Loading... |
7142 | 6939 |
7143 url = NewString("lib.dart"); | 6940 url = NewString("lib.dart"); |
7144 source = NewString(kLibraryChars); | 6941 source = NewString(kLibraryChars); |
7145 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6942 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7146 Dart_FinalizeLoading(false); | 6943 Dart_FinalizeLoading(false); |
7147 | 6944 |
7148 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 6945 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7149 EXPECT_VALID(result); | 6946 EXPECT_VALID(result); |
7150 } | 6947 } |
7151 | 6948 |
7152 | |
7153 void NewNativePort_send123(Dart_Port dest_port_id, Dart_CObject* message) { | 6949 void NewNativePort_send123(Dart_Port dest_port_id, Dart_CObject* message) { |
7154 // Gets a send port message. | 6950 // Gets a send port message. |
7155 EXPECT_NOTNULL(message); | 6951 EXPECT_NOTNULL(message); |
7156 EXPECT_EQ(Dart_CObject_kArray, message->type); | 6952 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7157 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 6953 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7158 | 6954 |
7159 // Post integer value. | 6955 // Post integer value. |
7160 Dart_CObject* response = | 6956 Dart_CObject* response = |
7161 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 6957 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
7162 response->type = Dart_CObject_kInt32; | 6958 response->type = Dart_CObject_kInt32; |
7163 response->value.as_int32 = 123; | 6959 response->value.as_int32 = 123; |
7164 Dart_PostCObject(message->value.as_array.values[0]->value.as_send_port.id, | 6960 Dart_PostCObject(message->value.as_array.values[0]->value.as_send_port.id, |
7165 response); | 6961 response); |
7166 } | 6962 } |
7167 | 6963 |
7168 | |
7169 void NewNativePort_send321(Dart_Port dest_port_id, Dart_CObject* message) { | 6964 void NewNativePort_send321(Dart_Port dest_port_id, Dart_CObject* message) { |
7170 // Gets a null message. | 6965 // Gets a null message. |
7171 EXPECT_NOTNULL(message); | 6966 EXPECT_NOTNULL(message); |
7172 EXPECT_EQ(Dart_CObject_kArray, message->type); | 6967 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7173 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 6968 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7174 | 6969 |
7175 // Post integer value. | 6970 // Post integer value. |
7176 Dart_CObject* response = | 6971 Dart_CObject* response = |
7177 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 6972 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
7178 response->type = Dart_CObject_kInt32; | 6973 response->type = Dart_CObject_kInt32; |
7179 response->value.as_int32 = 321; | 6974 response->value.as_int32 = 321; |
7180 Dart_PostCObject(message->value.as_array.values[0]->value.as_send_port.id, | 6975 Dart_PostCObject(message->value.as_array.values[0]->value.as_send_port.id, |
7181 response); | 6976 response); |
7182 } | 6977 } |
7183 | 6978 |
7184 | |
7185 TEST_CASE(IllegalNewSendPort) { | 6979 TEST_CASE(IllegalNewSendPort) { |
7186 Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT); | 6980 Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT); |
7187 EXPECT(Dart_IsError(error)); | 6981 EXPECT(Dart_IsError(error)); |
7188 EXPECT(Dart_IsApiError(error)); | 6982 EXPECT(Dart_IsApiError(error)); |
7189 } | 6983 } |
7190 | 6984 |
7191 | |
7192 TEST_CASE(IllegalPost) { | 6985 TEST_CASE(IllegalPost) { |
7193 Dart_Handle message = Dart_True(); | 6986 Dart_Handle message = Dart_True(); |
7194 bool success = Dart_Post(ILLEGAL_PORT, message); | 6987 bool success = Dart_Post(ILLEGAL_PORT, message); |
7195 EXPECT(!success); | 6988 EXPECT(!success); |
7196 } | 6989 } |
7197 | 6990 |
7198 | |
7199 VM_UNIT_TEST_CASE(NewNativePort) { | 6991 VM_UNIT_TEST_CASE(NewNativePort) { |
7200 // Create a port with a bogus handler. | 6992 // Create a port with a bogus handler. |
7201 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); | 6993 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); |
7202 EXPECT_EQ(ILLEGAL_PORT, error_port); | 6994 EXPECT_EQ(ILLEGAL_PORT, error_port); |
7203 | 6995 |
7204 // Create the port w/o a current isolate, just to make sure that works. | 6996 // Create the port w/o a current isolate, just to make sure that works. |
7205 Dart_Port port_id1 = | 6997 Dart_Port port_id1 = |
7206 Dart_NewNativePort("Port123", NewNativePort_send123, true); | 6998 Dart_NewNativePort("Port123", NewNativePort_send123, true); |
7207 | 6999 |
7208 TestIsolateScope __test_isolate__; | 7000 TestIsolateScope __test_isolate__; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7248 EXPECT(Dart_ErrorHasException(result)); | 7040 EXPECT(Dart_ErrorHasException(result)); |
7249 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 7041 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
7250 | 7042 |
7251 Dart_ExitScope(); | 7043 Dart_ExitScope(); |
7252 | 7044 |
7253 // Delete the native ports. | 7045 // Delete the native ports. |
7254 EXPECT(Dart_CloseNativePort(port_id1)); | 7046 EXPECT(Dart_CloseNativePort(port_id1)); |
7255 EXPECT(Dart_CloseNativePort(port_id2)); | 7047 EXPECT(Dart_CloseNativePort(port_id2)); |
7256 } | 7048 } |
7257 | 7049 |
7258 | |
7259 void NewNativePort_sendInteger123(Dart_Port dest_port_id, | 7050 void NewNativePort_sendInteger123(Dart_Port dest_port_id, |
7260 Dart_CObject* message) { | 7051 Dart_CObject* message) { |
7261 // Gets a send port message. | 7052 // Gets a send port message. |
7262 EXPECT_NOTNULL(message); | 7053 EXPECT_NOTNULL(message); |
7263 EXPECT_EQ(Dart_CObject_kArray, message->type); | 7054 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7264 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 7055 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7265 | 7056 |
7266 // Post integer value. | 7057 // Post integer value. |
7267 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, | 7058 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7268 123); | 7059 123); |
7269 } | 7060 } |
7270 | 7061 |
7271 | |
7272 void NewNativePort_sendInteger321(Dart_Port dest_port_id, | 7062 void NewNativePort_sendInteger321(Dart_Port dest_port_id, |
7273 Dart_CObject* message) { | 7063 Dart_CObject* message) { |
7274 // Gets a null message. | 7064 // Gets a null message. |
7275 EXPECT_NOTNULL(message); | 7065 EXPECT_NOTNULL(message); |
7276 EXPECT_EQ(Dart_CObject_kArray, message->type); | 7066 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7277 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 7067 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7278 | 7068 |
7279 // Post integer value. | 7069 // Post integer value. |
7280 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, | 7070 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7281 321); | 7071 321); |
7282 } | 7072 } |
7283 | 7073 |
7284 | |
7285 TEST_CASE(NativePortPostInteger) { | 7074 TEST_CASE(NativePortPostInteger) { |
7286 const char* kScriptChars = | 7075 const char* kScriptChars = |
7287 "import 'dart:isolate';\n" | 7076 "import 'dart:isolate';\n" |
7288 "void callPort(SendPort port) {\n" | 7077 "void callPort(SendPort port) {\n" |
7289 " var receivePort = new RawReceivePort();\n" | 7078 " var receivePort = new RawReceivePort();\n" |
7290 " var replyPort = receivePort.sendPort;\n" | 7079 " var replyPort = receivePort.sendPort;\n" |
7291 " port.send([replyPort]);\n" | 7080 " port.send([replyPort]);\n" |
7292 " receivePort.handler = (message) {\n" | 7081 " receivePort.handler = (message) {\n" |
7293 " receivePort.close();\n" | 7082 " receivePort.close();\n" |
7294 " throw new Exception(message);\n" | 7083 " throw new Exception(message);\n" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7326 EXPECT(Dart_ErrorHasException(result)); | 7115 EXPECT(Dart_ErrorHasException(result)); |
7327 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 7116 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
7328 | 7117 |
7329 Dart_ExitScope(); | 7118 Dart_ExitScope(); |
7330 | 7119 |
7331 // Delete the native ports. | 7120 // Delete the native ports. |
7332 EXPECT(Dart_CloseNativePort(port_id1)); | 7121 EXPECT(Dart_CloseNativePort(port_id1)); |
7333 EXPECT(Dart_CloseNativePort(port_id2)); | 7122 EXPECT(Dart_CloseNativePort(port_id2)); |
7334 } | 7123 } |
7335 | 7124 |
7336 | |
7337 void NewNativePort_nativeReceiveNull(Dart_Port dest_port_id, | 7125 void NewNativePort_nativeReceiveNull(Dart_Port dest_port_id, |
7338 Dart_CObject* message) { | 7126 Dart_CObject* message) { |
7339 EXPECT_NOTNULL(message); | 7127 EXPECT_NOTNULL(message); |
7340 | 7128 |
7341 if ((message->type == Dart_CObject_kArray) && | 7129 if ((message->type == Dart_CObject_kArray) && |
7342 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { | 7130 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { |
7343 // Post integer value. | 7131 // Post integer value. |
7344 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, | 7132 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7345 123); | 7133 123); |
7346 } else { | 7134 } else { |
7347 EXPECT_EQ(message->type, Dart_CObject_kNull); | 7135 EXPECT_EQ(message->type, Dart_CObject_kNull); |
7348 } | 7136 } |
7349 } | 7137 } |
7350 | 7138 |
7351 | |
7352 TEST_CASE(NativePortReceiveNull) { | 7139 TEST_CASE(NativePortReceiveNull) { |
7353 const char* kScriptChars = | 7140 const char* kScriptChars = |
7354 "import 'dart:isolate';\n" | 7141 "import 'dart:isolate';\n" |
7355 "void callPort(SendPort port) {\n" | 7142 "void callPort(SendPort port) {\n" |
7356 " var receivePort = new RawReceivePort();\n" | 7143 " var receivePort = new RawReceivePort();\n" |
7357 " var replyPort = receivePort.sendPort;\n" | 7144 " var replyPort = receivePort.sendPort;\n" |
7358 " port.send(null);\n" | 7145 " port.send(null);\n" |
7359 " port.send([replyPort]);\n" | 7146 " port.send([replyPort]);\n" |
7360 " receivePort.handler = (message) {\n" | 7147 " receivePort.handler = (message) {\n" |
7361 " receivePort.close();\n" | 7148 " receivePort.close();\n" |
(...skipping 17 matching lines...) Expand all Loading... |
7379 EXPECT(Dart_IsError(result)); | 7166 EXPECT(Dart_IsError(result)); |
7380 EXPECT(Dart_ErrorHasException(result)); | 7167 EXPECT(Dart_ErrorHasException(result)); |
7381 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 7168 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
7382 | 7169 |
7383 Dart_ExitScope(); | 7170 Dart_ExitScope(); |
7384 | 7171 |
7385 // Delete the native ports. | 7172 // Delete the native ports. |
7386 EXPECT(Dart_CloseNativePort(port_id1)); | 7173 EXPECT(Dart_CloseNativePort(port_id1)); |
7387 } | 7174 } |
7388 | 7175 |
7389 | |
7390 void NewNativePort_nativeReceiveInteger(Dart_Port dest_port_id, | 7176 void NewNativePort_nativeReceiveInteger(Dart_Port dest_port_id, |
7391 Dart_CObject* message) { | 7177 Dart_CObject* message) { |
7392 EXPECT_NOTNULL(message); | 7178 EXPECT_NOTNULL(message); |
7393 | 7179 |
7394 if ((message->type == Dart_CObject_kArray) && | 7180 if ((message->type == Dart_CObject_kArray) && |
7395 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { | 7181 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { |
7396 // Post integer value. | 7182 // Post integer value. |
7397 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, | 7183 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7398 123); | 7184 123); |
7399 } else { | 7185 } else { |
7400 EXPECT_EQ(message->type, Dart_CObject_kInt32); | 7186 EXPECT_EQ(message->type, Dart_CObject_kInt32); |
7401 EXPECT_EQ(message->value.as_int32, 321); | 7187 EXPECT_EQ(message->value.as_int32, 321); |
7402 } | 7188 } |
7403 } | 7189 } |
7404 | 7190 |
7405 | |
7406 TEST_CASE(NativePortReceiveInteger) { | 7191 TEST_CASE(NativePortReceiveInteger) { |
7407 const char* kScriptChars = | 7192 const char* kScriptChars = |
7408 "import 'dart:isolate';\n" | 7193 "import 'dart:isolate';\n" |
7409 "void callPort(SendPort port) {\n" | 7194 "void callPort(SendPort port) {\n" |
7410 " var receivePort = new RawReceivePort();\n" | 7195 " var receivePort = new RawReceivePort();\n" |
7411 " var replyPort = receivePort.sendPort;\n" | 7196 " var replyPort = receivePort.sendPort;\n" |
7412 " port.send(321);\n" | 7197 " port.send(321);\n" |
7413 " port.send([replyPort]);\n" | 7198 " port.send([replyPort]);\n" |
7414 " receivePort.handler = (message) {\n" | 7199 " receivePort.handler = (message) {\n" |
7415 " receivePort.close();\n" | 7200 " receivePort.close();\n" |
(...skipping 17 matching lines...) Expand all Loading... |
7433 EXPECT(Dart_IsError(result)); | 7218 EXPECT(Dart_IsError(result)); |
7434 EXPECT(Dart_ErrorHasException(result)); | 7219 EXPECT(Dart_ErrorHasException(result)); |
7435 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 7220 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
7436 | 7221 |
7437 Dart_ExitScope(); | 7222 Dart_ExitScope(); |
7438 | 7223 |
7439 // Delete the native ports. | 7224 // Delete the native ports. |
7440 EXPECT(Dart_CloseNativePort(port_id1)); | 7225 EXPECT(Dart_CloseNativePort(port_id1)); |
7441 } | 7226 } |
7442 | 7227 |
7443 | |
7444 static Dart_Isolate RunLoopTestCallback(const char* script_name, | 7228 static Dart_Isolate RunLoopTestCallback(const char* script_name, |
7445 const char* main, | 7229 const char* main, |
7446 const char* package_root, | 7230 const char* package_root, |
7447 const char* package_config, | 7231 const char* package_config, |
7448 Dart_IsolateFlags* flags, | 7232 Dart_IsolateFlags* flags, |
7449 void* data, | 7233 void* data, |
7450 char** error) { | 7234 char** error) { |
7451 const char* kScriptChars = | 7235 const char* kScriptChars = |
7452 "import 'builtin';\n" | 7236 "import 'builtin';\n" |
7453 "import 'dart:isolate';\n" | 7237 "import 'dart:isolate';\n" |
(...skipping 25 matching lines...) Expand all Loading... |
7479 EXPECT_VALID(lib); | 7263 EXPECT_VALID(lib); |
7480 result = Dart_FinalizeLoading(false); | 7264 result = Dart_FinalizeLoading(false); |
7481 EXPECT_VALID(result); | 7265 EXPECT_VALID(result); |
7482 Dart_ExitScope(); | 7266 Dart_ExitScope(); |
7483 Dart_ExitIsolate(); | 7267 Dart_ExitIsolate(); |
7484 bool retval = Dart_IsolateMakeRunnable(isolate); | 7268 bool retval = Dart_IsolateMakeRunnable(isolate); |
7485 EXPECT(retval); | 7269 EXPECT(retval); |
7486 return isolate; | 7270 return isolate; |
7487 } | 7271 } |
7488 | 7272 |
7489 | |
7490 // Common code for RunLoop_Success/RunLoop_Failure. | 7273 // Common code for RunLoop_Success/RunLoop_Failure. |
7491 static void RunLoopTest(bool throw_exception) { | 7274 static void RunLoopTest(bool throw_exception) { |
7492 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 7275 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
7493 Isolate::SetCreateCallback(RunLoopTestCallback); | 7276 Isolate::SetCreateCallback(RunLoopTestCallback); |
7494 Dart_Isolate isolate = | 7277 Dart_Isolate isolate = |
7495 RunLoopTestCallback(NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 7278 RunLoopTestCallback(NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
7496 | 7279 |
7497 Dart_EnterIsolate(isolate); | 7280 Dart_EnterIsolate(isolate); |
7498 Dart_EnterScope(); | 7281 Dart_EnterScope(); |
7499 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 7282 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
(...skipping 10 matching lines...) Expand all Loading... |
7510 } else { | 7293 } else { |
7511 EXPECT_VALID(result); | 7294 EXPECT_VALID(result); |
7512 } | 7295 } |
7513 | 7296 |
7514 Dart_ExitScope(); | 7297 Dart_ExitScope(); |
7515 Dart_ShutdownIsolate(); | 7298 Dart_ShutdownIsolate(); |
7516 | 7299 |
7517 Isolate::SetCreateCallback(saved); | 7300 Isolate::SetCreateCallback(saved); |
7518 } | 7301 } |
7519 | 7302 |
7520 | |
7521 VM_UNIT_TEST_CASE(RunLoop_Success) { | 7303 VM_UNIT_TEST_CASE(RunLoop_Success) { |
7522 RunLoopTest(false); | 7304 RunLoopTest(false); |
7523 } | 7305 } |
7524 | 7306 |
7525 | |
7526 VM_UNIT_TEST_CASE(RunLoop_Exception) { | 7307 VM_UNIT_TEST_CASE(RunLoop_Exception) { |
7527 RunLoopTest(true); | 7308 RunLoopTest(true); |
7528 } | 7309 } |
7529 | 7310 |
7530 | |
7531 // Utility functions and variables for test case IsolateInterrupt starts here. | 7311 // Utility functions and variables for test case IsolateInterrupt starts here. |
7532 static Monitor* sync = NULL; | 7312 static Monitor* sync = NULL; |
7533 static Dart_Isolate shared_isolate = NULL; | 7313 static Dart_Isolate shared_isolate = NULL; |
7534 static bool main_entered = false; | 7314 static bool main_entered = false; |
7535 | 7315 |
7536 | |
7537 void MarkMainEntered(Dart_NativeArguments args) { | 7316 void MarkMainEntered(Dart_NativeArguments args) { |
7538 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 7317 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
7539 // Indicate that main has been entered. | 7318 // Indicate that main has been entered. |
7540 { | 7319 { |
7541 MonitorLocker ml(sync); | 7320 MonitorLocker ml(sync); |
7542 main_entered = true; | 7321 main_entered = true; |
7543 ml.Notify(); | 7322 ml.Notify(); |
7544 } | 7323 } |
7545 Dart_SetReturnValue(args, Dart_Null()); | 7324 Dart_SetReturnValue(args, Dart_Null()); |
7546 Dart_ExitScope(); | 7325 Dart_ExitScope(); |
7547 } | 7326 } |
7548 | 7327 |
7549 | |
7550 static Dart_NativeFunction IsolateInterruptTestNativeLookup( | 7328 static Dart_NativeFunction IsolateInterruptTestNativeLookup( |
7551 Dart_Handle name, | 7329 Dart_Handle name, |
7552 int argument_count, | 7330 int argument_count, |
7553 bool* auto_setup_scope) { | 7331 bool* auto_setup_scope) { |
7554 ASSERT(auto_setup_scope != NULL); | 7332 ASSERT(auto_setup_scope != NULL); |
7555 *auto_setup_scope = false; | 7333 *auto_setup_scope = false; |
7556 return reinterpret_cast<Dart_NativeFunction>(&MarkMainEntered); | 7334 return reinterpret_cast<Dart_NativeFunction>(&MarkMainEntered); |
7557 } | 7335 } |
7558 | 7336 |
7559 | |
7560 void BusyLoop_start(uword unused) { | 7337 void BusyLoop_start(uword unused) { |
7561 const char* kScriptChars = | 7338 const char* kScriptChars = |
7562 "class Native {\n" | 7339 "class Native {\n" |
7563 " static void markMainEntered() native 'MarkMainEntered';\n" | 7340 " static void markMainEntered() native 'MarkMainEntered';\n" |
7564 "}\n" | 7341 "}\n" |
7565 "\n" | 7342 "\n" |
7566 "void main() {\n" | 7343 "void main() {\n" |
7567 " Native.markMainEntered();\n" | 7344 " Native.markMainEntered();\n" |
7568 " while (true) {\n" // Infinite empty loop. | 7345 " while (true) {\n" // Infinite empty loop. |
7569 " }\n" | 7346 " }\n" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7603 Dart_ShutdownIsolate(); | 7380 Dart_ShutdownIsolate(); |
7604 | 7381 |
7605 // Tell the other thread that we are done. | 7382 // Tell the other thread that we are done. |
7606 { | 7383 { |
7607 MonitorLocker ml(sync); | 7384 MonitorLocker ml(sync); |
7608 shared_isolate = NULL; | 7385 shared_isolate = NULL; |
7609 ml.Notify(); | 7386 ml.Notify(); |
7610 } | 7387 } |
7611 } | 7388 } |
7612 | 7389 |
7613 | |
7614 static void* saved_callback_data; | 7390 static void* saved_callback_data; |
7615 static void IsolateShutdownTestCallback(void* callback_data) { | 7391 static void IsolateShutdownTestCallback(void* callback_data) { |
7616 saved_callback_data = callback_data; | 7392 saved_callback_data = callback_data; |
7617 } | 7393 } |
7618 | 7394 |
7619 VM_UNIT_TEST_CASE(IsolateShutdown) { | 7395 VM_UNIT_TEST_CASE(IsolateShutdown) { |
7620 Dart_IsolateShutdownCallback saved = Isolate::ShutdownCallback(); | 7396 Dart_IsolateShutdownCallback saved = Isolate::ShutdownCallback(); |
7621 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); | 7397 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); |
7622 | 7398 |
7623 saved_callback_data = NULL; | 7399 saved_callback_data = NULL; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7695 EXPECT_VALID(result); | 7471 EXPECT_VALID(result); |
7696 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 7472 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7697 EXPECT_VALID(lib); | 7473 EXPECT_VALID(lib); |
7698 result = Dart_FinalizeLoading(false); | 7474 result = Dart_FinalizeLoading(false); |
7699 EXPECT_VALID(result); | 7475 EXPECT_VALID(result); |
7700 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 7476 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
7701 EXPECT_VALID(result); | 7477 EXPECT_VALID(result); |
7702 Dart_ExitScope(); | 7478 Dart_ExitScope(); |
7703 } | 7479 } |
7704 | 7480 |
7705 | |
7706 // The shutdown callback has not been called. | 7481 // The shutdown callback has not been called. |
7707 EXPECT_EQ(0, add_result); | 7482 EXPECT_EQ(0, add_result); |
7708 | 7483 |
7709 EXPECT(isolate != NULL); | 7484 EXPECT(isolate != NULL); |
7710 | 7485 |
7711 // Shutdown the isolate. | 7486 // Shutdown the isolate. |
7712 Dart_ShutdownIsolate(); | 7487 Dart_ShutdownIsolate(); |
7713 | 7488 |
7714 // The shutdown callback has been called and ran Dart code. | 7489 // The shutdown callback has been called and ran Dart code. |
7715 EXPECT_EQ(99, add_result); | 7490 EXPECT_EQ(99, add_result); |
(...skipping 10 matching lines...) Expand all Loading... |
7726 static void NativeFoo1(Dart_NativeArguments args) { | 7501 static void NativeFoo1(Dart_NativeArguments args) { |
7727 Dart_EnterScope(); | 7502 Dart_EnterScope(); |
7728 intptr_t i = Dart_GetNativeArgumentCount(args); | 7503 intptr_t i = Dart_GetNativeArgumentCount(args); |
7729 EXPECT_EQ(1, i); | 7504 EXPECT_EQ(1, i); |
7730 Dart_Handle arg = Dart_GetNativeArgument(args, 0); | 7505 Dart_Handle arg = Dart_GetNativeArgument(args, 0); |
7731 EXPECT_VALID(arg); | 7506 EXPECT_VALID(arg); |
7732 Dart_SetReturnValue(args, Dart_NewInteger(1)); | 7507 Dart_SetReturnValue(args, Dart_NewInteger(1)); |
7733 Dart_ExitScope(); | 7508 Dart_ExitScope(); |
7734 } | 7509 } |
7735 | 7510 |
7736 | |
7737 static void NativeFoo2(Dart_NativeArguments args) { | 7511 static void NativeFoo2(Dart_NativeArguments args) { |
7738 Dart_EnterScope(); | 7512 Dart_EnterScope(); |
7739 intptr_t i = Dart_GetNativeArgumentCount(args); | 7513 intptr_t i = Dart_GetNativeArgumentCount(args); |
7740 EXPECT_EQ(2, i); | 7514 EXPECT_EQ(2, i); |
7741 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); | 7515 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); |
7742 EXPECT_VALID(arg1); | 7516 EXPECT_VALID(arg1); |
7743 int64_t value = 0; | 7517 int64_t value = 0; |
7744 EXPECT_VALID(Dart_IntegerToInt64(arg1, &value)); | 7518 EXPECT_VALID(Dart_IntegerToInt64(arg1, &value)); |
7745 int64_t integer_value = 0; | 7519 int64_t integer_value = 0; |
7746 Dart_Handle result = Dart_GetNativeIntegerArgument(args, 1, &integer_value); | 7520 Dart_Handle result = Dart_GetNativeIntegerArgument(args, 1, &integer_value); |
7747 EXPECT_VALID(result); | 7521 EXPECT_VALID(result); |
7748 EXPECT_EQ(value, integer_value); | 7522 EXPECT_EQ(value, integer_value); |
7749 double double_value; | 7523 double double_value; |
7750 result = Dart_GetNativeDoubleArgument(args, 1, &double_value); | 7524 result = Dart_GetNativeDoubleArgument(args, 1, &double_value); |
7751 EXPECT_VALID(result); | 7525 EXPECT_VALID(result); |
7752 bool bool_value; | 7526 bool bool_value; |
7753 result = Dart_GetNativeBooleanArgument(args, 1, &bool_value); | 7527 result = Dart_GetNativeBooleanArgument(args, 1, &bool_value); |
7754 EXPECT(Dart_IsError(result)); | 7528 EXPECT(Dart_IsError(result)); |
7755 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1))); | 7529 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1))); |
7756 Dart_ExitScope(); | 7530 Dart_ExitScope(); |
7757 } | 7531 } |
7758 | 7532 |
7759 | |
7760 static void NativeFoo3(Dart_NativeArguments args) { | 7533 static void NativeFoo3(Dart_NativeArguments args) { |
7761 Dart_EnterScope(); | 7534 Dart_EnterScope(); |
7762 intptr_t i = Dart_GetNativeArgumentCount(args); | 7535 intptr_t i = Dart_GetNativeArgumentCount(args); |
7763 EXPECT_EQ(3, i); | 7536 EXPECT_EQ(3, i); |
7764 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); | 7537 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); |
7765 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); | 7538 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); |
7766 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2))); | 7539 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2))); |
7767 Dart_ExitScope(); | 7540 Dart_ExitScope(); |
7768 } | 7541 } |
7769 | 7542 |
7770 | |
7771 static void NativeFoo4(Dart_NativeArguments args) { | 7543 static void NativeFoo4(Dart_NativeArguments args) { |
7772 Dart_EnterScope(); | 7544 Dart_EnterScope(); |
7773 intptr_t i = Dart_GetNativeArgumentCount(args); | 7545 intptr_t i = Dart_GetNativeArgumentCount(args); |
7774 EXPECT_EQ(4, i); | 7546 EXPECT_EQ(4, i); |
7775 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); | 7547 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); |
7776 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); | 7548 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); |
7777 Dart_Handle arg3 = Dart_GetNativeArgument(args, 3); | 7549 Dart_Handle arg3 = Dart_GetNativeArgument(args, 3); |
7778 Dart_SetReturnValue( | 7550 Dart_SetReturnValue( |
7779 args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2) + GetValue(arg3))); | 7551 args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2) + GetValue(arg3))); |
7780 Dart_ExitScope(); | 7552 Dart_ExitScope(); |
7781 } | 7553 } |
7782 | 7554 |
7783 | |
7784 static Dart_NativeFunction MyNativeClosureResolver(Dart_Handle name, | 7555 static Dart_NativeFunction MyNativeClosureResolver(Dart_Handle name, |
7785 int arg_count, | 7556 int arg_count, |
7786 bool* auto_setup_scope) { | 7557 bool* auto_setup_scope) { |
7787 ASSERT(auto_setup_scope != NULL); | 7558 ASSERT(auto_setup_scope != NULL); |
7788 *auto_setup_scope = false; | 7559 *auto_setup_scope = false; |
7789 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 7560 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
7790 if (!obj.IsString()) { | 7561 if (!obj.IsString()) { |
7791 return NULL; | 7562 return NULL; |
7792 } | 7563 } |
7793 const char* function_name = obj.ToCString(); | 7564 const char* function_name = obj.ToCString(); |
7794 const char* kNativeFoo1 = "NativeFoo1"; | 7565 const char* kNativeFoo1 = "NativeFoo1"; |
7795 const char* kNativeFoo2 = "NativeFoo2"; | 7566 const char* kNativeFoo2 = "NativeFoo2"; |
7796 const char* kNativeFoo3 = "NativeFoo3"; | 7567 const char* kNativeFoo3 = "NativeFoo3"; |
7797 const char* kNativeFoo4 = "NativeFoo4"; | 7568 const char* kNativeFoo4 = "NativeFoo4"; |
7798 if (!strncmp(function_name, kNativeFoo1, strlen(kNativeFoo1))) { | 7569 if (!strncmp(function_name, kNativeFoo1, strlen(kNativeFoo1))) { |
7799 return &NativeFoo1; | 7570 return &NativeFoo1; |
7800 } else if (!strncmp(function_name, kNativeFoo2, strlen(kNativeFoo2))) { | 7571 } else if (!strncmp(function_name, kNativeFoo2, strlen(kNativeFoo2))) { |
7801 return &NativeFoo2; | 7572 return &NativeFoo2; |
7802 } else if (!strncmp(function_name, kNativeFoo3, strlen(kNativeFoo3))) { | 7573 } else if (!strncmp(function_name, kNativeFoo3, strlen(kNativeFoo3))) { |
7803 return &NativeFoo3; | 7574 return &NativeFoo3; |
7804 } else if (!strncmp(function_name, kNativeFoo4, strlen(kNativeFoo4))) { | 7575 } else if (!strncmp(function_name, kNativeFoo4, strlen(kNativeFoo4))) { |
7805 return &NativeFoo4; | 7576 return &NativeFoo4; |
7806 } else { | 7577 } else { |
7807 UNREACHABLE(); | 7578 UNREACHABLE(); |
7808 return NULL; | 7579 return NULL; |
7809 } | 7580 } |
7810 } | 7581 } |
7811 | 7582 |
7812 | |
7813 TEST_CASE(NativeFunctionClosure) { | 7583 TEST_CASE(NativeFunctionClosure) { |
7814 const char* kScriptChars = | 7584 const char* kScriptChars = |
7815 "class Test {" | 7585 "class Test {" |
7816 " int foo1() native \"NativeFoo1\";\n" | 7586 " int foo1() native \"NativeFoo1\";\n" |
7817 " int foo2(int i) native \"NativeFoo2\";\n" | 7587 " int foo2(int i) native \"NativeFoo2\";\n" |
7818 " int foo3([int k = 10000, int l = 1]) native \"NativeFoo3\";\n" | 7588 " int foo3([int k = 10000, int l = 1]) native \"NativeFoo3\";\n" |
7819 " int foo4(int i," | 7589 " int foo4(int i," |
7820 " [int j = 10, int k = 1]) native \"NativeFoo4\";\n" | 7590 " [int j = 10, int k = 1]) native \"NativeFoo4\";\n" |
7821 " int bar1() { var func = foo1; return func(); }\n" | 7591 " int bar1() { var func = foo1; return func(); }\n" |
7822 " int bar2(int i) { var func = foo2; return func(i); }\n" | 7592 " int bar2(int i) { var func = foo2; return func(i); }\n" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7878 EXPECT_VALID(result); | 7648 EXPECT_VALID(result); |
7879 | 7649 |
7880 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7650 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
7881 EXPECT_VALID(result); | 7651 EXPECT_VALID(result); |
7882 EXPECT(Dart_IsInteger(result)); | 7652 EXPECT(Dart_IsInteger(result)); |
7883 int64_t value = 0; | 7653 int64_t value = 0; |
7884 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 7654 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
7885 EXPECT_EQ(0, value); | 7655 EXPECT_EQ(0, value); |
7886 } | 7656 } |
7887 | 7657 |
7888 | |
7889 static void StaticNativeFoo1(Dart_NativeArguments args) { | 7658 static void StaticNativeFoo1(Dart_NativeArguments args) { |
7890 Dart_EnterScope(); | 7659 Dart_EnterScope(); |
7891 intptr_t i = Dart_GetNativeArgumentCount(args); | 7660 intptr_t i = Dart_GetNativeArgumentCount(args); |
7892 EXPECT_EQ(0, i); | 7661 EXPECT_EQ(0, i); |
7893 Dart_SetReturnValue(args, Dart_NewInteger(0)); | 7662 Dart_SetReturnValue(args, Dart_NewInteger(0)); |
7894 Dart_ExitScope(); | 7663 Dart_ExitScope(); |
7895 } | 7664 } |
7896 | 7665 |
7897 | |
7898 static void StaticNativeFoo2(Dart_NativeArguments args) { | 7666 static void StaticNativeFoo2(Dart_NativeArguments args) { |
7899 Dart_EnterScope(); | 7667 Dart_EnterScope(); |
7900 intptr_t i = Dart_GetNativeArgumentCount(args); | 7668 intptr_t i = Dart_GetNativeArgumentCount(args); |
7901 EXPECT_EQ(1, i); | 7669 EXPECT_EQ(1, i); |
7902 Dart_Handle arg = Dart_GetNativeArgument(args, 0); | 7670 Dart_Handle arg = Dart_GetNativeArgument(args, 0); |
7903 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg))); | 7671 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg))); |
7904 Dart_ExitScope(); | 7672 Dart_ExitScope(); |
7905 } | 7673 } |
7906 | 7674 |
7907 | |
7908 static void StaticNativeFoo3(Dart_NativeArguments args) { | 7675 static void StaticNativeFoo3(Dart_NativeArguments args) { |
7909 Dart_EnterScope(); | 7676 Dart_EnterScope(); |
7910 intptr_t i = Dart_GetNativeArgumentCount(args); | 7677 intptr_t i = Dart_GetNativeArgumentCount(args); |
7911 EXPECT_EQ(2, i); | 7678 EXPECT_EQ(2, i); |
7912 Dart_Handle arg1 = Dart_GetNativeArgument(args, 0); | 7679 Dart_Handle arg1 = Dart_GetNativeArgument(args, 0); |
7913 Dart_Handle arg2 = Dart_GetNativeArgument(args, 1); | 7680 Dart_Handle arg2 = Dart_GetNativeArgument(args, 1); |
7914 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2))); | 7681 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2))); |
7915 Dart_ExitScope(); | 7682 Dart_ExitScope(); |
7916 } | 7683 } |
7917 | 7684 |
7918 | |
7919 static void StaticNativeFoo4(Dart_NativeArguments args) { | 7685 static void StaticNativeFoo4(Dart_NativeArguments args) { |
7920 Dart_EnterScope(); | 7686 Dart_EnterScope(); |
7921 intptr_t i = Dart_GetNativeArgumentCount(args); | 7687 intptr_t i = Dart_GetNativeArgumentCount(args); |
7922 EXPECT_EQ(3, i); | 7688 EXPECT_EQ(3, i); |
7923 Dart_Handle arg1 = Dart_GetNativeArgument(args, 0); | 7689 Dart_Handle arg1 = Dart_GetNativeArgument(args, 0); |
7924 Dart_Handle arg2 = Dart_GetNativeArgument(args, 1); | 7690 Dart_Handle arg2 = Dart_GetNativeArgument(args, 1); |
7925 Dart_Handle arg3 = Dart_GetNativeArgument(args, 2); | 7691 Dart_Handle arg3 = Dart_GetNativeArgument(args, 2); |
7926 Dart_SetReturnValue( | 7692 Dart_SetReturnValue( |
7927 args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2) + GetValue(arg3))); | 7693 args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2) + GetValue(arg3))); |
7928 Dart_ExitScope(); | 7694 Dart_ExitScope(); |
7929 } | 7695 } |
7930 | 7696 |
7931 | |
7932 static Dart_NativeFunction MyStaticNativeClosureResolver( | 7697 static Dart_NativeFunction MyStaticNativeClosureResolver( |
7933 Dart_Handle name, | 7698 Dart_Handle name, |
7934 int arg_count, | 7699 int arg_count, |
7935 bool* auto_setup_scope) { | 7700 bool* auto_setup_scope) { |
7936 ASSERT(auto_setup_scope != NULL); | 7701 ASSERT(auto_setup_scope != NULL); |
7937 *auto_setup_scope = false; | 7702 *auto_setup_scope = false; |
7938 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 7703 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
7939 if (!obj.IsString()) { | 7704 if (!obj.IsString()) { |
7940 return NULL; | 7705 return NULL; |
7941 } | 7706 } |
7942 const char* function_name = obj.ToCString(); | 7707 const char* function_name = obj.ToCString(); |
7943 const char* kNativeFoo1 = "StaticNativeFoo1"; | 7708 const char* kNativeFoo1 = "StaticNativeFoo1"; |
7944 const char* kNativeFoo2 = "StaticNativeFoo2"; | 7709 const char* kNativeFoo2 = "StaticNativeFoo2"; |
7945 const char* kNativeFoo3 = "StaticNativeFoo3"; | 7710 const char* kNativeFoo3 = "StaticNativeFoo3"; |
7946 const char* kNativeFoo4 = "StaticNativeFoo4"; | 7711 const char* kNativeFoo4 = "StaticNativeFoo4"; |
7947 if (!strncmp(function_name, kNativeFoo1, strlen(kNativeFoo1))) { | 7712 if (!strncmp(function_name, kNativeFoo1, strlen(kNativeFoo1))) { |
7948 return &StaticNativeFoo1; | 7713 return &StaticNativeFoo1; |
7949 } else if (!strncmp(function_name, kNativeFoo2, strlen(kNativeFoo2))) { | 7714 } else if (!strncmp(function_name, kNativeFoo2, strlen(kNativeFoo2))) { |
7950 return &StaticNativeFoo2; | 7715 return &StaticNativeFoo2; |
7951 } else if (!strncmp(function_name, kNativeFoo3, strlen(kNativeFoo3))) { | 7716 } else if (!strncmp(function_name, kNativeFoo3, strlen(kNativeFoo3))) { |
7952 return &StaticNativeFoo3; | 7717 return &StaticNativeFoo3; |
7953 } else if (!strncmp(function_name, kNativeFoo4, strlen(kNativeFoo4))) { | 7718 } else if (!strncmp(function_name, kNativeFoo4, strlen(kNativeFoo4))) { |
7954 return &StaticNativeFoo4; | 7719 return &StaticNativeFoo4; |
7955 } else { | 7720 } else { |
7956 UNREACHABLE(); | 7721 UNREACHABLE(); |
7957 return NULL; | 7722 return NULL; |
7958 } | 7723 } |
7959 } | 7724 } |
7960 | 7725 |
7961 | |
7962 TEST_CASE(NativeStaticFunctionClosure) { | 7726 TEST_CASE(NativeStaticFunctionClosure) { |
7963 const char* kScriptChars = | 7727 const char* kScriptChars = |
7964 "class Test {" | 7728 "class Test {" |
7965 " static int foo1() native \"StaticNativeFoo1\";\n" | 7729 " static int foo1() native \"StaticNativeFoo1\";\n" |
7966 " static int foo2(int i) native \"StaticNativeFoo2\";\n" | 7730 " static int foo2(int i) native \"StaticNativeFoo2\";\n" |
7967 " static int foo3([int k = 10000, int l = 1])" | 7731 " static int foo3([int k = 10000, int l = 1])" |
7968 " native \"StaticNativeFoo3\";\n" | 7732 " native \"StaticNativeFoo3\";\n" |
7969 " static int foo4(int i, [int j = 10, int k = 1])" | 7733 " static int foo4(int i, [int j = 10, int k = 1])" |
7970 " native \"StaticNativeFoo4\";\n" | 7734 " native \"StaticNativeFoo4\";\n" |
7971 " int bar1() { var func = foo1; return func(); }\n" | 7735 " int bar1() { var func = foo1; return func(); }\n" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8028 EXPECT_VALID(result); | 7792 EXPECT_VALID(result); |
8029 | 7793 |
8030 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7794 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
8031 EXPECT_VALID(result); | 7795 EXPECT_VALID(result); |
8032 EXPECT(Dart_IsInteger(result)); | 7796 EXPECT(Dart_IsInteger(result)); |
8033 int64_t value = 0; | 7797 int64_t value = 0; |
8034 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 7798 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
8035 EXPECT_EQ(0, value); | 7799 EXPECT_EQ(0, value); |
8036 } | 7800 } |
8037 | 7801 |
8038 | |
8039 TEST_CASE(RangeLimits) { | 7802 TEST_CASE(RangeLimits) { |
8040 uint8_t chars8[1] = {'a'}; | 7803 uint8_t chars8[1] = {'a'}; |
8041 uint16_t chars16[1] = {'a'}; | 7804 uint16_t chars16[1] = {'a'}; |
8042 int32_t chars32[1] = {'a'}; | 7805 int32_t chars32[1] = {'a'}; |
8043 | 7806 |
8044 EXPECT_ERROR(Dart_NewList(-1), | 7807 EXPECT_ERROR(Dart_NewList(-1), |
8045 "expects argument 'length' to be in the range"); | 7808 "expects argument 'length' to be in the range"); |
8046 EXPECT_ERROR(Dart_NewList(Array::kMaxElements + 1), | 7809 EXPECT_ERROR(Dart_NewList(Array::kMaxElements + 1), |
8047 "expects argument 'length' to be in the range"); | 7810 "expects argument 'length' to be in the range"); |
8048 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, -1), | 7811 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, -1), |
8049 "expects argument 'length' to be in the range"); | 7812 "expects argument 'length' to be in the range"); |
8050 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, OneByteString::kMaxElements + 1), | 7813 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, OneByteString::kMaxElements + 1), |
8051 "expects argument 'length' to be in the range"); | 7814 "expects argument 'length' to be in the range"); |
8052 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, -1), | 7815 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, -1), |
8053 "expects argument 'length' to be in the range"); | 7816 "expects argument 'length' to be in the range"); |
8054 EXPECT_ERROR( | 7817 EXPECT_ERROR( |
8055 Dart_NewStringFromUTF16(chars16, TwoByteString::kMaxElements + 1), | 7818 Dart_NewStringFromUTF16(chars16, TwoByteString::kMaxElements + 1), |
8056 "expects argument 'length' to be in the range"); | 7819 "expects argument 'length' to be in the range"); |
8057 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, -1), | 7820 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, -1), |
8058 "expects argument 'length' to be in the range"); | 7821 "expects argument 'length' to be in the range"); |
8059 EXPECT_ERROR( | 7822 EXPECT_ERROR( |
8060 Dart_NewStringFromUTF32(chars32, TwoByteString::kMaxElements + 1), | 7823 Dart_NewStringFromUTF32(chars32, TwoByteString::kMaxElements + 1), |
8061 "expects argument 'length' to be in the range"); | 7824 "expects argument 'length' to be in the range"); |
8062 } | 7825 } |
8063 | 7826 |
8064 | |
8065 TEST_CASE(NewString_Null) { | 7827 TEST_CASE(NewString_Null) { |
8066 Dart_Handle str = Dart_NewStringFromUTF8(NULL, 0); | 7828 Dart_Handle str = Dart_NewStringFromUTF8(NULL, 0); |
8067 EXPECT_VALID(str); | 7829 EXPECT_VALID(str); |
8068 EXPECT(Dart_IsString(str)); | 7830 EXPECT(Dart_IsString(str)); |
8069 intptr_t len = -1; | 7831 intptr_t len = -1; |
8070 EXPECT_VALID(Dart_StringLength(str, &len)); | 7832 EXPECT_VALID(Dart_StringLength(str, &len)); |
8071 EXPECT_EQ(0, len); | 7833 EXPECT_EQ(0, len); |
8072 | 7834 |
8073 str = Dart_NewStringFromUTF16(NULL, 0); | 7835 str = Dart_NewStringFromUTF16(NULL, 0); |
8074 EXPECT_VALID(str); | 7836 EXPECT_VALID(str); |
8075 EXPECT(Dart_IsString(str)); | 7837 EXPECT(Dart_IsString(str)); |
8076 len = -1; | 7838 len = -1; |
8077 EXPECT_VALID(Dart_StringLength(str, &len)); | 7839 EXPECT_VALID(Dart_StringLength(str, &len)); |
8078 EXPECT_EQ(0, len); | 7840 EXPECT_EQ(0, len); |
8079 | 7841 |
8080 str = Dart_NewStringFromUTF32(NULL, 0); | 7842 str = Dart_NewStringFromUTF32(NULL, 0); |
8081 EXPECT_VALID(str); | 7843 EXPECT_VALID(str); |
8082 EXPECT(Dart_IsString(str)); | 7844 EXPECT(Dart_IsString(str)); |
8083 len = -1; | 7845 len = -1; |
8084 EXPECT_VALID(Dart_StringLength(str, &len)); | 7846 EXPECT_VALID(Dart_StringLength(str, &len)); |
8085 EXPECT_EQ(0, len); | 7847 EXPECT_EQ(0, len); |
8086 } | 7848 } |
8087 | 7849 |
8088 | |
8089 // Try to allocate a peer with a handles to objects of prohibited | 7850 // Try to allocate a peer with a handles to objects of prohibited |
8090 // subtypes. | 7851 // subtypes. |
8091 TEST_CASE(InvalidGetSetPeer) { | 7852 TEST_CASE(InvalidGetSetPeer) { |
8092 void* out = &out; | 7853 void* out = &out; |
8093 EXPECT(Dart_IsError(Dart_GetPeer(Dart_Null(), &out))); | 7854 EXPECT(Dart_IsError(Dart_GetPeer(Dart_Null(), &out))); |
8094 EXPECT(out == &out); | 7855 EXPECT(out == &out); |
8095 EXPECT(Dart_IsError(Dart_SetPeer(Dart_Null(), &out))); | 7856 EXPECT(Dart_IsError(Dart_SetPeer(Dart_Null(), &out))); |
8096 out = &out; | 7857 out = &out; |
8097 EXPECT(Dart_IsError(Dart_GetPeer(Dart_True(), &out))); | 7858 EXPECT(Dart_IsError(Dart_GetPeer(Dart_True(), &out))); |
8098 EXPECT(out == &out); | 7859 EXPECT(out == &out); |
(...skipping 11 matching lines...) Expand all Loading... |
8110 Dart_Handle big = Dart_NewIntegerFromHexCString("0x10000000000000000"); | 7871 Dart_Handle big = Dart_NewIntegerFromHexCString("0x10000000000000000"); |
8111 EXPECT(Dart_IsError(Dart_GetPeer(big, &out))); | 7872 EXPECT(Dart_IsError(Dart_GetPeer(big, &out))); |
8112 EXPECT(out == &out); | 7873 EXPECT(out == &out); |
8113 EXPECT(Dart_IsError(Dart_SetPeer(big, &out))); | 7874 EXPECT(Dart_IsError(Dart_SetPeer(big, &out))); |
8114 Dart_Handle dbl = Dart_NewDouble(0.0); | 7875 Dart_Handle dbl = Dart_NewDouble(0.0); |
8115 EXPECT(Dart_IsError(Dart_GetPeer(dbl, &out))); | 7876 EXPECT(Dart_IsError(Dart_GetPeer(dbl, &out))); |
8116 EXPECT(out == &out); | 7877 EXPECT(out == &out); |
8117 EXPECT(Dart_IsError(Dart_SetPeer(dbl, &out))); | 7878 EXPECT(Dart_IsError(Dart_SetPeer(dbl, &out))); |
8118 } | 7879 } |
8119 | 7880 |
8120 | |
8121 // Allocates an object in new space and assigns it a peer. Removes | 7881 // Allocates an object in new space and assigns it a peer. Removes |
8122 // the peer and checks that the count of peer objects is decremented | 7882 // the peer and checks that the count of peer objects is decremented |
8123 // by one. | 7883 // by one. |
8124 TEST_CASE(OneNewSpacePeer) { | 7884 TEST_CASE(OneNewSpacePeer) { |
8125 Isolate* isolate = Isolate::Current(); | 7885 Isolate* isolate = Isolate::Current(); |
8126 Dart_Handle str = NewString("a string"); | 7886 Dart_Handle str = NewString("a string"); |
8127 EXPECT_VALID(str); | 7887 EXPECT_VALID(str); |
8128 EXPECT(Dart_IsString(str)); | 7888 EXPECT(Dart_IsString(str)); |
8129 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7889 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8130 void* out = &out; | 7890 void* out = &out; |
8131 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7891 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8132 EXPECT(out == NULL); | 7892 EXPECT(out == NULL); |
8133 int peer = 1234; | 7893 int peer = 1234; |
8134 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 7894 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
8135 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7895 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8136 out = &out; | 7896 out = &out; |
8137 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7897 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8138 EXPECT(out == reinterpret_cast<void*>(&peer)); | 7898 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8139 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 7899 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
8140 out = &out; | 7900 out = &out; |
8141 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7901 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8142 EXPECT(out == NULL); | 7902 EXPECT(out == NULL); |
8143 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7903 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8144 } | 7904 } |
8145 | 7905 |
8146 | |
8147 // Allocates an object in new space and assigns it a peer. Allows the | 7906 // Allocates an object in new space and assigns it a peer. Allows the |
8148 // peer referent to be garbage collected and checks that the count of | 7907 // peer referent to be garbage collected and checks that the count of |
8149 // peer objects is decremented by one. | 7908 // peer objects is decremented by one. |
8150 TEST_CASE(CollectOneNewSpacePeer) { | 7909 TEST_CASE(CollectOneNewSpacePeer) { |
8151 Isolate* isolate = Isolate::Current(); | 7910 Isolate* isolate = Isolate::Current(); |
8152 Dart_EnterScope(); | 7911 Dart_EnterScope(); |
8153 { | 7912 { |
8154 CHECK_API_SCOPE(thread); | 7913 CHECK_API_SCOPE(thread); |
8155 HANDLESCOPE(thread); | 7914 HANDLESCOPE(thread); |
8156 Dart_Handle str = NewString("a string"); | 7915 Dart_Handle str = NewString("a string"); |
(...skipping 19 matching lines...) Expand all Loading... |
8176 EXPECT(out == reinterpret_cast<void*>(&peer)); | 7935 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8177 } | 7936 } |
8178 Dart_ExitScope(); | 7937 Dart_ExitScope(); |
8179 { | 7938 { |
8180 TransitionNativeToVM transition(thread); | 7939 TransitionNativeToVM transition(thread); |
8181 isolate->heap()->CollectGarbage(Heap::kNew); | 7940 isolate->heap()->CollectGarbage(Heap::kNew); |
8182 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7941 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8183 } | 7942 } |
8184 } | 7943 } |
8185 | 7944 |
8186 | |
8187 // Allocates two objects in new space and assigns them peers. Removes | 7945 // Allocates two objects in new space and assigns them peers. Removes |
8188 // the peers and checks that the count of peer objects is decremented | 7946 // the peers and checks that the count of peer objects is decremented |
8189 // by two. | 7947 // by two. |
8190 TEST_CASE(TwoNewSpacePeers) { | 7948 TEST_CASE(TwoNewSpacePeers) { |
8191 Isolate* isolate = Isolate::Current(); | 7949 Isolate* isolate = Isolate::Current(); |
8192 Dart_Handle s1 = NewString("s1"); | 7950 Dart_Handle s1 = NewString("s1"); |
8193 EXPECT_VALID(s1); | 7951 EXPECT_VALID(s1); |
8194 EXPECT(Dart_IsString(s1)); | 7952 EXPECT(Dart_IsString(s1)); |
8195 void* o1 = &o1; | 7953 void* o1 = &o1; |
8196 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 7954 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
(...skipping 19 matching lines...) Expand all Loading... |
8216 EXPECT_VALID(Dart_SetPeer(s1, NULL)); | 7974 EXPECT_VALID(Dart_SetPeer(s1, NULL)); |
8217 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7975 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8218 EXPECT(Dart_GetPeer(s1, &o1)); | 7976 EXPECT(Dart_GetPeer(s1, &o1)); |
8219 EXPECT(o1 == NULL); | 7977 EXPECT(o1 == NULL); |
8220 EXPECT_VALID(Dart_SetPeer(s2, NULL)); | 7978 EXPECT_VALID(Dart_SetPeer(s2, NULL)); |
8221 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7979 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8222 EXPECT(Dart_GetPeer(s2, &o2)); | 7980 EXPECT(Dart_GetPeer(s2, &o2)); |
8223 EXPECT(o2 == NULL); | 7981 EXPECT(o2 == NULL); |
8224 } | 7982 } |
8225 | 7983 |
8226 | |
8227 // Allocates two objects in new space and assigns them a peer. Allow | 7984 // Allocates two objects in new space and assigns them a peer. Allow |
8228 // the peer referents to be garbage collected and check that the count | 7985 // the peer referents to be garbage collected and check that the count |
8229 // of peer objects is decremented by two. | 7986 // of peer objects is decremented by two. |
8230 TEST_CASE(CollectTwoNewSpacePeers) { | 7987 TEST_CASE(CollectTwoNewSpacePeers) { |
8231 Isolate* isolate = Isolate::Current(); | 7988 Isolate* isolate = Isolate::Current(); |
8232 Dart_EnterScope(); | 7989 Dart_EnterScope(); |
8233 { | 7990 { |
8234 CHECK_API_SCOPE(thread); | 7991 CHECK_API_SCOPE(thread); |
8235 HANDLESCOPE(thread); | 7992 HANDLESCOPE(thread); |
8236 Dart_Handle s1 = NewString("s1"); | 7993 Dart_Handle s1 = NewString("s1"); |
(...skipping 22 matching lines...) Expand all Loading... |
8259 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 8016 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
8260 } | 8017 } |
8261 Dart_ExitScope(); | 8018 Dart_ExitScope(); |
8262 { | 8019 { |
8263 TransitionNativeToVM transition(thread); | 8020 TransitionNativeToVM transition(thread); |
8264 isolate->heap()->CollectGarbage(Heap::kNew); | 8021 isolate->heap()->CollectGarbage(Heap::kNew); |
8265 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8022 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8266 } | 8023 } |
8267 } | 8024 } |
8268 | 8025 |
8269 | |
8270 // Allocates several objects in new space. Performs successive | 8026 // Allocates several objects in new space. Performs successive |
8271 // garbage collections and checks that the peer count is stable. | 8027 // garbage collections and checks that the peer count is stable. |
8272 TEST_CASE(CopyNewSpacePeers) { | 8028 TEST_CASE(CopyNewSpacePeers) { |
8273 const int kPeerCount = 10; | 8029 const int kPeerCount = 10; |
8274 Isolate* isolate = Isolate::Current(); | 8030 Isolate* isolate = Isolate::Current(); |
8275 Dart_Handle s[kPeerCount]; | 8031 Dart_Handle s[kPeerCount]; |
8276 for (int i = 0; i < kPeerCount; ++i) { | 8032 for (int i = 0; i < kPeerCount; ++i) { |
8277 s[i] = NewString("a string"); | 8033 s[i] = NewString("a string"); |
8278 EXPECT_VALID(s[i]); | 8034 EXPECT_VALID(s[i]); |
8279 EXPECT(Dart_IsString(s[i])); | 8035 EXPECT(Dart_IsString(s[i])); |
(...skipping 13 matching lines...) Expand all Loading... |
8293 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8049 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
8294 { | 8050 { |
8295 TransitionNativeToVM transition(thread); | 8051 TransitionNativeToVM transition(thread); |
8296 isolate->heap()->CollectGarbage(Heap::kNew); | 8052 isolate->heap()->CollectGarbage(Heap::kNew); |
8297 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8053 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
8298 isolate->heap()->CollectGarbage(Heap::kNew); | 8054 isolate->heap()->CollectGarbage(Heap::kNew); |
8299 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8055 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
8300 } | 8056 } |
8301 } | 8057 } |
8302 | 8058 |
8303 | |
8304 // Allocates an object in new space and assigns it a peer. Promotes | 8059 // Allocates an object in new space and assigns it a peer. Promotes |
8305 // the peer to old space. Removes the peer and check that the count | 8060 // the peer to old space. Removes the peer and check that the count |
8306 // of peer objects is decremented by one. | 8061 // of peer objects is decremented by one. |
8307 TEST_CASE(OnePromotedPeer) { | 8062 TEST_CASE(OnePromotedPeer) { |
8308 Isolate* isolate = Isolate::Current(); | 8063 Isolate* isolate = Isolate::Current(); |
8309 Dart_Handle str = NewString("a string"); | 8064 Dart_Handle str = NewString("a string"); |
8310 EXPECT_VALID(str); | 8065 EXPECT_VALID(str); |
8311 EXPECT(Dart_IsString(str)); | 8066 EXPECT(Dart_IsString(str)); |
8312 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8067 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8313 void* out = &out; | 8068 void* out = &out; |
(...skipping 20 matching lines...) Expand all Loading... |
8334 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8089 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8335 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8090 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8336 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8091 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8337 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8092 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
8338 out = &out; | 8093 out = &out; |
8339 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8094 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8340 EXPECT(out == NULL); | 8095 EXPECT(out == NULL); |
8341 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8096 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8342 } | 8097 } |
8343 | 8098 |
8344 | |
8345 // Allocates an object in old space and assigns it a peer. Removes | 8099 // Allocates an object in old space and assigns it a peer. Removes |
8346 // the peer and checks that the count of peer objects is decremented | 8100 // the peer and checks that the count of peer objects is decremented |
8347 // by one. | 8101 // by one. |
8348 TEST_CASE(OneOldSpacePeer) { | 8102 TEST_CASE(OneOldSpacePeer) { |
8349 Isolate* isolate = Isolate::Current(); | 8103 Isolate* isolate = Isolate::Current(); |
8350 Dart_Handle str = Api::NewHandle(thread, String::New("str", Heap::kOld)); | 8104 Dart_Handle str = Api::NewHandle(thread, String::New("str", Heap::kOld)); |
8351 EXPECT_VALID(str); | 8105 EXPECT_VALID(str); |
8352 EXPECT(Dart_IsString(str)); | 8106 EXPECT(Dart_IsString(str)); |
8353 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8107 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8354 void* out = &out; | 8108 void* out = &out; |
(...skipping 12 matching lines...) Expand all Loading... |
8367 } | 8121 } |
8368 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8122 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8369 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8123 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8370 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8124 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
8371 out = &out; | 8125 out = &out; |
8372 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8126 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8373 EXPECT(out == NULL); | 8127 EXPECT(out == NULL); |
8374 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8128 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8375 } | 8129 } |
8376 | 8130 |
8377 | |
8378 // Allocates an object in old space and assigns it a peer. Allow the | 8131 // Allocates an object in old space and assigns it a peer. Allow the |
8379 // peer referent to be garbage collected and check that the count of | 8132 // peer referent to be garbage collected and check that the count of |
8380 // peer objects is decremented by one. | 8133 // peer objects is decremented by one. |
8381 TEST_CASE(CollectOneOldSpacePeer) { | 8134 TEST_CASE(CollectOneOldSpacePeer) { |
8382 Isolate* isolate = Isolate::Current(); | 8135 Isolate* isolate = Isolate::Current(); |
8383 Dart_EnterScope(); | 8136 Dart_EnterScope(); |
8384 { | 8137 { |
8385 Thread* T = Thread::Current(); | 8138 Thread* T = Thread::Current(); |
8386 CHECK_API_SCOPE(T); | 8139 CHECK_API_SCOPE(T); |
8387 HANDLESCOPE(T); | 8140 HANDLESCOPE(T); |
(...skipping 19 matching lines...) Expand all Loading... |
8407 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8160 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8408 } | 8161 } |
8409 Dart_ExitScope(); | 8162 Dart_ExitScope(); |
8410 { | 8163 { |
8411 TransitionNativeToVM transition(thread); | 8164 TransitionNativeToVM transition(thread); |
8412 isolate->heap()->CollectGarbage(Heap::kOld); | 8165 isolate->heap()->CollectGarbage(Heap::kOld); |
8413 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8166 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8414 } | 8167 } |
8415 } | 8168 } |
8416 | 8169 |
8417 | |
8418 // Allocates two objects in old space and assigns them peers. Removes | 8170 // Allocates two objects in old space and assigns them peers. Removes |
8419 // the peers and checks that the count of peer objects is decremented | 8171 // the peers and checks that the count of peer objects is decremented |
8420 // by two. | 8172 // by two. |
8421 TEST_CASE(TwoOldSpacePeers) { | 8173 TEST_CASE(TwoOldSpacePeers) { |
8422 Isolate* isolate = Isolate::Current(); | 8174 Isolate* isolate = Isolate::Current(); |
8423 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); | 8175 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); |
8424 EXPECT_VALID(s1); | 8176 EXPECT_VALID(s1); |
8425 EXPECT(Dart_IsString(s1)); | 8177 EXPECT(Dart_IsString(s1)); |
8426 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8178 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8427 void* o1 = &o1; | 8179 void* o1 = &o1; |
(...skipping 23 matching lines...) Expand all Loading... |
8451 o1 = &o1; | 8203 o1 = &o1; |
8452 EXPECT(Dart_GetPeer(s1, &o1)); | 8204 EXPECT(Dart_GetPeer(s1, &o1)); |
8453 EXPECT(o1 == NULL); | 8205 EXPECT(o1 == NULL); |
8454 EXPECT_VALID(Dart_SetPeer(s2, NULL)); | 8206 EXPECT_VALID(Dart_SetPeer(s2, NULL)); |
8455 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8207 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8456 o2 = &o2; | 8208 o2 = &o2; |
8457 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 8209 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
8458 EXPECT(o2 == NULL); | 8210 EXPECT(o2 == NULL); |
8459 } | 8211 } |
8460 | 8212 |
8461 | |
8462 // Allocates two objects in old space and assigns them a peer. Allows | 8213 // Allocates two objects in old space and assigns them a peer. Allows |
8463 // the peer referents to be garbage collected and checks that the | 8214 // the peer referents to be garbage collected and checks that the |
8464 // count of peer objects is decremented by two. | 8215 // count of peer objects is decremented by two. |
8465 TEST_CASE(CollectTwoOldSpacePeers) { | 8216 TEST_CASE(CollectTwoOldSpacePeers) { |
8466 Isolate* isolate = Isolate::Current(); | 8217 Isolate* isolate = Isolate::Current(); |
8467 Dart_EnterScope(); | 8218 Dart_EnterScope(); |
8468 { | 8219 { |
8469 Thread* T = Thread::Current(); | 8220 Thread* T = Thread::Current(); |
8470 CHECK_API_SCOPE(T); | 8221 CHECK_API_SCOPE(T); |
8471 HANDLESCOPE(T); | 8222 HANDLESCOPE(T); |
(...skipping 25 matching lines...) Expand all Loading... |
8497 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 8248 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
8498 } | 8249 } |
8499 Dart_ExitScope(); | 8250 Dart_ExitScope(); |
8500 { | 8251 { |
8501 TransitionNativeToVM transition(thread); | 8252 TransitionNativeToVM transition(thread); |
8502 isolate->heap()->CollectGarbage(Heap::kOld); | 8253 isolate->heap()->CollectGarbage(Heap::kOld); |
8503 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8254 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8504 } | 8255 } |
8505 } | 8256 } |
8506 | 8257 |
8507 | |
8508 // Test API call to make strings external. | 8258 // Test API call to make strings external. |
8509 static void MakeExternalCback(void* peer) { | 8259 static void MakeExternalCback(void* peer) { |
8510 *static_cast<int*>(peer) *= 2; | 8260 *static_cast<int*>(peer) *= 2; |
8511 } | 8261 } |
8512 | 8262 |
8513 | |
8514 TEST_CASE(MakeExternalString) { | 8263 TEST_CASE(MakeExternalString) { |
8515 const bool saved_flag = FLAG_support_externalizable_strings; | 8264 const bool saved_flag = FLAG_support_externalizable_strings; |
8516 FLAG_support_externalizable_strings = true; | 8265 FLAG_support_externalizable_strings = true; |
8517 | 8266 |
8518 static int peer8 = 40; | 8267 static int peer8 = 40; |
8519 static int peer16 = 41; | 8268 static int peer16 = 41; |
8520 static int canonical_str_peer = 42; | 8269 static int canonical_str_peer = 42; |
8521 intptr_t length = 0; | 8270 intptr_t length = 0; |
8522 intptr_t expected_length = 0; | 8271 intptr_t expected_length = 0; |
8523 { | 8272 { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8689 Isolate::Current()->heap()->CollectAllGarbage(); | 8438 Isolate::Current()->heap()->CollectAllGarbage(); |
8690 GCTestHelper::WaitForGCTasks(); | 8439 GCTestHelper::WaitForGCTasks(); |
8691 } | 8440 } |
8692 EXPECT_EQ(80, peer8); | 8441 EXPECT_EQ(80, peer8); |
8693 EXPECT_EQ(82, peer16); | 8442 EXPECT_EQ(82, peer16); |
8694 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8443 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
8695 | 8444 |
8696 FLAG_support_externalizable_strings = saved_flag; | 8445 FLAG_support_externalizable_strings = saved_flag; |
8697 } | 8446 } |
8698 | 8447 |
8699 | |
8700 TEST_CASE(ExternalizeConstantStrings) { | 8448 TEST_CASE(ExternalizeConstantStrings) { |
8701 const bool saved_flag = FLAG_support_externalizable_strings; | 8449 const bool saved_flag = FLAG_support_externalizable_strings; |
8702 FLAG_support_externalizable_strings = true; | 8450 FLAG_support_externalizable_strings = true; |
8703 | 8451 |
8704 const char* kScriptChars = | 8452 const char* kScriptChars = |
8705 "String testMain() {\n" | 8453 "String testMain() {\n" |
8706 " return 'constant string';\n" | 8454 " return 'constant string';\n" |
8707 "}\n"; | 8455 "}\n"; |
8708 | 8456 |
8709 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 8457 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
8710 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 8458 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
8711 const char* expected_str = "constant string"; | 8459 const char* expected_str = "constant string"; |
8712 const intptr_t kExpectedLen = 15; | 8460 const intptr_t kExpectedLen = 15; |
8713 uint8_t ext_str[kExpectedLen]; | 8461 uint8_t ext_str[kExpectedLen]; |
8714 Dart_Handle str = | 8462 Dart_Handle str = |
8715 Dart_MakeExternalString(result, ext_str, kExpectedLen, NULL, NULL); | 8463 Dart_MakeExternalString(result, ext_str, kExpectedLen, NULL, NULL); |
8716 | 8464 |
8717 EXPECT(Dart_IsExternalString(str)); | 8465 EXPECT(Dart_IsExternalString(str)); |
8718 for (intptr_t i = 0; i < kExpectedLen; i++) { | 8466 for (intptr_t i = 0; i < kExpectedLen; i++) { |
8719 EXPECT_EQ(expected_str[i], ext_str[i]); | 8467 EXPECT_EQ(expected_str[i], ext_str[i]); |
8720 } | 8468 } |
8721 | 8469 |
8722 FLAG_support_externalizable_strings = saved_flag; | 8470 FLAG_support_externalizable_strings = saved_flag; |
8723 } | 8471 } |
8724 | 8472 |
8725 | |
8726 TEST_CASE(LazyLoadDeoptimizes) { | 8473 TEST_CASE(LazyLoadDeoptimizes) { |
8727 const char* kLoadFirst = | 8474 const char* kLoadFirst = |
8728 "library L;\n" | 8475 "library L;\n" |
8729 "start(a) {\n" | 8476 "start(a) {\n" |
8730 " var obj = (a == 1) ? createB() : new A();\n" | 8477 " var obj = (a == 1) ? createB() : new A();\n" |
8731 " for (int i = 0; i < 4000; i++) {\n" | 8478 " for (int i = 0; i < 4000; i++) {\n" |
8732 " var res = obj.foo();\n" | 8479 " var res = obj.foo();\n" |
8733 " if (a == 1) { if (res != 1) throw 'Error'; }\n" | 8480 " if (a == 1) { if (res != 1) throw 'Error'; }\n" |
8734 " else if (res != 2) throw 'Error'; \n" | 8481 " else if (res != 2) throw 'Error'; \n" |
8735 " }\n" | 8482 " }\n" |
(...skipping 22 matching lines...) Expand all Loading... |
8758 Dart_Handle url = NewString(TestCase::url()); | 8505 Dart_Handle url = NewString(TestCase::url()); |
8759 Dart_LoadSource(TestCase::lib(), url, Dart_Null(), source, 0, 0); | 8506 Dart_LoadSource(TestCase::lib(), url, Dart_Null(), source, 0, 0); |
8760 result = Dart_FinalizeLoading(false); | 8507 result = Dart_FinalizeLoading(false); |
8761 EXPECT_VALID(result); | 8508 EXPECT_VALID(result); |
8762 | 8509 |
8763 dart_args[0] = Dart_NewInteger(1); | 8510 dart_args[0] = Dart_NewInteger(1); |
8764 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 8511 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
8765 EXPECT_VALID(result); | 8512 EXPECT_VALID(result); |
8766 } | 8513 } |
8767 | 8514 |
8768 | |
8769 // Test external strings and optimized code. | 8515 // Test external strings and optimized code. |
8770 static void ExternalStringDeoptimize_Finalize(void* peer) { | 8516 static void ExternalStringDeoptimize_Finalize(void* peer) { |
8771 delete[] reinterpret_cast<char*>(peer); | 8517 delete[] reinterpret_cast<char*>(peer); |
8772 } | 8518 } |
8773 | 8519 |
8774 | |
8775 static void A_change_str_native(Dart_NativeArguments args) { | 8520 static void A_change_str_native(Dart_NativeArguments args) { |
8776 Dart_EnterScope(); | 8521 Dart_EnterScope(); |
8777 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 8522 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
8778 EXPECT(Dart_IsString(str)); | 8523 EXPECT(Dart_IsString(str)); |
8779 void* peer; | 8524 void* peer; |
8780 Dart_Handle str_arg = Dart_GetNativeStringArgument(args, 0, &peer); | 8525 Dart_Handle str_arg = Dart_GetNativeStringArgument(args, 0, &peer); |
8781 EXPECT(Dart_IsString(str_arg)); | 8526 EXPECT(Dart_IsString(str_arg)); |
8782 EXPECT(!peer); | 8527 EXPECT(!peer); |
8783 intptr_t size = 0; | 8528 intptr_t size = 0; |
8784 EXPECT_VALID(Dart_StringStorageSize(str, &size)); | 8529 EXPECT_VALID(Dart_StringStorageSize(str, &size)); |
8785 intptr_t arg_size = 0; | 8530 intptr_t arg_size = 0; |
8786 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size)); | 8531 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size)); |
8787 EXPECT_EQ(size, arg_size); | 8532 EXPECT_EQ(size, arg_size); |
8788 char* str_data = new char[size]; | 8533 char* str_data = new char[size]; |
8789 Dart_Handle result = Dart_MakeExternalString( | 8534 Dart_Handle result = Dart_MakeExternalString( |
8790 str, str_data, size, str_data, &ExternalStringDeoptimize_Finalize); | 8535 str, str_data, size, str_data, &ExternalStringDeoptimize_Finalize); |
8791 EXPECT_VALID(result); | 8536 EXPECT_VALID(result); |
8792 EXPECT(Dart_IsExternalString(result)); | 8537 EXPECT(Dart_IsExternalString(result)); |
8793 Dart_ExitScope(); | 8538 Dart_ExitScope(); |
8794 } | 8539 } |
8795 | 8540 |
8796 | |
8797 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( | 8541 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( |
8798 Dart_Handle name, | 8542 Dart_Handle name, |
8799 int argument_count, | 8543 int argument_count, |
8800 bool* auto_setup_scope) { | 8544 bool* auto_setup_scope) { |
8801 ASSERT(auto_setup_scope != NULL); | 8545 ASSERT(auto_setup_scope != NULL); |
8802 *auto_setup_scope = true; | 8546 *auto_setup_scope = true; |
8803 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); | 8547 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); |
8804 } | 8548 } |
8805 | 8549 |
8806 | |
8807 // Do not use guarding mechanism on externalizable classes, since their class | 8550 // Do not use guarding mechanism on externalizable classes, since their class |
8808 // can change on the fly, | 8551 // can change on the fly, |
8809 TEST_CASE(GuardExternalizedString) { | 8552 TEST_CASE(GuardExternalizedString) { |
8810 const bool saved_flag = FLAG_support_externalizable_strings; | 8553 const bool saved_flag = FLAG_support_externalizable_strings; |
8811 FLAG_support_externalizable_strings = true; | 8554 FLAG_support_externalizable_strings = true; |
8812 | 8555 |
8813 const char* kScriptChars = | 8556 const char* kScriptChars = |
8814 "main() {\n" | 8557 "main() {\n" |
8815 " var a = new A('hello');\n" | 8558 " var a = new A('hello');\n" |
8816 " var res = runOne(a);\n" | 8559 " var res = runOne(a);\n" |
(...skipping 21 matching lines...) Expand all Loading... |
8838 kScriptChars, &ExternalStringDeoptimize_native_lookup); | 8581 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
8839 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8582 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
8840 int64_t value = 0; | 8583 int64_t value = 0; |
8841 result = Dart_IntegerToInt64(result, &value); | 8584 result = Dart_IntegerToInt64(result, &value); |
8842 EXPECT_VALID(result); | 8585 EXPECT_VALID(result); |
8843 EXPECT_EQ(10640000, value); | 8586 EXPECT_EQ(10640000, value); |
8844 | 8587 |
8845 FLAG_support_externalizable_strings = saved_flag; | 8588 FLAG_support_externalizable_strings = saved_flag; |
8846 } | 8589 } |
8847 | 8590 |
8848 | |
8849 TEST_CASE(ExternalStringDeoptimize) { | 8591 TEST_CASE(ExternalStringDeoptimize) { |
8850 const bool saved_flag = FLAG_support_externalizable_strings; | 8592 const bool saved_flag = FLAG_support_externalizable_strings; |
8851 FLAG_support_externalizable_strings = true; | 8593 FLAG_support_externalizable_strings = true; |
8852 | 8594 |
8853 const char* kScriptChars = | 8595 const char* kScriptChars = |
8854 "String str = 'A';\n" | 8596 "String str = 'A';\n" |
8855 "class A {\n" | 8597 "class A {\n" |
8856 " static change_str(String s) native 'A_change_str';\n" | 8598 " static change_str(String s) native 'A_change_str';\n" |
8857 "}\n" | 8599 "}\n" |
8858 "sum_chars(String s, bool b) {\n" | 8600 "sum_chars(String s, bool b) {\n" |
(...skipping 15 matching lines...) Expand all Loading... |
8874 kScriptChars, &ExternalStringDeoptimize_native_lookup); | 8616 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
8875 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8617 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
8876 int64_t value = 0; | 8618 int64_t value = 0; |
8877 result = Dart_IntegerToInt64(result, &value); | 8619 result = Dart_IntegerToInt64(result, &value); |
8878 EXPECT_VALID(result); | 8620 EXPECT_VALID(result); |
8879 EXPECT_EQ(260, value); | 8621 EXPECT_EQ(260, value); |
8880 | 8622 |
8881 FLAG_support_externalizable_strings = saved_flag; | 8623 FLAG_support_externalizable_strings = saved_flag; |
8882 } | 8624 } |
8883 | 8625 |
8884 | |
8885 TEST_CASE(ExternalStringPolymorphicDeoptimize) { | 8626 TEST_CASE(ExternalStringPolymorphicDeoptimize) { |
8886 const bool saved_flag = FLAG_support_externalizable_strings; | 8627 const bool saved_flag = FLAG_support_externalizable_strings; |
8887 FLAG_support_externalizable_strings = true; | 8628 FLAG_support_externalizable_strings = true; |
8888 | 8629 |
8889 const char* kScriptChars = | 8630 const char* kScriptChars = |
8890 "const strA = 'AAAA';\n" | 8631 "const strA = 'AAAA';\n" |
8891 "class A {\n" | 8632 "class A {\n" |
8892 " static change_str(String s) native 'A_change_str';\n" | 8633 " static change_str(String s) native 'A_change_str';\n" |
8893 "}\n" | 8634 "}\n" |
8894 "compare(a, b, [i = 0]) {\n" | 8635 "compare(a, b, [i = 0]) {\n" |
(...skipping 16 matching lines...) Expand all Loading... |
8911 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8652 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
8912 EXPECT_VALID(result); | 8653 EXPECT_VALID(result); |
8913 bool value = false; | 8654 bool value = false; |
8914 result = Dart_BooleanValue(result, &value); | 8655 result = Dart_BooleanValue(result, &value); |
8915 EXPECT_VALID(result); | 8656 EXPECT_VALID(result); |
8916 EXPECT(value); | 8657 EXPECT(value); |
8917 | 8658 |
8918 FLAG_support_externalizable_strings = saved_flag; | 8659 FLAG_support_externalizable_strings = saved_flag; |
8919 } | 8660 } |
8920 | 8661 |
8921 | |
8922 TEST_CASE(ExternalStringLoadElimination) { | 8662 TEST_CASE(ExternalStringLoadElimination) { |
8923 const bool saved_flag = FLAG_support_externalizable_strings; | 8663 const bool saved_flag = FLAG_support_externalizable_strings; |
8924 FLAG_support_externalizable_strings = true; | 8664 FLAG_support_externalizable_strings = true; |
8925 | 8665 |
8926 const char* kScriptChars = | 8666 const char* kScriptChars = |
8927 "class A {\n" | 8667 "class A {\n" |
8928 " static change_str(String s) native 'A_change_str';\n" | 8668 " static change_str(String s) native 'A_change_str';\n" |
8929 "}\n" | 8669 "}\n" |
8930 "double_char0(str) {\n" | 8670 "double_char0(str) {\n" |
8931 " return str.codeUnitAt(0) + str.codeUnitAt(0);\n" | 8671 " return str.codeUnitAt(0) + str.codeUnitAt(0);\n" |
(...skipping 10 matching lines...) Expand all Loading... |
8942 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8682 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
8943 EXPECT_VALID(result); | 8683 EXPECT_VALID(result); |
8944 bool value = false; | 8684 bool value = false; |
8945 result = Dart_BooleanValue(result, &value); | 8685 result = Dart_BooleanValue(result, &value); |
8946 EXPECT_VALID(result); | 8686 EXPECT_VALID(result); |
8947 EXPECT(value); | 8687 EXPECT(value); |
8948 | 8688 |
8949 FLAG_support_externalizable_strings = saved_flag; | 8689 FLAG_support_externalizable_strings = saved_flag; |
8950 } | 8690 } |
8951 | 8691 |
8952 | |
8953 TEST_CASE(ExternalStringGuardFieldDeoptimize) { | 8692 TEST_CASE(ExternalStringGuardFieldDeoptimize) { |
8954 const bool saved_flag = FLAG_support_externalizable_strings; | 8693 const bool saved_flag = FLAG_support_externalizable_strings; |
8955 FLAG_support_externalizable_strings = true; | 8694 FLAG_support_externalizable_strings = true; |
8956 | 8695 |
8957 const char* kScriptChars = | 8696 const char* kScriptChars = |
8958 "const strA = 'AAAA';\n" | 8697 "const strA = 'AAAA';\n" |
8959 "class A {\n" | 8698 "class A {\n" |
8960 " static change_str(String s) native 'A_change_str';\n" | 8699 " static change_str(String s) native 'A_change_str';\n" |
8961 "}\n" | 8700 "}\n" |
8962 "class G { var f = 'A'; }\n" | 8701 "class G { var f = 'A'; }\n" |
(...skipping 21 matching lines...) Expand all Loading... |
8984 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8723 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
8985 EXPECT_VALID(result); | 8724 EXPECT_VALID(result); |
8986 bool value = false; | 8725 bool value = false; |
8987 result = Dart_BooleanValue(result, &value); | 8726 result = Dart_BooleanValue(result, &value); |
8988 EXPECT_VALID(result); | 8727 EXPECT_VALID(result); |
8989 EXPECT(value); | 8728 EXPECT(value); |
8990 | 8729 |
8991 FLAG_support_externalizable_strings = saved_flag; | 8730 FLAG_support_externalizable_strings = saved_flag; |
8992 } | 8731 } |
8993 | 8732 |
8994 | |
8995 TEST_CASE(ExternalStringStaticFieldDeoptimize) { | 8733 TEST_CASE(ExternalStringStaticFieldDeoptimize) { |
8996 const bool saved_flag = FLAG_support_externalizable_strings; | 8734 const bool saved_flag = FLAG_support_externalizable_strings; |
8997 FLAG_support_externalizable_strings = true; | 8735 FLAG_support_externalizable_strings = true; |
8998 | 8736 |
8999 const char* kScriptChars = | 8737 const char* kScriptChars = |
9000 "const strA = 'AAAA';\n" | 8738 "const strA = 'AAAA';\n" |
9001 "class A {\n" | 8739 "class A {\n" |
9002 " static change_str(String s) native 'A_change_str';\n" | 8740 " static change_str(String s) native 'A_change_str';\n" |
9003 "}\n" | 8741 "}\n" |
9004 "class G { static final f = strA; }\n" | 8742 "class G { static final f = strA; }\n" |
(...skipping 16 matching lines...) Expand all Loading... |
9021 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8759 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9022 EXPECT_VALID(result); | 8760 EXPECT_VALID(result); |
9023 bool value = false; | 8761 bool value = false; |
9024 result = Dart_BooleanValue(result, &value); | 8762 result = Dart_BooleanValue(result, &value); |
9025 EXPECT_VALID(result); | 8763 EXPECT_VALID(result); |
9026 EXPECT(value); | 8764 EXPECT(value); |
9027 | 8765 |
9028 FLAG_support_externalizable_strings = saved_flag; | 8766 FLAG_support_externalizable_strings = saved_flag; |
9029 } | 8767 } |
9030 | 8768 |
9031 | |
9032 TEST_CASE(ExternalStringTrimDoubleParse) { | 8769 TEST_CASE(ExternalStringTrimDoubleParse) { |
9033 const bool saved_flag = FLAG_support_externalizable_strings; | 8770 const bool saved_flag = FLAG_support_externalizable_strings; |
9034 FLAG_support_externalizable_strings = true; | 8771 FLAG_support_externalizable_strings = true; |
9035 | 8772 |
9036 const char* kScriptChars = | 8773 const char* kScriptChars = |
9037 "String str = 'A';\n" | 8774 "String str = 'A';\n" |
9038 "class A {\n" | 8775 "class A {\n" |
9039 " static change_str(String s) native 'A_change_str';\n" | 8776 " static change_str(String s) native 'A_change_str';\n" |
9040 "}\n" | 8777 "}\n" |
9041 "main() {\n" | 8778 "main() {\n" |
9042 " var externalOneByteString = ' 0.2\\xA0 ';\n;" | 8779 " var externalOneByteString = ' 0.2\\xA0 ';\n;" |
9043 " A.change_str(externalOneByteString);\n" | 8780 " A.change_str(externalOneByteString);\n" |
9044 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" | 8781 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" |
9045 " A.change_str(externalTwoByteString);\n" | 8782 " A.change_str(externalTwoByteString);\n" |
9046 " var x = double.parse(externalOneByteString);\n" | 8783 " var x = double.parse(externalOneByteString);\n" |
9047 " var y = double.parse(externalTwoByteString);\n" | 8784 " var y = double.parse(externalTwoByteString);\n" |
9048 " return ((x + y) * 10).toInt();\n" | 8785 " return ((x + y) * 10).toInt();\n" |
9049 "}\n"; | 8786 "}\n"; |
9050 Dart_Handle lib = TestCase::LoadTestScript( | 8787 Dart_Handle lib = TestCase::LoadTestScript( |
9051 kScriptChars, &ExternalStringDeoptimize_native_lookup); | 8788 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9052 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8789 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9053 int64_t value = 0; | 8790 int64_t value = 0; |
9054 result = Dart_IntegerToInt64(result, &value); | 8791 result = Dart_IntegerToInt64(result, &value); |
9055 EXPECT_VALID(result); | 8792 EXPECT_VALID(result); |
9056 EXPECT_EQ(8, value); | 8793 EXPECT_EQ(8, value); |
9057 | 8794 |
9058 FLAG_support_externalizable_strings = saved_flag; | 8795 FLAG_support_externalizable_strings = saved_flag; |
9059 } | 8796 } |
9060 | 8797 |
9061 | |
9062 TEST_CASE(ExternalStringDoubleParse) { | 8798 TEST_CASE(ExternalStringDoubleParse) { |
9063 const bool saved_flag = FLAG_support_externalizable_strings; | 8799 const bool saved_flag = FLAG_support_externalizable_strings; |
9064 FLAG_support_externalizable_strings = true; | 8800 FLAG_support_externalizable_strings = true; |
9065 | 8801 |
9066 const char* kScriptChars = | 8802 const char* kScriptChars = |
9067 "String str = 'A';\n" | 8803 "String str = 'A';\n" |
9068 "class A {\n" | 8804 "class A {\n" |
9069 " static change_str(String s) native 'A_change_str';\n" | 8805 " static change_str(String s) native 'A_change_str';\n" |
9070 "}\n" | 8806 "}\n" |
9071 "main() {\n" | 8807 "main() {\n" |
9072 " var externalOneByteString = '0.2';\n;" | 8808 " var externalOneByteString = '0.2';\n;" |
9073 " A.change_str(externalOneByteString);\n" | 8809 " A.change_str(externalOneByteString);\n" |
9074 " var externalTwoByteString = '0.6';\n" | 8810 " var externalTwoByteString = '0.6';\n" |
9075 " A.change_str(externalTwoByteString);\n" | 8811 " A.change_str(externalTwoByteString);\n" |
9076 " var x = double.parse(externalOneByteString);\n" | 8812 " var x = double.parse(externalOneByteString);\n" |
9077 " var y = double.parse(externalTwoByteString);\n" | 8813 " var y = double.parse(externalTwoByteString);\n" |
9078 " return ((x + y) * 10).toInt();\n" | 8814 " return ((x + y) * 10).toInt();\n" |
9079 "}\n"; | 8815 "}\n"; |
9080 Dart_Handle lib = TestCase::LoadTestScript( | 8816 Dart_Handle lib = TestCase::LoadTestScript( |
9081 kScriptChars, &ExternalStringDeoptimize_native_lookup); | 8817 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9082 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 8818 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9083 int64_t value = 0; | 8819 int64_t value = 0; |
9084 result = Dart_IntegerToInt64(result, &value); | 8820 result = Dart_IntegerToInt64(result, &value); |
9085 EXPECT_VALID(result); | 8821 EXPECT_VALID(result); |
9086 EXPECT_EQ(8, value); | 8822 EXPECT_EQ(8, value); |
9087 | 8823 |
9088 FLAG_support_externalizable_strings = saved_flag; | 8824 FLAG_support_externalizable_strings = saved_flag; |
9089 } | 8825 } |
9090 | 8826 |
9091 | |
9092 TEST_CASE(ExternalStringIndexOf) { | 8827 TEST_CASE(ExternalStringIndexOf) { |
9093 const char* kScriptChars = | 8828 const char* kScriptChars = |
9094 "main(String pattern) {\n" | 8829 "main(String pattern) {\n" |
9095 " var str = 'Hello World';\n" | 8830 " var str = 'Hello World';\n" |
9096 " return str.indexOf(pattern);\n" | 8831 " return str.indexOf(pattern);\n" |
9097 "}\n"; | 8832 "}\n"; |
9098 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 8833 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9099 | 8834 |
9100 uint8_t data8[] = {'W'}; | 8835 uint8_t data8[] = {'W'}; |
9101 Dart_Handle ext8 = | 8836 Dart_Handle ext8 = |
9102 Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), data8, NULL); | 8837 Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), data8, NULL); |
9103 EXPECT_VALID(ext8); | 8838 EXPECT_VALID(ext8); |
9104 EXPECT(Dart_IsString(ext8)); | 8839 EXPECT(Dart_IsString(ext8)); |
9105 EXPECT(Dart_IsExternalString(ext8)); | 8840 EXPECT(Dart_IsExternalString(ext8)); |
9106 | 8841 |
9107 Dart_Handle dart_args[1]; | 8842 Dart_Handle dart_args[1]; |
9108 dart_args[0] = ext8; | 8843 dart_args[0] = ext8; |
9109 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 1, dart_args); | 8844 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 1, dart_args); |
9110 int64_t value = 0; | 8845 int64_t value = 0; |
9111 result = Dart_IntegerToInt64(result, &value); | 8846 result = Dart_IntegerToInt64(result, &value); |
9112 EXPECT_VALID(result); | 8847 EXPECT_VALID(result); |
9113 EXPECT_EQ(6, value); | 8848 EXPECT_EQ(6, value); |
9114 } | 8849 } |
9115 | 8850 |
9116 | |
9117 TEST_CASE(StringFromExternalTypedData) { | 8851 TEST_CASE(StringFromExternalTypedData) { |
9118 const char* kScriptChars = | 8852 const char* kScriptChars = |
9119 "test(external) {\n" | 8853 "test(external) {\n" |
9120 " var str1 = new String.fromCharCodes(external);\n" | 8854 " var str1 = new String.fromCharCodes(external);\n" |
9121 " var str2 = new String.fromCharCodes(new List.from(external));\n" | 8855 " var str2 = new String.fromCharCodes(new List.from(external));\n" |
9122 " if (str2 != str1) throw 'FAIL';\n" | 8856 " if (str2 != str1) throw 'FAIL';\n" |
9123 " return str1;\n" | 8857 " return str1;\n" |
9124 "}\n" | 8858 "}\n" |
9125 "testView8(external) {\n" | 8859 "testView8(external) {\n" |
9126 " return test(external.buffer.asUint8List());\n" | 8860 " return test(external.buffer.asUint8List());\n" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9184 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 1, dart_args); | 8918 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 1, dart_args); |
9185 EXPECT_VALID(result); | 8919 EXPECT_VALID(result); |
9186 EXPECT(Dart_IsString(result)); | 8920 EXPECT(Dart_IsString(result)); |
9187 | 8921 |
9188 result = Dart_Invoke(lib, NewString("testView16"), 1, dart_args); | 8922 result = Dart_Invoke(lib, NewString("testView16"), 1, dart_args); |
9189 EXPECT_VALID(result); | 8923 EXPECT_VALID(result); |
9190 EXPECT(Dart_IsString(result)); | 8924 EXPECT(Dart_IsString(result)); |
9191 } | 8925 } |
9192 } | 8926 } |
9193 | 8927 |
9194 | |
9195 #ifndef PRODUCT | 8928 #ifndef PRODUCT |
9196 | 8929 |
9197 | |
9198 TEST_CASE(Timeline_Dart_TimelineDuration) { | 8930 TEST_CASE(Timeline_Dart_TimelineDuration) { |
9199 Isolate* isolate = Isolate::Current(); | 8931 Isolate* isolate = Isolate::Current(); |
9200 // Grab embedder stream. | 8932 // Grab embedder stream. |
9201 TimelineStream* stream = Timeline::GetEmbedderStream(); | 8933 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9202 // Make sure it is enabled. | 8934 // Make sure it is enabled. |
9203 stream->set_enabled(true); | 8935 stream->set_enabled(true); |
9204 // Add a duration event. | 8936 // Add a duration event. |
9205 Dart_TimelineEvent("testDurationEvent", 0, 1, Dart_Timeline_Event_Duration, 0, | 8937 Dart_TimelineEvent("testDurationEvent", 0, 1, Dart_Timeline_Event_Duration, 0, |
9206 NULL, NULL); | 8938 NULL, NULL); |
9207 // Check that it is in the output. | 8939 // Check that it is in the output. |
9208 TimelineEventRecorder* recorder = Timeline::recorder(); | 8940 TimelineEventRecorder* recorder = Timeline::recorder(); |
9209 Timeline::ReclaimCachedBlocksFromThreads(); | 8941 Timeline::ReclaimCachedBlocksFromThreads(); |
9210 JSONStream js; | 8942 JSONStream js; |
9211 IsolateTimelineEventFilter filter(isolate->main_port()); | 8943 IsolateTimelineEventFilter filter(isolate->main_port()); |
9212 recorder->PrintJSON(&js, &filter); | 8944 recorder->PrintJSON(&js, &filter); |
9213 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); | 8945 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); |
9214 } | 8946 } |
9215 | 8947 |
9216 | |
9217 TEST_CASE(Timeline_Dart_TimelineInstant) { | 8948 TEST_CASE(Timeline_Dart_TimelineInstant) { |
9218 Isolate* isolate = Isolate::Current(); | 8949 Isolate* isolate = Isolate::Current(); |
9219 // Grab embedder stream. | 8950 // Grab embedder stream. |
9220 TimelineStream* stream = Timeline::GetEmbedderStream(); | 8951 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9221 // Make sure it is enabled. | 8952 // Make sure it is enabled. |
9222 stream->set_enabled(true); | 8953 stream->set_enabled(true); |
9223 Dart_TimelineEvent("testInstantEvent", 0, 1, Dart_Timeline_Event_Instant, 0, | 8954 Dart_TimelineEvent("testInstantEvent", 0, 1, Dart_Timeline_Event_Instant, 0, |
9224 NULL, NULL); | 8955 NULL, NULL); |
9225 // Check that it is in the output. | 8956 // Check that it is in the output. |
9226 TimelineEventRecorder* recorder = Timeline::recorder(); | 8957 TimelineEventRecorder* recorder = Timeline::recorder(); |
9227 Timeline::ReclaimCachedBlocksFromThreads(); | 8958 Timeline::ReclaimCachedBlocksFromThreads(); |
9228 JSONStream js; | 8959 JSONStream js; |
9229 IsolateTimelineEventFilter filter(isolate->main_port()); | 8960 IsolateTimelineEventFilter filter(isolate->main_port()); |
9230 recorder->PrintJSON(&js, &filter); | 8961 recorder->PrintJSON(&js, &filter); |
9231 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); | 8962 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); |
9232 } | 8963 } |
9233 | 8964 |
9234 | |
9235 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { | 8965 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { |
9236 // Grab embedder stream. | 8966 // Grab embedder stream. |
9237 TimelineStream* stream = Timeline::GetEmbedderStream(); | 8967 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9238 // Make sure it is disabled. | 8968 // Make sure it is disabled. |
9239 stream->set_enabled(false); | 8969 stream->set_enabled(false); |
9240 int64_t async_id = 99; | 8970 int64_t async_id = 99; |
9241 Dart_TimelineEvent("testAsyncEvent", 0, async_id, | 8971 Dart_TimelineEvent("testAsyncEvent", 0, async_id, |
9242 Dart_Timeline_Event_Async_Begin, 0, NULL, NULL); | 8972 Dart_Timeline_Event_Async_Begin, 0, NULL, NULL); |
9243 // Check that testAsync is not in the output. | 8973 // Check that testAsync is not in the output. |
9244 TimelineEventRecorder* recorder = Timeline::recorder(); | 8974 TimelineEventRecorder* recorder = Timeline::recorder(); |
9245 Timeline::ReclaimCachedBlocksFromThreads(); | 8975 Timeline::ReclaimCachedBlocksFromThreads(); |
9246 JSONStream js; | 8976 JSONStream js; |
9247 TimelineEventFilter filter; | 8977 TimelineEventFilter filter; |
9248 recorder->PrintJSON(&js, &filter); | 8978 recorder->PrintJSON(&js, &filter); |
9249 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); | 8979 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); |
9250 } | 8980 } |
9251 | 8981 |
9252 | |
9253 TEST_CASE(Timeline_Dart_TimelineAsync) { | 8982 TEST_CASE(Timeline_Dart_TimelineAsync) { |
9254 Isolate* isolate = Isolate::Current(); | 8983 Isolate* isolate = Isolate::Current(); |
9255 // Grab embedder stream. | 8984 // Grab embedder stream. |
9256 TimelineStream* stream = Timeline::GetEmbedderStream(); | 8985 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9257 // Make sure it is enabled. | 8986 // Make sure it is enabled. |
9258 stream->set_enabled(true); | 8987 stream->set_enabled(true); |
9259 int64_t async_id = 99; | 8988 int64_t async_id = 99; |
9260 Dart_TimelineEvent("testAsyncEvent", 0, async_id, | 8989 Dart_TimelineEvent("testAsyncEvent", 0, async_id, |
9261 Dart_Timeline_Event_Async_Begin, 0, NULL, NULL); | 8990 Dart_Timeline_Event_Async_Begin, 0, NULL, NULL); |
9262 | 8991 |
9263 // Check that it is in the output. | 8992 // Check that it is in the output. |
9264 TimelineEventRecorder* recorder = Timeline::recorder(); | 8993 TimelineEventRecorder* recorder = Timeline::recorder(); |
9265 Timeline::ReclaimCachedBlocksFromThreads(); | 8994 Timeline::ReclaimCachedBlocksFromThreads(); |
9266 JSONStream js; | 8995 JSONStream js; |
9267 IsolateTimelineEventFilter filter(isolate->main_port()); | 8996 IsolateTimelineEventFilter filter(isolate->main_port()); |
9268 recorder->PrintJSON(&js, &filter); | 8997 recorder->PrintJSON(&js, &filter); |
9269 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); | 8998 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); |
9270 } | 8999 } |
9271 | 9000 |
9272 | |
9273 struct AppendData { | 9001 struct AppendData { |
9274 uint8_t* buffer; | 9002 uint8_t* buffer; |
9275 intptr_t buffer_length; | 9003 intptr_t buffer_length; |
9276 }; | 9004 }; |
9277 | 9005 |
9278 | |
9279 static void AppendStreamConsumer(Dart_StreamConsumer_State state, | 9006 static void AppendStreamConsumer(Dart_StreamConsumer_State state, |
9280 const char* stream_name, | 9007 const char* stream_name, |
9281 const uint8_t* buffer, | 9008 const uint8_t* buffer, |
9282 intptr_t buffer_length, | 9009 intptr_t buffer_length, |
9283 void* user_data) { | 9010 void* user_data) { |
9284 if (state == Dart_StreamConsumer_kFinish) { | 9011 if (state == Dart_StreamConsumer_kFinish) { |
9285 return; | 9012 return; |
9286 } | 9013 } |
9287 AppendData* data = reinterpret_cast<AppendData*>(user_data); | 9014 AppendData* data = reinterpret_cast<AppendData*>(user_data); |
9288 if (state == Dart_StreamConsumer_kStart) { | 9015 if (state == Dart_StreamConsumer_kStart) { |
9289 // Initialize append data. | 9016 // Initialize append data. |
9290 data->buffer = NULL; | 9017 data->buffer = NULL; |
9291 data->buffer_length = 0; | 9018 data->buffer_length = 0; |
9292 return; | 9019 return; |
9293 } | 9020 } |
9294 ASSERT(state == Dart_StreamConsumer_kData); | 9021 ASSERT(state == Dart_StreamConsumer_kData); |
9295 | 9022 |
9296 // Grow buffer. | 9023 // Grow buffer. |
9297 data->buffer = reinterpret_cast<uint8_t*>( | 9024 data->buffer = reinterpret_cast<uint8_t*>( |
9298 realloc(data->buffer, data->buffer_length + buffer_length)); | 9025 realloc(data->buffer, data->buffer_length + buffer_length)); |
9299 // Copy new data. | 9026 // Copy new data. |
9300 memmove(&data->buffer[data->buffer_length], buffer, buffer_length); | 9027 memmove(&data->buffer[data->buffer_length], buffer, buffer_length); |
9301 // Update length. | 9028 // Update length. |
9302 data->buffer_length += buffer_length; | 9029 data->buffer_length += buffer_length; |
9303 } | 9030 } |
9304 | 9031 |
9305 | |
9306 TEST_CASE(Timeline_Dart_TimelineGetTrace) { | 9032 TEST_CASE(Timeline_Dart_TimelineGetTrace) { |
9307 const char* kScriptChars = | 9033 const char* kScriptChars = |
9308 "foo() => 'a';\n" | 9034 "foo() => 'a';\n" |
9309 "main() => foo();\n"; | 9035 "main() => foo();\n"; |
9310 | 9036 |
9311 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 9037 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9312 | 9038 |
9313 const char* buffer = NULL; | 9039 const char* buffer = NULL; |
9314 intptr_t buffer_length = 0; | 9040 intptr_t buffer_length = 0; |
9315 bool success = false; | 9041 bool success = false; |
(...skipping 23 matching lines...) Expand all Loading... |
9339 | 9065 |
9340 // Heartbeat test. | 9066 // Heartbeat test. |
9341 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9067 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9342 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9068 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9343 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9069 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9344 | 9070 |
9345 // Free buffer allocated by AppendStreamConsumer | 9071 // Free buffer allocated by AppendStreamConsumer |
9346 free(data.buffer); | 9072 free(data.buffer); |
9347 } | 9073 } |
9348 | 9074 |
9349 | |
9350 TEST_CASE(Timeline_Dart_TimelineGetTraceOnlyDartEvents) { | 9075 TEST_CASE(Timeline_Dart_TimelineGetTraceOnlyDartEvents) { |
9351 const char* kScriptChars = | 9076 const char* kScriptChars = |
9352 "import 'dart:developer';\n" | 9077 "import 'dart:developer';\n" |
9353 "" | 9078 "" |
9354 "main() {\n" | 9079 "main() {\n" |
9355 " Timeline.startSync('DART_NAME');\n" | 9080 " Timeline.startSync('DART_NAME');\n" |
9356 " Timeline.finishSync();\n" | 9081 " Timeline.finishSync();\n" |
9357 "}\n"; | 9082 "}\n"; |
9358 | 9083 |
9359 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 9084 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
(...skipping 27 matching lines...) Expand all Loading... |
9387 EXPECT(buffer[buffer_length - 2] == '}'); | 9112 EXPECT(buffer[buffer_length - 2] == '}'); |
9388 | 9113 |
9389 // Heartbeat test. | 9114 // Heartbeat test. |
9390 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer); | 9115 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer); |
9391 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); | 9116 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); |
9392 | 9117 |
9393 // Free buffer allocated by AppendStreamConsumer | 9118 // Free buffer allocated by AppendStreamConsumer |
9394 free(data.buffer); | 9119 free(data.buffer); |
9395 } | 9120 } |
9396 | 9121 |
9397 | |
9398 TEST_CASE(Timeline_Dart_TimelineGetTraceWithDartEvents) { | 9122 TEST_CASE(Timeline_Dart_TimelineGetTraceWithDartEvents) { |
9399 const char* kScriptChars = | 9123 const char* kScriptChars = |
9400 "import 'dart:developer';\n" | 9124 "import 'dart:developer';\n" |
9401 "\n" | 9125 "\n" |
9402 "main() {\n" | 9126 "main() {\n" |
9403 " Timeline.startSync('DART_NAME');\n" | 9127 " Timeline.startSync('DART_NAME');\n" |
9404 " Timeline.finishSync();\n" | 9128 " Timeline.finishSync();\n" |
9405 "}\n"; | 9129 "}\n"; |
9406 | 9130 |
9407 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 9131 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9480 | 9204 |
9481 // Heartbeat test. | 9205 // Heartbeat test. |
9482 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9206 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9483 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9207 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9484 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9208 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9485 | 9209 |
9486 // Free buffer allocated by AppendStreamConsumer | 9210 // Free buffer allocated by AppendStreamConsumer |
9487 free(data.buffer); | 9211 free(data.buffer); |
9488 } | 9212 } |
9489 | 9213 |
9490 | |
9491 static const char* arg_names[] = {"arg0"}; | 9214 static const char* arg_names[] = {"arg0"}; |
9492 | 9215 |
9493 | |
9494 static const char* arg_values[] = {"value0"}; | 9216 static const char* arg_values[] = {"value0"}; |
9495 | 9217 |
9496 | |
9497 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { | 9218 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { |
9498 const char* kScriptChars = | 9219 const char* kScriptChars = |
9499 "bar() => 'z';\n" | 9220 "bar() => 'z';\n" |
9500 "foo() => 'a';\n" | 9221 "foo() => 'a';\n" |
9501 "main() => foo();\n"; | 9222 "main() => foo();\n"; |
9502 | 9223 |
9503 // Enable all streams. | 9224 // Enable all streams. |
9504 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | | 9225 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | |
9505 DART_TIMELINE_STREAM_VM); | 9226 DART_TIMELINE_STREAM_VM); |
9506 Dart_Handle lib; | 9227 Dart_Handle lib; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9604 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9325 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9605 | 9326 |
9606 // Heartbeat test for new events. | 9327 // Heartbeat test for new events. |
9607 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9328 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9608 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9329 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9609 | 9330 |
9610 // Free buffer allocated by AppendStreamConsumer | 9331 // Free buffer allocated by AppendStreamConsumer |
9611 free(data.buffer); | 9332 free(data.buffer); |
9612 } | 9333 } |
9613 | 9334 |
9614 | |
9615 class GlobalTimelineThreadData { | 9335 class GlobalTimelineThreadData { |
9616 public: | 9336 public: |
9617 GlobalTimelineThreadData() | 9337 GlobalTimelineThreadData() |
9618 : monitor_(new Monitor()), data_(new AppendData()), running_(true) {} | 9338 : monitor_(new Monitor()), data_(new AppendData()), running_(true) {} |
9619 | 9339 |
9620 ~GlobalTimelineThreadData() { | 9340 ~GlobalTimelineThreadData() { |
9621 delete monitor_; | 9341 delete monitor_; |
9622 monitor_ = NULL; | 9342 monitor_ = NULL; |
9623 free(data_->buffer); | 9343 free(data_->buffer); |
9624 data_->buffer = NULL; | 9344 data_->buffer = NULL; |
9625 data_->buffer_length = 0; | 9345 data_->buffer_length = 0; |
9626 delete data_; | 9346 delete data_; |
9627 data_ = NULL; | 9347 data_ = NULL; |
9628 } | 9348 } |
9629 | 9349 |
9630 Monitor* monitor() const { return monitor_; } | 9350 Monitor* monitor() const { return monitor_; } |
9631 bool running() const { return running_; } | 9351 bool running() const { return running_; } |
9632 AppendData* data() const { return data_; } | 9352 AppendData* data() const { return data_; } |
9633 uint8_t* buffer() const { return data_->buffer; } | 9353 uint8_t* buffer() const { return data_->buffer; } |
9634 intptr_t buffer_length() const { return data_->buffer_length; } | 9354 intptr_t buffer_length() const { return data_->buffer_length; } |
9635 | 9355 |
9636 void set_running(bool running) { running_ = running; } | 9356 void set_running(bool running) { running_ = running; } |
9637 | 9357 |
9638 private: | 9358 private: |
9639 Monitor* monitor_; | 9359 Monitor* monitor_; |
9640 AppendData* data_; | 9360 AppendData* data_; |
9641 bool running_; | 9361 bool running_; |
9642 }; | 9362 }; |
9643 | 9363 |
9644 | |
9645 static void GlobalTimelineThread(uword parameter) { | 9364 static void GlobalTimelineThread(uword parameter) { |
9646 GlobalTimelineThreadData* data = | 9365 GlobalTimelineThreadData* data = |
9647 reinterpret_cast<GlobalTimelineThreadData*>(parameter); | 9366 reinterpret_cast<GlobalTimelineThreadData*>(parameter); |
9648 Thread* T = Thread::Current(); | 9367 Thread* T = Thread::Current(); |
9649 // When there is no current Thread, then Zone allocation will fail. | 9368 // When there is no current Thread, then Zone allocation will fail. |
9650 EXPECT(T == NULL); | 9369 EXPECT(T == NULL); |
9651 { | 9370 { |
9652 MonitorLocker ml(data->monitor()); | 9371 MonitorLocker ml(data->monitor()); |
9653 bool success = | 9372 bool success = |
9654 Dart_GlobalTimelineGetTrace(AppendStreamConsumer, data->data()); | 9373 Dart_GlobalTimelineGetTrace(AppendStreamConsumer, data->data()); |
9655 EXPECT(success); | 9374 EXPECT(success); |
9656 data->set_running(false); | 9375 data->set_running(false); |
9657 ml.Notify(); | 9376 ml.Notify(); |
9658 } | 9377 } |
9659 } | 9378 } |
9660 | 9379 |
9661 | |
9662 // This test is the same as the one above except that the calls to | 9380 // This test is the same as the one above except that the calls to |
9663 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that | 9381 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that |
9664 // we can call the function from a thread for which we have not set up a | 9382 // we can call the function from a thread for which we have not set up a |
9665 // Thread object. | 9383 // Thread object. |
9666 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) { | 9384 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) { |
9667 const char* kScriptChars = | 9385 const char* kScriptChars = |
9668 "bar() => 'z';\n" | 9386 "bar() => 'z';\n" |
9669 "foo() => 'a';\n" | 9387 "foo() => 'a';\n" |
9670 "main() => foo();\n"; | 9388 "main() => foo();\n"; |
9671 | 9389 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9764 static bool stop_called = false; | 9482 static bool stop_called = false; |
9765 | 9483 |
9766 static void StartRecording() { | 9484 static void StartRecording() { |
9767 start_called = true; | 9485 start_called = true; |
9768 } | 9486 } |
9769 | 9487 |
9770 static void StopRecording() { | 9488 static void StopRecording() { |
9771 stop_called = true; | 9489 stop_called = true; |
9772 } | 9490 } |
9773 | 9491 |
9774 | |
9775 TEST_CASE(Timeline_Dart_EmbedderTimelineStartStopRecording) { | 9492 TEST_CASE(Timeline_Dart_EmbedderTimelineStartStopRecording) { |
9776 Dart_SetEmbedderTimelineCallbacks(StartRecording, StopRecording); | 9493 Dart_SetEmbedderTimelineCallbacks(StartRecording, StopRecording); |
9777 | 9494 |
9778 EXPECT(!start_called); | 9495 EXPECT(!start_called); |
9779 EXPECT(!stop_called); | 9496 EXPECT(!stop_called); |
9780 Timeline::SetStreamEmbedderEnabled(true); | 9497 Timeline::SetStreamEmbedderEnabled(true); |
9781 EXPECT(start_called); | 9498 EXPECT(start_called); |
9782 EXPECT(!stop_called); | 9499 EXPECT(!stop_called); |
9783 | 9500 |
9784 start_called = false; | 9501 start_called = false; |
9785 stop_called = false; | 9502 stop_called = false; |
9786 EXPECT(!start_called); | 9503 EXPECT(!start_called); |
9787 EXPECT(!stop_called); | 9504 EXPECT(!stop_called); |
9788 Timeline::SetStreamEmbedderEnabled(false); | 9505 Timeline::SetStreamEmbedderEnabled(false); |
9789 EXPECT(!start_called); | 9506 EXPECT(!start_called); |
9790 EXPECT(stop_called); | 9507 EXPECT(stop_called); |
9791 } | 9508 } |
9792 | 9509 |
9793 | |
9794 TEST_CASE(Dart_LoadLibraryPatch_1) { | 9510 TEST_CASE(Dart_LoadLibraryPatch_1) { |
9795 const char* kScriptChars1 = | 9511 const char* kScriptChars1 = |
9796 "class A {\n" | 9512 "class A {\n" |
9797 " int foo() { return 10; }\n" | 9513 " int foo() { return 10; }\n" |
9798 " external int zoo();\n" | 9514 " external int zoo();\n" |
9799 " external static int moo();\n" | 9515 " external static int moo();\n" |
9800 "}\n" | 9516 "}\n" |
9801 "main() { new A().foo(); }\n" | 9517 "main() { new A().foo(); }\n" |
9802 "foozoo() { new A().zoo(); }\n" | 9518 "foozoo() { new A().zoo(); }\n" |
9803 "foomoo() { A.moo(); }\n"; | 9519 "foomoo() { A.moo(); }\n"; |
(...skipping 12 matching lines...) Expand all Loading... |
9816 result = Dart_LibraryLoadPatch(lib, url, source); | 9532 result = Dart_LibraryLoadPatch(lib, url, source); |
9817 EXPECT_VALID(result); | 9533 EXPECT_VALID(result); |
9818 result = Dart_FinalizeLoading(false); | 9534 result = Dart_FinalizeLoading(false); |
9819 EXPECT_VALID(result); | 9535 EXPECT_VALID(result); |
9820 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9536 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
9821 EXPECT_VALID(result); | 9537 EXPECT_VALID(result); |
9822 result = Dart_Invoke(lib, NewString("foomoo"), 0, NULL); | 9538 result = Dart_Invoke(lib, NewString("foomoo"), 0, NULL); |
9823 EXPECT_VALID(result); | 9539 EXPECT_VALID(result); |
9824 } | 9540 } |
9825 | 9541 |
9826 | |
9827 TEST_CASE(Dart_LoadLibraryPatch_Error1) { | 9542 TEST_CASE(Dart_LoadLibraryPatch_Error1) { |
9828 const char* kScriptChars1 = | 9543 const char* kScriptChars1 = |
9829 "class A {\n" | 9544 "class A {\n" |
9830 " int foo() { return 10; }\n" | 9545 " int foo() { return 10; }\n" |
9831 " external int zoo();\n" | 9546 " external int zoo();\n" |
9832 "}\n" | 9547 "}\n" |
9833 "main() { new A().foo(); }\n" | 9548 "main() { new A().foo(); }\n" |
9834 "foozoo() { new A().zoo(); }\n"; | 9549 "foozoo() { new A().zoo(); }\n"; |
9835 | 9550 |
9836 const char* kScriptChars2 = | 9551 const char* kScriptChars2 = |
(...skipping 10 matching lines...) Expand all Loading... |
9847 // We don't expect to be able to patch in this case as new fields | 9562 // We don't expect to be able to patch in this case as new fields |
9848 // are being added. | 9563 // are being added. |
9849 result = Dart_LibraryLoadPatch(lib, url, source); | 9564 result = Dart_LibraryLoadPatch(lib, url, source); |
9850 EXPECT_VALID(result); | 9565 EXPECT_VALID(result); |
9851 result = Dart_FinalizeLoading(false); | 9566 result = Dart_FinalizeLoading(false); |
9852 EXPECT_VALID(result); | 9567 EXPECT_VALID(result); |
9853 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9568 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
9854 EXPECT(Dart_IsError(result)); | 9569 EXPECT(Dart_IsError(result)); |
9855 } | 9570 } |
9856 | 9571 |
9857 | |
9858 TEST_CASE(Dart_LoadLibraryPatch_Error2) { | 9572 TEST_CASE(Dart_LoadLibraryPatch_Error2) { |
9859 const char* kScriptChars1 = | 9573 const char* kScriptChars1 = |
9860 "class A {\n" | 9574 "class A {\n" |
9861 " int foo() { return 10; }\n" | 9575 " int foo() { return 10; }\n" |
9862 " int zoo() { return 20; }\n" | 9576 " int zoo() { return 20; }\n" |
9863 "}\n" | 9577 "}\n" |
9864 "main() { new A().foo(); }\n" | 9578 "main() { new A().foo(); }\n" |
9865 "foozoo() { new A().zoo(); }\n"; | 9579 "foozoo() { new A().zoo(); }\n"; |
9866 | 9580 |
9867 const char* kScriptChars2 = | 9581 const char* kScriptChars2 = |
(...skipping 10 matching lines...) Expand all Loading... |
9878 // method is being patched. | 9592 // method is being patched. |
9879 result = Dart_LibraryLoadPatch(lib, url, source); | 9593 result = Dart_LibraryLoadPatch(lib, url, source); |
9880 EXPECT_VALID(result); | 9594 EXPECT_VALID(result); |
9881 result = Dart_FinalizeLoading(false); | 9595 result = Dart_FinalizeLoading(false); |
9882 EXPECT_VALID(result); | 9596 EXPECT_VALID(result); |
9883 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9597 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
9884 EXPECT(Dart_IsError(result)); | 9598 EXPECT(Dart_IsError(result)); |
9885 OS::Print("Patched class executed\n"); | 9599 OS::Print("Patched class executed\n"); |
9886 } | 9600 } |
9887 | 9601 |
9888 | |
9889 TEST_CASE(Dart_LoadLibraryPatch_Error3) { | 9602 TEST_CASE(Dart_LoadLibraryPatch_Error3) { |
9890 const char* kScriptChars1 = | 9603 const char* kScriptChars1 = |
9891 "class A {\n" | 9604 "class A {\n" |
9892 " int foo() { return 10; }\n" | 9605 " int foo() { return 10; }\n" |
9893 " external int zoo();\n" | 9606 " external int zoo();\n" |
9894 "}\n" | 9607 "}\n" |
9895 "main() { new A().foo(); }\n" | 9608 "main() { new A().foo(); }\n" |
9896 "foozoo() { new A().zoo(); }\n"; | 9609 "foozoo() { new A().zoo(); }\n"; |
9897 | 9610 |
9898 const char* kScriptChars2 = | 9611 const char* kScriptChars2 = |
(...skipping 15 matching lines...) Expand all Loading... |
9914 EXPECT_VALID(result); | 9627 EXPECT_VALID(result); |
9915 result = Dart_FinalizeLoading(false); | 9628 result = Dart_FinalizeLoading(false); |
9916 EXPECT_VALID(result); | 9629 EXPECT_VALID(result); |
9917 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9630 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
9918 EXPECT(Dart_IsError(result)); | 9631 EXPECT(Dart_IsError(result)); |
9919 } | 9632 } |
9920 | 9633 |
9921 #endif // !PRODUCT | 9634 #endif // !PRODUCT |
9922 | 9635 |
9923 } // namespace dart | 9636 } // namespace dart |
OLD | NEW |