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