| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const char* kScriptChars = | 24 const char* kScriptChars = |
| 25 "void testMain() {\n" | 25 "void testMain() {\n" |
| 26 " throw new Exception(\"bad news\");\n" | 26 " throw new Exception(\"bad news\");\n" |
| 27 "}\n"; | 27 "}\n"; |
| 28 | 28 |
| 29 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 29 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 30 | 30 |
| 31 Dart_Handle instance = Dart_True(); | 31 Dart_Handle instance = Dart_True(); |
| 32 Dart_Handle error = Api::NewError("myerror"); | 32 Dart_Handle error = Api::NewError("myerror"); |
| 33 Dart_Handle exception = Dart_Invoke(lib, | 33 Dart_Handle exception = Dart_Invoke(lib, |
| 34 Dart_NewString("testMain"), | 34 NewString("testMain"), |
| 35 0, | 35 0, |
| 36 NULL); | 36 NULL); |
| 37 | 37 |
| 38 EXPECT_VALID(instance); | 38 EXPECT_VALID(instance); |
| 39 EXPECT(Dart_IsError(error)); | 39 EXPECT(Dart_IsError(error)); |
| 40 EXPECT(Dart_IsError(exception)); | 40 EXPECT(Dart_IsError(exception)); |
| 41 | 41 |
| 42 EXPECT(!Dart_ErrorHasException(instance)); | 42 EXPECT(!Dart_ErrorHasException(instance)); |
| 43 EXPECT(!Dart_ErrorHasException(error)); | 43 EXPECT(!Dart_ErrorHasException(error)); |
| 44 EXPECT(Dart_ErrorHasException(exception)); | 44 EXPECT(Dart_ErrorHasException(exception)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); | 59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); |
| 60 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); | 60 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 | 63 |
| 64 TEST_CASE(ErrorHandleTypes) { | 64 TEST_CASE(ErrorHandleTypes) { |
| 65 Isolate* isolate = Isolate::Current(); | 65 Isolate* isolate = Isolate::Current(); |
| 66 const String& compile_message = String::Handle(String::New("CompileError")); | 66 const String& compile_message = String::Handle(String::New("CompileError")); |
| 67 const String& fatal_message = String::Handle(String::New("FatalError")); | 67 const String& fatal_message = String::Handle(String::New("FatalError")); |
| 68 | 68 |
| 69 Dart_Handle not_error = Dart_NewString("NotError"); | 69 Dart_Handle not_error = NewString("NotError"); |
| 70 Dart_Handle api_error = Dart_NewApiError("Api%s", "Error"); | 70 Dart_Handle api_error = Dart_NewApiError("Api%s", "Error"); |
| 71 Dart_Handle exception_error = | 71 Dart_Handle exception_error = |
| 72 Dart_NewUnhandledExceptionError(Dart_NewString("ExceptionError")); | 72 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
| 73 Dart_Handle compile_error = | 73 Dart_Handle compile_error = |
| 74 Api::NewHandle(isolate, LanguageError::New(compile_message)); | 74 Api::NewHandle(isolate, LanguageError::New(compile_message)); |
| 75 Dart_Handle fatal_error = | 75 Dart_Handle fatal_error = |
| 76 Api::NewHandle(isolate, UnwindError::New(fatal_message)); | 76 Api::NewHandle(isolate, UnwindError::New(fatal_message)); |
| 77 | 77 |
| 78 EXPECT_VALID(not_error); | 78 EXPECT_VALID(not_error); |
| 79 EXPECT(Dart_IsError(api_error)); | 79 EXPECT(Dart_IsError(api_error)); |
| 80 EXPECT(Dart_IsError(exception_error)); | 80 EXPECT(Dart_IsError(exception_error)); |
| 81 EXPECT(Dart_IsError(compile_error)); | 81 EXPECT(Dart_IsError(compile_error)); |
| 82 EXPECT(Dart_IsError(fatal_error)); | 82 EXPECT(Dart_IsError(fatal_error)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 " nativeFunc(() => raiseCompileError());\n" | 148 " nativeFunc(() => raiseCompileError());\n" |
| 149 "}\n" | 149 "}\n" |
| 150 "\n" | 150 "\n" |
| 151 "void Func2() {\n" | 151 "void Func2() {\n" |
| 152 " nativeFunc(() => throwException());\n" | 152 " nativeFunc(() => throwException());\n" |
| 153 "}\n"; | 153 "}\n"; |
| 154 Dart_Handle lib = TestCase::LoadTestScript( | 154 Dart_Handle lib = TestCase::LoadTestScript( |
| 155 kScriptChars, &PropagateError_native_lookup); | 155 kScriptChars, &PropagateError_native_lookup); |
| 156 Dart_Handle result; | 156 Dart_Handle result; |
| 157 | 157 |
| 158 result = Dart_Invoke(lib, Dart_NewString("Func1"), 0, NULL); | 158 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); |
| 159 EXPECT(Dart_IsError(result)); | 159 EXPECT(Dart_IsError(result)); |
| 160 EXPECT(!Dart_ErrorHasException(result)); | 160 EXPECT(!Dart_ErrorHasException(result)); |
| 161 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); | 161 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); |
| 162 | 162 |
| 163 result = Dart_Invoke(lib, Dart_NewString("Func2"), 0, NULL); | 163 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); |
| 164 EXPECT(Dart_IsError(result)); | 164 EXPECT(Dart_IsError(result)); |
| 165 EXPECT(Dart_ErrorHasException(result)); | 165 EXPECT(Dart_ErrorHasException(result)); |
| 166 EXPECT_SUBSTRING("myException", Dart_GetError(result)); | 166 EXPECT_SUBSTRING("myException", Dart_GetError(result)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 #endif | 169 #endif |
| 170 | 170 |
| 171 | 171 |
| 172 TEST_CASE(Dart_Error) { | 172 TEST_CASE(Dart_Error) { |
| 173 Dart_Handle error = Dart_Error("An %s", "error"); | 173 Dart_Handle error = Dart_Error("An %s", "error"); |
| 174 EXPECT(Dart_IsError(error)); | 174 EXPECT(Dart_IsError(error)); |
| 175 EXPECT_STREQ("An error", Dart_GetError(error)); | 175 EXPECT_STREQ("An error", Dart_GetError(error)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 TEST_CASE(Null) { | 179 TEST_CASE(Null) { |
| 180 Dart_Handle null = Dart_Null(); | 180 Dart_Handle null = Dart_Null(); |
| 181 EXPECT_VALID(null); | 181 EXPECT_VALID(null); |
| 182 EXPECT(Dart_IsNull(null)); | 182 EXPECT(Dart_IsNull(null)); |
| 183 | 183 |
| 184 Dart_Handle str = Dart_NewString("test"); | 184 Dart_Handle str = NewString("test"); |
| 185 EXPECT_VALID(str); | 185 EXPECT_VALID(str); |
| 186 EXPECT(!Dart_IsNull(str)); | 186 EXPECT(!Dart_IsNull(str)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 | 189 |
| 190 TEST_CASE(IdentityEquals) { | 190 TEST_CASE(IdentityEquals) { |
| 191 Dart_Handle five = Dart_NewString("5"); | 191 Dart_Handle five = NewString("5"); |
| 192 Dart_Handle five_again = Dart_NewString("5"); | 192 Dart_Handle five_again = NewString("5"); |
| 193 Dart_Handle seven = Dart_NewString("7"); | 193 Dart_Handle seven = NewString("7"); |
| 194 | 194 |
| 195 // Same objects. | 195 // Same objects. |
| 196 EXPECT(Dart_IdentityEquals(five, five)); | 196 EXPECT(Dart_IdentityEquals(five, five)); |
| 197 | 197 |
| 198 // Equal objects. | 198 // Equal objects. |
| 199 EXPECT(!Dart_IdentityEquals(five, five_again)); | 199 EXPECT(!Dart_IdentityEquals(five, five_again)); |
| 200 | 200 |
| 201 // Different objects. | 201 // Different objects. |
| 202 EXPECT(!Dart_IdentityEquals(five, seven)); | 202 EXPECT(!Dart_IdentityEquals(five, seven)); |
| 203 | 203 |
| 204 // Non-instance objects. | 204 // Non-instance objects. |
| 205 { | 205 { |
| 206 Isolate* isolate = Isolate::Current(); | 206 Isolate* isolate = Isolate::Current(); |
| 207 DARTSCOPE_NOCHECKS(isolate); | 207 DARTSCOPE_NOCHECKS(isolate); |
| 208 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); | 208 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); |
| 209 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); | 209 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); |
| 210 | 210 |
| 211 EXPECT(Dart_IdentityEquals(class1, class1)); | 211 EXPECT(Dart_IdentityEquals(class1, class1)); |
| 212 | 212 |
| 213 EXPECT(!Dart_IdentityEquals(class1, class2)); | 213 EXPECT(!Dart_IdentityEquals(class1, class2)); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 // Only ia32 and x64 can run execution tests. | 218 // Only ia32 and x64 can run execution tests. |
| 219 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 219 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 220 | 220 |
| 221 TEST_CASE(ObjectEquals) { | 221 TEST_CASE(ObjectEquals) { |
| 222 bool equal = false; | 222 bool equal = false; |
| 223 Dart_Handle five = Dart_NewString("5"); | 223 Dart_Handle five = NewString("5"); |
| 224 Dart_Handle five_again = Dart_NewString("5"); | 224 Dart_Handle five_again = NewString("5"); |
| 225 Dart_Handle seven = Dart_NewString("7"); | 225 Dart_Handle seven = NewString("7"); |
| 226 | 226 |
| 227 // Same objects. | 227 // Same objects. |
| 228 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); | 228 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
| 229 EXPECT(equal); | 229 EXPECT(equal); |
| 230 | 230 |
| 231 // Equal objects. | 231 // Equal objects. |
| 232 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); | 232 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); |
| 233 EXPECT(equal); | 233 EXPECT(equal); |
| 234 | 234 |
| 235 // Different objects. | 235 // Different objects. |
| 236 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); | 236 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); |
| 237 EXPECT(!equal); | 237 EXPECT(!equal); |
| 238 } | 238 } |
| 239 | 239 |
| 240 #endif | 240 #endif |
| 241 | 241 |
| 242 | 242 |
| 243 TEST_CASE(InstanceValues) { | 243 TEST_CASE(InstanceValues) { |
| 244 EXPECT(Dart_IsInstance(Dart_NewString("test"))); | 244 EXPECT(Dart_IsInstance(NewString("test"))); |
| 245 EXPECT(Dart_IsInstance(Dart_True())); | 245 EXPECT(Dart_IsInstance(Dart_True())); |
| 246 | 246 |
| 247 // By convention, our Is*() functions exclude null. | 247 // By convention, our Is*() functions exclude null. |
| 248 EXPECT(!Dart_IsInstance(Dart_Null())); | 248 EXPECT(!Dart_IsInstance(Dart_Null())); |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 TEST_CASE(InstanceGetClass) { | 252 TEST_CASE(InstanceGetClass) { |
| 253 // Get the handle from a valid instance handle. | 253 // Get the handle from a valid instance handle. |
| 254 Dart_Handle instance = Dart_True(); | 254 Dart_Handle instance = Dart_True(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 269 // Get the handle from a non-instance handle | 269 // Get the handle from a non-instance handle |
| 270 ASSERT(Dart_IsClass(cls)); | 270 ASSERT(Dart_IsClass(cls)); |
| 271 Dart_Handle cls_cls = Dart_InstanceGetClass(cls); | 271 Dart_Handle cls_cls = Dart_InstanceGetClass(cls); |
| 272 EXPECT_ERROR(cls_cls, | 272 EXPECT_ERROR(cls_cls, |
| 273 "Dart_InstanceGetClass expects argument 'instance' to be of " | 273 "Dart_InstanceGetClass expects argument 'instance' to be of " |
| 274 "type Instance."); | 274 "type Instance."); |
| 275 } | 275 } |
| 276 | 276 |
| 277 | 277 |
| 278 TEST_CASE(BooleanValues) { | 278 TEST_CASE(BooleanValues) { |
| 279 Dart_Handle str = Dart_NewString("test"); | 279 Dart_Handle str = NewString("test"); |
| 280 EXPECT(!Dart_IsBoolean(str)); | 280 EXPECT(!Dart_IsBoolean(str)); |
| 281 | 281 |
| 282 bool value = false; | 282 bool value = false; |
| 283 Dart_Handle result = Dart_BooleanValue(str, &value); | 283 Dart_Handle result = Dart_BooleanValue(str, &value); |
| 284 EXPECT(Dart_IsError(result)); | 284 EXPECT(Dart_IsError(result)); |
| 285 | 285 |
| 286 Dart_Handle val1 = Dart_NewBoolean(true); | 286 Dart_Handle val1 = Dart_NewBoolean(true); |
| 287 EXPECT(Dart_IsBoolean(val1)); | 287 EXPECT(Dart_IsBoolean(val1)); |
| 288 | 288 |
| 289 result = Dart_BooleanValue(val1, &value); | 289 result = Dart_BooleanValue(val1, &value); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 const char* kScriptChars = | 344 const char* kScriptChars = |
| 345 "int getInt() { return 1; }\n" | 345 "int getInt() { return 1; }\n" |
| 346 "double getDouble() { return 1.0; }\n" | 346 "double getDouble() { return 1.0; }\n" |
| 347 "bool getBool() { return false; }\n" | 347 "bool getBool() { return false; }\n" |
| 348 "getNull() { return null; }\n"; | 348 "getNull() { return null; }\n"; |
| 349 Dart_Handle result; | 349 Dart_Handle result; |
| 350 // Create a test library and Load up a test script in it. | 350 // Create a test library and Load up a test script in it. |
| 351 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 351 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 352 | 352 |
| 353 // Check int case. | 353 // Check int case. |
| 354 result = Dart_Invoke(lib, Dart_NewString("getInt"), 0, NULL); | 354 result = Dart_Invoke(lib, NewString("getInt"), 0, NULL); |
| 355 EXPECT_VALID(result); | 355 EXPECT_VALID(result); |
| 356 EXPECT(Dart_IsNumber(result)); | 356 EXPECT(Dart_IsNumber(result)); |
| 357 | 357 |
| 358 // Check double case. | 358 // Check double case. |
| 359 result = Dart_Invoke(lib, Dart_NewString("getDouble"), 0, NULL); | 359 result = Dart_Invoke(lib, NewString("getDouble"), 0, NULL); |
| 360 EXPECT_VALID(result); | 360 EXPECT_VALID(result); |
| 361 EXPECT(Dart_IsNumber(result)); | 361 EXPECT(Dart_IsNumber(result)); |
| 362 | 362 |
| 363 // Check bool case. | 363 // Check bool case. |
| 364 result = Dart_Invoke(lib, Dart_NewString("getBool"), 0, NULL); | 364 result = Dart_Invoke(lib, NewString("getBool"), 0, NULL); |
| 365 EXPECT_VALID(result); | 365 EXPECT_VALID(result); |
| 366 EXPECT(!Dart_IsNumber(result)); | 366 EXPECT(!Dart_IsNumber(result)); |
| 367 | 367 |
| 368 // Check null case. | 368 // Check null case. |
| 369 result = Dart_Invoke(lib, Dart_NewString("getNull"), 0, NULL); | 369 result = Dart_Invoke(lib, NewString("getNull"), 0, NULL); |
| 370 EXPECT_VALID(result); | 370 EXPECT_VALID(result); |
| 371 EXPECT(!Dart_IsNumber(result)); | 371 EXPECT(!Dart_IsNumber(result)); |
| 372 } | 372 } |
| 373 | 373 |
| 374 #endif | 374 #endif |
| 375 | 375 |
| 376 | 376 |
| 377 TEST_CASE(IntegerValues) { | 377 TEST_CASE(IntegerValues) { |
| 378 const int64_t kIntegerVal1 = 100; | 378 const int64_t kIntegerVal1 = 100; |
| 379 const int64_t kIntegerVal2 = 0xffffffff; | 379 const int64_t kIntegerVal2 = 0xffffffff; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 EXPECT(Dart_IsInteger(below_min)); | 471 EXPECT(Dart_IsInteger(below_min)); |
| 472 fits = true; | 472 fits = true; |
| 473 result = Dart_IntegerFitsIntoUint64(below_min, &fits); | 473 result = Dart_IntegerFitsIntoUint64(below_min, &fits); |
| 474 EXPECT_VALID(result); | 474 EXPECT_VALID(result); |
| 475 EXPECT(!fits); | 475 EXPECT(!fits); |
| 476 } | 476 } |
| 477 | 477 |
| 478 | 478 |
| 479 TEST_CASE(ArrayValues) { | 479 TEST_CASE(ArrayValues) { |
| 480 const int kArrayLength = 10; | 480 const int kArrayLength = 10; |
| 481 Dart_Handle str = Dart_NewString("test"); | 481 Dart_Handle str = NewString("test"); |
| 482 EXPECT(!Dart_IsList(str)); | 482 EXPECT(!Dart_IsList(str)); |
| 483 Dart_Handle val = Dart_NewList(kArrayLength); | 483 Dart_Handle val = Dart_NewList(kArrayLength); |
| 484 EXPECT(Dart_IsList(val)); | 484 EXPECT(Dart_IsList(val)); |
| 485 intptr_t len = 0; | 485 intptr_t len = 0; |
| 486 Dart_Handle result = Dart_ListLength(val, &len); | 486 Dart_Handle result = Dart_ListLength(val, &len); |
| 487 EXPECT_VALID(result); | 487 EXPECT_VALID(result); |
| 488 EXPECT_EQ(kArrayLength, len); | 488 EXPECT_EQ(kArrayLength, len); |
| 489 | 489 |
| 490 // Check invalid array access. | 490 // Check invalid array access. |
| 491 result = Dart_ListSetAt(val, (kArrayLength + 10), Dart_NewInteger(10)); | 491 result = Dart_ListSetAt(val, (kArrayLength + 10), Dart_NewInteger(10)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 506 EXPECT_VALID(result); | 506 EXPECT_VALID(result); |
| 507 int64_t value; | 507 int64_t value; |
| 508 result = Dart_IntegerToInt64(result, &value); | 508 result = Dart_IntegerToInt64(result, &value); |
| 509 EXPECT_VALID(result); | 509 EXPECT_VALID(result); |
| 510 EXPECT_EQ(i, value); | 510 EXPECT_EQ(i, value); |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 | 513 |
| 514 | 514 |
| 515 TEST_CASE(IsString) { | 515 TEST_CASE(IsString) { |
| 516 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; | 516 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; |
| 517 | 517 |
| 518 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); | 518 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); |
| 519 EXPECT_VALID(str8); | 519 EXPECT_VALID(str8); |
| 520 EXPECT(Dart_IsString(str8)); | 520 EXPECT(Dart_IsString(str8)); |
| 521 EXPECT(Dart_IsString8(str8)); | 521 EXPECT(Dart_IsAsciiString(str8)); |
| 522 EXPECT(Dart_IsString16(str8)); | |
| 523 EXPECT(!Dart_IsExternalString(str8)); | 522 EXPECT(!Dart_IsExternalString(str8)); |
| 524 | 523 |
| 525 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), | 524 Dart_Handle ext8 = Dart_NewExternalUTF8String(data8, ARRAY_SIZE(data8), |
| 526 NULL, NULL); | 525 NULL, NULL); |
| 527 EXPECT_VALID(ext8); | 526 EXPECT_VALID(ext8); |
| 528 EXPECT(Dart_IsString(ext8)); | 527 EXPECT(Dart_IsString(ext8)); |
| 529 EXPECT(Dart_IsString8(ext8)); | |
| 530 EXPECT(Dart_IsString16(ext8)); | |
| 531 EXPECT(Dart_IsExternalString(ext8)); | 528 EXPECT(Dart_IsExternalString(ext8)); |
| 532 | 529 |
| 533 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; | 530 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; |
| 534 | 531 |
| 535 Dart_Handle str16 = Dart_NewString16(data16, ARRAY_SIZE(data16)); | 532 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); |
| 536 EXPECT_VALID(str16); | 533 EXPECT_VALID(str16); |
| 537 EXPECT(Dart_IsString(str16)); | 534 EXPECT(Dart_IsString(str16)); |
| 538 EXPECT(!Dart_IsString8(str16)); | 535 EXPECT(!Dart_IsAsciiString(str16)); |
| 539 EXPECT(Dart_IsString16(str16)); | |
| 540 EXPECT(!Dart_IsExternalString(str16)); | 536 EXPECT(!Dart_IsExternalString(str16)); |
| 541 | 537 |
| 542 Dart_Handle ext16 = Dart_NewExternalString16(data16, ARRAY_SIZE(data16), | 538 Dart_Handle ext16 = Dart_NewExternalUTF16String(data16, ARRAY_SIZE(data16), |
| 543 NULL, NULL); | 539 NULL, NULL); |
| 544 EXPECT_VALID(ext16); | 540 EXPECT_VALID(ext16); |
| 545 EXPECT(Dart_IsString(ext16)); | 541 EXPECT(Dart_IsString(ext16)); |
| 546 EXPECT(!Dart_IsString8(ext16)); | |
| 547 EXPECT(Dart_IsString16(ext16)); | |
| 548 EXPECT(Dart_IsExternalString(ext16)); | 542 EXPECT(Dart_IsExternalString(ext16)); |
| 549 | 543 |
| 550 uint32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; | 544 uint32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; |
| 551 | 545 |
| 552 Dart_Handle str32 = Dart_NewString32(data32, ARRAY_SIZE(data32)); | 546 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); |
| 553 EXPECT_VALID(str32); | 547 EXPECT_VALID(str32); |
| 554 EXPECT(Dart_IsString(str32)); | 548 EXPECT(Dart_IsString(str32)); |
| 555 EXPECT(!Dart_IsString8(str32)); | |
| 556 EXPECT(!Dart_IsString16(str32)); | |
| 557 EXPECT(!Dart_IsExternalString(str32)); | 549 EXPECT(!Dart_IsExternalString(str32)); |
| 558 | |
| 559 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32), | |
| 560 NULL, NULL); | |
| 561 EXPECT_VALID(ext32); | |
| 562 EXPECT(Dart_IsString(ext32)); | |
| 563 EXPECT(!Dart_IsString8(ext32)); | |
| 564 EXPECT(!Dart_IsString16(ext32)); | |
| 565 EXPECT(Dart_IsExternalString(ext32)); | |
| 566 } | 550 } |
| 567 | 551 |
| 568 | 552 |
| 569 TEST_CASE(NewString) { | 553 TEST_CASE(NewString) { |
| 570 const char* ascii = "string"; | 554 const char* ascii = "string"; |
| 571 Dart_Handle ascii_str = Dart_NewString(ascii); | 555 Dart_Handle ascii_str = NewString(ascii); |
| 572 EXPECT_VALID(ascii_str); | 556 EXPECT_VALID(ascii_str); |
| 573 EXPECT(Dart_IsString(ascii_str)); | 557 EXPECT(Dart_IsString(ascii_str)); |
| 574 | 558 |
| 575 const char* null = NULL; | 559 const char* null = NULL; |
| 576 Dart_Handle null_str = Dart_NewString(null); | 560 Dart_Handle null_str = NewString(null); |
| 577 EXPECT(Dart_IsError(null_str)); | 561 EXPECT(Dart_IsError(null_str)); |
| 578 | 562 |
| 579 const char* utf8 = "\xE4\xBA\x8C"; // U+4E8C | 563 uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. |
| 580 Dart_Handle utf8_str = Dart_NewString(utf8); | 564 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); |
| 581 EXPECT_VALID(utf8_str); | 565 EXPECT_VALID(utf8_str); |
| 582 EXPECT(Dart_IsString(utf8_str)); | 566 EXPECT(Dart_IsString(utf8_str)); |
| 583 | 567 |
| 584 const char* invalid = "\xE4\xBA"; // underflow | 568 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. |
| 585 Dart_Handle invalid_str = Dart_NewString(invalid); | 569 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, |
| 570 ARRAY_SIZE(invalid)); |
| 586 EXPECT(Dart_IsError(invalid_str)); | 571 EXPECT(Dart_IsError(invalid_str)); |
| 587 } | 572 } |
| 588 | 573 |
| 589 | 574 |
| 590 TEST_CASE(ExternalStringGetPeer) { | 575 TEST_CASE(ExternalStringGetPeer) { |
| 591 Dart_Handle result; | 576 Dart_Handle result; |
| 592 | 577 |
| 593 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; | 578 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; |
| 594 int peer_data = 123; | 579 int peer_data = 123; |
| 595 void* peer = NULL; | 580 void* peer = NULL; |
| 596 | 581 |
| 597 // Success. | 582 // Success. |
| 598 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), | 583 Dart_Handle ext8 = Dart_NewExternalUTF8String(data8, ARRAY_SIZE(data8), |
| 599 &peer_data, NULL); | 584 &peer_data, NULL); |
| 600 EXPECT_VALID(ext8); | 585 EXPECT_VALID(ext8); |
| 601 | 586 |
| 602 result = Dart_ExternalStringGetPeer(ext8, &peer); | 587 result = Dart_ExternalStringGetPeer(ext8, &peer); |
| 603 EXPECT_VALID(result); | 588 EXPECT_VALID(result); |
| 604 EXPECT_EQ(&peer_data, peer); | 589 EXPECT_EQ(&peer_data, peer); |
| 605 | 590 |
| 606 // NULL peer. | 591 // NULL peer. |
| 607 result = Dart_ExternalStringGetPeer(ext8, NULL); | 592 result = Dart_ExternalStringGetPeer(ext8, NULL); |
| 608 EXPECT(Dart_IsError(result)); | 593 EXPECT(Dart_IsError(result)); |
| 609 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'peer' to be " | 594 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'peer' to be " |
| 610 "non-null.", Dart_GetError(result)); | 595 "non-null.", Dart_GetError(result)); |
| 611 | 596 |
| 612 // String is not external. | 597 // String is not external. |
| 613 peer = NULL; | 598 peer = NULL; |
| 614 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); | 599 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); |
| 615 EXPECT_VALID(str8); | 600 EXPECT_VALID(str8); |
| 616 result = Dart_ExternalStringGetPeer(str8, &peer); | 601 result = Dart_ExternalStringGetPeer(str8, &peer); |
| 617 EXPECT(Dart_IsError(result)); | 602 EXPECT(Dart_IsError(result)); |
| 618 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " | 603 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " |
| 619 "an external String.", Dart_GetError(result)); | 604 "an external String.", Dart_GetError(result)); |
| 620 EXPECT(peer == NULL); | 605 EXPECT(peer == NULL); |
| 621 | 606 |
| 622 // Not a String. | 607 // Not a String. |
| 623 peer = NULL; | 608 peer = NULL; |
| 624 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); | 609 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); |
| 625 EXPECT(Dart_IsError(result)); | 610 EXPECT(Dart_IsError(result)); |
| 626 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " | 611 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " |
| 627 "of type String.", Dart_GetError(result)); | 612 "of type String.", Dart_GetError(result)); |
| 628 EXPECT(peer == NULL); | 613 EXPECT(peer == NULL); |
| 629 } | 614 } |
| 630 | 615 |
| 631 | 616 |
| 632 // Only ia32 and x64 can run execution tests. | 617 // Only ia32 and x64 can run execution tests. |
| 633 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 618 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 634 | 619 |
| 635 static void ExternalStringCallbackFinalizer(void* peer) { | 620 static void ExternalStringCallbackFinalizer(void* peer) { |
| 636 *static_cast<int*>(peer) *= 2; | 621 *static_cast<int*>(peer) *= 2; |
| 637 } | 622 } |
| 638 | 623 |
| 639 | 624 |
| 640 TEST_CASE(ExternalStringCallback) { | 625 TEST_CASE(ExternalStringCallback) { |
| 641 int peer8 = 40; | 626 int peer8 = 40; |
| 642 int peer16 = 41; | 627 int peer16 = 41; |
| 643 int peer32 = 42; | |
| 644 | 628 |
| 645 { | 629 { |
| 646 Dart_EnterScope(); | 630 Dart_EnterScope(); |
| 647 | 631 |
| 648 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; | 632 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; |
| 649 Dart_Handle obj8 = Dart_NewExternalString8( | 633 Dart_Handle obj8 = Dart_NewExternalUTF8String( |
| 650 data8, | 634 data8, |
| 651 ARRAY_SIZE(data8), | 635 ARRAY_SIZE(data8), |
| 652 &peer8, | 636 &peer8, |
| 653 ExternalStringCallbackFinalizer); | 637 ExternalStringCallbackFinalizer); |
| 654 EXPECT_VALID(obj8); | 638 EXPECT_VALID(obj8); |
| 655 void* api_peer8 = NULL; | 639 void* api_peer8 = NULL; |
| 656 EXPECT_VALID(Dart_ExternalStringGetPeer(obj8, &api_peer8)); | 640 EXPECT_VALID(Dart_ExternalStringGetPeer(obj8, &api_peer8)); |
| 657 EXPECT_EQ(api_peer8, &peer8); | 641 EXPECT_EQ(api_peer8, &peer8); |
| 658 | 642 |
| 659 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' }; | 643 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' }; |
| 660 Dart_Handle obj16 = Dart_NewExternalString16( | 644 Dart_Handle obj16 = Dart_NewExternalUTF16String( |
| 661 data16, | 645 data16, |
| 662 ARRAY_SIZE(data16), | 646 ARRAY_SIZE(data16), |
| 663 &peer16, | 647 &peer16, |
| 664 ExternalStringCallbackFinalizer); | 648 ExternalStringCallbackFinalizer); |
| 665 EXPECT_VALID(obj16); | 649 EXPECT_VALID(obj16); |
| 666 void* api_peer16 = NULL; | 650 void* api_peer16 = NULL; |
| 667 EXPECT_VALID(Dart_ExternalStringGetPeer(obj16, &api_peer16)); | 651 EXPECT_VALID(Dart_ExternalStringGetPeer(obj16, &api_peer16)); |
| 668 EXPECT_EQ(api_peer16, &peer16); | 652 EXPECT_EQ(api_peer16, &peer16); |
| 669 | 653 |
| 670 uint32_t data32[] = { 'h', 'e', 'l', 'l', 'o' }; | |
| 671 Dart_Handle obj32 = Dart_NewExternalString32( | |
| 672 data32, | |
| 673 ARRAY_SIZE(data32), | |
| 674 &peer32, | |
| 675 ExternalStringCallbackFinalizer); | |
| 676 EXPECT_VALID(obj32); | |
| 677 void* api_peer32 = NULL; | |
| 678 EXPECT_VALID(Dart_ExternalStringGetPeer(obj32, &api_peer32)); | |
| 679 EXPECT_EQ(api_peer32, &peer32); | |
| 680 | |
| 681 Dart_ExitScope(); | 654 Dart_ExitScope(); |
| 682 } | 655 } |
| 683 | 656 |
| 684 EXPECT_EQ(40, peer8); | 657 EXPECT_EQ(40, peer8); |
| 685 EXPECT_EQ(41, peer16); | 658 EXPECT_EQ(41, peer16); |
| 686 EXPECT_EQ(42, peer32); | |
| 687 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 659 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 688 EXPECT_EQ(40, peer8); | 660 EXPECT_EQ(40, peer8); |
| 689 EXPECT_EQ(41, peer16); | 661 EXPECT_EQ(41, peer16); |
| 690 EXPECT_EQ(42, peer32); | |
| 691 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 662 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 692 EXPECT_EQ(80, peer8); | 663 EXPECT_EQ(80, peer8); |
| 693 EXPECT_EQ(82, peer16); | 664 EXPECT_EQ(82, peer16); |
| 694 EXPECT_EQ(84, peer32); | |
| 695 } | 665 } |
| 696 | 666 |
| 697 | 667 |
| 698 TEST_CASE(ListAccess) { | 668 TEST_CASE(ListAccess) { |
| 699 const char* kScriptChars = | 669 const char* kScriptChars = |
| 700 "List testMain() {" | 670 "List testMain() {" |
| 701 " List a = new List();" | 671 " List a = new List();" |
| 702 " a.add(10);" | 672 " a.add(10);" |
| 703 " a.add(20);" | 673 " a.add(20);" |
| 704 " a.add(30);" | 674 " a.add(30);" |
| 705 " return a;" | 675 " return a;" |
| 706 "}"; | 676 "}"; |
| 707 Dart_Handle result; | 677 Dart_Handle result; |
| 708 | 678 |
| 709 // Create a test library and Load up a test script in it. | 679 // Create a test library and Load up a test script in it. |
| 710 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 680 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 711 | 681 |
| 712 // Invoke a function which returns an object of type List. | 682 // Invoke a function which returns an object of type List. |
| 713 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 683 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 714 EXPECT_VALID(result); | 684 EXPECT_VALID(result); |
| 715 | 685 |
| 716 // First ensure that the returned object is an array. | 686 // First ensure that the returned object is an array. |
| 717 Dart_Handle ListAccessTestObj = result; | 687 Dart_Handle ListAccessTestObj = result; |
| 718 | 688 |
| 719 EXPECT(Dart_IsList(ListAccessTestObj)); | 689 EXPECT(Dart_IsList(ListAccessTestObj)); |
| 720 | 690 |
| 721 // Get length of array object. | 691 // Get length of array object. |
| 722 intptr_t len = 0; | 692 intptr_t len = 0; |
| 723 result = Dart_ListLength(ListAccessTestObj, &len); | 693 result = Dart_ListLength(ListAccessTestObj, &len); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 Dart_Handle weak_new_ref = Dart_Null(); | 1290 Dart_Handle weak_new_ref = Dart_Null(); |
| 1321 EXPECT(Dart_IsNull(weak_new_ref)); | 1291 EXPECT(Dart_IsNull(weak_new_ref)); |
| 1322 | 1292 |
| 1323 Dart_Handle weak_old_ref = Dart_Null(); | 1293 Dart_Handle weak_old_ref = Dart_Null(); |
| 1324 EXPECT(Dart_IsNull(weak_old_ref)); | 1294 EXPECT(Dart_IsNull(weak_old_ref)); |
| 1325 | 1295 |
| 1326 { | 1296 { |
| 1327 Dart_EnterScope(); | 1297 Dart_EnterScope(); |
| 1328 | 1298 |
| 1329 // Create an object in new space. | 1299 // Create an object in new space. |
| 1330 Dart_Handle new_ref = Dart_NewString("new string"); | 1300 Dart_Handle new_ref = NewString("new string"); |
| 1331 EXPECT_VALID(new_ref); | 1301 EXPECT_VALID(new_ref); |
| 1332 | 1302 |
| 1333 // Create an object in old space. | 1303 // Create an object in old space. |
| 1334 Dart_Handle old_ref; | 1304 Dart_Handle old_ref; |
| 1335 { | 1305 { |
| 1336 Isolate* isolate = Isolate::Current(); | 1306 Isolate* isolate = Isolate::Current(); |
| 1337 DARTSCOPE(isolate); | 1307 DARTSCOPE(isolate); |
| 1338 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); | 1308 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); |
| 1339 EXPECT_VALID(old_ref); | 1309 EXPECT_VALID(old_ref); |
| 1340 } | 1310 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 *static_cast<int*>(peer) = 42; | 1388 *static_cast<int*>(peer) = 42; |
| 1419 } | 1389 } |
| 1420 | 1390 |
| 1421 | 1391 |
| 1422 TEST_CASE(WeakPersistentHandleCallback) { | 1392 TEST_CASE(WeakPersistentHandleCallback) { |
| 1423 Dart_Handle weak_ref = Dart_Null(); | 1393 Dart_Handle weak_ref = Dart_Null(); |
| 1424 EXPECT(Dart_IsNull(weak_ref)); | 1394 EXPECT(Dart_IsNull(weak_ref)); |
| 1425 int peer = 0; | 1395 int peer = 0; |
| 1426 { | 1396 { |
| 1427 Dart_EnterScope(); | 1397 Dart_EnterScope(); |
| 1428 Dart_Handle obj = Dart_NewString("new string"); | 1398 Dart_Handle obj = NewString("new string"); |
| 1429 EXPECT_VALID(obj); | 1399 EXPECT_VALID(obj); |
| 1430 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, | 1400 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, |
| 1431 WeakPersistentHandlePeerFinalizer); | 1401 WeakPersistentHandlePeerFinalizer); |
| 1432 Dart_ExitScope(); | 1402 Dart_ExitScope(); |
| 1433 } | 1403 } |
| 1434 EXPECT_VALID(weak_ref); | 1404 EXPECT_VALID(weak_ref); |
| 1435 EXPECT(peer == 0); | 1405 EXPECT(peer == 0); |
| 1436 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1406 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1437 EXPECT(peer == 0); | 1407 EXPECT(peer == 0); |
| 1438 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 1408 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1439 EXPECT(peer == 42); | 1409 EXPECT(peer == 42); |
| 1440 Dart_DeletePersistentHandle(weak_ref); | 1410 Dart_DeletePersistentHandle(weak_ref); |
| 1441 } | 1411 } |
| 1442 | 1412 |
| 1443 | 1413 |
| 1444 TEST_CASE(WeakPersistentHandleNoCallback) { | 1414 TEST_CASE(WeakPersistentHandleNoCallback) { |
| 1445 Dart_Handle weak_ref = Dart_Null(); | 1415 Dart_Handle weak_ref = Dart_Null(); |
| 1446 EXPECT(Dart_IsNull(weak_ref)); | 1416 EXPECT(Dart_IsNull(weak_ref)); |
| 1447 int peer = 0; | 1417 int peer = 0; |
| 1448 { | 1418 { |
| 1449 Dart_EnterScope(); | 1419 Dart_EnterScope(); |
| 1450 Dart_Handle obj = Dart_NewString("new string"); | 1420 Dart_Handle obj = NewString("new string"); |
| 1451 EXPECT_VALID(obj); | 1421 EXPECT_VALID(obj); |
| 1452 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, | 1422 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, |
| 1453 WeakPersistentHandlePeerFinalizer); | 1423 WeakPersistentHandlePeerFinalizer); |
| 1454 Dart_ExitScope(); | 1424 Dart_ExitScope(); |
| 1455 } | 1425 } |
| 1456 // A finalizer is not invoked on a deleted handle. Therefore, the | 1426 // A finalizer is not invoked on a deleted handle. Therefore, the |
| 1457 // peer value should not change after the referent is collected. | 1427 // peer value should not change after the referent is collected. |
| 1458 Dart_DeletePersistentHandle(weak_ref); | 1428 Dart_DeletePersistentHandle(weak_ref); |
| 1459 EXPECT_VALID(weak_ref); | 1429 EXPECT_VALID(weak_ref); |
| 1460 EXPECT(peer == 0); | 1430 EXPECT(peer == 0); |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2357 | 2327 |
| 2358 TEST_CASE(ClassBasics) { | 2328 TEST_CASE(ClassBasics) { |
| 2359 const char* kScriptChars = | 2329 const char* kScriptChars = |
| 2360 "class MyClass {\n" | 2330 "class MyClass {\n" |
| 2361 "}\n" | 2331 "}\n" |
| 2362 "class MyDefault {\n" | 2332 "class MyDefault {\n" |
| 2363 "}\n" | 2333 "}\n" |
| 2364 "interface MyInterface default MyDefault {\n" | 2334 "interface MyInterface default MyDefault {\n" |
| 2365 "}\n"; | 2335 "}\n"; |
| 2366 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2336 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2367 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); | 2337 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); |
| 2368 Dart_Handle interface = Dart_GetClass(lib, Dart_NewString("MyInterface")); | 2338 Dart_Handle interface = Dart_GetClass(lib, NewString("MyInterface")); |
| 2369 | 2339 |
| 2370 // Test Dart_IsClass and Dart_IsInterface. | 2340 // Test Dart_IsClass and Dart_IsInterface. |
| 2371 EXPECT(Dart_IsClass(cls)); | 2341 EXPECT(Dart_IsClass(cls)); |
| 2372 EXPECT(!Dart_IsClass(interface)); | 2342 EXPECT(!Dart_IsClass(interface)); |
| 2373 EXPECT(!Dart_IsClass(Dart_True())); | 2343 EXPECT(!Dart_IsClass(Dart_True())); |
| 2374 | 2344 |
| 2375 EXPECT(!Dart_IsInterface(cls)); | 2345 EXPECT(!Dart_IsInterface(cls)); |
| 2376 EXPECT(Dart_IsInterface(interface)); | 2346 EXPECT(Dart_IsInterface(interface)); |
| 2377 EXPECT(!Dart_IsInterface(Dart_True())); | 2347 EXPECT(!Dart_IsInterface(Dart_True())); |
| 2378 | 2348 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2427 EXPECT_ERROR(Dart_ClassGetDefault(Dart_NewApiError("MyError")), "MyError"); | 2397 EXPECT_ERROR(Dart_ClassGetDefault(Dart_NewApiError("MyError")), "MyError"); |
| 2428 } | 2398 } |
| 2429 | 2399 |
| 2430 TEST_CASE(ClassTypedefsEtc) { | 2400 TEST_CASE(ClassTypedefsEtc) { |
| 2431 const char* kScriptChars = | 2401 const char* kScriptChars = |
| 2432 "class SomeClass {\n" | 2402 "class SomeClass {\n" |
| 2433 "}\n" | 2403 "}\n" |
| 2434 "typedef void SomeHandler(String a);\n"; | 2404 "typedef void SomeHandler(String a);\n"; |
| 2435 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2405 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2436 EXPECT_VALID(lib); | 2406 EXPECT_VALID(lib); |
| 2437 Dart_Handle normal_cls = Dart_GetClass(lib, Dart_NewString("SomeClass")); | 2407 Dart_Handle normal_cls = Dart_GetClass(lib, NewString("SomeClass")); |
| 2438 EXPECT_VALID(normal_cls); | 2408 EXPECT_VALID(normal_cls); |
| 2439 Dart_Handle typedef_cls = Dart_GetClass(lib, Dart_NewString("SomeHandler")); | 2409 Dart_Handle typedef_cls = Dart_GetClass(lib, NewString("SomeHandler")); |
| 2440 EXPECT_VALID(typedef_cls); | 2410 EXPECT_VALID(typedef_cls); |
| 2441 | 2411 |
| 2442 EXPECT(Dart_IsClass(normal_cls)); | 2412 EXPECT(Dart_IsClass(normal_cls)); |
| 2443 EXPECT(!Dart_ClassIsTypedef(normal_cls)); | 2413 EXPECT(!Dart_ClassIsTypedef(normal_cls)); |
| 2444 EXPECT(!Dart_ClassIsFunctionType(normal_cls)); | 2414 EXPECT(!Dart_ClassIsFunctionType(normal_cls)); |
| 2445 | 2415 |
| 2446 EXPECT(Dart_IsClass(typedef_cls)); | 2416 EXPECT(Dart_IsClass(typedef_cls)); |
| 2447 EXPECT(Dart_ClassIsTypedef(typedef_cls)); | 2417 EXPECT(Dart_ClassIsTypedef(typedef_cls)); |
| 2448 EXPECT(!Dart_ClassIsFunctionType(typedef_cls)); | 2418 EXPECT(!Dart_ClassIsFunctionType(typedef_cls)); |
| 2449 | 2419 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2499 "class MyClass2 implements MyInterface0, MyInterface1 {\n" | 2469 "class MyClass2 implements MyInterface0, MyInterface1 {\n" |
| 2500 "}\n" | 2470 "}\n" |
| 2501 "\n" | 2471 "\n" |
| 2502 "interface MyInterface0 {\n" | 2472 "interface MyInterface0 {\n" |
| 2503 "}\n" | 2473 "}\n" |
| 2504 "\n" | 2474 "\n" |
| 2505 "interface MyInterface1 extends MyInterface0 {\n" | 2475 "interface MyInterface1 extends MyInterface0 {\n" |
| 2506 "}\n"; | 2476 "}\n"; |
| 2507 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2477 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2508 | 2478 |
| 2509 Dart_Handle cls0 = Dart_GetClass(lib, Dart_NewString("MyClass0")); | 2479 Dart_Handle cls0 = Dart_GetClass(lib, NewString("MyClass0")); |
| 2510 Dart_Handle cls1 = Dart_GetClass(lib, Dart_NewString("MyClass1")); | 2480 Dart_Handle cls1 = Dart_GetClass(lib, NewString("MyClass1")); |
| 2511 Dart_Handle cls2 = Dart_GetClass(lib, Dart_NewString("MyClass2")); | 2481 Dart_Handle cls2 = Dart_GetClass(lib, NewString("MyClass2")); |
| 2512 Dart_Handle intf0 = Dart_GetClass(lib, Dart_NewString("MyInterface0")); | 2482 Dart_Handle intf0 = Dart_GetClass(lib, NewString("MyInterface0")); |
| 2513 Dart_Handle intf1 = Dart_GetClass(lib, Dart_NewString("MyInterface1")); | 2483 Dart_Handle intf1 = Dart_GetClass(lib, NewString("MyInterface1")); |
| 2514 | 2484 |
| 2515 intptr_t len = -1; | 2485 intptr_t len = -1; |
| 2516 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len)); | 2486 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len)); |
| 2517 EXPECT_EQ(0, len); | 2487 EXPECT_EQ(0, len); |
| 2518 | 2488 |
| 2519 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls0, 0), | 2489 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls0, 0), |
| 2520 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); | 2490 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); |
| 2521 | 2491 |
| 2522 len = -1; | 2492 len = -1; |
| 2523 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls1, &len)); | 2493 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls1, &len)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2567 const char* value = ""; | 2537 const char* value = ""; |
| 2568 EXPECT_VALID(Dart_StringToCString(result, &value)); | 2538 EXPECT_VALID(Dart_StringToCString(result, &value)); |
| 2569 EXPECT_STREQ(initial_value, value); | 2539 EXPECT_STREQ(initial_value, value); |
| 2570 | 2540 |
| 2571 // Use a unique expected value. | 2541 // Use a unique expected value. |
| 2572 static int counter = 0; | 2542 static int counter = 0; |
| 2573 char buffer[256]; | 2543 char buffer[256]; |
| 2574 OS::SNPrint(buffer, 256, "Expected%d", ++counter); | 2544 OS::SNPrint(buffer, 256, "Expected%d", ++counter); |
| 2575 | 2545 |
| 2576 // Try to change the field value. | 2546 // Try to change the field value. |
| 2577 result = Dart_SetField(container, name, Dart_NewString(buffer)); | 2547 result = Dart_SetField(container, name, NewString(buffer)); |
| 2578 if (final) { | 2548 if (final) { |
| 2579 EXPECT(Dart_IsError(result)); | 2549 EXPECT(Dart_IsError(result)); |
| 2580 } else { | 2550 } else { |
| 2581 EXPECT_VALID(result); | 2551 EXPECT_VALID(result); |
| 2582 } | 2552 } |
| 2583 | 2553 |
| 2584 // Make sure we have the right final value. | 2554 // Make sure we have the right final value. |
| 2585 result = Dart_GetField(container, name); | 2555 result = Dart_GetField(container, name); |
| 2586 EXPECT_VALID(result); | 2556 EXPECT_VALID(result); |
| 2587 EXPECT_VALID(Dart_StringToCString(result, &value)); | 2557 EXPECT_VALID(Dart_StringToCString(result, &value)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2680 "void set _imported_getset_fld(var value) { _gs_fld2 = value; }\n" | 2650 "void set _imported_getset_fld(var value) { _gs_fld2 = value; }\n" |
| 2681 "var _gs_fld1;\n" | 2651 "var _gs_fld1;\n" |
| 2682 "var _gs_fld2;\n" | 2652 "var _gs_fld2;\n" |
| 2683 "void test2() {\n" | 2653 "void test2() {\n" |
| 2684 " imported_getset_fld = 'imported getset';\n" | 2654 " imported_getset_fld = 'imported getset';\n" |
| 2685 " _imported_getset_fld = 'hidden imported getset';\n" | 2655 " _imported_getset_fld = 'hidden imported getset';\n" |
| 2686 "}\n"; | 2656 "}\n"; |
| 2687 | 2657 |
| 2688 // Shared setup. | 2658 // Shared setup. |
| 2689 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2659 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2690 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); | 2660 Dart_Handle cls = Dart_GetClass(lib, NewString("Fields")); |
| 2691 EXPECT_VALID(cls); | 2661 EXPECT_VALID(cls); |
| 2692 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); | 2662 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); |
| 2693 EXPECT_VALID(instance); | 2663 EXPECT_VALID(instance); |
| 2694 Dart_Handle name; | 2664 Dart_Handle name; |
| 2695 | 2665 |
| 2696 // Load imported lib. | 2666 // Load imported lib. |
| 2697 Dart_Handle url = Dart_NewString("library_url"); | 2667 Dart_Handle url = NewString("library_url"); |
| 2698 Dart_Handle source = Dart_NewString(kImportedScriptChars); | 2668 Dart_Handle source = NewString(kImportedScriptChars); |
| 2699 Dart_Handle imported_lib = Dart_LoadLibrary(url, source); | 2669 Dart_Handle imported_lib = Dart_LoadLibrary(url, source); |
| 2700 Dart_Handle prefix = Dart_NewString(""); | 2670 Dart_Handle prefix = NewString(""); |
| 2701 EXPECT_VALID(imported_lib); | 2671 EXPECT_VALID(imported_lib); |
| 2702 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); | 2672 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); |
| 2703 EXPECT_VALID(result); | 2673 EXPECT_VALID(result); |
| 2704 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); | 2674 result = Dart_Invoke(imported_lib, NewString("test2"), 0, NULL); |
| 2705 EXPECT_VALID(result); | 2675 EXPECT_VALID(result); |
| 2706 | 2676 |
| 2707 // Instance field. | 2677 // Instance field. |
| 2708 name = Dart_NewString("instance_fld"); | 2678 name = NewString("instance_fld"); |
| 2709 TestFieldNotFound(lib, name); | 2679 TestFieldNotFound(lib, name); |
| 2710 TestFieldNotFound(cls, name); | 2680 TestFieldNotFound(cls, name); |
| 2711 TestFieldOk(instance, name, false, "instance"); | 2681 TestFieldOk(instance, name, false, "instance"); |
| 2712 | 2682 |
| 2713 // Hidden instance field. | 2683 // Hidden instance field. |
| 2714 name = Dart_NewString("_instance_fld"); | 2684 name = NewString("_instance_fld"); |
| 2715 TestFieldNotFound(lib, name); | 2685 TestFieldNotFound(lib, name); |
| 2716 TestFieldNotFound(cls, name); | 2686 TestFieldNotFound(cls, name); |
| 2717 TestFieldOk(instance, name, false, "hidden instance"); | 2687 TestFieldOk(instance, name, false, "hidden instance"); |
| 2718 | 2688 |
| 2719 // Final instance field. | 2689 // Final instance field. |
| 2720 name = Dart_NewString("final_instance_fld"); | 2690 name = NewString("final_instance_fld"); |
| 2721 TestFieldNotFound(lib, name); | 2691 TestFieldNotFound(lib, name); |
| 2722 TestFieldNotFound(cls, name); | 2692 TestFieldNotFound(cls, name); |
| 2723 TestFieldOk(instance, name, true, "final instance"); | 2693 TestFieldOk(instance, name, true, "final instance"); |
| 2724 | 2694 |
| 2725 // Hidden final instance field. | 2695 // Hidden final instance field. |
| 2726 name = Dart_NewString("_final_instance_fld"); | 2696 name = NewString("_final_instance_fld"); |
| 2727 TestFieldNotFound(lib, name); | 2697 TestFieldNotFound(lib, name); |
| 2728 TestFieldNotFound(cls, name); | 2698 TestFieldNotFound(cls, name); |
| 2729 TestFieldOk(instance, name, true, "hidden final instance"); | 2699 TestFieldOk(instance, name, true, "hidden final instance"); |
| 2730 | 2700 |
| 2731 // Inherited field. | 2701 // Inherited field. |
| 2732 name = Dart_NewString("inherited_fld"); | 2702 name = NewString("inherited_fld"); |
| 2733 TestFieldNotFound(lib, name); | 2703 TestFieldNotFound(lib, name); |
| 2734 TestFieldNotFound(cls, name); | 2704 TestFieldNotFound(cls, name); |
| 2735 TestFieldOk(instance, name, false, "inherited"); | 2705 TestFieldOk(instance, name, false, "inherited"); |
| 2736 | 2706 |
| 2737 // Instance get/set field. | 2707 // Instance get/set field. |
| 2738 name = Dart_NewString("instance_getset_fld"); | 2708 name = NewString("instance_getset_fld"); |
| 2739 TestFieldNotFound(lib, name); | 2709 TestFieldNotFound(lib, name); |
| 2740 TestFieldNotFound(cls, name); | 2710 TestFieldNotFound(cls, name); |
| 2741 TestFieldOk(instance, name, false, "instance getset"); | 2711 TestFieldOk(instance, name, false, "instance getset"); |
| 2742 | 2712 |
| 2743 // Hidden instance get/set field. | 2713 // Hidden instance get/set field. |
| 2744 name = Dart_NewString("_instance_getset_fld"); | 2714 name = NewString("_instance_getset_fld"); |
| 2745 TestFieldNotFound(lib, name); | 2715 TestFieldNotFound(lib, name); |
| 2746 TestFieldNotFound(cls, name); | 2716 TestFieldNotFound(cls, name); |
| 2747 TestFieldOk(instance, name, false, "hidden instance getset"); | 2717 TestFieldOk(instance, name, false, "hidden instance getset"); |
| 2748 | 2718 |
| 2749 // Static field. | 2719 // Static field. |
| 2750 name = Dart_NewString("static_fld"); | 2720 name = NewString("static_fld"); |
| 2751 TestFieldNotFound(lib, name); | 2721 TestFieldNotFound(lib, name); |
| 2752 TestFieldNotFound(instance, name); | 2722 TestFieldNotFound(instance, name); |
| 2753 TestFieldOk(cls, name, false, "static"); | 2723 TestFieldOk(cls, name, false, "static"); |
| 2754 | 2724 |
| 2755 // Hidden static field. | 2725 // Hidden static field. |
| 2756 name = Dart_NewString("_static_fld"); | 2726 name = NewString("_static_fld"); |
| 2757 TestFieldNotFound(lib, name); | 2727 TestFieldNotFound(lib, name); |
| 2758 TestFieldNotFound(instance, name); | 2728 TestFieldNotFound(instance, name); |
| 2759 TestFieldOk(cls, name, false, "hidden static"); | 2729 TestFieldOk(cls, name, false, "hidden static"); |
| 2760 | 2730 |
| 2761 // Static final field. | 2731 // Static final field. |
| 2762 name = Dart_NewString("const_static_fld"); | 2732 name = NewString("const_static_fld"); |
| 2763 TestFieldNotFound(lib, name); | 2733 TestFieldNotFound(lib, name); |
| 2764 TestFieldNotFound(instance, name); | 2734 TestFieldNotFound(instance, name); |
| 2765 TestFieldOk(cls, name, true, "const static"); | 2735 TestFieldOk(cls, name, true, "const static"); |
| 2766 | 2736 |
| 2767 // Hidden static const field. | 2737 // Hidden static const field. |
| 2768 name = Dart_NewString("_const_static_fld"); | 2738 name = NewString("_const_static_fld"); |
| 2769 TestFieldNotFound(lib, name); | 2739 TestFieldNotFound(lib, name); |
| 2770 TestFieldNotFound(instance, name); | 2740 TestFieldNotFound(instance, name); |
| 2771 TestFieldOk(cls, name, true, "hidden const static"); | 2741 TestFieldOk(cls, name, true, "hidden const static"); |
| 2772 | 2742 |
| 2773 // Static non-inherited field. Not found at any level. | 2743 // Static non-inherited field. Not found at any level. |
| 2774 name = Dart_NewString("non_inherited_fld"); | 2744 name = NewString("non_inherited_fld"); |
| 2775 TestFieldNotFound(lib, name); | 2745 TestFieldNotFound(lib, name); |
| 2776 TestFieldNotFound(instance, name); | 2746 TestFieldNotFound(instance, name); |
| 2777 TestFieldNotFound(cls, name); | 2747 TestFieldNotFound(cls, name); |
| 2778 | 2748 |
| 2779 // Static get/set field. | 2749 // Static get/set field. |
| 2780 name = Dart_NewString("static_getset_fld"); | 2750 name = NewString("static_getset_fld"); |
| 2781 TestFieldNotFound(lib, name); | 2751 TestFieldNotFound(lib, name); |
| 2782 TestFieldNotFound(instance, name); | 2752 TestFieldNotFound(instance, name); |
| 2783 TestFieldOk(cls, name, false, "static getset"); | 2753 TestFieldOk(cls, name, false, "static getset"); |
| 2784 | 2754 |
| 2785 // Hidden static get/set field. | 2755 // Hidden static get/set field. |
| 2786 name = Dart_NewString("_static_getset_fld"); | 2756 name = NewString("_static_getset_fld"); |
| 2787 TestFieldNotFound(lib, name); | 2757 TestFieldNotFound(lib, name); |
| 2788 TestFieldNotFound(instance, name); | 2758 TestFieldNotFound(instance, name); |
| 2789 TestFieldOk(cls, name, false, "hidden static getset"); | 2759 TestFieldOk(cls, name, false, "hidden static getset"); |
| 2790 | 2760 |
| 2791 // Top-Level field. | 2761 // Top-Level field. |
| 2792 name = Dart_NewString("top_fld"); | 2762 name = NewString("top_fld"); |
| 2793 TestFieldNotFound(cls, name); | 2763 TestFieldNotFound(cls, name); |
| 2794 TestFieldNotFound(instance, name); | 2764 TestFieldNotFound(instance, name); |
| 2795 TestFieldOk(lib, name, false, "top"); | 2765 TestFieldOk(lib, name, false, "top"); |
| 2796 | 2766 |
| 2797 // Hidden top-level field. | 2767 // Hidden top-level field. |
| 2798 name = Dart_NewString("_top_fld"); | 2768 name = NewString("_top_fld"); |
| 2799 TestFieldNotFound(cls, name); | 2769 TestFieldNotFound(cls, name); |
| 2800 TestFieldNotFound(instance, name); | 2770 TestFieldNotFound(instance, name); |
| 2801 TestFieldOk(lib, name, false, "hidden top"); | 2771 TestFieldOk(lib, name, false, "hidden top"); |
| 2802 | 2772 |
| 2803 // Top-Level final field. | 2773 // Top-Level final field. |
| 2804 name = Dart_NewString("const_top_fld"); | 2774 name = NewString("const_top_fld"); |
| 2805 TestFieldNotFound(cls, name); | 2775 TestFieldNotFound(cls, name); |
| 2806 TestFieldNotFound(instance, name); | 2776 TestFieldNotFound(instance, name); |
| 2807 TestFieldOk(lib, name, true, "const top"); | 2777 TestFieldOk(lib, name, true, "const top"); |
| 2808 | 2778 |
| 2809 // Hidden top-level final field. | 2779 // Hidden top-level final field. |
| 2810 name = Dart_NewString("_const_top_fld"); | 2780 name = NewString("_const_top_fld"); |
| 2811 TestFieldNotFound(cls, name); | 2781 TestFieldNotFound(cls, name); |
| 2812 TestFieldNotFound(instance, name); | 2782 TestFieldNotFound(instance, name); |
| 2813 TestFieldOk(lib, name, true, "hidden const top"); | 2783 TestFieldOk(lib, name, true, "hidden const top"); |
| 2814 | 2784 |
| 2815 // Top-Level get/set field. | 2785 // Top-Level get/set field. |
| 2816 name = Dart_NewString("top_getset_fld"); | 2786 name = NewString("top_getset_fld"); |
| 2817 TestFieldNotFound(cls, name); | 2787 TestFieldNotFound(cls, name); |
| 2818 TestFieldNotFound(instance, name); | 2788 TestFieldNotFound(instance, name); |
| 2819 TestFieldOk(lib, name, false, "top getset"); | 2789 TestFieldOk(lib, name, false, "top getset"); |
| 2820 | 2790 |
| 2821 // Hidden top-level get/set field. | 2791 // Hidden top-level get/set field. |
| 2822 name = Dart_NewString("_top_getset_fld"); | 2792 name = NewString("_top_getset_fld"); |
| 2823 TestFieldNotFound(cls, name); | 2793 TestFieldNotFound(cls, name); |
| 2824 TestFieldNotFound(instance, name); | 2794 TestFieldNotFound(instance, name); |
| 2825 TestFieldOk(lib, name, false, "hidden top getset"); | 2795 TestFieldOk(lib, name, false, "hidden top getset"); |
| 2826 | 2796 |
| 2827 // Imported top-Level field. | 2797 // Imported top-Level field. |
| 2828 name = Dart_NewString("imported_fld"); | 2798 name = NewString("imported_fld"); |
| 2829 TestFieldNotFound(cls, name); | 2799 TestFieldNotFound(cls, name); |
| 2830 TestFieldNotFound(instance, name); | 2800 TestFieldNotFound(instance, name); |
| 2831 TestFieldOk(lib, name, false, "imported"); | 2801 TestFieldOk(lib, name, false, "imported"); |
| 2832 | 2802 |
| 2833 // Hidden imported top-level field. Not found at any level. | 2803 // Hidden imported top-level field. Not found at any level. |
| 2834 name = Dart_NewString("_imported_fld"); | 2804 name = NewString("_imported_fld"); |
| 2835 TestFieldNotFound(cls, name); | 2805 TestFieldNotFound(cls, name); |
| 2836 TestFieldNotFound(instance, name); | 2806 TestFieldNotFound(instance, name); |
| 2837 TestFieldNotFound(lib, name); | 2807 TestFieldNotFound(lib, name); |
| 2838 | 2808 |
| 2839 // Imported top-Level get/set field. | 2809 // Imported top-Level get/set field. |
| 2840 name = Dart_NewString("imported_getset_fld"); | 2810 name = NewString("imported_getset_fld"); |
| 2841 TestFieldNotFound(cls, name); | 2811 TestFieldNotFound(cls, name); |
| 2842 TestFieldNotFound(instance, name); | 2812 TestFieldNotFound(instance, name); |
| 2843 TestFieldOk(lib, name, false, "imported getset"); | 2813 TestFieldOk(lib, name, false, "imported getset"); |
| 2844 | 2814 |
| 2845 // Hidden imported top-level get/set field. Not found at any level. | 2815 // Hidden imported top-level get/set field. Not found at any level. |
| 2846 name = Dart_NewString("_imported_getset_fld"); | 2816 name = NewString("_imported_getset_fld"); |
| 2847 TestFieldNotFound(cls, name); | 2817 TestFieldNotFound(cls, name); |
| 2848 TestFieldNotFound(instance, name); | 2818 TestFieldNotFound(instance, name); |
| 2849 TestFieldNotFound(lib, name); | 2819 TestFieldNotFound(lib, name); |
| 2850 } | 2820 } |
| 2851 | 2821 |
| 2852 | 2822 |
| 2853 TEST_CASE(SetField_FunnyValue) { | 2823 TEST_CASE(SetField_FunnyValue) { |
| 2854 const char* kScriptChars = | 2824 const char* kScriptChars = |
| 2855 "var top;\n"; | 2825 "var top;\n"; |
| 2856 | 2826 |
| 2857 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2827 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2858 Dart_Handle name = Dart_NewString("top"); | 2828 Dart_Handle name = NewString("top"); |
| 2859 bool value; | 2829 bool value; |
| 2860 | 2830 |
| 2861 // Test that you can set the field to a good value. | 2831 // Test that you can set the field to a good value. |
| 2862 EXPECT_VALID(Dart_SetField(lib, name, Dart_True())); | 2832 EXPECT_VALID(Dart_SetField(lib, name, Dart_True())); |
| 2863 Dart_Handle result = Dart_GetField(lib, name); | 2833 Dart_Handle result = Dart_GetField(lib, name); |
| 2864 EXPECT_VALID(result); | 2834 EXPECT_VALID(result); |
| 2865 EXPECT(Dart_IsBoolean(result)); | 2835 EXPECT(Dart_IsBoolean(result)); |
| 2866 EXPECT_VALID(Dart_BooleanValue(result, &value)); | 2836 EXPECT_VALID(Dart_BooleanValue(result, &value)); |
| 2867 EXPECT(value); | 2837 EXPECT(value); |
| 2868 | 2838 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 | 2883 |
| 2914 const int kNumNativeFields = 4; | 2884 const int kNumNativeFields = 4; |
| 2915 | 2885 |
| 2916 // Create a test library. | 2886 // Create a test library. |
| 2917 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 2887 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
| 2918 native_field_lookup); | 2888 native_field_lookup); |
| 2919 | 2889 |
| 2920 // Create a native wrapper class with native fields. | 2890 // Create a native wrapper class with native fields. |
| 2921 result = Dart_CreateNativeWrapperClass( | 2891 result = Dart_CreateNativeWrapperClass( |
| 2922 lib, | 2892 lib, |
| 2923 Dart_NewString("NativeFieldsWrapper"), | 2893 NewString("NativeFieldsWrapper"), |
| 2924 kNumNativeFields); | 2894 kNumNativeFields); |
| 2925 | 2895 |
| 2926 // Load up a test script in the test library. | 2896 // Load up a test script in the test library. |
| 2927 | 2897 |
| 2928 // Invoke a function which returns an object of type NativeFields. | 2898 // Invoke a function which returns an object of type NativeFields. |
| 2929 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 2899 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 2930 EXPECT_VALID(result); | 2900 EXPECT_VALID(result); |
| 2931 DARTSCOPE_NOCHECKS(Isolate::Current()); | 2901 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 2932 Instance& obj = Instance::Handle(); | 2902 Instance& obj = Instance::Handle(); |
| 2933 obj ^= Api::UnwrapHandle(result); | 2903 obj ^= Api::UnwrapHandle(result); |
| 2934 const Class& cls = Class::Handle(obj.clazz()); | 2904 const Class& cls = Class::Handle(obj.clazz()); |
| 2935 // We expect the newly created "NativeFields" object to have | 2905 // We expect the newly created "NativeFields" object to have |
| 2936 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. | 2906 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. |
| 2937 // Hence the size of an instance of "NativeFields" should be | 2907 // Hence the size of an instance of "NativeFields" should be |
| 2938 // (kNumNativeFields + 2) * kWordSize + size of object header. | 2908 // (kNumNativeFields + 2) * kWordSize + size of object header. |
| 2939 // We check to make sure the instance size computed by the VM matches | 2909 // We check to make sure the instance size computed by the VM matches |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2956 "}\n" | 2926 "}\n" |
| 2957 "NativeFields testMain() {\n" | 2927 "NativeFields testMain() {\n" |
| 2958 " NativeFields obj = new NativeFields(10, 20);\n" | 2928 " NativeFields obj = new NativeFields(10, 20);\n" |
| 2959 " return obj;\n" | 2929 " return obj;\n" |
| 2960 "}\n"; | 2930 "}\n"; |
| 2961 Dart_Handle result; | 2931 Dart_Handle result; |
| 2962 // Create a test library and Load up a test script in it. | 2932 // Create a test library and Load up a test script in it. |
| 2963 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2933 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2964 | 2934 |
| 2965 // Invoke a function which returns an object of type NativeFields. | 2935 // Invoke a function which returns an object of type NativeFields. |
| 2966 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 2936 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 2967 | 2937 |
| 2968 // We expect this to fail as class "NativeFields" extends | 2938 // We expect this to fail as class "NativeFields" extends |
| 2969 // "NativeFieldsWrapper" and there is no definition of it either | 2939 // "NativeFieldsWrapper" and there is no definition of it either |
| 2970 // in the dart code or through the native field injection mechanism. | 2940 // in the dart code or through the native field injection mechanism. |
| 2971 EXPECT(Dart_IsError(result)); | 2941 EXPECT(Dart_IsError(result)); |
| 2972 } | 2942 } |
| 2973 | 2943 |
| 2974 | 2944 |
| 2975 TEST_CASE(InjectNativeFields3) { | 2945 TEST_CASE(InjectNativeFields3) { |
| 2976 const char* kScriptChars = | 2946 const char* kScriptChars = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2987 " return obj;\n" | 2957 " return obj;\n" |
| 2988 "}\n"; | 2958 "}\n"; |
| 2989 Dart_Handle result; | 2959 Dart_Handle result; |
| 2990 const int kNumNativeFields = 2; | 2960 const int kNumNativeFields = 2; |
| 2991 | 2961 |
| 2992 // Load up a test script in the test library. | 2962 // Load up a test script in the test library. |
| 2993 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 2963 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
| 2994 native_field_lookup); | 2964 native_field_lookup); |
| 2995 | 2965 |
| 2996 // Invoke a function which returns an object of type NativeFields. | 2966 // Invoke a function which returns an object of type NativeFields. |
| 2997 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 2967 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 2998 EXPECT_VALID(result); | 2968 EXPECT_VALID(result); |
| 2999 DARTSCOPE_NOCHECKS(Isolate::Current()); | 2969 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 3000 Instance& obj = Instance::Handle(); | 2970 Instance& obj = Instance::Handle(); |
| 3001 obj ^= Api::UnwrapHandle(result); | 2971 obj ^= Api::UnwrapHandle(result); |
| 3002 const Class& cls = Class::Handle(obj.clazz()); | 2972 const Class& cls = Class::Handle(obj.clazz()); |
| 3003 // We expect the newly created "NativeFields" object to have | 2973 // We expect the newly created "NativeFields" object to have |
| 3004 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. | 2974 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. |
| 3005 // Hence the size of an instance of "NativeFields" should be | 2975 // Hence the size of an instance of "NativeFields" should be |
| 3006 // (kNumNativeFields + 2) * kWordSize + size of object header. | 2976 // (kNumNativeFields + 2) * kWordSize + size of object header. |
| 3007 // We check to make sure the instance size computed by the VM matches | 2977 // We check to make sure the instance size computed by the VM matches |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3025 "}\n" | 2995 "}\n" |
| 3026 "NativeFields testMain() {\n" | 2996 "NativeFields testMain() {\n" |
| 3027 " NativeFields obj = new NativeFields(10, 20);\n" | 2997 " NativeFields obj = new NativeFields(10, 20);\n" |
| 3028 " return obj;\n" | 2998 " return obj;\n" |
| 3029 "}\n"; | 2999 "}\n"; |
| 3030 Dart_Handle result; | 3000 Dart_Handle result; |
| 3031 // Load up a test script in the test library. | 3001 // Load up a test script in the test library. |
| 3032 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3002 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3033 | 3003 |
| 3034 // Invoke a function which returns an object of type NativeFields. | 3004 // Invoke a function which returns an object of type NativeFields. |
| 3035 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 3005 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 3036 | 3006 |
| 3037 // We expect the test script to fail finalization with the error below: | 3007 // We expect the test script to fail finalization with the error below: |
| 3038 EXPECT(Dart_IsError(result)); | 3008 EXPECT(Dart_IsError(result)); |
| 3039 Dart_Handle expected_error = Dart_Error( | 3009 Dart_Handle expected_error = Dart_Error( |
| 3040 "'dart:test-lib': Error: line 1 pos 38: " | 3010 "'dart:test-lib': Error: line 1 pos 38: " |
| 3041 "class 'NativeFields' is trying to extend a native fields class, " | 3011 "class 'NativeFields' is trying to extend a native fields class, " |
| 3042 "but library '%s' has no native resolvers", | 3012 "but library '%s' has no native resolvers", |
| 3043 TestCase::url()); | 3013 TestCase::url()); |
| 3044 EXPECT_SUBSTRING(Dart_GetError(expected_error), Dart_GetError(result)); | 3014 EXPECT_SUBSTRING(Dart_GetError(expected_error), Dart_GetError(result)); |
| 3045 } | 3015 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3057 "}\n" | 3027 "}\n" |
| 3058 "int testMain() {\n" | 3028 "int testMain() {\n" |
| 3059 " NativeFields obj = new NativeFields();\n" | 3029 " NativeFields obj = new NativeFields();\n" |
| 3060 " return obj.fld();\n" | 3030 " return obj.fld();\n" |
| 3061 "}\n"; | 3031 "}\n"; |
| 3062 Dart_Handle result; | 3032 Dart_Handle result; |
| 3063 // Load up a test script in the test library. | 3033 // Load up a test script in the test library. |
| 3064 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); | 3034 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); |
| 3065 | 3035 |
| 3066 // Invoke a function which returns an object of type NativeFields. | 3036 // Invoke a function which returns an object of type NativeFields. |
| 3067 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 3037 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 3068 | 3038 |
| 3069 EXPECT_VALID(result); | 3039 EXPECT_VALID(result); |
| 3070 EXPECT(Dart_IsInteger(result)); | 3040 EXPECT(Dart_IsInteger(result)); |
| 3071 int64_t value = 0; | 3041 int64_t value = 0; |
| 3072 result = Dart_IntegerToInt64(result, &value); | 3042 result = Dart_IntegerToInt64(result, &value); |
| 3073 EXPECT_VALID(result); | 3043 EXPECT_VALID(result); |
| 3074 EXPECT_EQ(42, value); | 3044 EXPECT_EQ(42, value); |
| 3075 } | 3045 } |
| 3076 | 3046 |
| 3077 | 3047 |
| 3078 static void TestNativeFields(Dart_Handle retobj) { | 3048 static void TestNativeFields(Dart_Handle retobj) { |
| 3079 // Access and set various instance fields of the object. | 3049 // Access and set various instance fields of the object. |
| 3080 Dart_Handle result = Dart_GetField(retobj, Dart_NewString("fld3")); | 3050 Dart_Handle result = Dart_GetField(retobj, NewString("fld3")); |
| 3081 EXPECT(Dart_IsError(result)); | 3051 EXPECT(Dart_IsError(result)); |
| 3082 result = Dart_GetField(retobj, Dart_NewString("fld0")); | 3052 result = Dart_GetField(retobj, NewString("fld0")); |
| 3083 EXPECT_VALID(result); | 3053 EXPECT_VALID(result); |
| 3084 EXPECT(Dart_IsNull(result)); | 3054 EXPECT(Dart_IsNull(result)); |
| 3085 result = Dart_GetField(retobj, Dart_NewString("fld1")); | 3055 result = Dart_GetField(retobj, NewString("fld1")); |
| 3086 EXPECT_VALID(result); | 3056 EXPECT_VALID(result); |
| 3087 int64_t value = 0; | 3057 int64_t value = 0; |
| 3088 result = Dart_IntegerToInt64(result, &value); | 3058 result = Dart_IntegerToInt64(result, &value); |
| 3089 EXPECT_EQ(10, value); | 3059 EXPECT_EQ(10, value); |
| 3090 result = Dart_GetField(retobj, Dart_NewString("fld2")); | 3060 result = Dart_GetField(retobj, NewString("fld2")); |
| 3091 EXPECT_VALID(result); | 3061 EXPECT_VALID(result); |
| 3092 result = Dart_IntegerToInt64(result, &value); | 3062 result = Dart_IntegerToInt64(result, &value); |
| 3093 EXPECT_EQ(20, value); | 3063 EXPECT_EQ(20, value); |
| 3094 result = Dart_SetField(retobj, | 3064 result = Dart_SetField(retobj, |
| 3095 Dart_NewString("fld2"), | 3065 NewString("fld2"), |
| 3096 Dart_NewInteger(40)); | 3066 Dart_NewInteger(40)); |
| 3097 EXPECT(Dart_IsError(result)); | 3067 EXPECT(Dart_IsError(result)); |
| 3098 result = Dart_SetField(retobj, | 3068 result = Dart_SetField(retobj, |
| 3099 Dart_NewString("fld1"), | 3069 NewString("fld1"), |
| 3100 Dart_NewInteger(40)); | 3070 Dart_NewInteger(40)); |
| 3101 EXPECT_VALID(result); | 3071 EXPECT_VALID(result); |
| 3102 result = Dart_GetField(retobj, Dart_NewString("fld1")); | 3072 result = Dart_GetField(retobj, NewString("fld1")); |
| 3103 EXPECT_VALID(result); | 3073 EXPECT_VALID(result); |
| 3104 result = Dart_IntegerToInt64(result, &value); | 3074 result = Dart_IntegerToInt64(result, &value); |
| 3105 EXPECT_EQ(40, value); | 3075 EXPECT_EQ(40, value); |
| 3106 | 3076 |
| 3107 // Now access and set various native instance fields of the returned object. | 3077 // Now access and set various native instance fields of the returned object. |
| 3108 const int kNativeFld0 = 0; | 3078 const int kNativeFld0 = 0; |
| 3109 const int kNativeFld1 = 1; | 3079 const int kNativeFld1 = 1; |
| 3110 const int kNativeFld2 = 2; | 3080 const int kNativeFld2 = 2; |
| 3111 const int kNativeFld3 = 3; | 3081 const int kNativeFld3 = 3; |
| 3112 const int kNativeFld4 = 4; | 3082 const int kNativeFld4 = 4; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3137 result = Dart_SetNativeInstanceField(retobj, kNativeFld2, 400); | 3107 result = Dart_SetNativeInstanceField(retobj, kNativeFld2, 400); |
| 3138 EXPECT_VALID(result); | 3108 EXPECT_VALID(result); |
| 3139 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000); | 3109 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000); |
| 3140 EXPECT_VALID(result); | 3110 EXPECT_VALID(result); |
| 3141 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value); | 3111 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value); |
| 3142 EXPECT_VALID(result); | 3112 EXPECT_VALID(result); |
| 3143 EXPECT_EQ(4000, field_value); | 3113 EXPECT_EQ(4000, field_value); |
| 3144 | 3114 |
| 3145 // Now re-access various dart instance fields of the returned object | 3115 // Now re-access various dart instance fields of the returned object |
| 3146 // to ensure that there was no corruption while setting native fields. | 3116 // to ensure that there was no corruption while setting native fields. |
| 3147 result = Dart_GetField(retobj, Dart_NewString("fld1")); | 3117 result = Dart_GetField(retobj, NewString("fld1")); |
| 3148 EXPECT_VALID(result); | 3118 EXPECT_VALID(result); |
| 3149 result = Dart_IntegerToInt64(result, &value); | 3119 result = Dart_IntegerToInt64(result, &value); |
| 3150 EXPECT_EQ(40, value); | 3120 EXPECT_EQ(40, value); |
| 3151 result = Dart_GetField(retobj, Dart_NewString("fld2")); | 3121 result = Dart_GetField(retobj, NewString("fld2")); |
| 3152 EXPECT_VALID(result); | 3122 EXPECT_VALID(result); |
| 3153 result = Dart_IntegerToInt64(result, &value); | 3123 result = Dart_IntegerToInt64(result, &value); |
| 3154 EXPECT_EQ(20, value); | 3124 EXPECT_EQ(20, value); |
| 3155 } | 3125 } |
| 3156 | 3126 |
| 3157 | 3127 |
| 3158 TEST_CASE(NativeFieldAccess) { | 3128 TEST_CASE(NativeFieldAccess) { |
| 3159 const char* kScriptChars = | 3129 const char* kScriptChars = |
| 3160 "class NativeFields extends NativeFieldsWrapper {\n" | 3130 "class NativeFields extends NativeFieldsWrapper {\n" |
| 3161 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 3131 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
| 3162 " int fld0;\n" | 3132 " int fld0;\n" |
| 3163 " int fld1;\n" | 3133 " int fld1;\n" |
| 3164 " final int fld2;\n" | 3134 " final int fld2;\n" |
| 3165 " static int fld3;\n" | 3135 " static int fld3;\n" |
| 3166 " static const int fld4 = 10;\n" | 3136 " static const int fld4 = 10;\n" |
| 3167 "}\n" | 3137 "}\n" |
| 3168 "NativeFields testMain() {\n" | 3138 "NativeFields testMain() {\n" |
| 3169 " NativeFields obj = new NativeFields(10, 20);\n" | 3139 " NativeFields obj = new NativeFields(10, 20);\n" |
| 3170 " return obj;\n" | 3140 " return obj;\n" |
| 3171 "}\n"; | 3141 "}\n"; |
| 3172 const int kNumNativeFields = 4; | 3142 const int kNumNativeFields = 4; |
| 3173 | 3143 |
| 3174 // Create a test library. | 3144 // Create a test library. |
| 3175 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 3145 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
| 3176 native_field_lookup); | 3146 native_field_lookup); |
| 3177 | 3147 |
| 3178 // Create a native wrapper class with native fields. | 3148 // Create a native wrapper class with native fields. |
| 3179 Dart_Handle result = Dart_CreateNativeWrapperClass( | 3149 Dart_Handle result = Dart_CreateNativeWrapperClass( |
| 3180 lib, | 3150 lib, |
| 3181 Dart_NewString("NativeFieldsWrapper"), | 3151 NewString("NativeFieldsWrapper"), |
| 3182 kNumNativeFields); | 3152 kNumNativeFields); |
| 3183 EXPECT_VALID(result); | 3153 EXPECT_VALID(result); |
| 3184 | 3154 |
| 3185 // Load up a test script in it. | 3155 // Load up a test script in it. |
| 3186 | 3156 |
| 3187 // Invoke a function which returns an object of type NativeFields. | 3157 // Invoke a function which returns an object of type NativeFields. |
| 3188 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 3158 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 3189 EXPECT_VALID(retobj); | 3159 EXPECT_VALID(retobj); |
| 3190 | 3160 |
| 3191 // Now access and set various instance fields of the returned object. | 3161 // Now access and set various instance fields of the returned object. |
| 3192 TestNativeFields(retobj); | 3162 TestNativeFields(retobj); |
| 3193 | 3163 |
| 3194 // Test that accessing an error handle propagates the error. | 3164 // Test that accessing an error handle propagates the error. |
| 3195 Dart_Handle error = Api::NewError("myerror"); | 3165 Dart_Handle error = Api::NewError("myerror"); |
| 3196 intptr_t field_value = 0; | 3166 intptr_t field_value = 0; |
| 3197 | 3167 |
| 3198 result = Dart_GetNativeInstanceField(error, 0, &field_value); | 3168 result = Dart_GetNativeInstanceField(error, 0, &field_value); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3218 "}\n" | 3188 "}\n" |
| 3219 "NativeFields testMain() {\n" | 3189 "NativeFields testMain() {\n" |
| 3220 " NativeFields obj = new NativeFields(10, 20);\n" | 3190 " NativeFields obj = new NativeFields(10, 20);\n" |
| 3221 " return obj;\n" | 3191 " return obj;\n" |
| 3222 "}\n"; | 3192 "}\n"; |
| 3223 // Load up a test script in the test library. | 3193 // Load up a test script in the test library. |
| 3224 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 3194 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
| 3225 native_field_lookup); | 3195 native_field_lookup); |
| 3226 | 3196 |
| 3227 // Invoke a function which returns an object of type NativeFields. | 3197 // Invoke a function which returns an object of type NativeFields. |
| 3228 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 3198 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 3229 EXPECT_VALID(retobj); | 3199 EXPECT_VALID(retobj); |
| 3230 | 3200 |
| 3231 // Now access and set various instance fields of the returned object. | 3201 // Now access and set various instance fields of the returned object. |
| 3232 TestNativeFields(retobj); | 3202 TestNativeFields(retobj); |
| 3233 } | 3203 } |
| 3234 | 3204 |
| 3235 | 3205 |
| 3236 TEST_CASE(NegativeNativeFieldAccess) { | 3206 TEST_CASE(NegativeNativeFieldAccess) { |
| 3237 const char* kScriptChars = | 3207 const char* kScriptChars = |
| 3238 "class NativeFields {\n" | 3208 "class NativeFields {\n" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3249 "Function testMain2() {\n" | 3219 "Function testMain2() {\n" |
| 3250 " return function() {};\n" | 3220 " return function() {};\n" |
| 3251 "}\n"; | 3221 "}\n"; |
| 3252 Dart_Handle result; | 3222 Dart_Handle result; |
| 3253 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3223 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 3254 | 3224 |
| 3255 // Create a test library and Load up a test script in it. | 3225 // Create a test library and Load up a test script in it. |
| 3256 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3226 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3257 | 3227 |
| 3258 // Invoke a function which returns an object of type NativeFields. | 3228 // Invoke a function which returns an object of type NativeFields. |
| 3259 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain1"), 0, NULL); | 3229 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
| 3260 EXPECT_VALID(retobj); | 3230 EXPECT_VALID(retobj); |
| 3261 | 3231 |
| 3262 // Now access and set various native instance fields of the returned object. | 3232 // Now access and set various native instance fields of the returned object. |
| 3263 // All of these tests are expected to return failure as there are no | 3233 // All of these tests are expected to return failure as there are no |
| 3264 // native fields in an instance of NativeFields. | 3234 // native fields in an instance of NativeFields. |
| 3265 const int kNativeFld0 = 0; | 3235 const int kNativeFld0 = 0; |
| 3266 const int kNativeFld1 = 1; | 3236 const int kNativeFld1 = 1; |
| 3267 const int kNativeFld2 = 2; | 3237 const int kNativeFld2 = 2; |
| 3268 const int kNativeFld3 = 3; | 3238 const int kNativeFld3 = 3; |
| 3269 const int kNativeFld4 = 4; | 3239 const int kNativeFld4 = 4; |
| 3270 intptr_t value = 0; | 3240 intptr_t value = 0; |
| 3271 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); | 3241 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); |
| 3272 EXPECT(Dart_IsError(result)); | 3242 EXPECT(Dart_IsError(result)); |
| 3273 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); | 3243 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); |
| 3274 EXPECT(Dart_IsError(result)); | 3244 EXPECT(Dart_IsError(result)); |
| 3275 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); | 3245 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); |
| 3276 EXPECT(Dart_IsError(result)); | 3246 EXPECT(Dart_IsError(result)); |
| 3277 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); | 3247 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); |
| 3278 EXPECT(Dart_IsError(result)); | 3248 EXPECT(Dart_IsError(result)); |
| 3279 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); | 3249 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); |
| 3280 EXPECT(Dart_IsError(result)); | 3250 EXPECT(Dart_IsError(result)); |
| 3281 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); | 3251 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); |
| 3282 EXPECT(Dart_IsError(result)); | 3252 EXPECT(Dart_IsError(result)); |
| 3283 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); | 3253 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); |
| 3284 EXPECT(Dart_IsError(result)); | 3254 EXPECT(Dart_IsError(result)); |
| 3285 | 3255 |
| 3286 // Invoke a function which returns a closure object. | 3256 // Invoke a function which returns a closure object. |
| 3287 retobj = Dart_Invoke(lib, Dart_NewString("testMain2"), 0, NULL); | 3257 retobj = Dart_Invoke(lib, NewString("testMain2"), 0, NULL); |
| 3288 EXPECT_VALID(retobj); | 3258 EXPECT_VALID(retobj); |
| 3289 | 3259 |
| 3290 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); | 3260 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); |
| 3291 EXPECT(Dart_IsError(result)); | 3261 EXPECT(Dart_IsError(result)); |
| 3292 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); | 3262 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); |
| 3293 EXPECT(Dart_IsError(result)); | 3263 EXPECT(Dart_IsError(result)); |
| 3294 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); | 3264 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); |
| 3295 EXPECT(Dart_IsError(result)); | 3265 EXPECT(Dart_IsError(result)); |
| 3296 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); | 3266 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); |
| 3297 EXPECT(Dart_IsError(result)); | 3267 EXPECT(Dart_IsError(result)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3308 const char* kScriptChars = | 3278 const char* kScriptChars = |
| 3309 "class TestClass {\n" | 3279 "class TestClass {\n" |
| 3310 " static const int fld1 = 7;\n" | 3280 " static const int fld1 = 7;\n" |
| 3311 " static int fld2 = 11;\n" | 3281 " static int fld2 = 11;\n" |
| 3312 " static void testMain() {\n" | 3282 " static void testMain() {\n" |
| 3313 " }\n" | 3283 " }\n" |
| 3314 "}\n"; | 3284 "}\n"; |
| 3315 Dart_Handle result; | 3285 Dart_Handle result; |
| 3316 // Create a test library and Load up a test script in it. | 3286 // Create a test library and Load up a test script in it. |
| 3317 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3287 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3318 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); | 3288 Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass")); |
| 3319 EXPECT_VALID(cls); | 3289 EXPECT_VALID(cls); |
| 3320 | 3290 |
| 3321 // Invoke a function which returns an object. | 3291 // Invoke a function which returns an object. |
| 3322 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 3292 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
| 3323 EXPECT_VALID(result); | 3293 EXPECT_VALID(result); |
| 3324 | 3294 |
| 3325 // For uninitialized fields, the getter is returned | 3295 // For uninitialized fields, the getter is returned |
| 3326 result = Dart_GetField(cls, Dart_NewString("fld1")); | 3296 result = Dart_GetField(cls, NewString("fld1")); |
| 3327 EXPECT_VALID(result); | 3297 EXPECT_VALID(result); |
| 3328 int64_t value = 0; | 3298 int64_t value = 0; |
| 3329 result = Dart_IntegerToInt64(result, &value); | 3299 result = Dart_IntegerToInt64(result, &value); |
| 3330 EXPECT_EQ(7, value); | 3300 EXPECT_EQ(7, value); |
| 3331 | 3301 |
| 3332 result = Dart_GetField(cls, Dart_NewString("fld2")); | 3302 result = Dart_GetField(cls, NewString("fld2")); |
| 3333 EXPECT_VALID(result); | 3303 EXPECT_VALID(result); |
| 3334 result = Dart_IntegerToInt64(result, &value); | 3304 result = Dart_IntegerToInt64(result, &value); |
| 3335 EXPECT_EQ(11, value); | 3305 EXPECT_EQ(11, value); |
| 3336 | 3306 |
| 3337 // Overwrite fld2 | 3307 // Overwrite fld2 |
| 3338 result = Dart_SetField(cls, | 3308 result = Dart_SetField(cls, |
| 3339 Dart_NewString("fld2"), | 3309 NewString("fld2"), |
| 3340 Dart_NewInteger(13)); | 3310 Dart_NewInteger(13)); |
| 3341 EXPECT_VALID(result); | 3311 EXPECT_VALID(result); |
| 3342 | 3312 |
| 3343 // We now get the new value for fld2, not the initializer | 3313 // We now get the new value for fld2, not the initializer |
| 3344 result = Dart_GetField(cls, Dart_NewString("fld2")); | 3314 result = Dart_GetField(cls, NewString("fld2")); |
| 3345 EXPECT_VALID(result); | 3315 EXPECT_VALID(result); |
| 3346 result = Dart_IntegerToInt64(result, &value); | 3316 result = Dart_IntegerToInt64(result, &value); |
| 3347 EXPECT_EQ(13, value); | 3317 EXPECT_EQ(13, value); |
| 3348 } | 3318 } |
| 3349 | 3319 |
| 3350 | 3320 |
| 3351 TEST_CASE(New) { | 3321 TEST_CASE(New) { |
| 3352 const char* kScriptChars = | 3322 const char* kScriptChars = |
| 3353 "class MyClass implements MyInterface {\n" | 3323 "class MyClass implements MyInterface {\n" |
| 3354 " MyClass() : foo = 7 {}\n" | 3324 " MyClass() : foo = 7 {}\n" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3385 " MyInterface.multiply(value);\n" | 3355 " MyInterface.multiply(value);\n" |
| 3386 " MyInterface.notfound(value);\n" | 3356 " MyInterface.notfound(value);\n" |
| 3387 "}\n" | 3357 "}\n" |
| 3388 "\n" | 3358 "\n" |
| 3389 "interface MyInterface2 default MyClass {\n" | 3359 "interface MyInterface2 default MyClass {\n" |
| 3390 " MyInterface2.multiply(value);\n" | 3360 " MyInterface2.multiply(value);\n" |
| 3391 " MyInterface2.notfound(value);\n" | 3361 " MyInterface2.notfound(value);\n" |
| 3392 "}\n"; | 3362 "}\n"; |
| 3393 | 3363 |
| 3394 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3364 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3395 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); | 3365 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); |
| 3396 EXPECT_VALID(cls); | 3366 EXPECT_VALID(cls); |
| 3397 Dart_Handle cls2 = Dart_GetClass(lib, Dart_NewString("MyClass2")); | 3367 Dart_Handle cls2 = Dart_GetClass(lib, NewString("MyClass2")); |
| 3398 EXPECT_VALID(cls2); | 3368 EXPECT_VALID(cls2); |
| 3399 Dart_Handle intf = Dart_GetClass(lib, Dart_NewString("MyInterface")); | 3369 Dart_Handle intf = Dart_GetClass(lib, NewString("MyInterface")); |
| 3400 EXPECT_VALID(intf); | 3370 EXPECT_VALID(intf); |
| 3401 Dart_Handle intf2 = Dart_GetClass(lib, Dart_NewString("MyInterface2")); | 3371 Dart_Handle intf2 = Dart_GetClass(lib, NewString("MyInterface2")); |
| 3402 EXPECT_VALID(intf2); | 3372 EXPECT_VALID(intf2); |
| 3403 Dart_Handle args[1]; | 3373 Dart_Handle args[1]; |
| 3404 args[0] = Dart_NewInteger(11); | 3374 args[0] = Dart_NewInteger(11); |
| 3405 Dart_Handle bad_args[1]; | 3375 Dart_Handle bad_args[1]; |
| 3406 bad_args[0] = Dart_Error("myerror"); | 3376 bad_args[0] = Dart_Error("myerror"); |
| 3407 | 3377 |
| 3408 // Invoke the unnamed constructor. | 3378 // Invoke the unnamed constructor. |
| 3409 Dart_Handle result = Dart_New(cls, Dart_Null(), 0, NULL); | 3379 Dart_Handle result = Dart_New(cls, Dart_Null(), 0, NULL); |
| 3410 EXPECT_VALID(result); | 3380 EXPECT_VALID(result); |
| 3411 bool instanceof = false; | 3381 bool instanceof = false; |
| 3412 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3382 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3413 EXPECT(instanceof); | 3383 EXPECT(instanceof); |
| 3414 int64_t int_value = 0; | 3384 int64_t int_value = 0; |
| 3415 Dart_Handle foo = Dart_GetField(result, Dart_NewString("foo")); | 3385 Dart_Handle foo = Dart_GetField(result, NewString("foo")); |
| 3416 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3386 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3417 EXPECT_EQ(7, int_value); | 3387 EXPECT_EQ(7, int_value); |
| 3418 | 3388 |
| 3419 // Invoke the unnamed constructor with an empty string. | 3389 // Invoke the unnamed constructor with an empty string. |
| 3420 result = Dart_New(cls, Dart_NewString(""), 0, NULL); | 3390 result = Dart_New(cls, NewString(""), 0, NULL); |
| 3421 EXPECT_VALID(result); | 3391 EXPECT_VALID(result); |
| 3422 instanceof = false; | 3392 instanceof = false; |
| 3423 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3393 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3424 EXPECT(instanceof); | 3394 EXPECT(instanceof); |
| 3425 int_value = 0; | 3395 int_value = 0; |
| 3426 foo = Dart_GetField(result, Dart_NewString("foo")); | 3396 foo = Dart_GetField(result, NewString("foo")); |
| 3427 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3397 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3428 EXPECT_EQ(7, int_value); | 3398 EXPECT_EQ(7, int_value); |
| 3429 | 3399 |
| 3430 // Invoke a named constructor. | 3400 // Invoke a named constructor. |
| 3431 result = Dart_New(cls, Dart_NewString("named"), 1, args); | 3401 result = Dart_New(cls, NewString("named"), 1, args); |
| 3432 EXPECT_VALID(result); | 3402 EXPECT_VALID(result); |
| 3433 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3403 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3434 EXPECT(instanceof); | 3404 EXPECT(instanceof); |
| 3435 int_value = 0; | 3405 int_value = 0; |
| 3436 foo = Dart_GetField(result, Dart_NewString("foo")); | 3406 foo = Dart_GetField(result, NewString("foo")); |
| 3437 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3407 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3438 EXPECT_EQ(11, int_value); | 3408 EXPECT_EQ(11, int_value); |
| 3439 | 3409 |
| 3440 // Invoke a hidden named constructor. | 3410 // Invoke a hidden named constructor. |
| 3441 result = Dart_New(cls, Dart_NewString("_hidden"), 1, args); | 3411 result = Dart_New(cls, NewString("_hidden"), 1, args); |
| 3442 EXPECT_VALID(result); | 3412 EXPECT_VALID(result); |
| 3443 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3413 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3444 EXPECT(instanceof); | 3414 EXPECT(instanceof); |
| 3445 int_value = 0; | 3415 int_value = 0; |
| 3446 foo = Dart_GetField(result, Dart_NewString("foo")); | 3416 foo = Dart_GetField(result, NewString("foo")); |
| 3447 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3417 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3448 EXPECT_EQ(-11, int_value); | 3418 EXPECT_EQ(-11, int_value); |
| 3449 | 3419 |
| 3450 // Invoke a factory constructor. | 3420 // Invoke a factory constructor. |
| 3451 result = Dart_New(cls, Dart_NewString("multiply"), 1, args); | 3421 result = Dart_New(cls, NewString("multiply"), 1, args); |
| 3452 EXPECT_VALID(result); | 3422 EXPECT_VALID(result); |
| 3453 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3423 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3454 EXPECT(instanceof); | 3424 EXPECT(instanceof); |
| 3455 int_value = 0; | 3425 int_value = 0; |
| 3456 foo = Dart_GetField(result, Dart_NewString("foo")); | 3426 foo = Dart_GetField(result, NewString("foo")); |
| 3457 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3427 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3458 EXPECT_EQ(1100, int_value); | 3428 EXPECT_EQ(1100, int_value); |
| 3459 | 3429 |
| 3460 // Invoke a factory constructor which returns null. | 3430 // Invoke a factory constructor which returns null. |
| 3461 result = Dart_New(cls, Dart_NewString("nullo"), 0, NULL); | 3431 result = Dart_New(cls, NewString("nullo"), 0, NULL); |
| 3462 EXPECT_VALID(result); | 3432 EXPECT_VALID(result); |
| 3463 EXPECT(Dart_IsNull(result)); | 3433 EXPECT(Dart_IsNull(result)); |
| 3464 | 3434 |
| 3465 // Pass an error class object. Error is passed through. | 3435 // Pass an error class object. Error is passed through. |
| 3466 result = Dart_New(Dart_Error("myerror"), Dart_NewString("named"), 1, args); | 3436 result = Dart_New(Dart_Error("myerror"), NewString("named"), 1, args); |
| 3467 EXPECT_ERROR(result, "myerror"); | 3437 EXPECT_ERROR(result, "myerror"); |
| 3468 | 3438 |
| 3469 // Pass a bad class object. | 3439 // Pass a bad class object. |
| 3470 result = Dart_New(Dart_Null(), Dart_NewString("named"), 1, args); | 3440 result = Dart_New(Dart_Null(), NewString("named"), 1, args); |
| 3471 EXPECT_ERROR(result, "Dart_New expects argument 'clazz' to be non-null."); | 3441 EXPECT_ERROR(result, "Dart_New expects argument 'clazz' to be non-null."); |
| 3472 | 3442 |
| 3473 // Pass a negative arg count. | 3443 // Pass a negative arg count. |
| 3474 result = Dart_New(cls, Dart_NewString("named"), -1, args); | 3444 result = Dart_New(cls, NewString("named"), -1, args); |
| 3475 EXPECT_ERROR( | 3445 EXPECT_ERROR( |
| 3476 result, | 3446 result, |
| 3477 "Dart_New expects argument 'number_of_arguments' to be non-negative."); | 3447 "Dart_New expects argument 'number_of_arguments' to be non-negative."); |
| 3478 | 3448 |
| 3479 // Pass the wrong arg count. | 3449 // Pass the wrong arg count. |
| 3480 result = Dart_New(cls, Dart_NewString("named"), 0, NULL); | 3450 result = Dart_New(cls, NewString("named"), 0, NULL); |
| 3481 EXPECT_ERROR( | 3451 EXPECT_ERROR( |
| 3482 result, | 3452 result, |
| 3483 "Dart_New: wrong argument count for constructor 'MyClass.named': " | 3453 "Dart_New: wrong argument count for constructor 'MyClass.named': " |
| 3484 "0 passed, 1 expected."); | 3454 "0 passed, 1 expected."); |
| 3485 | 3455 |
| 3486 // Pass a bad argument. Error is passed through. | 3456 // Pass a bad argument. Error is passed through. |
| 3487 result = Dart_New(cls, Dart_NewString("named"), 1, bad_args); | 3457 result = Dart_New(cls, NewString("named"), 1, bad_args); |
| 3488 EXPECT_ERROR(result, "myerror"); | 3458 EXPECT_ERROR(result, "myerror"); |
| 3489 | 3459 |
| 3490 // Pass a bad constructor name. | 3460 // Pass a bad constructor name. |
| 3491 result = Dart_New(cls, Dart_NewInteger(55), 1, args); | 3461 result = Dart_New(cls, Dart_NewInteger(55), 1, args); |
| 3492 EXPECT_ERROR( | 3462 EXPECT_ERROR( |
| 3493 result, | 3463 result, |
| 3494 "Dart_New expects argument 'constructor_name' to be of type String."); | 3464 "Dart_New expects argument 'constructor_name' to be of type String."); |
| 3495 | 3465 |
| 3496 // Invoke a missing constructor. | 3466 // Invoke a missing constructor. |
| 3497 result = Dart_New(cls, Dart_NewString("missing"), 1, args); | 3467 result = Dart_New(cls, NewString("missing"), 1, args); |
| 3498 EXPECT_ERROR(result, | 3468 EXPECT_ERROR(result, |
| 3499 "Dart_New: could not find constructor 'MyClass.missing'."); | 3469 "Dart_New: could not find constructor 'MyClass.missing'."); |
| 3500 | 3470 |
| 3501 // Invoke a constructor which throws an exception. | 3471 // Invoke a constructor which throws an exception. |
| 3502 result = Dart_New(cls, Dart_NewString("exception"), 1, args); | 3472 result = Dart_New(cls, NewString("exception"), 1, args); |
| 3503 EXPECT_ERROR(result, "ConstructorDeath"); | 3473 EXPECT_ERROR(result, "ConstructorDeath"); |
| 3504 | 3474 |
| 3505 // MyInterface has default class MyClass. | 3475 // MyInterface has default class MyClass. |
| 3506 // | 3476 // |
| 3507 // MyClass *implements* MyInterface. | 3477 // MyClass *implements* MyInterface. |
| 3508 // | 3478 // |
| 3509 // Therefore the constructor call: | 3479 // Therefore the constructor call: |
| 3510 // | 3480 // |
| 3511 // MyInterface.foo() | 3481 // MyInterface.foo() |
| 3512 // | 3482 // |
| 3513 // Becomes: | 3483 // Becomes: |
| 3514 // | 3484 // |
| 3515 // MyClass.foo() from the class MyClass. | 3485 // MyClass.foo() from the class MyClass. |
| 3516 | 3486 |
| 3517 // Invoke an interface constructor. | 3487 // Invoke an interface constructor. |
| 3518 result = Dart_New(intf, Dart_NewString("named"), 1, args); | 3488 result = Dart_New(intf, NewString("named"), 1, args); |
| 3519 EXPECT_VALID(result); | 3489 EXPECT_VALID(result); |
| 3520 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3490 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3521 EXPECT(instanceof); | 3491 EXPECT(instanceof); |
| 3522 int_value = 0; | 3492 int_value = 0; |
| 3523 foo = Dart_GetField(result, Dart_NewString("foo")); | 3493 foo = Dart_GetField(result, NewString("foo")); |
| 3524 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3494 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3525 EXPECT_EQ(11, int_value); | 3495 EXPECT_EQ(11, int_value); |
| 3526 | 3496 |
| 3527 // Invoke an interface constructor which in turn calls a factory | 3497 // Invoke an interface constructor which in turn calls a factory |
| 3528 // constructor. | 3498 // constructor. |
| 3529 result = Dart_New(intf, Dart_NewString("multiply"), 1, args); | 3499 result = Dart_New(intf, NewString("multiply"), 1, args); |
| 3530 EXPECT_VALID(result); | 3500 EXPECT_VALID(result); |
| 3531 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); | 3501 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); |
| 3532 EXPECT(instanceof); | 3502 EXPECT(instanceof); |
| 3533 int_value = 0; | 3503 int_value = 0; |
| 3534 foo = Dart_GetField(result, Dart_NewString("foo")); | 3504 foo = Dart_GetField(result, NewString("foo")); |
| 3535 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 3505 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
| 3536 EXPECT_EQ(1100, int_value); | 3506 EXPECT_EQ(1100, int_value); |
| 3537 | 3507 |
| 3538 // Invoke a constructor that is missing in the interface but present | 3508 // Invoke a constructor that is missing in the interface but present |
| 3539 // in the default class. | 3509 // in the default class. |
| 3540 result = Dart_New(intf, Dart_Null(), 0, NULL); | 3510 result = Dart_New(intf, Dart_Null(), 0, NULL); |
| 3541 EXPECT_ERROR(result, | 3511 EXPECT_ERROR(result, |
| 3542 "Dart_New: could not find constructor 'MyInterface.'."); | 3512 "Dart_New: could not find constructor 'MyInterface.'."); |
| 3543 | 3513 |
| 3544 // Invoke a constructor that is present in the interface but missing | 3514 // Invoke a constructor that is present in the interface but missing |
| 3545 // in the default class. | 3515 // in the default class. |
| 3546 result = Dart_New(intf, Dart_NewString("notfound"), 1, args); | 3516 result = Dart_New(intf, NewString("notfound"), 1, args); |
| 3547 EXPECT_ERROR(result, | 3517 EXPECT_ERROR(result, |
| 3548 "Dart_New: could not find constructor 'MyClass.notfound'."); | 3518 "Dart_New: could not find constructor 'MyClass.notfound'."); |
| 3549 | 3519 |
| 3550 // MyInterface2 has default class MyClass. | 3520 // MyInterface2 has default class MyClass. |
| 3551 // | 3521 // |
| 3552 // MyClass *does not implement* MyInterface2. | 3522 // MyClass *does not implement* MyInterface2. |
| 3553 // | 3523 // |
| 3554 // Therefore the constructor call: | 3524 // Therefore the constructor call: |
| 3555 // | 3525 // |
| 3556 // new MyInterface2.foo() | 3526 // new MyInterface2.foo() |
| 3557 // | 3527 // |
| 3558 // Becomes: | 3528 // Becomes: |
| 3559 // | 3529 // |
| 3560 // new MyInterface2.foo() from the class MyClass. | 3530 // new MyInterface2.foo() from the class MyClass. |
| 3561 | 3531 |
| 3562 // Invoke an interface constructor which in turn calls a factory | 3532 // Invoke an interface constructor which in turn calls a factory |
| 3563 // constructor. | 3533 // constructor. |
| 3564 result = Dart_New(intf2, Dart_NewString("multiply"), 1, args); | 3534 result = Dart_New(intf2, NewString("multiply"), 1, args); |
| 3565 EXPECT_VALID(result); | 3535 EXPECT_VALID(result); |
| 3566 EXPECT_VALID(Dart_ObjectIsType(result, cls2, &instanceof)); | 3536 EXPECT_VALID(Dart_ObjectIsType(result, cls2, &instanceof)); |
| 3567 EXPECT(instanceof); | 3537 EXPECT(instanceof); |
| 3568 int_value = 0; | 3538 int_value = 0; |
| 3569 Dart_Handle bar = Dart_GetField(result, Dart_NewString("bar")); | 3539 Dart_Handle bar = Dart_GetField(result, NewString("bar")); |
| 3570 EXPECT_VALID(Dart_IntegerToInt64(bar, &int_value)); | 3540 EXPECT_VALID(Dart_IntegerToInt64(bar, &int_value)); |
| 3571 EXPECT_EQ(110000, int_value); | 3541 EXPECT_EQ(110000, int_value); |
| 3572 | 3542 |
| 3573 // Invoke a constructor that is missing in the interface but present | 3543 // Invoke a constructor that is missing in the interface but present |
| 3574 // in the default class. | 3544 // in the default class. |
| 3575 result = Dart_New(intf2, Dart_NewString("unused"), 1, args); | 3545 result = Dart_New(intf2, NewString("unused"), 1, args); |
| 3576 EXPECT_ERROR(result, | 3546 EXPECT_ERROR(result, |
| 3577 "Dart_New: could not find constructor 'MyInterface2.unused'."); | 3547 "Dart_New: could not find constructor 'MyInterface2.unused'."); |
| 3578 | 3548 |
| 3579 // Invoke a constructor that is present in the interface but missing | 3549 // Invoke a constructor that is present in the interface but missing |
| 3580 // in the default class. | 3550 // in the default class. |
| 3581 result = Dart_New(intf2, Dart_NewString("notfound"), 1, args); | 3551 result = Dart_New(intf2, NewString("notfound"), 1, args); |
| 3582 EXPECT_ERROR(result, | 3552 EXPECT_ERROR(result, |
| 3583 "Dart_New: could not find factory 'MyInterface2.notfound' " | 3553 "Dart_New: could not find factory 'MyInterface2.notfound' " |
| 3584 "in class 'MyClass'."); | 3554 "in class 'MyClass'."); |
| 3585 } | 3555 } |
| 3586 | 3556 |
| 3587 | 3557 |
| 3588 TEST_CASE(New_Issue2971) { | 3558 TEST_CASE(New_Issue2971) { |
| 3589 // Issue 2971: We were unable to use Dart_New to construct an | 3559 // Issue 2971: We were unable to use Dart_New to construct an |
| 3590 // instance of List, due to problems implementing interface | 3560 // instance of List, due to problems implementing interface |
| 3591 // factories. | 3561 // factories. |
| 3592 Dart_Handle core_lib = Dart_LookupLibrary(Dart_NewString("dart:core")); | 3562 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); |
| 3593 EXPECT_VALID(core_lib); | 3563 EXPECT_VALID(core_lib); |
| 3594 Dart_Handle list_class = Dart_GetClass(core_lib, Dart_NewString("List")); | 3564 Dart_Handle list_class = Dart_GetClass(core_lib, NewString("List")); |
| 3595 EXPECT_VALID(list_class); | 3565 EXPECT_VALID(list_class); |
| 3596 | 3566 |
| 3597 const int kNumArgs = 1; | 3567 const int kNumArgs = 1; |
| 3598 Dart_Handle args[kNumArgs]; | 3568 Dart_Handle args[kNumArgs]; |
| 3599 args[0] = Dart_NewInteger(1); | 3569 args[0] = Dart_NewInteger(1); |
| 3600 Dart_Handle list_obj = Dart_New(list_class, Dart_Null(), kNumArgs, args); | 3570 Dart_Handle list_obj = Dart_New(list_class, Dart_Null(), kNumArgs, args); |
| 3601 EXPECT_VALID(list_obj); | 3571 EXPECT_VALID(list_obj); |
| 3602 EXPECT(Dart_IsList(list_obj)); | 3572 EXPECT(Dart_IsList(list_obj)); |
| 3603 } | 3573 } |
| 3604 | 3574 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3619 "\n" | 3589 "\n" |
| 3620 "topMethod(arg) => 'top $arg';\n" | 3590 "topMethod(arg) => 'top $arg';\n" |
| 3621 "_topMethod(arg) => 'hidden top $arg';\n" | 3591 "_topMethod(arg) => 'hidden top $arg';\n" |
| 3622 "\n" | 3592 "\n" |
| 3623 "Methods test() {\n" | 3593 "Methods test() {\n" |
| 3624 " return new Methods();\n" | 3594 " return new Methods();\n" |
| 3625 "}\n"; | 3595 "}\n"; |
| 3626 | 3596 |
| 3627 // Shared setup. | 3597 // Shared setup. |
| 3628 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3598 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3629 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Methods")); | 3599 Dart_Handle cls = Dart_GetClass(lib, NewString("Methods")); |
| 3630 EXPECT_VALID(cls); | 3600 EXPECT_VALID(cls); |
| 3631 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); | 3601 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); |
| 3632 EXPECT_VALID(instance); | 3602 EXPECT_VALID(instance); |
| 3633 Dart_Handle args[1]; | 3603 Dart_Handle args[1]; |
| 3634 args[0] = Dart_NewString("!!!"); | 3604 args[0] = NewString("!!!"); |
| 3635 Dart_Handle bad_args[2]; | 3605 Dart_Handle bad_args[2]; |
| 3636 bad_args[0] = Dart_NewString("bad1"); | 3606 bad_args[0] = NewString("bad1"); |
| 3637 bad_args[1] = Dart_NewString("bad2"); | 3607 bad_args[1] = NewString("bad2"); |
| 3638 Dart_Handle result; | 3608 Dart_Handle result; |
| 3639 Dart_Handle name; | 3609 Dart_Handle name; |
| 3640 const char* str; | 3610 const char* str; |
| 3641 | 3611 |
| 3642 // Instance method. | 3612 // Instance method. |
| 3643 name = Dart_NewString("instanceMethod"); | 3613 name = NewString("instanceMethod"); |
| 3644 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3614 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
| 3645 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3615 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
| 3646 result = Dart_Invoke(instance, name, 1, args); | 3616 result = Dart_Invoke(instance, name, 1, args); |
| 3647 EXPECT_VALID(result); | 3617 EXPECT_VALID(result); |
| 3648 result = Dart_StringToCString(result, &str); | 3618 result = Dart_StringToCString(result, &str); |
| 3649 EXPECT_STREQ("instance !!!", str); | 3619 EXPECT_STREQ("instance !!!", str); |
| 3650 | 3620 |
| 3651 // Instance method, wrong arg count. | 3621 // Instance method, wrong arg count. |
| 3652 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args), | 3622 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args), |
| 3653 "did not find instance method 'Methods.instanceMethod'"); | 3623 "did not find instance method 'Methods.instanceMethod'"); |
| 3654 | 3624 |
| 3655 // Hidden instance method. | 3625 // Hidden instance method. |
| 3656 name = Dart_NewString("_instanceMethod"); | 3626 name = NewString("_instanceMethod"); |
| 3657 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3627 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
| 3658 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3628 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
| 3659 result = Dart_Invoke(instance, name, 1, args); | 3629 result = Dart_Invoke(instance, name, 1, args); |
| 3660 EXPECT_VALID(result); | 3630 EXPECT_VALID(result); |
| 3661 result = Dart_StringToCString(result, &str); | 3631 result = Dart_StringToCString(result, &str); |
| 3662 EXPECT_STREQ("hidden instance !!!", str); | 3632 EXPECT_STREQ("hidden instance !!!", str); |
| 3663 | 3633 |
| 3664 // Inherited method. | 3634 // Inherited method. |
| 3665 name = Dart_NewString("inheritedMethod"); | 3635 name = NewString("inheritedMethod"); |
| 3666 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3636 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
| 3667 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3637 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
| 3668 result = Dart_Invoke(instance, name, 1, args); | 3638 result = Dart_Invoke(instance, name, 1, args); |
| 3669 EXPECT_VALID(result); | 3639 EXPECT_VALID(result); |
| 3670 result = Dart_StringToCString(result, &str); | 3640 result = Dart_StringToCString(result, &str); |
| 3671 EXPECT_STREQ("inherited !!!", str); | 3641 EXPECT_STREQ("inherited !!!", str); |
| 3672 | 3642 |
| 3673 // Static method. | 3643 // Static method. |
| 3674 name = Dart_NewString("staticMethod"); | 3644 name = NewString("staticMethod"); |
| 3675 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3645 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
| 3676 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3646 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
| 3677 result = Dart_Invoke(cls, name, 1, args); | 3647 result = Dart_Invoke(cls, name, 1, args); |
| 3678 EXPECT_VALID(result); | 3648 EXPECT_VALID(result); |
| 3679 result = Dart_StringToCString(result, &str); | 3649 result = Dart_StringToCString(result, &str); |
| 3680 EXPECT_STREQ("static !!!", str); | 3650 EXPECT_STREQ("static !!!", str); |
| 3681 | 3651 |
| 3682 // Static method, wrong arg count. | 3652 // Static method, wrong arg count. |
| 3683 EXPECT_ERROR(Dart_Invoke(cls, name, 2, bad_args), | 3653 EXPECT_ERROR(Dart_Invoke(cls, name, 2, bad_args), |
| 3684 "did not find static method 'Methods.staticMethod'"); | 3654 "did not find static method 'Methods.staticMethod'"); |
| 3685 | 3655 |
| 3686 // Hidden static method. | 3656 // Hidden static method. |
| 3687 name = Dart_NewString("_staticMethod"); | 3657 name = NewString("_staticMethod"); |
| 3688 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3658 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
| 3689 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3659 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
| 3690 result = Dart_Invoke(cls, name, 1, args); | 3660 result = Dart_Invoke(cls, name, 1, args); |
| 3691 EXPECT_VALID(result); | 3661 EXPECT_VALID(result); |
| 3692 result = Dart_StringToCString(result, &str); | 3662 result = Dart_StringToCString(result, &str); |
| 3693 EXPECT_STREQ("hidden static !!!", str); | 3663 EXPECT_STREQ("hidden static !!!", str); |
| 3694 | 3664 |
| 3695 // Static non-inherited method. Not found at any level. | 3665 // Static non-inherited method. Not found at any level. |
| 3696 name = Dart_NewString("non_inheritedMethod"); | 3666 name = NewString("non_inheritedMethod"); |
| 3697 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3667 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
| 3698 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3668 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
| 3699 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3669 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
| 3700 | 3670 |
| 3701 // Top-Level method. | 3671 // Top-Level method. |
| 3702 name = Dart_NewString("topMethod"); | 3672 name = NewString("topMethod"); |
| 3703 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3673 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
| 3704 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3674 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
| 3705 result = Dart_Invoke(lib, name, 1, args); | 3675 result = Dart_Invoke(lib, name, 1, args); |
| 3706 EXPECT_VALID(result); | 3676 EXPECT_VALID(result); |
| 3707 result = Dart_StringToCString(result, &str); | 3677 result = Dart_StringToCString(result, &str); |
| 3708 EXPECT_STREQ("top !!!", str); | 3678 EXPECT_STREQ("top !!!", str); |
| 3709 | 3679 |
| 3710 // Top-level method, wrong arg count. | 3680 // Top-level method, wrong arg count. |
| 3711 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args), | 3681 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args), |
| 3712 "Dart_Invoke: wrong argument count for function 'topMethod': " | 3682 "Dart_Invoke: wrong argument count for function 'topMethod': " |
| 3713 "2 passed, 1 expected."); | 3683 "2 passed, 1 expected."); |
| 3714 | 3684 |
| 3715 // Hidden top-level method. | 3685 // Hidden top-level method. |
| 3716 name = Dart_NewString("_topMethod"); | 3686 name = NewString("_topMethod"); |
| 3717 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3687 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
| 3718 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3688 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
| 3719 result = Dart_Invoke(lib, name, 1, args); | 3689 result = Dart_Invoke(lib, name, 1, args); |
| 3720 EXPECT_VALID(result); | 3690 EXPECT_VALID(result); |
| 3721 result = Dart_StringToCString(result, &str); | 3691 result = Dart_StringToCString(result, &str); |
| 3722 EXPECT_STREQ("hidden top !!!", str); | 3692 EXPECT_STREQ("hidden top !!!", str); |
| 3723 } | 3693 } |
| 3724 | 3694 |
| 3725 | 3695 |
| 3726 TEST_CASE(Invoke_FunnyArgs) { | 3696 TEST_CASE(Invoke_FunnyArgs) { |
| 3727 const char* kScriptChars = | 3697 const char* kScriptChars = |
| 3728 "test(arg) => 'hello $arg';\n"; | 3698 "test(arg) => 'hello $arg';\n"; |
| 3729 | 3699 |
| 3730 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3700 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3731 Dart_Handle func_name = Dart_NewString("test"); | 3701 Dart_Handle func_name = NewString("test"); |
| 3732 Dart_Handle args[1]; | 3702 Dart_Handle args[1]; |
| 3733 const char* str; | 3703 const char* str; |
| 3734 | 3704 |
| 3735 // Make sure that valid args yield valid results. | 3705 // Make sure that valid args yield valid results. |
| 3736 args[0] = Dart_NewString("!!!"); | 3706 args[0] = NewString("!!!"); |
| 3737 Dart_Handle result = Dart_Invoke(lib, func_name, 1, args); | 3707 Dart_Handle result = Dart_Invoke(lib, func_name, 1, args); |
| 3738 EXPECT_VALID(result); | 3708 EXPECT_VALID(result); |
| 3739 result = Dart_StringToCString(result, &str); | 3709 result = Dart_StringToCString(result, &str); |
| 3740 EXPECT_STREQ("hello !!!", str); | 3710 EXPECT_STREQ("hello !!!", str); |
| 3741 | 3711 |
| 3742 // Make sure that null is legal. | 3712 // Make sure that null is legal. |
| 3743 args[0] = Dart_Null(); | 3713 args[0] = Dart_Null(); |
| 3744 result = Dart_Invoke(lib, func_name, 1, args); | 3714 result = Dart_Invoke(lib, func_name, 1, args); |
| 3745 EXPECT_VALID(result); | 3715 EXPECT_VALID(result); |
| 3746 result = Dart_StringToCString(result, &str); | 3716 result = Dart_StringToCString(result, &str); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3767 // Pass an error handle as a parameter. The error is propagated. | 3737 // Pass an error handle as a parameter. The error is propagated. |
| 3768 args[0] = Api::NewError("myerror"); | 3738 args[0] = Api::NewError("myerror"); |
| 3769 result = Dart_Invoke(lib, func_name, 1, args); | 3739 result = Dart_Invoke(lib, func_name, 1, args); |
| 3770 EXPECT(Dart_IsError(result)); | 3740 EXPECT(Dart_IsError(result)); |
| 3771 EXPECT_STREQ("myerror", Dart_GetError(result)); | 3741 EXPECT_STREQ("myerror", Dart_GetError(result)); |
| 3772 } | 3742 } |
| 3773 | 3743 |
| 3774 | 3744 |
| 3775 TEST_CASE(Invoke_Null) { | 3745 TEST_CASE(Invoke_Null) { |
| 3776 Dart_Handle result = Dart_Invoke(Dart_Null(), | 3746 Dart_Handle result = Dart_Invoke(Dart_Null(), |
| 3777 Dart_NewString("toString"), | 3747 NewString("toString"), |
| 3778 0, | 3748 0, |
| 3779 NULL); | 3749 NULL); |
| 3780 EXPECT_VALID(result); | 3750 EXPECT_VALID(result); |
| 3781 EXPECT(Dart_IsString(result)); | 3751 EXPECT(Dart_IsString(result)); |
| 3782 | 3752 |
| 3783 const char* value = ""; | 3753 const char* value = ""; |
| 3784 EXPECT_VALID(Dart_StringToCString(result, &value)); | 3754 EXPECT_VALID(Dart_StringToCString(result, &value)); |
| 3785 EXPECT_STREQ("null", value); | 3755 EXPECT_STREQ("null", value); |
| 3786 | 3756 |
| 3787 // Should throw a NullPointerException. Disabled due to bug 5415268. | 3757 // Should throw a NullPointerException. Disabled due to bug 5415268. |
| 3788 /* | 3758 /* |
| 3789 Dart_Handle function_name2 = Dart_NewString("NoNoNo"); | 3759 Dart_Handle function_name2 = NewString("NoNoNo"); |
| 3790 result = Dart_Invoke(null_receiver, | 3760 result = Dart_Invoke(null_receiver, |
| 3791 function_name2, | 3761 function_name2, |
| 3792 number_of_arguments, | 3762 number_of_arguments, |
| 3793 dart_arguments); | 3763 dart_arguments); |
| 3794 EXPECT(Dart_IsError(result)); | 3764 EXPECT(Dart_IsError(result)); |
| 3795 EXPECT(Dart_ErrorHasException(result)); */ | 3765 EXPECT(Dart_ErrorHasException(result)); */ |
| 3796 } | 3766 } |
| 3797 | 3767 |
| 3798 | 3768 |
| 3799 TEST_CASE(Invoke_CrossLibrary) { | 3769 TEST_CASE(Invoke_CrossLibrary) { |
| 3800 const char* kLibrary1Chars = | 3770 const char* kLibrary1Chars = |
| 3801 "#library('library1_name');\n" | 3771 "#library('library1_name');\n" |
| 3802 "void local() {}\n" | 3772 "void local() {}\n" |
| 3803 "void _local() {}\n"; | 3773 "void _local() {}\n"; |
| 3804 const char* kLibrary2Chars = | 3774 const char* kLibrary2Chars = |
| 3805 "#library('library2_name');\n" | 3775 "#library('library2_name');\n" |
| 3806 "void imported() {}\n" | 3776 "void imported() {}\n" |
| 3807 "void _imported() {}\n"; | 3777 "void _imported() {}\n"; |
| 3808 | 3778 |
| 3809 // Load lib1 | 3779 // Load lib1 |
| 3810 Dart_Handle url = Dart_NewString("library1_url"); | 3780 Dart_Handle url = NewString("library1_url"); |
| 3811 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 3781 Dart_Handle source = NewString(kLibrary1Chars); |
| 3812 Dart_Handle lib1 = Dart_LoadLibrary(url, source); | 3782 Dart_Handle lib1 = Dart_LoadLibrary(url, source); |
| 3813 EXPECT_VALID(lib1); | 3783 EXPECT_VALID(lib1); |
| 3814 | 3784 |
| 3815 // Load lib2 | 3785 // Load lib2 |
| 3816 url = Dart_NewString("library2_url"); | 3786 url = NewString("library2_url"); |
| 3817 source = Dart_NewString(kLibrary2Chars); | 3787 source = NewString(kLibrary2Chars); |
| 3818 Dart_Handle lib2 = Dart_LoadLibrary(url, source); | 3788 Dart_Handle lib2 = Dart_LoadLibrary(url, source); |
| 3819 EXPECT_VALID(lib2); | 3789 EXPECT_VALID(lib2); |
| 3820 | 3790 |
| 3821 // Import lib2 from lib1 | 3791 // Import lib2 from lib1 |
| 3822 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); | 3792 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); |
| 3823 EXPECT_VALID(result); | 3793 EXPECT_VALID(result); |
| 3824 | 3794 |
| 3825 // We can invoke both private and non-private local functions. | 3795 // We can invoke both private and non-private local functions. |
| 3826 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); | 3796 EXPECT_VALID(Dart_Invoke(lib1, NewString("local"), 0, NULL)); |
| 3827 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); | 3797 EXPECT_VALID(Dart_Invoke(lib1, NewString("_local"), 0, NULL)); |
| 3828 | 3798 |
| 3829 // We can only invoke non-private imported functions. | 3799 // We can only invoke non-private imported functions. |
| 3830 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("imported"), 0, NULL)); | 3800 EXPECT_VALID(Dart_Invoke(lib1, NewString("imported"), 0, NULL)); |
| 3831 EXPECT_ERROR(Dart_Invoke(lib1, Dart_NewString("_imported"), 0, NULL), | 3801 EXPECT_ERROR(Dart_Invoke(lib1, NewString("_imported"), 0, NULL), |
| 3832 "did not find top-level function '_imported'"); | 3802 "did not find top-level function '_imported'"); |
| 3833 } | 3803 } |
| 3834 | 3804 |
| 3835 TEST_CASE(ClosureFunction) { | 3805 TEST_CASE(ClosureFunction) { |
| 3836 const char* kScriptChars = | 3806 const char* kScriptChars = |
| 3837 "Function getClosure() {\n" | 3807 "Function getClosure() {\n" |
| 3838 " return (x, y, [z]) => x + y + z;\n" | 3808 " return (x, y, [z]) => x + y + z;\n" |
| 3839 "}\n" | 3809 "}\n" |
| 3840 "class Foo {\n" | 3810 "class Foo {\n" |
| 3841 " getInstanceClosure() {\n" | 3811 " getInstanceClosure() {\n" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3864 " return Foo.getStaticClosureWithArgs();\n" | 3834 " return Foo.getStaticClosureWithArgs();\n" |
| 3865 "}\n"; | 3835 "}\n"; |
| 3866 Dart_Handle result; | 3836 Dart_Handle result; |
| 3867 Dart_Handle owner; | 3837 Dart_Handle owner; |
| 3868 Dart_Handle defining_function; | 3838 Dart_Handle defining_function; |
| 3869 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3839 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 3870 | 3840 |
| 3871 // Create a test library and Load up a test script in it. | 3841 // Create a test library and Load up a test script in it. |
| 3872 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3842 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3873 EXPECT_VALID(lib); | 3843 EXPECT_VALID(lib); |
| 3874 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Foo")); | 3844 Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); |
| 3875 EXPECT_VALID(cls); | 3845 EXPECT_VALID(cls); |
| 3876 | 3846 |
| 3877 // Invoke a function which returns a closure. | 3847 // Invoke a function which returns a closure. |
| 3878 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("getClosure"), 0, NULL); | 3848 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); |
| 3879 EXPECT_VALID(retobj); | 3849 EXPECT_VALID(retobj); |
| 3880 | 3850 |
| 3881 EXPECT(Dart_IsClosure(retobj)); | 3851 EXPECT(Dart_IsClosure(retobj)); |
| 3882 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 3852 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
| 3883 | 3853 |
| 3884 // Retrieve the closure's function | 3854 // Retrieve the closure's function |
| 3885 result = Dart_ClosureFunction(retobj); | 3855 result = Dart_ClosureFunction(retobj); |
| 3886 EXPECT_VALID(result); | 3856 EXPECT_VALID(result); |
| 3887 EXPECT(Dart_IsFunction(result)); | 3857 EXPECT(Dart_IsFunction(result)); |
| 3888 owner = Dart_FunctionOwner(result); | 3858 owner = Dart_FunctionOwner(result); |
| 3889 EXPECT_VALID(owner); | 3859 EXPECT_VALID(owner); |
| 3890 defining_function = Dart_LookupFunction(lib, Dart_NewString("getClosure")); | 3860 defining_function = Dart_LookupFunction(lib, NewString("getClosure")); |
| 3891 EXPECT(Dart_IdentityEquals(owner, defining_function)); | 3861 EXPECT(Dart_IdentityEquals(owner, defining_function)); |
| 3892 int64_t fixed_param_count = -999; | 3862 int64_t fixed_param_count = -999; |
| 3893 int64_t opt_param_count = -999; | 3863 int64_t opt_param_count = -999; |
| 3894 result = Dart_FunctionParameterCounts(result, | 3864 result = Dart_FunctionParameterCounts(result, |
| 3895 &fixed_param_count, | 3865 &fixed_param_count, |
| 3896 &opt_param_count); | 3866 &opt_param_count); |
| 3897 EXPECT_VALID(result); | 3867 EXPECT_VALID(result); |
| 3898 EXPECT_EQ(2, fixed_param_count); | 3868 EXPECT_EQ(2, fixed_param_count); |
| 3899 EXPECT_EQ(1, opt_param_count); | 3869 EXPECT_EQ(1, opt_param_count); |
| 3900 | 3870 |
| 3901 // Try to retrieve function from a non-closure object | 3871 // Try to retrieve function from a non-closure object |
| 3902 result = Dart_ClosureFunction(Dart_NewInteger(1)); | 3872 result = Dart_ClosureFunction(Dart_NewInteger(1)); |
| 3903 EXPECT(Dart_IsError(result)); | 3873 EXPECT(Dart_IsError(result)); |
| 3904 | 3874 |
| 3905 // Invoke a function which returns an "instance" closure. | 3875 // Invoke a function which returns an "instance" closure. |
| 3906 retobj = Dart_Invoke(lib, Dart_NewString("getInstanceClosure"), 0, NULL); | 3876 retobj = Dart_Invoke(lib, NewString("getInstanceClosure"), 0, NULL); |
| 3907 EXPECT_VALID(retobj); | 3877 EXPECT_VALID(retobj); |
| 3908 EXPECT(Dart_IsClosure(retobj)); | 3878 EXPECT(Dart_IsClosure(retobj)); |
| 3909 | 3879 |
| 3910 // Retrieve the closure's function | 3880 // Retrieve the closure's function |
| 3911 result = Dart_ClosureFunction(retobj); | 3881 result = Dart_ClosureFunction(retobj); |
| 3912 EXPECT_VALID(result); | 3882 EXPECT_VALID(result); |
| 3913 EXPECT(Dart_IsFunction(result)); | 3883 EXPECT(Dart_IsFunction(result)); |
| 3914 owner = Dart_FunctionOwner(result); | 3884 owner = Dart_FunctionOwner(result); |
| 3915 EXPECT_VALID(owner); | 3885 EXPECT_VALID(owner); |
| 3916 defining_function = Dart_LookupFunction(cls, | 3886 defining_function = Dart_LookupFunction(cls, |
| 3917 Dart_NewString("getInstanceClosure")); | 3887 NewString("getInstanceClosure")); |
| 3918 EXPECT(Dart_IdentityEquals(owner, defining_function)); | 3888 EXPECT(Dart_IdentityEquals(owner, defining_function)); |
| 3919 // -999: We want to distinguish between a non-answer and a wrong answer, and | 3889 // -999: We want to distinguish between a non-answer and a wrong answer, and |
| 3920 // -1 has been a previous wrong answer | 3890 // -1 has been a previous wrong answer |
| 3921 fixed_param_count = -999; | 3891 fixed_param_count = -999; |
| 3922 opt_param_count = -999; | 3892 opt_param_count = -999; |
| 3923 result = Dart_FunctionParameterCounts(result, | 3893 result = Dart_FunctionParameterCounts(result, |
| 3924 &fixed_param_count, | 3894 &fixed_param_count, |
| 3925 &opt_param_count); | 3895 &opt_param_count); |
| 3926 EXPECT_VALID(result); | 3896 EXPECT_VALID(result); |
| 3927 EXPECT_EQ(0, fixed_param_count); | 3897 EXPECT_EQ(0, fixed_param_count); |
| 3928 EXPECT_EQ(0, opt_param_count); | 3898 EXPECT_EQ(0, opt_param_count); |
| 3929 | 3899 |
| 3930 // Invoke a function which returns an "instance" closure with arguments. | 3900 // Invoke a function which returns an "instance" closure with arguments. |
| 3931 retobj = Dart_Invoke(lib, | 3901 retobj = Dart_Invoke(lib, |
| 3932 Dart_NewString("getInstanceClosureWithArgs"), | 3902 NewString("getInstanceClosureWithArgs"), |
| 3933 0, | 3903 0, |
| 3934 NULL); | 3904 NULL); |
| 3935 EXPECT_VALID(retobj); | 3905 EXPECT_VALID(retobj); |
| 3936 EXPECT(Dart_IsClosure(retobj)); | 3906 EXPECT(Dart_IsClosure(retobj)); |
| 3937 | 3907 |
| 3938 // Retrieve the closure's function | 3908 // Retrieve the closure's function |
| 3939 result = Dart_ClosureFunction(retobj); | 3909 result = Dart_ClosureFunction(retobj); |
| 3940 EXPECT_VALID(result); | 3910 EXPECT_VALID(result); |
| 3941 EXPECT(Dart_IsFunction(result)); | 3911 EXPECT(Dart_IsFunction(result)); |
| 3942 owner = Dart_FunctionOwner(result); | 3912 owner = Dart_FunctionOwner(result); |
| 3943 EXPECT_VALID(owner); | 3913 EXPECT_VALID(owner); |
| 3944 defining_function = | 3914 defining_function = |
| 3945 Dart_LookupFunction(cls, Dart_NewString("getInstanceClosureWithArgs")); | 3915 Dart_LookupFunction(cls, NewString("getInstanceClosureWithArgs")); |
| 3946 EXPECT(Dart_IdentityEquals(owner, defining_function)); | 3916 EXPECT(Dart_IdentityEquals(owner, defining_function)); |
| 3947 // -999: We want to distinguish between a non-answer and a wrong answer, and | 3917 // -999: We want to distinguish between a non-answer and a wrong answer, and |
| 3948 // -1 has been a previous wrong answer | 3918 // -1 has been a previous wrong answer |
| 3949 fixed_param_count = -999; | 3919 fixed_param_count = -999; |
| 3950 opt_param_count = -999; | 3920 opt_param_count = -999; |
| 3951 result = Dart_FunctionParameterCounts(result, | 3921 result = Dart_FunctionParameterCounts(result, |
| 3952 &fixed_param_count, | 3922 &fixed_param_count, |
| 3953 &opt_param_count); | 3923 &opt_param_count); |
| 3954 EXPECT_VALID(result); | 3924 EXPECT_VALID(result); |
| 3955 EXPECT_EQ(2, fixed_param_count); | 3925 EXPECT_EQ(2, fixed_param_count); |
| 3956 EXPECT_EQ(1, opt_param_count); | 3926 EXPECT_EQ(1, opt_param_count); |
| 3957 | 3927 |
| 3958 // Invoke a function which returns a "static" closure. | 3928 // Invoke a function which returns a "static" closure. |
| 3959 retobj = Dart_Invoke(lib, Dart_NewString("getStaticClosure"), 0, NULL); | 3929 retobj = Dart_Invoke(lib, NewString("getStaticClosure"), 0, NULL); |
| 3960 EXPECT_VALID(retobj); | 3930 EXPECT_VALID(retobj); |
| 3961 EXPECT(Dart_IsClosure(retobj)); | 3931 EXPECT(Dart_IsClosure(retobj)); |
| 3962 | 3932 |
| 3963 // Retrieve the closure's function | 3933 // Retrieve the closure's function |
| 3964 result = Dart_ClosureFunction(retobj); | 3934 result = Dart_ClosureFunction(retobj); |
| 3965 EXPECT_VALID(result); | 3935 EXPECT_VALID(result); |
| 3966 EXPECT(Dart_IsFunction(result)); | 3936 EXPECT(Dart_IsFunction(result)); |
| 3967 owner = Dart_FunctionOwner(result); | 3937 owner = Dart_FunctionOwner(result); |
| 3968 EXPECT_VALID(owner); | 3938 EXPECT_VALID(owner); |
| 3969 defining_function = Dart_LookupFunction(cls, | 3939 defining_function = Dart_LookupFunction(cls, |
| 3970 Dart_NewString("getStaticClosure")); | 3940 NewString("getStaticClosure")); |
| 3971 EXPECT(Dart_IdentityEquals(owner, defining_function)); | 3941 EXPECT(Dart_IdentityEquals(owner, defining_function)); |
| 3972 // -999: We want to distinguish between a non-answer and a wrong answer, and | 3942 // -999: We want to distinguish between a non-answer and a wrong answer, and |
| 3973 // -1 has been a previous wrong answer | 3943 // -1 has been a previous wrong answer |
| 3974 fixed_param_count = -999; | 3944 fixed_param_count = -999; |
| 3975 opt_param_count = -999; | 3945 opt_param_count = -999; |
| 3976 result = Dart_FunctionParameterCounts(result, | 3946 result = Dart_FunctionParameterCounts(result, |
| 3977 &fixed_param_count, | 3947 &fixed_param_count, |
| 3978 &opt_param_count); | 3948 &opt_param_count); |
| 3979 EXPECT_VALID(result); | 3949 EXPECT_VALID(result); |
| 3980 EXPECT_EQ(0, fixed_param_count); | 3950 EXPECT_EQ(0, fixed_param_count); |
| 3981 EXPECT_EQ(0, opt_param_count); | 3951 EXPECT_EQ(0, opt_param_count); |
| 3982 | 3952 |
| 3983 | 3953 |
| 3984 // Invoke a function which returns a "static" closure with arguments. | 3954 // Invoke a function which returns a "static" closure with arguments. |
| 3985 retobj = Dart_Invoke(lib, | 3955 retobj = Dart_Invoke(lib, |
| 3986 Dart_NewString("getStaticClosureWithArgs"), | 3956 NewString("getStaticClosureWithArgs"), |
| 3987 0, | 3957 0, |
| 3988 NULL); | 3958 NULL); |
| 3989 EXPECT_VALID(retobj); | 3959 EXPECT_VALID(retobj); |
| 3990 EXPECT(Dart_IsClosure(retobj)); | 3960 EXPECT(Dart_IsClosure(retobj)); |
| 3991 | 3961 |
| 3992 // Retrieve the closure's function | 3962 // Retrieve the closure's function |
| 3993 result = Dart_ClosureFunction(retobj); | 3963 result = Dart_ClosureFunction(retobj); |
| 3994 EXPECT_VALID(result); | 3964 EXPECT_VALID(result); |
| 3995 EXPECT(Dart_IsFunction(result)); | 3965 EXPECT(Dart_IsFunction(result)); |
| 3996 owner = Dart_FunctionOwner(result); | 3966 owner = Dart_FunctionOwner(result); |
| 3997 EXPECT_VALID(owner); | 3967 EXPECT_VALID(owner); |
| 3998 defining_function = | 3968 defining_function = |
| 3999 Dart_LookupFunction(cls, Dart_NewString("getStaticClosureWithArgs")); | 3969 Dart_LookupFunction(cls, NewString("getStaticClosureWithArgs")); |
| 4000 EXPECT(Dart_IdentityEquals(owner, defining_function)); | 3970 EXPECT(Dart_IdentityEquals(owner, defining_function)); |
| 4001 // -999: We want to distinguish between a non-answer and a wrong answer, and | 3971 // -999: We want to distinguish between a non-answer and a wrong answer, and |
| 4002 // -1 has been a previous wrong answer | 3972 // -1 has been a previous wrong answer |
| 4003 fixed_param_count = -999; | 3973 fixed_param_count = -999; |
| 4004 opt_param_count = -999; | 3974 opt_param_count = -999; |
| 4005 result = Dart_FunctionParameterCounts(result, | 3975 result = Dart_FunctionParameterCounts(result, |
| 4006 &fixed_param_count, | 3976 &fixed_param_count, |
| 4007 &opt_param_count); | 3977 &opt_param_count); |
| 4008 EXPECT_VALID(result); | 3978 EXPECT_VALID(result); |
| 4009 EXPECT_EQ(2, fixed_param_count); | 3979 EXPECT_EQ(2, fixed_param_count); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4033 "Function testMain2() {\n" | 4003 "Function testMain2() {\n" |
| 4034 " return InvokeClosure.method2(10);\n" | 4004 " return InvokeClosure.method2(10);\n" |
| 4035 "}\n"; | 4005 "}\n"; |
| 4036 Dart_Handle result; | 4006 Dart_Handle result; |
| 4037 DARTSCOPE_NOCHECKS(Isolate::Current()); | 4007 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 4038 | 4008 |
| 4039 // Create a test library and Load up a test script in it. | 4009 // Create a test library and Load up a test script in it. |
| 4040 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4010 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4041 | 4011 |
| 4042 // Invoke a function which returns a closure. | 4012 // Invoke a function which returns a closure. |
| 4043 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain1"), 0, NULL); | 4013 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
| 4044 EXPECT_VALID(retobj); | 4014 EXPECT_VALID(retobj); |
| 4045 | 4015 |
| 4046 EXPECT(Dart_IsClosure(retobj)); | 4016 EXPECT(Dart_IsClosure(retobj)); |
| 4047 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 4017 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
| 4048 | 4018 |
| 4049 // Now invoke the closure and check the result. | 4019 // Now invoke the closure and check the result. |
| 4050 Dart_Handle dart_arguments[1]; | 4020 Dart_Handle dart_arguments[1]; |
| 4051 dart_arguments[0] = Dart_NewInteger(1); | 4021 dart_arguments[0] = Dart_NewInteger(1); |
| 4052 result = Dart_InvokeClosure(retobj, 1, dart_arguments); | 4022 result = Dart_InvokeClosure(retobj, 1, dart_arguments); |
| 4053 EXPECT_VALID(result); | 4023 EXPECT_VALID(result); |
| 4054 EXPECT(Dart_IsInteger(result)); | 4024 EXPECT(Dart_IsInteger(result)); |
| 4055 int64_t value = 0; | 4025 int64_t value = 0; |
| 4056 result = Dart_IntegerToInt64(result, &value); | 4026 result = Dart_IntegerToInt64(result, &value); |
| 4057 EXPECT_EQ(51, value); | 4027 EXPECT_EQ(51, value); |
| 4058 | 4028 |
| 4059 // Invoke closure with wrong number of args, should result in exception. | 4029 // Invoke closure with wrong number of args, should result in exception. |
| 4060 result = Dart_InvokeClosure(retobj, 0, NULL); | 4030 result = Dart_InvokeClosure(retobj, 0, NULL); |
| 4061 EXPECT(Dart_IsError(result)); | 4031 EXPECT(Dart_IsError(result)); |
| 4062 EXPECT(Dart_ErrorHasException(result)); | 4032 EXPECT(Dart_ErrorHasException(result)); |
| 4063 | 4033 |
| 4064 // Invoke a function which returns a closure. | 4034 // Invoke a function which returns a closure. |
| 4065 retobj = Dart_Invoke(lib, Dart_NewString("testMain2"), 0, NULL); | 4035 retobj = Dart_Invoke(lib, NewString("testMain2"), 0, NULL); |
| 4066 EXPECT_VALID(retobj); | 4036 EXPECT_VALID(retobj); |
| 4067 | 4037 |
| 4068 EXPECT(Dart_IsClosure(retobj)); | 4038 EXPECT(Dart_IsClosure(retobj)); |
| 4069 EXPECT(!Dart_IsClosure(Dart_NewString("abcdef"))); | 4039 EXPECT(!Dart_IsClosure(NewString("abcdef"))); |
| 4070 | 4040 |
| 4071 // Now invoke the closure and check the result (should be an exception). | 4041 // Now invoke the closure and check the result (should be an exception). |
| 4072 dart_arguments[0] = Dart_NewInteger(1); | 4042 dart_arguments[0] = Dart_NewInteger(1); |
| 4073 result = Dart_InvokeClosure(retobj, 1, dart_arguments); | 4043 result = Dart_InvokeClosure(retobj, 1, dart_arguments); |
| 4074 EXPECT(Dart_IsError(result)); | 4044 EXPECT(Dart_IsError(result)); |
| 4075 EXPECT(Dart_ErrorHasException(result)); | 4045 EXPECT(Dart_ErrorHasException(result)); |
| 4076 } | 4046 } |
| 4077 | 4047 |
| 4078 | 4048 |
| 4079 void ExceptionNative(Dart_NativeArguments args) { | 4049 void ExceptionNative(Dart_NativeArguments args) { |
| 4080 Dart_EnterScope(); | 4050 Dart_EnterScope(); |
| 4081 Dart_ThrowException(Dart_NewString("Hello from ExceptionNative!")); | 4051 Dart_ThrowException(NewString("Hello from ExceptionNative!")); |
| 4082 UNREACHABLE(); | 4052 UNREACHABLE(); |
| 4083 } | 4053 } |
| 4084 | 4054 |
| 4085 | 4055 |
| 4086 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) { | 4056 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) { |
| 4087 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); | 4057 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); |
| 4088 } | 4058 } |
| 4089 | 4059 |
| 4090 | 4060 |
| 4091 TEST_CASE(ThrowException) { | 4061 TEST_CASE(ThrowException) { |
| 4092 const char* kScriptChars = | 4062 const char* kScriptChars = |
| 4093 "int test() native \"ThrowException_native\";"; | 4063 "int test() native \"ThrowException_native\";"; |
| 4094 Dart_Handle result; | 4064 Dart_Handle result; |
| 4095 Isolate* isolate = Isolate::Current(); | 4065 Isolate* isolate = Isolate::Current(); |
| 4096 EXPECT(isolate != NULL); | 4066 EXPECT(isolate != NULL); |
| 4097 ApiState* state = isolate->api_state(); | 4067 ApiState* state = isolate->api_state(); |
| 4098 EXPECT(state != NULL); | 4068 EXPECT(state != NULL); |
| 4099 intptr_t size = state->ZoneSizeInBytes(); | 4069 intptr_t size = state->ZoneSizeInBytes(); |
| 4100 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 4070 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 4101 | 4071 |
| 4102 // Load up a test script which extends the native wrapper class. | 4072 // Load up a test script which extends the native wrapper class. |
| 4103 Dart_Handle lib = TestCase::LoadTestScript( | 4073 Dart_Handle lib = TestCase::LoadTestScript( |
| 4104 kScriptChars, | 4074 kScriptChars, |
| 4105 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | 4075 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
| 4106 | 4076 |
| 4107 // Throwing an exception here should result in an error. | 4077 // Throwing an exception here should result in an error. |
| 4108 result = Dart_ThrowException(Dart_NewString("This doesn't work")); | 4078 result = Dart_ThrowException(NewString("This doesn't work")); |
| 4109 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); | 4079 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); |
| 4110 EXPECT(!Dart_ErrorHasException(result)); | 4080 EXPECT(!Dart_ErrorHasException(result)); |
| 4111 | 4081 |
| 4112 // Invoke 'test' and check for an uncaught exception. | 4082 // Invoke 'test' and check for an uncaught exception. |
| 4113 result = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); | 4083 result = Dart_Invoke(lib, NewString("test"), 0, NULL); |
| 4114 EXPECT_ERROR(result, "Hello from ExceptionNative!"); | 4084 EXPECT_ERROR(result, "Hello from ExceptionNative!"); |
| 4115 EXPECT(Dart_ErrorHasException(result)); | 4085 EXPECT(Dart_ErrorHasException(result)); |
| 4116 | 4086 |
| 4117 Dart_ExitScope(); // Exit the Dart API scope. | 4087 Dart_ExitScope(); // Exit the Dart API scope. |
| 4118 EXPECT_EQ(size, state->ZoneSizeInBytes()); | 4088 EXPECT_EQ(size, state->ZoneSizeInBytes()); |
| 4119 } | 4089 } |
| 4120 | 4090 |
| 4121 | 4091 |
| 4122 void NativeArgumentCounter(Dart_NativeArguments args) { | 4092 void NativeArgumentCounter(Dart_NativeArguments args) { |
| 4123 Dart_EnterScope(); | 4093 Dart_EnterScope(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4139 "}" | 4109 "}" |
| 4140 "testMain() {" | 4110 "testMain() {" |
| 4141 " MyObject obj = new MyObject();" | 4111 " MyObject obj = new MyObject();" |
| 4142 " return obj.method1(77, 125);" | 4112 " return obj.method1(77, 125);" |
| 4143 "}"; | 4113 "}"; |
| 4144 | 4114 |
| 4145 Dart_Handle lib = TestCase::LoadTestScript( | 4115 Dart_Handle lib = TestCase::LoadTestScript( |
| 4146 kScriptChars, | 4116 kScriptChars, |
| 4147 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); | 4117 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); |
| 4148 | 4118 |
| 4149 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 4119 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 4150 EXPECT_VALID(result); | 4120 EXPECT_VALID(result); |
| 4151 EXPECT(Dart_IsInteger(result)); | 4121 EXPECT(Dart_IsInteger(result)); |
| 4152 | 4122 |
| 4153 int64_t value = 0; | 4123 int64_t value = 0; |
| 4154 result = Dart_IntegerToInt64(result, &value); | 4124 result = Dart_IntegerToInt64(result, &value); |
| 4155 EXPECT_VALID(result); | 4125 EXPECT_VALID(result); |
| 4156 EXPECT_EQ(3, value); | 4126 EXPECT_EQ(3, value); |
| 4157 } | 4127 } |
| 4158 | 4128 |
| 4159 | 4129 |
| 4160 TEST_CASE(GetClass) { | 4130 TEST_CASE(GetClass) { |
| 4161 const char* kScriptChars = | 4131 const char* kScriptChars = |
| 4162 "class Class {\n" | 4132 "class Class {\n" |
| 4163 " static var name = 'Class';\n" | 4133 " static var name = 'Class';\n" |
| 4164 "}\n" | 4134 "}\n" |
| 4165 "\n" | 4135 "\n" |
| 4166 "class _Class {\n" | 4136 "class _Class {\n" |
| 4167 " static var name = '_Class';\n" | 4137 " static var name = '_Class';\n" |
| 4168 "}\n"; | 4138 "}\n"; |
| 4169 | 4139 |
| 4170 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4140 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4171 | 4141 |
| 4172 // Lookup a class. | 4142 // Lookup a class. |
| 4173 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Class")); | 4143 Dart_Handle cls = Dart_GetClass(lib, NewString("Class")); |
| 4174 EXPECT_VALID(cls); | 4144 EXPECT_VALID(cls); |
| 4175 Dart_Handle name = Dart_GetField(cls, Dart_NewString("name")); | 4145 Dart_Handle name = Dart_GetField(cls, NewString("name")); |
| 4176 EXPECT_VALID(name); | 4146 EXPECT_VALID(name); |
| 4177 const char* name_cstr = ""; | 4147 const char* name_cstr = ""; |
| 4178 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); | 4148 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); |
| 4179 EXPECT_STREQ("Class", name_cstr); | 4149 EXPECT_STREQ("Class", name_cstr); |
| 4180 | 4150 |
| 4181 // Lookup a private class. | 4151 // Lookup a private class. |
| 4182 cls = Dart_GetClass(lib, Dart_NewString("_Class")); | 4152 cls = Dart_GetClass(lib, NewString("_Class")); |
| 4183 EXPECT_VALID(cls); | 4153 EXPECT_VALID(cls); |
| 4184 name = Dart_GetField(cls, Dart_NewString("name")); | 4154 name = Dart_GetField(cls, NewString("name")); |
| 4185 EXPECT_VALID(name); | 4155 EXPECT_VALID(name); |
| 4186 name_cstr = ""; | 4156 name_cstr = ""; |
| 4187 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); | 4157 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); |
| 4188 EXPECT_STREQ("_Class", name_cstr); | 4158 EXPECT_STREQ("_Class", name_cstr); |
| 4189 | 4159 |
| 4190 // Lookup a class that does not exist. | 4160 // Lookup a class that does not exist. |
| 4191 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist")); | 4161 cls = Dart_GetClass(lib, NewString("DoesNotExist")); |
| 4192 EXPECT(Dart_IsError(cls)); | 4162 EXPECT(Dart_IsError(cls)); |
| 4193 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.", | 4163 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.", |
| 4194 Dart_GetError(cls)); | 4164 Dart_GetError(cls)); |
| 4195 | 4165 |
| 4196 // Lookup a class from an error library. The error propagates. | 4166 // Lookup a class from an error library. The error propagates. |
| 4197 cls = Dart_GetClass(Api::NewError("myerror"), Dart_NewString("Class")); | 4167 cls = Dart_GetClass(Api::NewError("myerror"), NewString("Class")); |
| 4198 EXPECT(Dart_IsError(cls)); | 4168 EXPECT(Dart_IsError(cls)); |
| 4199 EXPECT_STREQ("myerror", Dart_GetError(cls)); | 4169 EXPECT_STREQ("myerror", Dart_GetError(cls)); |
| 4200 | 4170 |
| 4201 // Lookup a class using an error class name. The error propagates. | 4171 // Lookup a class using an error class name. The error propagates. |
| 4202 cls = Dart_GetClass(lib, Api::NewError("myerror")); | 4172 cls = Dart_GetClass(lib, Api::NewError("myerror")); |
| 4203 EXPECT(Dart_IsError(cls)); | 4173 EXPECT(Dart_IsError(cls)); |
| 4204 EXPECT_STREQ("myerror", Dart_GetError(cls)); | 4174 EXPECT_STREQ("myerror", Dart_GetError(cls)); |
| 4205 } | 4175 } |
| 4206 | 4176 |
| 4207 | 4177 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4285 " t([x, y, z]) {}\n" | 4255 " t([x, y, z]) {}\n" |
| 4286 " operator ==(x) {}\n" | 4256 " operator ==(x) {}\n" |
| 4287 "}\n" | 4257 "}\n" |
| 4288 "class _PrivateClass {\n" | 4258 "class _PrivateClass {\n" |
| 4289 " _PrivateClass() {}\n" | 4259 " _PrivateClass() {}\n" |
| 4290 " _PrivateClass.named() {}\n" | 4260 " _PrivateClass.named() {}\n" |
| 4291 "}\n"; | 4261 "}\n"; |
| 4292 | 4262 |
| 4293 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4263 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4294 EXPECT_VALID(lib); | 4264 EXPECT_VALID(lib); |
| 4295 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); | 4265 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); |
| 4296 EXPECT_VALID(cls); | 4266 EXPECT_VALID(cls); |
| 4297 Dart_Handle private_cls = Dart_GetClass(lib, Dart_NewString("_PrivateClass")); | 4267 Dart_Handle private_cls = Dart_GetClass(lib, NewString("_PrivateClass")); |
| 4298 EXPECT_VALID(private_cls); | 4268 EXPECT_VALID(private_cls); |
| 4299 TextBuffer buffer(128); | 4269 TextBuffer buffer(128); |
| 4300 | 4270 |
| 4301 // Lookup a top-level function. | 4271 // Lookup a top-level function. |
| 4302 Dart_Handle func = Dart_LookupFunction(lib, Dart_NewString("a")); | 4272 Dart_Handle func = Dart_LookupFunction(lib, NewString("a")); |
| 4303 EXPECT_VALID(func); | 4273 EXPECT_VALID(func); |
| 4304 EXPECT(Dart_IsFunction(func)); | 4274 EXPECT(Dart_IsFunction(func)); |
| 4305 BuildFunctionDescription(&buffer, func); | 4275 BuildFunctionDescription(&buffer, func); |
| 4306 EXPECT_STREQ("a 0 0 static", buffer.buf()); | 4276 EXPECT_STREQ("a 0 0 static", buffer.buf()); |
| 4307 EXPECT(Dart_IsLibrary(Dart_FunctionOwner(func))); | 4277 EXPECT(Dart_IsLibrary(Dart_FunctionOwner(func))); |
| 4308 Dart_Handle owner = Dart_FunctionOwner(func); | 4278 Dart_Handle owner = Dart_FunctionOwner(func); |
| 4309 EXPECT_VALID(owner); | 4279 EXPECT_VALID(owner); |
| 4310 EXPECT(Dart_IdentityEquals(owner, lib)); | 4280 EXPECT(Dart_IdentityEquals(owner, lib)); |
| 4311 | 4281 |
| 4312 // Lookup a private top-level function. | 4282 // Lookup a private top-level function. |
| 4313 func = Dart_LookupFunction(lib, Dart_NewString("_b")); | 4283 func = Dart_LookupFunction(lib, NewString("_b")); |
| 4314 EXPECT_VALID(func); | 4284 EXPECT_VALID(func); |
| 4315 EXPECT(Dart_IsFunction(func)); | 4285 EXPECT(Dart_IsFunction(func)); |
| 4316 BuildFunctionDescription(&buffer, func); | 4286 BuildFunctionDescription(&buffer, func); |
| 4317 EXPECT_STREQ("_b 0 0 static", buffer.buf()); | 4287 EXPECT_STREQ("_b 0 0 static", buffer.buf()); |
| 4318 owner = Dart_FunctionOwner(func); | 4288 owner = Dart_FunctionOwner(func); |
| 4319 EXPECT_VALID(owner); | 4289 EXPECT_VALID(owner); |
| 4320 EXPECT(Dart_IdentityEquals(owner, lib)); | 4290 EXPECT(Dart_IdentityEquals(owner, lib)); |
| 4321 | 4291 |
| 4322 // Lookup a top-level getter. | 4292 // Lookup a top-level getter. |
| 4323 func = Dart_LookupFunction(lib, Dart_NewString("c")); | 4293 func = Dart_LookupFunction(lib, NewString("c")); |
| 4324 EXPECT_VALID(func); | 4294 EXPECT_VALID(func); |
| 4325 EXPECT(Dart_IsFunction(func)); | 4295 EXPECT(Dart_IsFunction(func)); |
| 4326 BuildFunctionDescription(&buffer, func); | 4296 BuildFunctionDescription(&buffer, func); |
| 4327 EXPECT_STREQ("c 0 0 static getter", buffer.buf()); | 4297 EXPECT_STREQ("c 0 0 static getter", buffer.buf()); |
| 4328 owner = Dart_FunctionOwner(func); | 4298 owner = Dart_FunctionOwner(func); |
| 4329 EXPECT_VALID(owner); | 4299 EXPECT_VALID(owner); |
| 4330 EXPECT(Dart_IdentityEquals(owner, lib)); | 4300 EXPECT(Dart_IdentityEquals(owner, lib)); |
| 4331 | 4301 |
| 4332 // Lookup a top-level setter. | 4302 // Lookup a top-level setter. |
| 4333 func = Dart_LookupFunction(lib, Dart_NewString("d=")); | 4303 func = Dart_LookupFunction(lib, NewString("d=")); |
| 4334 EXPECT_VALID(func); | 4304 EXPECT_VALID(func); |
| 4335 EXPECT(Dart_IsFunction(func)); | 4305 EXPECT(Dart_IsFunction(func)); |
| 4336 BuildFunctionDescription(&buffer, func); | 4306 BuildFunctionDescription(&buffer, func); |
| 4337 EXPECT_STREQ("d= 1 0 static setter", buffer.buf()); | 4307 EXPECT_STREQ("d= 1 0 static setter", buffer.buf()); |
| 4338 owner = Dart_FunctionOwner(func); | 4308 owner = Dart_FunctionOwner(func); |
| 4339 EXPECT_VALID(owner); | 4309 EXPECT_VALID(owner); |
| 4340 EXPECT(Dart_IdentityEquals(owner, lib)); | 4310 EXPECT(Dart_IdentityEquals(owner, lib)); |
| 4341 | 4311 |
| 4342 // Lookup a private top-level getter. | 4312 // Lookup a private top-level getter. |
| 4343 func = Dart_LookupFunction(lib, Dart_NewString("_e")); | 4313 func = Dart_LookupFunction(lib, NewString("_e")); |
| 4344 EXPECT_VALID(func); | 4314 EXPECT_VALID(func); |
| 4345 EXPECT(Dart_IsFunction(func)); | 4315 EXPECT(Dart_IsFunction(func)); |
| 4346 BuildFunctionDescription(&buffer, func); | 4316 BuildFunctionDescription(&buffer, func); |
| 4347 EXPECT_STREQ("_e 0 0 static getter", buffer.buf()); | 4317 EXPECT_STREQ("_e 0 0 static getter", buffer.buf()); |
| 4348 owner = Dart_FunctionOwner(func); | 4318 owner = Dart_FunctionOwner(func); |
| 4349 EXPECT_VALID(owner); | 4319 EXPECT_VALID(owner); |
| 4350 EXPECT(Dart_IdentityEquals(owner, lib)); | 4320 EXPECT(Dart_IdentityEquals(owner, lib)); |
| 4351 | 4321 |
| 4352 // Lookup a private top-level setter. | 4322 // Lookup a private top-level setter. |
| 4353 func = Dart_LookupFunction(lib, Dart_NewString("_f=")); | 4323 func = Dart_LookupFunction(lib, NewString("_f=")); |
| 4354 EXPECT_VALID(func); | 4324 EXPECT_VALID(func); |
| 4355 EXPECT(Dart_IsFunction(func)); | 4325 EXPECT(Dart_IsFunction(func)); |
| 4356 BuildFunctionDescription(&buffer, func); | 4326 BuildFunctionDescription(&buffer, func); |
| 4357 EXPECT_STREQ("_f= 1 0 static setter", buffer.buf()); | 4327 EXPECT_STREQ("_f= 1 0 static setter", buffer.buf()); |
| 4358 owner = Dart_FunctionOwner(func); | 4328 owner = Dart_FunctionOwner(func); |
| 4359 EXPECT_VALID(owner); | 4329 EXPECT_VALID(owner); |
| 4360 EXPECT(Dart_IdentityEquals(owner, lib)); | 4330 EXPECT(Dart_IdentityEquals(owner, lib)); |
| 4361 | 4331 |
| 4362 // Lookup an unnamed constructor | 4332 // Lookup an unnamed constructor |
| 4363 func = Dart_LookupFunction(cls, Dart_NewString("MyClass")); | 4333 func = Dart_LookupFunction(cls, NewString("MyClass")); |
| 4364 EXPECT_VALID(func); | 4334 EXPECT_VALID(func); |
| 4365 EXPECT(Dart_IsFunction(func)); | 4335 EXPECT(Dart_IsFunction(func)); |
| 4366 BuildFunctionDescription(&buffer, func); | 4336 BuildFunctionDescription(&buffer, func); |
| 4367 EXPECT_STREQ("MyClass 0 0 constructor", buffer.buf()); | 4337 EXPECT_STREQ("MyClass 0 0 constructor", buffer.buf()); |
| 4368 owner = Dart_FunctionOwner(func); | 4338 owner = Dart_FunctionOwner(func); |
| 4369 EXPECT_VALID(owner); | 4339 EXPECT_VALID(owner); |
| 4370 EXPECT(Dart_IdentityEquals(owner, cls)); | 4340 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4371 | 4341 |
| 4372 // Lookup a named constructor | 4342 // Lookup a named constructor |
| 4373 func = Dart_LookupFunction(cls, Dart_NewString("MyClass.named")); | 4343 func = Dart_LookupFunction(cls, NewString("MyClass.named")); |
| 4374 EXPECT_VALID(func); | 4344 EXPECT_VALID(func); |
| 4375 EXPECT(Dart_IsFunction(func)); | 4345 EXPECT(Dart_IsFunction(func)); |
| 4376 BuildFunctionDescription(&buffer, func); | 4346 BuildFunctionDescription(&buffer, func); |
| 4377 EXPECT_STREQ("MyClass.named 0 0 constructor", buffer.buf()); | 4347 EXPECT_STREQ("MyClass.named 0 0 constructor", buffer.buf()); |
| 4378 owner = Dart_FunctionOwner(func); | 4348 owner = Dart_FunctionOwner(func); |
| 4379 EXPECT_VALID(owner); | 4349 EXPECT_VALID(owner); |
| 4380 EXPECT(Dart_IdentityEquals(owner, cls)); | 4350 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4381 | 4351 |
| 4382 // Lookup an private unnamed constructor | 4352 // Lookup an private unnamed constructor |
| 4383 func = Dart_LookupFunction(private_cls, Dart_NewString("_PrivateClass")); | 4353 func = Dart_LookupFunction(private_cls, NewString("_PrivateClass")); |
| 4384 EXPECT_VALID(func); | 4354 EXPECT_VALID(func); |
| 4385 EXPECT(Dart_IsFunction(func)); | 4355 EXPECT(Dart_IsFunction(func)); |
| 4386 BuildFunctionDescription(&buffer, func); | 4356 BuildFunctionDescription(&buffer, func); |
| 4387 EXPECT_STREQ("_PrivateClass 0 0 constructor", buffer.buf()); | 4357 EXPECT_STREQ("_PrivateClass 0 0 constructor", buffer.buf()); |
| 4388 owner = Dart_FunctionOwner(func); | 4358 owner = Dart_FunctionOwner(func); |
| 4389 EXPECT_VALID(owner); | 4359 EXPECT_VALID(owner); |
| 4390 EXPECT(Dart_IdentityEquals(owner, private_cls)); | 4360 EXPECT(Dart_IdentityEquals(owner, private_cls)); |
| 4391 | 4361 |
| 4392 // Lookup a private named constructor | 4362 // Lookup a private named constructor |
| 4393 func = Dart_LookupFunction(private_cls, | 4363 func = Dart_LookupFunction(private_cls, |
| 4394 Dart_NewString("_PrivateClass.named")); | 4364 NewString("_PrivateClass.named")); |
| 4395 EXPECT_VALID(func); | 4365 EXPECT_VALID(func); |
| 4396 EXPECT(Dart_IsFunction(func)); | 4366 EXPECT(Dart_IsFunction(func)); |
| 4397 BuildFunctionDescription(&buffer, func); | 4367 BuildFunctionDescription(&buffer, func); |
| 4398 EXPECT_STREQ("_PrivateClass.named 0 0 constructor", buffer.buf()); | 4368 EXPECT_STREQ("_PrivateClass.named 0 0 constructor", buffer.buf()); |
| 4399 owner = Dart_FunctionOwner(func); | 4369 owner = Dart_FunctionOwner(func); |
| 4400 EXPECT_VALID(owner); | 4370 EXPECT_VALID(owner); |
| 4401 EXPECT(Dart_IdentityEquals(owner, private_cls)); | 4371 EXPECT(Dart_IdentityEquals(owner, private_cls)); |
| 4402 | 4372 |
| 4403 // Lookup a method. | 4373 // Lookup a method. |
| 4404 func = Dart_LookupFunction(cls, Dart_NewString("a")); | 4374 func = Dart_LookupFunction(cls, NewString("a")); |
| 4405 EXPECT_VALID(func); | 4375 EXPECT_VALID(func); |
| 4406 EXPECT(Dart_IsFunction(func)); | 4376 EXPECT(Dart_IsFunction(func)); |
| 4407 BuildFunctionDescription(&buffer, func); | 4377 BuildFunctionDescription(&buffer, func); |
| 4408 EXPECT_STREQ("a 0 0", buffer.buf()); | 4378 EXPECT_STREQ("a 0 0", buffer.buf()); |
| 4409 owner = Dart_FunctionOwner(func); | 4379 owner = Dart_FunctionOwner(func); |
| 4410 EXPECT_VALID(owner); | 4380 EXPECT_VALID(owner); |
| 4411 EXPECT(Dart_IdentityEquals(owner, cls)); | 4381 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4412 | 4382 |
| 4413 // Lookup a private method. | 4383 // Lookup a private method. |
| 4414 func = Dart_LookupFunction(cls, Dart_NewString("_b")); | 4384 func = Dart_LookupFunction(cls, NewString("_b")); |
| 4415 EXPECT_VALID(func); | 4385 EXPECT_VALID(func); |
| 4416 EXPECT(Dart_IsFunction(func)); | 4386 EXPECT(Dart_IsFunction(func)); |
| 4417 BuildFunctionDescription(&buffer, func); | 4387 BuildFunctionDescription(&buffer, func); |
| 4418 EXPECT_STREQ("_b 0 0", buffer.buf()); | 4388 EXPECT_STREQ("_b 0 0", buffer.buf()); |
| 4419 owner = Dart_FunctionOwner(func); | 4389 owner = Dart_FunctionOwner(func); |
| 4420 EXPECT_VALID(owner); | 4390 EXPECT_VALID(owner); |
| 4421 EXPECT(Dart_IdentityEquals(owner, cls)); | 4391 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4422 | 4392 |
| 4423 // Lookup a instance getter. | 4393 // Lookup a instance getter. |
| 4424 func = Dart_LookupFunction(cls, Dart_NewString("c")); | 4394 func = Dart_LookupFunction(cls, NewString("c")); |
| 4425 EXPECT_VALID(func); | 4395 EXPECT_VALID(func); |
| 4426 EXPECT(Dart_IsFunction(func)); | 4396 EXPECT(Dart_IsFunction(func)); |
| 4427 BuildFunctionDescription(&buffer, func); | 4397 BuildFunctionDescription(&buffer, func); |
| 4428 EXPECT_STREQ("c 0 0 getter", buffer.buf()); | 4398 EXPECT_STREQ("c 0 0 getter", buffer.buf()); |
| 4429 owner = Dart_FunctionOwner(func); | 4399 owner = Dart_FunctionOwner(func); |
| 4430 EXPECT_VALID(owner); | 4400 EXPECT_VALID(owner); |
| 4431 EXPECT(Dart_IdentityEquals(owner, cls)); | 4401 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4432 | 4402 |
| 4433 // Lookup a instance setter. | 4403 // Lookup a instance setter. |
| 4434 func = Dart_LookupFunction(cls, Dart_NewString("d=")); | 4404 func = Dart_LookupFunction(cls, NewString("d=")); |
| 4435 EXPECT_VALID(func); | 4405 EXPECT_VALID(func); |
| 4436 EXPECT(Dart_IsFunction(func)); | 4406 EXPECT(Dart_IsFunction(func)); |
| 4437 BuildFunctionDescription(&buffer, func); | 4407 BuildFunctionDescription(&buffer, func); |
| 4438 EXPECT_STREQ("d= 1 0 setter", buffer.buf()); | 4408 EXPECT_STREQ("d= 1 0 setter", buffer.buf()); |
| 4439 owner = Dart_FunctionOwner(func); | 4409 owner = Dart_FunctionOwner(func); |
| 4440 EXPECT_VALID(owner); | 4410 EXPECT_VALID(owner); |
| 4441 EXPECT(Dart_IdentityEquals(owner, cls)); | 4411 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4442 | 4412 |
| 4443 // Lookup a private instance getter. | 4413 // Lookup a private instance getter. |
| 4444 func = Dart_LookupFunction(cls, Dart_NewString("_e")); | 4414 func = Dart_LookupFunction(cls, NewString("_e")); |
| 4445 EXPECT_VALID(func); | 4415 EXPECT_VALID(func); |
| 4446 EXPECT(Dart_IsFunction(func)); | 4416 EXPECT(Dart_IsFunction(func)); |
| 4447 BuildFunctionDescription(&buffer, func); | 4417 BuildFunctionDescription(&buffer, func); |
| 4448 EXPECT_STREQ("_e 0 0 getter", buffer.buf()); | 4418 EXPECT_STREQ("_e 0 0 getter", buffer.buf()); |
| 4449 owner = Dart_FunctionOwner(func); | 4419 owner = Dart_FunctionOwner(func); |
| 4450 EXPECT_VALID(owner); | 4420 EXPECT_VALID(owner); |
| 4451 EXPECT(Dart_IdentityEquals(owner, cls)); | 4421 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4452 | 4422 |
| 4453 // Lookup a private instance setter. | 4423 // Lookup a private instance setter. |
| 4454 func = Dart_LookupFunction(cls, Dart_NewString("_f=")); | 4424 func = Dart_LookupFunction(cls, NewString("_f=")); |
| 4455 EXPECT_VALID(func); | 4425 EXPECT_VALID(func); |
| 4456 EXPECT(Dart_IsFunction(func)); | 4426 EXPECT(Dart_IsFunction(func)); |
| 4457 BuildFunctionDescription(&buffer, func); | 4427 BuildFunctionDescription(&buffer, func); |
| 4458 EXPECT_STREQ("_f= 1 0 setter", buffer.buf()); | 4428 EXPECT_STREQ("_f= 1 0 setter", buffer.buf()); |
| 4459 owner = Dart_FunctionOwner(func); | 4429 owner = Dart_FunctionOwner(func); |
| 4460 EXPECT_VALID(owner); | 4430 EXPECT_VALID(owner); |
| 4461 EXPECT(Dart_IdentityEquals(owner, cls)); | 4431 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4462 | 4432 |
| 4463 // Lookup a static method. | 4433 // Lookup a static method. |
| 4464 func = Dart_LookupFunction(cls, Dart_NewString("g")); | 4434 func = Dart_LookupFunction(cls, NewString("g")); |
| 4465 EXPECT_VALID(func); | 4435 EXPECT_VALID(func); |
| 4466 EXPECT(Dart_IsFunction(func)); | 4436 EXPECT(Dart_IsFunction(func)); |
| 4467 BuildFunctionDescription(&buffer, func); | 4437 BuildFunctionDescription(&buffer, func); |
| 4468 EXPECT_STREQ("g 0 0 static", buffer.buf()); | 4438 EXPECT_STREQ("g 0 0 static", buffer.buf()); |
| 4469 owner = Dart_FunctionOwner(func); | 4439 owner = Dart_FunctionOwner(func); |
| 4470 EXPECT_VALID(owner); | 4440 EXPECT_VALID(owner); |
| 4471 EXPECT(Dart_IdentityEquals(owner, cls)); | 4441 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4472 | 4442 |
| 4473 // Lookup a private static method. | 4443 // Lookup a private static method. |
| 4474 func = Dart_LookupFunction(cls, Dart_NewString("_h")); | 4444 func = Dart_LookupFunction(cls, NewString("_h")); |
| 4475 EXPECT_VALID(func); | 4445 EXPECT_VALID(func); |
| 4476 EXPECT(Dart_IsFunction(func)); | 4446 EXPECT(Dart_IsFunction(func)); |
| 4477 BuildFunctionDescription(&buffer, func); | 4447 BuildFunctionDescription(&buffer, func); |
| 4478 EXPECT_STREQ("_h 0 0 static", buffer.buf()); | 4448 EXPECT_STREQ("_h 0 0 static", buffer.buf()); |
| 4479 owner = Dart_FunctionOwner(func); | 4449 owner = Dart_FunctionOwner(func); |
| 4480 EXPECT_VALID(owner); | 4450 EXPECT_VALID(owner); |
| 4481 EXPECT(Dart_IdentityEquals(owner, cls)); | 4451 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4482 | 4452 |
| 4483 // Lookup a static getter. | 4453 // Lookup a static getter. |
| 4484 func = Dart_LookupFunction(cls, Dart_NewString("i")); | 4454 func = Dart_LookupFunction(cls, NewString("i")); |
| 4485 EXPECT_VALID(func); | 4455 EXPECT_VALID(func); |
| 4486 EXPECT(Dart_IsFunction(func)); | 4456 EXPECT(Dart_IsFunction(func)); |
| 4487 BuildFunctionDescription(&buffer, func); | 4457 BuildFunctionDescription(&buffer, func); |
| 4488 EXPECT_STREQ("i 0 0 static getter", buffer.buf()); | 4458 EXPECT_STREQ("i 0 0 static getter", buffer.buf()); |
| 4489 owner = Dart_FunctionOwner(func); | 4459 owner = Dart_FunctionOwner(func); |
| 4490 EXPECT_VALID(owner); | 4460 EXPECT_VALID(owner); |
| 4491 EXPECT(Dart_IdentityEquals(owner, cls)); | 4461 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4492 | 4462 |
| 4493 // Lookup a static setter. | 4463 // Lookup a static setter. |
| 4494 func = Dart_LookupFunction(cls, Dart_NewString("j=")); | 4464 func = Dart_LookupFunction(cls, NewString("j=")); |
| 4495 EXPECT_VALID(func); | 4465 EXPECT_VALID(func); |
| 4496 EXPECT(Dart_IsFunction(func)); | 4466 EXPECT(Dart_IsFunction(func)); |
| 4497 BuildFunctionDescription(&buffer, func); | 4467 BuildFunctionDescription(&buffer, func); |
| 4498 EXPECT_STREQ("j= 1 0 static setter", buffer.buf()); | 4468 EXPECT_STREQ("j= 1 0 static setter", buffer.buf()); |
| 4499 owner = Dart_FunctionOwner(func); | 4469 owner = Dart_FunctionOwner(func); |
| 4500 EXPECT_VALID(owner); | 4470 EXPECT_VALID(owner); |
| 4501 EXPECT(Dart_IdentityEquals(owner, cls)); | 4471 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4502 | 4472 |
| 4503 // Lookup a private static getter. | 4473 // Lookup a private static getter. |
| 4504 func = Dart_LookupFunction(cls, Dart_NewString("_k")); | 4474 func = Dart_LookupFunction(cls, NewString("_k")); |
| 4505 EXPECT_VALID(func); | 4475 EXPECT_VALID(func); |
| 4506 EXPECT(Dart_IsFunction(func)); | 4476 EXPECT(Dart_IsFunction(func)); |
| 4507 BuildFunctionDescription(&buffer, func); | 4477 BuildFunctionDescription(&buffer, func); |
| 4508 EXPECT_STREQ("_k 0 0 static getter", buffer.buf()); | 4478 EXPECT_STREQ("_k 0 0 static getter", buffer.buf()); |
| 4509 owner = Dart_FunctionOwner(func); | 4479 owner = Dart_FunctionOwner(func); |
| 4510 EXPECT_VALID(owner); | 4480 EXPECT_VALID(owner); |
| 4511 EXPECT(Dart_IdentityEquals(owner, cls)); | 4481 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4512 | 4482 |
| 4513 // Lookup a private static setter. | 4483 // Lookup a private static setter. |
| 4514 func = Dart_LookupFunction(cls, Dart_NewString("_l=")); | 4484 func = Dart_LookupFunction(cls, NewString("_l=")); |
| 4515 EXPECT_VALID(func); | 4485 EXPECT_VALID(func); |
| 4516 EXPECT(Dart_IsFunction(func)); | 4486 EXPECT(Dart_IsFunction(func)); |
| 4517 BuildFunctionDescription(&buffer, func); | 4487 BuildFunctionDescription(&buffer, func); |
| 4518 EXPECT_STREQ("_l= 1 0 static setter", buffer.buf()); | 4488 EXPECT_STREQ("_l= 1 0 static setter", buffer.buf()); |
| 4519 owner = Dart_FunctionOwner(func); | 4489 owner = Dart_FunctionOwner(func); |
| 4520 EXPECT_VALID(owner); | 4490 EXPECT_VALID(owner); |
| 4521 EXPECT(Dart_IdentityEquals(owner, cls)); | 4491 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4522 | 4492 |
| 4523 // Lookup an abstract method. | 4493 // Lookup an abstract method. |
| 4524 func = Dart_LookupFunction(cls, Dart_NewString("m")); | 4494 func = Dart_LookupFunction(cls, NewString("m")); |
| 4525 EXPECT_VALID(func); | 4495 EXPECT_VALID(func); |
| 4526 EXPECT(Dart_IsFunction(func)); | 4496 EXPECT(Dart_IsFunction(func)); |
| 4527 BuildFunctionDescription(&buffer, func); | 4497 BuildFunctionDescription(&buffer, func); |
| 4528 EXPECT_STREQ("m 0 0 abstract", buffer.buf()); | 4498 EXPECT_STREQ("m 0 0 abstract", buffer.buf()); |
| 4529 owner = Dart_FunctionOwner(func); | 4499 owner = Dart_FunctionOwner(func); |
| 4530 EXPECT_VALID(owner); | 4500 EXPECT_VALID(owner); |
| 4531 EXPECT(Dart_IdentityEquals(owner, cls)); | 4501 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4532 | 4502 |
| 4533 // Lookup a private abstract method. | 4503 // Lookup a private abstract method. |
| 4534 func = Dart_LookupFunction(cls, Dart_NewString("_n")); | 4504 func = Dart_LookupFunction(cls, NewString("_n")); |
| 4535 EXPECT_VALID(func); | 4505 EXPECT_VALID(func); |
| 4536 EXPECT(Dart_IsFunction(func)); | 4506 EXPECT(Dart_IsFunction(func)); |
| 4537 BuildFunctionDescription(&buffer, func); | 4507 BuildFunctionDescription(&buffer, func); |
| 4538 EXPECT_STREQ("_n 0 0 abstract", buffer.buf()); | 4508 EXPECT_STREQ("_n 0 0 abstract", buffer.buf()); |
| 4539 owner = Dart_FunctionOwner(func); | 4509 owner = Dart_FunctionOwner(func); |
| 4540 EXPECT_VALID(owner); | 4510 EXPECT_VALID(owner); |
| 4541 EXPECT(Dart_IdentityEquals(owner, cls)); | 4511 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4542 | 4512 |
| 4543 // Lookup a abstract getter. | 4513 // Lookup a abstract getter. |
| 4544 func = Dart_LookupFunction(cls, Dart_NewString("o")); | 4514 func = Dart_LookupFunction(cls, NewString("o")); |
| 4545 EXPECT_VALID(func); | 4515 EXPECT_VALID(func); |
| 4546 EXPECT(Dart_IsFunction(func)); | 4516 EXPECT(Dart_IsFunction(func)); |
| 4547 BuildFunctionDescription(&buffer, func); | 4517 BuildFunctionDescription(&buffer, func); |
| 4548 EXPECT_STREQ("o 0 0 abstract getter", buffer.buf()); | 4518 EXPECT_STREQ("o 0 0 abstract getter", buffer.buf()); |
| 4549 owner = Dart_FunctionOwner(func); | 4519 owner = Dart_FunctionOwner(func); |
| 4550 EXPECT_VALID(owner); | 4520 EXPECT_VALID(owner); |
| 4551 EXPECT(Dart_IdentityEquals(owner, cls)); | 4521 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4552 | 4522 |
| 4553 // Lookup a abstract setter. | 4523 // Lookup a abstract setter. |
| 4554 func = Dart_LookupFunction(cls, Dart_NewString("p=")); | 4524 func = Dart_LookupFunction(cls, NewString("p=")); |
| 4555 EXPECT_VALID(func); | 4525 EXPECT_VALID(func); |
| 4556 EXPECT(Dart_IsFunction(func)); | 4526 EXPECT(Dart_IsFunction(func)); |
| 4557 BuildFunctionDescription(&buffer, func); | 4527 BuildFunctionDescription(&buffer, func); |
| 4558 EXPECT_STREQ("p= 1 0 abstract setter", buffer.buf()); | 4528 EXPECT_STREQ("p= 1 0 abstract setter", buffer.buf()); |
| 4559 owner = Dart_FunctionOwner(func); | 4529 owner = Dart_FunctionOwner(func); |
| 4560 EXPECT_VALID(owner); | 4530 EXPECT_VALID(owner); |
| 4561 EXPECT(Dart_IdentityEquals(owner, cls)); | 4531 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4562 | 4532 |
| 4563 // Lookup a private abstract getter. | 4533 // Lookup a private abstract getter. |
| 4564 func = Dart_LookupFunction(cls, Dart_NewString("_q")); | 4534 func = Dart_LookupFunction(cls, NewString("_q")); |
| 4565 EXPECT_VALID(func); | 4535 EXPECT_VALID(func); |
| 4566 EXPECT(Dart_IsFunction(func)); | 4536 EXPECT(Dart_IsFunction(func)); |
| 4567 BuildFunctionDescription(&buffer, func); | 4537 BuildFunctionDescription(&buffer, func); |
| 4568 EXPECT_STREQ("_q 0 0 abstract getter", buffer.buf()); | 4538 EXPECT_STREQ("_q 0 0 abstract getter", buffer.buf()); |
| 4569 owner = Dart_FunctionOwner(func); | 4539 owner = Dart_FunctionOwner(func); |
| 4570 EXPECT_VALID(owner); | 4540 EXPECT_VALID(owner); |
| 4571 EXPECT(Dart_IdentityEquals(owner, cls)); | 4541 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4572 | 4542 |
| 4573 // Lookup a private abstract setter. | 4543 // Lookup a private abstract setter. |
| 4574 func = Dart_LookupFunction(cls, Dart_NewString("_r=")); | 4544 func = Dart_LookupFunction(cls, NewString("_r=")); |
| 4575 EXPECT_VALID(func); | 4545 EXPECT_VALID(func); |
| 4576 EXPECT(Dart_IsFunction(func)); | 4546 EXPECT(Dart_IsFunction(func)); |
| 4577 BuildFunctionDescription(&buffer, func); | 4547 BuildFunctionDescription(&buffer, func); |
| 4578 EXPECT_STREQ("_r= 1 0 abstract setter", buffer.buf()); | 4548 EXPECT_STREQ("_r= 1 0 abstract setter", buffer.buf()); |
| 4579 owner = Dart_FunctionOwner(func); | 4549 owner = Dart_FunctionOwner(func); |
| 4580 EXPECT_VALID(owner); | 4550 EXPECT_VALID(owner); |
| 4581 EXPECT(Dart_IdentityEquals(owner, cls)); | 4551 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4582 | 4552 |
| 4583 // Lookup a method with fixed and optional parameters. | 4553 // Lookup a method with fixed and optional parameters. |
| 4584 func = Dart_LookupFunction(cls, Dart_NewString("s")); | 4554 func = Dart_LookupFunction(cls, NewString("s")); |
| 4585 EXPECT_VALID(func); | 4555 EXPECT_VALID(func); |
| 4586 EXPECT(Dart_IsFunction(func)); | 4556 EXPECT(Dart_IsFunction(func)); |
| 4587 BuildFunctionDescription(&buffer, func); | 4557 BuildFunctionDescription(&buffer, func); |
| 4588 EXPECT_STREQ("s 1 2", buffer.buf()); | 4558 EXPECT_STREQ("s 1 2", buffer.buf()); |
| 4589 owner = Dart_FunctionOwner(func); | 4559 owner = Dart_FunctionOwner(func); |
| 4590 EXPECT_VALID(owner); | 4560 EXPECT_VALID(owner); |
| 4591 EXPECT(Dart_IdentityEquals(owner, cls)); | 4561 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4592 | 4562 |
| 4593 // Lookup a method with only optional parameters. | 4563 // Lookup a method with only optional parameters. |
| 4594 func = Dart_LookupFunction(cls, Dart_NewString("t")); | 4564 func = Dart_LookupFunction(cls, NewString("t")); |
| 4595 EXPECT_VALID(func); | 4565 EXPECT_VALID(func); |
| 4596 EXPECT(Dart_IsFunction(func)); | 4566 EXPECT(Dart_IsFunction(func)); |
| 4597 BuildFunctionDescription(&buffer, func); | 4567 BuildFunctionDescription(&buffer, func); |
| 4598 EXPECT_STREQ("t 0 3", buffer.buf()); | 4568 EXPECT_STREQ("t 0 3", buffer.buf()); |
| 4599 owner = Dart_FunctionOwner(func); | 4569 owner = Dart_FunctionOwner(func); |
| 4600 EXPECT_VALID(owner); | 4570 EXPECT_VALID(owner); |
| 4601 EXPECT(Dart_IdentityEquals(owner, cls)); | 4571 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4602 | 4572 |
| 4603 // Lookup an operator | 4573 // Lookup an operator |
| 4604 func = Dart_LookupFunction(cls, Dart_NewString("==")); | 4574 func = Dart_LookupFunction(cls, NewString("==")); |
| 4605 EXPECT_VALID(func); | 4575 EXPECT_VALID(func); |
| 4606 EXPECT(Dart_IsFunction(func)); | 4576 EXPECT(Dart_IsFunction(func)); |
| 4607 BuildFunctionDescription(&buffer, func); | 4577 BuildFunctionDescription(&buffer, func); |
| 4608 EXPECT_STREQ("== 1 0", buffer.buf()); | 4578 EXPECT_STREQ("== 1 0", buffer.buf()); |
| 4609 owner = Dart_FunctionOwner(func); | 4579 owner = Dart_FunctionOwner(func); |
| 4610 EXPECT_VALID(owner); | 4580 EXPECT_VALID(owner); |
| 4611 EXPECT(Dart_IdentityEquals(owner, cls)); | 4581 EXPECT(Dart_IdentityEquals(owner, cls)); |
| 4612 | 4582 |
| 4613 // Lookup a function that does not exist from a library. | 4583 // Lookup a function that does not exist from a library. |
| 4614 func = Dart_LookupFunction(lib, Dart_NewString("DoesNotExist")); | 4584 func = Dart_LookupFunction(lib, NewString("DoesNotExist")); |
| 4615 EXPECT(Dart_IsNull(func)); | 4585 EXPECT(Dart_IsNull(func)); |
| 4616 | 4586 |
| 4617 // Lookup a function that does not exist from a class. | 4587 // Lookup a function that does not exist from a class. |
| 4618 func = Dart_LookupFunction(cls, Dart_NewString("DoesNotExist")); | 4588 func = Dart_LookupFunction(cls, NewString("DoesNotExist")); |
| 4619 EXPECT(Dart_IsNull(func)); | 4589 EXPECT(Dart_IsNull(func)); |
| 4620 | 4590 |
| 4621 // Lookup a class using an error class name. The error propagates. | 4591 // Lookup a class using an error class name. The error propagates. |
| 4622 func = Dart_LookupFunction(cls, Api::NewError("myerror")); | 4592 func = Dart_LookupFunction(cls, Api::NewError("myerror")); |
| 4623 EXPECT_ERROR(func, "myerror"); | 4593 EXPECT_ERROR(func, "myerror"); |
| 4624 | 4594 |
| 4625 // Lookup a class from an error library. The error propagates. | 4595 // Lookup a class from an error library. The error propagates. |
| 4626 func = Dart_LookupFunction(Api::NewError("myerror"), Dart_NewString("foo")); | 4596 func = Dart_LookupFunction(Api::NewError("myerror"), NewString("foo")); |
| 4627 EXPECT_ERROR(func, "myerror"); | 4597 EXPECT_ERROR(func, "myerror"); |
| 4628 } | 4598 } |
| 4629 | 4599 |
| 4630 | 4600 |
| 4631 TEST_CASE(TypeReflection) { | 4601 TEST_CASE(TypeReflection) { |
| 4632 const char* kScriptChars = | 4602 const char* kScriptChars = |
| 4633 "void func(String a, int b) {}\n" | 4603 "void func(String a, int b) {}\n" |
| 4634 "int variable;\n"; | 4604 "int variable;\n"; |
| 4635 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4605 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4636 EXPECT_VALID(lib); | 4606 EXPECT_VALID(lib); |
| 4637 | 4607 |
| 4638 Dart_Handle func = Dart_LookupFunction(lib, Dart_NewString("func")); | 4608 Dart_Handle func = Dart_LookupFunction(lib, NewString("func")); |
| 4639 EXPECT_VALID(func); | 4609 EXPECT_VALID(func); |
| 4640 EXPECT(Dart_IsFunction(func)); | 4610 EXPECT(Dart_IsFunction(func)); |
| 4641 | 4611 |
| 4642 // Make sure parameter counts are right. | 4612 // Make sure parameter counts are right. |
| 4643 int64_t fixed_params = -1; | 4613 int64_t fixed_params = -1; |
| 4644 int64_t opt_params = -1; | 4614 int64_t opt_params = -1; |
| 4645 EXPECT_VALID(Dart_FunctionParameterCounts(func, &fixed_params, &opt_params)); | 4615 EXPECT_VALID(Dart_FunctionParameterCounts(func, &fixed_params, &opt_params)); |
| 4646 EXPECT_EQ(2, fixed_params); | 4616 EXPECT_EQ(2, fixed_params); |
| 4647 EXPECT_EQ(0, opt_params); | 4617 EXPECT_EQ(0, opt_params); |
| 4648 | 4618 |
| 4649 // Check the return type. | 4619 // Check the return type. |
| 4650 Dart_Handle type = Dart_FunctionReturnType(func); | 4620 Dart_Handle type = Dart_FunctionReturnType(func); |
| 4651 EXPECT_VALID(type); | 4621 EXPECT_VALID(type); |
| 4652 Dart_Handle cls_name = Dart_ClassName(type); | 4622 Dart_Handle cls_name = Dart_ClassName(type); |
| 4653 EXPECT_VALID(cls_name); | 4623 EXPECT_VALID(cls_name); |
| 4654 const char* cls_name_cstr = ""; | 4624 const char* cls_name_cstr = ""; |
| 4655 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); | 4625 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| 4656 EXPECT_STREQ("void", cls_name_cstr); | 4626 EXPECT_STREQ("void", cls_name_cstr); |
| 4657 | 4627 |
| 4658 // Check a parameter type. | 4628 // Check a parameter type. |
| 4659 type = Dart_FunctionParameterType(func, 0); | 4629 type = Dart_FunctionParameterType(func, 0); |
| 4660 EXPECT_VALID(type); | 4630 EXPECT_VALID(type); |
| 4661 cls_name = Dart_ClassName(type); | 4631 cls_name = Dart_ClassName(type); |
| 4662 EXPECT_VALID(cls_name); | 4632 EXPECT_VALID(cls_name); |
| 4663 cls_name_cstr = ""; | 4633 cls_name_cstr = ""; |
| 4664 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); | 4634 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| 4665 EXPECT_STREQ("String", cls_name_cstr); | 4635 EXPECT_STREQ("String", cls_name_cstr); |
| 4666 | 4636 |
| 4667 Dart_Handle var = Dart_LookupVariable(lib, Dart_NewString("variable")); | 4637 Dart_Handle var = Dart_LookupVariable(lib, NewString("variable")); |
| 4668 EXPECT_VALID(var); | 4638 EXPECT_VALID(var); |
| 4669 EXPECT(Dart_IsVariable(var)); | 4639 EXPECT(Dart_IsVariable(var)); |
| 4670 | 4640 |
| 4671 // Check the variable type. | 4641 // Check the variable type. |
| 4672 type = Dart_VariableType(var); | 4642 type = Dart_VariableType(var); |
| 4673 EXPECT_VALID(type); | 4643 EXPECT_VALID(type); |
| 4674 cls_name = Dart_ClassName(type); | 4644 cls_name = Dart_ClassName(type); |
| 4675 EXPECT_VALID(cls_name); | 4645 EXPECT_VALID(cls_name); |
| 4676 cls_name_cstr = ""; | 4646 cls_name_cstr = ""; |
| 4677 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); | 4647 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4715 " final c = 'c';\n" | 4685 " final c = 'c';\n" |
| 4716 " final _d = '_d';\n" | 4686 " final _d = '_d';\n" |
| 4717 " static var e = 'e';\n" | 4687 " static var e = 'e';\n" |
| 4718 " static var _f = '_f';\n" | 4688 " static var _f = '_f';\n" |
| 4719 " static const g = 'g';\n" | 4689 " static const g = 'g';\n" |
| 4720 " static const _h = '_h';\n" | 4690 " static const _h = '_h';\n" |
| 4721 "}\n"; | 4691 "}\n"; |
| 4722 | 4692 |
| 4723 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4693 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4724 EXPECT_VALID(lib); | 4694 EXPECT_VALID(lib); |
| 4725 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); | 4695 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); |
| 4726 EXPECT_VALID(cls); | 4696 EXPECT_VALID(cls); |
| 4727 TextBuffer buffer(128); | 4697 TextBuffer buffer(128); |
| 4728 | 4698 |
| 4729 // Lookup a top-level variable. | 4699 // Lookup a top-level variable. |
| 4730 Dart_Handle var = Dart_LookupVariable(lib, Dart_NewString("a")); | 4700 Dart_Handle var = Dart_LookupVariable(lib, NewString("a")); |
| 4731 EXPECT_VALID(var); | 4701 EXPECT_VALID(var); |
| 4732 EXPECT(Dart_IsVariable(var)); | 4702 EXPECT(Dart_IsVariable(var)); |
| 4733 BuildVariableDescription(&buffer, var); | 4703 BuildVariableDescription(&buffer, var); |
| 4734 EXPECT_STREQ("a static", buffer.buf()); | 4704 EXPECT_STREQ("a static", buffer.buf()); |
| 4735 | 4705 |
| 4736 // Lookup a private top-level variable. | 4706 // Lookup a private top-level variable. |
| 4737 var = Dart_LookupVariable(lib, Dart_NewString("_b")); | 4707 var = Dart_LookupVariable(lib, NewString("_b")); |
| 4738 EXPECT_VALID(var); | 4708 EXPECT_VALID(var); |
| 4739 EXPECT(Dart_IsVariable(var)); | 4709 EXPECT(Dart_IsVariable(var)); |
| 4740 BuildVariableDescription(&buffer, var); | 4710 BuildVariableDescription(&buffer, var); |
| 4741 EXPECT_STREQ("_b static", buffer.buf()); | 4711 EXPECT_STREQ("_b static", buffer.buf()); |
| 4742 | 4712 |
| 4743 // Lookup a const top-level variable. | 4713 // Lookup a const top-level variable. |
| 4744 var = Dart_LookupVariable(lib, Dart_NewString("c")); | 4714 var = Dart_LookupVariable(lib, NewString("c")); |
| 4745 EXPECT_VALID(var); | 4715 EXPECT_VALID(var); |
| 4746 EXPECT(Dart_IsVariable(var)); | 4716 EXPECT(Dart_IsVariable(var)); |
| 4747 BuildVariableDescription(&buffer, var); | 4717 BuildVariableDescription(&buffer, var); |
| 4748 EXPECT_STREQ("c static final", buffer.buf()); | 4718 EXPECT_STREQ("c static final", buffer.buf()); |
| 4749 | 4719 |
| 4750 // Lookup a private const top-level variable. | 4720 // Lookup a private const top-level variable. |
| 4751 var = Dart_LookupVariable(lib, Dart_NewString("_d")); | 4721 var = Dart_LookupVariable(lib, NewString("_d")); |
| 4752 EXPECT_VALID(var); | 4722 EXPECT_VALID(var); |
| 4753 EXPECT(Dart_IsVariable(var)); | 4723 EXPECT(Dart_IsVariable(var)); |
| 4754 BuildVariableDescription(&buffer, var); | 4724 BuildVariableDescription(&buffer, var); |
| 4755 EXPECT_STREQ("_d static final", buffer.buf()); | 4725 EXPECT_STREQ("_d static final", buffer.buf()); |
| 4756 | 4726 |
| 4757 // Lookup a instance variable. | 4727 // Lookup a instance variable. |
| 4758 var = Dart_LookupVariable(cls, Dart_NewString("a")); | 4728 var = Dart_LookupVariable(cls, NewString("a")); |
| 4759 EXPECT_VALID(var); | 4729 EXPECT_VALID(var); |
| 4760 EXPECT(Dart_IsVariable(var)); | 4730 EXPECT(Dart_IsVariable(var)); |
| 4761 BuildVariableDescription(&buffer, var); | 4731 BuildVariableDescription(&buffer, var); |
| 4762 EXPECT_STREQ("a", buffer.buf()); | 4732 EXPECT_STREQ("a", buffer.buf()); |
| 4763 | 4733 |
| 4764 // Lookup a private instance variable. | 4734 // Lookup a private instance variable. |
| 4765 var = Dart_LookupVariable(cls, Dart_NewString("_b")); | 4735 var = Dart_LookupVariable(cls, NewString("_b")); |
| 4766 EXPECT_VALID(var); | 4736 EXPECT_VALID(var); |
| 4767 EXPECT(Dart_IsVariable(var)); | 4737 EXPECT(Dart_IsVariable(var)); |
| 4768 BuildVariableDescription(&buffer, var); | 4738 BuildVariableDescription(&buffer, var); |
| 4769 EXPECT_STREQ("_b", buffer.buf()); | 4739 EXPECT_STREQ("_b", buffer.buf()); |
| 4770 | 4740 |
| 4771 // Lookup a final instance variable. | 4741 // Lookup a final instance variable. |
| 4772 var = Dart_LookupVariable(cls, Dart_NewString("c")); | 4742 var = Dart_LookupVariable(cls, NewString("c")); |
| 4773 EXPECT_VALID(var); | 4743 EXPECT_VALID(var); |
| 4774 EXPECT(Dart_IsVariable(var)); | 4744 EXPECT(Dart_IsVariable(var)); |
| 4775 BuildVariableDescription(&buffer, var); | 4745 BuildVariableDescription(&buffer, var); |
| 4776 EXPECT_STREQ("c final", buffer.buf()); | 4746 EXPECT_STREQ("c final", buffer.buf()); |
| 4777 | 4747 |
| 4778 // Lookup a private final instance variable. | 4748 // Lookup a private final instance variable. |
| 4779 var = Dart_LookupVariable(cls, Dart_NewString("_d")); | 4749 var = Dart_LookupVariable(cls, NewString("_d")); |
| 4780 EXPECT_VALID(var); | 4750 EXPECT_VALID(var); |
| 4781 EXPECT(Dart_IsVariable(var)); | 4751 EXPECT(Dart_IsVariable(var)); |
| 4782 BuildVariableDescription(&buffer, var); | 4752 BuildVariableDescription(&buffer, var); |
| 4783 EXPECT_STREQ("_d final", buffer.buf()); | 4753 EXPECT_STREQ("_d final", buffer.buf()); |
| 4784 | 4754 |
| 4785 // Lookup a static variable. | 4755 // Lookup a static variable. |
| 4786 var = Dart_LookupVariable(cls, Dart_NewString("e")); | 4756 var = Dart_LookupVariable(cls, NewString("e")); |
| 4787 EXPECT_VALID(var); | 4757 EXPECT_VALID(var); |
| 4788 EXPECT(Dart_IsVariable(var)); | 4758 EXPECT(Dart_IsVariable(var)); |
| 4789 BuildVariableDescription(&buffer, var); | 4759 BuildVariableDescription(&buffer, var); |
| 4790 EXPECT_STREQ("e static", buffer.buf()); | 4760 EXPECT_STREQ("e static", buffer.buf()); |
| 4791 | 4761 |
| 4792 // Lookup a private static variable. | 4762 // Lookup a private static variable. |
| 4793 var = Dart_LookupVariable(cls, Dart_NewString("_f")); | 4763 var = Dart_LookupVariable(cls, NewString("_f")); |
| 4794 EXPECT_VALID(var); | 4764 EXPECT_VALID(var); |
| 4795 EXPECT(Dart_IsVariable(var)); | 4765 EXPECT(Dart_IsVariable(var)); |
| 4796 BuildVariableDescription(&buffer, var); | 4766 BuildVariableDescription(&buffer, var); |
| 4797 EXPECT_STREQ("_f static", buffer.buf()); | 4767 EXPECT_STREQ("_f static", buffer.buf()); |
| 4798 | 4768 |
| 4799 // Lookup a const static variable. | 4769 // Lookup a const static variable. |
| 4800 var = Dart_LookupVariable(cls, Dart_NewString("g")); | 4770 var = Dart_LookupVariable(cls, NewString("g")); |
| 4801 EXPECT_VALID(var); | 4771 EXPECT_VALID(var); |
| 4802 EXPECT(Dart_IsVariable(var)); | 4772 EXPECT(Dart_IsVariable(var)); |
| 4803 BuildVariableDescription(&buffer, var); | 4773 BuildVariableDescription(&buffer, var); |
| 4804 EXPECT_STREQ("g static final", buffer.buf()); | 4774 EXPECT_STREQ("g static final", buffer.buf()); |
| 4805 | 4775 |
| 4806 // Lookup a private const static variable. | 4776 // Lookup a private const static variable. |
| 4807 var = Dart_LookupVariable(cls, Dart_NewString("_h")); | 4777 var = Dart_LookupVariable(cls, NewString("_h")); |
| 4808 EXPECT_VALID(var); | 4778 EXPECT_VALID(var); |
| 4809 EXPECT(Dart_IsVariable(var)); | 4779 EXPECT(Dart_IsVariable(var)); |
| 4810 BuildVariableDescription(&buffer, var); | 4780 BuildVariableDescription(&buffer, var); |
| 4811 EXPECT_STREQ("_h static final", buffer.buf()); | 4781 EXPECT_STREQ("_h static final", buffer.buf()); |
| 4812 | 4782 |
| 4813 // Lookup a variable that does not exist from a library. | 4783 // Lookup a variable that does not exist from a library. |
| 4814 var = Dart_LookupVariable(lib, Dart_NewString("DoesNotExist")); | 4784 var = Dart_LookupVariable(lib, NewString("DoesNotExist")); |
| 4815 EXPECT(Dart_IsNull(var)); | 4785 EXPECT(Dart_IsNull(var)); |
| 4816 | 4786 |
| 4817 // Lookup a variable that does not exist from a class. | 4787 // Lookup a variable that does not exist from a class. |
| 4818 var = Dart_LookupVariable(cls, Dart_NewString("DoesNotExist")); | 4788 var = Dart_LookupVariable(cls, NewString("DoesNotExist")); |
| 4819 EXPECT(Dart_IsNull(var)); | 4789 EXPECT(Dart_IsNull(var)); |
| 4820 | 4790 |
| 4821 // Lookup a class from an error library. The error propagates. | 4791 // Lookup a class from an error library. The error propagates. |
| 4822 var = Dart_LookupVariable(Api::NewError("myerror"), Dart_NewString("foo")); | 4792 var = Dart_LookupVariable(Api::NewError("myerror"), NewString("foo")); |
| 4823 EXPECT_ERROR(var, "myerror"); | 4793 EXPECT_ERROR(var, "myerror"); |
| 4824 | 4794 |
| 4825 // Lookup a class using an error class name. The error propagates. | 4795 // Lookup a class using an error class name. The error propagates. |
| 4826 var = Dart_LookupVariable(lib, Api::NewError("myerror")); | 4796 var = Dart_LookupVariable(lib, Api::NewError("myerror")); |
| 4827 EXPECT_ERROR(var, "myerror"); | 4797 EXPECT_ERROR(var, "myerror"); |
| 4828 } | 4798 } |
| 4829 | 4799 |
| 4830 | 4800 |
| 4831 TEST_CASE(TypeVariableReflection) { | 4801 TEST_CASE(TypeVariableReflection) { |
| 4832 const char* kScriptChars = | 4802 const char* kScriptChars = |
| 4833 "interface UpperBound {}\n" | 4803 "interface UpperBound {}\n" |
| 4834 "class GenericClass<U, T extends UpperBound> {\n" | 4804 "class GenericClass<U, T extends UpperBound> {\n" |
| 4835 " T func1() { return null; }\n" | 4805 " T func1() { return null; }\n" |
| 4836 " U func2() { return null; }\n" | 4806 " U func2() { return null; }\n" |
| 4837 "}\n"; | 4807 "}\n"; |
| 4838 | 4808 |
| 4839 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4809 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4840 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("GenericClass")); | 4810 Dart_Handle cls = Dart_GetClass(lib, NewString("GenericClass")); |
| 4841 EXPECT_VALID(cls); | 4811 EXPECT_VALID(cls); |
| 4842 | 4812 |
| 4843 // Test Dart_GetTypeVariableNames. | 4813 // Test Dart_GetTypeVariableNames. |
| 4844 Dart_Handle names = Dart_GetTypeVariableNames(cls); | 4814 Dart_Handle names = Dart_GetTypeVariableNames(cls); |
| 4845 EXPECT_VALID(names); | 4815 EXPECT_VALID(names); |
| 4846 Dart_Handle names_str = Dart_ToString(names); | 4816 Dart_Handle names_str = Dart_ToString(names); |
| 4847 EXPECT_VALID(names_str); | 4817 EXPECT_VALID(names_str); |
| 4848 const char* cstr = ""; | 4818 const char* cstr = ""; |
| 4849 EXPECT_VALID(Dart_StringToCString(names_str, &cstr)); | 4819 EXPECT_VALID(Dart_StringToCString(names_str, &cstr)); |
| 4850 EXPECT_STREQ("[U, T]", cstr); | 4820 EXPECT_STREQ("[U, T]", cstr); |
| 4851 | 4821 |
| 4852 // Test variable U. | 4822 // Test variable U. |
| 4853 Dart_Handle type_var = Dart_LookupTypeVariable(cls, Dart_NewString("U")); | 4823 Dart_Handle type_var = Dart_LookupTypeVariable(cls, NewString("U")); |
| 4854 EXPECT_VALID(type_var); | 4824 EXPECT_VALID(type_var); |
| 4855 EXPECT(Dart_IsTypeVariable(type_var)); | 4825 EXPECT(Dart_IsTypeVariable(type_var)); |
| 4856 Dart_Handle type_var_name = Dart_TypeVariableName(type_var); | 4826 Dart_Handle type_var_name = Dart_TypeVariableName(type_var); |
| 4857 EXPECT_VALID(type_var_name); | 4827 EXPECT_VALID(type_var_name); |
| 4858 EXPECT_VALID(Dart_StringToCString(type_var_name, &cstr)); | 4828 EXPECT_VALID(Dart_StringToCString(type_var_name, &cstr)); |
| 4859 EXPECT_STREQ("U", cstr); | 4829 EXPECT_STREQ("U", cstr); |
| 4860 Dart_Handle type_var_owner = Dart_TypeVariableOwner(type_var); | 4830 Dart_Handle type_var_owner = Dart_TypeVariableOwner(type_var); |
| 4861 EXPECT_VALID(type_var_owner); | 4831 EXPECT_VALID(type_var_owner); |
| 4862 EXPECT(Dart_IdentityEquals(cls, type_var_owner)); | 4832 EXPECT(Dart_IdentityEquals(cls, type_var_owner)); |
| 4863 Dart_Handle type_var_bound = Dart_TypeVariableUpperBound(type_var); | 4833 Dart_Handle type_var_bound = Dart_TypeVariableUpperBound(type_var); |
| 4864 Dart_Handle bound_name = Dart_ClassName(type_var_bound); | 4834 Dart_Handle bound_name = Dart_ClassName(type_var_bound); |
| 4865 EXPECT_VALID(Dart_StringToCString(bound_name, &cstr)); | 4835 EXPECT_VALID(Dart_StringToCString(bound_name, &cstr)); |
| 4866 EXPECT_STREQ("Object", cstr); | 4836 EXPECT_STREQ("Object", cstr); |
| 4867 | 4837 |
| 4868 // Test variable T. | 4838 // Test variable T. |
| 4869 type_var = Dart_LookupTypeVariable(cls, Dart_NewString("T")); | 4839 type_var = Dart_LookupTypeVariable(cls, NewString("T")); |
| 4870 EXPECT_VALID(type_var); | 4840 EXPECT_VALID(type_var); |
| 4871 EXPECT(Dart_IsTypeVariable(type_var)); | 4841 EXPECT(Dart_IsTypeVariable(type_var)); |
| 4872 type_var_name = Dart_TypeVariableName(type_var); | 4842 type_var_name = Dart_TypeVariableName(type_var); |
| 4873 EXPECT_VALID(type_var_name); | 4843 EXPECT_VALID(type_var_name); |
| 4874 EXPECT_VALID(Dart_StringToCString(type_var_name, &cstr)); | 4844 EXPECT_VALID(Dart_StringToCString(type_var_name, &cstr)); |
| 4875 EXPECT_STREQ("T", cstr); | 4845 EXPECT_STREQ("T", cstr); |
| 4876 type_var_owner = Dart_TypeVariableOwner(type_var); | 4846 type_var_owner = Dart_TypeVariableOwner(type_var); |
| 4877 EXPECT_VALID(type_var_owner); | 4847 EXPECT_VALID(type_var_owner); |
| 4878 EXPECT(Dart_IdentityEquals(cls, type_var_owner)); | 4848 EXPECT(Dart_IdentityEquals(cls, type_var_owner)); |
| 4879 type_var_bound = Dart_TypeVariableUpperBound(type_var); | 4849 type_var_bound = Dart_TypeVariableUpperBound(type_var); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4892 " InstanceOfTest() {}\n" | 4862 " InstanceOfTest() {}\n" |
| 4893 " static InstanceOfTest testMain() {\n" | 4863 " static InstanceOfTest testMain() {\n" |
| 4894 " return new InstanceOfTest();\n" | 4864 " return new InstanceOfTest();\n" |
| 4895 " }\n" | 4865 " }\n" |
| 4896 "}\n"; | 4866 "}\n"; |
| 4897 Dart_Handle result; | 4867 Dart_Handle result; |
| 4898 // Create a test library and Load up a test script in it. | 4868 // Create a test library and Load up a test script in it. |
| 4899 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4869 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4900 | 4870 |
| 4901 // Fetch InstanceOfTest class. | 4871 // Fetch InstanceOfTest class. |
| 4902 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest")); | 4872 Dart_Handle cls = Dart_GetClass(lib, NewString("InstanceOfTest")); |
| 4903 EXPECT_VALID(cls); | 4873 EXPECT_VALID(cls); |
| 4904 | 4874 |
| 4905 // Invoke a function which returns an object of type InstanceOf.. | 4875 // Invoke a function which returns an object of type InstanceOf.. |
| 4906 Dart_Handle instanceOfTestObj = | 4876 Dart_Handle instanceOfTestObj = |
| 4907 Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 4877 Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
| 4908 EXPECT_VALID(instanceOfTestObj); | 4878 EXPECT_VALID(instanceOfTestObj); |
| 4909 | 4879 |
| 4910 // Now check instanceOfTestObj reported as an instance of | 4880 // Now check instanceOfTestObj reported as an instance of |
| 4911 // InstanceOfTest class. | 4881 // InstanceOfTest class. |
| 4912 bool is_instance = false; | 4882 bool is_instance = false; |
| 4913 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance); | 4883 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance); |
| 4914 EXPECT_VALID(result); | 4884 EXPECT_VALID(result); |
| 4915 EXPECT(is_instance); | 4885 EXPECT(is_instance); |
| 4916 | 4886 |
| 4917 // Fetch OtherClass and check if instanceOfTestObj is instance of it. | 4887 // Fetch OtherClass and check if instanceOfTestObj is instance of it. |
| 4918 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass")); | 4888 Dart_Handle otherClass = Dart_GetClass(lib, NewString("OtherClass")); |
| 4919 EXPECT_VALID(otherClass); | 4889 EXPECT_VALID(otherClass); |
| 4920 | 4890 |
| 4921 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); | 4891 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); |
| 4922 EXPECT_VALID(result); | 4892 EXPECT_VALID(result); |
| 4923 EXPECT(!is_instance); | 4893 EXPECT(!is_instance); |
| 4924 | 4894 |
| 4925 // Check that primitives are not instances of InstanceOfTest class. | 4895 // Check that primitives are not instances of InstanceOfTest class. |
| 4926 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass, | 4896 result = Dart_ObjectIsType(NewString("a string"), otherClass, |
| 4927 &is_instance); | 4897 &is_instance); |
| 4928 EXPECT_VALID(result); | 4898 EXPECT_VALID(result); |
| 4929 EXPECT(!is_instance); | 4899 EXPECT(!is_instance); |
| 4930 | 4900 |
| 4931 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance); | 4901 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance); |
| 4932 EXPECT_VALID(result); | 4902 EXPECT_VALID(result); |
| 4933 EXPECT(!is_instance); | 4903 EXPECT(!is_instance); |
| 4934 | 4904 |
| 4935 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance); | 4905 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance); |
| 4936 EXPECT_VALID(result); | 4906 EXPECT_VALID(result); |
| 4937 EXPECT(!is_instance); | 4907 EXPECT(!is_instance); |
| 4938 | 4908 |
| 4939 // Check that null is not an instance of InstanceOfTest class. | 4909 // Check that null is not an instance of InstanceOfTest class. |
| 4940 Dart_Handle null = Dart_Invoke(otherClass, | 4910 Dart_Handle null = Dart_Invoke(otherClass, |
| 4941 Dart_NewString("returnNull"), | 4911 NewString("returnNull"), |
| 4942 0, | 4912 0, |
| 4943 NULL); | 4913 NULL); |
| 4944 EXPECT_VALID(null); | 4914 EXPECT_VALID(null); |
| 4945 | 4915 |
| 4946 result = Dart_ObjectIsType(null, otherClass, &is_instance); | 4916 result = Dart_ObjectIsType(null, otherClass, &is_instance); |
| 4947 EXPECT_VALID(result); | 4917 EXPECT_VALID(result); |
| 4948 EXPECT(!is_instance); | 4918 EXPECT(!is_instance); |
| 4949 | 4919 |
| 4950 // Check that error is returned if null is passed as a class argument. | 4920 // Check that error is returned if null is passed as a class argument. |
| 4951 result = Dart_ObjectIsType(null, null, &is_instance); | 4921 result = Dart_ObjectIsType(null, null, &is_instance); |
| 4952 EXPECT(Dart_IsError(result)); | 4922 EXPECT(Dart_IsError(result)); |
| 4953 } | 4923 } |
| 4954 | 4924 |
| 4955 | 4925 |
| 4956 static Dart_Handle library_handler(Dart_LibraryTag tag, | 4926 static Dart_Handle library_handler(Dart_LibraryTag tag, |
| 4957 Dart_Handle library, | 4927 Dart_Handle library, |
| 4958 Dart_Handle url) { | 4928 Dart_Handle url) { |
| 4959 if (tag == kCanonicalizeUrl) { | 4929 if (tag == kCanonicalizeUrl) { |
| 4960 return url; | 4930 return url; |
| 4961 } | 4931 } |
| 4962 return Api::Success(Isolate::Current()); | 4932 return Api::Success(Isolate::Current()); |
| 4963 } | 4933 } |
| 4964 | 4934 |
| 4965 | 4935 |
| 4966 TEST_CASE(LoadScript) { | 4936 TEST_CASE(LoadScript) { |
| 4967 const char* kScriptChars = | 4937 const char* kScriptChars = |
| 4968 "main() {" | 4938 "main() {" |
| 4969 " return 12345;" | 4939 " return 12345;" |
| 4970 "}"; | 4940 "}"; |
| 4971 Dart_Handle url = Dart_NewString(TestCase::url()); | 4941 Dart_Handle url = NewString(TestCase::url()); |
| 4972 Dart_Handle source = Dart_NewString(kScriptChars); | 4942 Dart_Handle source = NewString(kScriptChars); |
| 4973 Dart_Handle error = Dart_Error("incoming error"); | 4943 Dart_Handle error = Dart_Error("incoming error"); |
| 4974 Dart_Handle result; | 4944 Dart_Handle result; |
| 4975 | 4945 |
| 4976 result = Dart_SetLibraryTagHandler(library_handler); | 4946 result = Dart_SetLibraryTagHandler(library_handler); |
| 4977 EXPECT_VALID(result); | 4947 EXPECT_VALID(result); |
| 4978 | 4948 |
| 4979 result = Dart_LoadScript(Dart_Null(), source); | 4949 result = Dart_LoadScript(Dart_Null(), source); |
| 4980 EXPECT(Dart_IsError(result)); | 4950 EXPECT(Dart_IsError(result)); |
| 4981 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", | 4951 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", |
| 4982 Dart_GetError(result)); | 4952 Dart_GetError(result)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5002 Dart_GetError(result)); | 4972 Dart_GetError(result)); |
| 5003 | 4973 |
| 5004 result = Dart_LoadScript(url, error); | 4974 result = Dart_LoadScript(url, error); |
| 5005 EXPECT(Dart_IsError(result)); | 4975 EXPECT(Dart_IsError(result)); |
| 5006 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 4976 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5007 | 4977 |
| 5008 // Load a script successfully. | 4978 // Load a script successfully. |
| 5009 result = Dart_LoadScript(url, source); | 4979 result = Dart_LoadScript(url, source); |
| 5010 EXPECT_VALID(result); | 4980 EXPECT_VALID(result); |
| 5011 | 4981 |
| 5012 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 4982 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 5013 EXPECT_VALID(result); | 4983 EXPECT_VALID(result); |
| 5014 EXPECT(Dart_IsInteger(result)); | 4984 EXPECT(Dart_IsInteger(result)); |
| 5015 int64_t value = 0; | 4985 int64_t value = 0; |
| 5016 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 4986 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5017 EXPECT_EQ(12345, value); | 4987 EXPECT_EQ(12345, value); |
| 5018 | 4988 |
| 5019 // Further calls to LoadScript are errors. | 4989 // Further calls to LoadScript are errors. |
| 5020 result = Dart_LoadScript(url, source); | 4990 result = Dart_LoadScript(url, source); |
| 5021 EXPECT(Dart_IsError(result)); | 4991 EXPECT(Dart_IsError(result)); |
| 5022 EXPECT_STREQ("Dart_LoadScript: " | 4992 EXPECT_STREQ("Dart_LoadScript: " |
| 5023 "A script has already been loaded from 'dart:test-lib'.", | 4993 "A script has already been loaded from 'dart:test-lib'.", |
| 5024 Dart_GetError(result)); | 4994 Dart_GetError(result)); |
| 5025 } | 4995 } |
| 5026 | 4996 |
| 5027 | 4997 |
| 5028 TEST_CASE(RootLibrary) { | 4998 TEST_CASE(RootLibrary) { |
| 5029 const char* kScriptChars = | 4999 const char* kScriptChars = |
| 5030 "main() {" | 5000 "main() {" |
| 5031 " return 12345;" | 5001 " return 12345;" |
| 5032 "}"; | 5002 "}"; |
| 5033 | 5003 |
| 5034 Dart_Handle root_lib = Dart_RootLibrary(); | 5004 Dart_Handle root_lib = Dart_RootLibrary(); |
| 5035 EXPECT_VALID(root_lib); | 5005 EXPECT_VALID(root_lib); |
| 5036 EXPECT(Dart_IsNull(root_lib)); | 5006 EXPECT(Dart_IsNull(root_lib)); |
| 5037 | 5007 |
| 5038 // Load a script. | 5008 // Load a script. |
| 5039 Dart_Handle url = Dart_NewString(TestCase::url()); | 5009 Dart_Handle url = NewString(TestCase::url()); |
| 5040 Dart_Handle source = Dart_NewString(kScriptChars); | 5010 Dart_Handle source = NewString(kScriptChars); |
| 5041 EXPECT_VALID(Dart_LoadScript(url, source)); | 5011 EXPECT_VALID(Dart_LoadScript(url, source)); |
| 5042 | 5012 |
| 5043 root_lib = Dart_RootLibrary(); | 5013 root_lib = Dart_RootLibrary(); |
| 5044 Dart_Handle lib_name = Dart_LibraryName(root_lib); | 5014 Dart_Handle lib_name = Dart_LibraryName(root_lib); |
| 5045 EXPECT_VALID(lib_name); | 5015 EXPECT_VALID(lib_name); |
| 5046 EXPECT(!Dart_IsNull(root_lib)); | 5016 EXPECT(!Dart_IsNull(root_lib)); |
| 5047 const char* name_cstr = ""; | 5017 const char* name_cstr = ""; |
| 5048 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); | 5018 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); |
| 5049 EXPECT_STREQ(TestCase::url(), name_cstr); | 5019 EXPECT_STREQ(TestCase::url(), name_cstr); |
| 5050 } | 5020 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5083 return Api::NewError("invalid callback"); | 5053 return Api::NewError("invalid callback"); |
| 5084 } | 5054 } |
| 5085 index += 1; | 5055 index += 1; |
| 5086 return Api::Success(Isolate::Current()); | 5056 return Api::Success(Isolate::Current()); |
| 5087 } | 5057 } |
| 5088 | 5058 |
| 5089 | 5059 |
| 5090 TEST_CASE(LoadScript_CompileError) { | 5060 TEST_CASE(LoadScript_CompileError) { |
| 5091 const char* kScriptChars = | 5061 const char* kScriptChars = |
| 5092 ")"; | 5062 ")"; |
| 5093 Dart_Handle url = Dart_NewString(TestCase::url()); | 5063 Dart_Handle url = NewString(TestCase::url()); |
| 5094 Dart_Handle source = Dart_NewString(kScriptChars); | 5064 Dart_Handle source = NewString(kScriptChars); |
| 5095 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 5065 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
| 5096 EXPECT_VALID(result); | 5066 EXPECT_VALID(result); |
| 5097 result = Dart_LoadScript(url, source); | 5067 result = Dart_LoadScript(url, source); |
| 5098 EXPECT(Dart_IsError(result)); | 5068 EXPECT(Dart_IsError(result)); |
| 5099 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 5069 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
| 5100 } | 5070 } |
| 5101 | 5071 |
| 5102 | 5072 |
| 5103 TEST_CASE(LookupLibrary) { | 5073 TEST_CASE(LookupLibrary) { |
| 5104 const char* kScriptChars = | 5074 const char* kScriptChars = |
| 5105 "#import('library1.dart');" | 5075 "#import('library1.dart');" |
| 5106 "main() {}"; | 5076 "main() {}"; |
| 5107 const char* kLibrary1Chars = | 5077 const char* kLibrary1Chars = |
| 5108 "#library('library1.dart');" | 5078 "#library('library1.dart');" |
| 5109 "#import('library2.dart');"; | 5079 "#import('library2.dart');"; |
| 5110 | 5080 |
| 5111 // Create a test library and Load up a test script in it. | 5081 // Create a test library and Load up a test script in it. |
| 5112 Dart_Handle url = Dart_NewString(TestCase::url()); | 5082 Dart_Handle url = NewString(TestCase::url()); |
| 5113 Dart_Handle source = Dart_NewString(kScriptChars); | 5083 Dart_Handle source = NewString(kScriptChars); |
| 5114 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); | 5084 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); |
| 5115 EXPECT_VALID(result); | 5085 EXPECT_VALID(result); |
| 5116 result = Dart_LoadScript(url, source); | 5086 result = Dart_LoadScript(url, source); |
| 5117 EXPECT_VALID(result); | 5087 EXPECT_VALID(result); |
| 5118 | 5088 |
| 5119 url = Dart_NewString("library1.dart"); | 5089 url = NewString("library1.dart"); |
| 5120 source = Dart_NewString(kLibrary1Chars); | 5090 source = NewString(kLibrary1Chars); |
| 5121 result = Dart_LoadLibrary(url, source); | 5091 result = Dart_LoadLibrary(url, source); |
| 5122 EXPECT_VALID(result); | 5092 EXPECT_VALID(result); |
| 5123 | 5093 |
| 5124 result = Dart_LookupLibrary(url); | 5094 result = Dart_LookupLibrary(url); |
| 5125 EXPECT_VALID(result); | 5095 EXPECT_VALID(result); |
| 5126 | 5096 |
| 5127 result = Dart_LookupLibrary(Dart_Null()); | 5097 result = Dart_LookupLibrary(Dart_Null()); |
| 5128 EXPECT(Dart_IsError(result)); | 5098 EXPECT(Dart_IsError(result)); |
| 5129 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", | 5099 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", |
| 5130 Dart_GetError(result)); | 5100 Dart_GetError(result)); |
| 5131 | 5101 |
| 5132 result = Dart_LookupLibrary(Dart_True()); | 5102 result = Dart_LookupLibrary(Dart_True()); |
| 5133 EXPECT(Dart_IsError(result)); | 5103 EXPECT(Dart_IsError(result)); |
| 5134 EXPECT_STREQ( | 5104 EXPECT_STREQ( |
| 5135 "Dart_LookupLibrary expects argument 'url' to be of type String.", | 5105 "Dart_LookupLibrary expects argument 'url' to be of type String.", |
| 5136 Dart_GetError(result)); | 5106 Dart_GetError(result)); |
| 5137 | 5107 |
| 5138 result = Dart_LookupLibrary(Dart_Error("incoming error")); | 5108 result = Dart_LookupLibrary(Dart_Error("incoming error")); |
| 5139 EXPECT(Dart_IsError(result)); | 5109 EXPECT(Dart_IsError(result)); |
| 5140 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5110 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5141 | 5111 |
| 5142 url = Dart_NewString("noodles.dart"); | 5112 url = NewString("noodles.dart"); |
| 5143 result = Dart_LookupLibrary(url); | 5113 result = Dart_LookupLibrary(url); |
| 5144 EXPECT(Dart_IsError(result)); | 5114 EXPECT(Dart_IsError(result)); |
| 5145 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", | 5115 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", |
| 5146 Dart_GetError(result)); | 5116 Dart_GetError(result)); |
| 5147 } | 5117 } |
| 5148 | 5118 |
| 5149 | 5119 |
| 5150 TEST_CASE(LibraryName) { | 5120 TEST_CASE(LibraryName) { |
| 5151 const char* kLibrary1Chars = | 5121 const char* kLibrary1Chars = |
| 5152 "#library('library1_name');"; | 5122 "#library('library1_name');"; |
| 5153 Dart_Handle url = Dart_NewString("library1_url"); | 5123 Dart_Handle url = NewString("library1_url"); |
| 5154 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5124 Dart_Handle source = NewString(kLibrary1Chars); |
| 5155 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5125 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5156 Dart_Handle error = Dart_Error("incoming error"); | 5126 Dart_Handle error = Dart_Error("incoming error"); |
| 5157 EXPECT_VALID(lib); | 5127 EXPECT_VALID(lib); |
| 5158 | 5128 |
| 5159 Dart_Handle result = Dart_LibraryName(Dart_Null()); | 5129 Dart_Handle result = Dart_LibraryName(Dart_Null()); |
| 5160 EXPECT(Dart_IsError(result)); | 5130 EXPECT(Dart_IsError(result)); |
| 5161 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.", | 5131 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.", |
| 5162 Dart_GetError(result)); | 5132 Dart_GetError(result)); |
| 5163 | 5133 |
| 5164 result = Dart_LibraryName(Dart_True()); | 5134 result = Dart_LibraryName(Dart_True()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5176 EXPECT(Dart_IsString(result)); | 5146 EXPECT(Dart_IsString(result)); |
| 5177 const char* cstr = NULL; | 5147 const char* cstr = NULL; |
| 5178 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 5148 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
| 5179 EXPECT_STREQ("library1_name", cstr); | 5149 EXPECT_STREQ("library1_name", cstr); |
| 5180 } | 5150 } |
| 5181 | 5151 |
| 5182 | 5152 |
| 5183 TEST_CASE(LibraryUrl) { | 5153 TEST_CASE(LibraryUrl) { |
| 5184 const char* kLibrary1Chars = | 5154 const char* kLibrary1Chars = |
| 5185 "#library('library1_name');"; | 5155 "#library('library1_name');"; |
| 5186 Dart_Handle url = Dart_NewString("library1_url"); | 5156 Dart_Handle url = NewString("library1_url"); |
| 5187 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5157 Dart_Handle source = NewString(kLibrary1Chars); |
| 5188 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5158 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5189 Dart_Handle error = Dart_Error("incoming error"); | 5159 Dart_Handle error = Dart_Error("incoming error"); |
| 5190 EXPECT_VALID(lib); | 5160 EXPECT_VALID(lib); |
| 5191 | 5161 |
| 5192 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); | 5162 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); |
| 5193 EXPECT(Dart_IsError(result)); | 5163 EXPECT(Dart_IsError(result)); |
| 5194 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", | 5164 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", |
| 5195 Dart_GetError(result)); | 5165 Dart_GetError(result)); |
| 5196 | 5166 |
| 5197 result = Dart_LibraryUrl(Dart_True()); | 5167 result = Dart_LibraryUrl(Dart_True()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5220 "class A {}\n" | 5190 "class A {}\n" |
| 5221 "class B {}\n" | 5191 "class B {}\n" |
| 5222 "interface C {}\n" | 5192 "interface C {}\n" |
| 5223 "class _A {}\n" | 5193 "class _A {}\n" |
| 5224 "class _B {}\n" | 5194 "class _B {}\n" |
| 5225 "interface _C {}\n" | 5195 "interface _C {}\n" |
| 5226 "\n" | 5196 "\n" |
| 5227 "_compare(String a, String b) => a.compareTo(b);\n" | 5197 "_compare(String a, String b) => a.compareTo(b);\n" |
| 5228 "sort(list) => list.sort(_compare);\n"; | 5198 "sort(list) => list.sort(_compare);\n"; |
| 5229 | 5199 |
| 5230 Dart_Handle url = Dart_NewString("library_url"); | 5200 Dart_Handle url = NewString("library_url"); |
| 5231 Dart_Handle source = Dart_NewString(kLibraryChars); | 5201 Dart_Handle source = NewString(kLibraryChars); |
| 5232 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5202 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5233 EXPECT_VALID(lib); | 5203 EXPECT_VALID(lib); |
| 5234 | 5204 |
| 5235 Dart_Handle list = Dart_LibraryGetClassNames(lib); | 5205 Dart_Handle list = Dart_LibraryGetClassNames(lib); |
| 5236 EXPECT_VALID(list); | 5206 EXPECT_VALID(list); |
| 5237 EXPECT(Dart_IsList(list)); | 5207 EXPECT(Dart_IsList(list)); |
| 5238 | 5208 |
| 5239 // Sort the list. | 5209 // Sort the list. |
| 5240 const int kNumArgs = 1; | 5210 const int kNumArgs = 1; |
| 5241 Dart_Handle args[1]; | 5211 Dart_Handle args[1]; |
| 5242 args[0] = list; | 5212 args[0] = list; |
| 5243 EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); | 5213 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
| 5244 | 5214 |
| 5245 Dart_Handle list_string = Dart_ToString(list); | 5215 Dart_Handle list_string = Dart_ToString(list); |
| 5246 EXPECT_VALID(list_string); | 5216 EXPECT_VALID(list_string); |
| 5247 const char* list_cstr = ""; | 5217 const char* list_cstr = ""; |
| 5248 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 5218 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
| 5249 EXPECT_STREQ("[A, B, C, _A, _B, _C]", list_cstr); | 5219 EXPECT_STREQ("[A, B, C, _A, _B, _C]", list_cstr); |
| 5250 } | 5220 } |
| 5251 | 5221 |
| 5252 | 5222 |
| 5253 TEST_CASE(GetFunctionNames) { | 5223 TEST_CASE(GetFunctionNames) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5271 " void _A2() {}\n" | 5241 " void _A2() {}\n" |
| 5272 " get _B2 => 11;\n" | 5242 " get _B2 => 11;\n" |
| 5273 " set _C2(x) { }\n" | 5243 " set _C2(x) { }\n" |
| 5274 " var _D2;\n" | 5244 " var _D2;\n" |
| 5275 "}\n" | 5245 "}\n" |
| 5276 "\n" | 5246 "\n" |
| 5277 "_compare(String a, String b) => a.compareTo(b);\n" | 5247 "_compare(String a, String b) => a.compareTo(b);\n" |
| 5278 "sort(list) => list.sort(_compare);\n"; | 5248 "sort(list) => list.sort(_compare);\n"; |
| 5279 | 5249 |
| 5280 // Get the functions from a library. | 5250 // Get the functions from a library. |
| 5281 Dart_Handle url = Dart_NewString("library_url"); | 5251 Dart_Handle url = NewString("library_url"); |
| 5282 Dart_Handle source = Dart_NewString(kLibraryChars); | 5252 Dart_Handle source = NewString(kLibraryChars); |
| 5283 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5253 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5284 EXPECT_VALID(lib); | 5254 EXPECT_VALID(lib); |
| 5285 | 5255 |
| 5286 Dart_Handle list = Dart_GetFunctionNames(lib); | 5256 Dart_Handle list = Dart_GetFunctionNames(lib); |
| 5287 EXPECT_VALID(list); | 5257 EXPECT_VALID(list); |
| 5288 EXPECT(Dart_IsList(list)); | 5258 EXPECT(Dart_IsList(list)); |
| 5289 | 5259 |
| 5290 // Sort the list. | 5260 // Sort the list. |
| 5291 const int kNumArgs = 1; | 5261 const int kNumArgs = 1; |
| 5292 Dart_Handle args[1]; | 5262 Dart_Handle args[1]; |
| 5293 args[0] = list; | 5263 args[0] = list; |
| 5294 EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); | 5264 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
| 5295 | 5265 |
| 5296 Dart_Handle list_string = Dart_ToString(list); | 5266 Dart_Handle list_string = Dart_ToString(list); |
| 5297 EXPECT_VALID(list_string); | 5267 EXPECT_VALID(list_string); |
| 5298 const char* list_cstr = ""; | 5268 const char* list_cstr = ""; |
| 5299 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 5269 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
| 5300 EXPECT_STREQ("[A, B, C=, _A, _B, _C=, _compare, sort]", list_cstr); | 5270 EXPECT_STREQ("[A, B, C=, _A, _B, _C=, _compare, sort]", list_cstr); |
| 5301 | 5271 |
| 5302 // Get the functions from a class. | 5272 // Get the functions from a class. |
| 5303 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); | 5273 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); |
| 5304 EXPECT_VALID(cls); | 5274 EXPECT_VALID(cls); |
| 5305 | 5275 |
| 5306 list = Dart_GetFunctionNames(cls); | 5276 list = Dart_GetFunctionNames(cls); |
| 5307 EXPECT_VALID(list); | 5277 EXPECT_VALID(list); |
| 5308 EXPECT(Dart_IsList(list)); | 5278 EXPECT(Dart_IsList(list)); |
| 5309 | 5279 |
| 5310 // Sort the list. | 5280 // Sort the list. |
| 5311 args[0] = list; | 5281 args[0] = list; |
| 5312 EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); | 5282 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
| 5313 | 5283 |
| 5314 // Check list contents. | 5284 // Check list contents. |
| 5315 list_string = Dart_ToString(list); | 5285 list_string = Dart_ToString(list); |
| 5316 EXPECT_VALID(list_string); | 5286 EXPECT_VALID(list_string); |
| 5317 list_cstr = ""; | 5287 list_cstr = ""; |
| 5318 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 5288 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
| 5319 EXPECT_STREQ("[A2, B2, C2=, MyClass, _A2, _B2, _C2=]", list_cstr); | 5289 EXPECT_STREQ("[A2, B2, C2=, MyClass, _A2, _B2, _C2=]", list_cstr); |
| 5320 } | 5290 } |
| 5321 | 5291 |
| 5322 | 5292 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5335 "\n" | 5305 "\n" |
| 5336 "class MyClass {\n" | 5306 "class MyClass {\n" |
| 5337 " var A2;\n" | 5307 " var A2;\n" |
| 5338 " var _A2;\n" | 5308 " var _A2;\n" |
| 5339 "}\n" | 5309 "}\n" |
| 5340 "\n" | 5310 "\n" |
| 5341 "_compare(String a, String b) => a.compareTo(b);\n" | 5311 "_compare(String a, String b) => a.compareTo(b);\n" |
| 5342 "sort(list) => list.sort(_compare);\n"; | 5312 "sort(list) => list.sort(_compare);\n"; |
| 5343 | 5313 |
| 5344 // Get the variables from a library. | 5314 // Get the variables from a library. |
| 5345 Dart_Handle url = Dart_NewString("library_url"); | 5315 Dart_Handle url = NewString("library_url"); |
| 5346 Dart_Handle source = Dart_NewString(kLibraryChars); | 5316 Dart_Handle source = NewString(kLibraryChars); |
| 5347 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5317 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5348 EXPECT_VALID(lib); | 5318 EXPECT_VALID(lib); |
| 5349 | 5319 |
| 5350 Dart_Handle list = Dart_GetVariableNames(lib); | 5320 Dart_Handle list = Dart_GetVariableNames(lib); |
| 5351 EXPECT_VALID(list); | 5321 EXPECT_VALID(list); |
| 5352 EXPECT(Dart_IsList(list)); | 5322 EXPECT(Dart_IsList(list)); |
| 5353 | 5323 |
| 5354 // Sort the list. | 5324 // Sort the list. |
| 5355 const int kNumArgs = 1; | 5325 const int kNumArgs = 1; |
| 5356 Dart_Handle args[1]; | 5326 Dart_Handle args[1]; |
| 5357 args[0] = list; | 5327 args[0] = list; |
| 5358 EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); | 5328 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
| 5359 | 5329 |
| 5360 // Check list contents. | 5330 // Check list contents. |
| 5361 Dart_Handle list_string = Dart_ToString(list); | 5331 Dart_Handle list_string = Dart_ToString(list); |
| 5362 EXPECT_VALID(list_string); | 5332 EXPECT_VALID(list_string); |
| 5363 const char* list_cstr = ""; | 5333 const char* list_cstr = ""; |
| 5364 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 5334 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
| 5365 EXPECT_STREQ("[A, _A]", list_cstr); | 5335 EXPECT_STREQ("[A, _A]", list_cstr); |
| 5366 | 5336 |
| 5367 // Get the variables from a class. | 5337 // Get the variables from a class. |
| 5368 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); | 5338 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); |
| 5369 EXPECT_VALID(cls); | 5339 EXPECT_VALID(cls); |
| 5370 | 5340 |
| 5371 list = Dart_GetVariableNames(cls); | 5341 list = Dart_GetVariableNames(cls); |
| 5372 EXPECT_VALID(list); | 5342 EXPECT_VALID(list); |
| 5373 EXPECT(Dart_IsList(list)); | 5343 EXPECT(Dart_IsList(list)); |
| 5374 | 5344 |
| 5375 // Sort the list. | 5345 // Sort the list. |
| 5376 args[0] = list; | 5346 args[0] = list; |
| 5377 EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); | 5347 EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); |
| 5378 | 5348 |
| 5379 // Check list contents. | 5349 // Check list contents. |
| 5380 list_string = Dart_ToString(list); | 5350 list_string = Dart_ToString(list); |
| 5381 EXPECT_VALID(list_string); | 5351 EXPECT_VALID(list_string); |
| 5382 list_cstr = ""; | 5352 list_cstr = ""; |
| 5383 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 5353 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
| 5384 EXPECT_STREQ("[A2, _A2]", list_cstr); | 5354 EXPECT_STREQ("[A2, _A2]", list_cstr); |
| 5385 } | 5355 } |
| 5386 | 5356 |
| 5387 | 5357 |
| 5388 TEST_CASE(LibraryImportLibrary) { | 5358 TEST_CASE(LibraryImportLibrary) { |
| 5389 const char* kLibrary1Chars = | 5359 const char* kLibrary1Chars = |
| 5390 "#library('library1_name');"; | 5360 "#library('library1_name');"; |
| 5391 const char* kLibrary2Chars = | 5361 const char* kLibrary2Chars = |
| 5392 "#library('library2_name');"; | 5362 "#library('library2_name');"; |
| 5393 Dart_Handle error = Dart_Error("incoming error"); | 5363 Dart_Handle error = Dart_Error("incoming error"); |
| 5394 Dart_Handle result; | 5364 Dart_Handle result; |
| 5395 | 5365 |
| 5396 Dart_Handle url = Dart_NewString("library1_url"); | 5366 Dart_Handle url = NewString("library1_url"); |
| 5397 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5367 Dart_Handle source = NewString(kLibrary1Chars); |
| 5398 Dart_Handle lib1 = Dart_LoadLibrary(url, source); | 5368 Dart_Handle lib1 = Dart_LoadLibrary(url, source); |
| 5399 EXPECT_VALID(lib1); | 5369 EXPECT_VALID(lib1); |
| 5400 | 5370 |
| 5401 url = Dart_NewString("library2_url"); | 5371 url = NewString("library2_url"); |
| 5402 source = Dart_NewString(kLibrary2Chars); | 5372 source = NewString(kLibrary2Chars); |
| 5403 Dart_Handle lib2 = Dart_LoadLibrary(url, source); | 5373 Dart_Handle lib2 = Dart_LoadLibrary(url, source); |
| 5404 EXPECT_VALID(lib2); | 5374 EXPECT_VALID(lib2); |
| 5405 | 5375 |
| 5406 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, Dart_Null()); | 5376 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, Dart_Null()); |
| 5407 EXPECT(Dart_IsError(result)); | 5377 EXPECT(Dart_IsError(result)); |
| 5408 EXPECT_STREQ( | 5378 EXPECT_STREQ( |
| 5409 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", | 5379 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", |
| 5410 Dart_GetError(result)); | 5380 Dart_GetError(result)); |
| 5411 | 5381 |
| 5412 result = Dart_LibraryImportLibrary(Dart_True(), lib2, Dart_Null()); | 5382 result = Dart_LibraryImportLibrary(Dart_True(), lib2, Dart_Null()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5437 | 5407 |
| 5438 result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); | 5408 result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); |
| 5439 EXPECT_VALID(result); | 5409 EXPECT_VALID(result); |
| 5440 } | 5410 } |
| 5441 | 5411 |
| 5442 | 5412 |
| 5443 TEST_CASE(ImportLibraryWithPrefix) { | 5413 TEST_CASE(ImportLibraryWithPrefix) { |
| 5444 const char* kLibrary1Chars = | 5414 const char* kLibrary1Chars = |
| 5445 "#library('library1_name');" | 5415 "#library('library1_name');" |
| 5446 "int bar() => 42;"; | 5416 "int bar() => 42;"; |
| 5447 Dart_Handle url1 = Dart_NewString("library1_url"); | 5417 Dart_Handle url1 = NewString("library1_url"); |
| 5448 Dart_Handle source1 = Dart_NewString(kLibrary1Chars); | 5418 Dart_Handle source1 = NewString(kLibrary1Chars); |
| 5449 Dart_Handle lib1 = Dart_LoadLibrary(url1, source1); | 5419 Dart_Handle lib1 = Dart_LoadLibrary(url1, source1); |
| 5450 EXPECT_VALID(lib1); | 5420 EXPECT_VALID(lib1); |
| 5451 EXPECT(Dart_IsLibrary(lib1)); | 5421 EXPECT(Dart_IsLibrary(lib1)); |
| 5452 | 5422 |
| 5453 const char* kLibrary2Chars = | 5423 const char* kLibrary2Chars = |
| 5454 "#library('library2_name');" | 5424 "#library('library2_name');" |
| 5455 "int foobar() => foo.bar();"; | 5425 "int foobar() => foo.bar();"; |
| 5456 Dart_Handle url2 = Dart_NewString("library2_url"); | 5426 Dart_Handle url2 = NewString("library2_url"); |
| 5457 Dart_Handle source2 = Dart_NewString(kLibrary2Chars); | 5427 Dart_Handle source2 = NewString(kLibrary2Chars); |
| 5458 Dart_Handle lib2 = Dart_LoadLibrary(url2, source2); | 5428 Dart_Handle lib2 = Dart_LoadLibrary(url2, source2); |
| 5459 EXPECT_VALID(lib2); | 5429 EXPECT_VALID(lib2); |
| 5460 EXPECT(Dart_IsLibrary(lib2)); | 5430 EXPECT(Dart_IsLibrary(lib2)); |
| 5461 | 5431 |
| 5462 Dart_Handle prefix = Dart_NewString("foo"); | 5432 Dart_Handle prefix = NewString("foo"); |
| 5463 Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); | 5433 Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); |
| 5464 EXPECT_VALID(result); | 5434 EXPECT_VALID(result); |
| 5465 | 5435 |
| 5466 // Lib1 is imported under a library prefix and therefore 'foo' should | 5436 // Lib1 is imported under a library prefix and therefore 'foo' should |
| 5467 // not be found directly in lib2. | 5437 // not be found directly in lib2. |
| 5468 Dart_Handle method_name = Dart_NewString("foo"); | 5438 Dart_Handle method_name = NewString("foo"); |
| 5469 result = Dart_Invoke(lib2, method_name, 0, NULL); | 5439 result = Dart_Invoke(lib2, method_name, 0, NULL); |
| 5470 EXPECT_ERROR(result, "Dart_Invoke: did not find top-level function 'foo'"); | 5440 EXPECT_ERROR(result, "Dart_Invoke: did not find top-level function 'foo'"); |
| 5471 | 5441 |
| 5472 // Check that lib1 is available under the prefix in lib2. | 5442 // Check that lib1 is available under the prefix in lib2. |
| 5473 method_name = Dart_NewString("foobar"); | 5443 method_name = NewString("foobar"); |
| 5474 result = Dart_Invoke(lib2, method_name, 0, NULL); | 5444 result = Dart_Invoke(lib2, method_name, 0, NULL); |
| 5475 EXPECT_VALID(result); | 5445 EXPECT_VALID(result); |
| 5476 EXPECT(Dart_IsInteger(result)); | 5446 EXPECT(Dart_IsInteger(result)); |
| 5477 int64_t value = 0; | 5447 int64_t value = 0; |
| 5478 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5448 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5479 EXPECT_EQ(42, value); | 5449 EXPECT_EQ(42, value); |
| 5480 } | 5450 } |
| 5481 | 5451 |
| 5482 | 5452 |
| 5483 | 5453 |
| 5484 TEST_CASE(LoadLibrary) { | 5454 TEST_CASE(LoadLibrary) { |
| 5485 const char* kLibrary1Chars = | 5455 const char* kLibrary1Chars = |
| 5486 "#library('library1_name');"; | 5456 "#library('library1_name');"; |
| 5487 Dart_Handle error = Dart_Error("incoming error"); | 5457 Dart_Handle error = Dart_Error("incoming error"); |
| 5488 Dart_Handle result; | 5458 Dart_Handle result; |
| 5489 | 5459 |
| 5490 Dart_Handle url = Dart_NewString("library1_url"); | 5460 Dart_Handle url = NewString("library1_url"); |
| 5491 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5461 Dart_Handle source = NewString(kLibrary1Chars); |
| 5492 | 5462 |
| 5493 result = Dart_LoadLibrary(Dart_Null(), source); | 5463 result = Dart_LoadLibrary(Dart_Null(), source); |
| 5494 EXPECT(Dart_IsError(result)); | 5464 EXPECT(Dart_IsError(result)); |
| 5495 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", | 5465 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", |
| 5496 Dart_GetError(result)); | 5466 Dart_GetError(result)); |
| 5497 | 5467 |
| 5498 result = Dart_LoadLibrary(Dart_True(), source); | 5468 result = Dart_LoadLibrary(Dart_True(), source); |
| 5499 EXPECT(Dart_IsError(result)); | 5469 EXPECT(Dart_IsError(result)); |
| 5500 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.", | 5470 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.", |
| 5501 Dart_GetError(result)); | 5471 Dart_GetError(result)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5530 EXPECT_STREQ( | 5500 EXPECT_STREQ( |
| 5531 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", | 5501 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", |
| 5532 Dart_GetError(result)); | 5502 Dart_GetError(result)); |
| 5533 } | 5503 } |
| 5534 | 5504 |
| 5535 | 5505 |
| 5536 TEST_CASE(LoadLibrary_CompileError) { | 5506 TEST_CASE(LoadLibrary_CompileError) { |
| 5537 const char* kLibrary1Chars = | 5507 const char* kLibrary1Chars = |
| 5538 "#library('library1_name');" | 5508 "#library('library1_name');" |
| 5539 ")"; | 5509 ")"; |
| 5540 Dart_Handle url = Dart_NewString("library1_url"); | 5510 Dart_Handle url = NewString("library1_url"); |
| 5541 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5511 Dart_Handle source = NewString(kLibrary1Chars); |
| 5542 Dart_Handle result = Dart_LoadLibrary(url, source); | 5512 Dart_Handle result = Dart_LoadLibrary(url, source); |
| 5543 EXPECT(Dart_IsError(result)); | 5513 EXPECT(Dart_IsError(result)); |
| 5544 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 5514 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
| 5545 } | 5515 } |
| 5546 | 5516 |
| 5547 | 5517 |
| 5548 TEST_CASE(LoadSource) { | 5518 TEST_CASE(LoadSource) { |
| 5549 const char* kLibrary1Chars = | 5519 const char* kLibrary1Chars = |
| 5550 "#library('library1_name');"; | 5520 "#library('library1_name');"; |
| 5551 const char* kSourceChars = | 5521 const char* kSourceChars = |
| 5552 "// Something innocuous"; | 5522 "// Something innocuous"; |
| 5553 const char* kBadSourceChars = | 5523 const char* kBadSourceChars = |
| 5554 ")"; | 5524 ")"; |
| 5555 Dart_Handle error = Dart_Error("incoming error"); | 5525 Dart_Handle error = Dart_Error("incoming error"); |
| 5556 Dart_Handle result; | 5526 Dart_Handle result; |
| 5557 | 5527 |
| 5558 // Load up a library. | 5528 // Load up a library. |
| 5559 Dart_Handle url = Dart_NewString("library1_url"); | 5529 Dart_Handle url = NewString("library1_url"); |
| 5560 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5530 Dart_Handle source = NewString(kLibrary1Chars); |
| 5561 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5531 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5562 EXPECT_VALID(lib); | 5532 EXPECT_VALID(lib); |
| 5563 EXPECT(Dart_IsLibrary(lib)); | 5533 EXPECT(Dart_IsLibrary(lib)); |
| 5564 | 5534 |
| 5565 url = Dart_NewString("source_url"); | 5535 url = NewString("source_url"); |
| 5566 source = Dart_NewString(kSourceChars); | 5536 source = NewString(kSourceChars); |
| 5567 | 5537 |
| 5568 result = Dart_LoadSource(Dart_Null(), url, source); | 5538 result = Dart_LoadSource(Dart_Null(), url, source); |
| 5569 EXPECT(Dart_IsError(result)); | 5539 EXPECT(Dart_IsError(result)); |
| 5570 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.", | 5540 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.", |
| 5571 Dart_GetError(result)); | 5541 Dart_GetError(result)); |
| 5572 | 5542 |
| 5573 result = Dart_LoadSource(Dart_True(), url, source); | 5543 result = Dart_LoadSource(Dart_True(), url, source); |
| 5574 EXPECT(Dart_IsError(result)); | 5544 EXPECT(Dart_IsError(result)); |
| 5575 EXPECT_STREQ( | 5545 EXPECT_STREQ( |
| 5576 "Dart_LoadSource expects argument 'library' to be of type Library.", | 5546 "Dart_LoadSource expects argument 'library' to be of type Library.", |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5615 EXPECT(Dart_IsLibrary(result)); | 5585 EXPECT(Dart_IsLibrary(result)); |
| 5616 EXPECT(Dart_IdentityEquals(lib, result)); | 5586 EXPECT(Dart_IdentityEquals(lib, result)); |
| 5617 | 5587 |
| 5618 // Duplicate calls are okay. | 5588 // Duplicate calls are okay. |
| 5619 result = Dart_LoadSource(lib, url, source); | 5589 result = Dart_LoadSource(lib, url, source); |
| 5620 EXPECT_VALID(result); | 5590 EXPECT_VALID(result); |
| 5621 EXPECT(Dart_IsLibrary(result)); | 5591 EXPECT(Dart_IsLibrary(result)); |
| 5622 EXPECT(Dart_IdentityEquals(lib, result)); | 5592 EXPECT(Dart_IdentityEquals(lib, result)); |
| 5623 | 5593 |
| 5624 // Language errors are detected. | 5594 // Language errors are detected. |
| 5625 source = Dart_NewString(kBadSourceChars); | 5595 source = NewString(kBadSourceChars); |
| 5626 result = Dart_LoadSource(lib, url, source); | 5596 result = Dart_LoadSource(lib, url, source); |
| 5627 EXPECT(Dart_IsError(result)); | 5597 EXPECT(Dart_IsError(result)); |
| 5628 } | 5598 } |
| 5629 | 5599 |
| 5630 | 5600 |
| 5631 TEST_CASE(LoadSource_LateLoad) { | 5601 TEST_CASE(LoadSource_LateLoad) { |
| 5632 const char* kLibrary1Chars = | 5602 const char* kLibrary1Chars = |
| 5633 "#library('library1_name');\n" | 5603 "#library('library1_name');\n" |
| 5634 "class OldClass {\n" | 5604 "class OldClass {\n" |
| 5635 " foo() => 'foo';\n" | 5605 " foo() => 'foo';\n" |
| 5636 "}\n"; | 5606 "}\n"; |
| 5637 const char* kSourceChars = | 5607 const char* kSourceChars = |
| 5638 "class NewClass extends OldClass{\n" | 5608 "class NewClass extends OldClass{\n" |
| 5639 " bar() => 'bar';\n" | 5609 " bar() => 'bar';\n" |
| 5640 "}\n"; | 5610 "}\n"; |
| 5641 Dart_Handle url = Dart_NewString("library1_url"); | 5611 Dart_Handle url = NewString("library1_url"); |
| 5642 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5612 Dart_Handle source = NewString(kLibrary1Chars); |
| 5643 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5613 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5644 EXPECT_VALID(lib); | 5614 EXPECT_VALID(lib); |
| 5645 EXPECT(Dart_IsLibrary(lib)); | 5615 EXPECT(Dart_IsLibrary(lib)); |
| 5646 | 5616 |
| 5647 // Call a dynamic function on OldClass. | 5617 // Call a dynamic function on OldClass. |
| 5648 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("OldClass")); | 5618 Dart_Handle cls = Dart_GetClass(lib, NewString("OldClass")); |
| 5649 EXPECT_VALID(cls); | 5619 EXPECT_VALID(cls); |
| 5650 Dart_Handle recv = Dart_New(cls, Dart_Null(), 0, NULL); | 5620 Dart_Handle recv = Dart_New(cls, Dart_Null(), 0, NULL); |
| 5651 Dart_Handle result = Dart_Invoke(recv, Dart_NewString("foo"), 0, NULL); | 5621 Dart_Handle result = Dart_Invoke(recv, NewString("foo"), 0, NULL); |
| 5652 EXPECT_VALID(result); | 5622 EXPECT_VALID(result); |
| 5653 EXPECT(Dart_IsString(result)); | 5623 EXPECT(Dart_IsString(result)); |
| 5654 const char* result_cstr = ""; | 5624 const char* result_cstr = ""; |
| 5655 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 5625 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
| 5656 EXPECT_STREQ("foo", result_cstr); | 5626 EXPECT_STREQ("foo", result_cstr); |
| 5657 | 5627 |
| 5658 // Load a source file late. | 5628 // Load a source file late. |
| 5659 url = Dart_NewString("source_url"); | 5629 url = NewString("source_url"); |
| 5660 source = Dart_NewString(kSourceChars); | 5630 source = NewString(kSourceChars); |
| 5661 EXPECT_VALID(Dart_LoadSource(lib, url, source)); | 5631 EXPECT_VALID(Dart_LoadSource(lib, url, source)); |
| 5662 | 5632 |
| 5663 // Call a dynamic function on NewClass in the updated library. | 5633 // Call a dynamic function on NewClass in the updated library. |
| 5664 cls = Dart_GetClass(lib, Dart_NewString("NewClass")); | 5634 cls = Dart_GetClass(lib, NewString("NewClass")); |
| 5665 EXPECT_VALID(cls); | 5635 EXPECT_VALID(cls); |
| 5666 recv = Dart_New(cls, Dart_Null(), 0, NULL); | 5636 recv = Dart_New(cls, Dart_Null(), 0, NULL); |
| 5667 result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL); | 5637 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); |
| 5668 EXPECT_VALID(result); | 5638 EXPECT_VALID(result); |
| 5669 EXPECT(Dart_IsString(result)); | 5639 EXPECT(Dart_IsString(result)); |
| 5670 result_cstr = ""; | 5640 result_cstr = ""; |
| 5671 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 5641 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
| 5672 EXPECT_STREQ("bar", result_cstr); | 5642 EXPECT_STREQ("bar", result_cstr); |
| 5673 } | 5643 } |
| 5674 | 5644 |
| 5675 | 5645 |
| 5676 TEST_CASE(LoadPatch) { | 5646 TEST_CASE(LoadPatch) { |
| 5677 const char* kLibrary1Chars = | 5647 const char* kLibrary1Chars = |
| 5678 "#library('library1_name');"; | 5648 "#library('library1_name');"; |
| 5679 const char* kSourceChars = | 5649 const char* kSourceChars = |
| 5680 "external int foo();"; | 5650 "external int foo();"; |
| 5681 const char* kPatchChars = | 5651 const char* kPatchChars = |
| 5682 "patch int foo() => 42;"; | 5652 "patch int foo() => 42;"; |
| 5683 | 5653 |
| 5684 // Load up a library. | 5654 // Load up a library. |
| 5685 Dart_Handle url = Dart_NewString("library1_url"); | 5655 Dart_Handle url = NewString("library1_url"); |
| 5686 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5656 Dart_Handle source = NewString(kLibrary1Chars); |
| 5687 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5657 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5688 EXPECT_VALID(lib); | 5658 EXPECT_VALID(lib); |
| 5689 EXPECT(Dart_IsLibrary(lib)); | 5659 EXPECT(Dart_IsLibrary(lib)); |
| 5690 | 5660 |
| 5691 url = Dart_NewString("source_url"); | 5661 url = NewString("source_url"); |
| 5692 source = Dart_NewString(kSourceChars); | 5662 source = NewString(kSourceChars); |
| 5693 | 5663 |
| 5694 Dart_Handle result = Dart_LoadSource(lib, url, source); | 5664 Dart_Handle result = Dart_LoadSource(lib, url, source); |
| 5695 EXPECT_VALID(result); | 5665 EXPECT_VALID(result); |
| 5696 | 5666 |
| 5697 url = Dart_NewString("patch_url"); | 5667 url = NewString("patch_url"); |
| 5698 source = Dart_NewString(kPatchChars); | 5668 source = NewString(kPatchChars); |
| 5699 | 5669 |
| 5700 result = Dart_LoadPatch(lib, url, source); | 5670 result = Dart_LoadPatch(lib, url, source); |
| 5701 EXPECT_VALID(result); | 5671 EXPECT_VALID(result); |
| 5702 | 5672 |
| 5703 result = Dart_Invoke(lib, Dart_NewString("foo"), 0, NULL); | 5673 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 5704 EXPECT_VALID(result); | 5674 EXPECT_VALID(result); |
| 5705 EXPECT(Dart_IsInteger(result)); | 5675 EXPECT(Dart_IsInteger(result)); |
| 5706 int64_t value = 0; | 5676 int64_t value = 0; |
| 5707 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5677 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5708 EXPECT_EQ(42, value); | 5678 EXPECT_EQ(42, value); |
| 5709 } | 5679 } |
| 5710 | 5680 |
| 5711 | 5681 |
| 5712 static void PatchNativeFunction(Dart_NativeArguments args) { | 5682 static void PatchNativeFunction(Dart_NativeArguments args) { |
| 5713 Dart_EnterScope(); | 5683 Dart_EnterScope(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5782 "m5() => new B(3);\n" | 5752 "m5() => new B(3);\n" |
| 5783 "m6() {\n" | 5753 "m6() {\n" |
| 5784 " var b = new B.named(8);\n" | 5754 " var b = new B.named(8);\n" |
| 5785 " return b.val;\n" | 5755 " return b.val;\n" |
| 5786 "}\n" | 5756 "}\n" |
| 5787 ; // NOLINT | 5757 ; // NOLINT |
| 5788 | 5758 |
| 5789 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); | 5759 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); |
| 5790 EXPECT_VALID(result); | 5760 EXPECT_VALID(result); |
| 5791 | 5761 |
| 5792 Dart_Handle url = Dart_NewString("theLibrary"); | 5762 Dart_Handle url = NewString("theLibrary"); |
| 5793 Dart_Handle source = Dart_NewString(kLibraryChars); | 5763 Dart_Handle source = NewString(kLibraryChars); |
| 5794 result = Dart_LoadLibrary(url, source); | 5764 result = Dart_LoadLibrary(url, source); |
| 5795 EXPECT_VALID(result); | 5765 EXPECT_VALID(result); |
| 5796 | 5766 |
| 5797 const String& patch_url = String::Handle(String::New("theLibrary patch")); | 5767 const String& patch_url = String::Handle(String::New("theLibrary patch")); |
| 5798 const String& patch_source = String::Handle(String::New(kPatchChars)); | 5768 const String& patch_source = String::Handle(String::New(kPatchChars)); |
| 5799 const Script& patch_script = Script::Handle(Script::New( | 5769 const Script& patch_script = Script::Handle(Script::New( |
| 5800 patch_url, patch_source, RawScript::kPatchTag)); | 5770 patch_url, patch_source, RawScript::kPatchTag)); |
| 5801 | 5771 |
| 5802 const String& lib_url = String::Handle(String::New("theLibrary")); | 5772 const String& lib_url = String::Handle(String::New("theLibrary")); |
| 5803 const Library& lib = Library::Handle(Library::LookupLibrary(lib_url)); | 5773 const Library& lib = Library::Handle(Library::LookupLibrary(lib_url)); |
| 5804 const Error& err = Error::Handle(lib.Patch(patch_script)); | 5774 const Error& err = Error::Handle(lib.Patch(patch_script)); |
| 5805 if (!err.IsNull()) { | 5775 if (!err.IsNull()) { |
| 5806 OS::Print("Patching error: %s\n", err.ToErrorCString()); | 5776 OS::Print("Patching error: %s\n", err.ToErrorCString()); |
| 5807 EXPECT(false); | 5777 EXPECT(false); |
| 5808 } | 5778 } |
| 5809 result = Dart_SetNativeResolver(result, &PatchNativeResolver); | 5779 result = Dart_SetNativeResolver(result, &PatchNativeResolver); |
| 5810 EXPECT_VALID(result); | 5780 EXPECT_VALID(result); |
| 5811 | 5781 |
| 5812 Dart_Handle script_url = Dart_NewString("theScript"); | 5782 Dart_Handle script_url = NewString("theScript"); |
| 5813 source = Dart_NewString(kScriptChars); | 5783 source = NewString(kScriptChars); |
| 5814 Dart_Handle test_script = Dart_LoadScript(script_url, source); | 5784 Dart_Handle test_script = Dart_LoadScript(script_url, source); |
| 5815 EXPECT_VALID(test_script); | 5785 EXPECT_VALID(test_script); |
| 5816 | 5786 |
| 5817 // Make sure that we can compile all of the patched code. | 5787 // Make sure that we can compile all of the patched code. |
| 5818 result = Dart_CompileAll(); | 5788 result = Dart_CompileAll(); |
| 5819 EXPECT_VALID(result); | 5789 EXPECT_VALID(result); |
| 5820 | 5790 |
| 5821 result = Dart_Invoke(test_script, Dart_NewString("e1"), 0, NULL); | 5791 result = Dart_Invoke(test_script, NewString("e1"), 0, NULL); |
| 5822 EXPECT_ERROR(result, "No such method: 'unpatched'"); | 5792 EXPECT_ERROR(result, "No such method: 'unpatched'"); |
| 5823 | 5793 |
| 5824 int64_t value = 0; | 5794 int64_t value = 0; |
| 5825 result = Dart_Invoke(test_script, Dart_NewString("m1"), 0, NULL); | 5795 result = Dart_Invoke(test_script, NewString("m1"), 0, NULL); |
| 5826 EXPECT_VALID(result); | 5796 EXPECT_VALID(result); |
| 5827 EXPECT(Dart_IsInteger(result)); | 5797 EXPECT(Dart_IsInteger(result)); |
| 5828 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5798 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5829 EXPECT_EQ(4, value); | 5799 EXPECT_EQ(4, value); |
| 5830 | 5800 |
| 5831 value = 0; | 5801 value = 0; |
| 5832 result = Dart_Invoke(test_script, Dart_NewString("m2"), 0, NULL); | 5802 result = Dart_Invoke(test_script, NewString("m2"), 0, NULL); |
| 5833 EXPECT_VALID(result); | 5803 EXPECT_VALID(result); |
| 5834 EXPECT(Dart_IsInteger(result)); | 5804 EXPECT(Dart_IsInteger(result)); |
| 5835 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5805 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5836 EXPECT_EQ(40, value); | 5806 EXPECT_EQ(40, value); |
| 5837 | 5807 |
| 5838 value = 0; | 5808 value = 0; |
| 5839 result = Dart_Invoke(test_script, Dart_NewString("m3"), 0, NULL); | 5809 result = Dart_Invoke(test_script, NewString("m3"), 0, NULL); |
| 5840 EXPECT_VALID(result); | 5810 EXPECT_VALID(result); |
| 5841 EXPECT(Dart_IsInteger(result)); | 5811 EXPECT(Dart_IsInteger(result)); |
| 5842 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5812 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5843 EXPECT_EQ(21, value); | 5813 EXPECT_EQ(21, value); |
| 5844 | 5814 |
| 5845 value = 0; | 5815 value = 0; |
| 5846 result = Dart_Invoke(test_script, Dart_NewString("m4"), 0, NULL); | 5816 result = Dart_Invoke(test_script, NewString("m4"), 0, NULL); |
| 5847 EXPECT_VALID(result); | 5817 EXPECT_VALID(result); |
| 5848 EXPECT(Dart_IsInteger(result)); | 5818 EXPECT(Dart_IsInteger(result)); |
| 5849 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5819 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5850 EXPECT_EQ(-25, value); | 5820 EXPECT_EQ(-25, value); |
| 5851 | 5821 |
| 5852 result = Dart_Invoke(test_script, Dart_NewString("m5"), 0, NULL); | 5822 result = Dart_Invoke(test_script, NewString("m5"), 0, NULL); |
| 5853 EXPECT_VALID(result); | 5823 EXPECT_VALID(result); |
| 5854 EXPECT(Dart_IsNull(result)); | 5824 EXPECT(Dart_IsNull(result)); |
| 5855 | 5825 |
| 5856 value = 0; | 5826 value = 0; |
| 5857 result = Dart_Invoke(test_script, Dart_NewString("m6"), 0, NULL); | 5827 result = Dart_Invoke(test_script, NewString("m6"), 0, NULL); |
| 5858 EXPECT_VALID(result); | 5828 EXPECT_VALID(result); |
| 5859 EXPECT(Dart_IsInteger(result)); | 5829 EXPECT(Dart_IsInteger(result)); |
| 5860 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5830 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5861 EXPECT_EQ(8, value); | 5831 EXPECT_EQ(8, value); |
| 5862 } | 5832 } |
| 5863 | 5833 |
| 5864 | 5834 |
| 5865 static void MyNativeFunction1(Dart_NativeArguments args) { | 5835 static void MyNativeFunction1(Dart_NativeArguments args) { |
| 5866 Dart_EnterScope(); | 5836 Dart_EnterScope(); |
| 5867 Dart_SetReturnValue(args, Dart_NewInteger(654321)); | 5837 Dart_SetReturnValue(args, Dart_NewInteger(654321)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5892 const char* kScriptChars = | 5862 const char* kScriptChars = |
| 5893 "class Test {" | 5863 "class Test {" |
| 5894 " static foo() native \"SomeNativeFunction\";" | 5864 " static foo() native \"SomeNativeFunction\";" |
| 5895 " static bar() native \"SomeNativeFunction2\";" | 5865 " static bar() native \"SomeNativeFunction2\";" |
| 5896 " static baz() native \"SomeNativeFunction3\";" | 5866 " static baz() native \"SomeNativeFunction3\";" |
| 5897 "}"; | 5867 "}"; |
| 5898 Dart_Handle error = Dart_Error("incoming error"); | 5868 Dart_Handle error = Dart_Error("incoming error"); |
| 5899 Dart_Handle result; | 5869 Dart_Handle result; |
| 5900 | 5870 |
| 5901 // Load a test script. | 5871 // Load a test script. |
| 5902 Dart_Handle url = Dart_NewString(TestCase::url()); | 5872 Dart_Handle url = NewString(TestCase::url()); |
| 5903 Dart_Handle source = Dart_NewString(kScriptChars); | 5873 Dart_Handle source = NewString(kScriptChars); |
| 5904 result = Dart_SetLibraryTagHandler(library_handler); | 5874 result = Dart_SetLibraryTagHandler(library_handler); |
| 5905 EXPECT_VALID(result); | 5875 EXPECT_VALID(result); |
| 5906 Dart_Handle lib = Dart_LoadScript(url, source); | 5876 Dart_Handle lib = Dart_LoadScript(url, source); |
| 5907 EXPECT_VALID(lib); | 5877 EXPECT_VALID(lib); |
| 5908 EXPECT(Dart_IsLibrary(lib)); | 5878 EXPECT(Dart_IsLibrary(lib)); |
| 5909 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Test")); | 5879 Dart_Handle cls = Dart_GetClass(lib, NewString("Test")); |
| 5910 EXPECT_VALID(cls); | 5880 EXPECT_VALID(cls); |
| 5911 | 5881 |
| 5912 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); | 5882 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); |
| 5913 EXPECT(Dart_IsError(result)); | 5883 EXPECT(Dart_IsError(result)); |
| 5914 EXPECT_STREQ( | 5884 EXPECT_STREQ( |
| 5915 "Dart_SetNativeResolver expects argument 'library' to be non-null.", | 5885 "Dart_SetNativeResolver expects argument 'library' to be non-null.", |
| 5916 Dart_GetError(result)); | 5886 Dart_GetError(result)); |
| 5917 | 5887 |
| 5918 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1); | 5888 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1); |
| 5919 EXPECT(Dart_IsError(result)); | 5889 EXPECT(Dart_IsError(result)); |
| 5920 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of " | 5890 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of " |
| 5921 "type Library.", | 5891 "type Library.", |
| 5922 Dart_GetError(result)); | 5892 Dart_GetError(result)); |
| 5923 | 5893 |
| 5924 result = Dart_SetNativeResolver(error, &MyNativeResolver1); | 5894 result = Dart_SetNativeResolver(error, &MyNativeResolver1); |
| 5925 EXPECT(Dart_IsError(result)); | 5895 EXPECT(Dart_IsError(result)); |
| 5926 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5896 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5927 | 5897 |
| 5928 result = Dart_SetNativeResolver(lib, &MyNativeResolver1); | 5898 result = Dart_SetNativeResolver(lib, &MyNativeResolver1); |
| 5929 EXPECT_VALID(result); | 5899 EXPECT_VALID(result); |
| 5930 | 5900 |
| 5931 // Call a function and make sure native resolution works. | 5901 // Call a function and make sure native resolution works. |
| 5932 result = Dart_Invoke(cls, Dart_NewString("foo"), 0, NULL); | 5902 result = Dart_Invoke(cls, NewString("foo"), 0, NULL); |
| 5933 EXPECT_VALID(result); | 5903 EXPECT_VALID(result); |
| 5934 EXPECT(Dart_IsInteger(result)); | 5904 EXPECT(Dart_IsInteger(result)); |
| 5935 int64_t value = 0; | 5905 int64_t value = 0; |
| 5936 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5906 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5937 EXPECT_EQ(654321, value); | 5907 EXPECT_EQ(654321, value); |
| 5938 | 5908 |
| 5939 // A second call succeeds. | 5909 // A second call succeeds. |
| 5940 result = Dart_SetNativeResolver(lib, &MyNativeResolver2); | 5910 result = Dart_SetNativeResolver(lib, &MyNativeResolver2); |
| 5941 EXPECT_VALID(result); | 5911 EXPECT_VALID(result); |
| 5942 | 5912 |
| 5943 // 'foo' has already been resolved so gets the old value. | 5913 // 'foo' has already been resolved so gets the old value. |
| 5944 result = Dart_Invoke(cls, Dart_NewString("foo"), 0, NULL); | 5914 result = Dart_Invoke(cls, NewString("foo"), 0, NULL); |
| 5945 EXPECT_VALID(result); | 5915 EXPECT_VALID(result); |
| 5946 EXPECT(Dart_IsInteger(result)); | 5916 EXPECT(Dart_IsInteger(result)); |
| 5947 value = 0; | 5917 value = 0; |
| 5948 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5918 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5949 EXPECT_EQ(654321, value); | 5919 EXPECT_EQ(654321, value); |
| 5950 | 5920 |
| 5951 // 'bar' has not yet been resolved so gets the new value. | 5921 // 'bar' has not yet been resolved so gets the new value. |
| 5952 result = Dart_Invoke(cls, Dart_NewString("bar"), 0, NULL); | 5922 result = Dart_Invoke(cls, NewString("bar"), 0, NULL); |
| 5953 EXPECT_VALID(result); | 5923 EXPECT_VALID(result); |
| 5954 EXPECT(Dart_IsInteger(result)); | 5924 EXPECT(Dart_IsInteger(result)); |
| 5955 value = 0; | 5925 value = 0; |
| 5956 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5926 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5957 EXPECT_EQ(123456, value); | 5927 EXPECT_EQ(123456, value); |
| 5958 | 5928 |
| 5959 // A NULL resolver is okay, but resolution will fail. | 5929 // A NULL resolver is okay, but resolution will fail. |
| 5960 result = Dart_SetNativeResolver(lib, NULL); | 5930 result = Dart_SetNativeResolver(lib, NULL); |
| 5961 EXPECT_VALID(result); | 5931 EXPECT_VALID(result); |
| 5962 | 5932 |
| 5963 EXPECT_ERROR(Dart_Invoke(cls, Dart_NewString("baz"), 0, NULL), | 5933 EXPECT_ERROR(Dart_Invoke(cls, NewString("baz"), 0, NULL), |
| 5964 "native function 'SomeNativeFunction3' cannot be found"); | 5934 "native function 'SomeNativeFunction3' cannot be found"); |
| 5965 } | 5935 } |
| 5966 | 5936 |
| 5967 | 5937 |
| 5968 // Test that an imported name does not clash with the same name defined | 5938 // Test that an imported name does not clash with the same name defined |
| 5969 // in the importing library. | 5939 // in the importing library. |
| 5970 TEST_CASE(ImportLibrary2) { | 5940 TEST_CASE(ImportLibrary2) { |
| 5971 const char* kScriptChars = | 5941 const char* kScriptChars = |
| 5972 "#import('library1.dart');\n" | 5942 "#import('library1.dart');\n" |
| 5973 "var foo;\n" | 5943 "var foo;\n" |
| 5974 "main() { foo = 0; }\n"; | 5944 "main() { foo = 0; }\n"; |
| 5975 const char* kLibrary1Chars = | 5945 const char* kLibrary1Chars = |
| 5976 "#library('library1.dart');\n" | 5946 "#library('library1.dart');\n" |
| 5977 "#import('library2.dart');\n" | 5947 "#import('library2.dart');\n" |
| 5978 "var foo;\n"; | 5948 "var foo;\n"; |
| 5979 const char* kLibrary2Chars = | 5949 const char* kLibrary2Chars = |
| 5980 "#library('library2.dart');\n" | 5950 "#library('library2.dart');\n" |
| 5981 "#import('library1.dart');\n" | 5951 "#import('library1.dart');\n" |
| 5982 "var foo;\n"; | 5952 "var foo;\n"; |
| 5983 Dart_Handle result; | 5953 Dart_Handle result; |
| 5984 // Create a test library and Load up a test script in it. | 5954 // Create a test library and Load up a test script in it. |
| 5985 Dart_Handle url = Dart_NewString(TestCase::url()); | 5955 Dart_Handle url = NewString(TestCase::url()); |
| 5986 Dart_Handle source = Dart_NewString(kScriptChars); | 5956 Dart_Handle source = NewString(kScriptChars); |
| 5987 result = Dart_SetLibraryTagHandler(library_handler); | 5957 result = Dart_SetLibraryTagHandler(library_handler); |
| 5988 EXPECT_VALID(result); | 5958 EXPECT_VALID(result); |
| 5989 result = Dart_LoadScript(url, source); | 5959 result = Dart_LoadScript(url, source); |
| 5990 | 5960 |
| 5991 url = Dart_NewString("library1.dart"); | 5961 url = NewString("library1.dart"); |
| 5992 source = Dart_NewString(kLibrary1Chars); | 5962 source = NewString(kLibrary1Chars); |
| 5993 Dart_LoadLibrary(url, source); | 5963 Dart_LoadLibrary(url, source); |
| 5994 | 5964 |
| 5995 url = Dart_NewString("library2.dart"); | 5965 url = NewString("library2.dart"); |
| 5996 source = Dart_NewString(kLibrary2Chars); | 5966 source = NewString(kLibrary2Chars); |
| 5997 Dart_LoadLibrary(url, source); | 5967 Dart_LoadLibrary(url, source); |
| 5998 | 5968 |
| 5999 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 5969 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 6000 EXPECT_VALID(result); | 5970 EXPECT_VALID(result); |
| 6001 } | 5971 } |
| 6002 | 5972 |
| 6003 | 5973 |
| 6004 // Test that if the same name is imported from two libraries, it is | 5974 // Test that if the same name is imported from two libraries, it is |
| 6005 // an error if that name is referenced. | 5975 // an error if that name is referenced. |
| 6006 TEST_CASE(ImportLibrary3) { | 5976 TEST_CASE(ImportLibrary3) { |
| 6007 const char* kScriptChars = | 5977 const char* kScriptChars = |
| 6008 "#import('library2.dart');\n" | 5978 "#import('library2.dart');\n" |
| 6009 "#import('library1.dart');\n" | 5979 "#import('library1.dart');\n" |
| 6010 "var foo_top = 10; // foo has dup def. So should be an error.\n" | 5980 "var foo_top = 10; // foo has dup def. So should be an error.\n" |
| 6011 "main() { foo = 0; }\n"; | 5981 "main() { foo = 0; }\n"; |
| 6012 const char* kLibrary1Chars = | 5982 const char* kLibrary1Chars = |
| 6013 "#library('library1.dart');\n" | 5983 "#library('library1.dart');\n" |
| 6014 "var foo;"; | 5984 "var foo;"; |
| 6015 const char* kLibrary2Chars = | 5985 const char* kLibrary2Chars = |
| 6016 "#library('library2.dart');\n" | 5986 "#library('library2.dart');\n" |
| 6017 "var foo;"; | 5987 "var foo;"; |
| 6018 Dart_Handle result; | 5988 Dart_Handle result; |
| 6019 | 5989 |
| 6020 // Create a test library and Load up a test script in it. | 5990 // Create a test library and Load up a test script in it. |
| 6021 Dart_Handle url = Dart_NewString(TestCase::url()); | 5991 Dart_Handle url = NewString(TestCase::url()); |
| 6022 Dart_Handle source = Dart_NewString(kScriptChars); | 5992 Dart_Handle source = NewString(kScriptChars); |
| 6023 result = Dart_SetLibraryTagHandler(library_handler); | 5993 result = Dart_SetLibraryTagHandler(library_handler); |
| 6024 EXPECT_VALID(result); | 5994 EXPECT_VALID(result); |
| 6025 result = Dart_LoadScript(url, source); | 5995 result = Dart_LoadScript(url, source); |
| 6026 EXPECT_VALID(result); | 5996 EXPECT_VALID(result); |
| 6027 | 5997 |
| 6028 url = Dart_NewString("library2.dart"); | 5998 url = NewString("library2.dart"); |
| 6029 source = Dart_NewString(kLibrary2Chars); | 5999 source = NewString(kLibrary2Chars); |
| 6030 Dart_LoadLibrary(url, source); | 6000 Dart_LoadLibrary(url, source); |
| 6031 | 6001 |
| 6032 url = Dart_NewString("library1.dart"); | 6002 url = NewString("library1.dart"); |
| 6033 source = Dart_NewString(kLibrary1Chars); | 6003 source = NewString(kLibrary1Chars); |
| 6034 Dart_LoadLibrary(url, source); | 6004 Dart_LoadLibrary(url, source); |
| 6035 | 6005 |
| 6036 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 6006 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 6037 EXPECT(Dart_IsError(result)); | 6007 EXPECT(Dart_IsError(result)); |
| 6038 EXPECT_SUBSTRING("ambiguous reference: 'foo'", Dart_GetError(result)); | 6008 EXPECT_SUBSTRING("ambiguous reference: 'foo'", Dart_GetError(result)); |
| 6039 } | 6009 } |
| 6040 | 6010 |
| 6041 | 6011 |
| 6042 // Test that if the same name is imported from two libraries, it is | 6012 // Test that if the same name is imported from two libraries, it is |
| 6043 // not an error if that name is not used. | 6013 // not an error if that name is not used. |
| 6044 TEST_CASE(ImportLibrary4) { | 6014 TEST_CASE(ImportLibrary4) { |
| 6045 const char* kScriptChars = | 6015 const char* kScriptChars = |
| 6046 "#import('library2.dart');\n" | 6016 "#import('library2.dart');\n" |
| 6047 "#import('library1.dart');\n" | 6017 "#import('library1.dart');\n" |
| 6048 "main() { }\n"; | 6018 "main() { }\n"; |
| 6049 const char* kLibrary1Chars = | 6019 const char* kLibrary1Chars = |
| 6050 "#library('library1.dart');\n" | 6020 "#library('library1.dart');\n" |
| 6051 "var foo;"; | 6021 "var foo;"; |
| 6052 const char* kLibrary2Chars = | 6022 const char* kLibrary2Chars = |
| 6053 "#library('library2.dart');\n" | 6023 "#library('library2.dart');\n" |
| 6054 "var foo;"; | 6024 "var foo;"; |
| 6055 Dart_Handle result; | 6025 Dart_Handle result; |
| 6056 | 6026 |
| 6057 // Create a test library and Load up a test script in it. | 6027 // Create a test library and Load up a test script in it. |
| 6058 Dart_Handle url = Dart_NewString(TestCase::url()); | 6028 Dart_Handle url = NewString(TestCase::url()); |
| 6059 Dart_Handle source = Dart_NewString(kScriptChars); | 6029 Dart_Handle source = NewString(kScriptChars); |
| 6060 result = Dart_SetLibraryTagHandler(library_handler); | 6030 result = Dart_SetLibraryTagHandler(library_handler); |
| 6061 EXPECT_VALID(result); | 6031 EXPECT_VALID(result); |
| 6062 result = Dart_LoadScript(url, source); | 6032 result = Dart_LoadScript(url, source); |
| 6063 EXPECT_VALID(result); | 6033 EXPECT_VALID(result); |
| 6064 | 6034 |
| 6065 url = Dart_NewString("library2.dart"); | 6035 url = NewString("library2.dart"); |
| 6066 source = Dart_NewString(kLibrary2Chars); | 6036 source = NewString(kLibrary2Chars); |
| 6067 Dart_LoadLibrary(url, source); | 6037 Dart_LoadLibrary(url, source); |
| 6068 | 6038 |
| 6069 url = Dart_NewString("library1.dart"); | 6039 url = NewString("library1.dart"); |
| 6070 source = Dart_NewString(kLibrary1Chars); | 6040 source = NewString(kLibrary1Chars); |
| 6071 Dart_LoadLibrary(url, source); | 6041 Dart_LoadLibrary(url, source); |
| 6072 | 6042 |
| 6073 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 6043 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 6074 EXPECT_VALID(result); | 6044 EXPECT_VALID(result); |
| 6075 } | 6045 } |
| 6076 | 6046 |
| 6077 | 6047 |
| 6078 TEST_CASE(ImportLibrary5) { | 6048 TEST_CASE(ImportLibrary5) { |
| 6079 const char* kScriptChars = | 6049 const char* kScriptChars = |
| 6080 "#import('lib.dart');\n" | 6050 "#import('lib.dart');\n" |
| 6081 "interface Y {\n" | 6051 "interface Y {\n" |
| 6082 " void set handler(void callback(List<int> x));\n" | 6052 " void set handler(void callback(List<int> x));\n" |
| 6083 "}\n" | 6053 "}\n" |
| 6084 "void main() {}\n"; | 6054 "void main() {}\n"; |
| 6085 const char* kLibraryChars = | 6055 const char* kLibraryChars = |
| 6086 "#library('lib.dart');\n" | 6056 "#library('lib.dart');\n" |
| 6087 "interface X {\n" | 6057 "interface X {\n" |
| 6088 " void set handler(void callback(List<int> x));\n" | 6058 " void set handler(void callback(List<int> x));\n" |
| 6089 "}\n"; | 6059 "}\n"; |
| 6090 Dart_Handle result; | 6060 Dart_Handle result; |
| 6091 | 6061 |
| 6092 // Create a test library and Load up a test script in it. | 6062 // Create a test library and Load up a test script in it. |
| 6093 Dart_Handle url = Dart_NewString(TestCase::url()); | 6063 Dart_Handle url = NewString(TestCase::url()); |
| 6094 Dart_Handle source = Dart_NewString(kScriptChars); | 6064 Dart_Handle source = NewString(kScriptChars); |
| 6095 result = Dart_SetLibraryTagHandler(library_handler); | 6065 result = Dart_SetLibraryTagHandler(library_handler); |
| 6096 EXPECT_VALID(result); | 6066 EXPECT_VALID(result); |
| 6097 result = Dart_LoadScript(url, source); | 6067 result = Dart_LoadScript(url, source); |
| 6098 | 6068 |
| 6099 url = Dart_NewString("lib.dart"); | 6069 url = NewString("lib.dart"); |
| 6100 source = Dart_NewString(kLibraryChars); | 6070 source = NewString(kLibraryChars); |
| 6101 Dart_LoadLibrary(url, source); | 6071 Dart_LoadLibrary(url, source); |
| 6102 | 6072 |
| 6103 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 6073 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 6104 EXPECT_VALID(result); | 6074 EXPECT_VALID(result); |
| 6105 } | 6075 } |
| 6106 | 6076 |
| 6107 | 6077 |
| 6108 void NewNativePort_send123(Dart_Port dest_port_id, | 6078 void NewNativePort_send123(Dart_Port dest_port_id, |
| 6109 Dart_Port reply_port_id, | 6079 Dart_Port reply_port_id, |
| 6110 Dart_CObject *message) { | 6080 Dart_CObject *message) { |
| 6111 // Gets a null message. | 6081 // Gets a null message. |
| 6112 EXPECT_NOTNULL(message); | 6082 EXPECT_NOTNULL(message); |
| 6113 EXPECT_EQ(Dart_CObject::kNull, message->type); | 6083 EXPECT_EQ(Dart_CObject::kNull, message->type); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6163 | 6133 |
| 6164 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 6134 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
| 6165 EXPECT_VALID(send_port1); | 6135 EXPECT_VALID(send_port1); |
| 6166 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); | 6136 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); |
| 6167 EXPECT_VALID(send_port2); | 6137 EXPECT_VALID(send_port2); |
| 6168 | 6138 |
| 6169 // Test first port. | 6139 // Test first port. |
| 6170 Dart_Handle dart_args[1]; | 6140 Dart_Handle dart_args[1]; |
| 6171 dart_args[0] = send_port1; | 6141 dart_args[0] = send_port1; |
| 6172 Dart_Handle result = | 6142 Dart_Handle result = |
| 6173 Dart_Invoke(lib, Dart_NewString("callPort"), 1, dart_args); | 6143 Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
| 6174 EXPECT_VALID(result); | 6144 EXPECT_VALID(result); |
| 6175 result = Dart_RunLoop(); | 6145 result = Dart_RunLoop(); |
| 6176 EXPECT(Dart_IsError(result)); | 6146 EXPECT(Dart_IsError(result)); |
| 6177 EXPECT(Dart_ErrorHasException(result)); | 6147 EXPECT(Dart_ErrorHasException(result)); |
| 6178 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 6148 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
| 6179 | 6149 |
| 6180 // result second port. | 6150 // result second port. |
| 6181 dart_args[0] = send_port2; | 6151 dart_args[0] = send_port2; |
| 6182 result = Dart_Invoke(lib, Dart_NewString("callPort"), 1, dart_args); | 6152 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
| 6183 EXPECT_VALID(result); | 6153 EXPECT_VALID(result); |
| 6184 result = Dart_RunLoop(); | 6154 result = Dart_RunLoop(); |
| 6185 EXPECT(Dart_IsError(result)); | 6155 EXPECT(Dart_IsError(result)); |
| 6186 EXPECT(Dart_ErrorHasException(result)); | 6156 EXPECT(Dart_ErrorHasException(result)); |
| 6187 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 6157 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
| 6188 | 6158 |
| 6189 Dart_ExitScope(); | 6159 Dart_ExitScope(); |
| 6190 | 6160 |
| 6191 // Delete the native ports. | 6161 // Delete the native ports. |
| 6192 EXPECT(Dart_CloseNativePort(port_id1)); | 6162 EXPECT(Dart_CloseNativePort(port_id1)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 6219 " if (exc_parent) throw new Exception('MakeParentExit');\n" | 6189 " if (exc_parent) throw new Exception('MakeParentExit');\n" |
| 6220 " });\n" | 6190 " });\n" |
| 6221 "}\n"; | 6191 "}\n"; |
| 6222 | 6192 |
| 6223 if (Dart_CurrentIsolate() != NULL) { | 6193 if (Dart_CurrentIsolate() != NULL) { |
| 6224 Dart_ExitIsolate(); | 6194 Dart_ExitIsolate(); |
| 6225 } | 6195 } |
| 6226 Dart_Isolate isolate = TestCase::CreateTestIsolate(); | 6196 Dart_Isolate isolate = TestCase::CreateTestIsolate(); |
| 6227 ASSERT(isolate != NULL); | 6197 ASSERT(isolate != NULL); |
| 6228 Dart_EnterScope(); | 6198 Dart_EnterScope(); |
| 6229 Dart_Handle url = Dart_NewString(TestCase::url()); | 6199 Dart_Handle url = NewString(TestCase::url()); |
| 6230 Dart_Handle source = Dart_NewString(kScriptChars); | 6200 Dart_Handle source = NewString(kScriptChars); |
| 6231 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 6201 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
| 6232 EXPECT_VALID(result); | 6202 EXPECT_VALID(result); |
| 6233 Dart_Handle lib = Dart_LoadScript(url, source); | 6203 Dart_Handle lib = Dart_LoadScript(url, source); |
| 6234 EXPECT_VALID(lib); | 6204 EXPECT_VALID(lib); |
| 6235 Dart_ExitScope(); | 6205 Dart_ExitScope(); |
| 6236 return true; | 6206 return true; |
| 6237 } | 6207 } |
| 6238 | 6208 |
| 6239 | 6209 |
| 6240 // Common code for RunLoop_Success/RunLoop_Failure. | 6210 // Common code for RunLoop_Success/RunLoop_Failure. |
| 6241 static void RunLoopTest(bool throw_exception_child, | 6211 static void RunLoopTest(bool throw_exception_child, |
| 6242 bool throw_exception_parent) { | 6212 bool throw_exception_parent) { |
| 6243 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 6213 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
| 6244 Isolate::SetCreateCallback(RunLoopTestCallback); | 6214 Isolate::SetCreateCallback(RunLoopTestCallback); |
| 6245 RunLoopTestCallback(NULL, NULL, NULL, NULL); | 6215 RunLoopTestCallback(NULL, NULL, NULL, NULL); |
| 6246 | 6216 |
| 6247 Dart_EnterScope(); | 6217 Dart_EnterScope(); |
| 6248 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); | 6218 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
| 6249 EXPECT_VALID(lib); | 6219 EXPECT_VALID(lib); |
| 6250 | 6220 |
| 6251 Dart_Handle result; | 6221 Dart_Handle result; |
| 6252 Dart_Handle args[2]; | 6222 Dart_Handle args[2]; |
| 6253 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); | 6223 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); |
| 6254 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); | 6224 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); |
| 6255 result = Dart_Invoke(lib, Dart_NewString("main"), 2, args); | 6225 result = Dart_Invoke(lib, NewString("main"), 2, args); |
| 6256 EXPECT_VALID(result); | 6226 EXPECT_VALID(result); |
| 6257 result = Dart_RunLoop(); | 6227 result = Dart_RunLoop(); |
| 6258 if (throw_exception_parent) { | 6228 if (throw_exception_parent) { |
| 6259 EXPECT_ERROR(result, "Exception: MakeParentExit"); | 6229 EXPECT_ERROR(result, "Exception: MakeParentExit"); |
| 6260 } else { | 6230 } else { |
| 6261 EXPECT_VALID(result); | 6231 EXPECT_VALID(result); |
| 6262 } | 6232 } |
| 6263 | 6233 |
| 6264 Dart_ExitScope(); | 6234 Dart_ExitScope(); |
| 6265 Dart_ShutdownIsolate(); | 6235 Dart_ShutdownIsolate(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6322 "}\n"; | 6292 "}\n"; |
| 6323 | 6293 |
| 6324 // Tell the other thread that shared_isolate is created. | 6294 // Tell the other thread that shared_isolate is created. |
| 6325 Dart_Handle lib; | 6295 Dart_Handle lib; |
| 6326 { | 6296 { |
| 6327 sync->Enter(); | 6297 sync->Enter(); |
| 6328 char* error = NULL; | 6298 char* error = NULL; |
| 6329 shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); | 6299 shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); |
| 6330 EXPECT(shared_isolate != NULL); | 6300 EXPECT(shared_isolate != NULL); |
| 6331 Dart_EnterScope(); | 6301 Dart_EnterScope(); |
| 6332 Dart_Handle url = Dart_NewString(TestCase::url()); | 6302 Dart_Handle url = NewString(TestCase::url()); |
| 6333 Dart_Handle source = Dart_NewString(kScriptChars); | 6303 Dart_Handle source = NewString(kScriptChars); |
| 6334 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 6304 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
| 6335 EXPECT_VALID(result); | 6305 EXPECT_VALID(result); |
| 6336 lib = Dart_LoadScript(url, source); | 6306 lib = Dart_LoadScript(url, source); |
| 6337 EXPECT_VALID(lib); | 6307 EXPECT_VALID(lib); |
| 6338 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup); | 6308 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup); |
| 6339 DART_CHECK_VALID(result); | 6309 DART_CHECK_VALID(result); |
| 6340 | 6310 |
| 6341 sync->Notify(); | 6311 sync->Notify(); |
| 6342 sync->Exit(); | 6312 sync->Exit(); |
| 6343 } | 6313 } |
| 6344 | 6314 |
| 6345 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); | 6315 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 6346 EXPECT(Dart_IsError(result)); | 6316 EXPECT(Dart_IsError(result)); |
| 6347 EXPECT(Dart_ErrorHasException(result)); | 6317 EXPECT(Dart_ErrorHasException(result)); |
| 6348 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", | 6318 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", |
| 6349 Dart_GetError(result)); | 6319 Dart_GetError(result)); |
| 6350 | 6320 |
| 6351 Dart_ExitScope(); | 6321 Dart_ExitScope(); |
| 6352 Dart_ShutdownIsolate(); | 6322 Dart_ShutdownIsolate(); |
| 6353 | 6323 |
| 6354 // Tell the other thread that we are done (don't use MonitorLocker | 6324 // Tell the other thread that we are done (don't use MonitorLocker |
| 6355 // as there is no current isolate any more). | 6325 // as there is no current isolate any more). |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6367 static int interrupt_count = 0; | 6337 static int interrupt_count = 0; |
| 6368 static bool IsolateInterruptTestCallback() { | 6338 static bool IsolateInterruptTestCallback() { |
| 6369 OS::Print(" ========== Interrupt callback called #%d\n", interrupt_count + 1); | 6339 OS::Print(" ========== Interrupt callback called #%d\n", interrupt_count + 1); |
| 6370 { | 6340 { |
| 6371 MonitorLocker ml(sync); | 6341 MonitorLocker ml(sync); |
| 6372 interrupt_count++; | 6342 interrupt_count++; |
| 6373 ml.Notify(); | 6343 ml.Notify(); |
| 6374 } | 6344 } |
| 6375 if (interrupt_count == kInterruptCount) { | 6345 if (interrupt_count == kInterruptCount) { |
| 6376 Dart_EnterScope(); | 6346 Dart_EnterScope(); |
| 6377 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); | 6347 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
| 6378 EXPECT_VALID(lib); | 6348 EXPECT_VALID(lib); |
| 6379 Dart_Handle exc = Dart_NewString("foo"); | 6349 Dart_Handle exc = NewString("foo"); |
| 6380 EXPECT_VALID(exc); | 6350 EXPECT_VALID(exc); |
| 6381 Dart_Handle result = Dart_ThrowException(exc); | 6351 Dart_Handle result = Dart_ThrowException(exc); |
| 6382 EXPECT_VALID(result); | 6352 EXPECT_VALID(result); |
| 6383 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. | 6353 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. |
| 6384 return false; | 6354 return false; |
| 6385 } | 6355 } |
| 6386 ASSERT(interrupt_count < kInterruptCount); | 6356 ASSERT(interrupt_count < kInterruptCount); |
| 6387 return true; | 6357 return true; |
| 6388 } | 6358 } |
| 6389 | 6359 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6590 " Expect.equals(3, obj.bar42(1, 1));\n" | 6560 " Expect.equals(3, obj.bar42(1, 1));\n" |
| 6591 " Expect.equals(6, obj.foo4(2, 2, 2));\n" | 6561 " Expect.equals(6, obj.foo4(2, 2, 2));\n" |
| 6592 " Expect.equals(6, obj.bar43(2, 2, 2));\n" | 6562 " Expect.equals(6, obj.bar43(2, 2, 2));\n" |
| 6593 "\n" | 6563 "\n" |
| 6594 " return 0;\n" | 6564 " return 0;\n" |
| 6595 "}\n"; | 6565 "}\n"; |
| 6596 | 6566 |
| 6597 Dart_Handle result; | 6567 Dart_Handle result; |
| 6598 | 6568 |
| 6599 // Load a test script. | 6569 // Load a test script. |
| 6600 Dart_Handle url = Dart_NewString(TestCase::url()); | 6570 Dart_Handle url = NewString(TestCase::url()); |
| 6601 Dart_Handle source = Dart_NewString(kScriptChars); | 6571 Dart_Handle source = NewString(kScriptChars); |
| 6602 result = Dart_SetLibraryTagHandler(library_handler); | 6572 result = Dart_SetLibraryTagHandler(library_handler); |
| 6603 EXPECT_VALID(result); | 6573 EXPECT_VALID(result); |
| 6604 Dart_Handle lib = Dart_LoadScript(url, source); | 6574 Dart_Handle lib = Dart_LoadScript(url, source); |
| 6605 EXPECT_VALID(lib); | 6575 EXPECT_VALID(lib); |
| 6606 EXPECT(Dart_IsLibrary(lib)); | 6576 EXPECT(Dart_IsLibrary(lib)); |
| 6607 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver); | 6577 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver); |
| 6608 EXPECT_VALID(result); | 6578 EXPECT_VALID(result); |
| 6609 | 6579 |
| 6610 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 6580 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 6611 EXPECT_VALID(result); | 6581 EXPECT_VALID(result); |
| 6612 EXPECT(Dart_IsInteger(result)); | 6582 EXPECT(Dart_IsInteger(result)); |
| 6613 int64_t value = 0; | 6583 int64_t value = 0; |
| 6614 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6584 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6615 EXPECT_EQ(0, value); | 6585 EXPECT_EQ(0, value); |
| 6616 } | 6586 } |
| 6617 | 6587 |
| 6618 | 6588 |
| 6619 static void StaticNativeFoo1(Dart_NativeArguments args) { | 6589 static void StaticNativeFoo1(Dart_NativeArguments args) { |
| 6620 Dart_EnterScope(); | 6590 Dart_EnterScope(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6728 " Expect.equals(3, obj.bar42(1, 1));\n" | 6698 " Expect.equals(3, obj.bar42(1, 1));\n" |
| 6729 " Expect.equals(6, Test.foo4(2, 2, 2));\n" | 6699 " Expect.equals(6, Test.foo4(2, 2, 2));\n" |
| 6730 " Expect.equals(6, obj.bar43(2, 2, 2));\n" | 6700 " Expect.equals(6, obj.bar43(2, 2, 2));\n" |
| 6731 "\n" | 6701 "\n" |
| 6732 " return 0;\n" | 6702 " return 0;\n" |
| 6733 "}\n"; | 6703 "}\n"; |
| 6734 | 6704 |
| 6735 Dart_Handle result; | 6705 Dart_Handle result; |
| 6736 | 6706 |
| 6737 // Load a test script. | 6707 // Load a test script. |
| 6738 Dart_Handle url = Dart_NewString(TestCase::url()); | 6708 Dart_Handle url = NewString(TestCase::url()); |
| 6739 Dart_Handle source = Dart_NewString(kScriptChars); | 6709 Dart_Handle source = NewString(kScriptChars); |
| 6740 result = Dart_SetLibraryTagHandler(library_handler); | 6710 result = Dart_SetLibraryTagHandler(library_handler); |
| 6741 EXPECT_VALID(result); | 6711 EXPECT_VALID(result); |
| 6742 Dart_Handle lib = Dart_LoadScript(url, source); | 6712 Dart_Handle lib = Dart_LoadScript(url, source); |
| 6743 EXPECT_VALID(lib); | 6713 EXPECT_VALID(lib); |
| 6744 EXPECT(Dart_IsLibrary(lib)); | 6714 EXPECT(Dart_IsLibrary(lib)); |
| 6745 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver); | 6715 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver); |
| 6746 EXPECT_VALID(result); | 6716 EXPECT_VALID(result); |
| 6747 | 6717 |
| 6748 result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); | 6718 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 6749 EXPECT_VALID(result); | 6719 EXPECT_VALID(result); |
| 6750 EXPECT(Dart_IsInteger(result)); | 6720 EXPECT(Dart_IsInteger(result)); |
| 6751 int64_t value = 0; | 6721 int64_t value = 0; |
| 6752 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6722 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6753 EXPECT_EQ(0, value); | 6723 EXPECT_EQ(0, value); |
| 6754 } | 6724 } |
| 6755 | 6725 |
| 6756 | 6726 |
| 6757 TEST_CASE(RangeLimits) { | 6727 TEST_CASE(RangeLimits) { |
| 6758 uint8_t chars8[1] = {'a'}; | 6728 uint8_t chars8[1] = {'a'}; |
| 6759 uint16_t chars16[1] = {'a'}; | 6729 uint16_t chars16[1] = {'a'}; |
| 6760 uint32_t chars32[1] = {'a'}; | 6730 uint32_t chars32[1] = {'a'}; |
| 6761 | 6731 |
| 6762 EXPECT_ERROR(Dart_NewList(-1), | 6732 EXPECT_ERROR(Dart_NewList(-1), |
| 6763 "expects argument 'length' to be in the range"); | 6733 "expects argument 'length' to be in the range"); |
| 6764 EXPECT_ERROR(Dart_NewList(Array::kMaxElements+1), | 6734 EXPECT_ERROR(Dart_NewList(Array::kMaxElements+1), |
| 6765 "expects argument 'length' to be in the range"); | 6735 "expects argument 'length' to be in the range"); |
| 6766 EXPECT_ERROR(Dart_NewString8(chars8, -1), | 6736 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, -1), |
| 6767 "expects argument 'length' to be in the range"); | 6737 "expects argument 'length' to be in the range"); |
| 6768 EXPECT_ERROR(Dart_NewString8(chars8, OneByteString::kMaxElements+1), | 6738 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, OneByteString::kMaxElements+1), |
| 6769 "expects argument 'length' to be in the range"); | 6739 "expects argument 'length' to be in the range"); |
| 6770 EXPECT_ERROR(Dart_NewString16(chars16, -1), | 6740 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, -1), |
| 6771 "expects argument 'length' to be in the range"); | 6741 "expects argument 'length' to be in the range"); |
| 6772 EXPECT_ERROR(Dart_NewString16(chars16, TwoByteString::kMaxElements+1), | 6742 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, TwoByteString::kMaxElements+1), |
| 6773 "expects argument 'length' to be in the range"); | 6743 "expects argument 'length' to be in the range"); |
| 6774 EXPECT_ERROR(Dart_NewString32(chars32, -1), | 6744 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, -1), |
| 6775 "expects argument 'length' to be in the range"); | 6745 "expects argument 'length' to be in the range"); |
| 6776 EXPECT_ERROR(Dart_NewString32(chars32, FourByteString::kMaxElements+1), | 6746 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, TwoByteString::kMaxElements+1), |
| 6777 "expects argument 'length' to be in the range"); | 6747 "expects argument 'length' to be in the range"); |
| 6778 } | 6748 } |
| 6779 | 6749 |
| 6780 | 6750 |
| 6781 TEST_CASE(NewString_Null) { | 6751 TEST_CASE(NewString_Null) { |
| 6782 Dart_Handle str = Dart_NewString8(NULL, 0); | 6752 Dart_Handle str = Dart_NewStringFromUTF8(NULL, 0); |
| 6783 EXPECT_VALID(str); | 6753 EXPECT_VALID(str); |
| 6784 EXPECT(Dart_IsString(str)); | 6754 EXPECT(Dart_IsString(str)); |
| 6785 intptr_t len = -1; | 6755 intptr_t len = -1; |
| 6786 EXPECT_VALID(Dart_StringLength(str, &len)); | 6756 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6787 EXPECT_EQ(0, len); | 6757 EXPECT_EQ(0, len); |
| 6788 | 6758 |
| 6789 str = Dart_NewString16(NULL, 0); | 6759 str = Dart_NewStringFromUTF16(NULL, 0); |
| 6790 EXPECT_VALID(str); | 6760 EXPECT_VALID(str); |
| 6791 EXPECT(Dart_IsString(str)); | 6761 EXPECT(Dart_IsString(str)); |
| 6792 len = -1; | 6762 len = -1; |
| 6793 EXPECT_VALID(Dart_StringLength(str, &len)); | 6763 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6794 EXPECT_EQ(0, len); | 6764 EXPECT_EQ(0, len); |
| 6795 | 6765 |
| 6796 str = Dart_NewString32(NULL, 0); | 6766 str = Dart_NewStringFromUTF32(NULL, 0); |
| 6797 EXPECT_VALID(str); | 6767 EXPECT_VALID(str); |
| 6798 EXPECT(Dart_IsString(str)); | 6768 EXPECT(Dart_IsString(str)); |
| 6799 len = -1; | 6769 len = -1; |
| 6800 EXPECT_VALID(Dart_StringLength(str, &len)); | 6770 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6801 EXPECT_EQ(0, len); | 6771 EXPECT_EQ(0, len); |
| 6802 } | 6772 } |
| 6803 | 6773 |
| 6804 | 6774 |
| 6805 // Try to allocate a peer with a handles to objects of prohibited | 6775 // Try to allocate a peer with a handles to objects of prohibited |
| 6806 // subtypes. | 6776 // subtypes. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 6832 EXPECT(out == &out); | 6802 EXPECT(out == &out); |
| 6833 EXPECT(Dart_IsError(Dart_SetPeer(dbl, &out))); | 6803 EXPECT(Dart_IsError(Dart_SetPeer(dbl, &out))); |
| 6834 } | 6804 } |
| 6835 | 6805 |
| 6836 | 6806 |
| 6837 // Allocates an object in new space and assigns it a peer. Removes | 6807 // Allocates an object in new space and assigns it a peer. Removes |
| 6838 // the peer and checks that the count of peer objects is decremented | 6808 // the peer and checks that the count of peer objects is decremented |
| 6839 // by one. | 6809 // by one. |
| 6840 TEST_CASE(OneNewSpacePeer) { | 6810 TEST_CASE(OneNewSpacePeer) { |
| 6841 Isolate* isolate = Isolate::Current(); | 6811 Isolate* isolate = Isolate::Current(); |
| 6842 Dart_Handle str = Dart_NewString("a string"); | 6812 Dart_Handle str = NewString("a string"); |
| 6843 EXPECT_VALID(str); | 6813 EXPECT_VALID(str); |
| 6844 EXPECT(Dart_IsString(str)); | 6814 EXPECT(Dart_IsString(str)); |
| 6845 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6815 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6846 void* out = &out; | 6816 void* out = &out; |
| 6847 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6817 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 6848 EXPECT(out == NULL); | 6818 EXPECT(out == NULL); |
| 6849 int peer = 1234; | 6819 int peer = 1234; |
| 6850 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6820 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 6851 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6821 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6852 out = &out; | 6822 out = &out; |
| 6853 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6823 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 6854 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6824 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 6855 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 6825 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
| 6856 out = &out; | 6826 out = &out; |
| 6857 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6827 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 6858 EXPECT(out == NULL); | 6828 EXPECT(out == NULL); |
| 6859 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6829 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6860 } | 6830 } |
| 6861 | 6831 |
| 6862 | 6832 |
| 6863 // Allocates an object in new space and assigns it a peer. Allows the | 6833 // Allocates an object in new space and assigns it a peer. Allows the |
| 6864 // peer referent to be garbage collected and checks that the count of | 6834 // peer referent to be garbage collected and checks that the count of |
| 6865 // peer objects is decremented by one. | 6835 // peer objects is decremented by one. |
| 6866 TEST_CASE(CollectOneNewSpacePeer) { | 6836 TEST_CASE(CollectOneNewSpacePeer) { |
| 6867 Isolate* isolate = Isolate::Current(); | 6837 Isolate* isolate = Isolate::Current(); |
| 6868 Dart_EnterScope(); | 6838 Dart_EnterScope(); |
| 6869 { | 6839 { |
| 6870 DARTSCOPE_NOCHECKS(isolate); | 6840 DARTSCOPE_NOCHECKS(isolate); |
| 6871 Dart_Handle str = Dart_NewString("a string"); | 6841 Dart_Handle str = NewString("a string"); |
| 6872 EXPECT_VALID(str); | 6842 EXPECT_VALID(str); |
| 6873 EXPECT(Dart_IsString(str)); | 6843 EXPECT(Dart_IsString(str)); |
| 6874 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6844 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6875 void* out = &out; | 6845 void* out = &out; |
| 6876 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6846 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 6877 EXPECT(out == NULL); | 6847 EXPECT(out == NULL); |
| 6878 int peer = 1234; | 6848 int peer = 1234; |
| 6879 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6849 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 6880 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6850 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6881 out = &out; | 6851 out = &out; |
| 6882 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6852 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 6883 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6853 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 6884 isolate->heap()->CollectGarbage(Heap::kNew); | 6854 isolate->heap()->CollectGarbage(Heap::kNew); |
| 6885 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6855 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6886 out = &out; | 6856 out = &out; |
| 6887 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6857 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 6888 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6858 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 6889 } | 6859 } |
| 6890 Dart_ExitScope(); | 6860 Dart_ExitScope(); |
| 6891 isolate->heap()->CollectGarbage(Heap::kNew); | 6861 isolate->heap()->CollectGarbage(Heap::kNew); |
| 6892 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6862 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6893 } | 6863 } |
| 6894 | 6864 |
| 6895 | 6865 |
| 6896 // Allocates two objects in new space and assigns them peers. Removes | 6866 // Allocates two objects in new space and assigns them peers. Removes |
| 6897 // the peers and checks that the count of peer objects is decremented | 6867 // the peers and checks that the count of peer objects is decremented |
| 6898 // by two. | 6868 // by two. |
| 6899 TEST_CASE(TwoNewSpacePeers) { | 6869 TEST_CASE(TwoNewSpacePeers) { |
| 6900 Isolate* isolate = Isolate::Current(); | 6870 Isolate* isolate = Isolate::Current(); |
| 6901 Dart_Handle s1 = Dart_NewString("s1"); | 6871 Dart_Handle s1 = NewString("s1"); |
| 6902 EXPECT_VALID(s1); | 6872 EXPECT_VALID(s1); |
| 6903 EXPECT(Dart_IsString(s1)); | 6873 EXPECT(Dart_IsString(s1)); |
| 6904 void* o1 = &o1; | 6874 void* o1 = &o1; |
| 6905 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 6875 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
| 6906 EXPECT(o1 == NULL); | 6876 EXPECT(o1 == NULL); |
| 6907 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6877 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6908 int p1 = 1234; | 6878 int p1 = 1234; |
| 6909 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 6879 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
| 6910 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6880 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6911 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 6881 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
| 6912 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 6882 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
| 6913 Dart_Handle s2 = Dart_NewString("a string"); | 6883 Dart_Handle s2 = NewString("a string"); |
| 6914 EXPECT_VALID(s2); | 6884 EXPECT_VALID(s2); |
| 6915 EXPECT(Dart_IsString(s2)); | 6885 EXPECT(Dart_IsString(s2)); |
| 6916 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6886 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6917 void* o2 = &o2; | 6887 void* o2 = &o2; |
| 6918 EXPECT(Dart_GetPeer(s2, &o2)); | 6888 EXPECT(Dart_GetPeer(s2, &o2)); |
| 6919 EXPECT(o2 == NULL); | 6889 EXPECT(o2 == NULL); |
| 6920 int p2 = 5678; | 6890 int p2 = 5678; |
| 6921 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 6891 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
| 6922 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 6892 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
| 6923 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 6893 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6934 | 6904 |
| 6935 | 6905 |
| 6936 // Allocates two objects in new space and assigns them a peer. Allow | 6906 // Allocates two objects in new space and assigns them a peer. Allow |
| 6937 // the peer referents to be garbage collected and check that the count | 6907 // the peer referents to be garbage collected and check that the count |
| 6938 // of peer objects is decremented by two. | 6908 // of peer objects is decremented by two. |
| 6939 TEST_CASE(CollectTwoNewSpacePeers) { | 6909 TEST_CASE(CollectTwoNewSpacePeers) { |
| 6940 Isolate* isolate = Isolate::Current(); | 6910 Isolate* isolate = Isolate::Current(); |
| 6941 Dart_EnterScope(); | 6911 Dart_EnterScope(); |
| 6942 { | 6912 { |
| 6943 DARTSCOPE_NOCHECKS(isolate); | 6913 DARTSCOPE_NOCHECKS(isolate); |
| 6944 Dart_Handle s1 = Dart_NewString("s1"); | 6914 Dart_Handle s1 = NewString("s1"); |
| 6945 EXPECT_VALID(s1); | 6915 EXPECT_VALID(s1); |
| 6946 EXPECT(Dart_IsString(s1)); | 6916 EXPECT(Dart_IsString(s1)); |
| 6947 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6917 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6948 void* o1 = &o1; | 6918 void* o1 = &o1; |
| 6949 EXPECT(Dart_GetPeer(s1, &o1)); | 6919 EXPECT(Dart_GetPeer(s1, &o1)); |
| 6950 EXPECT(o1 == NULL); | 6920 EXPECT(o1 == NULL); |
| 6951 int p1 = 1234; | 6921 int p1 = 1234; |
| 6952 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 6922 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
| 6953 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6923 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6954 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 6924 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
| 6955 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 6925 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
| 6956 Dart_Handle s2 = Dart_NewString("s2"); | 6926 Dart_Handle s2 = NewString("s2"); |
| 6957 EXPECT_VALID(s2); | 6927 EXPECT_VALID(s2); |
| 6958 EXPECT(Dart_IsString(s2)); | 6928 EXPECT(Dart_IsString(s2)); |
| 6959 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6929 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 6960 void* o2 = &o2; | 6930 void* o2 = &o2; |
| 6961 EXPECT(Dart_GetPeer(s2, &o2)); | 6931 EXPECT(Dart_GetPeer(s2, &o2)); |
| 6962 EXPECT(o2 == NULL); | 6932 EXPECT(o2 == NULL); |
| 6963 int p2 = 5678; | 6933 int p2 = 5678; |
| 6964 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 6934 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
| 6965 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 6935 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
| 6966 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 6936 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
| 6967 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 6937 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
| 6968 } | 6938 } |
| 6969 Dart_ExitScope(); | 6939 Dart_ExitScope(); |
| 6970 isolate->heap()->CollectGarbage(Heap::kNew); | 6940 isolate->heap()->CollectGarbage(Heap::kNew); |
| 6971 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6941 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6972 } | 6942 } |
| 6973 | 6943 |
| 6974 | 6944 |
| 6975 // Allocates several objects in new space. Performs successive | 6945 // Allocates several objects in new space. Performs successive |
| 6976 // garbage collections and checks that the peer count is stable. | 6946 // garbage collections and checks that the peer count is stable. |
| 6977 TEST_CASE(CopyNewSpacePeers) { | 6947 TEST_CASE(CopyNewSpacePeers) { |
| 6978 const int kPeerCount = 10; | 6948 const int kPeerCount = 10; |
| 6979 Isolate* isolate = Isolate::Current(); | 6949 Isolate* isolate = Isolate::Current(); |
| 6980 Dart_Handle s[kPeerCount]; | 6950 Dart_Handle s[kPeerCount]; |
| 6981 for (int i = 0; i < kPeerCount; ++i) { | 6951 for (int i = 0; i < kPeerCount; ++i) { |
| 6982 s[i] = Dart_NewString("a string"); | 6952 s[i] = NewString("a string"); |
| 6983 EXPECT_VALID(s[i]); | 6953 EXPECT_VALID(s[i]); |
| 6984 EXPECT(Dart_IsString(s[i])); | 6954 EXPECT(Dart_IsString(s[i])); |
| 6985 void* o = &o; | 6955 void* o = &o; |
| 6986 EXPECT_VALID(Dart_GetPeer(s[i], &o)); | 6956 EXPECT_VALID(Dart_GetPeer(s[i], &o)); |
| 6987 EXPECT(o == NULL); | 6957 EXPECT(o == NULL); |
| 6988 } | 6958 } |
| 6989 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6959 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 6990 int p[kPeerCount]; | 6960 int p[kPeerCount]; |
| 6991 for (int i = 0; i < kPeerCount; ++i) { | 6961 for (int i = 0; i < kPeerCount; ++i) { |
| 6992 EXPECT_VALID(Dart_SetPeer(s[i], &p[i])); | 6962 EXPECT_VALID(Dart_SetPeer(s[i], &p[i])); |
| 6993 EXPECT_EQ(i + 1, isolate->heap()->PeerCount()); | 6963 EXPECT_EQ(i + 1, isolate->heap()->PeerCount()); |
| 6994 void* o = &o; | 6964 void* o = &o; |
| 6995 EXPECT_VALID(Dart_GetPeer(s[i], &o)); | 6965 EXPECT_VALID(Dart_GetPeer(s[i], &o)); |
| 6996 EXPECT(o == reinterpret_cast<void*>(&p[i])); | 6966 EXPECT(o == reinterpret_cast<void*>(&p[i])); |
| 6997 } | 6967 } |
| 6998 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 6968 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 6999 isolate->heap()->CollectGarbage(Heap::kNew); | 6969 isolate->heap()->CollectGarbage(Heap::kNew); |
| 7000 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 6970 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 7001 isolate->heap()->CollectGarbage(Heap::kNew); | 6971 isolate->heap()->CollectGarbage(Heap::kNew); |
| 7002 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 6972 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 7003 } | 6973 } |
| 7004 | 6974 |
| 7005 | 6975 |
| 7006 // Allocates an object in new space and assigns it a peer. Promotes | 6976 // Allocates an object in new space and assigns it a peer. Promotes |
| 7007 // the peer to old space. Removes the peer and check that the count | 6977 // the peer to old space. Removes the peer and check that the count |
| 7008 // of peer objects is decremented by one. | 6978 // of peer objects is decremented by one. |
| 7009 TEST_CASE(OnePromotedPeer) { | 6979 TEST_CASE(OnePromotedPeer) { |
| 7010 Isolate* isolate = Isolate::Current(); | 6980 Isolate* isolate = Isolate::Current(); |
| 7011 Dart_Handle str = Dart_NewString("a string"); | 6981 Dart_Handle str = NewString("a string"); |
| 7012 EXPECT_VALID(str); | 6982 EXPECT_VALID(str); |
| 7013 EXPECT(Dart_IsString(str)); | 6983 EXPECT(Dart_IsString(str)); |
| 7014 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6984 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 7015 void* out = &out; | 6985 void* out = &out; |
| 7016 EXPECT(Dart_GetPeer(str, &out)); | 6986 EXPECT(Dart_GetPeer(str, &out)); |
| 7017 EXPECT(out == NULL); | 6987 EXPECT(out == NULL); |
| 7018 int peer = 1234; | 6988 int peer = 1234; |
| 7019 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6989 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 7020 out = &out; | 6990 out = &out; |
| 7021 EXPECT(Dart_GetPeer(str, &out)); | 6991 EXPECT(Dart_GetPeer(str, &out)); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7182 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 7152 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
| 7183 } | 7153 } |
| 7184 Dart_ExitScope(); | 7154 Dart_ExitScope(); |
| 7185 isolate->heap()->CollectGarbage(Heap::kOld); | 7155 isolate->heap()->CollectGarbage(Heap::kOld); |
| 7186 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7156 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 7187 } | 7157 } |
| 7188 | 7158 |
| 7189 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7159 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 7190 | 7160 |
| 7191 } // namespace dart | 7161 } // namespace dart |
| OLD | NEW |