| OLD | NEW |
| 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" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 EXPECT_VALID(result); | 332 EXPECT_VALID(result); |
| 333 EXPECT(fits); | 333 EXPECT(fits); |
| 334 | 334 |
| 335 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3); | 335 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3); |
| 336 EXPECT(Dart_IsInteger(val3)); | 336 EXPECT(Dart_IsInteger(val3)); |
| 337 result = Dart_IntegerFitsIntoInt64(val3, &fits); | 337 result = Dart_IntegerFitsIntoInt64(val3, &fits); |
| 338 EXPECT_VALID(result); | 338 EXPECT_VALID(result); |
| 339 EXPECT(!fits); | 339 EXPECT(!fits); |
| 340 | 340 |
| 341 int64_t out = 0; | 341 int64_t out = 0; |
| 342 result = Dart_IntegerValue(val1, &out); | 342 result = Dart_IntegerToInt64(val1, &out); |
| 343 EXPECT_VALID(result); | 343 EXPECT_VALID(result); |
| 344 EXPECT_EQ(kIntegerVal1, out); | 344 EXPECT_EQ(kIntegerVal1, out); |
| 345 | 345 |
| 346 result = Dart_IntegerValue(val2, &out); | 346 result = Dart_IntegerToInt64(val2, &out); |
| 347 EXPECT_VALID(result); | 347 EXPECT_VALID(result); |
| 348 EXPECT_EQ(kIntegerVal2, out); | 348 EXPECT_EQ(kIntegerVal2, out); |
| 349 | 349 |
| 350 const char* chars = NULL; | 350 const char* chars = NULL; |
| 351 result = Dart_IntegerValueHexCString(val3, &chars); | 351 result = Dart_IntegerValueHexCString(val3, &chars); |
| 352 EXPECT_VALID(result); | 352 EXPECT_VALID(result); |
| 353 EXPECT(!strcmp(kIntegerVal3, chars)); | 353 EXPECT(!strcmp(kIntegerVal3, chars)); |
| 354 | 354 |
| 355 Dart_ExitScope(); // Exit the Dart API scope. | 355 Dart_ExitScope(); // Exit the Dart API scope. |
| 356 Dart_ShutdownIsolate(); | 356 Dart_ShutdownIsolate(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 382 EXPECT(Dart_IsError(result)); | 382 EXPECT(Dart_IsError(result)); |
| 383 | 383 |
| 384 for (int i = 0; i < kArrayLength; i++) { | 384 for (int i = 0; i < kArrayLength; i++) { |
| 385 result = Dart_ListSetAt(val, i, Dart_NewInteger(i)); | 385 result = Dart_ListSetAt(val, i, Dart_NewInteger(i)); |
| 386 EXPECT_VALID(result); | 386 EXPECT_VALID(result); |
| 387 } | 387 } |
| 388 for (int i = 0; i < kArrayLength; i++) { | 388 for (int i = 0; i < kArrayLength; i++) { |
| 389 result = Dart_ListGetAt(val, i); | 389 result = Dart_ListGetAt(val, i); |
| 390 EXPECT_VALID(result); | 390 EXPECT_VALID(result); |
| 391 int64_t value; | 391 int64_t value; |
| 392 result = Dart_IntegerValue(result, &value); | 392 result = Dart_IntegerToInt64(result, &value); |
| 393 EXPECT_VALID(result); | 393 EXPECT_VALID(result); |
| 394 EXPECT_EQ(i, value); | 394 EXPECT_EQ(i, value); |
| 395 } | 395 } |
| 396 | 396 |
| 397 Dart_ExitScope(); // Exit the Dart API scope. | 397 Dart_ExitScope(); // Exit the Dart API scope. |
| 398 Dart_ShutdownIsolate(); | 398 Dart_ShutdownIsolate(); |
| 399 } | 399 } |
| 400 | 400 |
| 401 | 401 |
| 402 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 402 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 intptr_t len = 0; | 439 intptr_t len = 0; |
| 440 result = Dart_ListLength(ListAccessTestObj, &len); | 440 result = Dart_ListLength(ListAccessTestObj, &len); |
| 441 EXPECT_VALID(result); | 441 EXPECT_VALID(result); |
| 442 EXPECT_EQ(3, len); | 442 EXPECT_EQ(3, len); |
| 443 | 443 |
| 444 // Access elements in the array. | 444 // Access elements in the array. |
| 445 int64_t value; | 445 int64_t value; |
| 446 | 446 |
| 447 result = Dart_ListGetAt(ListAccessTestObj, 0); | 447 result = Dart_ListGetAt(ListAccessTestObj, 0); |
| 448 EXPECT_VALID(result); | 448 EXPECT_VALID(result); |
| 449 result = Dart_IntegerValue(result, &value); | 449 result = Dart_IntegerToInt64(result, &value); |
| 450 EXPECT_VALID(result); | 450 EXPECT_VALID(result); |
| 451 EXPECT_EQ(10, value); | 451 EXPECT_EQ(10, value); |
| 452 | 452 |
| 453 result = Dart_ListGetAt(ListAccessTestObj, 1); | 453 result = Dart_ListGetAt(ListAccessTestObj, 1); |
| 454 EXPECT_VALID(result); | 454 EXPECT_VALID(result); |
| 455 result = Dart_IntegerValue(result, &value); | 455 result = Dart_IntegerToInt64(result, &value); |
| 456 EXPECT_VALID(result); | 456 EXPECT_VALID(result); |
| 457 EXPECT_EQ(20, value); | 457 EXPECT_EQ(20, value); |
| 458 | 458 |
| 459 result = Dart_ListGetAt(ListAccessTestObj, 2); | 459 result = Dart_ListGetAt(ListAccessTestObj, 2); |
| 460 EXPECT_VALID(result); | 460 EXPECT_VALID(result); |
| 461 result = Dart_IntegerValue(result, &value); | 461 result = Dart_IntegerToInt64(result, &value); |
| 462 EXPECT_VALID(result); | 462 EXPECT_VALID(result); |
| 463 EXPECT_EQ(30, value); | 463 EXPECT_EQ(30, value); |
| 464 | 464 |
| 465 // Set some elements in the array. | 465 // Set some elements in the array. |
| 466 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); | 466 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); |
| 467 EXPECT_VALID(result); | 467 EXPECT_VALID(result); |
| 468 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); | 468 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); |
| 469 EXPECT_VALID(result); | 469 EXPECT_VALID(result); |
| 470 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); | 470 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); |
| 471 EXPECT_VALID(result); | 471 EXPECT_VALID(result); |
| 472 | 472 |
| 473 // Get length of array object. | 473 // Get length of array object. |
| 474 result = Dart_ListLength(ListAccessTestObj, &len); | 474 result = Dart_ListLength(ListAccessTestObj, &len); |
| 475 EXPECT_VALID(result); | 475 EXPECT_VALID(result); |
| 476 EXPECT_EQ(3, len); | 476 EXPECT_EQ(3, len); |
| 477 | 477 |
| 478 // Now try and access these elements in the array. | 478 // Now try and access these elements in the array. |
| 479 result = Dart_ListGetAt(ListAccessTestObj, 0); | 479 result = Dart_ListGetAt(ListAccessTestObj, 0); |
| 480 EXPECT_VALID(result); | 480 EXPECT_VALID(result); |
| 481 result = Dart_IntegerValue(result, &value); | 481 result = Dart_IntegerToInt64(result, &value); |
| 482 EXPECT_VALID(result); | 482 EXPECT_VALID(result); |
| 483 EXPECT_EQ(0, value); | 483 EXPECT_EQ(0, value); |
| 484 | 484 |
| 485 result = Dart_ListGetAt(ListAccessTestObj, 1); | 485 result = Dart_ListGetAt(ListAccessTestObj, 1); |
| 486 EXPECT_VALID(result); | 486 EXPECT_VALID(result); |
| 487 result = Dart_IntegerValue(result, &value); | 487 result = Dart_IntegerToInt64(result, &value); |
| 488 EXPECT_VALID(result); | 488 EXPECT_VALID(result); |
| 489 EXPECT_EQ(1, value); | 489 EXPECT_EQ(1, value); |
| 490 | 490 |
| 491 result = Dart_ListGetAt(ListAccessTestObj, 2); | 491 result = Dart_ListGetAt(ListAccessTestObj, 2); |
| 492 EXPECT_VALID(result); | 492 EXPECT_VALID(result); |
| 493 result = Dart_IntegerValue(result, &value); | 493 result = Dart_IntegerToInt64(result, &value); |
| 494 EXPECT_VALID(result); | 494 EXPECT_VALID(result); |
| 495 EXPECT_EQ(2, value); | 495 EXPECT_EQ(2, value); |
| 496 | 496 |
| 497 uint8_t native_array[3]; | 497 uint8_t native_array[3]; |
| 498 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); | 498 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); |
| 499 EXPECT_VALID(result); | 499 EXPECT_VALID(result); |
| 500 EXPECT_EQ(0, native_array[0]); | 500 EXPECT_EQ(0, native_array[0]); |
| 501 EXPECT_EQ(1, native_array[1]); | 501 EXPECT_EQ(1, native_array[1]); |
| 502 EXPECT_EQ(2, native_array[2]); | 502 EXPECT_EQ(2, native_array[2]); |
| 503 | 503 |
| 504 native_array[0] = 10; | 504 native_array[0] = 10; |
| 505 native_array[1] = 20; | 505 native_array[1] = 20; |
| 506 native_array[2] = 30; | 506 native_array[2] = 30; |
| 507 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3); | 507 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3); |
| 508 EXPECT_VALID(result); | 508 EXPECT_VALID(result); |
| 509 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); | 509 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); |
| 510 EXPECT_VALID(result); | 510 EXPECT_VALID(result); |
| 511 EXPECT_EQ(10, native_array[0]); | 511 EXPECT_EQ(10, native_array[0]); |
| 512 EXPECT_EQ(20, native_array[1]); | 512 EXPECT_EQ(20, native_array[1]); |
| 513 EXPECT_EQ(30, native_array[2]); | 513 EXPECT_EQ(30, native_array[2]); |
| 514 result = Dart_ListGetAt(ListAccessTestObj, 2); | 514 result = Dart_ListGetAt(ListAccessTestObj, 2); |
| 515 EXPECT_VALID(result); | 515 EXPECT_VALID(result); |
| 516 result = Dart_IntegerValue(result, &value); | 516 result = Dart_IntegerToInt64(result, &value); |
| 517 EXPECT_VALID(result); | 517 EXPECT_VALID(result); |
| 518 EXPECT_EQ(30, value); | 518 EXPECT_EQ(30, value); |
| 519 | 519 |
| 520 // Check if we get an exception when accessing beyond limit. | 520 // Check if we get an exception when accessing beyond limit. |
| 521 result = Dart_ListGetAt(ListAccessTestObj, 4); | 521 result = Dart_ListGetAt(ListAccessTestObj, 4); |
| 522 EXPECT(Dart_IsError(result)); | 522 EXPECT(Dart_IsError(result)); |
| 523 | 523 |
| 524 Dart_ExitScope(); // Exit the Dart API scope. | 524 Dart_ExitScope(); // Exit the Dart API scope. |
| 525 } | 525 } |
| 526 Dart_ShutdownIsolate(); | 526 Dart_ShutdownIsolate(); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 // Now access and set various static fields of Fields class. | 849 // Now access and set various static fields of Fields class. |
| 850 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); | 850 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); |
| 851 EXPECT_VALID(cls); | 851 EXPECT_VALID(cls); |
| 852 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); | 852 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); |
| 853 EXPECT(Dart_IsError(result)); | 853 EXPECT(Dart_IsError(result)); |
| 854 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); | 854 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); |
| 855 EXPECT(Dart_IsError(result)); | 855 EXPECT(Dart_IsError(result)); |
| 856 result = Dart_GetStaticField(cls, Dart_NewString("fld4")); | 856 result = Dart_GetStaticField(cls, Dart_NewString("fld4")); |
| 857 EXPECT_VALID(result); | 857 EXPECT_VALID(result); |
| 858 int64_t value = 0; | 858 int64_t value = 0; |
| 859 result = Dart_IntegerValue(result, &value); | 859 result = Dart_IntegerToInt64(result, &value); |
| 860 EXPECT_EQ(10, value); | 860 EXPECT_EQ(10, value); |
| 861 result = Dart_SetStaticField(cls, | 861 result = Dart_SetStaticField(cls, |
| 862 Dart_NewString("fld4"), | 862 Dart_NewString("fld4"), |
| 863 Dart_NewInteger(20)); | 863 Dart_NewInteger(20)); |
| 864 EXPECT(Dart_IsError(result)); | 864 EXPECT(Dart_IsError(result)); |
| 865 result = Dart_GetStaticField(cls, Dart_NewString("fld3")); | 865 result = Dart_GetStaticField(cls, Dart_NewString("fld3")); |
| 866 EXPECT_VALID(result); | 866 EXPECT_VALID(result); |
| 867 result = Dart_SetStaticField(cls, | 867 result = Dart_SetStaticField(cls, |
| 868 Dart_NewString("fld3"), | 868 Dart_NewString("fld3"), |
| 869 Dart_NewInteger(200)); | 869 Dart_NewInteger(200)); |
| 870 EXPECT_VALID(result); | 870 EXPECT_VALID(result); |
| 871 result = Dart_IntegerValue(result, &value); | 871 result = Dart_IntegerToInt64(result, &value); |
| 872 EXPECT_EQ(200, value); | 872 EXPECT_EQ(200, value); |
| 873 | 873 |
| 874 // Now access and set various instance fields of the returned object. | 874 // Now access and set various instance fields of the returned object. |
| 875 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); | 875 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); |
| 876 EXPECT(Dart_IsError(result)); | 876 EXPECT(Dart_IsError(result)); |
| 877 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); | 877 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| 878 EXPECT_VALID(result); | 878 EXPECT_VALID(result); |
| 879 result = Dart_IntegerValue(result, &value); | 879 result = Dart_IntegerToInt64(result, &value); |
| 880 EXPECT_EQ(10, value); | 880 EXPECT_EQ(10, value); |
| 881 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); | 881 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); |
| 882 EXPECT_VALID(result); | 882 EXPECT_VALID(result); |
| 883 result = Dart_IntegerValue(result, &value); | 883 result = Dart_IntegerToInt64(result, &value); |
| 884 EXPECT_EQ(20, value); | 884 EXPECT_EQ(20, value); |
| 885 result = Dart_SetInstanceField(retobj, | 885 result = Dart_SetInstanceField(retobj, |
| 886 Dart_NewString("fld2"), | 886 Dart_NewString("fld2"), |
| 887 Dart_NewInteger(40)); | 887 Dart_NewInteger(40)); |
| 888 EXPECT(Dart_IsError(result)); | 888 EXPECT(Dart_IsError(result)); |
| 889 result = Dart_SetInstanceField(retobj, | 889 result = Dart_SetInstanceField(retobj, |
| 890 Dart_NewString("fld1"), | 890 Dart_NewString("fld1"), |
| 891 Dart_NewInteger(40)); | 891 Dart_NewInteger(40)); |
| 892 EXPECT_VALID(result); | 892 EXPECT_VALID(result); |
| 893 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); | 893 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| 894 EXPECT_VALID(result); | 894 EXPECT_VALID(result); |
| 895 result = Dart_IntegerValue(result, &value); | 895 result = Dart_IntegerToInt64(result, &value); |
| 896 EXPECT_EQ(40, value); | 896 EXPECT_EQ(40, value); |
| 897 | 897 |
| 898 Dart_ExitScope(); // Exit the Dart API scope. | 898 Dart_ExitScope(); // Exit the Dart API scope. |
| 899 } | 899 } |
| 900 Dart_ShutdownIsolate(); | 900 Dart_ShutdownIsolate(); |
| 901 } | 901 } |
| 902 | 902 |
| 903 | 903 |
| 904 UNIT_TEST_CASE(HiddenFieldAccess) { | 904 UNIT_TEST_CASE(HiddenFieldAccess) { |
| 905 const char* kScriptChars = | 905 const char* kScriptChars = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 936 // Now access and set various static fields of HiddenFields class. | 936 // Now access and set various static fields of HiddenFields class. |
| 937 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields")); | 937 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields")); |
| 938 EXPECT_VALID(cls); | 938 EXPECT_VALID(cls); |
| 939 result = Dart_GetStaticField(cls, Dart_NewString("_fld1")); | 939 result = Dart_GetStaticField(cls, Dart_NewString("_fld1")); |
| 940 EXPECT(Dart_IsError(result)); | 940 EXPECT(Dart_IsError(result)); |
| 941 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); | 941 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); |
| 942 EXPECT(Dart_IsError(result)); | 942 EXPECT(Dart_IsError(result)); |
| 943 result = Dart_GetStaticField(cls, Dart_NewString("_fld4")); | 943 result = Dart_GetStaticField(cls, Dart_NewString("_fld4")); |
| 944 EXPECT_VALID(result); | 944 EXPECT_VALID(result); |
| 945 int64_t value = 0; | 945 int64_t value = 0; |
| 946 result = Dart_IntegerValue(result, &value); | 946 result = Dart_IntegerToInt64(result, &value); |
| 947 EXPECT_EQ(10, value); | 947 EXPECT_EQ(10, value); |
| 948 result = Dart_SetStaticField(cls, | 948 result = Dart_SetStaticField(cls, |
| 949 Dart_NewString("_fld4"), | 949 Dart_NewString("_fld4"), |
| 950 Dart_NewInteger(20)); | 950 Dart_NewInteger(20)); |
| 951 EXPECT(Dart_IsError(result)); | 951 EXPECT(Dart_IsError(result)); |
| 952 result = Dart_GetStaticField(cls, Dart_NewString("_fld3")); | 952 result = Dart_GetStaticField(cls, Dart_NewString("_fld3")); |
| 953 EXPECT_VALID(result); | 953 EXPECT_VALID(result); |
| 954 result = Dart_SetStaticField(cls, | 954 result = Dart_SetStaticField(cls, |
| 955 Dart_NewString("_fld3"), | 955 Dart_NewString("_fld3"), |
| 956 Dart_NewInteger(200)); | 956 Dart_NewInteger(200)); |
| 957 EXPECT_VALID(result); | 957 EXPECT_VALID(result); |
| 958 result = Dart_IntegerValue(result, &value); | 958 result = Dart_IntegerToInt64(result, &value); |
| 959 EXPECT_EQ(200, value); | 959 EXPECT_EQ(200, value); |
| 960 | 960 |
| 961 // Now access and set various instance fields of the returned object. | 961 // Now access and set various instance fields of the returned object. |
| 962 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); | 962 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); |
| 963 EXPECT(Dart_IsError(result)); | 963 EXPECT(Dart_IsError(result)); |
| 964 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); | 964 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); |
| 965 EXPECT_VALID(result); | 965 EXPECT_VALID(result); |
| 966 result = Dart_IntegerValue(result, &value); | 966 result = Dart_IntegerToInt64(result, &value); |
| 967 EXPECT_EQ(10, value); | 967 EXPECT_EQ(10, value); |
| 968 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2")); | 968 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2")); |
| 969 EXPECT_VALID(result); | 969 EXPECT_VALID(result); |
| 970 result = Dart_IntegerValue(result, &value); | 970 result = Dart_IntegerToInt64(result, &value); |
| 971 EXPECT_EQ(20, value); | 971 EXPECT_EQ(20, value); |
| 972 result = Dart_SetInstanceField(retobj, | 972 result = Dart_SetInstanceField(retobj, |
| 973 Dart_NewString("_fld2"), | 973 Dart_NewString("_fld2"), |
| 974 Dart_NewInteger(40)); | 974 Dart_NewInteger(40)); |
| 975 EXPECT(Dart_IsError(result)); | 975 EXPECT(Dart_IsError(result)); |
| 976 result = Dart_SetInstanceField(retobj, | 976 result = Dart_SetInstanceField(retobj, |
| 977 Dart_NewString("_fld1"), | 977 Dart_NewString("_fld1"), |
| 978 Dart_NewInteger(40)); | 978 Dart_NewInteger(40)); |
| 979 EXPECT_VALID(result); | 979 EXPECT_VALID(result); |
| 980 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); | 980 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); |
| 981 EXPECT_VALID(result); | 981 EXPECT_VALID(result); |
| 982 result = Dart_IntegerValue(result, &value); | 982 result = Dart_IntegerToInt64(result, &value); |
| 983 EXPECT_EQ(40, value); | 983 EXPECT_EQ(40, value); |
| 984 | 984 |
| 985 Dart_ExitScope(); // Exit the Dart API scope. | 985 Dart_ExitScope(); // Exit the Dart API scope. |
| 986 } | 986 } |
| 987 Dart_ShutdownIsolate(); | 987 Dart_ShutdownIsolate(); |
| 988 } | 988 } |
| 989 | 989 |
| 990 | 990 |
| 991 UNIT_TEST_CASE(InjectNativeFields1) { | 991 UNIT_TEST_CASE(InjectNativeFields1) { |
| 992 const char* kScriptChars = | 992 const char* kScriptChars = |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 0, | 1129 0, |
| 1130 NULL); | 1130 NULL); |
| 1131 EXPECT_VALID(retobj); | 1131 EXPECT_VALID(retobj); |
| 1132 | 1132 |
| 1133 // Now access and set various instance fields of the returned object. | 1133 // Now access and set various instance fields of the returned object. |
| 1134 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); | 1134 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); |
| 1135 EXPECT(Dart_IsError(result)); | 1135 EXPECT(Dart_IsError(result)); |
| 1136 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); | 1136 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| 1137 EXPECT_VALID(result); | 1137 EXPECT_VALID(result); |
| 1138 int64_t value = 0; | 1138 int64_t value = 0; |
| 1139 result = Dart_IntegerValue(result, &value); | 1139 result = Dart_IntegerToInt64(result, &value); |
| 1140 EXPECT_EQ(10, value); | 1140 EXPECT_EQ(10, value); |
| 1141 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); | 1141 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); |
| 1142 EXPECT_VALID(result); | 1142 EXPECT_VALID(result); |
| 1143 result = Dart_IntegerValue(result, &value); | 1143 result = Dart_IntegerToInt64(result, &value); |
| 1144 EXPECT_EQ(20, value); | 1144 EXPECT_EQ(20, value); |
| 1145 result = Dart_SetInstanceField(retobj, | 1145 result = Dart_SetInstanceField(retobj, |
| 1146 Dart_NewString("fld2"), | 1146 Dart_NewString("fld2"), |
| 1147 Dart_NewInteger(40)); | 1147 Dart_NewInteger(40)); |
| 1148 EXPECT(Dart_IsError(result)); | 1148 EXPECT(Dart_IsError(result)); |
| 1149 result = Dart_SetInstanceField(retobj, | 1149 result = Dart_SetInstanceField(retobj, |
| 1150 Dart_NewString("fld1"), | 1150 Dart_NewString("fld1"), |
| 1151 Dart_NewInteger(40)); | 1151 Dart_NewInteger(40)); |
| 1152 EXPECT_VALID(result); | 1152 EXPECT_VALID(result); |
| 1153 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); | 1153 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| 1154 EXPECT_VALID(result); | 1154 EXPECT_VALID(result); |
| 1155 result = Dart_IntegerValue(result, &value); | 1155 result = Dart_IntegerToInt64(result, &value); |
| 1156 EXPECT_EQ(40, value); | 1156 EXPECT_EQ(40, value); |
| 1157 | 1157 |
| 1158 // Now access and set various native instance fields of the returned object. | 1158 // Now access and set various native instance fields of the returned object. |
| 1159 const int kNativeFld0 = 0; | 1159 const int kNativeFld0 = 0; |
| 1160 const int kNativeFld1 = 1; | 1160 const int kNativeFld1 = 1; |
| 1161 const int kNativeFld2 = 2; | 1161 const int kNativeFld2 = 2; |
| 1162 const int kNativeFld3 = 3; | 1162 const int kNativeFld3 = 3; |
| 1163 const int kNativeFld4 = 4; | 1163 const int kNativeFld4 = 4; |
| 1164 intptr_t field_value = 0; | 1164 intptr_t field_value = 0; |
| 1165 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value); | 1165 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1184 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000); | 1184 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000); |
| 1185 EXPECT_VALID(result); | 1185 EXPECT_VALID(result); |
| 1186 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value); | 1186 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value); |
| 1187 EXPECT_VALID(result); | 1187 EXPECT_VALID(result); |
| 1188 EXPECT_EQ(4000, field_value); | 1188 EXPECT_EQ(4000, field_value); |
| 1189 | 1189 |
| 1190 // Now re-access various dart instance fields of the returned object | 1190 // Now re-access various dart instance fields of the returned object |
| 1191 // to ensure that there was no corruption while setting native fields. | 1191 // to ensure that there was no corruption while setting native fields. |
| 1192 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); | 1192 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| 1193 EXPECT_VALID(result); | 1193 EXPECT_VALID(result); |
| 1194 result = Dart_IntegerValue(result, &value); | 1194 result = Dart_IntegerToInt64(result, &value); |
| 1195 EXPECT_EQ(40, value); | 1195 EXPECT_EQ(40, value); |
| 1196 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); | 1196 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); |
| 1197 EXPECT_VALID(result); | 1197 EXPECT_VALID(result); |
| 1198 result = Dart_IntegerValue(result, &value); | 1198 result = Dart_IntegerToInt64(result, &value); |
| 1199 EXPECT_EQ(20, value); | 1199 EXPECT_EQ(20, value); |
| 1200 | 1200 |
| 1201 Dart_ExitScope(); // Exit the Dart API scope. | 1201 Dart_ExitScope(); // Exit the Dart API scope. |
| 1202 } | 1202 } |
| 1203 Dart_ShutdownIsolate(); | 1203 Dart_ShutdownIsolate(); |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 | 1206 |
| 1207 UNIT_TEST_CASE(NegativeNativeFieldAccess) { | 1207 UNIT_TEST_CASE(NegativeNativeFieldAccess) { |
| 1208 const char* kScriptChars = | 1208 const char* kScriptChars = |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 0, | 1316 0, |
| 1317 NULL); | 1317 NULL); |
| 1318 | 1318 |
| 1319 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); | 1319 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); |
| 1320 EXPECT_VALID(cls); | 1320 EXPECT_VALID(cls); |
| 1321 | 1321 |
| 1322 // For uninitialized fields, the getter is returned | 1322 // For uninitialized fields, the getter is returned |
| 1323 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); | 1323 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); |
| 1324 EXPECT_VALID(result); | 1324 EXPECT_VALID(result); |
| 1325 int64_t value = 0; | 1325 int64_t value = 0; |
| 1326 result = Dart_IntegerValue(result, &value); | 1326 result = Dart_IntegerToInt64(result, &value); |
| 1327 EXPECT_EQ(7, value); | 1327 EXPECT_EQ(7, value); |
| 1328 | 1328 |
| 1329 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); | 1329 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); |
| 1330 EXPECT_VALID(result); | 1330 EXPECT_VALID(result); |
| 1331 result = Dart_IntegerValue(result, &value); | 1331 result = Dart_IntegerToInt64(result, &value); |
| 1332 EXPECT_EQ(11, value); | 1332 EXPECT_EQ(11, value); |
| 1333 | 1333 |
| 1334 // Overwrite fld2 | 1334 // Overwrite fld2 |
| 1335 result = Dart_SetStaticField(cls, | 1335 result = Dart_SetStaticField(cls, |
| 1336 Dart_NewString("fld2"), | 1336 Dart_NewString("fld2"), |
| 1337 Dart_NewInteger(13)); | 1337 Dart_NewInteger(13)); |
| 1338 EXPECT_VALID(result); | 1338 EXPECT_VALID(result); |
| 1339 | 1339 |
| 1340 // We now get the new value for fld2, not the initializer | 1340 // We now get the new value for fld2, not the initializer |
| 1341 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); | 1341 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); |
| 1342 EXPECT_VALID(result); | 1342 EXPECT_VALID(result); |
| 1343 result = Dart_IntegerValue(result, &value); | 1343 result = Dart_IntegerToInt64(result, &value); |
| 1344 EXPECT_EQ(13, value); | 1344 EXPECT_EQ(13, value); |
| 1345 | 1345 |
| 1346 Dart_ExitScope(); // Exit the Dart API scope. | 1346 Dart_ExitScope(); // Exit the Dart API scope. |
| 1347 } | 1347 } |
| 1348 Dart_ShutdownIsolate(); | 1348 Dart_ShutdownIsolate(); |
| 1349 } | 1349 } |
| 1350 | 1350 |
| 1351 | 1351 |
| 1352 UNIT_TEST_CASE(StaticFieldNotFound) { | 1352 UNIT_TEST_CASE(StaticFieldNotFound) { |
| 1353 const char* kScriptChars = | 1353 const char* kScriptChars = |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 // Now invoke a dynamic method and check the result. | 1430 // Now invoke a dynamic method and check the result. |
| 1431 Dart_Handle dart_arguments[1]; | 1431 Dart_Handle dart_arguments[1]; |
| 1432 dart_arguments[0] = Dart_NewInteger(1); | 1432 dart_arguments[0] = Dart_NewInteger(1); |
| 1433 result = Dart_InvokeDynamic(retobj, | 1433 result = Dart_InvokeDynamic(retobj, |
| 1434 Dart_NewString("method1"), | 1434 Dart_NewString("method1"), |
| 1435 1, | 1435 1, |
| 1436 dart_arguments); | 1436 dart_arguments); |
| 1437 EXPECT_VALID(result); | 1437 EXPECT_VALID(result); |
| 1438 EXPECT(Dart_IsInteger(result)); | 1438 EXPECT(Dart_IsInteger(result)); |
| 1439 int64_t value = 0; | 1439 int64_t value = 0; |
| 1440 result = Dart_IntegerValue(result, &value); | 1440 result = Dart_IntegerToInt64(result, &value); |
| 1441 EXPECT_EQ(41, value); | 1441 EXPECT_EQ(41, value); |
| 1442 | 1442 |
| 1443 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); | 1443 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); |
| 1444 EXPECT(Dart_IsError(result)); | 1444 EXPECT(Dart_IsError(result)); |
| 1445 | 1445 |
| 1446 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL); | 1446 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL); |
| 1447 EXPECT(Dart_IsError(result)); | 1447 EXPECT(Dart_IsError(result)); |
| 1448 | 1448 |
| 1449 Dart_ExitScope(); // Exit the Dart API scope. | 1449 Dart_ExitScope(); // Exit the Dart API scope. |
| 1450 } | 1450 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 EXPECT(Dart_IsClosure(retobj)); | 1498 EXPECT(Dart_IsClosure(retobj)); |
| 1499 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 1499 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
| 1500 | 1500 |
| 1501 // Now invoke the closure and check the result. | 1501 // Now invoke the closure and check the result. |
| 1502 Dart_Handle dart_arguments[1]; | 1502 Dart_Handle dart_arguments[1]; |
| 1503 dart_arguments[0] = Dart_NewInteger(1); | 1503 dart_arguments[0] = Dart_NewInteger(1); |
| 1504 result = Dart_InvokeClosure(retobj, 1, dart_arguments); | 1504 result = Dart_InvokeClosure(retobj, 1, dart_arguments); |
| 1505 EXPECT_VALID(result); | 1505 EXPECT_VALID(result); |
| 1506 EXPECT(Dart_IsInteger(result)); | 1506 EXPECT(Dart_IsInteger(result)); |
| 1507 int64_t value = 0; | 1507 int64_t value = 0; |
| 1508 result = Dart_IntegerValue(result, &value); | 1508 result = Dart_IntegerToInt64(result, &value); |
| 1509 EXPECT_EQ(51, value); | 1509 EXPECT_EQ(51, value); |
| 1510 | 1510 |
| 1511 // Invoke closure with wrong number of args, should result in exception. | 1511 // Invoke closure with wrong number of args, should result in exception. |
| 1512 result = Dart_InvokeClosure(retobj, 0, NULL); | 1512 result = Dart_InvokeClosure(retobj, 0, NULL); |
| 1513 EXPECT(Dart_IsError(result)); | 1513 EXPECT(Dart_IsError(result)); |
| 1514 EXPECT(Dart_ErrorHasException(result)); | 1514 EXPECT(Dart_ErrorHasException(result)); |
| 1515 | 1515 |
| 1516 // Invoke a function which returns a closure. | 1516 // Invoke a function which returns a closure. |
| 1517 retobj = Dart_InvokeStatic(lib, | 1517 retobj = Dart_InvokeStatic(lib, |
| 1518 Dart_NewString("InvokeClosureTest"), | 1518 Dart_NewString("InvokeClosureTest"), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 result = Dart_ThrowException(retobj); | 1595 result = Dart_ThrowException(retobj); |
| 1596 EXPECT(Dart_IsError(result)); | 1596 EXPECT(Dart_IsError(result)); |
| 1597 | 1597 |
| 1598 // Now invoke method2 which invokes a natve method where it is | 1598 // Now invoke method2 which invokes a natve method where it is |
| 1599 // ok to throw an exception, check the result which would indicate | 1599 // ok to throw an exception, check the result which would indicate |
| 1600 // if an exception was thrown or not. | 1600 // if an exception was thrown or not. |
| 1601 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); | 1601 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); |
| 1602 EXPECT_VALID(result); | 1602 EXPECT_VALID(result); |
| 1603 EXPECT(Dart_IsInteger(result)); | 1603 EXPECT(Dart_IsInteger(result)); |
| 1604 int64_t value = 0; | 1604 int64_t value = 0; |
| 1605 result = Dart_IntegerValue(result, &value); | 1605 result = Dart_IntegerToInt64(result, &value); |
| 1606 EXPECT_EQ(5, value); | 1606 EXPECT_EQ(5, value); |
| 1607 | 1607 |
| 1608 Dart_ExitScope(); // Exit the Dart API scope. | 1608 Dart_ExitScope(); // Exit the Dart API scope. |
| 1609 EXPECT_EQ(size, state->ZoneSizeInBytes()); | 1609 EXPECT_EQ(size, state->ZoneSizeInBytes()); |
| 1610 } | 1610 } |
| 1611 Dart_ShutdownIsolate(); | 1611 Dart_ShutdownIsolate(); |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 | 1614 |
| 1615 void NativeArgumentCounter(Dart_NativeArguments args) { | 1615 void NativeArgumentCounter(Dart_NativeArguments args) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1646 | 1646 |
| 1647 Dart_Handle result = Dart_InvokeStatic(lib, | 1647 Dart_Handle result = Dart_InvokeStatic(lib, |
| 1648 Dart_NewString("Test"), | 1648 Dart_NewString("Test"), |
| 1649 Dart_NewString("testMain"), | 1649 Dart_NewString("testMain"), |
| 1650 0, | 1650 0, |
| 1651 NULL); | 1651 NULL); |
| 1652 EXPECT_VALID(result); | 1652 EXPECT_VALID(result); |
| 1653 EXPECT(Dart_IsInteger(result)); | 1653 EXPECT(Dart_IsInteger(result)); |
| 1654 | 1654 |
| 1655 int64_t value = 0; | 1655 int64_t value = 0; |
| 1656 result = Dart_IntegerValue(result, &value); | 1656 result = Dart_IntegerToInt64(result, &value); |
| 1657 EXPECT_VALID(result); | 1657 EXPECT_VALID(result); |
| 1658 EXPECT_EQ(3, value); | 1658 EXPECT_EQ(3, value); |
| 1659 | 1659 |
| 1660 Dart_ExitScope(); | 1660 Dart_ExitScope(); |
| 1661 } | 1661 } |
| 1662 Dart_ShutdownIsolate(); | 1662 Dart_ShutdownIsolate(); |
| 1663 } | 1663 } |
| 1664 | 1664 |
| 1665 | 1665 |
| 1666 UNIT_TEST_CASE(GetClass) { | 1666 UNIT_TEST_CASE(GetClass) { |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2119 NULL); | 2119 NULL); |
| 2120 EXPECT_VALID(result); | 2120 EXPECT_VALID(result); |
| 2121 | 2121 |
| 2122 Dart_ExitScope(); // Exit the Dart API scope. | 2122 Dart_ExitScope(); // Exit the Dart API scope. |
| 2123 } | 2123 } |
| 2124 Dart_ShutdownIsolate(); | 2124 Dart_ShutdownIsolate(); |
| 2125 } | 2125 } |
| 2126 #endif // TARGET_ARCH_IA32. | 2126 #endif // TARGET_ARCH_IA32. |
| 2127 | 2127 |
| 2128 } // namespace dart | 2128 } // namespace dart |
| OLD | NEW |