OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
6 #include "bin/builtin.h" | 6 #include "bin/builtin.h" |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
12 #include "platform/text_buffer.h" | 12 #include "platform/text_buffer.h" |
13 #include "platform/utils.h" | 13 #include "platform/utils.h" |
14 #include "vm/class_finalizer.h" | 14 #include "vm/class_finalizer.h" |
15 #include "vm/compiler.h" | 15 #include "vm/compiler.h" |
16 #include "vm/dart_api_state.h" | 16 #include "vm/dart_api_state.h" |
17 #include "vm/lockers.h" | 17 #include "vm/lockers.h" |
18 #include "vm/timeline.h" | 18 #include "vm/timeline.h" |
19 #include "vm/unit_test.h" | 19 #include "vm/unit_test.h" |
20 #include "vm/verifier.h" | 20 #include "vm/verifier.h" |
21 | 21 |
22 namespace dart { | 22 namespace dart { |
23 | 23 |
24 DECLARE_FLAG(bool, verify_acquired_data); | 24 DECLARE_FLAG(bool, verify_acquired_data); |
25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); | 25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
26 DECLARE_FLAG(bool, support_externalizable_strings); | 26 DECLARE_FLAG(bool, support_externalizable_strings); |
| 27 DECLARE_FLAG(bool, use_dart_frontend); |
27 | 28 |
28 #ifndef PRODUCT | 29 #ifndef PRODUCT |
29 | 30 |
30 TEST_CASE(ErrorHandleBasics) { | 31 TEST_CASE(ErrorHandleBasics) { |
31 const char* kScriptChars = | 32 const char* kScriptChars = |
32 "void testMain() {\n" | 33 "void testMain() {\n" |
33 " throw new Exception(\"bad news\");\n" | 34 " throw new Exception(\"bad news\");\n" |
34 "}\n"; | 35 "}\n"; |
35 | 36 |
36 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 37 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 93 |
93 Dart_ActivationFrame frame; | 94 Dart_ActivationFrame frame; |
94 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 95 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
95 EXPECT_VALID(result); | 96 EXPECT_VALID(result); |
96 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 97 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
97 &line_number, &column_number); | 98 &line_number, &column_number); |
98 EXPECT_VALID(result); | 99 EXPECT_VALID(result); |
99 Dart_StringToCString(function_name, &cstr); | 100 Dart_StringToCString(function_name, &cstr); |
100 EXPECT_STREQ("bar", cstr); | 101 EXPECT_STREQ("bar", cstr); |
101 Dart_StringToCString(script_url, &cstr); | 102 Dart_StringToCString(script_url, &cstr); |
102 EXPECT_STREQ("test-lib", cstr); | 103 EXPECT_SUBSTRING("test-lib", cstr); |
103 EXPECT_EQ(1, line_number); | 104 EXPECT_EQ(1, line_number); |
104 EXPECT_EQ(10, column_number); | 105 EXPECT_EQ(10, column_number); |
105 | 106 |
106 result = Dart_GetActivationFrame(stacktrace, 1, &frame); | 107 result = Dart_GetActivationFrame(stacktrace, 1, &frame); |
107 EXPECT_VALID(result); | 108 EXPECT_VALID(result); |
108 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 109 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
109 &line_number, &column_number); | 110 &line_number, &column_number); |
110 EXPECT_VALID(result); | 111 EXPECT_VALID(result); |
111 Dart_StringToCString(function_name, &cstr); | 112 Dart_StringToCString(function_name, &cstr); |
112 EXPECT_STREQ("foo", cstr); | 113 EXPECT_STREQ("foo", cstr); |
113 Dart_StringToCString(script_url, &cstr); | 114 Dart_StringToCString(script_url, &cstr); |
114 EXPECT_STREQ("test-lib", cstr); | 115 EXPECT_SUBSTRING("test-lib", cstr); |
115 EXPECT_EQ(2, line_number); | 116 EXPECT_EQ(2, line_number); |
116 EXPECT_EQ(10, column_number); | 117 EXPECT_EQ(10, column_number); |
117 | 118 |
118 result = Dart_GetActivationFrame(stacktrace, 2, &frame); | 119 result = Dart_GetActivationFrame(stacktrace, 2, &frame); |
119 EXPECT_VALID(result); | 120 EXPECT_VALID(result); |
120 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 121 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
121 &line_number, &column_number); | 122 &line_number, &column_number); |
122 EXPECT_VALID(result); | 123 EXPECT_VALID(result); |
123 Dart_StringToCString(function_name, &cstr); | 124 Dart_StringToCString(function_name, &cstr); |
124 EXPECT_STREQ("testMain", cstr); | 125 EXPECT_STREQ("testMain", cstr); |
125 Dart_StringToCString(script_url, &cstr); | 126 Dart_StringToCString(script_url, &cstr); |
126 EXPECT_STREQ("test-lib", cstr); | 127 EXPECT_SUBSTRING("test-lib", cstr); |
127 EXPECT_EQ(3, line_number); | 128 EXPECT_EQ(3, line_number); |
128 EXPECT_EQ(15, column_number); | 129 EXPECT_EQ(15, column_number); |
129 | 130 |
130 // Out-of-bounds frames. | 131 // Out-of-bounds frames. |
131 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 132 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
132 EXPECT(Dart_IsError(result)); | 133 EXPECT(Dart_IsError(result)); |
133 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 134 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
134 EXPECT(Dart_IsError(result)); | 135 EXPECT(Dart_IsError(result)); |
135 } | 136 } |
136 | 137 |
(...skipping 28 matching lines...) Expand all Loading... |
165 // Top frame at positioned at throw. | 166 // Top frame at positioned at throw. |
166 Dart_ActivationFrame frame; | 167 Dart_ActivationFrame frame; |
167 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 168 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
168 EXPECT_VALID(result); | 169 EXPECT_VALID(result); |
169 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 170 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
170 &line_number, &column_number); | 171 &line_number, &column_number); |
171 EXPECT_VALID(result); | 172 EXPECT_VALID(result); |
172 Dart_StringToCString(function_name, &cstr); | 173 Dart_StringToCString(function_name, &cstr); |
173 EXPECT_STREQ("foo", cstr); | 174 EXPECT_STREQ("foo", cstr); |
174 Dart_StringToCString(script_url, &cstr); | 175 Dart_StringToCString(script_url, &cstr); |
175 EXPECT_STREQ("test-lib", cstr); | 176 EXPECT_SUBSTRING("test-lib", cstr); |
176 EXPECT_EQ(1, line_number); | 177 EXPECT_EQ(1, line_number); |
177 EXPECT_EQ(20, column_number); | 178 EXPECT_EQ(20, column_number); |
178 | 179 |
179 // Middle frames positioned at the recursive call. | 180 // Middle frames positioned at the recursive call. |
180 for (intptr_t frame_index = 1; frame_index < (frame_count - 1); | 181 for (intptr_t frame_index = 1; frame_index < (frame_count - 1); |
181 frame_index++) { | 182 frame_index++) { |
182 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); | 183 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); |
183 EXPECT_VALID(result); | 184 EXPECT_VALID(result); |
184 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 185 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
185 &line_number, &column_number); | 186 &line_number, &column_number); |
186 EXPECT_VALID(result); | 187 EXPECT_VALID(result); |
187 Dart_StringToCString(function_name, &cstr); | 188 Dart_StringToCString(function_name, &cstr); |
188 EXPECT_STREQ("foo", cstr); | 189 EXPECT_STREQ("foo", cstr); |
189 Dart_StringToCString(script_url, &cstr); | 190 Dart_StringToCString(script_url, &cstr); |
190 EXPECT_STREQ("test-lib", cstr); | 191 EXPECT_SUBSTRING("test-lib", cstr); |
191 EXPECT_EQ(1, line_number); | 192 EXPECT_EQ(1, line_number); |
192 EXPECT_EQ(40, column_number); | 193 EXPECT_EQ(40, column_number); |
193 } | 194 } |
194 | 195 |
195 // Bottom frame positioned at testMain(). | 196 // Bottom frame positioned at testMain(). |
196 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); | 197 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); |
197 EXPECT_VALID(result); | 198 EXPECT_VALID(result); |
198 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 199 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
199 &line_number, &column_number); | 200 &line_number, &column_number); |
200 EXPECT_VALID(result); | 201 EXPECT_VALID(result); |
201 Dart_StringToCString(function_name, &cstr); | 202 Dart_StringToCString(function_name, &cstr); |
202 EXPECT_STREQ("testMain", cstr); | 203 EXPECT_STREQ("testMain", cstr); |
203 Dart_StringToCString(script_url, &cstr); | 204 Dart_StringToCString(script_url, &cstr); |
204 EXPECT_STREQ("test-lib", cstr); | 205 EXPECT_SUBSTRING("test-lib", cstr); |
205 EXPECT_EQ(2, line_number); | 206 EXPECT_EQ(2, line_number); |
206 EXPECT_EQ(15, column_number); | 207 EXPECT_EQ(15, column_number); |
207 | 208 |
208 // Out-of-bounds frames. | 209 // Out-of-bounds frames. |
209 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 210 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
210 EXPECT(Dart_IsError(result)); | 211 EXPECT(Dart_IsError(result)); |
211 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 212 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
212 EXPECT(Dart_IsError(result)); | 213 EXPECT(Dart_IsError(result)); |
213 } | 214 } |
214 | 215 |
(...skipping 3158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3373 Dart_Isolate isolate = | 3374 Dart_Isolate isolate = |
3374 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 3375 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
3375 bin::core_isolate_snapshot_instructions, NULL, | 3376 bin::core_isolate_snapshot_instructions, NULL, |
3376 reinterpret_cast<void*>(mydata), &err); | 3377 reinterpret_cast<void*>(mydata), &err); |
3377 EXPECT(isolate != NULL); | 3378 EXPECT(isolate != NULL); |
3378 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); | 3379 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); |
3379 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); | 3380 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); |
3380 Dart_ShutdownIsolate(); | 3381 Dart_ShutdownIsolate(); |
3381 } | 3382 } |
3382 | 3383 |
| 3384 static Dart_Handle LoadScript(const char* url_str, const char* source) { |
| 3385 Dart_Handle url = NewString(url_str); |
| 3386 Dart_Handle result; |
| 3387 Dart_Handle script; |
| 3388 if (!FLAG_use_dart_frontend) { |
| 3389 result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
| 3390 EXPECT_VALID(result); |
| 3391 script = NewString(source); |
| 3392 } else { |
| 3393 void* kernel_pgm = NULL; |
| 3394 char* error = |
| 3395 TestCase::CompileTestScriptWithDFE(url_str, source, &kernel_pgm); |
| 3396 if (error != NULL) { |
| 3397 return Dart_NewApiError(error); |
| 3398 } |
| 3399 script = reinterpret_cast<Dart_Handle>(kernel_pgm); |
| 3400 } |
| 3401 return Dart_LoadScript(url, Dart_Null(), script, 0, 0); |
| 3402 } |
| 3403 |
3383 VM_UNIT_TEST_CASE(IsolateSetCheckedMode) { | 3404 VM_UNIT_TEST_CASE(IsolateSetCheckedMode) { |
3384 const char* kScriptChars = | 3405 const char* kScriptChars = |
3385 "int bad1() {\n" | 3406 "int bad1() {\n" |
3386 " int foo = 'string';\n" | 3407 " int foo = 'string';\n" |
3387 " return foo;\n" | 3408 " return foo;\n" |
3388 "}\n" | 3409 "}\n" |
3389 "\n" | 3410 "\n" |
3390 "int good1() {\n" | 3411 "int good1() {\n" |
3391 " int five = 5;\n" | 3412 " int five = 5;\n" |
3392 " return five;" | 3413 " return five;" |
(...skipping 11 matching lines...) Expand all Loading... |
3404 Dart_Isolate isolate = Dart_CreateIsolate( | 3425 Dart_Isolate isolate = Dart_CreateIsolate( |
3405 NULL, NULL, bin::core_isolate_snapshot_data, | 3426 NULL, NULL, bin::core_isolate_snapshot_data, |
3406 bin::core_isolate_snapshot_instructions, &api_flags, NULL, &err); | 3427 bin::core_isolate_snapshot_instructions, &api_flags, NULL, &err); |
3407 if (isolate == NULL) { | 3428 if (isolate == NULL) { |
3408 OS::Print("Creation of isolate failed '%s'\n", err); | 3429 OS::Print("Creation of isolate failed '%s'\n", err); |
3409 free(err); | 3430 free(err); |
3410 } | 3431 } |
3411 EXPECT(isolate != NULL); | 3432 EXPECT(isolate != NULL); |
3412 | 3433 |
3413 { | 3434 { |
| 3435 Dart_Handle result; |
3414 Dart_EnterScope(); | 3436 Dart_EnterScope(); |
3415 Dart_Handle url = NewString(TestCase::url()); | 3437 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3416 Dart_Handle source = NewString(kScriptChars); | |
3417 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | |
3418 EXPECT_VALID(result); | |
3419 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | |
3420 EXPECT_VALID(lib); | 3438 EXPECT_VALID(lib); |
3421 result = Dart_FinalizeLoading(false); | 3439 result = Dart_FinalizeLoading(false); |
3422 EXPECT_VALID(result); | 3440 EXPECT_VALID(result); |
3423 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); | 3441 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); |
3424 EXPECT_ERROR(result, | 3442 EXPECT_ERROR(result, |
3425 "Unhandled exception:\n" | 3443 "Unhandled exception:\n" |
3426 "type 'String' is not a subtype of type 'int' of 'foo'"); | 3444 "type 'String' is not a subtype of type 'int' of 'foo'"); |
3427 | 3445 |
3428 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); | 3446 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); |
3429 EXPECT_VALID(result); | 3447 EXPECT_VALID(result); |
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5648 result = Dart_LoadScript(url, Dart_True(), source, 0, 0); | 5666 result = Dart_LoadScript(url, Dart_True(), source, 0, 0); |
5649 EXPECT(Dart_IsError(result)); | 5667 EXPECT(Dart_IsError(result)); |
5650 EXPECT_STREQ( | 5668 EXPECT_STREQ( |
5651 "Dart_LoadScript expects argument 'resolved_url' to be of type String.", | 5669 "Dart_LoadScript expects argument 'resolved_url' to be of type String.", |
5652 Dart_GetError(result)); | 5670 Dart_GetError(result)); |
5653 | 5671 |
5654 result = Dart_LoadScript(url, error, source, 0, 0); | 5672 result = Dart_LoadScript(url, error, source, 0, 0); |
5655 EXPECT(Dart_IsError(result)); | 5673 EXPECT(Dart_IsError(result)); |
5656 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5674 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
5657 | 5675 |
5658 result = Dart_LoadScript(url, Dart_Null(), Dart_Null(), 0, 0); | 5676 if (!FLAG_use_dart_frontend) { |
5659 EXPECT(Dart_IsError(result)); | 5677 result = Dart_LoadScript(url, Dart_Null(), Dart_Null(), 0, 0); |
5660 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.", | 5678 EXPECT(Dart_IsError(result)); |
5661 Dart_GetError(result)); | 5679 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.", |
| 5680 Dart_GetError(result)); |
5662 | 5681 |
5663 result = Dart_LoadScript(url, Dart_Null(), Dart_True(), 0, 0); | 5682 result = Dart_LoadScript(url, Dart_Null(), Dart_True(), 0, 0); |
5664 EXPECT(Dart_IsError(result)); | 5683 EXPECT(Dart_IsError(result)); |
5665 EXPECT_STREQ( | 5684 EXPECT_STREQ( |
5666 "Dart_LoadScript expects argument 'source' to be of type String.", | 5685 "Dart_LoadScript expects argument 'source' to be of type String.", |
5667 Dart_GetError(result)); | 5686 Dart_GetError(result)); |
5668 | 5687 |
5669 result = Dart_LoadScript(url, Dart_Null(), error, 0, 0); | 5688 result = Dart_LoadScript(url, Dart_Null(), error, 0, 0); |
5670 EXPECT(Dart_IsError(result)); | 5689 EXPECT(Dart_IsError(result)); |
5671 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5690 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5691 } |
5672 | 5692 |
5673 // Load a script successfully. | 5693 // Load a script successfully. |
5674 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5694 result = TestCase::LoadTestScript(kScriptChars, NULL); |
5675 EXPECT_VALID(result); | 5695 EXPECT_VALID(result); |
5676 Dart_FinalizeLoading(false); | 5696 Dart_FinalizeLoading(false); |
5677 | 5697 |
5678 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 5698 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
5679 EXPECT_VALID(result); | 5699 EXPECT_VALID(result); |
5680 EXPECT(Dart_IsInteger(result)); | 5700 EXPECT(Dart_IsInteger(result)); |
5681 int64_t value = 0; | 5701 int64_t value = 0; |
5682 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5702 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
5683 EXPECT_EQ(12345, value); | 5703 EXPECT_EQ(12345, value); |
5684 | 5704 |
5685 // Further calls to LoadScript are errors. | 5705 // Further calls to LoadScript are errors. |
5686 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5706 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
5687 EXPECT(Dart_IsError(result)); | 5707 EXPECT(Dart_IsError(result)); |
5688 EXPECT_STREQ( | 5708 EXPECT_SUBSTRING("Dart_LoadScript: A script has already been loaded from", |
5689 "Dart_LoadScript: " | 5709 Dart_GetError(result)); |
5690 "A script has already been loaded from 'test-lib'.", | |
5691 Dart_GetError(result)); | |
5692 } | 5710 } |
5693 | 5711 |
5694 TEST_CASE(RootLibrary) { | 5712 TEST_CASE(RootLibrary) { |
5695 const char* kScriptChars = | 5713 const char* kScriptChars = |
5696 "library testlib;" | 5714 "library testlib;" |
5697 "main() {" | 5715 "main() {" |
5698 " return 12345;" | 5716 " return 12345;" |
5699 "}"; | 5717 "}"; |
5700 | 5718 |
5701 Dart_Handle root_lib = Dart_RootLibrary(); | 5719 Dart_Handle root_lib = Dart_RootLibrary(); |
5702 EXPECT_VALID(root_lib); | 5720 EXPECT_VALID(root_lib); |
5703 EXPECT(Dart_IsNull(root_lib)); | 5721 EXPECT(Dart_IsNull(root_lib)); |
5704 | 5722 |
5705 // Load a script. | 5723 // Load a script. |
5706 Dart_Handle url = NewString(TestCase::url()); | 5724 EXPECT_VALID(LoadScript(TestCase::url(), kScriptChars)); |
5707 Dart_Handle source = NewString(kScriptChars); | |
5708 EXPECT_VALID(Dart_LoadScript(url, Dart_Null(), source, 0, 0)); | |
5709 | 5725 |
5710 root_lib = Dart_RootLibrary(); | 5726 root_lib = Dart_RootLibrary(); |
5711 Dart_Handle lib_name = Dart_LibraryName(root_lib); | 5727 Dart_Handle lib_name = Dart_LibraryName(root_lib); |
5712 EXPECT_VALID(lib_name); | 5728 EXPECT_VALID(lib_name); |
5713 EXPECT(!Dart_IsNull(root_lib)); | 5729 EXPECT(!Dart_IsNull(root_lib)); |
5714 const char* name_cstr = ""; | 5730 const char* name_cstr = ""; |
5715 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); | 5731 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); |
5716 EXPECT_STREQ("testlib", name_cstr); | 5732 EXPECT_STREQ("testlib", name_cstr); |
5717 | 5733 |
5718 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); | 5734 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5777 default: | 5793 default: |
5778 EXPECT(false); | 5794 EXPECT(false); |
5779 return Api::NewError("invalid callback"); | 5795 return Api::NewError("invalid callback"); |
5780 } | 5796 } |
5781 index += 1; | 5797 index += 1; |
5782 return Api::Success(); | 5798 return Api::Success(); |
5783 } | 5799 } |
5784 | 5800 |
5785 TEST_CASE(LoadScript_CompileError) { | 5801 TEST_CASE(LoadScript_CompileError) { |
5786 const char* kScriptChars = ")"; | 5802 const char* kScriptChars = ")"; |
5787 Dart_Handle url = NewString(TestCase::url()); | |
5788 Dart_Handle source = NewString(kScriptChars); | |
5789 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 5803 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
5790 EXPECT_VALID(result); | 5804 EXPECT_VALID(result); |
5791 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5805 result = LoadScript(TestCase::url(), kScriptChars); |
5792 EXPECT(Dart_IsError(result)); | 5806 EXPECT(Dart_IsError(result)); |
5793 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 5807 if (!FLAG_use_dart_frontend) { |
| 5808 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
| 5809 } |
5794 } | 5810 } |
5795 | 5811 |
5796 TEST_CASE(LookupLibrary) { | 5812 TEST_CASE(LookupLibrary) { |
5797 const char* kScriptChars = | 5813 const char* kScriptChars = |
5798 "import 'library1_dart';" | 5814 "import 'library1_dart';" |
5799 "main() {}"; | 5815 "main() {}"; |
5800 const char* kLibrary1Chars = | 5816 const char* kLibrary1Chars = |
5801 "library library1_dart;" | 5817 "library library1_dart;" |
5802 "import 'library2_dart';"; | 5818 "import 'library2_dart';"; |
5803 | 5819 |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6719 const char* kScriptChars = | 6735 const char* kScriptChars = |
6720 "class Test {" | 6736 "class Test {" |
6721 " static foo() native \"SomeNativeFunction\";\n" | 6737 " static foo() native \"SomeNativeFunction\";\n" |
6722 " static bar() native \"SomeNativeFunction2\";\n" | 6738 " static bar() native \"SomeNativeFunction2\";\n" |
6723 " static baz() native \"SomeNativeFunction3\";\n" | 6739 " static baz() native \"SomeNativeFunction3\";\n" |
6724 "}"; | 6740 "}"; |
6725 Dart_Handle error = Dart_NewApiError("incoming error"); | 6741 Dart_Handle error = Dart_NewApiError("incoming error"); |
6726 Dart_Handle result; | 6742 Dart_Handle result; |
6727 | 6743 |
6728 // Load a test script. | 6744 // Load a test script. |
6729 Dart_Handle url = NewString(TestCase::url()); | 6745 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
6730 Dart_Handle source = NewString(kScriptChars); | |
6731 result = Dart_SetLibraryTagHandler(library_handler); | |
6732 EXPECT_VALID(result); | |
6733 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | |
6734 EXPECT_VALID(lib); | 6746 EXPECT_VALID(lib); |
6735 result = Dart_FinalizeLoading(false); | 6747 result = Dart_FinalizeLoading(false); |
6736 EXPECT_VALID(result); | 6748 EXPECT_VALID(result); |
6737 EXPECT(Dart_IsLibrary(lib)); | 6749 EXPECT(Dart_IsLibrary(lib)); |
6738 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL); | 6750 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL); |
6739 EXPECT_VALID(type); | 6751 EXPECT_VALID(type); |
6740 | 6752 |
6741 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); | 6753 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); |
6742 EXPECT(Dart_IsError(result)); | 6754 EXPECT(Dart_IsError(result)); |
6743 EXPECT_STREQ( | 6755 EXPECT_STREQ( |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7217 } | 7229 } |
7218 | 7230 |
7219 static Dart_Isolate RunLoopTestCallback(const char* script_name, | 7231 static Dart_Isolate RunLoopTestCallback(const char* script_name, |
7220 const char* main, | 7232 const char* main, |
7221 const char* package_root, | 7233 const char* package_root, |
7222 const char* package_config, | 7234 const char* package_config, |
7223 Dart_IsolateFlags* flags, | 7235 Dart_IsolateFlags* flags, |
7224 void* data, | 7236 void* data, |
7225 char** error) { | 7237 char** error) { |
7226 const char* kScriptChars = | 7238 const char* kScriptChars = |
7227 "import 'builtin';\n" | |
7228 "import 'dart:isolate';\n" | 7239 "import 'dart:isolate';\n" |
7229 "void main(shouldThrowException) {\n" | 7240 "void main(shouldThrowException) {\n" |
7230 " var rp = new RawReceivePort();\n" | 7241 " var rp = new RawReceivePort();\n" |
7231 " rp.handler = (msg) {\n" | 7242 " rp.handler = (msg) {\n" |
7232 " rp.close();\n" | 7243 " rp.close();\n" |
7233 " if (shouldThrowException) {\n" | 7244 " if (shouldThrowException) {\n" |
7234 " throw new Exception('ExceptionFromTimer');\n" | 7245 " throw new Exception('ExceptionFromTimer');\n" |
7235 " }\n" | 7246 " }\n" |
7236 " };\n" | 7247 " };\n" |
7237 " rp.sendPort.send(1);\n" | 7248 " rp.sendPort.send(1);\n" |
7238 "}\n"; | 7249 "}\n"; |
7239 | 7250 |
7240 if (Dart_CurrentIsolate() != NULL) { | 7251 if (Dart_CurrentIsolate() != NULL) { |
7241 Dart_ExitIsolate(); | 7252 Dart_ExitIsolate(); |
7242 } | 7253 } |
7243 Dart_Isolate isolate = TestCase::CreateTestIsolate(script_name); | 7254 Dart_Isolate isolate = TestCase::CreateTestIsolate(script_name); |
7244 ASSERT(isolate != NULL); | 7255 ASSERT(isolate != NULL); |
7245 if (Dart_IsServiceIsolate(isolate)) { | 7256 if (Dart_IsServiceIsolate(isolate)) { |
7246 return isolate; | 7257 return isolate; |
7247 } | 7258 } |
7248 Dart_EnterScope(); | 7259 Dart_EnterScope(); |
7249 Dart_Handle url = NewString(TestCase::url()); | 7260 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
7250 Dart_Handle source = NewString(kScriptChars); | |
7251 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | |
7252 EXPECT_VALID(result); | |
7253 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | |
7254 EXPECT_VALID(lib); | 7261 EXPECT_VALID(lib); |
7255 result = Dart_FinalizeLoading(false); | 7262 Dart_Handle result = Dart_FinalizeLoading(false); |
7256 EXPECT_VALID(result); | 7263 EXPECT_VALID(result); |
7257 Dart_ExitScope(); | 7264 Dart_ExitScope(); |
7258 Dart_ExitIsolate(); | 7265 Dart_ExitIsolate(); |
7259 bool retval = Dart_IsolateMakeRunnable(isolate); | 7266 bool retval = Dart_IsolateMakeRunnable(isolate); |
7260 EXPECT(retval); | 7267 EXPECT(retval); |
7261 return isolate; | 7268 return isolate; |
7262 } | 7269 } |
7263 | 7270 |
7264 // Common code for RunLoop_Success/RunLoop_Failure. | 7271 // Common code for RunLoop_Success/RunLoop_Failure. |
7265 static void RunLoopTest(bool throw_exception) { | 7272 static void RunLoopTest(bool throw_exception) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7619 " Expect.equals(3, obj.bar42(1, 1));\n" | 7626 " Expect.equals(3, obj.bar42(1, 1));\n" |
7620 " Expect.equals(6, obj.foo4(2, 2, 2));\n" | 7627 " Expect.equals(6, obj.foo4(2, 2, 2));\n" |
7621 " Expect.equals(6, obj.bar43(2, 2, 2));\n" | 7628 " Expect.equals(6, obj.bar43(2, 2, 2));\n" |
7622 "\n" | 7629 "\n" |
7623 " return 0;\n" | 7630 " return 0;\n" |
7624 "}\n"; | 7631 "}\n"; |
7625 | 7632 |
7626 Dart_Handle result; | 7633 Dart_Handle result; |
7627 | 7634 |
7628 // Load a test script. | 7635 // Load a test script. |
7629 Dart_Handle url = NewString(TestCase::url()); | 7636 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
7630 Dart_Handle source = NewString(kScriptChars); | |
7631 result = Dart_SetLibraryTagHandler(library_handler); | |
7632 EXPECT_VALID(result); | |
7633 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | |
7634 EXPECT_VALID(lib); | 7637 EXPECT_VALID(lib); |
7635 EXPECT(Dart_IsLibrary(lib)); | 7638 EXPECT(Dart_IsLibrary(lib)); |
7636 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver, NULL); | 7639 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver, NULL); |
7637 EXPECT_VALID(result); | 7640 EXPECT_VALID(result); |
7638 result = Dart_FinalizeLoading(false); | 7641 result = Dart_FinalizeLoading(false); |
7639 EXPECT_VALID(result); | 7642 EXPECT_VALID(result); |
7640 | 7643 |
7641 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7644 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
7642 EXPECT_VALID(result); | 7645 EXPECT_VALID(result); |
7643 EXPECT(Dart_IsInteger(result)); | 7646 EXPECT(Dart_IsInteger(result)); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7763 " Expect.equals(3, obj.bar42(1, 1));\n" | 7766 " Expect.equals(3, obj.bar42(1, 1));\n" |
7764 " Expect.equals(6, Test.foo4(2, 2, 2));\n" | 7767 " Expect.equals(6, Test.foo4(2, 2, 2));\n" |
7765 " Expect.equals(6, obj.bar43(2, 2, 2));\n" | 7768 " Expect.equals(6, obj.bar43(2, 2, 2));\n" |
7766 "\n" | 7769 "\n" |
7767 " return 0;\n" | 7770 " return 0;\n" |
7768 "}\n"; | 7771 "}\n"; |
7769 | 7772 |
7770 Dart_Handle result; | 7773 Dart_Handle result; |
7771 | 7774 |
7772 // Load a test script. | 7775 // Load a test script. |
7773 Dart_Handle url = NewString(TestCase::url()); | 7776 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
7774 Dart_Handle source = NewString(kScriptChars); | |
7775 result = Dart_SetLibraryTagHandler(library_handler); | |
7776 EXPECT_VALID(result); | |
7777 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | |
7778 EXPECT_VALID(lib); | 7777 EXPECT_VALID(lib); |
7779 EXPECT(Dart_IsLibrary(lib)); | 7778 EXPECT(Dart_IsLibrary(lib)); |
7780 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver, NULL); | 7779 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver, NULL); |
7781 EXPECT_VALID(result); | 7780 EXPECT_VALID(result); |
7782 result = Dart_FinalizeLoading(false); | 7781 result = Dart_FinalizeLoading(false); |
7783 EXPECT_VALID(result); | 7782 EXPECT_VALID(result); |
7784 | 7783 |
7785 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7784 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
7786 EXPECT_VALID(result); | 7785 EXPECT_VALID(result); |
7787 EXPECT(Dart_IsInteger(result)); | 7786 EXPECT(Dart_IsInteger(result)); |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9623 EXPECT_VALID(result); | 9622 EXPECT_VALID(result); |
9624 result = Dart_FinalizeLoading(false); | 9623 result = Dart_FinalizeLoading(false); |
9625 EXPECT_VALID(result); | 9624 EXPECT_VALID(result); |
9626 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9625 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
9627 EXPECT(Dart_IsError(result)); | 9626 EXPECT(Dart_IsError(result)); |
9628 } | 9627 } |
9629 | 9628 |
9630 #endif // !PRODUCT | 9629 #endif // !PRODUCT |
9631 | 9630 |
9632 } // namespace dart | 9631 } // namespace dart |
OLD | NEW |