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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 8673002: - Refactor the isolate callback mechanism to also include creation of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
11 #include "vm/utils.h" 11 #include "vm/utils.h"
12 #include "vm/verifier.h" 12 #include "vm/verifier.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 16
17 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 17 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
18 18
19 UNIT_TEST_CASE(ErrorHandles) { 19 UNIT_TEST_CASE(ErrorHandles) {
20 const char* kScriptChars = 20 const char* kScriptChars =
21 "class TestClass {\n" 21 "class TestClass {\n"
22 " static void testMain() {\n" 22 " static void testMain() {\n"
23 " throw new Exception(\"bad news\");\n" 23 " throw new Exception(\"bad news\");\n"
24 " }\n" 24 " }\n"
25 "}\n"; 25 "}\n";
26 26
27 Dart_CreateIsolate(NULL, NULL); 27 Dart_CreateIsolate(NULL);
28 Dart_EnterScope(); 28 Dart_EnterScope();
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::Error("myerror"); 32 Dart_Handle error = Api::Error("myerror");
33 Dart_Handle exception = Dart_InvokeStatic(lib, 33 Dart_Handle exception = Dart_InvokeStatic(lib,
34 Dart_NewString("TestClass"), 34 Dart_NewString("TestClass"),
35 Dart_NewString("testMain"), 35 Dart_NewString("testMain"),
36 0, 36 0,
37 NULL); 37 NULL);
(...skipping 23 matching lines...) Expand all
61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); 61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception));
62 62
63 Dart_ExitScope(); 63 Dart_ExitScope();
64 Dart_ShutdownIsolate(); 64 Dart_ShutdownIsolate();
65 } 65 }
66 66
67 #endif 67 #endif
68 68
69 69
70 UNIT_TEST_CASE(Dart_Error) { 70 UNIT_TEST_CASE(Dart_Error) {
71 Dart_CreateIsolate(NULL, NULL); 71 Dart_CreateIsolate(NULL);
72 Dart_EnterScope(); 72 Dart_EnterScope();
73 73
74 Dart_Handle error = Dart_Error("An %s", "error"); 74 Dart_Handle error = Dart_Error("An %s", "error");
75 EXPECT(Dart_IsError(error)); 75 EXPECT(Dart_IsError(error));
76 EXPECT_STREQ("An error", Dart_GetError(error)); 76 EXPECT_STREQ("An error", Dart_GetError(error));
77 77
78 Dart_ExitScope(); 78 Dart_ExitScope();
79 Dart_ShutdownIsolate(); 79 Dart_ShutdownIsolate();
80 } 80 }
81 81
82 82
83 UNIT_TEST_CASE(Null) { 83 UNIT_TEST_CASE(Null) {
84 Dart_CreateIsolate(NULL, NULL); 84 Dart_CreateIsolate(NULL);
85 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 85 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
86 86
87 Dart_Handle null = Dart_Null(); 87 Dart_Handle null = Dart_Null();
88 EXPECT_VALID(null); 88 EXPECT_VALID(null);
89 EXPECT(Dart_IsNull(null)); 89 EXPECT(Dart_IsNull(null));
90 90
91 Dart_Handle str = Dart_NewString("test"); 91 Dart_Handle str = Dart_NewString("test");
92 EXPECT_VALID(str); 92 EXPECT_VALID(str);
93 EXPECT(!Dart_IsNull(str)); 93 EXPECT(!Dart_IsNull(str));
94 94
95 Dart_ExitScope(); // Exit the Dart API scope. 95 Dart_ExitScope(); // Exit the Dart API scope.
96 Dart_ShutdownIsolate(); 96 Dart_ShutdownIsolate();
97 } 97 }
98 98
99 99
100 UNIT_TEST_CASE(IsSame) { 100 UNIT_TEST_CASE(IsSame) {
101 Dart_CreateIsolate(NULL, NULL); 101 Dart_CreateIsolate(NULL);
102 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 102 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
103 103
104 bool same = false; 104 bool same = false;
105 Dart_Handle five = Dart_NewString("5"); 105 Dart_Handle five = Dart_NewString("5");
106 Dart_Handle five_again = Dart_NewString("5"); 106 Dart_Handle five_again = Dart_NewString("5");
107 Dart_Handle seven = Dart_NewString("7"); 107 Dart_Handle seven = Dart_NewString("7");
108 108
109 // Same objects. 109 // Same objects.
110 EXPECT_VALID(Dart_IsSame(five, five, &same)); 110 EXPECT_VALID(Dart_IsSame(five, five, &same));
111 EXPECT(same); 111 EXPECT(same);
(...skipping 22 matching lines...) Expand all
134 } 134 }
135 135
136 Dart_ExitScope(); // Exit the Dart API scope. 136 Dart_ExitScope(); // Exit the Dart API scope.
137 Dart_ShutdownIsolate(); 137 Dart_ShutdownIsolate();
138 } 138 }
139 139
140 140
141 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 141 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
142 142
143 UNIT_TEST_CASE(ObjectEquals) { 143 UNIT_TEST_CASE(ObjectEquals) {
144 Dart_CreateIsolate(NULL, NULL); 144 Dart_CreateIsolate(NULL);
145 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 145 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
146 146
147 bool equal = false; 147 bool equal = false;
148 Dart_Handle five = Dart_NewString("5"); 148 Dart_Handle five = Dart_NewString("5");
149 Dart_Handle five_again = Dart_NewString("5"); 149 Dart_Handle five_again = Dart_NewString("5");
150 Dart_Handle seven = Dart_NewString("7"); 150 Dart_Handle seven = Dart_NewString("7");
151 151
152 // Same objects. 152 // Same objects.
153 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); 153 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal));
154 EXPECT(equal); 154 EXPECT(equal);
155 155
156 // Equal objects. 156 // Equal objects.
157 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); 157 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal));
158 EXPECT(equal); 158 EXPECT(equal);
159 159
160 // Different objects. 160 // Different objects.
161 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); 161 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal));
162 EXPECT(!equal); 162 EXPECT(!equal);
163 163
164 Dart_ExitScope(); // Exit the Dart API scope. 164 Dart_ExitScope(); // Exit the Dart API scope.
165 Dart_ShutdownIsolate(); 165 Dart_ShutdownIsolate();
166 } 166 }
167 167
168 #endif 168 #endif
169 169
170 UNIT_TEST_CASE(BooleanValues) { 170 UNIT_TEST_CASE(BooleanValues) {
171 Dart_CreateIsolate(NULL, NULL); 171 Dart_CreateIsolate(NULL);
172 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 172 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
173 173
174 Dart_Handle str = Dart_NewString("test"); 174 Dart_Handle str = Dart_NewString("test");
175 EXPECT(!Dart_IsBoolean(str)); 175 EXPECT(!Dart_IsBoolean(str));
176 176
177 bool value = false; 177 bool value = false;
178 Dart_Handle result = Dart_BooleanValue(str, &value); 178 Dart_Handle result = Dart_BooleanValue(str, &value);
179 EXPECT(Dart_IsError(result)); 179 EXPECT(Dart_IsError(result));
180 180
181 Dart_Handle val1 = Dart_NewBoolean(true); 181 Dart_Handle val1 = Dart_NewBoolean(true);
182 EXPECT(Dart_IsBoolean(val1)); 182 EXPECT(Dart_IsBoolean(val1));
183 183
184 result = Dart_BooleanValue(val1, &value); 184 result = Dart_BooleanValue(val1, &value);
185 EXPECT_VALID(result); 185 EXPECT_VALID(result);
186 EXPECT(value); 186 EXPECT(value);
187 187
188 Dart_Handle val2 = Dart_NewBoolean(false); 188 Dart_Handle val2 = Dart_NewBoolean(false);
189 EXPECT(Dart_IsBoolean(val2)); 189 EXPECT(Dart_IsBoolean(val2));
190 190
191 result = Dart_BooleanValue(val2, &value); 191 result = Dart_BooleanValue(val2, &value);
192 EXPECT_VALID(result); 192 EXPECT_VALID(result);
193 EXPECT(!value); 193 EXPECT(!value);
194 194
195 Dart_ExitScope(); // Exit the Dart API scope. 195 Dart_ExitScope(); // Exit the Dart API scope.
196 Dart_ShutdownIsolate(); 196 Dart_ShutdownIsolate();
197 } 197 }
198 198
199 199
200 UNIT_TEST_CASE(BooleanConstants) { 200 UNIT_TEST_CASE(BooleanConstants) {
201 Dart_CreateIsolate(NULL, NULL); 201 Dart_CreateIsolate(NULL);
202 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 202 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
203 203
204 Dart_Handle true_handle = Dart_True(); 204 Dart_Handle true_handle = Dart_True();
205 EXPECT_VALID(true_handle); 205 EXPECT_VALID(true_handle);
206 EXPECT(Dart_IsBoolean(true_handle)); 206 EXPECT(Dart_IsBoolean(true_handle));
207 207
208 bool value = false; 208 bool value = false;
209 Dart_Handle result = Dart_BooleanValue(true_handle, &value); 209 Dart_Handle result = Dart_BooleanValue(true_handle, &value);
210 EXPECT_VALID(result); 210 EXPECT_VALID(result);
211 EXPECT(value); 211 EXPECT(value);
212 212
213 Dart_Handle false_handle = Dart_False(); 213 Dart_Handle false_handle = Dart_False();
214 EXPECT_VALID(false_handle); 214 EXPECT_VALID(false_handle);
215 EXPECT(Dart_IsBoolean(false_handle)); 215 EXPECT(Dart_IsBoolean(false_handle));
216 216
217 result = Dart_BooleanValue(false_handle, &value); 217 result = Dart_BooleanValue(false_handle, &value);
218 EXPECT_VALID(result); 218 EXPECT_VALID(result);
219 EXPECT(!value); 219 EXPECT(!value);
220 220
221 Dart_ExitScope(); // Exit the Dart API scope. 221 Dart_ExitScope(); // Exit the Dart API scope.
222 Dart_ShutdownIsolate(); 222 Dart_ShutdownIsolate();
223 } 223 }
224 224
225 225
226 UNIT_TEST_CASE(DoubleValues) { 226 UNIT_TEST_CASE(DoubleValues) {
227 Dart_CreateIsolate(NULL, NULL); 227 Dart_CreateIsolate(NULL);
228 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 228 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
229 229
230 const double kDoubleVal1 = 201.29; 230 const double kDoubleVal1 = 201.29;
231 const double kDoubleVal2 = 101.19; 231 const double kDoubleVal2 = 101.19;
232 Dart_Handle val1 = Dart_NewDouble(kDoubleVal1); 232 Dart_Handle val1 = Dart_NewDouble(kDoubleVal1);
233 EXPECT(Dart_IsDouble(val1)); 233 EXPECT(Dart_IsDouble(val1));
234 Dart_Handle val2 = Dart_NewDouble(kDoubleVal2); 234 Dart_Handle val2 = Dart_NewDouble(kDoubleVal2);
235 EXPECT(Dart_IsDouble(val2)); 235 EXPECT(Dart_IsDouble(val2));
236 double out1, out2; 236 double out1, out2;
237 Dart_Handle result = Dart_DoubleValue(val1, &out1); 237 Dart_Handle result = Dart_DoubleValue(val1, &out1);
(...skipping 14 matching lines...) Expand all
252 // TODO(antonm): add various kinds of ints (smi, mint, bigint). 252 // TODO(antonm): add various kinds of ints (smi, mint, bigint).
253 const char* kScriptChars = 253 const char* kScriptChars =
254 "class NumberValuesHelper {\n" 254 "class NumberValuesHelper {\n"
255 " static int getInt() { return 1; }\n" 255 " static int getInt() { return 1; }\n"
256 " static double getDouble() { return 1.0; }\n" 256 " static double getDouble() { return 1.0; }\n"
257 " static bool getBool() { return false; }\n" 257 " static bool getBool() { return false; }\n"
258 " static getNull() { return null; }\n" 258 " static getNull() { return null; }\n"
259 "}\n"; 259 "}\n";
260 Dart_Handle result; 260 Dart_Handle result;
261 261
262 Dart_CreateIsolate(NULL, NULL); 262 Dart_CreateIsolate(NULL);
263 { 263 {
264 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 264 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
265 265
266 // Create a test library and Load up a test script in it. 266 // Create a test library and Load up a test script in it.
267 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 267 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
268 268
269 Dart_Handle class_name = Dart_NewString("NumberValuesHelper"); 269 Dart_Handle class_name = Dart_NewString("NumberValuesHelper");
270 // Check int case. 270 // Check int case.
271 result = Dart_InvokeStatic(lib, 271 result = Dart_InvokeStatic(lib,
272 class_name, 272 class_name,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 305
306 Dart_ExitScope(); // Exit the Dart API scope. 306 Dart_ExitScope(); // Exit the Dart API scope.
307 } 307 }
308 Dart_ShutdownIsolate(); 308 Dart_ShutdownIsolate();
309 } 309 }
310 310
311 #endif 311 #endif
312 312
313 313
314 UNIT_TEST_CASE(IntegerValues) { 314 UNIT_TEST_CASE(IntegerValues) {
315 Dart_CreateIsolate(NULL, NULL); 315 Dart_CreateIsolate(NULL);
316 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 316 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
317 317
318 const int64_t kIntegerVal1 = 100; 318 const int64_t kIntegerVal1 = 100;
319 const int64_t kIntegerVal2 = 0xffffffff; 319 const int64_t kIntegerVal2 = 0xffffffff;
320 const char* kIntegerVal3 = "0x123456789123456789123456789"; 320 const char* kIntegerVal3 = "0x123456789123456789123456789";
321 321
322 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); 322 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1);
323 EXPECT(Dart_IsInteger(val1)); 323 EXPECT(Dart_IsInteger(val1));
324 bool fits = false; 324 bool fits = false;
325 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); 325 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits);
(...skipping 25 matching lines...) Expand all
351 result = Dart_IntegerValueHexCString(val3, &chars); 351 result = Dart_IntegerValueHexCString(val3, &chars);
352 EXPECT_VALID(result); 352 EXPECT_VALID(result);
353 EXPECT(!strcmp(kIntegerVal3, chars)); 353 EXPECT(!strcmp(kIntegerVal3, chars));
354 354
355 Dart_ExitScope(); // Exit the Dart API scope. 355 Dart_ExitScope(); // Exit the Dart API scope.
356 Dart_ShutdownIsolate(); 356 Dart_ShutdownIsolate();
357 } 357 }
358 358
359 359
360 UNIT_TEST_CASE(ArrayValues) { 360 UNIT_TEST_CASE(ArrayValues) {
361 Dart_CreateIsolate(NULL, NULL); 361 Dart_CreateIsolate(NULL);
362 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 362 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
363 363
364 const int kArrayLength = 10; 364 const int kArrayLength = 10;
365 Dart_Handle str = Dart_NewString("test"); 365 Dart_Handle str = Dart_NewString("test");
366 EXPECT(!Dart_IsList(str)); 366 EXPECT(!Dart_IsList(str));
367 Dart_Handle val = Dart_NewList(kArrayLength); 367 Dart_Handle val = Dart_NewList(kArrayLength);
368 EXPECT(Dart_IsList(val)); 368 EXPECT(Dart_IsList(val));
369 intptr_t len = 0; 369 intptr_t len = 0;
370 Dart_Handle result = Dart_ListLength(val, &len); 370 Dart_Handle result = Dart_ListLength(val, &len);
371 EXPECT_VALID(result); 371 EXPECT_VALID(result);
(...skipping 21 matching lines...) Expand all
393 EXPECT_VALID(result); 393 EXPECT_VALID(result);
394 EXPECT_EQ(i, value); 394 EXPECT_EQ(i, value);
395 } 395 }
396 396
397 Dart_ExitScope(); // Exit the Dart API scope. 397 Dart_ExitScope(); // Exit the Dart API scope.
398 Dart_ShutdownIsolate(); 398 Dart_ShutdownIsolate();
399 } 399 }
400 400
401 401
402 UNIT_TEST_CASE(IsString) { 402 UNIT_TEST_CASE(IsString) {
403 Dart_CreateIsolate(NULL, NULL); 403 Dart_CreateIsolate(NULL);
404 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 404 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
405 405
406 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; 406 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
407 407
408 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); 408 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8));
409 EXPECT_VALID(str8); 409 EXPECT_VALID(str8);
410 EXPECT(Dart_IsString(str8)); 410 EXPECT(Dart_IsString(str8));
411 EXPECT(Dart_IsString8(str8)); 411 EXPECT(Dart_IsString8(str8));
412 EXPECT(Dart_IsString16(str8)); 412 EXPECT(Dart_IsString16(str8));
413 413
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 " static List testMain() {" 462 " static List testMain() {"
463 " List a = new List();" 463 " List a = new List();"
464 " a.add(10);" 464 " a.add(10);"
465 " a.add(20);" 465 " a.add(20);"
466 " a.add(30);" 466 " a.add(30);"
467 " return a;" 467 " return a;"
468 " }" 468 " }"
469 "}"; 469 "}";
470 Dart_Handle result; 470 Dart_Handle result;
471 471
472 Dart_CreateIsolate(NULL, NULL); 472 Dart_CreateIsolate(NULL);
473 { 473 {
474 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 474 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
475 475
476 // Create a test library and Load up a test script in it. 476 // Create a test library and Load up a test script in it.
477 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 477 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
478 478
479 // Invoke a function which returns an object of type InstanceOf.. 479 // Invoke a function which returns an object of type InstanceOf..
480 result = Dart_InvokeStatic(lib, 480 result = Dart_InvokeStatic(lib,
481 Dart_NewString("ListAccessTest"), 481 Dart_NewString("ListAccessTest"),
482 Dart_NewString("testMain"), 482 Dart_NewString("testMain"),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 579 }
580 Dart_ShutdownIsolate(); 580 Dart_ShutdownIsolate();
581 } 581 }
582 582
583 #endif // TARGET_ARCH_IA32. 583 #endif // TARGET_ARCH_IA32.
584 584
585 585
586 // Unit test for entering a scope, creating a local handle and exiting 586 // Unit test for entering a scope, creating a local handle and exiting
587 // the scope. 587 // the scope.
588 UNIT_TEST_CASE(EnterExitScope) { 588 UNIT_TEST_CASE(EnterExitScope) {
589 Dart_CreateIsolate(NULL, NULL); 589 Dart_CreateIsolate(NULL);
590 Isolate* isolate = Isolate::Current(); 590 Isolate* isolate = Isolate::Current();
591 EXPECT(isolate != NULL); 591 EXPECT(isolate != NULL);
592 ApiState* state = isolate->api_state(); 592 ApiState* state = isolate->api_state();
593 EXPECT(state != NULL); 593 EXPECT(state != NULL);
594 ApiLocalScope* scope = state->top_scope(); 594 ApiLocalScope* scope = state->top_scope();
595 Dart_EnterScope(); 595 Dart_EnterScope();
596 { 596 {
597 EXPECT(state->top_scope() != NULL); 597 EXPECT(state->top_scope() != NULL);
598 DARTSCOPE(isolate); 598 DARTSCOPE(isolate);
599 const String& str1 = String::Handle(String::New("Test String")); 599 const String& str1 = String::Handle(String::New("Test String"));
600 Dart_Handle ref = Api::NewLocalHandle(str1); 600 Dart_Handle ref = Api::NewLocalHandle(str1);
601 String& str2 = String::Handle(); 601 String& str2 = String::Handle();
602 str2 ^= Api::UnwrapHandle(ref); 602 str2 ^= Api::UnwrapHandle(ref);
603 EXPECT(str1.Equals(str2)); 603 EXPECT(str1.Equals(str2));
604 } 604 }
605 Dart_ExitScope(); 605 Dart_ExitScope();
606 EXPECT(scope == state->top_scope()); 606 EXPECT(scope == state->top_scope());
607 Dart_ShutdownIsolate(); 607 Dart_ShutdownIsolate();
608 } 608 }
609 609
610 610
611 // Unit test for creating and deleting persistent handles. 611 // Unit test for creating and deleting persistent handles.
612 UNIT_TEST_CASE(PersistentHandles) { 612 UNIT_TEST_CASE(PersistentHandles) {
613 const char* kTestString1 = "Test String1"; 613 const char* kTestString1 = "Test String1";
614 const char* kTestString2 = "Test String2"; 614 const char* kTestString2 = "Test String2";
615 Dart_CreateIsolate(NULL, NULL); 615 Dart_CreateIsolate(NULL);
616 Isolate* isolate = Isolate::Current(); 616 Isolate* isolate = Isolate::Current();
617 EXPECT(isolate != NULL); 617 EXPECT(isolate != NULL);
618 ApiState* state = isolate->api_state(); 618 ApiState* state = isolate->api_state();
619 EXPECT(state != NULL); 619 EXPECT(state != NULL);
620 ApiLocalScope* scope = state->top_scope(); 620 ApiLocalScope* scope = state->top_scope();
621 Dart_Handle handles[2000]; 621 Dart_Handle handles[2000];
622 Dart_EnterScope(); 622 Dart_EnterScope();
623 { 623 {
624 DARTSCOPE(isolate); 624 DARTSCOPE(isolate);
625 const String& str1 = String::Handle(String::New(kTestString1)); 625 const String& str1 = String::Handle(String::New(kTestString1));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 671 }
672 EXPECT(scope == state->top_scope()); 672 EXPECT(scope == state->top_scope());
673 EXPECT_EQ(2000, state->CountPersistentHandles()); 673 EXPECT_EQ(2000, state->CountPersistentHandles());
674 Dart_ShutdownIsolate(); 674 Dart_ShutdownIsolate();
675 } 675 }
676 676
677 677
678 // Test that we are able to create a persistent handle from a 678 // Test that we are able to create a persistent handle from a
679 // persistent handle. 679 // persistent handle.
680 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { 680 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) {
681 Dart_CreateIsolate(NULL, NULL); 681 Dart_CreateIsolate(NULL);
682 682
683 Isolate* isolate = Isolate::Current(); 683 Isolate* isolate = Isolate::Current();
684 EXPECT(isolate != NULL); 684 EXPECT(isolate != NULL);
685 ApiState* state = isolate->api_state(); 685 ApiState* state = isolate->api_state();
686 EXPECT(state != NULL); 686 EXPECT(state != NULL);
687 687
688 // Start with a known persistent handle. 688 // Start with a known persistent handle.
689 Dart_Handle obj1 = Dart_True(); 689 Dart_Handle obj1 = Dart_True();
690 EXPECT(state->IsValidPersistentHandle(obj1)); 690 EXPECT(state->IsValidPersistentHandle(obj1));
691 691
692 // And use it to allocate a second persistent handle. 692 // And use it to allocate a second persistent handle.
693 Dart_Handle obj2 = Dart_NewPersistentHandle(obj1); 693 Dart_Handle obj2 = Dart_NewPersistentHandle(obj1);
694 EXPECT(state->IsValidPersistentHandle(obj2)); 694 EXPECT(state->IsValidPersistentHandle(obj2));
695 695
696 // Make sure that the value transferred. 696 // Make sure that the value transferred.
697 EXPECT(Dart_IsBoolean(obj2)); 697 EXPECT(Dart_IsBoolean(obj2));
698 bool value = false; 698 bool value = false;
699 Dart_Handle result = Dart_BooleanValue(obj2, &value); 699 Dart_Handle result = Dart_BooleanValue(obj2, &value);
700 EXPECT_VALID(result); 700 EXPECT_VALID(result);
701 EXPECT(value); 701 EXPECT(value);
702 702
703 Dart_ShutdownIsolate(); 703 Dart_ShutdownIsolate();
704 } 704 }
705 705
706 706
707 // Unit test for creating multiple scopes and local handles within them. 707 // Unit test for creating multiple scopes and local handles within them.
708 // Ensure that the local handles get all cleaned out when exiting the 708 // Ensure that the local handles get all cleaned out when exiting the
709 // scope. 709 // scope.
710 UNIT_TEST_CASE(LocalHandles) { 710 UNIT_TEST_CASE(LocalHandles) {
711 Dart_CreateIsolate(NULL, NULL); 711 Dart_CreateIsolate(NULL);
712 Isolate* isolate = Isolate::Current(); 712 Isolate* isolate = Isolate::Current();
713 EXPECT(isolate != NULL); 713 EXPECT(isolate != NULL);
714 ApiState* state = isolate->api_state(); 714 ApiState* state = isolate->api_state();
715 EXPECT(state != NULL); 715 EXPECT(state != NULL);
716 ApiLocalScope* scope = state->top_scope(); 716 ApiLocalScope* scope = state->top_scope();
717 Dart_Handle handles[300]; 717 Dart_Handle handles[300];
718 { 718 {
719 DARTSCOPE(isolate); 719 DARTSCOPE(isolate);
720 Smi& val = Smi::Handle(); 720 Smi& val = Smi::Handle();
721 721
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 EXPECT_EQ(0, state->CountLocalHandles()); 768 EXPECT_EQ(0, state->CountLocalHandles());
769 EXPECT(scope == state->top_scope()); 769 EXPECT(scope == state->top_scope());
770 Dart_ShutdownIsolate(); 770 Dart_ShutdownIsolate();
771 } 771 }
772 772
773 773
774 // Unit test for creating multiple scopes and allocating objects in the 774 // Unit test for creating multiple scopes and allocating objects in the
775 // zone for the scope. Ensure that the memory is freed when the scope 775 // zone for the scope. Ensure that the memory is freed when the scope
776 // exits. 776 // exits.
777 UNIT_TEST_CASE(LocalZoneMemory) { 777 UNIT_TEST_CASE(LocalZoneMemory) {
778 Dart_CreateIsolate(NULL, NULL); 778 Dart_CreateIsolate(NULL);
779 Isolate* isolate = Isolate::Current(); 779 Isolate* isolate = Isolate::Current();
780 EXPECT(isolate != NULL); 780 EXPECT(isolate != NULL);
781 ApiState* state = isolate->api_state(); 781 ApiState* state = isolate->api_state();
782 EXPECT(state != NULL); 782 EXPECT(state != NULL);
783 ApiLocalScope* scope = state->top_scope(); 783 ApiLocalScope* scope = state->top_scope();
784 { 784 {
785 // Start a new scope and allocate some memory. 785 // Start a new scope and allocate some memory.
786 Dart_EnterScope(); 786 Dart_EnterScope();
787 for (int i = 0; i < 100; i++) { 787 for (int i = 0; i < 100; i++) {
788 Api::Allocate(16); 788 Api::Allocate(16);
(...skipping 25 matching lines...) Expand all
814 } 814 }
815 EXPECT_EQ(0, state->ZoneSizeInBytes()); 815 EXPECT_EQ(0, state->ZoneSizeInBytes());
816 EXPECT(scope == state->top_scope()); 816 EXPECT(scope == state->top_scope());
817 Dart_ShutdownIsolate(); 817 Dart_ShutdownIsolate();
818 } 818 }
819 819
820 820
821 UNIT_TEST_CASE(Isolates) { 821 UNIT_TEST_CASE(Isolates) {
822 // This test currently assumes that the Dart_Isolate type is an opaque 822 // This test currently assumes that the Dart_Isolate type is an opaque
823 // representation of Isolate*. 823 // representation of Isolate*.
824 Dart_Isolate iso_1 = Dart_CreateIsolate(NULL, NULL); 824 Dart_Isolate iso_1 = Dart_CreateIsolate(NULL);
825 EXPECT_EQ(iso_1, Isolate::Current()); 825 EXPECT_EQ(iso_1, Isolate::Current());
826 Dart_Isolate isolate = Dart_CurrentIsolate(); 826 Dart_Isolate isolate = Dart_CurrentIsolate();
827 EXPECT_EQ(iso_1, isolate); 827 EXPECT_EQ(iso_1, isolate);
828 Dart_ExitIsolate(); 828 Dart_ExitIsolate();
829 EXPECT(NULL == Isolate::Current()); 829 EXPECT(NULL == Isolate::Current());
830 EXPECT(NULL == Dart_CurrentIsolate()); 830 EXPECT(NULL == Dart_CurrentIsolate());
831 Dart_Isolate iso_2 = Dart_CreateIsolate(NULL, NULL); 831 Dart_Isolate iso_2 = Dart_CreateIsolate(NULL);
832 EXPECT_EQ(iso_2, Isolate::Current()); 832 EXPECT_EQ(iso_2, Isolate::Current());
833 Dart_ExitIsolate(); 833 Dart_ExitIsolate();
834 EXPECT(NULL == Isolate::Current()); 834 EXPECT(NULL == Isolate::Current());
835 Dart_EnterIsolate(iso_2); 835 Dart_EnterIsolate(iso_2);
836 EXPECT_EQ(iso_2, Isolate::Current()); 836 EXPECT_EQ(iso_2, Isolate::Current());
837 Dart_ShutdownIsolate(); 837 Dart_ShutdownIsolate();
838 EXPECT(NULL == Isolate::Current()); 838 EXPECT(NULL == Isolate::Current());
839 Dart_EnterIsolate(iso_1); 839 Dart_EnterIsolate(iso_1);
840 EXPECT_EQ(iso_1, Isolate::Current()); 840 EXPECT_EQ(iso_1, Isolate::Current());
841 Dart_ShutdownIsolate(); 841 Dart_ShutdownIsolate();
842 EXPECT(NULL == Isolate::Current()); 842 EXPECT(NULL == Isolate::Current());
843 } 843 }
844 844
845 845
846 static bool MyPostMessageCallback(Dart_Isolate dest_isolate, 846 static bool MyPostMessageCallback(Dart_Isolate dest_isolate,
847 Dart_Port send_port, 847 Dart_Port send_port,
848 Dart_Port reply_port, 848 Dart_Port reply_port,
849 Dart_Message message) { 849 Dart_Message message) {
850 return true; 850 return true;
851 } 851 }
852 852
853 853
854 static void MyClosePortCallback(Dart_Isolate dest_isolate, 854 static void MyClosePortCallback(Dart_Isolate dest_isolate,
855 Dart_Port port) { 855 Dart_Port port) {
856 } 856 }
857 857
858 858
859 UNIT_TEST_CASE(SetMessageCallbacks) { 859 UNIT_TEST_CASE(SetMessageCallbacks) {
860 Dart_Isolate dart_isolate = Dart_CreateIsolate(NULL, NULL); 860 Dart_Isolate dart_isolate = Dart_CreateIsolate(NULL);
861 Dart_SetMessageCallbacks(&MyPostMessageCallback, &MyClosePortCallback); 861 Dart_SetMessageCallbacks(&MyPostMessageCallback, &MyClosePortCallback);
862 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); 862 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
863 EXPECT_EQ(&MyPostMessageCallback, isolate->post_message_callback()); 863 EXPECT_EQ(&MyPostMessageCallback, isolate->post_message_callback());
864 EXPECT_EQ(&MyClosePortCallback, isolate->close_port_callback()); 864 EXPECT_EQ(&MyClosePortCallback, isolate->close_port_callback());
865 Dart_ShutdownIsolate(); 865 Dart_ShutdownIsolate();
866 } 866 }
867 867
868 868
869 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 869 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
870 870
871 UNIT_TEST_CASE(FieldAccess) { 871 UNIT_TEST_CASE(FieldAccess) {
872 const char* kScriptChars = 872 const char* kScriptChars =
873 "class Fields {\n" 873 "class Fields {\n"
874 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" 874 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n"
875 " int fld1;\n" 875 " int fld1;\n"
876 " final int fld2;\n" 876 " final int fld2;\n"
877 " static int fld3;\n" 877 " static int fld3;\n"
878 " static final int fld4 = 10;\n" 878 " static final int fld4 = 10;\n"
879 "}\n" 879 "}\n"
880 "class FieldsTest {\n" 880 "class FieldsTest {\n"
881 " static Fields testMain() {\n" 881 " static Fields testMain() {\n"
882 " Fields obj = new Fields(10, 20);\n" 882 " Fields obj = new Fields(10, 20);\n"
883 " return obj;\n" 883 " return obj;\n"
884 " }\n" 884 " }\n"
885 "}\n"; 885 "}\n";
886 Dart_Handle result; 886 Dart_Handle result;
887 887
888 Dart_CreateIsolate(NULL, NULL); 888 Dart_CreateIsolate(NULL);
889 { 889 {
890 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 890 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
891 891
892 // Create a test library and Load up a test script in it. 892 // Create a test library and Load up a test script in it.
893 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 893 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
894 894
895 // Invoke a function which returns an object. 895 // Invoke a function which returns an object.
896 Dart_Handle retobj = Dart_InvokeStatic(lib, 896 Dart_Handle retobj = Dart_InvokeStatic(lib,
897 Dart_NewString("FieldsTest"), 897 Dart_NewString("FieldsTest"),
898 Dart_NewString("testMain"), 898 Dart_NewString("testMain"),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 " static final int _fld4 = 10;\n" 965 " static final int _fld4 = 10;\n"
966 "}\n" 966 "}\n"
967 "class HiddenFieldsTest {\n" 967 "class HiddenFieldsTest {\n"
968 " static HiddenFields testMain() {\n" 968 " static HiddenFields testMain() {\n"
969 " HiddenFields obj = new HiddenFields(10, 20);\n" 969 " HiddenFields obj = new HiddenFields(10, 20);\n"
970 " return obj;\n" 970 " return obj;\n"
971 " }\n" 971 " }\n"
972 "}\n"; 972 "}\n";
973 Dart_Handle result; 973 Dart_Handle result;
974 974
975 Dart_CreateIsolate(NULL, NULL); 975 Dart_CreateIsolate(NULL);
976 { 976 {
977 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 977 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
978 978
979 // Load up a test script which extends the native wrapper class. 979 // Load up a test script which extends the native wrapper class.
980 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 980 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
981 981
982 // Invoke a function which returns an object. 982 // Invoke a function which returns an object.
983 Dart_Handle retobj = Dart_InvokeStatic(lib, 983 Dart_Handle retobj = Dart_InvokeStatic(lib,
984 Dart_NewString("HiddenFieldsTest"), 984 Dart_NewString("HiddenFieldsTest"),
985 Dart_NewString("testMain"), 985 Dart_NewString("testMain"),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 " static final int fld4 = 10;\n" 1063 " static final int fld4 = 10;\n"
1064 "}\n" 1064 "}\n"
1065 "class NativeFieldsTest {\n" 1065 "class NativeFieldsTest {\n"
1066 " static NativeFields testMain() {\n" 1066 " static NativeFields testMain() {\n"
1067 " NativeFields obj = new NativeFields(10, 20);\n" 1067 " NativeFields obj = new NativeFields(10, 20);\n"
1068 " return obj;\n" 1068 " return obj;\n"
1069 " }\n" 1069 " }\n"
1070 "}\n"; 1070 "}\n";
1071 Dart_Handle result; 1071 Dart_Handle result;
1072 1072
1073 Dart_CreateIsolate(NULL, NULL); 1073 Dart_CreateIsolate(NULL);
1074 { 1074 {
1075 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1075 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1076 const int kNumNativeFields = 4; 1076 const int kNumNativeFields = 4;
1077 1077
1078 // Create a test library. 1078 // Create a test library.
1079 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1079 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1080 native_field_lookup); 1080 native_field_lookup);
1081 1081
1082 // Create a native wrapper class with native fields. 1082 // Create a native wrapper class with native fields.
1083 result = Dart_CreateNativeWrapperClass( 1083 result = Dart_CreateNativeWrapperClass(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 " static final int fld4 = 10;\n" 1124 " static final int fld4 = 10;\n"
1125 "}\n" 1125 "}\n"
1126 "class NativeFieldsTest {\n" 1126 "class NativeFieldsTest {\n"
1127 " static NativeFields testMain() {\n" 1127 " static NativeFields testMain() {\n"
1128 " NativeFields obj = new NativeFields(10, 20);\n" 1128 " NativeFields obj = new NativeFields(10, 20);\n"
1129 " return obj;\n" 1129 " return obj;\n"
1130 " }\n" 1130 " }\n"
1131 "}\n"; 1131 "}\n";
1132 Dart_Handle result; 1132 Dart_Handle result;
1133 1133
1134 Dart_CreateIsolate(NULL, NULL); 1134 Dart_CreateIsolate(NULL);
1135 { 1135 {
1136 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1136 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1137 1137
1138 // Create a test library and Load up a test script in it. 1138 // Create a test library and Load up a test script in it.
1139 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1139 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1140 1140
1141 // Invoke a function which returns an object of type NativeFields. 1141 // Invoke a function which returns an object of type NativeFields.
1142 result = Dart_InvokeStatic(lib, 1142 result = Dart_InvokeStatic(lib,
1143 Dart_NewString("NativeFieldsTest"), 1143 Dart_NewString("NativeFieldsTest"),
1144 Dart_NewString("testMain"), 1144 Dart_NewString("testMain"),
(...skipping 21 matching lines...) Expand all
1166 " static final int fld4 = 10;\n" 1166 " static final int fld4 = 10;\n"
1167 "}\n" 1167 "}\n"
1168 "class NativeFieldsTest {\n" 1168 "class NativeFieldsTest {\n"
1169 " static NativeFields testMain() {\n" 1169 " static NativeFields testMain() {\n"
1170 " NativeFields obj = new NativeFields(10, 20);\n" 1170 " NativeFields obj = new NativeFields(10, 20);\n"
1171 " return obj;\n" 1171 " return obj;\n"
1172 " }\n" 1172 " }\n"
1173 "}\n"; 1173 "}\n";
1174 Dart_Handle result; 1174 Dart_Handle result;
1175 1175
1176 Dart_CreateIsolate(NULL, NULL); 1176 Dart_CreateIsolate(NULL);
1177 { 1177 {
1178 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1178 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1179 const int kNumNativeFields = 2; 1179 const int kNumNativeFields = 2;
1180 1180
1181 // Load up a test script in the test library. 1181 // Load up a test script in the test library.
1182 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1182 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1183 native_field_lookup); 1183 native_field_lookup);
1184 1184
1185 // Invoke a function which returns an object of type NativeFields. 1185 // Invoke a function which returns an object of type NativeFields.
1186 result = Dart_InvokeStatic(lib, 1186 result = Dart_InvokeStatic(lib,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 " static final int fld4 = 10;\n" 1220 " static final int fld4 = 10;\n"
1221 "}\n" 1221 "}\n"
1222 "class NativeFieldsTest {\n" 1222 "class NativeFieldsTest {\n"
1223 " static NativeFields testMain() {\n" 1223 " static NativeFields testMain() {\n"
1224 " NativeFields obj = new NativeFields(10, 20);\n" 1224 " NativeFields obj = new NativeFields(10, 20);\n"
1225 " return obj;\n" 1225 " return obj;\n"
1226 " }\n" 1226 " }\n"
1227 "}\n"; 1227 "}\n";
1228 Dart_Handle result; 1228 Dart_Handle result;
1229 1229
1230 Dart_CreateIsolate(NULL, NULL); 1230 Dart_CreateIsolate(NULL);
1231 { 1231 {
1232 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1232 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1233 1233
1234 // Load up a test script in the test library. 1234 // Load up a test script in the test library.
1235 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1235 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1236 1236
1237 // Invoke a function which returns an object of type NativeFields. 1237 // Invoke a function which returns an object of type NativeFields.
1238 result = Dart_InvokeStatic(lib, 1238 result = Dart_InvokeStatic(lib,
1239 Dart_NewString("NativeFieldsTest"), 1239 Dart_NewString("NativeFieldsTest"),
1240 Dart_NewString("testMain"), 1240 Dart_NewString("testMain"),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 " static final int fld4 = 10;\n" 1334 " static final int fld4 = 10;\n"
1335 "}\n" 1335 "}\n"
1336 "class NativeFieldsTest {\n" 1336 "class NativeFieldsTest {\n"
1337 " static NativeFields testMain() {\n" 1337 " static NativeFields testMain() {\n"
1338 " NativeFields obj = new NativeFields(10, 20);\n" 1338 " NativeFields obj = new NativeFields(10, 20);\n"
1339 " return obj;\n" 1339 " return obj;\n"
1340 " }\n" 1340 " }\n"
1341 "}\n"; 1341 "}\n";
1342 Dart_Handle result; 1342 Dart_Handle result;
1343 1343
1344 Dart_CreateIsolate(NULL, NULL); 1344 Dart_CreateIsolate(NULL);
1345 { 1345 {
1346 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1346 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1347 const int kNumNativeFields = 4; 1347 const int kNumNativeFields = 4;
1348 1348
1349 // Create a test library. 1349 // Create a test library.
1350 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1350 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1351 native_field_lookup); 1351 native_field_lookup);
1352 1352
1353 // Create a native wrapper class with native fields. 1353 // Create a native wrapper class with native fields.
1354 result = Dart_CreateNativeWrapperClass( 1354 result = Dart_CreateNativeWrapperClass(
(...skipping 29 matching lines...) Expand all
1384 " final int fld2;\n" 1384 " final int fld2;\n"
1385 " static int fld3;\n" 1385 " static int fld3;\n"
1386 " static final int fld4 = 10;\n" 1386 " static final int fld4 = 10;\n"
1387 "}\n" 1387 "}\n"
1388 "class NativeFieldsTest {\n" 1388 "class NativeFieldsTest {\n"
1389 " static NativeFields testMain() {\n" 1389 " static NativeFields testMain() {\n"
1390 " NativeFields obj = new NativeFields(10, 20);\n" 1390 " NativeFields obj = new NativeFields(10, 20);\n"
1391 " return obj;\n" 1391 " return obj;\n"
1392 " }\n" 1392 " }\n"
1393 "}\n"; 1393 "}\n";
1394 Dart_CreateIsolate(NULL, NULL); 1394 Dart_CreateIsolate(NULL);
1395 { 1395 {
1396 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1396 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1397 1397
1398 // Load up a test script in the test library. 1398 // Load up a test script in the test library.
1399 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1399 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1400 native_field_lookup); 1400 native_field_lookup);
1401 1401
1402 // Invoke a function which returns an object of type NativeFields. 1402 // Invoke a function which returns an object of type NativeFields.
1403 Dart_Handle retobj = Dart_InvokeStatic(lib, 1403 Dart_Handle retobj = Dart_InvokeStatic(lib,
1404 Dart_NewString("NativeFieldsTest"), 1404 Dart_NewString("NativeFieldsTest"),
(...skipping 24 matching lines...) Expand all
1429 " static NativeFields testMain1() {\n" 1429 " static NativeFields testMain1() {\n"
1430 " NativeFields obj = new NativeFields(10, 20);\n" 1430 " NativeFields obj = new NativeFields(10, 20);\n"
1431 " return obj;\n" 1431 " return obj;\n"
1432 " }\n" 1432 " }\n"
1433 " static Function testMain2() {\n" 1433 " static Function testMain2() {\n"
1434 " return function() {};\n" 1434 " return function() {};\n"
1435 " }\n" 1435 " }\n"
1436 "}\n"; 1436 "}\n";
1437 Dart_Handle result; 1437 Dart_Handle result;
1438 1438
1439 Dart_CreateIsolate(NULL, NULL); 1439 Dart_CreateIsolate(NULL);
1440 { 1440 {
1441 DARTSCOPE(Isolate::Current()); 1441 DARTSCOPE(Isolate::Current());
1442 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1442 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1443 1443
1444 // Create a test library and Load up a test script in it. 1444 // Create a test library and Load up a test script in it.
1445 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1445 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1446 1446
1447 // Invoke a function which returns an object of type NativeFields. 1447 // Invoke a function which returns an object of type NativeFields.
1448 Dart_Handle retobj = Dart_InvokeStatic(lib, 1448 Dart_Handle retobj = Dart_InvokeStatic(lib,
1449 Dart_NewString("NativeFieldsTest"), 1449 Dart_NewString("NativeFieldsTest"),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 UNIT_TEST_CASE(GetStaticField_RunsInitializer) { 1507 UNIT_TEST_CASE(GetStaticField_RunsInitializer) {
1508 const char* kScriptChars = 1508 const char* kScriptChars =
1509 "class TestClass {\n" 1509 "class TestClass {\n"
1510 " static final int fld1 = 7;\n" 1510 " static final int fld1 = 7;\n"
1511 " static int fld2 = 11;\n" 1511 " static int fld2 = 11;\n"
1512 " static void testMain() {\n" 1512 " static void testMain() {\n"
1513 " }\n" 1513 " }\n"
1514 "}\n"; 1514 "}\n";
1515 Dart_Handle result; 1515 Dart_Handle result;
1516 1516
1517 Dart_CreateIsolate(NULL, NULL); 1517 Dart_CreateIsolate(NULL);
1518 { 1518 {
1519 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1519 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1520 1520
1521 // Create a test library and Load up a test script in it. 1521 // Create a test library and Load up a test script in it.
1522 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1522 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1523 1523
1524 // Invoke a function which returns an object. 1524 // Invoke a function which returns an object.
1525 result = Dart_InvokeStatic(lib, 1525 result = Dart_InvokeStatic(lib,
1526 Dart_NewString("TestClass"), 1526 Dart_NewString("TestClass"),
1527 Dart_NewString("testMain"), 1527 Dart_NewString("testMain"),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 1562
1563 1563
1564 UNIT_TEST_CASE(StaticFieldNotFound) { 1564 UNIT_TEST_CASE(StaticFieldNotFound) {
1565 const char* kScriptChars = 1565 const char* kScriptChars =
1566 "class TestClass {\n" 1566 "class TestClass {\n"
1567 " static void testMain() {\n" 1567 " static void testMain() {\n"
1568 " }\n" 1568 " }\n"
1569 "}\n"; 1569 "}\n";
1570 Dart_Handle result; 1570 Dart_Handle result;
1571 1571
1572 Dart_CreateIsolate(NULL, NULL); 1572 Dart_CreateIsolate(NULL);
1573 { 1573 {
1574 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1574 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1575 1575
1576 // Create a test library and Load up a test script in it. 1576 // Create a test library and Load up a test script in it.
1577 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1577 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1578 1578
1579 // Invoke a function. 1579 // Invoke a function.
1580 result = Dart_InvokeStatic(lib, 1580 result = Dart_InvokeStatic(lib,
1581 Dart_NewString("TestClass"), 1581 Dart_NewString("TestClass"),
1582 Dart_NewString("testMain"), 1582 Dart_NewString("testMain"),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 " static final int fld4 = 10;\n" 1615 " static final int fld4 = 10;\n"
1616 "}\n" 1616 "}\n"
1617 "class InvokeDynamicTest {\n" 1617 "class InvokeDynamicTest {\n"
1618 " static InvokeDynamic testMain() {\n" 1618 " static InvokeDynamic testMain() {\n"
1619 " InvokeDynamic obj = new InvokeDynamic(10, 20);\n" 1619 " InvokeDynamic obj = new InvokeDynamic(10, 20);\n"
1620 " return obj;\n" 1620 " return obj;\n"
1621 " }\n" 1621 " }\n"
1622 "}\n"; 1622 "}\n";
1623 Dart_Handle result; 1623 Dart_Handle result;
1624 1624
1625 Dart_CreateIsolate(NULL, NULL); 1625 Dart_CreateIsolate(NULL);
1626 { 1626 {
1627 DARTSCOPE(Isolate::Current()); 1627 DARTSCOPE(Isolate::Current());
1628 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1628 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1629 1629
1630 // Create a test library and Load up a test script in it. 1630 // Create a test library and Load up a test script in it.
1631 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1631 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1632 1632
1633 // Invoke a function which returns an object of type InvokeDynamic. 1633 // Invoke a function which returns an object of type InvokeDynamic.
1634 Dart_Handle retobj = Dart_InvokeStatic(lib, 1634 Dart_Handle retobj = Dart_InvokeStatic(lib,
1635 Dart_NewString("InvokeDynamicTest"), 1635 Dart_NewString("InvokeDynamicTest"),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 " static Function testMain1() {\n" 1684 " static Function testMain1() {\n"
1685 " InvokeClosure obj = new InvokeClosure(10, 20);\n" 1685 " InvokeClosure obj = new InvokeClosure(10, 20);\n"
1686 " return obj.method1(10);\n" 1686 " return obj.method1(10);\n"
1687 " }\n" 1687 " }\n"
1688 " static Function testMain2() {\n" 1688 " static Function testMain2() {\n"
1689 " return InvokeClosure.method2(10);\n" 1689 " return InvokeClosure.method2(10);\n"
1690 " }\n" 1690 " }\n"
1691 "}\n"; 1691 "}\n";
1692 Dart_Handle result; 1692 Dart_Handle result;
1693 1693
1694 Dart_CreateIsolate(NULL, NULL); 1694 Dart_CreateIsolate(NULL);
1695 { 1695 {
1696 DARTSCOPE(Isolate::Current()); 1696 DARTSCOPE(Isolate::Current());
1697 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1697 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1698 1698
1699 // Create a test library and Load up a test script in it. 1699 // Create a test library and Load up a test script in it.
1700 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1700 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1701 1701
1702 // Invoke a function which returns a closure. 1702 // Invoke a function which returns a closure.
1703 Dart_Handle retobj = Dart_InvokeStatic(lib, 1703 Dart_Handle retobj = Dart_InvokeStatic(lib,
1704 Dart_NewString("InvokeClosureTest"), 1704 Dart_NewString("InvokeClosureTest"),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 " int fld1;\n" 1774 " int fld1;\n"
1775 "}\n" 1775 "}\n"
1776 "class ThrowExceptionTest {\n" 1776 "class ThrowExceptionTest {\n"
1777 " static ThrowException testMain() {\n" 1777 " static ThrowException testMain() {\n"
1778 " ThrowException obj = new ThrowException(10);\n" 1778 " ThrowException obj = new ThrowException(10);\n"
1779 " return obj;\n" 1779 " return obj;\n"
1780 " }\n" 1780 " }\n"
1781 "}\n"; 1781 "}\n";
1782 Dart_Handle result; 1782 Dart_Handle result;
1783 1783
1784 Dart_CreateIsolate(NULL, NULL); 1784 Dart_CreateIsolate(NULL);
1785 Isolate* isolate = Isolate::Current(); 1785 Isolate* isolate = Isolate::Current();
1786 EXPECT(isolate != NULL); 1786 EXPECT(isolate != NULL);
1787 ApiState* state = isolate->api_state(); 1787 ApiState* state = isolate->api_state();
1788 EXPECT(state != NULL); 1788 EXPECT(state != NULL);
1789 { 1789 {
1790 intptr_t size = state->ZoneSizeInBytes(); 1790 intptr_t size = state->ZoneSizeInBytes();
1791 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1791 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1792 1792
1793 // Load up a test script which extends the native wrapper class. 1793 // Load up a test script which extends the native wrapper class.
1794 Dart_Handle lib = TestCase::LoadTestScript( 1794 Dart_Handle lib = TestCase::LoadTestScript(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 "class MyObject {" 1842 "class MyObject {"
1843 " int method1(int i, int j) native 'Name_Does_Not_Matter';" 1843 " int method1(int i, int j) native 'Name_Does_Not_Matter';"
1844 "}" 1844 "}"
1845 "class Test {" 1845 "class Test {"
1846 " static testMain() {" 1846 " static testMain() {"
1847 " MyObject obj = new MyObject();" 1847 " MyObject obj = new MyObject();"
1848 " return obj.method1(77, 125);" 1848 " return obj.method1(77, 125);"
1849 " }" 1849 " }"
1850 "}"; 1850 "}";
1851 1851
1852 Dart_CreateIsolate(NULL, NULL); 1852 Dart_CreateIsolate(NULL);
1853 { 1853 {
1854 Dart_EnterScope(); 1854 Dart_EnterScope();
1855 Dart_Handle lib = TestCase::LoadTestScript( 1855 Dart_Handle lib = TestCase::LoadTestScript(
1856 kScriptChars, 1856 kScriptChars,
1857 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); 1857 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup));
1858 1858
1859 Dart_Handle result = Dart_InvokeStatic(lib, 1859 Dart_Handle result = Dart_InvokeStatic(lib,
1860 Dart_NewString("Test"), 1860 Dart_NewString("Test"),
1861 Dart_NewString("testMain"), 1861 Dart_NewString("testMain"),
1862 0, 1862 0,
(...skipping 10 matching lines...) Expand all
1873 } 1873 }
1874 Dart_ShutdownIsolate(); 1874 Dart_ShutdownIsolate();
1875 } 1875 }
1876 1876
1877 1877
1878 UNIT_TEST_CASE(GetClass) { 1878 UNIT_TEST_CASE(GetClass) {
1879 const char* kScriptChars = 1879 const char* kScriptChars =
1880 "class DoesExist {" 1880 "class DoesExist {"
1881 "}"; 1881 "}";
1882 1882
1883 Dart_CreateIsolate(NULL, NULL); 1883 Dart_CreateIsolate(NULL);
1884 Dart_EnterScope(); 1884 Dart_EnterScope();
1885 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1885 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1886 1886
1887 // Lookup a class that does exist. 1887 // Lookup a class that does exist.
1888 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist")); 1888 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist"));
1889 EXPECT_VALID(cls); 1889 EXPECT_VALID(cls);
1890 1890
1891 // Lookup a class that does not exist. 1891 // Lookup a class that does not exist.
1892 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist")); 1892 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist"));
1893 EXPECT(Dart_IsError(cls)); 1893 EXPECT(Dart_IsError(cls));
(...skipping 11 matching lines...) Expand all
1905 " static returnNull() { return null; }\n" 1905 " static returnNull() { return null; }\n"
1906 "}\n" 1906 "}\n"
1907 "class InstanceOfTest {\n" 1907 "class InstanceOfTest {\n"
1908 " InstanceOfTest() {}\n" 1908 " InstanceOfTest() {}\n"
1909 " static InstanceOfTest testMain() {\n" 1909 " static InstanceOfTest testMain() {\n"
1910 " return new InstanceOfTest();\n" 1910 " return new InstanceOfTest();\n"
1911 " }\n" 1911 " }\n"
1912 "}\n"; 1912 "}\n";
1913 Dart_Handle result; 1913 Dart_Handle result;
1914 1914
1915 Dart_CreateIsolate(NULL, NULL); 1915 Dart_CreateIsolate(NULL);
1916 { 1916 {
1917 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1917 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1918 1918
1919 // Create a test library and Load up a test script in it. 1919 // Create a test library and Load up a test script in it.
1920 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1920 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1921 1921
1922 // Invoke a function which returns an object of type InstanceOf.. 1922 // Invoke a function which returns an object of type InstanceOf..
1923 Dart_Handle instanceOfTestObj = 1923 Dart_Handle instanceOfTestObj =
1924 Dart_InvokeStatic(lib, 1924 Dart_InvokeStatic(lib,
1925 Dart_NewString("InstanceOfTest"), 1925 Dart_NewString("InstanceOfTest"),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 result = Dart_ObjectIsType(null, null, &is_instance); 1977 result = Dart_ObjectIsType(null, null, &is_instance);
1978 EXPECT(Dart_IsError(result)); 1978 EXPECT(Dart_IsError(result));
1979 1979
1980 Dart_ExitScope(); // Exit the Dart API scope. 1980 Dart_ExitScope(); // Exit the Dart API scope.
1981 } 1981 }
1982 Dart_ShutdownIsolate(); 1982 Dart_ShutdownIsolate();
1983 } 1983 }
1984 1984
1985 1985
1986 UNIT_TEST_CASE(NullReceiver) { 1986 UNIT_TEST_CASE(NullReceiver) {
1987 Dart_CreateIsolate(NULL, NULL); 1987 Dart_CreateIsolate(NULL);
1988 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 1988 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
1989 { 1989 {
1990 DARTSCOPE(Isolate::Current()); 1990 DARTSCOPE(Isolate::Current());
1991 1991
1992 Dart_Handle function_name = Dart_NewString("toString"); 1992 Dart_Handle function_name = Dart_NewString("toString");
1993 const int number_of_arguments = 0; 1993 const int number_of_arguments = 0;
1994 Dart_Handle null_receiver = Api::NewLocalHandle(Object::Handle()); 1994 Dart_Handle null_receiver = Api::NewLocalHandle(Object::Handle());
1995 Dart_Handle result = Dart_InvokeDynamic(null_receiver, 1995 Dart_Handle result = Dart_InvokeDynamic(null_receiver,
1996 function_name, 1996 function_name,
1997 number_of_arguments, 1997 number_of_arguments,
(...skipping 25 matching lines...) Expand all
2023 return Api::Success(); 2023 return Api::Success();
2024 } 2024 }
2025 2025
2026 2026
2027 UNIT_TEST_CASE(LoadScript) { 2027 UNIT_TEST_CASE(LoadScript) {
2028 const char* kScriptChars = 2028 const char* kScriptChars =
2029 "main() {" 2029 "main() {"
2030 " return 12345;" 2030 " return 12345;"
2031 "}"; 2031 "}";
2032 2032
2033 Dart_CreateIsolate(NULL, NULL); 2033 Dart_CreateIsolate(NULL);
2034 Dart_EnterScope(); 2034 Dart_EnterScope();
2035 2035
2036 Dart_Handle url = Dart_NewString(TestCase::url()); 2036 Dart_Handle url = Dart_NewString(TestCase::url());
2037 Dart_Handle source = Dart_NewString(kScriptChars); 2037 Dart_Handle source = Dart_NewString(kScriptChars);
2038 Dart_Handle error = Dart_Error("incoming error"); 2038 Dart_Handle error = Dart_Error("incoming error");
2039 Dart_Handle result; 2039 Dart_Handle result;
2040 2040
2041 result = Dart_LoadScript(Dart_Null(), source, library_handler); 2041 result = Dart_LoadScript(Dart_Null(), source, library_handler);
2042 EXPECT(Dart_IsError(result)); 2042 EXPECT(Dart_IsError(result));
2043 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", 2043 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.",
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 2091
2092 Dart_ExitScope(); 2092 Dart_ExitScope();
2093 Dart_ShutdownIsolate(); 2093 Dart_ShutdownIsolate();
2094 } 2094 }
2095 2095
2096 2096
2097 UNIT_TEST_CASE(LoadScript_CompileError) { 2097 UNIT_TEST_CASE(LoadScript_CompileError) {
2098 const char* kScriptChars = 2098 const char* kScriptChars =
2099 ")"; 2099 ")";
2100 2100
2101 Dart_CreateIsolate(NULL, NULL); 2101 Dart_CreateIsolate(NULL);
2102 Dart_EnterScope(); 2102 Dart_EnterScope();
2103 2103
2104 Dart_Handle url = Dart_NewString(TestCase::url()); 2104 Dart_Handle url = Dart_NewString(TestCase::url());
2105 Dart_Handle source = Dart_NewString(kScriptChars); 2105 Dart_Handle source = Dart_NewString(kScriptChars);
2106 Dart_Handle result = Dart_LoadScript(url, source, library_handler); 2106 Dart_Handle result = Dart_LoadScript(url, source, library_handler);
2107 EXPECT(Dart_IsError(result)); 2107 EXPECT(Dart_IsError(result));
2108 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 2108 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
2109 2109
2110 Dart_ExitScope(); 2110 Dart_ExitScope();
2111 Dart_ShutdownIsolate(); 2111 Dart_ShutdownIsolate();
2112 } 2112 }
2113 2113
2114 2114
2115 UNIT_TEST_CASE(LookupLibrary) { 2115 UNIT_TEST_CASE(LookupLibrary) {
2116 const char* kScriptChars = 2116 const char* kScriptChars =
2117 "#import('library1.dart');" 2117 "#import('library1.dart');"
2118 "main() {}"; 2118 "main() {}";
2119 const char* kLibrary1Chars = 2119 const char* kLibrary1Chars =
2120 "#library('library1.dart');" 2120 "#library('library1.dart');"
2121 "#import('library2.dart');"; 2121 "#import('library2.dart');";
2122 2122
2123 Dart_CreateIsolate(NULL, NULL); 2123 Dart_CreateIsolate(NULL);
2124 Dart_EnterScope(); 2124 Dart_EnterScope();
2125 2125
2126 // Create a test library and Load up a test script in it. 2126 // Create a test library and Load up a test script in it.
2127 Dart_Handle url = Dart_NewString(TestCase::url()); 2127 Dart_Handle url = Dart_NewString(TestCase::url());
2128 Dart_Handle source = Dart_NewString(kScriptChars); 2128 Dart_Handle source = Dart_NewString(kScriptChars);
2129 Dart_Handle result = Dart_LoadScript(url, source, library_handler); 2129 Dart_Handle result = Dart_LoadScript(url, source, library_handler);
2130 EXPECT_VALID(result); 2130 EXPECT_VALID(result);
2131 2131
2132 url = Dart_NewString("library1.dart"); 2132 url = Dart_NewString("library1.dart");
2133 source = Dart_NewString(kLibrary1Chars); 2133 source = Dart_NewString(kLibrary1Chars);
(...skipping 26 matching lines...) Expand all
2160 2160
2161 Dart_ExitScope(); 2161 Dart_ExitScope();
2162 Dart_ShutdownIsolate(); 2162 Dart_ShutdownIsolate();
2163 } 2163 }
2164 2164
2165 2165
2166 UNIT_TEST_CASE(LibraryUrl) { 2166 UNIT_TEST_CASE(LibraryUrl) {
2167 const char* kLibrary1Chars = 2167 const char* kLibrary1Chars =
2168 "#library('library1_name');"; 2168 "#library('library1_name');";
2169 2169
2170 Dart_CreateIsolate(NULL, NULL); 2170 Dart_CreateIsolate(NULL);
2171 Dart_EnterScope(); 2171 Dart_EnterScope();
2172 2172
2173 Dart_Handle url = Dart_NewString("library1_url"); 2173 Dart_Handle url = Dart_NewString("library1_url");
2174 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2174 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2175 Dart_Handle lib = Dart_LoadLibrary(url, source); 2175 Dart_Handle lib = Dart_LoadLibrary(url, source);
2176 Dart_Handle error = Dart_Error("incoming error"); 2176 Dart_Handle error = Dart_Error("incoming error");
2177 EXPECT_VALID(lib); 2177 EXPECT_VALID(lib);
2178 2178
2179 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); 2179 Dart_Handle result = Dart_LibraryUrl(Dart_Null());
2180 EXPECT(Dart_IsError(result)); 2180 EXPECT(Dart_IsError(result));
(...skipping 21 matching lines...) Expand all
2202 Dart_ShutdownIsolate(); 2202 Dart_ShutdownIsolate();
2203 } 2203 }
2204 2204
2205 2205
2206 UNIT_TEST_CASE(LibraryImportLibrary) { 2206 UNIT_TEST_CASE(LibraryImportLibrary) {
2207 const char* kLibrary1Chars = 2207 const char* kLibrary1Chars =
2208 "#library('library1_name');"; 2208 "#library('library1_name');";
2209 const char* kLibrary2Chars = 2209 const char* kLibrary2Chars =
2210 "#library('library2_name');"; 2210 "#library('library2_name');";
2211 2211
2212 Dart_CreateIsolate(NULL, NULL); 2212 Dart_CreateIsolate(NULL);
2213 Dart_EnterScope(); 2213 Dart_EnterScope();
2214 2214
2215 Dart_Handle error = Dart_Error("incoming error"); 2215 Dart_Handle error = Dart_Error("incoming error");
2216 Dart_Handle result; 2216 Dart_Handle result;
2217 2217
2218 Dart_Handle url = Dart_NewString("library1_url"); 2218 Dart_Handle url = Dart_NewString("library1_url");
2219 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2219 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2220 Dart_Handle lib1 = Dart_LoadLibrary(url, source); 2220 Dart_Handle lib1 = Dart_LoadLibrary(url, source);
2221 EXPECT_VALID(lib1); 2221 EXPECT_VALID(lib1);
2222 2222
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 Dart_ExitScope(); 2263 Dart_ExitScope();
2264 Dart_ShutdownIsolate(); 2264 Dart_ShutdownIsolate();
2265 } 2265 }
2266 2266
2267 2267
2268 2268
2269 UNIT_TEST_CASE(LoadLibrary) { 2269 UNIT_TEST_CASE(LoadLibrary) {
2270 const char* kLibrary1Chars = 2270 const char* kLibrary1Chars =
2271 "#library('library1_name');"; 2271 "#library('library1_name');";
2272 2272
2273 Dart_CreateIsolate(NULL, NULL); 2273 Dart_CreateIsolate(NULL);
2274 Dart_EnterScope(); 2274 Dart_EnterScope();
2275 2275
2276 Dart_Handle error = Dart_Error("incoming error"); 2276 Dart_Handle error = Dart_Error("incoming error");
2277 Dart_Handle result; 2277 Dart_Handle result;
2278 2278
2279 Dart_Handle url = Dart_NewString("library1_url"); 2279 Dart_Handle url = Dart_NewString("library1_url");
2280 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2280 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2281 2281
2282 result = Dart_LoadLibrary(Dart_Null(), source); 2282 result = Dart_LoadLibrary(Dart_Null(), source);
2283 EXPECT(Dart_IsError(result)); 2283 EXPECT(Dart_IsError(result));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 Dart_ExitScope(); 2323 Dart_ExitScope();
2324 Dart_ShutdownIsolate(); 2324 Dart_ShutdownIsolate();
2325 } 2325 }
2326 2326
2327 2327
2328 UNIT_TEST_CASE(LoadLibrary_CompileError) { 2328 UNIT_TEST_CASE(LoadLibrary_CompileError) {
2329 const char* kLibrary1Chars = 2329 const char* kLibrary1Chars =
2330 "#library('library1_name');" 2330 "#library('library1_name');"
2331 ")"; 2331 ")";
2332 2332
2333 Dart_CreateIsolate(NULL, NULL); 2333 Dart_CreateIsolate(NULL);
2334 Dart_EnterScope(); 2334 Dart_EnterScope();
2335 2335
2336 Dart_Handle url = Dart_NewString("library1_url"); 2336 Dart_Handle url = Dart_NewString("library1_url");
2337 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2337 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2338 Dart_Handle result = Dart_LoadLibrary(url, source); 2338 Dart_Handle result = Dart_LoadLibrary(url, source);
2339 EXPECT(Dart_IsError(result)); 2339 EXPECT(Dart_IsError(result));
2340 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 2340 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
2341 2341
2342 Dart_ExitScope(); 2342 Dart_ExitScope();
2343 Dart_ShutdownIsolate(); 2343 Dart_ShutdownIsolate();
2344 } 2344 }
2345 2345
2346 2346
2347 UNIT_TEST_CASE(LoadSource) { 2347 UNIT_TEST_CASE(LoadSource) {
2348 const char* kLibrary1Chars = 2348 const char* kLibrary1Chars =
2349 "#library('library1_name');"; 2349 "#library('library1_name');";
2350 const char* kSourceChars = 2350 const char* kSourceChars =
2351 "// Something innocuous"; 2351 "// Something innocuous";
2352 const char* kBadSourceChars = 2352 const char* kBadSourceChars =
2353 ")"; 2353 ")";
2354 2354
2355 Dart_CreateIsolate(NULL, NULL); 2355 Dart_CreateIsolate(NULL);
2356 Dart_EnterScope(); 2356 Dart_EnterScope();
2357 2357
2358 Dart_Handle error = Dart_Error("incoming error"); 2358 Dart_Handle error = Dart_Error("incoming error");
2359 Dart_Handle result; 2359 Dart_Handle result;
2360 2360
2361 // Load up a library. 2361 // Load up a library.
2362 Dart_Handle url = Dart_NewString("library1_url"); 2362 Dart_Handle url = Dart_NewString("library1_url");
2363 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2363 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2364 Dart_Handle lib = Dart_LoadLibrary(url, source); 2364 Dart_Handle lib = Dart_LoadLibrary(url, source);
2365 EXPECT_VALID(lib); 2365 EXPECT_VALID(lib);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 2465
2466 2466
2467 UNIT_TEST_CASE(SetNativeResolver) { 2467 UNIT_TEST_CASE(SetNativeResolver) {
2468 const char* kScriptChars = 2468 const char* kScriptChars =
2469 "class Test {" 2469 "class Test {"
2470 " static foo() native \"SomeNativeFunction\";" 2470 " static foo() native \"SomeNativeFunction\";"
2471 " static bar() native \"SomeNativeFunction2\";" 2471 " static bar() native \"SomeNativeFunction2\";"
2472 " static baz() native \"SomeNativeFunction3\";" 2472 " static baz() native \"SomeNativeFunction3\";"
2473 "}"; 2473 "}";
2474 2474
2475 Dart_CreateIsolate(NULL, NULL); 2475 Dart_CreateIsolate(NULL);
2476 Dart_EnterScope(); 2476 Dart_EnterScope();
2477 2477
2478 Dart_Handle error = Dart_Error("incoming error"); 2478 Dart_Handle error = Dart_Error("incoming error");
2479 Dart_Handle result; 2479 Dart_Handle result;
2480 2480
2481 // Load a test script. 2481 // Load a test script.
2482 Dart_Handle url = Dart_NewString(TestCase::url()); 2482 Dart_Handle url = Dart_NewString(TestCase::url());
2483 Dart_Handle source = Dart_NewString(kScriptChars); 2483 Dart_Handle source = Dart_NewString(kScriptChars);
2484 Dart_Handle lib = Dart_LoadScript(url, source, library_handler); 2484 Dart_Handle lib = Dart_LoadScript(url, source, library_handler);
2485 EXPECT_VALID(lib); 2485 EXPECT_VALID(lib);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 "main() {}"; 2570 "main() {}";
2571 const char* kLibrary1Chars = 2571 const char* kLibrary1Chars =
2572 "#library('library1.dart');" 2572 "#library('library1.dart');"
2573 "#import('library2.dart');" 2573 "#import('library2.dart');"
2574 "var foo1;"; 2574 "var foo1;";
2575 const char* kLibrary2Chars = 2575 const char* kLibrary2Chars =
2576 "#library('library2.dart');" 2576 "#library('library2.dart');"
2577 "var foo;"; 2577 "var foo;";
2578 Dart_Handle result; 2578 Dart_Handle result;
2579 2579
2580 Dart_CreateIsolate(NULL, NULL); 2580 Dart_CreateIsolate(NULL);
2581 { 2581 {
2582 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 2582 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
2583 2583
2584 // Create a test library and Load up a test script in it. 2584 // Create a test library and Load up a test script in it.
2585 Dart_Handle url = Dart_NewString(TestCase::url()); 2585 Dart_Handle url = Dart_NewString(TestCase::url());
2586 Dart_Handle source = Dart_NewString(kScriptChars); 2586 Dart_Handle source = Dart_NewString(kScriptChars);
2587 result = Dart_LoadScript(url, source, library_handler); 2587 result = Dart_LoadScript(url, source, library_handler);
2588 2588
2589 url = Dart_NewString("library1.dart"); 2589 url = Dart_NewString("library1.dart");
2590 source = Dart_NewString(kLibrary1Chars); 2590 source = Dart_NewString(kLibrary1Chars);
(...skipping 27 matching lines...) Expand all
2618 const char* kLibrary1Chars = 2618 const char* kLibrary1Chars =
2619 "#library('library1.dart');" 2619 "#library('library1.dart');"
2620 "#import('library2.dart');" 2620 "#import('library2.dart');"
2621 "var foo1;"; 2621 "var foo1;";
2622 const char* kLibrary2Chars = 2622 const char* kLibrary2Chars =
2623 "#library('library2.dart');" 2623 "#library('library2.dart');"
2624 "#import('library1.dart');" 2624 "#import('library1.dart');"
2625 "var foo;"; 2625 "var foo;";
2626 Dart_Handle result; 2626 Dart_Handle result;
2627 2627
2628 Dart_CreateIsolate(NULL, NULL); 2628 Dart_CreateIsolate(NULL);
2629 { 2629 {
2630 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 2630 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
2631 2631
2632 // Create a test library and Load up a test script in it. 2632 // Create a test library and Load up a test script in it.
2633 Dart_Handle url = Dart_NewString(TestCase::url()); 2633 Dart_Handle url = Dart_NewString(TestCase::url());
2634 Dart_Handle source = Dart_NewString(kScriptChars); 2634 Dart_Handle source = Dart_NewString(kScriptChars);
2635 result = Dart_LoadScript(url, source, library_handler); 2635 result = Dart_LoadScript(url, source, library_handler);
2636 2636
2637 url = Dart_NewString("library1.dart"); 2637 url = Dart_NewString("library1.dart");
2638 source = Dart_NewString(kLibrary1Chars); 2638 source = Dart_NewString(kLibrary1Chars);
(...skipping 23 matching lines...) Expand all
2662 "var foo_top = 10; // foo has dup def. So should be an error." 2662 "var foo_top = 10; // foo has dup def. So should be an error."
2663 "main() {}"; 2663 "main() {}";
2664 const char* kLibrary1Chars = 2664 const char* kLibrary1Chars =
2665 "#library('library1.dart');" 2665 "#library('library1.dart');"
2666 "var foo;"; 2666 "var foo;";
2667 const char* kLibrary2Chars = 2667 const char* kLibrary2Chars =
2668 "#library('library2.dart');" 2668 "#library('library2.dart');"
2669 "var foo;"; 2669 "var foo;";
2670 Dart_Handle result; 2670 Dart_Handle result;
2671 2671
2672 Dart_CreateIsolate(NULL, NULL); 2672 Dart_CreateIsolate(NULL);
2673 { 2673 {
2674 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 2674 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
2675 2675
2676 // Create a test library and Load up a test script in it. 2676 // Create a test library and Load up a test script in it.
2677 Dart_Handle url = Dart_NewString(TestCase::url()); 2677 Dart_Handle url = Dart_NewString(TestCase::url());
2678 Dart_Handle source = Dart_NewString(kScriptChars); 2678 Dart_Handle source = Dart_NewString(kScriptChars);
2679 result = Dart_LoadScript(url, source, library_handler); 2679 result = Dart_LoadScript(url, source, library_handler);
2680 2680
2681 url = Dart_NewString("library2.dart"); 2681 url = Dart_NewString("library2.dart");
2682 source = Dart_NewString(kLibrary2Chars); 2682 source = Dart_NewString(kLibrary2Chars);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 const char* kLibraryEChars = 2728 const char* kLibraryEChars =
2729 "#library('libraryE.dart');" 2729 "#library('libraryE.dart');"
2730 "#import('libraryC.dart');" 2730 "#import('libraryC.dart');"
2731 "#import('libraryF.dart');" 2731 "#import('libraryF.dart');"
2732 "var fooE = 10; //fooC has duplicate def. so should be an error."; 2732 "var fooE = 10; //fooC has duplicate def. so should be an error.";
2733 const char* kLibraryFChars = 2733 const char* kLibraryFChars =
2734 "#library('libraryF.dart');" 2734 "#library('libraryF.dart');"
2735 "var fooC;"; 2735 "var fooC;";
2736 Dart_Handle result; 2736 Dart_Handle result;
2737 2737
2738 Dart_CreateIsolate(NULL, NULL); 2738 Dart_CreateIsolate(NULL);
2739 { 2739 {
2740 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 2740 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
2741 2741
2742 // Create a test library and Load up a test script in it. 2742 // Create a test library and Load up a test script in it.
2743 Dart_Handle url = Dart_NewString(TestCase::url()); 2743 Dart_Handle url = Dart_NewString(TestCase::url());
2744 Dart_Handle source = Dart_NewString(kScriptChars); 2744 Dart_Handle source = Dart_NewString(kScriptChars);
2745 result = Dart_LoadScript(url, source, library_handler); 2745 result = Dart_LoadScript(url, source, library_handler);
2746 2746
2747 url = Dart_NewString("libraryA.dart"); 2747 url = Dart_NewString("libraryA.dart");
2748 source = Dart_NewString(kLibraryAChars); 2748 source = Dart_NewString(kLibraryAChars);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2791 " void set handler(void callback(List<int> x));" 2791 " void set handler(void callback(List<int> x));"
2792 "}" 2792 "}"
2793 "void main() {}"; 2793 "void main() {}";
2794 const char* kLibraryChars = 2794 const char* kLibraryChars =
2795 "#library('lib.dart');" 2795 "#library('lib.dart');"
2796 "interface X {" 2796 "interface X {"
2797 " void set handler(void callback(List<int> x));" 2797 " void set handler(void callback(List<int> x));"
2798 "}"; 2798 "}";
2799 Dart_Handle result; 2799 Dart_Handle result;
2800 2800
2801 Dart_CreateIsolate(NULL, NULL); 2801 Dart_CreateIsolate(NULL);
2802 { 2802 {
2803 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 2803 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
2804 2804
2805 // Create a test library and Load up a test script in it. 2805 // Create a test library and Load up a test script in it.
2806 Dart_Handle url = Dart_NewString(TestCase::url()); 2806 Dart_Handle url = Dart_NewString(TestCase::url());
2807 Dart_Handle source = Dart_NewString(kScriptChars); 2807 Dart_Handle source = Dart_NewString(kScriptChars);
2808 result = Dart_LoadScript(url, source, library_handler); 2808 result = Dart_LoadScript(url, source, library_handler);
2809 2809
2810 url = Dart_NewString("lib.dart"); 2810 url = Dart_NewString("lib.dart");
2811 source = Dart_NewString(kLibraryChars); 2811 source = Dart_NewString(kLibraryChars);
2812 Dart_LoadLibrary(url, source); 2812 Dart_LoadLibrary(url, source);
2813 2813
2814 result = Dart_InvokeStatic(result, 2814 result = Dart_InvokeStatic(result,
2815 Dart_NewString(""), 2815 Dart_NewString(""),
2816 Dart_NewString("main"), 2816 Dart_NewString("main"),
2817 0, 2817 0,
2818 NULL); 2818 NULL);
2819 EXPECT_VALID(result); 2819 EXPECT_VALID(result);
2820 2820
2821 Dart_ExitScope(); // Exit the Dart API scope. 2821 Dart_ExitScope(); // Exit the Dart API scope.
2822 } 2822 }
2823 Dart_ShutdownIsolate(); 2823 Dart_ShutdownIsolate();
2824 } 2824 }
2825 #endif // TARGET_ARCH_IA32. 2825 #endif // TARGET_ARCH_IA32.
2826 2826
2827 } // namespace dart 2827 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698