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

Side by Side Diff: vm/dart_api_impl_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698