Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 8501034: Deal with unhandled exceptions the same way in all Dart api functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/exceptions_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
11 #include "vm/utils.h" 11 #include "vm/utils.h"
12 #include "vm/verifier.h" 12 #include "vm/verifier.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16
17 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
18
19 UNIT_TEST_CASE(ErrorHandles) {
20 const char* kScriptChars =
21 "class TestClass {\n"
22 " static void testMain() {\n"
23 " throw new Exception(\"bad news\");\n"
24 " }\n"
25 "}\n";
26
27 Dart_CreateIsolate(NULL, NULL);
28 Dart_EnterScope();
29 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
30
31 Dart_Handle instance = Dart_True();
32 Dart_Handle error = Api::Error("myerror");
33 Dart_Handle exception = Dart_InvokeStatic(lib,
34 Dart_NewString("TestClass"),
35 Dart_NewString("testMain"),
36 0,
37 NULL);
38
39 EXPECT(!Dart_IsError(instance));
40 EXPECT(Dart_IsError(error));
41 EXPECT(Dart_IsError(exception));
42
43 EXPECT(!Dart_ErrorHasException(instance));
44 EXPECT(!Dart_ErrorHasException(error));
45 EXPECT(Dart_ErrorHasException(exception));
46
47 EXPECT_STREQ("", Dart_GetError(instance));
48 EXPECT_STREQ("myerror", Dart_GetError(error));
49 EXPECT_STREQ(
50 "Unhandled exception:\n"
51 "Exception: bad news\n"
52 " 0. Function: 'TestClass.testMain' url: 'dart:test-lib' line:3 col:5\n",
53 Dart_GetError(exception));
54
55 EXPECT(Dart_IsError(Dart_ErrorGetException(instance)));
56 EXPECT(Dart_IsError(Dart_ErrorGetException(error)));
57 EXPECT_VALID(Dart_ErrorGetException(exception));
58
59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance)));
60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error)));
61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception));
62
63 Dart_ExitScope();
64 Dart_ShutdownIsolate();
65 }
66
67 #endif
68
69
16 UNIT_TEST_CASE(Dart_Error) { 70 UNIT_TEST_CASE(Dart_Error) {
17 Dart_CreateIsolate(NULL, NULL); 71 Dart_CreateIsolate(NULL, NULL);
18 Dart_EnterScope(); 72 Dart_EnterScope();
19 73
20 Dart_Handle error = Dart_Error("An %s", "error"); 74 Dart_Handle error = Dart_Error("An %s", "error");
21 EXPECT(!Dart_IsValid(error)); 75 EXPECT(Dart_IsError(error));
22 EXPECT_STREQ("An error", Dart_GetError(error)); 76 EXPECT_STREQ("An error", Dart_GetError(error));
23 77
24 Dart_ExitScope(); 78 Dart_ExitScope();
25 Dart_ShutdownIsolate(); 79 Dart_ShutdownIsolate();
26 } 80 }
27 81
28 82
29 UNIT_TEST_CASE(Null) { 83 UNIT_TEST_CASE(Null) {
30 Dart_CreateIsolate(NULL, NULL); 84 Dart_CreateIsolate(NULL, NULL);
31 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 85 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 170
117 UNIT_TEST_CASE(BooleanValues) { 171 UNIT_TEST_CASE(BooleanValues) {
118 Dart_CreateIsolate(NULL, NULL); 172 Dart_CreateIsolate(NULL, NULL);
119 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 173 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
120 174
121 Dart_Handle str = Dart_NewString("test"); 175 Dart_Handle str = Dart_NewString("test");
122 EXPECT(!Dart_IsBoolean(str)); 176 EXPECT(!Dart_IsBoolean(str));
123 177
124 bool value = false; 178 bool value = false;
125 Dart_Handle result = Dart_BooleanValue(str, &value); 179 Dart_Handle result = Dart_BooleanValue(str, &value);
126 EXPECT(!Dart_IsValid(result)); 180 EXPECT(Dart_IsError(result));
127 181
128 Dart_Handle val1 = Dart_NewBoolean(true); 182 Dart_Handle val1 = Dart_NewBoolean(true);
129 EXPECT(Dart_IsBoolean(val1)); 183 EXPECT(Dart_IsBoolean(val1));
130 184
131 result = Dart_BooleanValue(val1, &value); 185 result = Dart_BooleanValue(val1, &value);
132 EXPECT_VALID(result); 186 EXPECT_VALID(result);
133 EXPECT(value); 187 EXPECT(value);
134 188
135 Dart_Handle val2 = Dart_NewBoolean(false); 189 Dart_Handle val2 = Dart_NewBoolean(false);
136 EXPECT(Dart_IsBoolean(val2)); 190 EXPECT(Dart_IsBoolean(val2));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 268 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
215 269
216 Dart_Handle class_name = Dart_NewString("NumberValuesHelper"); 270 Dart_Handle class_name = Dart_NewString("NumberValuesHelper");
217 // Check int case. 271 // Check int case.
218 result = Dart_InvokeStatic(lib, 272 result = Dart_InvokeStatic(lib,
219 class_name, 273 class_name,
220 Dart_NewString("getInt"), 274 Dart_NewString("getInt"),
221 0, 275 0,
222 NULL); 276 NULL);
223 EXPECT_VALID(result); 277 EXPECT_VALID(result);
224 EXPECT(!Dart_ExceptionOccurred(result));
225 EXPECT(Dart_IsNumber(result)); 278 EXPECT(Dart_IsNumber(result));
226 279
227 // Check double case. 280 // Check double case.
228 result = Dart_InvokeStatic(lib, 281 result = Dart_InvokeStatic(lib,
229 class_name, 282 class_name,
230 Dart_NewString("getDouble"), 283 Dart_NewString("getDouble"),
231 0, 284 0,
232 NULL); 285 NULL);
233 EXPECT_VALID(result); 286 EXPECT_VALID(result);
234 EXPECT(!Dart_ExceptionOccurred(result));
235 EXPECT(Dart_IsNumber(result)); 287 EXPECT(Dart_IsNumber(result));
236 288
237 // Check bool case. 289 // Check bool case.
238 result = Dart_InvokeStatic(lib, 290 result = Dart_InvokeStatic(lib,
239 class_name, 291 class_name,
240 Dart_NewString("getBool"), 292 Dart_NewString("getBool"),
241 0, 293 0,
242 NULL); 294 NULL);
243 EXPECT_VALID(result); 295 EXPECT_VALID(result);
244 EXPECT(!Dart_ExceptionOccurred(result));
245 EXPECT(!Dart_IsNumber(result)); 296 EXPECT(!Dart_IsNumber(result));
246 297
247 // Check null case. 298 // Check null case.
248 result = Dart_InvokeStatic(lib, 299 result = Dart_InvokeStatic(lib,
249 class_name, 300 class_name,
250 Dart_NewString("getNull"), 301 Dart_NewString("getNull"),
251 0, 302 0,
252 NULL); 303 NULL);
253 EXPECT_VALID(result); 304 EXPECT_VALID(result);
254 EXPECT(!Dart_ExceptionOccurred(result));
255 EXPECT(!Dart_IsNumber(result)); 305 EXPECT(!Dart_IsNumber(result));
256 306
257 Dart_ExitScope(); // Exit the Dart API scope. 307 Dart_ExitScope(); // Exit the Dart API scope.
258 } 308 }
259 Dart_ShutdownIsolate(); 309 Dart_ShutdownIsolate();
260 } 310 }
261 311
262 #endif 312 #endif
263 313
264 314
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 EXPECT(!Dart_IsList(str)); 367 EXPECT(!Dart_IsList(str));
318 Dart_Handle val = Dart_NewList(kArrayLength); 368 Dart_Handle val = Dart_NewList(kArrayLength);
319 EXPECT(Dart_IsList(val)); 369 EXPECT(Dart_IsList(val));
320 intptr_t len = 0; 370 intptr_t len = 0;
321 Dart_Handle result = Dart_ListLength(val, &len); 371 Dart_Handle result = Dart_ListLength(val, &len);
322 EXPECT_VALID(result); 372 EXPECT_VALID(result);
323 EXPECT_EQ(kArrayLength, len); 373 EXPECT_EQ(kArrayLength, len);
324 374
325 // Check invalid array access. 375 // Check invalid array access.
326 result = Dart_ListSetAt(val, (kArrayLength + 10), Dart_NewInteger(10)); 376 result = Dart_ListSetAt(val, (kArrayLength + 10), Dart_NewInteger(10));
327 EXPECT(!Dart_IsValid(result)); 377 EXPECT(Dart_IsError(result));
328 result = Dart_ListSetAt(val, -10, Dart_NewInteger(10)); 378 result = Dart_ListSetAt(val, -10, Dart_NewInteger(10));
329 EXPECT(!Dart_IsValid(result)); 379 EXPECT(Dart_IsError(result));
330 result = Dart_ListGetAt(val, (kArrayLength + 10)); 380 result = Dart_ListGetAt(val, (kArrayLength + 10));
331 EXPECT(!Dart_IsValid(result)); 381 EXPECT(Dart_IsError(result));
332 result = Dart_ListGetAt(val, -10); 382 result = Dart_ListGetAt(val, -10);
333 EXPECT(!Dart_IsValid(result)); 383 EXPECT(Dart_IsError(result));
334 384
335 for (int i = 0; i < kArrayLength; i++) { 385 for (int i = 0; i < kArrayLength; i++) {
336 result = Dart_ListSetAt(val, i, Dart_NewInteger(i)); 386 result = Dart_ListSetAt(val, i, Dart_NewInteger(i));
337 EXPECT_VALID(result); 387 EXPECT_VALID(result);
338 } 388 }
339 for (int i = 0; i < kArrayLength; i++) { 389 for (int i = 0; i < kArrayLength; i++) {
340 result = Dart_ListGetAt(val, i); 390 result = Dart_ListGetAt(val, i);
341 EXPECT_VALID(result); 391 EXPECT_VALID(result);
342 int64_t value; 392 int64_t value;
343 result = Dart_IntegerValue(result, &value); 393 result = Dart_IntegerValue(result, &value);
(...skipping 28 matching lines...) Expand all
372 422
373 // Create a test library and Load up a test script in it. 423 // Create a test library and Load up a test script in it.
374 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 424 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
375 425
376 // Invoke a function which returns an object of type InstanceOf.. 426 // Invoke a function which returns an object of type InstanceOf..
377 result = Dart_InvokeStatic(lib, 427 result = Dart_InvokeStatic(lib,
378 Dart_NewString("ListAccessTest"), 428 Dart_NewString("ListAccessTest"),
379 Dart_NewString("testMain"), 429 Dart_NewString("testMain"),
380 0, 430 0,
381 NULL); 431 NULL);
382 EXPECT(Dart_IsValid(result)); 432 EXPECT_VALID(result);
383 EXPECT(!Dart_ExceptionOccurred(result));
384 433
385 // First ensure that the returned object is an array. 434 // First ensure that the returned object is an array.
386 Dart_Handle ListAccessTestObj = result; 435 Dart_Handle ListAccessTestObj = result;
387 436
388 EXPECT(Dart_IsList(ListAccessTestObj)); 437 EXPECT(Dart_IsList(ListAccessTestObj));
389 438
390 // Get length of array object. 439 // Get length of array object.
391 intptr_t len = 0; 440 intptr_t len = 0;
392 result = Dart_ListLength(ListAccessTestObj, &len); 441 result = Dart_ListLength(ListAccessTestObj, &len);
393 EXPECT(Dart_IsValid(result)); 442 EXPECT_VALID(result);
394 EXPECT_EQ(3, len); 443 EXPECT_EQ(3, len);
395 444
396 // Access elements in the array. 445 // Access elements in the array.
397 int64_t value; 446 int64_t value;
398 447
399 result = Dart_ListGetAt(ListAccessTestObj, 0); 448 result = Dart_ListGetAt(ListAccessTestObj, 0);
400 EXPECT(Dart_IsValid(result)); 449 EXPECT_VALID(result);
401 result = Dart_IntegerValue(result, &value); 450 result = Dart_IntegerValue(result, &value);
402 EXPECT(Dart_IsValid(result)); 451 EXPECT_VALID(result);
403 EXPECT_EQ(10, value); 452 EXPECT_EQ(10, value);
404 453
405 result = Dart_ListGetAt(ListAccessTestObj, 1); 454 result = Dart_ListGetAt(ListAccessTestObj, 1);
406 EXPECT(Dart_IsValid(result)); 455 EXPECT_VALID(result);
407 result = Dart_IntegerValue(result, &value); 456 result = Dart_IntegerValue(result, &value);
408 EXPECT(Dart_IsValid(result)); 457 EXPECT_VALID(result);
409 EXPECT_EQ(20, value); 458 EXPECT_EQ(20, value);
410 459
411 result = Dart_ListGetAt(ListAccessTestObj, 2); 460 result = Dart_ListGetAt(ListAccessTestObj, 2);
412 EXPECT(Dart_IsValid(result)); 461 EXPECT_VALID(result);
413 result = Dart_IntegerValue(result, &value); 462 result = Dart_IntegerValue(result, &value);
414 EXPECT(Dart_IsValid(result)); 463 EXPECT_VALID(result);
415 EXPECT_EQ(30, value); 464 EXPECT_EQ(30, value);
416 465
417 // Set some elements in the array. 466 // Set some elements in the array.
418 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); 467 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0));
419 EXPECT(Dart_IsValid(result)); 468 EXPECT_VALID(result);
420 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); 469 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1));
421 EXPECT(Dart_IsValid(result)); 470 EXPECT_VALID(result);
422 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); 471 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2));
423 EXPECT(Dart_IsValid(result)); 472 EXPECT_VALID(result);
424 473
425 // Get length of array object. 474 // Get length of array object.
426 result = Dart_ListLength(ListAccessTestObj, &len); 475 result = Dart_ListLength(ListAccessTestObj, &len);
427 EXPECT(Dart_IsValid(result)); 476 EXPECT_VALID(result);
428 EXPECT_EQ(3, len); 477 EXPECT_EQ(3, len);
429 478
430 // Now try and access these elements in the array. 479 // Now try and access these elements in the array.
431 result = Dart_ListGetAt(ListAccessTestObj, 0); 480 result = Dart_ListGetAt(ListAccessTestObj, 0);
432 EXPECT(Dart_IsValid(result)); 481 EXPECT_VALID(result);
433 result = Dart_IntegerValue(result, &value); 482 result = Dart_IntegerValue(result, &value);
434 EXPECT(Dart_IsValid(result)); 483 EXPECT_VALID(result);
435 EXPECT_EQ(0, value); 484 EXPECT_EQ(0, value);
436 485
437 result = Dart_ListGetAt(ListAccessTestObj, 1); 486 result = Dart_ListGetAt(ListAccessTestObj, 1);
438 EXPECT(Dart_IsValid(result)); 487 EXPECT_VALID(result);
439 result = Dart_IntegerValue(result, &value); 488 result = Dart_IntegerValue(result, &value);
440 EXPECT(Dart_IsValid(result)); 489 EXPECT_VALID(result);
441 EXPECT_EQ(1, value); 490 EXPECT_EQ(1, value);
442 491
443 result = Dart_ListGetAt(ListAccessTestObj, 2); 492 result = Dart_ListGetAt(ListAccessTestObj, 2);
444 EXPECT(Dart_IsValid(result)); 493 EXPECT_VALID(result);
445 result = Dart_IntegerValue(result, &value); 494 result = Dart_IntegerValue(result, &value);
446 EXPECT(Dart_IsValid(result)); 495 EXPECT_VALID(result);
447 EXPECT_EQ(2, value); 496 EXPECT_EQ(2, value);
448 497
449 uint8_t native_array[3]; 498 uint8_t native_array[3];
450 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 499 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
451 EXPECT(Dart_IsValid(result)); 500 EXPECT_VALID(result);
452 EXPECT_EQ(0, native_array[0]); 501 EXPECT_EQ(0, native_array[0]);
453 EXPECT_EQ(1, native_array[1]); 502 EXPECT_EQ(1, native_array[1]);
454 EXPECT_EQ(2, native_array[2]); 503 EXPECT_EQ(2, native_array[2]);
455 504
456 native_array[0] = 10; 505 native_array[0] = 10;
457 native_array[1] = 20; 506 native_array[1] = 20;
458 native_array[2] = 30; 507 native_array[2] = 30;
459 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3); 508 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3);
460 EXPECT(Dart_IsValid(result)); 509 EXPECT_VALID(result);
461 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 510 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
462 EXPECT(Dart_IsValid(result)); 511 EXPECT_VALID(result);
463 EXPECT_EQ(10, native_array[0]); 512 EXPECT_EQ(10, native_array[0]);
464 EXPECT_EQ(20, native_array[1]); 513 EXPECT_EQ(20, native_array[1]);
465 EXPECT_EQ(30, native_array[2]); 514 EXPECT_EQ(30, native_array[2]);
466 result = Dart_ListGetAt(ListAccessTestObj, 2); 515 result = Dart_ListGetAt(ListAccessTestObj, 2);
467 EXPECT(Dart_IsValid(result)); 516 EXPECT_VALID(result);
468 result = Dart_IntegerValue(result, &value); 517 result = Dart_IntegerValue(result, &value);
469 EXPECT(Dart_IsValid(result)); 518 EXPECT_VALID(result);
470 EXPECT_EQ(30, value); 519 EXPECT_EQ(30, value);
471 520
472 // Check if we get an exception when accessing beyond limit. 521 // Check if we get an exception when accessing beyond limit.
473 result = Dart_ListGetAt(ListAccessTestObj, 4); 522 result = Dart_ListGetAt(ListAccessTestObj, 4);
474 EXPECT(!Dart_IsValid(result)); 523 EXPECT(Dart_IsError(result));
475 524
476 Dart_ExitScope(); // Exit the Dart API scope. 525 Dart_ExitScope(); // Exit the Dart API scope.
477 } 526 }
478 Dart_ShutdownIsolate(); 527 Dart_ShutdownIsolate();
479 } 528 }
480 529
481 #endif // TARGET_ARCH_IA32. 530 #endif // TARGET_ARCH_IA32.
482 531
483 532
484 // Unit test for entering a scope, creating a local handle and exiting 533 // Unit test for entering a scope, creating a local handle and exiting
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 // Create a test library and Load up a test script in it. 843 // Create a test library and Load up a test script in it.
795 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 844 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
796 845
797 // Invoke a function which returns an object. 846 // Invoke a function which returns an object.
798 Dart_Handle retobj = Dart_InvokeStatic(lib, 847 Dart_Handle retobj = Dart_InvokeStatic(lib,
799 Dart_NewString("FieldsTest"), 848 Dart_NewString("FieldsTest"),
800 Dart_NewString("testMain"), 849 Dart_NewString("testMain"),
801 0, 850 0,
802 NULL); 851 NULL);
803 EXPECT_VALID(retobj); 852 EXPECT_VALID(retobj);
804 EXPECT(!Dart_ExceptionOccurred(retobj));
805 853
806 // Now access and set various static fields of Fields class. 854 // Now access and set various static fields of Fields class.
807 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); 855 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields"));
808 EXPECT_VALID(cls); 856 EXPECT_VALID(cls);
809 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); 857 result = Dart_GetStaticField(cls, Dart_NewString("fld1"));
810 EXPECT(!Dart_IsValid(result)); 858 EXPECT(Dart_IsError(result));
811 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 859 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
812 EXPECT(!Dart_IsValid(result)); 860 EXPECT(Dart_IsError(result));
813 result = Dart_GetStaticField(cls, Dart_NewString("fld4")); 861 result = Dart_GetStaticField(cls, Dart_NewString("fld4"));
814 EXPECT_VALID(result); 862 EXPECT_VALID(result);
815 int64_t value = 0; 863 int64_t value = 0;
816 result = Dart_IntegerValue(result, &value); 864 result = Dart_IntegerValue(result, &value);
817 EXPECT_EQ(10, value); 865 EXPECT_EQ(10, value);
818 result = Dart_SetStaticField(cls, 866 result = Dart_SetStaticField(cls,
819 Dart_NewString("fld4"), 867 Dart_NewString("fld4"),
820 Dart_NewInteger(20)); 868 Dart_NewInteger(20));
821 EXPECT(!Dart_IsValid(result)); 869 EXPECT(Dart_IsError(result));
822 result = Dart_GetStaticField(cls, Dart_NewString("fld3")); 870 result = Dart_GetStaticField(cls, Dart_NewString("fld3"));
823 EXPECT_VALID(result); 871 EXPECT_VALID(result);
824 result = Dart_SetStaticField(cls, 872 result = Dart_SetStaticField(cls,
825 Dart_NewString("fld3"), 873 Dart_NewString("fld3"),
826 Dart_NewInteger(200)); 874 Dart_NewInteger(200));
827 EXPECT_VALID(result); 875 EXPECT_VALID(result);
828 result = Dart_IntegerValue(result, &value); 876 result = Dart_IntegerValue(result, &value);
829 EXPECT_EQ(200, value); 877 EXPECT_EQ(200, value);
830 878
831 // Now access and set various instance fields of the returned object. 879 // Now access and set various instance fields of the returned object.
832 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 880 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
833 EXPECT(!Dart_IsValid(result)); 881 EXPECT(Dart_IsError(result));
834 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 882 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
835 EXPECT_VALID(result); 883 EXPECT_VALID(result);
836 result = Dart_IntegerValue(result, &value); 884 result = Dart_IntegerValue(result, &value);
837 EXPECT_EQ(10, value); 885 EXPECT_EQ(10, value);
838 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); 886 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
839 EXPECT_VALID(result); 887 EXPECT_VALID(result);
840 result = Dart_IntegerValue(result, &value); 888 result = Dart_IntegerValue(result, &value);
841 EXPECT_EQ(20, value); 889 EXPECT_EQ(20, value);
842 result = Dart_SetInstanceField(retobj, 890 result = Dart_SetInstanceField(retobj,
843 Dart_NewString("fld2"), 891 Dart_NewString("fld2"),
844 Dart_NewInteger(40)); 892 Dart_NewInteger(40));
845 EXPECT(!Dart_IsValid(result)); 893 EXPECT(Dart_IsError(result));
846 result = Dart_SetInstanceField(retobj, 894 result = Dart_SetInstanceField(retobj,
847 Dart_NewString("fld1"), 895 Dart_NewString("fld1"),
848 Dart_NewInteger(40)); 896 Dart_NewInteger(40));
849 EXPECT_VALID(result); 897 EXPECT_VALID(result);
850 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 898 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
851 EXPECT_VALID(result); 899 EXPECT_VALID(result);
852 result = Dart_IntegerValue(result, &value); 900 result = Dart_IntegerValue(result, &value);
853 EXPECT_EQ(40, value); 901 EXPECT_EQ(40, value);
854 902
855 Dart_ExitScope(); // Exit the Dart API scope. 903 Dart_ExitScope(); // Exit the Dart API scope.
(...skipping 26 matching lines...) Expand all
882 // Load up a test script which extends the native wrapper class. 930 // Load up a test script which extends the native wrapper class.
883 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 931 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
884 932
885 // Invoke a function which returns an object. 933 // Invoke a function which returns an object.
886 Dart_Handle retobj = Dart_InvokeStatic(lib, 934 Dart_Handle retobj = Dart_InvokeStatic(lib,
887 Dart_NewString("HiddenFieldsTest"), 935 Dart_NewString("HiddenFieldsTest"),
888 Dart_NewString("testMain"), 936 Dart_NewString("testMain"),
889 0, 937 0,
890 NULL); 938 NULL);
891 EXPECT_VALID(retobj); 939 EXPECT_VALID(retobj);
892 EXPECT(!Dart_ExceptionOccurred(retobj));
893 940
894 // Now access and set various static fields of HiddenFields class. 941 // Now access and set various static fields of HiddenFields class.
895 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields")); 942 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields"));
896 EXPECT_VALID(cls); 943 EXPECT_VALID(cls);
897 result = Dart_GetStaticField(cls, Dart_NewString("_fld1")); 944 result = Dart_GetStaticField(cls, Dart_NewString("_fld1"));
898 EXPECT(!Dart_IsValid(result)); 945 EXPECT(Dart_IsError(result));
899 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); 946 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
900 EXPECT(!Dart_IsValid(result)); 947 EXPECT(Dart_IsError(result));
901 result = Dart_GetStaticField(cls, Dart_NewString("_fld4")); 948 result = Dart_GetStaticField(cls, Dart_NewString("_fld4"));
902 EXPECT_VALID(result); 949 EXPECT_VALID(result);
903 int64_t value = 0; 950 int64_t value = 0;
904 result = Dart_IntegerValue(result, &value); 951 result = Dart_IntegerValue(result, &value);
905 EXPECT_EQ(10, value); 952 EXPECT_EQ(10, value);
906 result = Dart_SetStaticField(cls, 953 result = Dart_SetStaticField(cls,
907 Dart_NewString("_fld4"), 954 Dart_NewString("_fld4"),
908 Dart_NewInteger(20)); 955 Dart_NewInteger(20));
909 EXPECT(!Dart_IsValid(result)); 956 EXPECT(Dart_IsError(result));
910 result = Dart_GetStaticField(cls, Dart_NewString("_fld3")); 957 result = Dart_GetStaticField(cls, Dart_NewString("_fld3"));
911 EXPECT_VALID(result); 958 EXPECT_VALID(result);
912 result = Dart_SetStaticField(cls, 959 result = Dart_SetStaticField(cls,
913 Dart_NewString("_fld3"), 960 Dart_NewString("_fld3"),
914 Dart_NewInteger(200)); 961 Dart_NewInteger(200));
915 EXPECT_VALID(result); 962 EXPECT_VALID(result);
916 result = Dart_IntegerValue(result, &value); 963 result = Dart_IntegerValue(result, &value);
917 EXPECT_EQ(200, value); 964 EXPECT_EQ(200, value);
918 965
919 // Now access and set various instance fields of the returned object. 966 // Now access and set various instance fields of the returned object.
920 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); 967 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
921 EXPECT(!Dart_IsValid(result)); 968 EXPECT(Dart_IsError(result));
922 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); 969 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
923 EXPECT_VALID(result); 970 EXPECT_VALID(result);
924 result = Dart_IntegerValue(result, &value); 971 result = Dart_IntegerValue(result, &value);
925 EXPECT_EQ(10, value); 972 EXPECT_EQ(10, value);
926 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2")); 973 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2"));
927 EXPECT_VALID(result); 974 EXPECT_VALID(result);
928 result = Dart_IntegerValue(result, &value); 975 result = Dart_IntegerValue(result, &value);
929 EXPECT_EQ(20, value); 976 EXPECT_EQ(20, value);
930 result = Dart_SetInstanceField(retobj, 977 result = Dart_SetInstanceField(retobj,
931 Dart_NewString("_fld2"), 978 Dart_NewString("_fld2"),
932 Dart_NewInteger(40)); 979 Dart_NewInteger(40));
933 EXPECT(!Dart_IsValid(result)); 980 EXPECT(Dart_IsError(result));
934 result = Dart_SetInstanceField(retobj, 981 result = Dart_SetInstanceField(retobj,
935 Dart_NewString("_fld1"), 982 Dart_NewString("_fld1"),
936 Dart_NewInteger(40)); 983 Dart_NewInteger(40));
937 EXPECT_VALID(result); 984 EXPECT_VALID(result);
938 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); 985 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
939 EXPECT_VALID(result); 986 EXPECT_VALID(result);
940 result = Dart_IntegerValue(result, &value); 987 result = Dart_IntegerValue(result, &value);
941 EXPECT_EQ(40, value); 988 EXPECT_EQ(40, value);
942 989
943 Dart_ExitScope(); // Exit the Dart API scope. 990 Dart_ExitScope(); // Exit the Dart API scope.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 1028
982 // Load up a test script in the test library. 1029 // Load up a test script in the test library.
983 1030
984 // Invoke a function which returns an object of type NativeFields. 1031 // Invoke a function which returns an object of type NativeFields.
985 result = Dart_InvokeStatic(lib, 1032 result = Dart_InvokeStatic(lib,
986 Dart_NewString("NativeFieldsTest"), 1033 Dart_NewString("NativeFieldsTest"),
987 Dart_NewString("testMain"), 1034 Dart_NewString("testMain"),
988 0, 1035 0,
989 NULL); 1036 NULL);
990 EXPECT_VALID(result); 1037 EXPECT_VALID(result);
991 EXPECT(!Dart_ExceptionOccurred(result));
992 Instance& obj = Instance::Handle(); 1038 Instance& obj = Instance::Handle();
993 obj ^= Api::UnwrapHandle(result); 1039 obj ^= Api::UnwrapHandle(result);
994 const Class& cls = Class::Handle(obj.clazz()); 1040 const Class& cls = Class::Handle(obj.clazz());
995 // We expect the newly created "NativeFields" object to have 1041 // We expect the newly created "NativeFields" object to have
996 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. 1042 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields.
997 // Hence the size of an instance of "NativeFields" should be 1043 // Hence the size of an instance of "NativeFields" should be
998 // (kNumNativeFields + 2) * kWordSize + sizeof the header word. 1044 // (kNumNativeFields + 2) * kWordSize + sizeof the header word.
999 // We check to make sure the instance size computed by the VM matches 1045 // We check to make sure the instance size computed by the VM matches
1000 // our expectations. 1046 // our expectations.
1001 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + kWordSize, 1047 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + kWordSize,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 1080
1035 // Invoke a function which returns an object of type NativeFields. 1081 // Invoke a function which returns an object of type NativeFields.
1036 result = Dart_InvokeStatic(lib, 1082 result = Dart_InvokeStatic(lib,
1037 Dart_NewString("NativeFieldsTest"), 1083 Dart_NewString("NativeFieldsTest"),
1038 Dart_NewString("testMain"), 1084 Dart_NewString("testMain"),
1039 0, 1085 0,
1040 NULL); 1086 NULL);
1041 // We expect this to fail as class "NativeFields" extends 1087 // We expect this to fail as class "NativeFields" extends
1042 // "NativeFieldsWrapper" and there is no definition of it either 1088 // "NativeFieldsWrapper" and there is no definition of it either
1043 // in the dart code or through the native field injection mechanism. 1089 // in the dart code or through the native field injection mechanism.
1044 EXPECT(!Dart_IsValid(result)); 1090 EXPECT(Dart_IsError(result));
1045 1091
1046 Dart_ExitScope(); // Exit the Dart API scope. 1092 Dart_ExitScope(); // Exit the Dart API scope.
1047 } 1093 }
1048 Dart_ShutdownIsolate(); 1094 Dart_ShutdownIsolate();
1049 } 1095 }
1050 1096
1051 1097
1052 UNIT_TEST_CASE(NativeFieldAccess) { 1098 UNIT_TEST_CASE(NativeFieldAccess) {
1053 const char* kScriptChars = 1099 const char* kScriptChars =
1054 "class NativeFields extends NativeFieldsWrapper {\n" 1100 "class NativeFields extends NativeFieldsWrapper {\n"
(...skipping 27 matching lines...) Expand all
1082 1128
1083 // Load up a test script in it. 1129 // Load up a test script in it.
1084 1130
1085 // Invoke a function which returns an object of type NativeFields. 1131 // Invoke a function which returns an object of type NativeFields.
1086 Dart_Handle retobj = Dart_InvokeStatic(lib, 1132 Dart_Handle retobj = Dart_InvokeStatic(lib,
1087 Dart_NewString("NativeFieldsTest"), 1133 Dart_NewString("NativeFieldsTest"),
1088 Dart_NewString("testMain"), 1134 Dart_NewString("testMain"),
1089 0, 1135 0,
1090 NULL); 1136 NULL);
1091 EXPECT_VALID(retobj); 1137 EXPECT_VALID(retobj);
1092 EXPECT(!Dart_ExceptionOccurred(retobj));
1093 1138
1094 // Now access and set various instance fields of the returned object. 1139 // Now access and set various instance fields of the returned object.
1095 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 1140 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
1096 EXPECT(!Dart_IsValid(result)); 1141 EXPECT(Dart_IsError(result));
1097 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 1142 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1098 EXPECT_VALID(result); 1143 EXPECT_VALID(result);
1099 int64_t value = 0; 1144 int64_t value = 0;
1100 result = Dart_IntegerValue(result, &value); 1145 result = Dart_IntegerValue(result, &value);
1101 EXPECT_EQ(10, value); 1146 EXPECT_EQ(10, value);
1102 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); 1147 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
1103 EXPECT_VALID(result); 1148 EXPECT_VALID(result);
1104 result = Dart_IntegerValue(result, &value); 1149 result = Dart_IntegerValue(result, &value);
1105 EXPECT_EQ(20, value); 1150 EXPECT_EQ(20, value);
1106 result = Dart_SetInstanceField(retobj, 1151 result = Dart_SetInstanceField(retobj,
1107 Dart_NewString("fld2"), 1152 Dart_NewString("fld2"),
1108 Dart_NewInteger(40)); 1153 Dart_NewInteger(40));
1109 EXPECT(!Dart_IsValid(result)); 1154 EXPECT(Dart_IsError(result));
1110 result = Dart_SetInstanceField(retobj, 1155 result = Dart_SetInstanceField(retobj,
1111 Dart_NewString("fld1"), 1156 Dart_NewString("fld1"),
1112 Dart_NewInteger(40)); 1157 Dart_NewInteger(40));
1113 EXPECT_VALID(result); 1158 EXPECT_VALID(result);
1114 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 1159 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1115 EXPECT_VALID(result); 1160 EXPECT_VALID(result);
1116 result = Dart_IntegerValue(result, &value); 1161 result = Dart_IntegerValue(result, &value);
1117 EXPECT_EQ(40, value); 1162 EXPECT_EQ(40, value);
1118 1163
1119 // Now access and set various native instance fields of the returned object. 1164 // Now access and set various native instance fields of the returned object.
1120 const int kNativeFld0 = 0; 1165 const int kNativeFld0 = 0;
1121 const int kNativeFld1 = 1; 1166 const int kNativeFld1 = 1;
1122 const int kNativeFld2 = 2; 1167 const int kNativeFld2 = 2;
1123 const int kNativeFld3 = 3; 1168 const int kNativeFld3 = 3;
1124 const int kNativeFld4 = 4; 1169 const int kNativeFld4 = 4;
1125 intptr_t field_value = 0; 1170 intptr_t field_value = 0;
1126 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value); 1171 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value);
1127 EXPECT(!Dart_IsValid(result)); 1172 EXPECT(Dart_IsError(result));
1128 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &field_value); 1173 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &field_value);
1129 EXPECT_VALID(result); 1174 EXPECT_VALID(result);
1130 EXPECT_EQ(0, field_value); 1175 EXPECT_EQ(0, field_value);
1131 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &field_value); 1176 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &field_value);
1132 EXPECT_VALID(result); 1177 EXPECT_VALID(result);
1133 EXPECT_EQ(0, field_value); 1178 EXPECT_EQ(0, field_value);
1134 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &field_value); 1179 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &field_value);
1135 EXPECT_VALID(result); 1180 EXPECT_VALID(result);
1136 EXPECT_EQ(0, field_value); 1181 EXPECT_EQ(0, field_value);
1137 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); 1182 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40);
1138 EXPECT(!Dart_IsValid(result)); 1183 EXPECT(Dart_IsError(result));
1139 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 4); 1184 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 4);
1140 EXPECT_VALID(result); 1185 EXPECT_VALID(result);
1141 result = Dart_SetNativeInstanceField(retobj, kNativeFld1, 40); 1186 result = Dart_SetNativeInstanceField(retobj, kNativeFld1, 40);
1142 EXPECT_VALID(result); 1187 EXPECT_VALID(result);
1143 result = Dart_SetNativeInstanceField(retobj, kNativeFld2, 400); 1188 result = Dart_SetNativeInstanceField(retobj, kNativeFld2, 400);
1144 EXPECT_VALID(result); 1189 EXPECT_VALID(result);
1145 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000); 1190 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000);
1146 EXPECT_VALID(result); 1191 EXPECT_VALID(result);
1147 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value); 1192 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value);
1148 EXPECT_VALID(result); 1193 EXPECT_VALID(result);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 // Create a test library and Load up a test script in it. 1239 // Create a test library and Load up a test script in it.
1195 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1240 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1196 1241
1197 // Invoke a function which returns an object of type NativeFields. 1242 // Invoke a function which returns an object of type NativeFields.
1198 Dart_Handle retobj = Dart_InvokeStatic(lib, 1243 Dart_Handle retobj = Dart_InvokeStatic(lib,
1199 Dart_NewString("NativeFieldsTest"), 1244 Dart_NewString("NativeFieldsTest"),
1200 Dart_NewString("testMain1"), 1245 Dart_NewString("testMain1"),
1201 0, 1246 0,
1202 NULL); 1247 NULL);
1203 EXPECT_VALID(retobj); 1248 EXPECT_VALID(retobj);
1204 EXPECT(!Dart_ExceptionOccurred(retobj));
1205 1249
1206 // Now access and set various native instance fields of the returned object. 1250 // Now access and set various native instance fields of the returned object.
1207 // All of these tests are expected to return failure as there are no 1251 // All of these tests are expected to return failure as there are no
1208 // native fields in an instance of NativeFields. 1252 // native fields in an instance of NativeFields.
1209 const int kNativeFld0 = 0; 1253 const int kNativeFld0 = 0;
1210 const int kNativeFld1 = 1; 1254 const int kNativeFld1 = 1;
1211 const int kNativeFld2 = 2; 1255 const int kNativeFld2 = 2;
1212 const int kNativeFld3 = 3; 1256 const int kNativeFld3 = 3;
1213 const int kNativeFld4 = 4; 1257 const int kNativeFld4 = 4;
1214 intptr_t value = 0; 1258 intptr_t value = 0;
1215 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); 1259 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value);
1216 EXPECT(!Dart_IsValid(result)); 1260 EXPECT(Dart_IsError(result));
1217 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); 1261 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value);
1218 EXPECT(!Dart_IsValid(result)); 1262 EXPECT(Dart_IsError(result));
1219 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); 1263 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value);
1220 EXPECT(!Dart_IsValid(result)); 1264 EXPECT(Dart_IsError(result));
1221 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); 1265 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value);
1222 EXPECT(!Dart_IsValid(result)); 1266 EXPECT(Dart_IsError(result));
1223 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); 1267 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40);
1224 EXPECT(!Dart_IsValid(result)); 1268 EXPECT(Dart_IsError(result));
1225 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); 1269 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40);
1226 EXPECT(!Dart_IsValid(result)); 1270 EXPECT(Dart_IsError(result));
1227 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); 1271 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
1228 EXPECT(!Dart_IsValid(result)); 1272 EXPECT(Dart_IsError(result));
1229 1273
1230 // Invoke a function which returns a closure object. 1274 // Invoke a function which returns a closure object.
1231 retobj = Dart_InvokeStatic(lib, 1275 retobj = Dart_InvokeStatic(lib,
1232 Dart_NewString("NativeFieldsTest"), 1276 Dart_NewString("NativeFieldsTest"),
1233 Dart_NewString("testMain2"), 1277 Dart_NewString("testMain2"),
1234 0, 1278 0,
1235 NULL); 1279 NULL);
1236 EXPECT_VALID(retobj); 1280 EXPECT_VALID(retobj);
1237 EXPECT(!Dart_ExceptionOccurred(retobj));
1238 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); 1281 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value);
1239 EXPECT(!Dart_IsValid(result)); 1282 EXPECT(Dart_IsError(result));
1240 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); 1283 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value);
1241 EXPECT(!Dart_IsValid(result)); 1284 EXPECT(Dart_IsError(result));
1242 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); 1285 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value);
1243 EXPECT(!Dart_IsValid(result)); 1286 EXPECT(Dart_IsError(result));
1244 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); 1287 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value);
1245 EXPECT(!Dart_IsValid(result)); 1288 EXPECT(Dart_IsError(result));
1246 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); 1289 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40);
1247 EXPECT(!Dart_IsValid(result)); 1290 EXPECT(Dart_IsError(result));
1248 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); 1291 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40);
1249 EXPECT(!Dart_IsValid(result)); 1292 EXPECT(Dart_IsError(result));
1250 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); 1293 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
1251 EXPECT(!Dart_IsValid(result)); 1294 EXPECT(Dart_IsError(result));
1252 1295
1253 Dart_ExitScope(); // Exit the Dart API scope. 1296 Dart_ExitScope(); // Exit the Dart API scope.
1254 } 1297 }
1255 Dart_ShutdownIsolate(); 1298 Dart_ShutdownIsolate();
1256 } 1299 }
1257 1300
1258 1301
1259 UNIT_TEST_CASE(GetStaticField_RunsInitializer) { 1302 UNIT_TEST_CASE(GetStaticField_RunsInitializer) {
1260 const char* kScriptChars = 1303 const char* kScriptChars =
1261 "class TestClass {\n" 1304 "class TestClass {\n"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 result = Dart_InvokeStatic(lib, 1375 result = Dart_InvokeStatic(lib,
1333 Dart_NewString("TestClass"), 1376 Dart_NewString("TestClass"),
1334 Dart_NewString("testMain"), 1377 Dart_NewString("testMain"),
1335 0, 1378 0,
1336 NULL); 1379 NULL);
1337 1380
1338 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); 1381 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass"));
1339 EXPECT_VALID(cls); 1382 EXPECT_VALID(cls);
1340 1383
1341 result = Dart_GetStaticField(cls, Dart_NewString("not_found")); 1384 result = Dart_GetStaticField(cls, Dart_NewString("not_found"));
1342 EXPECT(!Dart_IsValid(result)); 1385 EXPECT(Dart_IsError(result));
1343 EXPECT_STREQ("Specified field is not found in the class", 1386 EXPECT_STREQ("Specified field is not found in the class",
1344 Dart_GetError(result)); 1387 Dart_GetError(result));
1345 1388
1346 result = Dart_SetStaticField(cls, 1389 result = Dart_SetStaticField(cls,
1347 Dart_NewString("not_found"), 1390 Dart_NewString("not_found"),
1348 Dart_NewInteger(13)); 1391 Dart_NewInteger(13));
1349 EXPECT(!Dart_IsValid(result)); 1392 EXPECT(Dart_IsError(result));
1350 EXPECT_STREQ("Specified field is not found in the class", 1393 EXPECT_STREQ("Specified field is not found in the class",
1351 Dart_GetError(result)); 1394 Dart_GetError(result));
1352 1395
1353 Dart_ExitScope(); // Exit the Dart API scope. 1396 Dart_ExitScope(); // Exit the Dart API scope.
1354 } 1397 }
1355 Dart_ShutdownIsolate(); 1398 Dart_ShutdownIsolate();
1356 } 1399 }
1357 1400
1358 1401
1359 UNIT_TEST_CASE(InvokeDynamic) { 1402 UNIT_TEST_CASE(InvokeDynamic) {
(...skipping 23 matching lines...) Expand all
1383 // Create a test library and Load up a test script in it. 1426 // Create a test library and Load up a test script in it.
1384 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1427 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1385 1428
1386 // Invoke a function which returns an object of type InvokeDynamic. 1429 // Invoke a function which returns an object of type InvokeDynamic.
1387 Dart_Handle retobj = Dart_InvokeStatic(lib, 1430 Dart_Handle retobj = Dart_InvokeStatic(lib,
1388 Dart_NewString("InvokeDynamicTest"), 1431 Dart_NewString("InvokeDynamicTest"),
1389 Dart_NewString("testMain"), 1432 Dart_NewString("testMain"),
1390 0, 1433 0,
1391 NULL); 1434 NULL);
1392 EXPECT_VALID(retobj); 1435 EXPECT_VALID(retobj);
1393 EXPECT(!Dart_ExceptionOccurred(retobj));
1394 1436
1395 1437
1396 // Now invoke a dynamic method and check the result. 1438 // Now invoke a dynamic method and check the result.
1397 Dart_Handle dart_arguments[1]; 1439 Dart_Handle dart_arguments[1];
1398 dart_arguments[0] = Dart_NewInteger(1); 1440 dart_arguments[0] = Dart_NewInteger(1);
1399 result = Dart_InvokeDynamic(retobj, 1441 result = Dart_InvokeDynamic(retobj,
1400 Dart_NewString("method1"), 1442 Dart_NewString("method1"),
1401 1, 1443 1,
1402 dart_arguments); 1444 dart_arguments);
1403 EXPECT_VALID(result); 1445 EXPECT_VALID(result);
1404 EXPECT(!Dart_ExceptionOccurred(result));
1405 EXPECT(Dart_IsInteger(result)); 1446 EXPECT(Dart_IsInteger(result));
1406 int64_t value = 0; 1447 int64_t value = 0;
1407 result = Dart_IntegerValue(result, &value); 1448 result = Dart_IntegerValue(result, &value);
1408 EXPECT_EQ(41, value); 1449 EXPECT_EQ(41, value);
1409 1450
1410 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); 1451 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL);
1411 EXPECT(!Dart_IsValid(result)); 1452 EXPECT(Dart_IsError(result));
1412 1453
1413 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL); 1454 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL);
1414 EXPECT(!Dart_IsValid(result)); 1455 EXPECT(Dart_IsError(result));
1415 1456
1416 Dart_ExitScope(); // Exit the Dart API scope. 1457 Dart_ExitScope(); // Exit the Dart API scope.
1417 } 1458 }
1418 Dart_ShutdownIsolate(); 1459 Dart_ShutdownIsolate();
1419 } 1460 }
1420 1461
1421 1462
1422 UNIT_TEST_CASE(InvokeClosure) { 1463 UNIT_TEST_CASE(InvokeClosure) {
1423 const char* kScriptChars = 1464 const char* kScriptChars =
1424 "class InvokeClosure {\n" 1465 "class InvokeClosure {\n"
(...skipping 30 matching lines...) Expand all
1455 // Create a test library and Load up a test script in it. 1496 // Create a test library and Load up a test script in it.
1456 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1497 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1457 1498
1458 // Invoke a function which returns a closure. 1499 // Invoke a function which returns a closure.
1459 Dart_Handle retobj = Dart_InvokeStatic(lib, 1500 Dart_Handle retobj = Dart_InvokeStatic(lib,
1460 Dart_NewString("InvokeClosureTest"), 1501 Dart_NewString("InvokeClosureTest"),
1461 Dart_NewString("testMain1"), 1502 Dart_NewString("testMain1"),
1462 0, 1503 0,
1463 NULL); 1504 NULL);
1464 EXPECT_VALID(retobj); 1505 EXPECT_VALID(retobj);
1465 EXPECT(!Dart_ExceptionOccurred(retobj));
1466 1506
1467 EXPECT(Dart_IsClosure(retobj)); 1507 EXPECT(Dart_IsClosure(retobj));
1468 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); 1508 EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
1469 1509
1470 // Now invoke the closure and check the result. 1510 // Now invoke the closure and check the result.
1471 Dart_Handle dart_arguments[1]; 1511 Dart_Handle dart_arguments[1];
1472 dart_arguments[0] = Dart_NewInteger(1); 1512 dart_arguments[0] = Dart_NewInteger(1);
1473 result = Dart_InvokeClosure(retobj, 1, dart_arguments); 1513 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
1474 EXPECT_VALID(result); 1514 EXPECT_VALID(result);
1475 EXPECT(!Dart_ExceptionOccurred(result));
1476 EXPECT(Dart_IsInteger(result)); 1515 EXPECT(Dart_IsInteger(result));
1477 int64_t value = 0; 1516 int64_t value = 0;
1478 result = Dart_IntegerValue(result, &value); 1517 result = Dart_IntegerValue(result, &value);
1479 EXPECT_EQ(51, value); 1518 EXPECT_EQ(51, value);
1480 1519
1481 // Invoke closure with wrong number of args, should result in exception. 1520 // Invoke closure with wrong number of args, should result in exception.
1482 result = Dart_InvokeClosure(retobj, 0, NULL); 1521 result = Dart_InvokeClosure(retobj, 0, NULL);
1483 EXPECT_VALID(result); 1522 EXPECT(Dart_IsError(result));
1484 EXPECT(Dart_ExceptionOccurred(result)); 1523 EXPECT(Dart_ErrorHasException(result));
1485 1524
1486 // Invoke a function which returns a closure. 1525 // Invoke a function which returns a closure.
1487 retobj = Dart_InvokeStatic(lib, 1526 retobj = Dart_InvokeStatic(lib,
1488 Dart_NewString("InvokeClosureTest"), 1527 Dart_NewString("InvokeClosureTest"),
1489 Dart_NewString("testMain2"), 1528 Dart_NewString("testMain2"),
1490 0, 1529 0,
1491 NULL); 1530 NULL);
1492 EXPECT_VALID(retobj); 1531 EXPECT_VALID(retobj);
1493 EXPECT(!Dart_ExceptionOccurred(retobj));
1494 1532
1495 EXPECT(Dart_IsClosure(retobj)); 1533 EXPECT(Dart_IsClosure(retobj));
1496 EXPECT(!Dart_IsClosure(Dart_NewString("abcdef"))); 1534 EXPECT(!Dart_IsClosure(Dart_NewString("abcdef")));
1497 1535
1498 // Now invoke the closure and check the result (should be an exception). 1536 // Now invoke the closure and check the result (should be an exception).
1499 dart_arguments[0] = Dart_NewInteger(1); 1537 dart_arguments[0] = Dart_NewInteger(1);
1500 result = Dart_InvokeClosure(retobj, 1, dart_arguments); 1538 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
1501 EXPECT(Dart_ExceptionOccurred(result)); 1539 EXPECT(Dart_IsError(result));
1540 EXPECT(Dart_ErrorHasException(result));
1502 1541
1503 Dart_ExitScope(); // Exit the Dart API scope. 1542 Dart_ExitScope(); // Exit the Dart API scope.
1504 } 1543 }
1505 Dart_ShutdownIsolate(); 1544 Dart_ShutdownIsolate();
1506 } 1545 }
1507 1546
1508 1547
1509 void ExceptionNative(Dart_NativeArguments args) { 1548 void ExceptionNative(Dart_NativeArguments args) {
1510 Dart_Handle param = Dart_GetNativeArgument(args, 0); 1549 Dart_Handle param = Dart_GetNativeArgument(args, 0);
1511 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1550 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 kScriptChars, 1592 kScriptChars,
1554 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); 1593 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
1555 1594
1556 // Invoke a function which returns an object of type ThrowException. 1595 // Invoke a function which returns an object of type ThrowException.
1557 Dart_Handle retobj = Dart_InvokeStatic(lib, 1596 Dart_Handle retobj = Dart_InvokeStatic(lib,
1558 Dart_NewString("ThrowExceptionTest"), 1597 Dart_NewString("ThrowExceptionTest"),
1559 Dart_NewString("testMain"), 1598 Dart_NewString("testMain"),
1560 0, 1599 0,
1561 NULL); 1600 NULL);
1562 EXPECT_VALID(retobj); 1601 EXPECT_VALID(retobj);
1563 EXPECT(!Dart_ExceptionOccurred(retobj));
1564 1602
1565 // Throwing an exception here should result in an error. 1603 // Throwing an exception here should result in an error.
1566 result = Dart_ThrowException(retobj); 1604 result = Dart_ThrowException(retobj);
1567 EXPECT(!Dart_IsValid(result)); 1605 EXPECT(Dart_IsError(result));
1568 1606
1569 // Now invoke method2 which invokes a natve method where it is 1607 // Now invoke method2 which invokes a natve method where it is
1570 // ok to throw an exception, check the result which would indicate 1608 // ok to throw an exception, check the result which would indicate
1571 // if an exception was thrown or not. 1609 // if an exception was thrown or not.
1572 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); 1610 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL);
1573 EXPECT_VALID(result); 1611 EXPECT_VALID(result);
1574 EXPECT(!Dart_ExceptionOccurred(result));
1575 EXPECT(Dart_IsInteger(result)); 1612 EXPECT(Dart_IsInteger(result));
1576 int64_t value = 0; 1613 int64_t value = 0;
1577 result = Dart_IntegerValue(result, &value); 1614 result = Dart_IntegerValue(result, &value);
1578 EXPECT_EQ(5, value); 1615 EXPECT_EQ(5, value);
1579 1616
1580 Dart_ExitScope(); // Exit the Dart API scope. 1617 Dart_ExitScope(); // Exit the Dart API scope.
1581 EXPECT_EQ(size, state->ZoneSizeInBytes()); 1618 EXPECT_EQ(size, state->ZoneSizeInBytes());
1582 } 1619 }
1583 Dart_ShutdownIsolate(); 1620 Dart_ShutdownIsolate();
1584 } 1621 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 Dart_CreateIsolate(NULL, NULL); 1680 Dart_CreateIsolate(NULL, NULL);
1644 Dart_EnterScope(); 1681 Dart_EnterScope();
1645 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1682 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1646 1683
1647 // Lookup a class that does exist. 1684 // Lookup a class that does exist.
1648 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist")); 1685 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist"));
1649 EXPECT_VALID(cls); 1686 EXPECT_VALID(cls);
1650 1687
1651 // Lookup a class that does not exist. 1688 // Lookup a class that does not exist.
1652 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist")); 1689 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist"));
1653 EXPECT(!Dart_IsValid(cls)); 1690 EXPECT(Dart_IsError(cls));
1654 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.", 1691 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.",
1655 Dart_GetError(cls)); 1692 Dart_GetError(cls));
1656 1693
1657 Dart_ExitScope(); 1694 Dart_ExitScope();
1658 Dart_ShutdownIsolate(); 1695 Dart_ShutdownIsolate();
1659 } 1696 }
1660 1697
1661 1698
1662 UNIT_TEST_CASE(InstanceOf) { 1699 UNIT_TEST_CASE(InstanceOf) {
1663 const char* kScriptChars = 1700 const char* kScriptChars =
(...skipping 16 matching lines...) Expand all
1680 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1717 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1681 1718
1682 // Invoke a function which returns an object of type InstanceOf.. 1719 // Invoke a function which returns an object of type InstanceOf..
1683 Dart_Handle instanceOfTestObj = 1720 Dart_Handle instanceOfTestObj =
1684 Dart_InvokeStatic(lib, 1721 Dart_InvokeStatic(lib,
1685 Dart_NewString("InstanceOfTest"), 1722 Dart_NewString("InstanceOfTest"),
1686 Dart_NewString("testMain"), 1723 Dart_NewString("testMain"),
1687 0, 1724 0,
1688 NULL); 1725 NULL);
1689 EXPECT_VALID(instanceOfTestObj); 1726 EXPECT_VALID(instanceOfTestObj);
1690 EXPECT(!Dart_ExceptionOccurred(instanceOfTestObj));
1691 1727
1692 // Fetch InstanceOfTest class. 1728 // Fetch InstanceOfTest class.
1693 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest")); 1729 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest"));
1694 EXPECT_VALID(cls); 1730 EXPECT_VALID(cls);
1695 EXPECT(!Dart_ExceptionOccurred(cls));
1696 1731
1697 // Now check instanceOfTestObj reported as an instance of 1732 // Now check instanceOfTestObj reported as an instance of
1698 // InstanceOfTest class. 1733 // InstanceOfTest class.
1699 bool is_instance = false; 1734 bool is_instance = false;
1700 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance); 1735 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance);
1701 EXPECT_VALID(result); 1736 EXPECT_VALID(result);
1702 EXPECT(is_instance); 1737 EXPECT(is_instance);
1703 1738
1704 // Fetch OtherClass and check if instanceOfTestObj is instance of it. 1739 // Fetch OtherClass and check if instanceOfTestObj is instance of it.
1705 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass")); 1740 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass"));
1706 EXPECT_VALID(otherClass); 1741 EXPECT_VALID(otherClass);
1707 EXPECT(!Dart_ExceptionOccurred(otherClass));
1708 1742
1709 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); 1743 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance);
1710 EXPECT_VALID(result); 1744 EXPECT_VALID(result);
1711 EXPECT(!is_instance); 1745 EXPECT(!is_instance);
1712 1746
1713 // Check that primitives are not instances of InstanceOfTest class. 1747 // Check that primitives are not instances of InstanceOfTest class.
1714 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass, 1748 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass,
1715 &is_instance); 1749 &is_instance);
1716 EXPECT_VALID(result); 1750 EXPECT_VALID(result);
1717 EXPECT(!is_instance); 1751 EXPECT(!is_instance);
1718 1752
1719 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance); 1753 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance);
1720 EXPECT_VALID(result); 1754 EXPECT_VALID(result);
1721 EXPECT(!is_instance); 1755 EXPECT(!is_instance);
1722 1756
1723 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance); 1757 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance);
1724 EXPECT_VALID(result); 1758 EXPECT_VALID(result);
1725 EXPECT(!is_instance); 1759 EXPECT(!is_instance);
1726 1760
1727 // Check that null is not an instance of InstanceOfTest class. 1761 // Check that null is not an instance of InstanceOfTest class.
1728 Dart_Handle null = Dart_InvokeStatic(lib, 1762 Dart_Handle null = Dart_InvokeStatic(lib,
1729 Dart_NewString("OtherClass"), 1763 Dart_NewString("OtherClass"),
1730 Dart_NewString("returnNull"), 1764 Dart_NewString("returnNull"),
1731 0, 1765 0,
1732 NULL); 1766 NULL);
1733 EXPECT_VALID(null); 1767 EXPECT_VALID(null);
1734 EXPECT(!Dart_ExceptionOccurred(null));
1735 1768
1736 result = Dart_ObjectIsType(null, otherClass, &is_instance); 1769 result = Dart_ObjectIsType(null, otherClass, &is_instance);
1737 EXPECT_VALID(result); 1770 EXPECT_VALID(result);
1738 EXPECT(!is_instance); 1771 EXPECT(!is_instance);
1739 1772
1740 // Check that error is returned if null is passed as a class argument. 1773 // Check that error is returned if null is passed as a class argument.
1741 result = Dart_ObjectIsType(null, null, &is_instance); 1774 result = Dart_ObjectIsType(null, null, &is_instance);
1742 EXPECT(!Dart_IsValid(result)); 1775 EXPECT(Dart_IsError(result));
1743 1776
1744 Dart_ExitScope(); // Exit the Dart API scope. 1777 Dart_ExitScope(); // Exit the Dart API scope.
1745 } 1778 }
1746 Dart_ShutdownIsolate(); 1779 Dart_ShutdownIsolate();
1747 } 1780 }
1748 1781
1749 1782
1750 UNIT_TEST_CASE(NullReceiver) { 1783 UNIT_TEST_CASE(NullReceiver) {
1751 Dart_CreateIsolate(NULL, NULL); 1784 Dart_CreateIsolate(NULL, NULL);
1752 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 1785 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
(...skipping 11 matching lines...) Expand all
1764 EXPECT_VALID(result); 1797 EXPECT_VALID(result);
1765 EXPECT(Dart_IsString(result)); 1798 EXPECT(Dart_IsString(result));
1766 1799
1767 // Should throw a NullPointerException. Disabled due to bug 5415268. 1800 // Should throw a NullPointerException. Disabled due to bug 5415268.
1768 /* 1801 /*
1769 Dart_Handle function_name2 = Dart_NewString("NoNoNo"); 1802 Dart_Handle function_name2 = Dart_NewString("NoNoNo");
1770 result = Dart_InvokeDynamic(null_receiver, 1803 result = Dart_InvokeDynamic(null_receiver,
1771 function_name2, 1804 function_name2,
1772 number_of_arguments, 1805 number_of_arguments,
1773 dart_arguments); 1806 dart_arguments);
1774 EXPECT_VALID(result); 1807 EXPECT(Dart_IsError(result));
1775 EXPECT(Dart_ExceptionOccurred(result)); */ 1808 EXPECT(Dart_ErrorHasException(result)); */
1776 } 1809 }
1777 Dart_ExitScope(); // Exit the Dart API scope. 1810 Dart_ExitScope(); // Exit the Dart API scope.
1778 Dart_ShutdownIsolate(); 1811 Dart_ShutdownIsolate();
1779 } 1812 }
1780 1813
1781 1814
1782 static Dart_Handle library_handler(Dart_LibraryTag tag, 1815 static Dart_Handle library_handler(Dart_LibraryTag tag,
1783 Dart_Handle library, 1816 Dart_Handle library,
1784 Dart_Handle url) { 1817 Dart_Handle url) {
1785 if (tag == kCanonicalizeUrl) { 1818 if (tag == kCanonicalizeUrl) {
(...skipping 22 matching lines...) Expand all
1808 1841
1809 url = Dart_NewString("library1.dart"); 1842 url = Dart_NewString("library1.dart");
1810 source = Dart_NewString(kLibrary1Chars); 1843 source = Dart_NewString(kLibrary1Chars);
1811 result = Dart_LoadLibrary(url, source); 1844 result = Dart_LoadLibrary(url, source);
1812 EXPECT_VALID(result); 1845 EXPECT_VALID(result);
1813 1846
1814 result = Dart_LookupLibrary(url); 1847 result = Dart_LookupLibrary(url);
1815 EXPECT_VALID(result); 1848 EXPECT_VALID(result);
1816 1849
1817 result = Dart_LookupLibrary(Dart_Null()); 1850 result = Dart_LookupLibrary(Dart_Null());
1818 EXPECT(!Dart_IsValid(result)); 1851 EXPECT(Dart_IsError(result));
1819 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", 1852 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.",
1820 Dart_GetError(result)); 1853 Dart_GetError(result));
1821 1854
1822 result = Dart_LookupLibrary(Dart_True()); 1855 result = Dart_LookupLibrary(Dart_True());
1823 EXPECT(!Dart_IsValid(result)); 1856 EXPECT(Dart_IsError(result));
1824 EXPECT_STREQ( 1857 EXPECT_STREQ(
1825 "Dart_LookupLibrary expects argument 'url' to be of type String.", 1858 "Dart_LookupLibrary expects argument 'url' to be of type String.",
1826 Dart_GetError(result)); 1859 Dart_GetError(result));
1827 1860
1828 result = Dart_LookupLibrary(Dart_Error("incoming error pass-thru")); 1861 result = Dart_LookupLibrary(Dart_Error("incoming error pass-thru"));
1829 EXPECT(!Dart_IsValid(result)); 1862 EXPECT(Dart_IsError(result));
1830 EXPECT_STREQ("incoming error pass-thru", Dart_GetError(result)); 1863 EXPECT_STREQ("incoming error pass-thru", Dart_GetError(result));
1831 1864
1832 url = Dart_NewString("noodles.dart"); 1865 url = Dart_NewString("noodles.dart");
1833 result = Dart_LookupLibrary(url); 1866 result = Dart_LookupLibrary(url);
1834 EXPECT(!Dart_IsValid(result)); 1867 EXPECT(Dart_IsError(result));
1835 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", 1868 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.",
1836 Dart_GetError(result)); 1869 Dart_GetError(result));
1837 1870
1838 Dart_ExitScope(); 1871 Dart_ExitScope();
1839 Dart_ShutdownIsolate(); 1872 Dart_ShutdownIsolate();
1840 } 1873 }
1841 1874
1842 1875
1843 UNIT_TEST_CASE(ImportLibrary1) { 1876 UNIT_TEST_CASE(ImportLibrary1) {
1844 const char* kScriptChars = 1877 const char* kScriptChars =
(...skipping 25 matching lines...) Expand all
1870 1903
1871 url = Dart_NewString("library2.dart"); 1904 url = Dart_NewString("library2.dart");
1872 source = Dart_NewString(kLibrary2Chars); 1905 source = Dart_NewString(kLibrary2Chars);
1873 Dart_LoadLibrary(url, source); 1906 Dart_LoadLibrary(url, source);
1874 1907
1875 result = Dart_InvokeStatic(result, 1908 result = Dart_InvokeStatic(result,
1876 Dart_NewString(""), 1909 Dart_NewString(""),
1877 Dart_NewString("main"), 1910 Dart_NewString("main"),
1878 0, 1911 0,
1879 NULL); 1912 NULL);
1880 EXPECT(!Dart_IsValid(result)); 1913 EXPECT(Dart_IsError(result));
1881 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 1914 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
1882 " 'library2.dart' and 'dart:test-lib'\n", 1915 " 'library2.dart' and 'dart:test-lib'\n",
1883 Dart_GetError(result)); 1916 Dart_GetError(result));
1884 1917
1885 Dart_ExitScope(); // Exit the Dart API scope. 1918 Dart_ExitScope(); // Exit the Dart API scope.
1886 } 1919 }
1887 Dart_ShutdownIsolate(); 1920 Dart_ShutdownIsolate();
1888 } 1921 }
1889 1922
1890 1923
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 1995
1963 url = Dart_NewString("library1.dart"); 1996 url = Dart_NewString("library1.dart");
1964 source = Dart_NewString(kLibrary1Chars); 1997 source = Dart_NewString(kLibrary1Chars);
1965 Dart_LoadLibrary(url, source); 1998 Dart_LoadLibrary(url, source);
1966 1999
1967 result = Dart_InvokeStatic(result, 2000 result = Dart_InvokeStatic(result,
1968 Dart_NewString(""), 2001 Dart_NewString(""),
1969 Dart_NewString("main"), 2002 Dart_NewString("main"),
1970 0, 2003 0,
1971 NULL); 2004 NULL);
1972 EXPECT(!Dart_IsValid(result)); 2005 EXPECT(Dart_IsError(result));
1973 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 2006 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
1974 " 'library1.dart' and 'library2.dart'\n", 2007 " 'library1.dart' and 'library2.dart'\n",
1975 Dart_GetError(result)); 2008 Dart_GetError(result));
1976 2009
1977 Dart_ExitScope(); // Exit the Dart API scope. 2010 Dart_ExitScope(); // Exit the Dart API scope.
1978 } 2011 }
1979 Dart_ShutdownIsolate(); 2012 Dart_ShutdownIsolate();
1980 } 2013 }
1981 2014
1982 2015
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 2077
2045 url = Dart_NewString("libraryE.dart"); 2078 url = Dart_NewString("libraryE.dart");
2046 source = Dart_NewString(kLibraryEChars); 2079 source = Dart_NewString(kLibraryEChars);
2047 Dart_LoadLibrary(url, source); 2080 Dart_LoadLibrary(url, source);
2048 2081
2049 result = Dart_InvokeStatic(result, 2082 result = Dart_InvokeStatic(result,
2050 Dart_NewString(""), 2083 Dart_NewString(""),
2051 Dart_NewString("main"), 2084 Dart_NewString("main"),
2052 0, 2085 0,
2053 NULL); 2086 NULL);
2054 EXPECT(!Dart_IsValid(result)); 2087 EXPECT(Dart_IsError(result));
2055 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in" 2088 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in"
2056 " 'libraryF.dart' and 'libraryC.dart'\n", 2089 " 'libraryF.dart' and 'libraryC.dart'\n",
2057 Dart_GetError(result)); 2090 Dart_GetError(result));
2058 2091
2059 Dart_ExitScope(); // Exit the Dart API scope. 2092 Dart_ExitScope(); // Exit the Dart API scope.
2060 } 2093 }
2061 Dart_ShutdownIsolate(); 2094 Dart_ShutdownIsolate();
2062 } 2095 }
2063 2096
2064 2097
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 NULL); 2129 NULL);
2097 EXPECT_VALID(result); 2130 EXPECT_VALID(result);
2098 2131
2099 Dart_ExitScope(); // Exit the Dart API scope. 2132 Dart_ExitScope(); // Exit the Dart API scope.
2100 } 2133 }
2101 Dart_ShutdownIsolate(); 2134 Dart_ShutdownIsolate();
2102 } 2135 }
2103 #endif // TARGET_ARCH_IA32. 2136 #endif // TARGET_ARCH_IA32.
2104 2137
2105 } // namespace dart 2138 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/exceptions_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698