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