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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "vm/compiler.h" | 6 #include "vm/compiler.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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 TEST_CASE(ErrorHandleBasics) { | 30 TEST_CASE(ErrorHandleBasics) { |
31 const char* kScriptChars = | 31 const char* kScriptChars = |
32 "void testMain() {\n" | 32 "void testMain() {\n" |
33 " throw new Exception(\"bad news\");\n" | 33 " throw new Exception(\"bad news\");\n" |
34 "}\n"; | 34 "}\n"; |
35 | 35 |
36 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 36 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
37 | 37 |
38 Dart_Handle instance = Dart_True(); | 38 Dart_Handle instance = Dart_True(); |
39 Dart_Handle error = Api::NewError("myerror"); | 39 Dart_Handle error = Api::NewError("myerror"); |
40 Dart_Handle exception = Dart_Invoke(lib, | 40 Dart_Handle exception = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
41 NewString("testMain"), | |
42 0, | |
43 NULL); | |
44 | 41 |
45 EXPECT_VALID(instance); | 42 EXPECT_VALID(instance); |
46 EXPECT(Dart_IsError(error)); | 43 EXPECT(Dart_IsError(error)); |
47 EXPECT(Dart_IsError(exception)); | 44 EXPECT(Dart_IsError(exception)); |
48 | 45 |
49 EXPECT(!Dart_ErrorHasException(instance)); | 46 EXPECT(!Dart_ErrorHasException(instance)); |
50 EXPECT(!Dart_ErrorHasException(error)); | 47 EXPECT(!Dart_ErrorHasException(error)); |
51 EXPECT(Dart_ErrorHasException(exception)); | 48 EXPECT(Dart_ErrorHasException(exception)); |
52 | 49 |
53 EXPECT_STREQ("", Dart_GetError(instance)); | 50 EXPECT_STREQ("", Dart_GetError(instance)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 87 |
91 Dart_Handle function_name; | 88 Dart_Handle function_name; |
92 Dart_Handle script_url; | 89 Dart_Handle script_url; |
93 intptr_t line_number = 0; | 90 intptr_t line_number = 0; |
94 intptr_t column_number = 0; | 91 intptr_t column_number = 0; |
95 const char* cstr = ""; | 92 const char* cstr = ""; |
96 | 93 |
97 Dart_ActivationFrame frame; | 94 Dart_ActivationFrame frame; |
98 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 95 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
99 EXPECT_VALID(result); | 96 EXPECT_VALID(result); |
100 result = Dart_ActivationFrameInfo( | 97 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
101 frame, &function_name, &script_url, &line_number, &column_number); | 98 &line_number, &column_number); |
102 EXPECT_VALID(result); | 99 EXPECT_VALID(result); |
103 Dart_StringToCString(function_name, &cstr); | 100 Dart_StringToCString(function_name, &cstr); |
104 EXPECT_STREQ("bar", cstr); | 101 EXPECT_STREQ("bar", cstr); |
105 Dart_StringToCString(script_url, &cstr); | 102 Dart_StringToCString(script_url, &cstr); |
106 EXPECT_STREQ("test-lib", cstr); | 103 EXPECT_STREQ("test-lib", cstr); |
107 EXPECT_EQ(1, line_number); | 104 EXPECT_EQ(1, line_number); |
108 EXPECT_EQ(10, column_number); | 105 EXPECT_EQ(10, column_number); |
109 | 106 |
110 result = Dart_GetActivationFrame(stacktrace, 1, &frame); | 107 result = Dart_GetActivationFrame(stacktrace, 1, &frame); |
111 EXPECT_VALID(result); | 108 EXPECT_VALID(result); |
112 result = Dart_ActivationFrameInfo( | 109 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
113 frame, &function_name, &script_url, &line_number, &column_number); | 110 &line_number, &column_number); |
114 EXPECT_VALID(result); | 111 EXPECT_VALID(result); |
115 Dart_StringToCString(function_name, &cstr); | 112 Dart_StringToCString(function_name, &cstr); |
116 EXPECT_STREQ("foo", cstr); | 113 EXPECT_STREQ("foo", cstr); |
117 Dart_StringToCString(script_url, &cstr); | 114 Dart_StringToCString(script_url, &cstr); |
118 EXPECT_STREQ("test-lib", cstr); | 115 EXPECT_STREQ("test-lib", cstr); |
119 EXPECT_EQ(2, line_number); | 116 EXPECT_EQ(2, line_number); |
120 EXPECT_EQ(10, column_number); | 117 EXPECT_EQ(10, column_number); |
121 | 118 |
122 result = Dart_GetActivationFrame(stacktrace, 2, &frame); | 119 result = Dart_GetActivationFrame(stacktrace, 2, &frame); |
123 EXPECT_VALID(result); | 120 EXPECT_VALID(result); |
124 result = Dart_ActivationFrameInfo( | 121 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
125 frame, &function_name, &script_url, &line_number, &column_number); | 122 &line_number, &column_number); |
126 EXPECT_VALID(result); | 123 EXPECT_VALID(result); |
127 Dart_StringToCString(function_name, &cstr); | 124 Dart_StringToCString(function_name, &cstr); |
128 EXPECT_STREQ("testMain", cstr); | 125 EXPECT_STREQ("testMain", cstr); |
129 Dart_StringToCString(script_url, &cstr); | 126 Dart_StringToCString(script_url, &cstr); |
130 EXPECT_STREQ("test-lib", cstr); | 127 EXPECT_STREQ("test-lib", cstr); |
131 EXPECT_EQ(3, line_number); | 128 EXPECT_EQ(3, line_number); |
132 EXPECT_EQ(15, column_number); | 129 EXPECT_EQ(15, column_number); |
133 | 130 |
134 // Out-of-bounds frames. | 131 // Out-of-bounds frames. |
135 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 132 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
(...skipping 28 matching lines...) Expand all Loading... |
164 Dart_Handle function_name; | 161 Dart_Handle function_name; |
165 Dart_Handle script_url; | 162 Dart_Handle script_url; |
166 intptr_t line_number = 0; | 163 intptr_t line_number = 0; |
167 intptr_t column_number = 0; | 164 intptr_t column_number = 0; |
168 const char* cstr = ""; | 165 const char* cstr = ""; |
169 | 166 |
170 // Top frame at positioned at throw. | 167 // Top frame at positioned at throw. |
171 Dart_ActivationFrame frame; | 168 Dart_ActivationFrame frame; |
172 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 169 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
173 EXPECT_VALID(result); | 170 EXPECT_VALID(result); |
174 result = Dart_ActivationFrameInfo( | 171 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
175 frame, &function_name, &script_url, &line_number, &column_number); | 172 &line_number, &column_number); |
176 EXPECT_VALID(result); | 173 EXPECT_VALID(result); |
177 Dart_StringToCString(function_name, &cstr); | 174 Dart_StringToCString(function_name, &cstr); |
178 EXPECT_STREQ("foo", cstr); | 175 EXPECT_STREQ("foo", cstr); |
179 Dart_StringToCString(script_url, &cstr); | 176 Dart_StringToCString(script_url, &cstr); |
180 EXPECT_STREQ("test-lib", cstr); | 177 EXPECT_STREQ("test-lib", cstr); |
181 EXPECT_EQ(1, line_number); | 178 EXPECT_EQ(1, line_number); |
182 EXPECT_EQ(20, column_number); | 179 EXPECT_EQ(20, column_number); |
183 | 180 |
184 // Middle frames positioned at the recursive call. | 181 // Middle frames positioned at the recursive call. |
185 for (intptr_t frame_index = 1; | 182 for (intptr_t frame_index = 1; frame_index < (frame_count - 1); |
186 frame_index < (frame_count - 1); | |
187 frame_index++) { | 183 frame_index++) { |
188 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); | 184 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); |
189 EXPECT_VALID(result); | 185 EXPECT_VALID(result); |
190 result = Dart_ActivationFrameInfo( | 186 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
191 frame, &function_name, &script_url, &line_number, &column_number); | 187 &line_number, &column_number); |
192 EXPECT_VALID(result); | 188 EXPECT_VALID(result); |
193 Dart_StringToCString(function_name, &cstr); | 189 Dart_StringToCString(function_name, &cstr); |
194 EXPECT_STREQ("foo", cstr); | 190 EXPECT_STREQ("foo", cstr); |
195 Dart_StringToCString(script_url, &cstr); | 191 Dart_StringToCString(script_url, &cstr); |
196 EXPECT_STREQ("test-lib", cstr); | 192 EXPECT_STREQ("test-lib", cstr); |
197 EXPECT_EQ(1, line_number); | 193 EXPECT_EQ(1, line_number); |
198 EXPECT_EQ(40, column_number); | 194 EXPECT_EQ(40, column_number); |
199 } | 195 } |
200 | 196 |
201 // Bottom frame positioned at testMain(). | 197 // Bottom frame positioned at testMain(). |
202 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); | 198 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); |
203 EXPECT_VALID(result); | 199 EXPECT_VALID(result); |
204 result = Dart_ActivationFrameInfo( | 200 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
205 frame, &function_name, &script_url, &line_number, &column_number); | 201 &line_number, &column_number); |
206 EXPECT_VALID(result); | 202 EXPECT_VALID(result); |
207 Dart_StringToCString(function_name, &cstr); | 203 Dart_StringToCString(function_name, &cstr); |
208 EXPECT_STREQ("testMain", cstr); | 204 EXPECT_STREQ("testMain", cstr); |
209 Dart_StringToCString(script_url, &cstr); | 205 Dart_StringToCString(script_url, &cstr); |
210 EXPECT_STREQ("test-lib", cstr); | 206 EXPECT_STREQ("test-lib", cstr); |
211 EXPECT_EQ(2, line_number); | 207 EXPECT_EQ(2, line_number); |
212 EXPECT_EQ(15, column_number); | 208 EXPECT_EQ(15, column_number); |
213 | 209 |
214 // Out-of-bounds frames. | 210 // Out-of-bounds frames. |
215 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 211 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
(...skipping 27 matching lines...) Expand all Loading... |
243 Dart_Handle function_name; | 239 Dart_Handle function_name; |
244 Dart_Handle script_url; | 240 Dart_Handle script_url; |
245 intptr_t line_number = 0; | 241 intptr_t line_number = 0; |
246 intptr_t column_number = 0; | 242 intptr_t column_number = 0; |
247 const char* cstr = ""; | 243 const char* cstr = ""; |
248 | 244 |
249 // Top frame at recursive call. | 245 // Top frame at recursive call. |
250 Dart_ActivationFrame frame; | 246 Dart_ActivationFrame frame; |
251 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 247 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
252 EXPECT_VALID(result); | 248 EXPECT_VALID(result); |
253 result = Dart_ActivationFrameInfo( | 249 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
254 frame, &function_name, &script_url, &line_number, &column_number); | 250 &line_number, &column_number); |
255 EXPECT_VALID(result); | 251 EXPECT_VALID(result); |
256 Dart_StringToCString(function_name, &cstr); | 252 Dart_StringToCString(function_name, &cstr); |
257 EXPECT_STREQ("C.foo", cstr); | 253 EXPECT_STREQ("C.foo", cstr); |
258 Dart_StringToCString(script_url, &cstr); | 254 Dart_StringToCString(script_url, &cstr); |
259 EXPECT_STREQ("test-lib", cstr); | 255 EXPECT_STREQ("test-lib", cstr); |
260 EXPECT_EQ(2, line_number); | 256 EXPECT_EQ(2, line_number); |
261 EXPECT_EQ(13, column_number); | 257 EXPECT_EQ(13, column_number); |
262 | 258 |
263 // Out-of-bounds frames. | 259 // Out-of-bounds frames. |
264 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 260 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 Dart_Handle function_name; | 300 Dart_Handle function_name; |
305 Dart_Handle script_url; | 301 Dart_Handle script_url; |
306 intptr_t line_number = 0; | 302 intptr_t line_number = 0; |
307 intptr_t column_number = 0; | 303 intptr_t column_number = 0; |
308 const char* cstr = ""; | 304 const char* cstr = ""; |
309 | 305 |
310 // Top frame is inspectStack(). | 306 // Top frame is inspectStack(). |
311 Dart_ActivationFrame frame; | 307 Dart_ActivationFrame frame; |
312 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 308 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
313 EXPECT_VALID(result); | 309 EXPECT_VALID(result); |
314 result = Dart_ActivationFrameInfo( | 310 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
315 frame, &function_name, &script_url, &line_number, &column_number); | 311 &line_number, &column_number); |
316 EXPECT_VALID(result); | 312 EXPECT_VALID(result); |
317 Dart_StringToCString(function_name, &cstr); | 313 Dart_StringToCString(function_name, &cstr); |
318 EXPECT_STREQ("inspectStack", cstr); | 314 EXPECT_STREQ("inspectStack", cstr); |
319 Dart_StringToCString(script_url, &cstr); | 315 Dart_StringToCString(script_url, &cstr); |
320 EXPECT_STREQ("test-lib", cstr); | 316 EXPECT_STREQ("test-lib", cstr); |
321 EXPECT_EQ(1, line_number); | 317 EXPECT_EQ(1, line_number); |
322 EXPECT_EQ(47, column_number); | 318 EXPECT_EQ(47, column_number); |
323 | 319 |
324 // Second frame is foo() positioned at call to inspectStack(). | 320 // Second frame is foo() positioned at call to inspectStack(). |
325 result = Dart_GetActivationFrame(stacktrace, 1, &frame); | 321 result = Dart_GetActivationFrame(stacktrace, 1, &frame); |
326 EXPECT_VALID(result); | 322 EXPECT_VALID(result); |
327 result = Dart_ActivationFrameInfo( | 323 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
328 frame, &function_name, &script_url, &line_number, &column_number); | 324 &line_number, &column_number); |
329 EXPECT_VALID(result); | 325 EXPECT_VALID(result); |
330 Dart_StringToCString(function_name, &cstr); | 326 Dart_StringToCString(function_name, &cstr); |
331 EXPECT_STREQ("foo", cstr); | 327 EXPECT_STREQ("foo", cstr); |
332 Dart_StringToCString(script_url, &cstr); | 328 Dart_StringToCString(script_url, &cstr); |
333 EXPECT_STREQ("test-lib", cstr); | 329 EXPECT_STREQ("test-lib", cstr); |
334 EXPECT_EQ(2, line_number); | 330 EXPECT_EQ(2, line_number); |
335 EXPECT_EQ(20, column_number); | 331 EXPECT_EQ(20, column_number); |
336 | 332 |
337 // Middle frames positioned at the recursive call. | 333 // Middle frames positioned at the recursive call. |
338 for (intptr_t frame_index = 2; | 334 for (intptr_t frame_index = 2; frame_index < (frame_count - 1); |
339 frame_index < (frame_count - 1); | |
340 frame_index++) { | 335 frame_index++) { |
341 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); | 336 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); |
342 EXPECT_VALID(result); | 337 EXPECT_VALID(result); |
343 result = Dart_ActivationFrameInfo( | 338 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
344 frame, &function_name, &script_url, &line_number, &column_number); | 339 &line_number, &column_number); |
345 EXPECT_VALID(result); | 340 EXPECT_VALID(result); |
346 Dart_StringToCString(function_name, &cstr); | 341 Dart_StringToCString(function_name, &cstr); |
347 EXPECT_STREQ("foo", cstr); | 342 EXPECT_STREQ("foo", cstr); |
348 Dart_StringToCString(script_url, &cstr); | 343 Dart_StringToCString(script_url, &cstr); |
349 EXPECT_STREQ("test-lib", cstr); | 344 EXPECT_STREQ("test-lib", cstr); |
350 EXPECT_EQ(2, line_number); | 345 EXPECT_EQ(2, line_number); |
351 EXPECT_EQ(37, column_number); | 346 EXPECT_EQ(37, column_number); |
352 } | 347 } |
353 | 348 |
354 // Bottom frame positioned at testMain(). | 349 // Bottom frame positioned at testMain(). |
355 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); | 350 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); |
356 EXPECT_VALID(result); | 351 EXPECT_VALID(result); |
357 result = Dart_ActivationFrameInfo( | 352 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
358 frame, &function_name, &script_url, &line_number, &column_number); | 353 &line_number, &column_number); |
359 EXPECT_VALID(result); | 354 EXPECT_VALID(result); |
360 Dart_StringToCString(function_name, &cstr); | 355 Dart_StringToCString(function_name, &cstr); |
361 EXPECT_STREQ("testMain", cstr); | 356 EXPECT_STREQ("testMain", cstr); |
362 Dart_StringToCString(script_url, &cstr); | 357 Dart_StringToCString(script_url, &cstr); |
363 EXPECT_STREQ("test-lib", cstr); | 358 EXPECT_STREQ("test-lib", cstr); |
364 EXPECT_EQ(3, line_number); | 359 EXPECT_EQ(3, line_number); |
365 EXPECT_EQ(15, column_number); | 360 EXPECT_EQ(15, column_number); |
366 | 361 |
367 // Out-of-bounds frames. | 362 // Out-of-bounds frames. |
368 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 363 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
369 EXPECT(Dart_IsError(result)); | 364 EXPECT(Dart_IsError(result)); |
370 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 365 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
371 EXPECT(Dart_IsError(result)); | 366 EXPECT(Dart_IsError(result)); |
372 | 367 |
373 Dart_SetReturnValue(args, Dart_NewInteger(42)); | 368 Dart_SetReturnValue(args, Dart_NewInteger(42)); |
374 Dart_ExitScope(); | 369 Dart_ExitScope(); |
375 } | 370 } |
376 | 371 |
377 | 372 |
378 static Dart_NativeFunction CurrentStackTraceNativeLookup( | 373 static Dart_NativeFunction CurrentStackTraceNativeLookup( |
379 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 374 Dart_Handle name, |
| 375 int argument_count, |
| 376 bool* auto_setup_scope) { |
380 ASSERT(auto_setup_scope != NULL); | 377 ASSERT(auto_setup_scope != NULL); |
381 *auto_setup_scope = true; | 378 *auto_setup_scope = true; |
382 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); | 379 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); |
383 } | 380 } |
384 | 381 |
385 | 382 |
386 TEST_CASE(CurrentStacktraceInfo) { | 383 TEST_CASE(CurrentStacktraceInfo) { |
387 const char* kScriptChars = | 384 const char* kScriptChars = |
388 "inspectStack() native 'CurrentStackTraceNatve';\n" | 385 "inspectStack() native 'CurrentStackTraceNatve';\n" |
389 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" | 386 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" |
390 "testMain() => foo(50);\n"; | 387 "testMain() => foo(50);\n"; |
391 | 388 |
392 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 389 Dart_Handle lib = |
393 &CurrentStackTraceNativeLookup); | 390 TestCase::LoadTestScript(kScriptChars, &CurrentStackTraceNativeLookup); |
394 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 391 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
395 EXPECT_VALID(result); | 392 EXPECT_VALID(result); |
396 EXPECT(Dart_IsInteger(result)); | 393 EXPECT(Dart_IsInteger(result)); |
397 int64_t value = 0; | 394 int64_t value = 0; |
398 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 395 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
399 EXPECT_EQ(42, value); | 396 EXPECT_EQ(42, value); |
400 } | 397 } |
401 | 398 |
402 | 399 |
403 #endif // !PRODUCT | 400 #endif // !PRODUCT |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); | 451 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); |
455 } | 452 } |
456 | 453 |
457 | 454 |
458 TEST_CASE(UnhandleExceptionError) { | 455 TEST_CASE(UnhandleExceptionError) { |
459 const char* exception_cstr = ""; | 456 const char* exception_cstr = ""; |
460 | 457 |
461 // Test with an API Error. | 458 // Test with an API Error. |
462 const char* kApiError = "Api Error Exception Test."; | 459 const char* kApiError = "Api Error Exception Test."; |
463 Dart_Handle api_error = Api::NewHandle( | 460 Dart_Handle api_error = Api::NewHandle( |
464 thread, | 461 thread, ApiError::New(String::Handle(String::New(kApiError)))); |
465 ApiError::New(String::Handle(String::New(kApiError)))); | |
466 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); | 462 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); |
467 EXPECT(!Dart_IsApiError(exception_error)); | 463 EXPECT(!Dart_IsApiError(exception_error)); |
468 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 464 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
469 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 465 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
470 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 466 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
471 &exception_cstr)); | 467 &exception_cstr)); |
472 EXPECT_STREQ(kApiError, exception_cstr); | 468 EXPECT_STREQ(kApiError, exception_cstr); |
473 | 469 |
474 // Test with a Compilation Error. | 470 // Test with a Compilation Error. |
475 const char* kCompileError = "CompileError Exception Test."; | 471 const char* kCompileError = "CompileError Exception Test."; |
476 const String& compile_message = | 472 const String& compile_message = String::Handle(String::New(kCompileError)); |
477 String::Handle(String::New(kCompileError)); | |
478 Dart_Handle compile_error = | 473 Dart_Handle compile_error = |
479 Api::NewHandle(thread, LanguageError::New(compile_message)); | 474 Api::NewHandle(thread, LanguageError::New(compile_message)); |
480 exception_error = Dart_NewUnhandledExceptionError(compile_error); | 475 exception_error = Dart_NewUnhandledExceptionError(compile_error); |
481 EXPECT(!Dart_IsApiError(exception_error)); | 476 EXPECT(!Dart_IsApiError(exception_error)); |
482 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 477 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
483 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 478 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
484 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 479 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
485 &exception_cstr)); | 480 &exception_cstr)); |
486 EXPECT_STREQ(kCompileError, exception_cstr); | 481 EXPECT_STREQ(kCompileError, exception_cstr); |
487 | 482 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 UNREACHABLE(); | 522 UNREACHABLE(); |
528 } else { | 523 } else { |
529 result = Dart_PropagateError(result); | 524 result = Dart_PropagateError(result); |
530 EXPECT_VALID(result); // We do not expect to reach here. | 525 EXPECT_VALID(result); // We do not expect to reach here. |
531 UNREACHABLE(); | 526 UNREACHABLE(); |
532 } | 527 } |
533 } | 528 } |
534 | 529 |
535 | 530 |
536 static Dart_NativeFunction PropagateError_native_lookup( | 531 static Dart_NativeFunction PropagateError_native_lookup( |
537 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 532 Dart_Handle name, |
| 533 int argument_count, |
| 534 bool* auto_setup_scope) { |
538 ASSERT(auto_setup_scope != NULL); | 535 ASSERT(auto_setup_scope != NULL); |
539 *auto_setup_scope = true; | 536 *auto_setup_scope = true; |
540 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); | 537 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); |
541 } | 538 } |
542 | 539 |
543 | 540 |
544 TEST_CASE(Dart_PropagateError) { | 541 TEST_CASE(Dart_PropagateError) { |
545 const char* kScriptChars = | 542 const char* kScriptChars = |
546 "raiseCompileError() {\n" | 543 "raiseCompileError() {\n" |
547 " return missing_semicolon\n" | 544 " return missing_semicolon\n" |
548 "}\n" | 545 "}\n" |
549 "\n" | 546 "\n" |
550 "void throwException() {\n" | 547 "void throwException() {\n" |
551 " throw new Exception('myException');\n" | 548 " throw new Exception('myException');\n" |
552 "}\n" | 549 "}\n" |
553 "\n" | 550 "\n" |
554 "void nativeFunc(closure) native 'Test_nativeFunc';\n" | 551 "void nativeFunc(closure) native 'Test_nativeFunc';\n" |
555 "\n" | 552 "\n" |
556 "void Func1() {\n" | 553 "void Func1() {\n" |
557 " nativeFunc(() => raiseCompileError());\n" | 554 " nativeFunc(() => raiseCompileError());\n" |
558 "}\n" | 555 "}\n" |
559 "\n" | 556 "\n" |
560 "void Func2() {\n" | 557 "void Func2() {\n" |
561 " nativeFunc(() => throwException());\n" | 558 " nativeFunc(() => throwException());\n" |
562 "}\n"; | 559 "}\n"; |
563 Dart_Handle lib = TestCase::LoadTestScript( | 560 Dart_Handle lib = |
564 kScriptChars, &PropagateError_native_lookup); | 561 TestCase::LoadTestScript(kScriptChars, &PropagateError_native_lookup); |
565 Dart_Handle result; | 562 Dart_Handle result; |
566 | 563 |
567 // Use Dart_PropagateError to propagate the error. | 564 // Use Dart_PropagateError to propagate the error. |
568 use_throw_exception = false; | 565 use_throw_exception = false; |
569 use_set_return = false; | 566 use_set_return = false; |
570 | 567 |
571 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); | 568 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); |
572 EXPECT(Dart_IsError(result)); | 569 EXPECT(Dart_IsError(result)); |
573 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); | 570 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); |
574 | 571 |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 EXPECT_VALID(result); | 1036 EXPECT_VALID(result); |
1040 int64_t value; | 1037 int64_t value; |
1041 result = Dart_IntegerToInt64(result, &value); | 1038 result = Dart_IntegerToInt64(result, &value); |
1042 EXPECT_VALID(result); | 1039 EXPECT_VALID(result); |
1043 EXPECT_EQ(i, value); | 1040 EXPECT_EQ(i, value); |
1044 } | 1041 } |
1045 } | 1042 } |
1046 | 1043 |
1047 | 1044 |
1048 TEST_CASE(IsString) { | 1045 TEST_CASE(IsString) { |
1049 uint8_t latin1[] = { 'o', 'n', 'e', 0xC2, 0xA2 }; | 1046 uint8_t latin1[] = {'o', 'n', 'e', 0xC2, 0xA2}; |
1050 | 1047 |
1051 Dart_Handle latin1str = Dart_NewStringFromUTF8(latin1, ARRAY_SIZE(latin1)); | 1048 Dart_Handle latin1str = Dart_NewStringFromUTF8(latin1, ARRAY_SIZE(latin1)); |
1052 EXPECT_VALID(latin1str); | 1049 EXPECT_VALID(latin1str); |
1053 EXPECT(Dart_IsString(latin1str)); | 1050 EXPECT(Dart_IsString(latin1str)); |
1054 EXPECT(Dart_IsStringLatin1(latin1str)); | 1051 EXPECT(Dart_IsStringLatin1(latin1str)); |
1055 EXPECT(!Dart_IsExternalString(latin1str)); | 1052 EXPECT(!Dart_IsExternalString(latin1str)); |
1056 intptr_t len = -1; | 1053 intptr_t len = -1; |
1057 EXPECT_VALID(Dart_StringLength(latin1str, &len)); | 1054 EXPECT_VALID(Dart_StringLength(latin1str, &len)); |
1058 EXPECT_EQ(4, len); | 1055 EXPECT_EQ(4, len); |
1059 intptr_t char_size; | 1056 intptr_t char_size; |
1060 intptr_t str_len; | 1057 intptr_t str_len; |
1061 void* peer; | 1058 void* peer; |
1062 EXPECT_VALID(Dart_StringGetProperties(latin1str, | 1059 EXPECT_VALID( |
1063 &char_size, | 1060 Dart_StringGetProperties(latin1str, &char_size, &str_len, &peer)); |
1064 &str_len, | |
1065 &peer)); | |
1066 EXPECT_EQ(1, char_size); | 1061 EXPECT_EQ(1, char_size); |
1067 EXPECT_EQ(4, str_len); | 1062 EXPECT_EQ(4, str_len); |
1068 EXPECT(!peer); | 1063 EXPECT(!peer); |
1069 | 1064 |
1070 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; | 1065 uint8_t data8[] = {'o', 'n', 'e', 0x7F}; |
1071 | 1066 |
1072 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); | 1067 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); |
1073 EXPECT_VALID(str8); | 1068 EXPECT_VALID(str8); |
1074 EXPECT(Dart_IsString(str8)); | 1069 EXPECT(Dart_IsString(str8)); |
1075 EXPECT(Dart_IsStringLatin1(str8)); | 1070 EXPECT(Dart_IsStringLatin1(str8)); |
1076 EXPECT(!Dart_IsExternalString(str8)); | 1071 EXPECT(!Dart_IsExternalString(str8)); |
1077 | 1072 |
1078 uint8_t latin1_array[] = {0, 0, 0, 0, 0}; | 1073 uint8_t latin1_array[] = {0, 0, 0, 0, 0}; |
1079 len = 5; | 1074 len = 5; |
1080 Dart_Handle result = Dart_StringToLatin1(str8, latin1_array, &len); | 1075 Dart_Handle result = Dart_StringToLatin1(str8, latin1_array, &len); |
1081 EXPECT_VALID(result); | 1076 EXPECT_VALID(result); |
1082 EXPECT_EQ(4, len); | 1077 EXPECT_EQ(4, len); |
1083 EXPECT(latin1_array != NULL); | 1078 EXPECT(latin1_array != NULL); |
1084 for (intptr_t i = 0; i < len; i++) { | 1079 for (intptr_t i = 0; i < len; i++) { |
1085 EXPECT_EQ(data8[i], latin1_array[i]); | 1080 EXPECT_EQ(data8[i], latin1_array[i]); |
1086 } | 1081 } |
1087 | 1082 |
1088 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), | 1083 Dart_Handle ext8 = |
1089 data8, NULL); | 1084 Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), data8, NULL); |
1090 EXPECT_VALID(ext8); | 1085 EXPECT_VALID(ext8); |
1091 EXPECT(Dart_IsString(ext8)); | 1086 EXPECT(Dart_IsString(ext8)); |
1092 EXPECT(Dart_IsExternalString(ext8)); | 1087 EXPECT(Dart_IsExternalString(ext8)); |
1093 EXPECT_VALID(Dart_StringGetProperties(ext8, | 1088 EXPECT_VALID(Dart_StringGetProperties(ext8, &char_size, &str_len, &peer)); |
1094 &char_size, | |
1095 &str_len, | |
1096 &peer)); | |
1097 EXPECT_EQ(1, char_size); | 1089 EXPECT_EQ(1, char_size); |
1098 EXPECT_EQ(4, str_len); | 1090 EXPECT_EQ(4, str_len); |
1099 EXPECT_EQ(data8, peer); | 1091 EXPECT_EQ(data8, peer); |
1100 | 1092 |
1101 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; | 1093 uint16_t data16[] = {'t', 'w', 'o', 0xFFFF}; |
1102 | 1094 |
1103 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); | 1095 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); |
1104 EXPECT_VALID(str16); | 1096 EXPECT_VALID(str16); |
1105 EXPECT(Dart_IsString(str16)); | 1097 EXPECT(Dart_IsString(str16)); |
1106 EXPECT(!Dart_IsStringLatin1(str16)); | 1098 EXPECT(!Dart_IsStringLatin1(str16)); |
1107 EXPECT(!Dart_IsExternalString(str16)); | 1099 EXPECT(!Dart_IsExternalString(str16)); |
1108 EXPECT_VALID(Dart_StringGetProperties(str16, | 1100 EXPECT_VALID(Dart_StringGetProperties(str16, &char_size, &str_len, &peer)); |
1109 &char_size, | |
1110 &str_len, | |
1111 &peer)); | |
1112 EXPECT_EQ(2, char_size); | 1101 EXPECT_EQ(2, char_size); |
1113 EXPECT_EQ(4, str_len); | 1102 EXPECT_EQ(4, str_len); |
1114 EXPECT(!peer); | 1103 EXPECT(!peer); |
1115 | 1104 |
1116 Dart_Handle ext16 = Dart_NewExternalUTF16String(data16, ARRAY_SIZE(data16), | 1105 Dart_Handle ext16 = |
1117 data16, NULL); | 1106 Dart_NewExternalUTF16String(data16, ARRAY_SIZE(data16), data16, NULL); |
1118 EXPECT_VALID(ext16); | 1107 EXPECT_VALID(ext16); |
1119 EXPECT(Dart_IsString(ext16)); | 1108 EXPECT(Dart_IsString(ext16)); |
1120 EXPECT(Dart_IsExternalString(ext16)); | 1109 EXPECT(Dart_IsExternalString(ext16)); |
1121 EXPECT_VALID(Dart_StringGetProperties(ext16, | 1110 EXPECT_VALID(Dart_StringGetProperties(ext16, &char_size, &str_len, &peer)); |
1122 &char_size, | |
1123 &str_len, | |
1124 &peer)); | |
1125 EXPECT_EQ(2, char_size); | 1111 EXPECT_EQ(2, char_size); |
1126 EXPECT_EQ(4, str_len); | 1112 EXPECT_EQ(4, str_len); |
1127 EXPECT_EQ(data16, peer); | 1113 EXPECT_EQ(data16, peer); |
1128 | 1114 |
1129 int32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; | 1115 int32_t data32[] = {'f', 'o', 'u', 'r', 0x10FFFF}; |
1130 | 1116 |
1131 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); | 1117 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); |
1132 EXPECT_VALID(str32); | 1118 EXPECT_VALID(str32); |
1133 EXPECT(Dart_IsString(str32)); | 1119 EXPECT(Dart_IsString(str32)); |
1134 EXPECT(!Dart_IsExternalString(str32)); | 1120 EXPECT(!Dart_IsExternalString(str32)); |
1135 } | 1121 } |
1136 | 1122 |
1137 | 1123 |
1138 TEST_CASE(NewString) { | 1124 TEST_CASE(NewString) { |
1139 const char* ascii = "string"; | 1125 const char* ascii = "string"; |
1140 Dart_Handle ascii_str = NewString(ascii); | 1126 Dart_Handle ascii_str = NewString(ascii); |
1141 EXPECT_VALID(ascii_str); | 1127 EXPECT_VALID(ascii_str); |
1142 EXPECT(Dart_IsString(ascii_str)); | 1128 EXPECT(Dart_IsString(ascii_str)); |
1143 | 1129 |
1144 const char* null = NULL; | 1130 const char* null = NULL; |
1145 Dart_Handle null_str = NewString(null); | 1131 Dart_Handle null_str = NewString(null); |
1146 EXPECT(Dart_IsError(null_str)); | 1132 EXPECT(Dart_IsError(null_str)); |
1147 | 1133 |
1148 uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. | 1134 uint8_t data[] = {0xE4, 0xBA, 0x8c}; // U+4E8C. |
1149 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | 1135 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); |
1150 EXPECT_VALID(utf8_str); | 1136 EXPECT_VALID(utf8_str); |
1151 EXPECT(Dart_IsString(utf8_str)); | 1137 EXPECT(Dart_IsString(utf8_str)); |
1152 | 1138 |
1153 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. | 1139 uint8_t invalid[] = {0xE4, 0xBA}; // underflow. |
1154 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, | 1140 Dart_Handle invalid_str = |
1155 ARRAY_SIZE(invalid)); | 1141 Dart_NewStringFromUTF8(invalid, ARRAY_SIZE(invalid)); |
1156 EXPECT(Dart_IsError(invalid_str)); | 1142 EXPECT(Dart_IsError(invalid_str)); |
1157 } | 1143 } |
1158 | 1144 |
1159 | 1145 |
1160 TEST_CASE(MalformedStringToUTF8) { | 1146 TEST_CASE(MalformedStringToUTF8) { |
1161 // 1D11E = treble clef | 1147 // 1D11E = treble clef |
1162 // [0] should be high surrogate D834 | 1148 // [0] should be high surrogate D834 |
1163 // [1] should be low surrogate DD1E | 1149 // [1] should be low surrogate DD1E |
1164 // Strings are allowed to have individual or out of order surrogates, even | 1150 // Strings are allowed to have individual or out of order surrogates, even |
1165 // if that doesn't make sense as renderable characters. | 1151 // if that doesn't make sense as renderable characters. |
(...skipping 19 matching lines...) Expand all Loading... |
1185 EXPECT_EQ(180, static_cast<intptr_t>(utf8_encoded[1])); | 1171 EXPECT_EQ(180, static_cast<intptr_t>(utf8_encoded[1])); |
1186 EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2])); | 1172 EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2])); |
1187 | 1173 |
1188 Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length); | 1174 Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length); |
1189 EXPECT_VALID(str2); // Standalone low surrogate, but still valid | 1175 EXPECT_VALID(str2); // Standalone low surrogate, but still valid |
1190 | 1176 |
1191 Dart_Handle reversed = Dart_Invoke(lib, NewString("reversed"), 0, NULL); | 1177 Dart_Handle reversed = Dart_Invoke(lib, NewString("reversed"), 0, NULL); |
1192 EXPECT_VALID(reversed); // This is also allowed. | 1178 EXPECT_VALID(reversed); // This is also allowed. |
1193 uint8_t* utf8_encoded_reversed = NULL; | 1179 uint8_t* utf8_encoded_reversed = NULL; |
1194 intptr_t utf8_length_reversed = 0; | 1180 intptr_t utf8_length_reversed = 0; |
1195 result = Dart_StringToUTF8(reversed, | 1181 result = Dart_StringToUTF8(reversed, &utf8_encoded_reversed, |
1196 &utf8_encoded_reversed, &utf8_length_reversed); | 1182 &utf8_length_reversed); |
1197 EXPECT_VALID(result); | 1183 EXPECT_VALID(result); |
1198 EXPECT_EQ(6, utf8_length_reversed); | 1184 EXPECT_EQ(6, utf8_length_reversed); |
1199 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; | 1185 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; |
1200 for (int i = 0; i < 6; i++) { | 1186 for (int i = 0; i < 6; i++) { |
1201 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); | 1187 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); |
1202 } | 1188 } |
1203 } | 1189 } |
1204 | 1190 |
1205 | 1191 |
1206 // Helper class to ensure new gen GC is triggered without any side effects. | 1192 // Helper class to ensure new gen GC is triggered without any side effects. |
(...skipping 23 matching lines...) Expand all Loading... |
1230 } | 1216 } |
1231 | 1217 |
1232 | 1218 |
1233 TEST_CASE(ExternalStringCallback) { | 1219 TEST_CASE(ExternalStringCallback) { |
1234 int peer8 = 40; | 1220 int peer8 = 40; |
1235 int peer16 = 41; | 1221 int peer16 = 41; |
1236 | 1222 |
1237 { | 1223 { |
1238 Dart_EnterScope(); | 1224 Dart_EnterScope(); |
1239 | 1225 |
1240 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; | 1226 uint8_t data8[] = {'h', 'e', 'l', 'l', 'o'}; |
1241 Dart_Handle obj8 = Dart_NewExternalLatin1String( | 1227 Dart_Handle obj8 = Dart_NewExternalLatin1String( |
1242 data8, | 1228 data8, ARRAY_SIZE(data8), &peer8, ExternalStringCallbackFinalizer); |
1243 ARRAY_SIZE(data8), | |
1244 &peer8, | |
1245 ExternalStringCallbackFinalizer); | |
1246 EXPECT_VALID(obj8); | 1229 EXPECT_VALID(obj8); |
1247 | 1230 |
1248 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' }; | 1231 uint16_t data16[] = {'h', 'e', 'l', 'l', 'o'}; |
1249 Dart_Handle obj16 = Dart_NewExternalUTF16String( | 1232 Dart_Handle obj16 = Dart_NewExternalUTF16String( |
1250 data16, | 1233 data16, ARRAY_SIZE(data16), &peer16, ExternalStringCallbackFinalizer); |
1251 ARRAY_SIZE(data16), | |
1252 &peer16, | |
1253 ExternalStringCallbackFinalizer); | |
1254 EXPECT_VALID(obj16); | 1234 EXPECT_VALID(obj16); |
1255 | 1235 |
1256 Dart_ExitScope(); | 1236 Dart_ExitScope(); |
1257 } | 1237 } |
1258 | 1238 |
1259 { | 1239 { |
1260 TransitionNativeToVM transition(thread); | 1240 TransitionNativeToVM transition(thread); |
1261 EXPECT_EQ(40, peer8); | 1241 EXPECT_EQ(40, peer8); |
1262 EXPECT_EQ(41, peer16); | 1242 EXPECT_EQ(41, peer16); |
1263 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1243 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
1264 GCTestHelper::WaitForGCTasks(); | 1244 GCTestHelper::WaitForGCTasks(); |
1265 EXPECT_EQ(40, peer8); | 1245 EXPECT_EQ(40, peer8); |
1266 EXPECT_EQ(41, peer16); | 1246 EXPECT_EQ(41, peer16); |
1267 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1247 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
1268 GCTestHelper::WaitForGCTasks(); | 1248 GCTestHelper::WaitForGCTasks(); |
1269 EXPECT_EQ(80, peer8); | 1249 EXPECT_EQ(80, peer8); |
1270 EXPECT_EQ(82, peer16); | 1250 EXPECT_EQ(82, peer16); |
1271 } | 1251 } |
1272 } | 1252 } |
1273 | 1253 |
1274 | 1254 |
1275 TEST_CASE(ExternalStringPretenure) { | 1255 TEST_CASE(ExternalStringPretenure) { |
1276 { | 1256 { |
1277 Dart_EnterScope(); | 1257 Dart_EnterScope(); |
1278 static const uint8_t big_data8[16*MB] = {0, }; | 1258 static const uint8_t big_data8[16 * MB] = { |
| 1259 0, |
| 1260 }; |
1279 Dart_Handle big8 = Dart_NewExternalLatin1String( | 1261 Dart_Handle big8 = Dart_NewExternalLatin1String( |
1280 big_data8, | 1262 big_data8, ARRAY_SIZE(big_data8), NULL, NULL); |
1281 ARRAY_SIZE(big_data8), | |
1282 NULL, | |
1283 NULL); | |
1284 EXPECT_VALID(big8); | 1263 EXPECT_VALID(big8); |
1285 static const uint16_t big_data16[16*MB/2] = {0, }; | 1264 static const uint16_t big_data16[16 * MB / 2] = { |
| 1265 0, |
| 1266 }; |
1286 Dart_Handle big16 = Dart_NewExternalUTF16String( | 1267 Dart_Handle big16 = Dart_NewExternalUTF16String( |
1287 big_data16, | 1268 big_data16, ARRAY_SIZE(big_data16), NULL, NULL); |
1288 ARRAY_SIZE(big_data16), | |
1289 NULL, | |
1290 NULL); | |
1291 static const uint8_t small_data8[] = {'f', 'o', 'o'}; | 1269 static const uint8_t small_data8[] = {'f', 'o', 'o'}; |
1292 Dart_Handle small8 = Dart_NewExternalLatin1String( | 1270 Dart_Handle small8 = Dart_NewExternalLatin1String( |
1293 small_data8, | 1271 small_data8, ARRAY_SIZE(small_data8), NULL, NULL); |
1294 ARRAY_SIZE(small_data8), | |
1295 NULL, | |
1296 NULL); | |
1297 EXPECT_VALID(small8); | 1272 EXPECT_VALID(small8); |
1298 static const uint16_t small_data16[] = {'b', 'a', 'r'}; | 1273 static const uint16_t small_data16[] = {'b', 'a', 'r'}; |
1299 Dart_Handle small16 = Dart_NewExternalUTF16String( | 1274 Dart_Handle small16 = Dart_NewExternalUTF16String( |
1300 small_data16, | 1275 small_data16, ARRAY_SIZE(small_data16), NULL, NULL); |
1301 ARRAY_SIZE(small_data16), | |
1302 NULL, | |
1303 NULL); | |
1304 EXPECT_VALID(small16); | 1276 EXPECT_VALID(small16); |
1305 { | 1277 { |
1306 CHECK_API_SCOPE(thread); | 1278 CHECK_API_SCOPE(thread); |
1307 HANDLESCOPE(thread); | 1279 HANDLESCOPE(thread); |
1308 String& handle = String::Handle(); | 1280 String& handle = String::Handle(); |
1309 handle ^= Api::UnwrapHandle(big8); | 1281 handle ^= Api::UnwrapHandle(big8); |
1310 EXPECT(handle.IsOld()); | 1282 EXPECT(handle.IsOld()); |
1311 handle ^= Api::UnwrapHandle(big16); | 1283 handle ^= Api::UnwrapHandle(big16); |
1312 EXPECT(handle.IsOld()); | 1284 EXPECT(handle.IsOld()); |
1313 handle ^= Api::UnwrapHandle(small8); | 1285 handle ^= Api::UnwrapHandle(small8); |
1314 EXPECT(handle.IsNew()); | 1286 EXPECT(handle.IsNew()); |
1315 handle ^= Api::UnwrapHandle(small16); | 1287 handle ^= Api::UnwrapHandle(small16); |
1316 EXPECT(handle.IsNew()); | 1288 EXPECT(handle.IsNew()); |
1317 } | 1289 } |
1318 Dart_ExitScope(); | 1290 Dart_ExitScope(); |
1319 } | 1291 } |
1320 } | 1292 } |
1321 | 1293 |
1322 | 1294 |
1323 TEST_CASE(ExternalTypedDataPretenure) { | 1295 TEST_CASE(ExternalTypedDataPretenure) { |
1324 { | 1296 { |
1325 Dart_EnterScope(); | 1297 Dart_EnterScope(); |
1326 static const int kBigLength = 16*MB/8; | 1298 static const int kBigLength = 16 * MB / 8; |
1327 int64_t* big_data = new int64_t[kBigLength](); | 1299 int64_t* big_data = new int64_t[kBigLength](); |
1328 Dart_Handle big = Dart_NewExternalTypedData( | 1300 Dart_Handle big = |
1329 Dart_TypedData_kInt64, | 1301 Dart_NewExternalTypedData(Dart_TypedData_kInt64, big_data, kBigLength); |
1330 big_data, | |
1331 kBigLength); | |
1332 EXPECT_VALID(big); | 1302 EXPECT_VALID(big); |
1333 static const int kSmallLength = 16*KB/8; | 1303 static const int kSmallLength = 16 * KB / 8; |
1334 int64_t* small_data = new int64_t[kSmallLength](); | 1304 int64_t* small_data = new int64_t[kSmallLength](); |
1335 Dart_Handle small = Dart_NewExternalTypedData( | 1305 Dart_Handle small = Dart_NewExternalTypedData(Dart_TypedData_kInt64, |
1336 Dart_TypedData_kInt64, | 1306 small_data, kSmallLength); |
1337 small_data, | |
1338 kSmallLength); | |
1339 EXPECT_VALID(small); | 1307 EXPECT_VALID(small); |
1340 { | 1308 { |
1341 CHECK_API_SCOPE(thread); | 1309 CHECK_API_SCOPE(thread); |
1342 HANDLESCOPE(thread); | 1310 HANDLESCOPE(thread); |
1343 ExternalTypedData& handle = ExternalTypedData::Handle(); | 1311 ExternalTypedData& handle = ExternalTypedData::Handle(); |
1344 handle ^= Api::UnwrapHandle(big); | 1312 handle ^= Api::UnwrapHandle(big); |
1345 EXPECT(handle.IsOld()); | 1313 EXPECT(handle.IsOld()); |
1346 handle ^= Api::UnwrapHandle(small); | 1314 handle ^= Api::UnwrapHandle(small); |
1347 EXPECT(handle.IsNew()); | 1315 EXPECT(handle.IsNew()); |
1348 } | 1316 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 // Check if we can get a range of values. | 1437 // Check if we can get a range of values. |
1470 result = Dart_ListGetRange(list_access_test_obj, 8, 4, NULL); | 1438 result = Dart_ListGetRange(list_access_test_obj, 8, 4, NULL); |
1471 EXPECT(Dart_IsError(result)); | 1439 EXPECT(Dart_IsError(result)); |
1472 const int kRangeOffset = 1; | 1440 const int kRangeOffset = 1; |
1473 const int kRangeLength = 2; | 1441 const int kRangeLength = 2; |
1474 Dart_Handle values[kRangeLength]; | 1442 Dart_Handle values[kRangeLength]; |
1475 | 1443 |
1476 result = Dart_ListGetRange(list_access_test_obj, 8, 4, values); | 1444 result = Dart_ListGetRange(list_access_test_obj, 8, 4, values); |
1477 EXPECT(Dart_IsError(result)); | 1445 EXPECT(Dart_IsError(result)); |
1478 | 1446 |
1479 result = Dart_ListGetRange( | 1447 result = Dart_ListGetRange(list_access_test_obj, kRangeOffset, kRangeLength, |
1480 list_access_test_obj, kRangeOffset, kRangeLength, values); | 1448 values); |
1481 EXPECT_VALID(result); | 1449 EXPECT_VALID(result); |
1482 | 1450 |
1483 result = Dart_IntegerToInt64(values[0], &value); | 1451 result = Dart_IntegerToInt64(values[0], &value); |
1484 EXPECT_VALID(result); | 1452 EXPECT_VALID(result); |
1485 EXPECT_EQ(20, value); | 1453 EXPECT_EQ(20, value); |
1486 | 1454 |
1487 result = Dart_IntegerToInt64(values[1], &value); | 1455 result = Dart_IntegerToInt64(values[1], &value); |
1488 EXPECT_VALID(result); | 1456 EXPECT_VALID(result); |
1489 EXPECT_EQ(30, value); | 1457 EXPECT_EQ(30, value); |
1490 | 1458 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 Dart_Handle dart_args[1]; | 1640 Dart_Handle dart_args[1]; |
1673 dart_args[0] = Dart_NewInteger(kSize); | 1641 dart_args[0] = Dart_NewInteger(kSize); |
1674 Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args); | 1642 Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args); |
1675 EXPECT_VALID(view_obj); | 1643 EXPECT_VALID(view_obj); |
1676 // Test that the API considers it a TypedData object. | 1644 // Test that the API considers it a TypedData object. |
1677 EXPECT(Dart_IsTypedData(view_obj)); | 1645 EXPECT(Dart_IsTypedData(view_obj)); |
1678 } | 1646 } |
1679 | 1647 |
1680 | 1648 |
1681 TEST_CASE(TypedDataAccess) { | 1649 TEST_CASE(TypedDataAccess) { |
1682 EXPECT_EQ(Dart_TypedData_kInvalid, | 1650 EXPECT_EQ(Dart_TypedData_kInvalid, Dart_GetTypeOfTypedData(Dart_True())); |
1683 Dart_GetTypeOfTypedData(Dart_True())); | |
1684 EXPECT_EQ(Dart_TypedData_kInvalid, | 1651 EXPECT_EQ(Dart_TypedData_kInvalid, |
1685 Dart_GetTypeOfExternalTypedData(Dart_False())); | 1652 Dart_GetTypeOfExternalTypedData(Dart_False())); |
1686 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1653 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
1687 EXPECT_VALID(byte_array1); | 1654 EXPECT_VALID(byte_array1); |
1688 EXPECT_EQ(Dart_TypedData_kUint8, | 1655 EXPECT_EQ(Dart_TypedData_kUint8, Dart_GetTypeOfTypedData(byte_array1)); |
1689 Dart_GetTypeOfTypedData(byte_array1)); | |
1690 EXPECT_EQ(Dart_TypedData_kInvalid, | 1656 EXPECT_EQ(Dart_TypedData_kInvalid, |
1691 Dart_GetTypeOfExternalTypedData(byte_array1)); | 1657 Dart_GetTypeOfExternalTypedData(byte_array1)); |
1692 EXPECT(Dart_IsList(byte_array1)); | 1658 EXPECT(Dart_IsList(byte_array1)); |
1693 EXPECT(!Dart_IsTypedData(Dart_True())); | 1659 EXPECT(!Dart_IsTypedData(Dart_True())); |
1694 EXPECT(Dart_IsTypedData(byte_array1)); | 1660 EXPECT(Dart_IsTypedData(byte_array1)); |
1695 EXPECT(!Dart_IsByteBuffer(byte_array1)); | 1661 EXPECT(!Dart_IsByteBuffer(byte_array1)); |
1696 | 1662 |
1697 intptr_t length = 0; | 1663 intptr_t length = 0; |
1698 Dart_Handle result = Dart_ListLength(byte_array1, &length); | 1664 Dart_Handle result = Dart_ListLength(byte_array1, &length); |
1699 EXPECT_VALID(result); | 1665 EXPECT_VALID(result); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 } | 1698 } |
1733 for (intptr_t i = 0; i < 10; ++i) { | 1699 for (intptr_t i = 0; i < 10; ++i) { |
1734 // Get through the List API. | 1700 // Get through the List API. |
1735 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); | 1701 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); |
1736 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); | 1702 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); |
1737 is_equal = false; | 1703 is_equal = false; |
1738 Dart_ObjectEquals(e1, e2, &is_equal); | 1704 Dart_ObjectEquals(e1, e2, &is_equal); |
1739 EXPECT(is_equal); | 1705 EXPECT(is_equal); |
1740 } | 1706 } |
1741 | 1707 |
1742 uint8_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | 1708 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
1743 for (intptr_t i = 0; i < 10; ++i) { | 1709 for (intptr_t i = 0; i < 10; ++i) { |
1744 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); | 1710 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); |
1745 } | 1711 } |
1746 Dart_ListGetAsBytes(byte_array1, 0, data, 10); | 1712 Dart_ListGetAsBytes(byte_array1, 0, data, 10); |
1747 for (intptr_t i = 0; i < 10; ++i) { | 1713 for (intptr_t i = 0; i < 10; ++i) { |
1748 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 1714 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
1749 EXPECT_VALID(integer_obj); | 1715 EXPECT_VALID(integer_obj); |
1750 int64_t int64_t_value = -1; | 1716 int64_t int64_t_value = -1; |
1751 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 1717 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
1752 EXPECT_EQ(10 - i, int64_t_value); | 1718 EXPECT_EQ(10 - i, int64_t_value); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 Dart_SetNativeResolver(lib, &ByteDataNativeResolver, NULL); | 1815 Dart_SetNativeResolver(lib, &ByteDataNativeResolver, NULL); |
1850 EXPECT_VALID(result); | 1816 EXPECT_VALID(result); |
1851 | 1817 |
1852 // Invoke 'main' function. | 1818 // Invoke 'main' function. |
1853 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1819 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1854 EXPECT_VALID(result); | 1820 EXPECT_VALID(result); |
1855 } | 1821 } |
1856 | 1822 |
1857 | 1823 |
1858 static const intptr_t kExtLength = 16; | 1824 static const intptr_t kExtLength = 16; |
1859 static int8_t data[kExtLength] = { 0x41, 0x42, 0x41, 0x42, | 1825 static int8_t data[kExtLength] = { |
1860 0x41, 0x42, 0x41, 0x42, | 1826 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, |
1861 0x41, 0x42, 0x41, 0x42, | 1827 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, |
1862 0x41, 0x42, 0x41, 0x42, }; | 1828 }; |
1863 | 1829 |
1864 static void ExternalByteDataNativeFunction(Dart_NativeArguments args) { | 1830 static void ExternalByteDataNativeFunction(Dart_NativeArguments args) { |
1865 Dart_EnterScope(); | 1831 Dart_EnterScope(); |
1866 Dart_Handle external_byte_data = Dart_NewExternalTypedData( | 1832 Dart_Handle external_byte_data = |
1867 Dart_TypedData_kByteData, data, 16); | 1833 Dart_NewExternalTypedData(Dart_TypedData_kByteData, data, 16); |
1868 EXPECT_VALID(external_byte_data); | 1834 EXPECT_VALID(external_byte_data); |
1869 EXPECT_EQ(Dart_TypedData_kByteData, | 1835 EXPECT_EQ(Dart_TypedData_kByteData, |
1870 Dart_GetTypeOfTypedData(external_byte_data)); | 1836 Dart_GetTypeOfTypedData(external_byte_data)); |
1871 Dart_SetReturnValue(args, external_byte_data); | 1837 Dart_SetReturnValue(args, external_byte_data); |
1872 Dart_ExitScope(); | 1838 Dart_ExitScope(); |
1873 } | 1839 } |
1874 | 1840 |
1875 | 1841 |
1876 static Dart_NativeFunction ExternalByteDataNativeResolver( | 1842 static Dart_NativeFunction ExternalByteDataNativeResolver( |
1877 Dart_Handle name, int arg_count, bool* auto_setup_scope) { | 1843 Dart_Handle name, |
| 1844 int arg_count, |
| 1845 bool* auto_setup_scope) { |
1878 ASSERT(auto_setup_scope != NULL); | 1846 ASSERT(auto_setup_scope != NULL); |
1879 *auto_setup_scope = true; | 1847 *auto_setup_scope = true; |
1880 return &ExternalByteDataNativeFunction; | 1848 return &ExternalByteDataNativeFunction; |
1881 } | 1849 } |
1882 | 1850 |
1883 | 1851 |
1884 TEST_CASE(ExternalByteDataAccess) { | 1852 TEST_CASE(ExternalByteDataAccess) { |
1885 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the | 1853 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the |
1886 // appropriate getter instead of the host endian format used now. | 1854 // appropriate getter instead of the host endian format used now. |
1887 const char* kScriptChars = | 1855 const char* kScriptChars = |
(...skipping 18 matching lines...) Expand all Loading... |
1906 " a.setInt8(i + 1, 0x28);" | 1874 " a.setInt8(i + 1, 0x28);" |
1907 " }" | 1875 " }" |
1908 " for (int i = 0; i < length; i+=2) {" | 1876 " for (int i = 0; i < length; i+=2) {" |
1909 " Expect.equals(0x2824, a.getInt16(i, Endianness.LITTLE_ENDIAN));" | 1877 " Expect.equals(0x2824, a.getInt16(i, Endianness.LITTLE_ENDIAN));" |
1910 " }" | 1878 " }" |
1911 " return a;" | 1879 " return a;" |
1912 "}\n"; | 1880 "}\n"; |
1913 // Create a test library and Load up a test script in it. | 1881 // Create a test library and Load up a test script in it. |
1914 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1882 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1915 | 1883 |
1916 Dart_Handle result = Dart_SetNativeResolver(lib, | 1884 Dart_Handle result = |
1917 &ExternalByteDataNativeResolver, | 1885 Dart_SetNativeResolver(lib, &ExternalByteDataNativeResolver, NULL); |
1918 NULL); | |
1919 EXPECT_VALID(result); | 1886 EXPECT_VALID(result); |
1920 | 1887 |
1921 // Invoke 'main' function. | 1888 // Invoke 'main' function. |
1922 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1889 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1923 EXPECT_VALID(result); | 1890 EXPECT_VALID(result); |
1924 | 1891 |
1925 for (intptr_t i = 0; i < kExtLength; i+=2) { | 1892 for (intptr_t i = 0; i < kExtLength; i += 2) { |
1926 EXPECT_EQ(0x24, data[i]); | 1893 EXPECT_EQ(0x24, data[i]); |
1927 EXPECT_EQ(0x28, data[i+1]); | 1894 EXPECT_EQ(0x28, data[i + 1]); |
1928 } | 1895 } |
1929 } | 1896 } |
1930 | 1897 |
1931 | 1898 |
1932 #ifndef PRODUCT | 1899 #ifndef PRODUCT |
1933 | 1900 |
1934 | 1901 |
1935 static const intptr_t kOptExtLength = 16; | 1902 static const intptr_t kOptExtLength = 16; |
1936 static int8_t opt_data[kOptExtLength] = { 0x01, 0x02, 0x03, 0x04, | 1903 static int8_t opt_data[kOptExtLength] = { |
1937 0x05, 0x06, 0x07, 0x08, | 1904 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
1938 0x09, 0x0a, 0x0b, 0x0c, | 1905 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
1939 0x0d, 0x0e, 0x0f, 0x10, }; | 1906 }; |
1940 | 1907 |
1941 static void OptExternalByteDataNativeFunction(Dart_NativeArguments args) { | 1908 static void OptExternalByteDataNativeFunction(Dart_NativeArguments args) { |
1942 Dart_EnterScope(); | 1909 Dart_EnterScope(); |
1943 Dart_Handle external_byte_data = Dart_NewExternalTypedData( | 1910 Dart_Handle external_byte_data = |
1944 Dart_TypedData_kByteData, opt_data, 16); | 1911 Dart_NewExternalTypedData(Dart_TypedData_kByteData, opt_data, 16); |
1945 EXPECT_VALID(external_byte_data); | 1912 EXPECT_VALID(external_byte_data); |
1946 EXPECT_EQ(Dart_TypedData_kByteData, | 1913 EXPECT_EQ(Dart_TypedData_kByteData, |
1947 Dart_GetTypeOfTypedData(external_byte_data)); | 1914 Dart_GetTypeOfTypedData(external_byte_data)); |
1948 Dart_SetReturnValue(args, external_byte_data); | 1915 Dart_SetReturnValue(args, external_byte_data); |
1949 Dart_ExitScope(); | 1916 Dart_ExitScope(); |
1950 } | 1917 } |
1951 | 1918 |
1952 | 1919 |
1953 static Dart_NativeFunction OptExternalByteDataNativeResolver( | 1920 static Dart_NativeFunction OptExternalByteDataNativeResolver( |
1954 Dart_Handle name, int arg_count, bool* auto_setup_scope) { | 1921 Dart_Handle name, |
| 1922 int arg_count, |
| 1923 bool* auto_setup_scope) { |
1955 ASSERT(auto_setup_scope != NULL); | 1924 ASSERT(auto_setup_scope != NULL); |
1956 *auto_setup_scope = true; | 1925 *auto_setup_scope = true; |
1957 return &OptExternalByteDataNativeFunction; | 1926 return &OptExternalByteDataNativeFunction; |
1958 } | 1927 } |
1959 | 1928 |
1960 | 1929 |
1961 TEST_CASE(OptimizedExternalByteDataAccess) { | 1930 TEST_CASE(OptimizedExternalByteDataAccess) { |
1962 const char* kScriptChars = | 1931 const char* kScriptChars = |
1963 "import 'dart:typed_data';\n" | 1932 "import 'dart:typed_data';\n" |
1964 "class Expect {\n" | 1933 "class Expect {\n" |
(...skipping 15 matching lines...) Expand all Loading... |
1980 " var a = createExternalByteData();" | 1949 " var a = createExternalByteData();" |
1981 " Expect.equals(length, a.lengthInBytes);" | 1950 " Expect.equals(length, a.lengthInBytes);" |
1982 " for (int i = 0; i < 20; i++) {" | 1951 " for (int i = 0; i < 20; i++) {" |
1983 " access(a);" | 1952 " access(a);" |
1984 " }" | 1953 " }" |
1985 " return a;" | 1954 " return a;" |
1986 "}\n"; | 1955 "}\n"; |
1987 // Create a test library and Load up a test script in it. | 1956 // Create a test library and Load up a test script in it. |
1988 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1957 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1989 | 1958 |
1990 Dart_Handle result = Dart_SetNativeResolver( | 1959 Dart_Handle result = |
1991 lib, &OptExternalByteDataNativeResolver, NULL); | 1960 Dart_SetNativeResolver(lib, &OptExternalByteDataNativeResolver, NULL); |
1992 EXPECT_VALID(result); | 1961 EXPECT_VALID(result); |
1993 | 1962 |
1994 // Invoke 'main' function. | 1963 // Invoke 'main' function. |
1995 int old_oct = FLAG_optimization_counter_threshold; | 1964 int old_oct = FLAG_optimization_counter_threshold; |
1996 FLAG_optimization_counter_threshold = 5; | 1965 FLAG_optimization_counter_threshold = 5; |
1997 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1966 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1998 EXPECT_VALID(result); | 1967 EXPECT_VALID(result); |
1999 FLAG_optimization_counter_threshold = old_oct; | 1968 FLAG_optimization_counter_threshold = old_oct; |
2000 } | 1969 } |
2001 | 1970 |
2002 | 1971 |
2003 #endif // !PRODUCT | 1972 #endif // !PRODUCT |
2004 | 1973 |
2005 | 1974 |
2006 static void TestTypedDataDirectAccess() { | 1975 static void TestTypedDataDirectAccess() { |
2007 Dart_Handle str = Dart_NewStringFromCString("junk"); | 1976 Dart_Handle str = Dart_NewStringFromCString("junk"); |
2008 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1977 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
2009 EXPECT_VALID(byte_array); | 1978 EXPECT_VALID(byte_array); |
2010 Dart_Handle result; | 1979 Dart_Handle result; |
2011 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL); | 1980 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL); |
2012 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'type'" | 1981 EXPECT_ERROR(result, |
2013 " to be non-null."); | 1982 "Dart_TypedDataAcquireData expects argument 'type'" |
| 1983 " to be non-null."); |
2014 Dart_TypedData_Type type; | 1984 Dart_TypedData_Type type; |
2015 result = Dart_TypedDataAcquireData(byte_array, &type, NULL, NULL); | 1985 result = Dart_TypedDataAcquireData(byte_array, &type, NULL, NULL); |
2016 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'data'" | 1986 EXPECT_ERROR(result, |
2017 " to be non-null."); | 1987 "Dart_TypedDataAcquireData expects argument 'data'" |
| 1988 " to be non-null."); |
2018 void* data; | 1989 void* data; |
2019 result = Dart_TypedDataAcquireData(byte_array, &type, &data, NULL); | 1990 result = Dart_TypedDataAcquireData(byte_array, &type, &data, NULL); |
2020 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'len'" | 1991 EXPECT_ERROR(result, |
2021 " to be non-null."); | 1992 "Dart_TypedDataAcquireData expects argument 'len'" |
| 1993 " to be non-null."); |
2022 intptr_t len; | 1994 intptr_t len; |
2023 result = Dart_TypedDataAcquireData(Dart_Null(), &type, &data, &len); | 1995 result = Dart_TypedDataAcquireData(Dart_Null(), &type, &data, &len); |
2024 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'object'" | 1996 EXPECT_ERROR(result, |
2025 " to be non-null."); | 1997 "Dart_TypedDataAcquireData expects argument 'object'" |
| 1998 " to be non-null."); |
2026 result = Dart_TypedDataAcquireData(str, &type, &data, &len); | 1999 result = Dart_TypedDataAcquireData(str, &type, &data, &len); |
2027 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'object'" | 2000 EXPECT_ERROR(result, |
2028 " to be of type 'TypedData'."); | 2001 "Dart_TypedDataAcquireData expects argument 'object'" |
| 2002 " to be of type 'TypedData'."); |
2029 | 2003 |
2030 result = Dart_TypedDataReleaseData(Dart_Null()); | 2004 result = Dart_TypedDataReleaseData(Dart_Null()); |
2031 EXPECT_ERROR(result, "Dart_TypedDataReleaseData expects argument 'object'" | 2005 EXPECT_ERROR(result, |
2032 " to be non-null."); | 2006 "Dart_TypedDataReleaseData expects argument 'object'" |
| 2007 " to be non-null."); |
2033 result = Dart_TypedDataReleaseData(str); | 2008 result = Dart_TypedDataReleaseData(str); |
2034 EXPECT_ERROR(result, "Dart_TypedDataReleaseData expects argument 'object'" | 2009 EXPECT_ERROR(result, |
2035 " to be of type 'TypedData'."); | 2010 "Dart_TypedDataReleaseData expects argument 'object'" |
| 2011 " to be of type 'TypedData'."); |
2036 } | 2012 } |
2037 | 2013 |
2038 | 2014 |
2039 TEST_CASE(TypedDataDirectAccessUnverified) { | 2015 TEST_CASE(TypedDataDirectAccessUnverified) { |
2040 FLAG_verify_acquired_data = false; | 2016 FLAG_verify_acquired_data = false; |
2041 TestTypedDataDirectAccess(); | 2017 TestTypedDataDirectAccess(); |
2042 } | 2018 } |
2043 | 2019 |
2044 | 2020 |
2045 TEST_CASE(TypedDataDirectAccessVerified) { | 2021 TEST_CASE(TypedDataDirectAccessVerified) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 // Create a test library and Load up a test script in it. | 2103 // Create a test library and Load up a test script in it. |
2128 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2104 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2129 | 2105 |
2130 // Test with an regular typed data object. | 2106 // Test with an regular typed data object. |
2131 Dart_Handle list_access_test_obj; | 2107 Dart_Handle list_access_test_obj; |
2132 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2108 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2133 EXPECT_VALID(list_access_test_obj); | 2109 EXPECT_VALID(list_access_test_obj); |
2134 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false); | 2110 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false); |
2135 | 2111 |
2136 // Test with an external typed data object. | 2112 // Test with an external typed data object. |
2137 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | 2113 uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
2138 intptr_t data_length = ARRAY_SIZE(data); | 2114 intptr_t data_length = ARRAY_SIZE(data); |
2139 Dart_Handle ext_list_access_test_obj; | 2115 Dart_Handle ext_list_access_test_obj; |
2140 ext_list_access_test_obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8, | 2116 ext_list_access_test_obj = |
2141 data, data_length); | 2117 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, data_length); |
2142 EXPECT_VALID(ext_list_access_test_obj); | 2118 EXPECT_VALID(ext_list_access_test_obj); |
2143 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8, true); | 2119 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8, true); |
2144 } | 2120 } |
2145 | 2121 |
2146 | 2122 |
2147 TEST_CASE(TypedDataDirectAccess1Unverified) { | 2123 TEST_CASE(TypedDataDirectAccess1Unverified) { |
2148 FLAG_verify_acquired_data = false; | 2124 FLAG_verify_acquired_data = false; |
2149 TestTypedDataDirectAccess1(); | 2125 TestTypedDataDirectAccess1(); |
2150 } | 2126 } |
2151 | 2127 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 EXPECT_VALID(Dart_ListSetAt(obj, i, value)); | 2285 EXPECT_VALID(Dart_ListSetAt(obj, i, value)); |
2310 } | 2286 } |
2311 // Read them back through the underlying array. | 2287 // Read them back through the underlying array. |
2312 for (intptr_t i = 0; i < data_length; ++i) { | 2288 for (intptr_t i = 0; i < data_length; ++i) { |
2313 EXPECT_EQ(33 * i, data[i]); | 2289 EXPECT_EQ(33 * i, data[i]); |
2314 } | 2290 } |
2315 } | 2291 } |
2316 | 2292 |
2317 | 2293 |
2318 TEST_CASE(ExternalTypedDataAccess) { | 2294 TEST_CASE(ExternalTypedDataAccess) { |
2319 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; | 2295 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; |
2320 intptr_t data_length = ARRAY_SIZE(data); | 2296 intptr_t data_length = ARRAY_SIZE(data); |
2321 | 2297 |
2322 Dart_Handle obj = Dart_NewExternalTypedData( | 2298 Dart_Handle obj = |
2323 Dart_TypedData_kUint8, data, data_length); | 2299 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, data_length); |
2324 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8, data, data_length); | 2300 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8, data, data_length); |
2325 } | 2301 } |
2326 | 2302 |
2327 | 2303 |
2328 TEST_CASE(ExternalClampedTypedDataAccess) { | 2304 TEST_CASE(ExternalClampedTypedDataAccess) { |
2329 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; | 2305 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; |
2330 intptr_t data_length = ARRAY_SIZE(data); | 2306 intptr_t data_length = ARRAY_SIZE(data); |
2331 | 2307 |
2332 Dart_Handle obj = Dart_NewExternalTypedData( | 2308 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8Clamped, |
2333 Dart_TypedData_kUint8Clamped, data, data_length); | 2309 data, data_length); |
2334 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8Clamped, | 2310 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8Clamped, data, |
2335 data, data_length); | 2311 data_length); |
2336 } | 2312 } |
2337 | 2313 |
2338 | 2314 |
2339 TEST_CASE(ExternalUint8ClampedArrayAccess) { | 2315 TEST_CASE(ExternalUint8ClampedArrayAccess) { |
2340 const char* kScriptChars = | 2316 const char* kScriptChars = |
2341 "testClamped(List a) {\n" | 2317 "testClamped(List a) {\n" |
2342 " if (a[1] != 11) return false;\n" | 2318 " if (a[1] != 11) return false;\n" |
2343 " a[1] = 3;\n" | 2319 " a[1] = 3;\n" |
2344 " if (a[1] != 3) return false;\n" | 2320 " if (a[1] != 3) return false;\n" |
2345 " a[1] = -12;\n" | 2321 " a[1] = -12;\n" |
2346 " if (a[1] != 0) return false;\n" | 2322 " if (a[1] != 0) return false;\n" |
2347 " a[1] = 1200;\n" | 2323 " a[1] = 1200;\n" |
2348 " if (a[1] != 255) return false;\n" | 2324 " if (a[1] != 255) return false;\n" |
2349 " return true;\n" | 2325 " return true;\n" |
2350 "}\n"; | 2326 "}\n"; |
2351 | 2327 |
2352 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; | 2328 uint8_t data[] = {0, 11, 22, 33, 44, 55, 66, 77}; |
2353 intptr_t data_length = ARRAY_SIZE(data); | 2329 intptr_t data_length = ARRAY_SIZE(data); |
2354 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8Clamped, | 2330 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8Clamped, |
2355 data, data_length); | 2331 data, data_length); |
2356 EXPECT_VALID(obj); | 2332 EXPECT_VALID(obj); |
2357 Dart_Handle result; | 2333 Dart_Handle result; |
2358 // Create a test library and Load up a test script in it. | 2334 // Create a test library and Load up a test script in it. |
2359 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2335 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2360 Dart_Handle args[1]; | 2336 Dart_Handle args[1]; |
2361 args[0] = obj; | 2337 args[0] = obj; |
2362 result = Dart_Invoke(lib, NewString("testClamped"), 1, args); | 2338 result = Dart_Invoke(lib, NewString("testClamped"), 1, args); |
2363 | 2339 |
2364 // Check that result is true. | 2340 // Check that result is true. |
2365 EXPECT_VALID(result); | 2341 EXPECT_VALID(result); |
2366 EXPECT(Dart_IsBoolean(result)); | 2342 EXPECT(Dart_IsBoolean(result)); |
2367 bool value = false; | 2343 bool value = false; |
2368 result = Dart_BooleanValue(result, &value); | 2344 result = Dart_BooleanValue(result, &value); |
2369 EXPECT_VALID(result); | 2345 EXPECT_VALID(result); |
2370 EXPECT(value); | 2346 EXPECT(value); |
2371 } | 2347 } |
2372 | 2348 |
2373 | 2349 |
2374 static void NopCallback(void* isolate_callback_data, | 2350 static void NopCallback(void* isolate_callback_data, |
2375 Dart_WeakPersistentHandle handle, | 2351 Dart_WeakPersistentHandle handle, |
2376 void* peer) { | 2352 void* peer) {} |
2377 } | |
2378 | 2353 |
2379 | 2354 |
2380 static void UnreachedCallback(void* isolate_callback_data, | 2355 static void UnreachedCallback(void* isolate_callback_data, |
2381 Dart_WeakPersistentHandle handle, | 2356 Dart_WeakPersistentHandle handle, |
2382 void* peer) { | 2357 void* peer) { |
2383 UNREACHABLE(); | 2358 UNREACHABLE(); |
2384 } | 2359 } |
2385 | 2360 |
2386 | 2361 |
2387 static void ExternalTypedDataFinalizer(void* isolate_callback_data, | 2362 static void ExternalTypedDataFinalizer(void* isolate_callback_data, |
2388 Dart_WeakPersistentHandle handle, | 2363 Dart_WeakPersistentHandle handle, |
2389 void* peer) { | 2364 void* peer) { |
2390 *static_cast<int*>(peer) = 42; | 2365 *static_cast<int*>(peer) = 42; |
2391 } | 2366 } |
2392 | 2367 |
2393 | 2368 |
2394 TEST_CASE(ExternalTypedDataCallback) { | 2369 TEST_CASE(ExternalTypedDataCallback) { |
2395 int peer = 0; | 2370 int peer = 0; |
2396 { | 2371 { |
2397 Dart_EnterScope(); | 2372 Dart_EnterScope(); |
2398 uint8_t data[] = { 1, 2, 3, 4 }; | 2373 uint8_t data[] = {1, 2, 3, 4}; |
2399 Dart_Handle obj = Dart_NewExternalTypedData( | 2374 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, |
2400 Dart_TypedData_kUint8, | 2375 ARRAY_SIZE(data)); |
2401 data, | 2376 Dart_NewWeakPersistentHandle(obj, &peer, sizeof(data), |
2402 ARRAY_SIZE(data)); | 2377 ExternalTypedDataFinalizer); |
2403 Dart_NewWeakPersistentHandle( | |
2404 obj, &peer, sizeof(data), ExternalTypedDataFinalizer); | |
2405 EXPECT_VALID(obj); | 2378 EXPECT_VALID(obj); |
2406 Dart_ExitScope(); | 2379 Dart_ExitScope(); |
2407 } | 2380 } |
2408 { | 2381 { |
2409 TransitionNativeToVM transition(thread); | 2382 TransitionNativeToVM transition(thread); |
2410 EXPECT(peer == 0); | 2383 EXPECT(peer == 0); |
2411 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2384 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2412 GCTestHelper::WaitForGCTasks(); | 2385 GCTestHelper::WaitForGCTasks(); |
2413 EXPECT(peer == 0); | 2386 EXPECT(peer == 0); |
2414 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2387 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 EXPECT_EQ(len, 10); | 2434 EXPECT_EQ(len, 10); |
2462 float* float_data = reinterpret_cast<float*>(raw_data); | 2435 float* float_data = reinterpret_cast<float*>(raw_data); |
2463 for (int i = 0; i < len * 4; i++) { | 2436 for (int i = 0; i < len * 4; i++) { |
2464 EXPECT_EQ(0.0, float_data[i]); | 2437 EXPECT_EQ(0.0, float_data[i]); |
2465 } | 2438 } |
2466 EXPECT_VALID(Dart_TypedDataReleaseData(obj)); | 2439 EXPECT_VALID(Dart_TypedDataReleaseData(obj)); |
2467 } | 2440 } |
2468 | 2441 |
2469 | 2442 |
2470 TEST_CASE(Float32x4List) { | 2443 TEST_CASE(Float32x4List) { |
2471 const char* kScriptChars = | 2444 const char* kScriptChars = |
2472 "import 'dart:typed_data';\n" | 2445 "import 'dart:typed_data';\n" |
2473 "Float32x4List float32x4() {\n" | 2446 "Float32x4List float32x4() {\n" |
2474 " return new Float32x4List(10);\n" | 2447 " return new Float32x4List(10);\n" |
2475 "}\n"; | 2448 "}\n"; |
2476 // Create a test library and Load up a test script in it. | 2449 // Create a test library and Load up a test script in it. |
2477 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2450 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2478 | 2451 |
2479 Dart_Handle obj = Dart_Invoke(lib, NewString("float32x4"), 0, NULL); | 2452 Dart_Handle obj = Dart_Invoke(lib, NewString("float32x4"), 0, NULL); |
2480 EXPECT_VALID(obj); | 2453 EXPECT_VALID(obj); |
2481 CheckFloat32x4Data(obj); | 2454 CheckFloat32x4Data(obj); |
2482 | 2455 |
2483 obj = Dart_NewTypedData(Dart_TypedData_kFloat32x4, 10); | 2456 obj = Dart_NewTypedData(Dart_TypedData_kFloat32x4, 10); |
2484 EXPECT_VALID(obj); | 2457 EXPECT_VALID(obj); |
2485 CheckFloat32x4Data(obj); | 2458 CheckFloat32x4Data(obj); |
2486 | 2459 |
2487 int peer = 0; | 2460 int peer = 0; |
2488 float data[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, | 2461 float data[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
2489 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, | 2462 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
2490 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, | 2463 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
2491 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; | 2464 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; |
2492 // Push a scope so that we can collect the local handle created as part of | 2465 // Push a scope so that we can collect the local handle created as part of |
2493 // Dart_NewExternalTypedData. | 2466 // Dart_NewExternalTypedData. |
2494 Dart_EnterScope(); | 2467 Dart_EnterScope(); |
2495 { | 2468 { |
2496 Dart_Handle lcl = Dart_NewExternalTypedData( | 2469 Dart_Handle lcl = |
2497 Dart_TypedData_kFloat32x4, data, 10); | 2470 Dart_NewExternalTypedData(Dart_TypedData_kFloat32x4, data, 10); |
2498 Dart_NewWeakPersistentHandle( | 2471 Dart_NewWeakPersistentHandle(lcl, &peer, sizeof(data), |
2499 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2472 ExternalTypedDataFinalizer); |
2500 CheckFloat32x4Data(lcl); | 2473 CheckFloat32x4Data(lcl); |
2501 } | 2474 } |
2502 Dart_ExitScope(); | 2475 Dart_ExitScope(); |
2503 { | 2476 { |
2504 TransitionNativeToVM transition(thread); | 2477 TransitionNativeToVM transition(thread); |
2505 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2478 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
2506 GCTestHelper::WaitForGCTasks(); | 2479 GCTestHelper::WaitForGCTasks(); |
2507 EXPECT(peer == 42); | 2480 EXPECT(peer == 42); |
2508 } | 2481 } |
2509 } | 2482 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2686 if (handle == weak_new_ref) { | 2659 if (handle == weak_new_ref) { |
2687 weak_new_ref = NULL; | 2660 weak_new_ref = NULL; |
2688 } else if (handle == weak_old_ref) { | 2661 } else if (handle == weak_old_ref) { |
2689 weak_old_ref = NULL; | 2662 weak_old_ref = NULL; |
2690 } | 2663 } |
2691 } | 2664 } |
2692 | 2665 |
2693 | 2666 |
2694 TEST_CASE(WeakPersistentHandle) { | 2667 TEST_CASE(WeakPersistentHandle) { |
2695 Dart_Handle local_new_ref = Dart_Null(); | 2668 Dart_Handle local_new_ref = Dart_Null(); |
2696 weak_new_ref = Dart_NewWeakPersistentHandle( | 2669 weak_new_ref = Dart_NewWeakPersistentHandle(local_new_ref, NULL, 0, |
2697 local_new_ref, NULL, 0, WeakPersistentHandleCallback); | 2670 WeakPersistentHandleCallback); |
2698 | 2671 |
2699 Dart_Handle local_old_ref = Dart_Null(); | 2672 Dart_Handle local_old_ref = Dart_Null(); |
2700 weak_old_ref = Dart_NewWeakPersistentHandle( | 2673 weak_old_ref = Dart_NewWeakPersistentHandle(local_old_ref, NULL, 0, |
2701 local_old_ref, NULL, 0, WeakPersistentHandleCallback); | 2674 WeakPersistentHandleCallback); |
2702 | 2675 |
2703 { | 2676 { |
2704 Dart_EnterScope(); | 2677 Dart_EnterScope(); |
2705 | 2678 |
2706 // Create an object in new space. | 2679 // Create an object in new space. |
2707 Dart_Handle new_ref = NewString("new string"); | 2680 Dart_Handle new_ref = NewString("new string"); |
2708 EXPECT_VALID(new_ref); | 2681 EXPECT_VALID(new_ref); |
2709 | 2682 |
2710 // Create an object in old space. | 2683 // Create an object in old space. |
2711 Dart_Handle old_ref; | 2684 Dart_Handle old_ref; |
2712 { | 2685 { |
2713 CHECK_API_SCOPE(thread); | 2686 CHECK_API_SCOPE(thread); |
2714 HANDLESCOPE(thread); | 2687 HANDLESCOPE(thread); |
2715 old_ref = Api::NewHandle(thread, String::New("old string", Heap::kOld)); | 2688 old_ref = Api::NewHandle(thread, String::New("old string", Heap::kOld)); |
2716 EXPECT_VALID(old_ref); | 2689 EXPECT_VALID(old_ref); |
2717 } | 2690 } |
2718 | 2691 |
2719 // Create a weak ref to the new space object. | 2692 // Create a weak ref to the new space object. |
2720 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, | 2693 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, 0, |
2721 NULL, | |
2722 0, | |
2723 WeakPersistentHandleCallback); | 2694 WeakPersistentHandleCallback); |
2724 EXPECT_VALID(AsHandle(weak_new_ref)); | 2695 EXPECT_VALID(AsHandle(weak_new_ref)); |
2725 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 2696 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
2726 | 2697 |
2727 // Create a weak ref to the old space object. | 2698 // Create a weak ref to the old space object. |
2728 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, | 2699 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, 0, |
2729 NULL, | |
2730 0, | |
2731 WeakPersistentHandleCallback); | 2700 WeakPersistentHandleCallback); |
2732 EXPECT_VALID(AsHandle(weak_old_ref)); | 2701 EXPECT_VALID(AsHandle(weak_old_ref)); |
2733 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2702 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
2734 | 2703 |
2735 { | 2704 { |
2736 TransitionNativeToVM transition(thread); | 2705 TransitionNativeToVM transition(thread); |
2737 // Garbage collect new space. | 2706 // Garbage collect new space. |
2738 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2707 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
2739 } | 2708 } |
2740 | 2709 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2815 } | 2784 } |
2816 } | 2785 } |
2817 | 2786 |
2818 | 2787 |
2819 TEST_CASE(WeakPersistentHandleErrors) { | 2788 TEST_CASE(WeakPersistentHandleErrors) { |
2820 Dart_EnterScope(); | 2789 Dart_EnterScope(); |
2821 | 2790 |
2822 // NULL callback. | 2791 // NULL callback. |
2823 Dart_Handle obj1 = NewString("new string"); | 2792 Dart_Handle obj1 = NewString("new string"); |
2824 EXPECT_VALID(obj1); | 2793 EXPECT_VALID(obj1); |
2825 Dart_WeakPersistentHandle ref1 = Dart_NewWeakPersistentHandle( | 2794 Dart_WeakPersistentHandle ref1 = |
2826 obj1, NULL, 0, NULL); | 2795 Dart_NewWeakPersistentHandle(obj1, NULL, 0, NULL); |
2827 EXPECT_EQ(ref1, static_cast<void*>(NULL)); | 2796 EXPECT_EQ(ref1, static_cast<void*>(NULL)); |
2828 | 2797 |
2829 // Immediate object. | 2798 // Immediate object. |
2830 Dart_Handle obj2 = Dart_NewInteger(0); | 2799 Dart_Handle obj2 = Dart_NewInteger(0); |
2831 EXPECT_VALID(obj2); | 2800 EXPECT_VALID(obj2); |
2832 Dart_WeakPersistentHandle ref2 = Dart_NewWeakPersistentHandle( | 2801 Dart_WeakPersistentHandle ref2 = |
2833 obj2, NULL, 0, WeakPersistentHandleCallback); | 2802 Dart_NewWeakPersistentHandle(obj2, NULL, 0, WeakPersistentHandleCallback); |
2834 EXPECT_EQ(ref2, static_cast<void*>(NULL)); | 2803 EXPECT_EQ(ref2, static_cast<void*>(NULL)); |
2835 | 2804 |
2836 Dart_ExitScope(); | 2805 Dart_ExitScope(); |
2837 } | 2806 } |
2838 | 2807 |
2839 | 2808 |
2840 static void WeakPersistentHandlePeerFinalizer(void* isolate_callback_data, | 2809 static void WeakPersistentHandlePeerFinalizer(void* isolate_callback_data, |
2841 Dart_WeakPersistentHandle handle, | 2810 Dart_WeakPersistentHandle handle, |
2842 void* peer) { | 2811 void* peer) { |
2843 *static_cast<int*>(peer) = 42; | 2812 *static_cast<int*>(peer) = 42; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2893 EXPECT(peer == 0); | 2862 EXPECT(peer == 0); |
2894 } | 2863 } |
2895 } | 2864 } |
2896 | 2865 |
2897 | 2866 |
2898 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { | 2867 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { |
2899 TestCase::CreateTestIsolate(); | 2868 TestCase::CreateTestIsolate(); |
2900 Dart_EnterScope(); | 2869 Dart_EnterScope(); |
2901 Dart_Handle ref = Dart_True(); | 2870 Dart_Handle ref = Dart_True(); |
2902 int peer = 1234; | 2871 int peer = 1234; |
2903 Dart_NewWeakPersistentHandle(ref, | 2872 Dart_NewWeakPersistentHandle(ref, &peer, 0, |
2904 &peer, | |
2905 0, | |
2906 WeakPersistentHandlePeerFinalizer); | 2873 WeakPersistentHandlePeerFinalizer); |
2907 Dart_ExitScope(); | 2874 Dart_ExitScope(); |
2908 Dart_ShutdownIsolate(); | 2875 Dart_ShutdownIsolate(); |
2909 EXPECT(peer == 42); | 2876 EXPECT(peer == 42); |
2910 } | 2877 } |
2911 | 2878 |
2912 | 2879 |
2913 TEST_CASE(WeakPersistentHandleExternalAllocationSize) { | 2880 TEST_CASE(WeakPersistentHandleExternalAllocationSize) { |
2914 Heap* heap = Isolate::Current()->heap(); | 2881 Heap* heap = Isolate::Current()->heap(); |
2915 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2882 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
2916 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2883 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
2917 Dart_WeakPersistentHandle weak1 = NULL; | 2884 Dart_WeakPersistentHandle weak1 = NULL; |
2918 static const intptr_t kWeak1ExternalSize = 1 * KB; | 2885 static const intptr_t kWeak1ExternalSize = 1 * KB; |
2919 { | 2886 { |
2920 Dart_EnterScope(); | 2887 Dart_EnterScope(); |
2921 Dart_Handle obj = NewString("weakly referenced string"); | 2888 Dart_Handle obj = NewString("weakly referenced string"); |
2922 EXPECT_VALID(obj); | 2889 EXPECT_VALID(obj); |
2923 weak1 = Dart_NewWeakPersistentHandle(obj, | 2890 weak1 = Dart_NewWeakPersistentHandle(obj, NULL, kWeak1ExternalSize, |
2924 NULL, | |
2925 kWeak1ExternalSize, | |
2926 NopCallback); | 2891 NopCallback); |
2927 EXPECT_VALID(AsHandle(weak1)); | 2892 EXPECT_VALID(AsHandle(weak1)); |
2928 Dart_ExitScope(); | 2893 Dart_ExitScope(); |
2929 } | 2894 } |
2930 Dart_PersistentHandle strong_ref = NULL; | 2895 Dart_PersistentHandle strong_ref = NULL; |
2931 Dart_WeakPersistentHandle weak2 = NULL; | 2896 Dart_WeakPersistentHandle weak2 = NULL; |
2932 static const intptr_t kWeak2ExternalSize = 2 * KB; | 2897 static const intptr_t kWeak2ExternalSize = 2 * KB; |
2933 { | 2898 { |
2934 Dart_EnterScope(); | 2899 Dart_EnterScope(); |
2935 Dart_Handle obj = NewString("strongly referenced string"); | 2900 Dart_Handle obj = NewString("strongly referenced string"); |
2936 EXPECT_VALID(obj); | 2901 EXPECT_VALID(obj); |
2937 strong_ref = Dart_NewPersistentHandle(obj); | 2902 strong_ref = Dart_NewPersistentHandle(obj); |
2938 weak2 = Dart_NewWeakPersistentHandle(obj, | 2903 weak2 = Dart_NewWeakPersistentHandle(obj, NULL, kWeak2ExternalSize, |
2939 NULL, | |
2940 kWeak2ExternalSize, | |
2941 NopCallback); | 2904 NopCallback); |
2942 EXPECT_VALID(AsHandle(strong_ref)); | 2905 EXPECT_VALID(AsHandle(strong_ref)); |
2943 Dart_ExitScope(); | 2906 Dart_ExitScope(); |
2944 } | 2907 } |
2945 { | 2908 { |
2946 TransitionNativeToVM transition(thread); | 2909 TransitionNativeToVM transition(thread); |
2947 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2910 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2948 EXPECT(heap->ExternalInWords(Heap::kNew) == | 2911 EXPECT(heap->ExternalInWords(Heap::kNew) == |
2949 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2912 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
2950 // Collect weakly referenced string, and promote strongly referenced string. | 2913 // Collect weakly referenced string, and promote strongly referenced string. |
(...skipping 20 matching lines...) Expand all Loading... |
2971 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2934 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2972 Heap* heap = Isolate::Current()->heap(); | 2935 Heap* heap = Isolate::Current()->heap(); |
2973 Dart_WeakPersistentHandle weak1 = NULL; | 2936 Dart_WeakPersistentHandle weak1 = NULL; |
2974 // Large enough to exceed any new space limit. Not actually allocated. | 2937 // Large enough to exceed any new space limit. Not actually allocated. |
2975 const intptr_t kWeak1ExternalSize = 500 * MB; | 2938 const intptr_t kWeak1ExternalSize = 500 * MB; |
2976 { | 2939 { |
2977 Dart_EnterScope(); | 2940 Dart_EnterScope(); |
2978 Dart_Handle obj = NewString("weakly referenced string"); | 2941 Dart_Handle obj = NewString("weakly referenced string"); |
2979 EXPECT_VALID(obj); | 2942 EXPECT_VALID(obj); |
2980 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit. | 2943 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit. |
2981 weak1 = Dart_NewWeakPersistentHandle(obj, | 2944 weak1 = Dart_NewWeakPersistentHandle(obj, NULL, kWeak1ExternalSize, |
2982 NULL, | |
2983 kWeak1ExternalSize, | |
2984 NopCallback); | 2945 NopCallback); |
2985 EXPECT_VALID(AsHandle(weak1)); | 2946 EXPECT_VALID(AsHandle(weak1)); |
2986 // ... but the object is still alive and not yet promoted, so external size | 2947 // ... but the object is still alive and not yet promoted, so external size |
2987 // in new space is still above the limit. Thus, even the following tiny | 2948 // in new space is still above the limit. Thus, even the following tiny |
2988 // external allocation will trigger another scavenge. | 2949 // external allocation will trigger another scavenge. |
2989 Dart_WeakPersistentHandle trigger = | 2950 Dart_WeakPersistentHandle trigger = |
2990 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback); | 2951 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback); |
2991 EXPECT_VALID(AsHandle(trigger)); | 2952 EXPECT_VALID(AsHandle(trigger)); |
2992 Dart_DeleteWeakPersistentHandle(isolate, trigger); | 2953 Dart_DeleteWeakPersistentHandle(isolate, trigger); |
2993 // After the two scavenges above, 'obj' should now be promoted, hence its | 2954 // After the two scavenges above, 'obj' should now be promoted, hence its |
2994 // external size charged to old space. | 2955 // external size charged to old space. |
2995 { | 2956 { |
2996 CHECK_API_SCOPE(thread); | 2957 CHECK_API_SCOPE(thread); |
2997 HANDLESCOPE(thread); | 2958 HANDLESCOPE(thread); |
2998 String& handle = String::Handle(thread->zone()); | 2959 String& handle = String::Handle(thread->zone()); |
2999 handle ^= Api::UnwrapHandle(obj); | 2960 handle ^= Api::UnwrapHandle(obj); |
3000 EXPECT(handle.IsOld()); | 2961 EXPECT(handle.IsOld()); |
(...skipping 18 matching lines...) Expand all Loading... |
3019 Dart_EnterScope(); | 2980 Dart_EnterScope(); |
3020 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); | 2981 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); |
3021 EXPECT_VALID(live); | 2982 EXPECT_VALID(live); |
3022 Dart_WeakPersistentHandle weak = NULL; | 2983 Dart_WeakPersistentHandle weak = NULL; |
3023 EXPECT_EQ(0, isolate->heap()->ExternalInWords(Heap::kOld)); | 2984 EXPECT_EQ(0, isolate->heap()->ExternalInWords(Heap::kOld)); |
3024 const intptr_t kSmallExternalSize = 1 * KB; | 2985 const intptr_t kSmallExternalSize = 1 * KB; |
3025 { | 2986 { |
3026 Dart_EnterScope(); | 2987 Dart_EnterScope(); |
3027 Dart_Handle dead = Api::NewHandle(thread, String::New("dead", Heap::kOld)); | 2988 Dart_Handle dead = Api::NewHandle(thread, String::New("dead", Heap::kOld)); |
3028 EXPECT_VALID(dead); | 2989 EXPECT_VALID(dead); |
3029 weak = Dart_NewWeakPersistentHandle(dead, | 2990 weak = Dart_NewWeakPersistentHandle(dead, NULL, kSmallExternalSize, |
3030 NULL, | |
3031 kSmallExternalSize, | |
3032 NopCallback); | 2991 NopCallback); |
3033 EXPECT_VALID(AsHandle(weak)); | 2992 EXPECT_VALID(AsHandle(weak)); |
3034 Dart_ExitScope(); | 2993 Dart_ExitScope(); |
3035 } | 2994 } |
3036 EXPECT_EQ(kSmallExternalSize, | 2995 EXPECT_EQ(kSmallExternalSize, |
3037 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); | 2996 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); |
3038 // Large enough to trigger GC in old space. Not actually allocated. | 2997 // Large enough to trigger GC in old space. Not actually allocated. |
3039 const intptr_t kHugeExternalSize = (kWordSize == 4) ? 513 * MB : 1025 * MB; | 2998 const intptr_t kHugeExternalSize = (kWordSize == 4) ? 513 * MB : 1025 * MB; |
3040 Dart_NewWeakPersistentHandle(live, | 2999 Dart_NewWeakPersistentHandle(live, NULL, kHugeExternalSize, NopCallback); |
3041 NULL, | |
3042 kHugeExternalSize, | |
3043 NopCallback); | |
3044 // Expect small garbage to be collected. | 3000 // Expect small garbage to be collected. |
3045 EXPECT_EQ(kHugeExternalSize, | 3001 EXPECT_EQ(kHugeExternalSize, |
3046 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); | 3002 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); |
3047 Dart_ExitScope(); | 3003 Dart_ExitScope(); |
3048 } | 3004 } |
3049 | 3005 |
3050 | 3006 |
3051 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { | 3007 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { |
3052 Heap* heap = Isolate::Current()->heap(); | 3008 Heap* heap = Isolate::Current()->heap(); |
3053 Dart_WeakPersistentHandle weak1 = NULL; | 3009 Dart_WeakPersistentHandle weak1 = NULL; |
3054 static const intptr_t kWeak1ExternalSize = 1 * KB; | 3010 static const intptr_t kWeak1ExternalSize = 1 * KB; |
3055 Dart_WeakPersistentHandle weak2 = NULL; | 3011 Dart_WeakPersistentHandle weak2 = NULL; |
3056 static const intptr_t kWeak2ExternalSize = 2 * KB; | 3012 static const intptr_t kWeak2ExternalSize = 2 * KB; |
3057 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); | 3013 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); |
3058 { | 3014 { |
3059 Dart_EnterScope(); | 3015 Dart_EnterScope(); |
3060 Dart_Handle dart_true = Dart_True(); // VM heap object. | 3016 Dart_Handle dart_true = Dart_True(); // VM heap object. |
3061 EXPECT_VALID(dart_true); | 3017 EXPECT_VALID(dart_true); |
3062 weak1 = Dart_NewWeakPersistentHandle( | 3018 weak1 = Dart_NewWeakPersistentHandle(dart_true, NULL, kWeak1ExternalSize, |
3063 dart_true, NULL, kWeak1ExternalSize, UnreachedCallback); | 3019 UnreachedCallback); |
3064 EXPECT_VALID(AsHandle(weak1)); | 3020 EXPECT_VALID(AsHandle(weak1)); |
3065 Dart_Handle zero = Dart_False(); // VM heap object. | 3021 Dart_Handle zero = Dart_False(); // VM heap object. |
3066 EXPECT_VALID(zero); | 3022 EXPECT_VALID(zero); |
3067 weak2 = Dart_NewWeakPersistentHandle( | 3023 weak2 = Dart_NewWeakPersistentHandle(zero, NULL, kWeak2ExternalSize, |
3068 zero, NULL, kWeak2ExternalSize, UnreachedCallback); | 3024 UnreachedCallback); |
3069 EXPECT_VALID(AsHandle(weak2)); | 3025 EXPECT_VALID(AsHandle(weak2)); |
3070 // Both should be charged to old space. | 3026 // Both should be charged to old space. |
3071 EXPECT(heap->ExternalInWords(Heap::kOld) == | 3027 EXPECT(heap->ExternalInWords(Heap::kOld) == |
3072 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 3028 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
3073 Dart_ExitScope(); | 3029 Dart_ExitScope(); |
3074 } | 3030 } |
3075 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 3031 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
3076 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 3032 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
3077 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 3033 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
3078 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); | 3034 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); |
(...skipping 25 matching lines...) Expand all Loading... |
3104 | 3060 |
3105 TEST_CASE(ImplicitReferencesOldSpace) { | 3061 TEST_CASE(ImplicitReferencesOldSpace) { |
3106 Dart_PersistentHandle strong = NULL; | 3062 Dart_PersistentHandle strong = NULL; |
3107 Dart_WeakPersistentHandle strong_weak = NULL; | 3063 Dart_WeakPersistentHandle strong_weak = NULL; |
3108 | 3064 |
3109 Dart_EnterScope(); | 3065 Dart_EnterScope(); |
3110 { | 3066 { |
3111 CHECK_API_SCOPE(thread); | 3067 CHECK_API_SCOPE(thread); |
3112 HANDLESCOPE(thread); | 3068 HANDLESCOPE(thread); |
3113 | 3069 |
3114 Dart_Handle local = Api::NewHandle( | 3070 Dart_Handle local = |
3115 thread, String::New("strongly reachable", Heap::kOld)); | 3071 Api::NewHandle(thread, String::New("strongly reachable", Heap::kOld)); |
3116 strong = Dart_NewPersistentHandle(local); | 3072 strong = Dart_NewPersistentHandle(local); |
3117 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3073 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
3118 | 3074 |
3119 EXPECT(!Dart_IsNull(AsHandle(strong))); | 3075 EXPECT(!Dart_IsNull(AsHandle(strong))); |
3120 EXPECT_VALID(AsHandle(strong)); | 3076 EXPECT_VALID(AsHandle(strong)); |
3121 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 3077 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
3122 EXPECT_VALID(AsHandle(strong_weak)); | 3078 EXPECT_VALID(AsHandle(strong_weak)); |
3123 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) | 3079 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) |
3124 | 3080 |
3125 weak1 = Dart_NewWeakPersistentHandle( | 3081 weak1 = Dart_NewWeakPersistentHandle( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 TEST_CASE(ImplicitReferencesNewSpace) { | 3127 TEST_CASE(ImplicitReferencesNewSpace) { |
3172 Dart_PersistentHandle strong = NULL; | 3128 Dart_PersistentHandle strong = NULL; |
3173 Dart_WeakPersistentHandle strong_weak = NULL; | 3129 Dart_WeakPersistentHandle strong_weak = NULL; |
3174 | 3130 |
3175 | 3131 |
3176 Dart_EnterScope(); | 3132 Dart_EnterScope(); |
3177 { | 3133 { |
3178 CHECK_API_SCOPE(thread); | 3134 CHECK_API_SCOPE(thread); |
3179 HANDLESCOPE(thread); | 3135 HANDLESCOPE(thread); |
3180 | 3136 |
3181 Dart_Handle local = Api::NewHandle( | 3137 Dart_Handle local = |
3182 thread, String::New("strongly reachable", Heap::kOld)); | 3138 Api::NewHandle(thread, String::New("strongly reachable", Heap::kOld)); |
3183 strong = Dart_NewPersistentHandle(local); | 3139 strong = Dart_NewPersistentHandle(local); |
3184 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3140 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
3185 | 3141 |
3186 EXPECT(!Dart_IsNull(AsHandle(strong))); | 3142 EXPECT(!Dart_IsNull(AsHandle(strong))); |
3187 EXPECT_VALID(AsHandle(strong)); | 3143 EXPECT_VALID(AsHandle(strong)); |
3188 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 3144 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
3189 EXPECT_VALID(AsHandle(strong_weak)); | 3145 EXPECT_VALID(AsHandle(strong_weak)); |
3190 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) | 3146 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) |
3191 | 3147 |
3192 weak1 = Dart_NewWeakPersistentHandle( | 3148 weak1 = Dart_NewWeakPersistentHandle( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3243 | 3199 |
3244 | 3200 |
3245 static void PrologueCallbackTimes3() { | 3201 static void PrologueCallbackTimes3() { |
3246 global_prologue_callback_status *= 3; | 3202 global_prologue_callback_status *= 3; |
3247 } | 3203 } |
3248 | 3204 |
3249 | 3205 |
3250 static int global_epilogue_callback_status; | 3206 static int global_epilogue_callback_status; |
3251 | 3207 |
3252 | 3208 |
3253 static void EpilogueCallbackNOP() { | 3209 static void EpilogueCallbackNOP() {} |
3254 } | |
3255 | 3210 |
3256 | 3211 |
3257 static void EpilogueCallbackTimes4() { | 3212 static void EpilogueCallbackTimes4() { |
3258 global_epilogue_callback_status *= 4; | 3213 global_epilogue_callback_status *= 4; |
3259 } | 3214 } |
3260 | 3215 |
3261 | 3216 |
3262 static void EpilogueCallbackTimes5() { | 3217 static void EpilogueCallbackTimes5() { |
3263 global_epilogue_callback_status *= 5; | 3218 global_epilogue_callback_status *= 5; |
3264 } | 3219 } |
3265 | 3220 |
3266 | 3221 |
3267 TEST_CASE(SetGarbageCollectionCallbacks) { | 3222 TEST_CASE(SetGarbageCollectionCallbacks) { |
3268 // GC callback addition testing. | 3223 // GC callback addition testing. |
3269 | 3224 |
3270 // Add GC callbacks. | 3225 // Add GC callbacks. |
3271 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3226 EXPECT_VALID( |
3272 &EpilogueCallbackTimes4)); | 3227 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); |
3273 | 3228 |
3274 // Add the same callbacks again. This is an error. | 3229 // Add the same callbacks again. This is an error. |
3275 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3230 EXPECT(Dart_IsError( |
3276 &EpilogueCallbackTimes4))); | 3231 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4))); |
3277 | 3232 |
3278 // Add another callback. This is an error. | 3233 // Add another callback. This is an error. |
3279 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes3, | 3234 EXPECT(Dart_IsError( |
3280 &EpilogueCallbackTimes5))); | 3235 Dart_SetGcCallbacks(&PrologueCallbackTimes3, &EpilogueCallbackTimes5))); |
3281 | 3236 |
3282 // GC callback removal testing. | 3237 // GC callback removal testing. |
3283 | 3238 |
3284 // Remove GC callbacks. | 3239 // Remove GC callbacks. |
3285 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | 3240 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); |
3286 | 3241 |
3287 // Remove GC callbacks whennone exist. This is an error. | 3242 // Remove GC callbacks whennone exist. This is an error. |
3288 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, NULL))); | 3243 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, NULL))); |
3289 | 3244 |
3290 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3245 EXPECT_VALID( |
3291 &EpilogueCallbackTimes4)); | 3246 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); |
3292 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); | 3247 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); |
3293 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); | 3248 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); |
3294 } | 3249 } |
3295 | 3250 |
3296 | 3251 |
3297 TEST_CASE(SingleGarbageCollectionCallback) { | 3252 TEST_CASE(SingleGarbageCollectionCallback) { |
3298 // Add a prologue callback. | 3253 // Add a prologue callback. |
3299 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3254 EXPECT_VALID( |
3300 &EpilogueCallbackNOP)); | 3255 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackNOP)); |
3301 | 3256 |
3302 { | 3257 { |
3303 TransitionNativeToVM transition(thread); | 3258 TransitionNativeToVM transition(thread); |
3304 | 3259 |
3305 // Garbage collect new space ignoring callbacks. This should not | 3260 // Garbage collect new space ignoring callbacks. This should not |
3306 // invoke the prologue callback. No status values should change. | 3261 // invoke the prologue callback. No status values should change. |
3307 global_prologue_callback_status = 3; | 3262 global_prologue_callback_status = 3; |
3308 global_epilogue_callback_status = 7; | 3263 global_epilogue_callback_status = 7; |
3309 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 3264 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
3310 EXPECT_EQ(3, global_prologue_callback_status); | 3265 EXPECT_EQ(3, global_prologue_callback_status); |
3311 EXPECT_EQ(7, global_epilogue_callback_status); | 3266 EXPECT_EQ(7, global_epilogue_callback_status); |
3312 | 3267 |
3313 // Garbage collect new space invoking callbacks. This should | 3268 // Garbage collect new space invoking callbacks. This should |
3314 // invoke the prologue callback. No status values should change. | 3269 // invoke the prologue callback. No status values should change. |
3315 global_prologue_callback_status = 3; | 3270 global_prologue_callback_status = 3; |
3316 global_epilogue_callback_status = 7; | 3271 global_epilogue_callback_status = 7; |
3317 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); | 3272 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
3318 EXPECT_EQ(6, global_prologue_callback_status); | 3273 EXPECT_EQ(6, global_prologue_callback_status); |
3319 EXPECT_EQ(7, global_epilogue_callback_status); | 3274 EXPECT_EQ(7, global_epilogue_callback_status); |
3320 | 3275 |
3321 // Garbage collect old space ignoring callbacks. This should invoke | 3276 // Garbage collect old space ignoring callbacks. This should invoke |
3322 // the prologue callback. The prologue status value should change. | 3277 // the prologue callback. The prologue status value should change. |
3323 global_prologue_callback_status = 3; | 3278 global_prologue_callback_status = 3; |
3324 global_epilogue_callback_status = 7; | 3279 global_epilogue_callback_status = 7; |
3325 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 3280 Isolate::Current()->heap()->CollectGarbage( |
3326 Heap::kIgnoreApiCallbacks, | 3281 Heap::kOld, Heap::kIgnoreApiCallbacks, Heap::kGCTestCase); |
3327 Heap::kGCTestCase); | |
3328 EXPECT_EQ(3, global_prologue_callback_status); | 3282 EXPECT_EQ(3, global_prologue_callback_status); |
3329 EXPECT_EQ(7, global_epilogue_callback_status); | 3283 EXPECT_EQ(7, global_epilogue_callback_status); |
3330 | 3284 |
3331 // Garbage collect old space. This should invoke the prologue | 3285 // Garbage collect old space. This should invoke the prologue |
3332 // callback. The prologue status value should change. | 3286 // callback. The prologue status value should change. |
3333 global_prologue_callback_status = 3; | 3287 global_prologue_callback_status = 3; |
3334 global_epilogue_callback_status = 7; | 3288 global_epilogue_callback_status = 7; |
3335 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3289 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3336 EXPECT_EQ(6, global_prologue_callback_status); | 3290 EXPECT_EQ(6, global_prologue_callback_status); |
3337 EXPECT_EQ(7, global_epilogue_callback_status); | 3291 EXPECT_EQ(7, global_epilogue_callback_status); |
3338 | 3292 |
3339 // Garbage collect old space again. Callbacks are persistent so the | 3293 // Garbage collect old space again. Callbacks are persistent so the |
3340 // prologue status value should change again. | 3294 // prologue status value should change again. |
3341 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3295 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3342 EXPECT_EQ(12, global_prologue_callback_status); | 3296 EXPECT_EQ(12, global_prologue_callback_status); |
3343 EXPECT_EQ(7, global_epilogue_callback_status); | 3297 EXPECT_EQ(7, global_epilogue_callback_status); |
3344 } | 3298 } |
3345 | 3299 |
3346 // Add an epilogue callback. | 3300 // Add an epilogue callback. |
3347 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | 3301 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); |
3348 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3302 EXPECT_VALID( |
3349 &EpilogueCallbackTimes4)); | 3303 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); |
3350 | 3304 |
3351 { | 3305 { |
3352 TransitionNativeToVM transition(thread); | 3306 TransitionNativeToVM transition(thread); |
3353 // Garbage collect new space. This should not invoke the prologue | 3307 // Garbage collect new space. This should not invoke the prologue |
3354 // or the epilogue callback. No status values should change. | 3308 // or the epilogue callback. No status values should change. |
3355 global_prologue_callback_status = 3; | 3309 global_prologue_callback_status = 3; |
3356 global_epilogue_callback_status = 7; | 3310 global_epilogue_callback_status = 7; |
3357 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 3311 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
3358 EXPECT_EQ(3, global_prologue_callback_status); | 3312 EXPECT_EQ(3, global_prologue_callback_status); |
3359 EXPECT_EQ(7, global_epilogue_callback_status); | 3313 EXPECT_EQ(7, global_epilogue_callback_status); |
3360 | 3314 |
3361 // Garbage collect new space. This should invoke the prologue and | 3315 // Garbage collect new space. This should invoke the prologue and |
3362 // the epilogue callback. The prologue and epilogue status values | 3316 // the epilogue callback. The prologue and epilogue status values |
3363 // should change. | 3317 // should change. |
3364 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); | 3318 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
3365 EXPECT_EQ(6, global_prologue_callback_status); | 3319 EXPECT_EQ(6, global_prologue_callback_status); |
3366 EXPECT_EQ(28, global_epilogue_callback_status); | 3320 EXPECT_EQ(28, global_epilogue_callback_status); |
3367 | 3321 |
3368 // Garbage collect old space. This should invoke the prologue and | 3322 // Garbage collect old space. This should invoke the prologue and |
3369 // the epilogue callbacks. The prologue and epilogue status values | 3323 // the epilogue callbacks. The prologue and epilogue status values |
3370 // should change. | 3324 // should change. |
3371 global_prologue_callback_status = 3; | 3325 global_prologue_callback_status = 3; |
3372 global_epilogue_callback_status = 7; | 3326 global_epilogue_callback_status = 7; |
3373 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3327 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3374 EXPECT_EQ(6, global_prologue_callback_status); | 3328 EXPECT_EQ(6, global_prologue_callback_status); |
3375 EXPECT_EQ(28, global_epilogue_callback_status); | 3329 EXPECT_EQ(28, global_epilogue_callback_status); |
3376 | 3330 |
3377 // Garbage collect old space again without invoking callbacks. | 3331 // Garbage collect old space again without invoking callbacks. |
3378 // Nothing should change. | 3332 // Nothing should change. |
3379 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 3333 Isolate::Current()->heap()->CollectGarbage( |
3380 Heap::kIgnoreApiCallbacks, | 3334 Heap::kOld, Heap::kIgnoreApiCallbacks, Heap::kGCTestCase); |
3381 Heap::kGCTestCase); | |
3382 EXPECT_EQ(6, global_prologue_callback_status); | 3335 EXPECT_EQ(6, global_prologue_callback_status); |
3383 EXPECT_EQ(28, global_epilogue_callback_status); | 3336 EXPECT_EQ(28, global_epilogue_callback_status); |
3384 | 3337 |
3385 // Garbage collect old space again. Callbacks are persistent so the | 3338 // Garbage collect old space again. Callbacks are persistent so the |
3386 // prologue and epilogue status values should change again. | 3339 // prologue and epilogue status values should change again. |
3387 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3340 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3388 EXPECT_EQ(12, global_prologue_callback_status); | 3341 EXPECT_EQ(12, global_prologue_callback_status); |
3389 EXPECT_EQ(112, global_epilogue_callback_status); | 3342 EXPECT_EQ(112, global_epilogue_callback_status); |
3390 } | 3343 } |
3391 | 3344 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3536 Dart_ShutdownIsolate(); | 3489 Dart_ShutdownIsolate(); |
3537 EXPECT(NULL == Dart_CurrentIsolate()); | 3490 EXPECT(NULL == Dart_CurrentIsolate()); |
3538 } | 3491 } |
3539 | 3492 |
3540 | 3493 |
3541 UNIT_TEST_CASE(CurrentIsolateData) { | 3494 UNIT_TEST_CASE(CurrentIsolateData) { |
3542 intptr_t mydata = 12345; | 3495 intptr_t mydata = 12345; |
3543 char* err; | 3496 char* err; |
3544 Dart_Isolate isolate = | 3497 Dart_Isolate isolate = |
3545 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, | 3498 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, |
3546 reinterpret_cast<void*>(mydata), | 3499 reinterpret_cast<void*>(mydata), &err); |
3547 &err); | |
3548 EXPECT(isolate != NULL); | 3500 EXPECT(isolate != NULL); |
3549 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); | 3501 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); |
3550 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); | 3502 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); |
3551 Dart_ShutdownIsolate(); | 3503 Dart_ShutdownIsolate(); |
3552 } | 3504 } |
3553 | 3505 |
3554 | 3506 |
3555 UNIT_TEST_CASE(IsolateSetCheckedMode) { | 3507 UNIT_TEST_CASE(IsolateSetCheckedMode) { |
3556 const char* kScriptChars = | 3508 const char* kScriptChars = |
3557 "int bad1() {\n" | 3509 "int bad1() {\n" |
3558 " int foo = 'string';\n" | 3510 " int foo = 'string';\n" |
3559 " return foo;\n" | 3511 " return foo;\n" |
3560 "}\n" | 3512 "}\n" |
3561 "\n" | 3513 "\n" |
3562 "int good1() {\n" | 3514 "int good1() {\n" |
3563 " int five = 5;\n" | 3515 " int five = 5;\n" |
3564 " return five;" | 3516 " return five;" |
3565 "}\n"; | 3517 "}\n"; |
3566 | 3518 |
3567 // Create an isolate with checked mode flags. | 3519 // Create an isolate with checked mode flags. |
3568 Dart_IsolateFlags api_flags; | 3520 Dart_IsolateFlags api_flags; |
3569 api_flags.version = DART_FLAGS_CURRENT_VERSION; | 3521 api_flags.version = DART_FLAGS_CURRENT_VERSION; |
3570 api_flags.enable_type_checks = true; | 3522 api_flags.enable_type_checks = true; |
3571 api_flags.enable_asserts = true; | 3523 api_flags.enable_asserts = true; |
3572 api_flags.enable_error_on_bad_type = true; | 3524 api_flags.enable_error_on_bad_type = true; |
3573 api_flags.enable_error_on_bad_override = true; | 3525 api_flags.enable_error_on_bad_override = true; |
3574 | 3526 |
3575 char* err; | 3527 char* err; |
3576 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, | 3528 Dart_Isolate isolate = Dart_CreateIsolate( |
3577 bin::isolate_snapshot_buffer, | 3529 NULL, NULL, bin::isolate_snapshot_buffer, &api_flags, NULL, &err); |
3578 &api_flags, | |
3579 NULL, &err); | |
3580 if (isolate == NULL) { | 3530 if (isolate == NULL) { |
3581 OS::Print("Creation of isolate failed '%s'\n", err); | 3531 OS::Print("Creation of isolate failed '%s'\n", err); |
3582 free(err); | 3532 free(err); |
3583 } | 3533 } |
3584 EXPECT(isolate != NULL); | 3534 EXPECT(isolate != NULL); |
3585 | 3535 |
3586 { | 3536 { |
3587 Dart_EnterScope(); | 3537 Dart_EnterScope(); |
3588 Dart_Handle url = NewString(TestCase::url()); | 3538 Dart_Handle url = NewString(TestCase::url()); |
3589 Dart_Handle source = NewString(kScriptChars); | 3539 Dart_Handle source = NewString(kScriptChars); |
3590 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 3540 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
3591 EXPECT_VALID(result); | 3541 EXPECT_VALID(result); |
3592 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 3542 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
3593 EXPECT_VALID(lib); | 3543 EXPECT_VALID(lib); |
3594 result = Dart_FinalizeLoading(false); | 3544 result = Dart_FinalizeLoading(false); |
3595 EXPECT_VALID(result); | 3545 EXPECT_VALID(result); |
3596 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); | 3546 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); |
3597 EXPECT_ERROR(result, "Unhandled exception:\n" | 3547 EXPECT_ERROR(result, |
3598 "type 'String' is not a subtype of type 'int' of 'foo'"); | 3548 "Unhandled exception:\n" |
| 3549 "type 'String' is not a subtype of type 'int' of 'foo'"); |
3599 | 3550 |
3600 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); | 3551 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); |
3601 EXPECT_VALID(result); | 3552 EXPECT_VALID(result); |
3602 Dart_ExitScope(); | 3553 Dart_ExitScope(); |
3603 } | 3554 } |
3604 | 3555 |
3605 EXPECT(isolate != NULL); | 3556 EXPECT(isolate != NULL); |
3606 | 3557 |
3607 // Shutdown the isolate. | 3558 // Shutdown the isolate. |
3608 Dart_ShutdownIsolate(); | 3559 Dart_ShutdownIsolate(); |
3609 } | 3560 } |
3610 | 3561 |
3611 | 3562 |
3612 TEST_CASE(DebugName) { | 3563 TEST_CASE(DebugName) { |
3613 Dart_Handle debug_name = Dart_DebugName(); | 3564 Dart_Handle debug_name = Dart_DebugName(); |
3614 EXPECT_VALID(debug_name); | 3565 EXPECT_VALID(debug_name); |
3615 EXPECT(Dart_IsString(debug_name)); | 3566 EXPECT(Dart_IsString(debug_name)); |
3616 } | 3567 } |
3617 | 3568 |
3618 | 3569 |
3619 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) { | 3570 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {} |
3620 } | |
3621 | 3571 |
3622 | 3572 |
3623 UNIT_TEST_CASE(SetMessageCallbacks) { | 3573 UNIT_TEST_CASE(SetMessageCallbacks) { |
3624 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); | 3574 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); |
3625 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); | 3575 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); |
3626 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 3576 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
3627 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); | 3577 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); |
3628 Dart_ShutdownIsolate(); | 3578 Dart_ShutdownIsolate(); |
3629 } | 3579 } |
3630 | 3580 |
3631 | 3581 |
3632 TEST_CASE(SetStickyError) { | 3582 TEST_CASE(SetStickyError) { |
3633 const char* kScriptChars = | 3583 const char* kScriptChars = "main() => throw 'HI';"; |
3634 "main() => throw 'HI';"; | |
3635 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3584 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3636 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 3585 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
3637 EXPECT(Dart_IsError(retobj)); | 3586 EXPECT(Dart_IsError(retobj)); |
3638 EXPECT(Dart_IsUnhandledExceptionError(retobj)); | 3587 EXPECT(Dart_IsUnhandledExceptionError(retobj)); |
3639 EXPECT(!Dart_HasStickyError()); | 3588 EXPECT(!Dart_HasStickyError()); |
3640 EXPECT(Dart_GetStickyError() == Dart_Null()); | 3589 EXPECT(Dart_GetStickyError() == Dart_Null()); |
3641 Dart_SetStickyError(retobj); | 3590 Dart_SetStickyError(retobj); |
3642 EXPECT(Dart_HasStickyError()); | 3591 EXPECT(Dart_HasStickyError()); |
3643 EXPECT(Dart_GetStickyError() != Dart_Null()); | 3592 EXPECT(Dart_GetStickyError() != Dart_Null()); |
3644 Dart_SetStickyError(Dart_Null()); | 3593 Dart_SetStickyError(Dart_Null()); |
(...skipping 18 matching lines...) Expand all Loading... |
3663 "\n" | 3612 "\n" |
3664 "abstract class MyInterface1 implements MyInterface0 {\n" | 3613 "abstract class MyInterface1 implements MyInterface0 {\n" |
3665 "}\n" | 3614 "}\n" |
3666 "MyClass0 getMyClass0() { return new MyClass0(); }\n" | 3615 "MyClass0 getMyClass0() { return new MyClass0(); }\n" |
3667 "MyClass1 getMyClass1() { return new MyClass1(); }\n" | 3616 "MyClass1 getMyClass1() { return new MyClass1(); }\n" |
3668 "MyClass2 getMyClass2() { return new MyClass2(); }\n" | 3617 "MyClass2 getMyClass2() { return new MyClass2(); }\n" |
3669 "Type getMyClass0Type() { return new MyClass0().runtimeType; }\n" | 3618 "Type getMyClass0Type() { return new MyClass0().runtimeType; }\n" |
3670 "Type getMyClass1Type() { return new MyClass1().runtimeType; }\n" | 3619 "Type getMyClass1Type() { return new MyClass1().runtimeType; }\n" |
3671 "Type getMyClass2Type() { return new MyClass2().runtimeType; }\n"; | 3620 "Type getMyClass2Type() { return new MyClass2().runtimeType; }\n"; |
3672 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3621 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3673 bool instanceof = false; | 3622 bool instanceOf = false; |
3674 | 3623 |
3675 // First get the type objects of these non parameterized types. | 3624 // First get the type objects of these non parameterized types. |
3676 Dart_Handle type0 = Dart_GetType(lib, NewString("MyClass0"), 0, NULL); | 3625 Dart_Handle type0 = Dart_GetType(lib, NewString("MyClass0"), 0, NULL); |
3677 EXPECT_VALID(type0); | 3626 EXPECT_VALID(type0); |
3678 Dart_Handle type1 = Dart_GetType(lib, NewString("MyClass1"), 0, NULL); | 3627 Dart_Handle type1 = Dart_GetType(lib, NewString("MyClass1"), 0, NULL); |
3679 EXPECT_VALID(type1); | 3628 EXPECT_VALID(type1); |
3680 Dart_Handle type2 = Dart_GetType(lib, NewString("MyClass2"), 0, NULL); | 3629 Dart_Handle type2 = Dart_GetType(lib, NewString("MyClass2"), 0, NULL); |
3681 EXPECT_VALID(type2); | 3630 EXPECT_VALID(type2); |
3682 Dart_Handle type3 = Dart_GetType(lib, NewString("MyInterface0"), 0, NULL); | 3631 Dart_Handle type3 = Dart_GetType(lib, NewString("MyInterface0"), 0, NULL); |
3683 EXPECT_VALID(type3); | 3632 EXPECT_VALID(type3); |
3684 Dart_Handle type4 = Dart_GetType(lib, NewString("MyInterface1"), 0, NULL); | 3633 Dart_Handle type4 = Dart_GetType(lib, NewString("MyInterface1"), 0, NULL); |
3685 EXPECT_VALID(type4); | 3634 EXPECT_VALID(type4); |
3686 | 3635 |
3687 // Now create objects of these non parameterized types and check | 3636 // Now create objects of these non parameterized types and check |
3688 // that the validity of the type of the created object. | 3637 // that the validity of the type of the created object. |
3689 // MyClass0 type. | 3638 // MyClass0 type. |
3690 Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL); | 3639 Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL); |
3691 EXPECT_VALID(type0_obj); | 3640 EXPECT_VALID(type0_obj); |
3692 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type0, &instanceof)); | 3641 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type0, &instanceOf)); |
3693 EXPECT(instanceof); | 3642 EXPECT(instanceOf); |
3694 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type1, &instanceof)); | 3643 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type1, &instanceOf)); |
3695 EXPECT(!instanceof); | 3644 EXPECT(!instanceOf); |
3696 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type2, &instanceof)); | 3645 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type2, &instanceOf)); |
3697 EXPECT(!instanceof); | 3646 EXPECT(!instanceOf); |
3698 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type3, &instanceof)); | 3647 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type3, &instanceOf)); |
3699 EXPECT(!instanceof); | 3648 EXPECT(!instanceOf); |
3700 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type4, &instanceof)); | 3649 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type4, &instanceOf)); |
3701 EXPECT(!instanceof); | 3650 EXPECT(!instanceOf); |
3702 type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL); | 3651 type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL); |
3703 EXPECT_VALID(type0_obj); | 3652 EXPECT_VALID(type0_obj); |
3704 EXPECT(Dart_IdentityEquals(type0, type0_obj)); | 3653 EXPECT(Dart_IdentityEquals(type0, type0_obj)); |
3705 | 3654 |
3706 // MyClass1 type. | 3655 // MyClass1 type. |
3707 Dart_Handle type1_obj = Dart_Invoke(lib, NewString("getMyClass1"), 0, NULL); | 3656 Dart_Handle type1_obj = Dart_Invoke(lib, NewString("getMyClass1"), 0, NULL); |
3708 EXPECT_VALID(type1_obj); | 3657 EXPECT_VALID(type1_obj); |
3709 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type1, &instanceof)); | 3658 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type1, &instanceOf)); |
3710 EXPECT(instanceof); | 3659 EXPECT(instanceOf); |
3711 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type0, &instanceof)); | 3660 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type0, &instanceOf)); |
3712 EXPECT(!instanceof); | 3661 EXPECT(!instanceOf); |
3713 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type2, &instanceof)); | 3662 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type2, &instanceOf)); |
3714 EXPECT(!instanceof); | 3663 EXPECT(!instanceOf); |
3715 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type3, &instanceof)); | 3664 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type3, &instanceOf)); |
3716 EXPECT(instanceof); | 3665 EXPECT(instanceOf); |
3717 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type4, &instanceof)); | 3666 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type4, &instanceOf)); |
3718 EXPECT(instanceof); | 3667 EXPECT(instanceOf); |
3719 type1_obj = Dart_Invoke(lib, NewString("getMyClass1Type"), 0, NULL); | 3668 type1_obj = Dart_Invoke(lib, NewString("getMyClass1Type"), 0, NULL); |
3720 EXPECT_VALID(type1_obj); | 3669 EXPECT_VALID(type1_obj); |
3721 EXPECT(Dart_IdentityEquals(type1, type1_obj)); | 3670 EXPECT(Dart_IdentityEquals(type1, type1_obj)); |
3722 | 3671 |
3723 // MyClass2 type. | 3672 // MyClass2 type. |
3724 Dart_Handle type2_obj = Dart_Invoke(lib, NewString("getMyClass2"), 0, NULL); | 3673 Dart_Handle type2_obj = Dart_Invoke(lib, NewString("getMyClass2"), 0, NULL); |
3725 EXPECT_VALID(type2_obj); | 3674 EXPECT_VALID(type2_obj); |
3726 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type2, &instanceof)); | 3675 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type2, &instanceOf)); |
3727 EXPECT(instanceof); | 3676 EXPECT(instanceOf); |
3728 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type0, &instanceof)); | 3677 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type0, &instanceOf)); |
3729 EXPECT(!instanceof); | 3678 EXPECT(!instanceOf); |
3730 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type1, &instanceof)); | 3679 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type1, &instanceOf)); |
3731 EXPECT(!instanceof); | 3680 EXPECT(!instanceOf); |
3732 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type3, &instanceof)); | 3681 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type3, &instanceOf)); |
3733 EXPECT(instanceof); | 3682 EXPECT(instanceOf); |
3734 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type4, &instanceof)); | 3683 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type4, &instanceOf)); |
3735 EXPECT(instanceof); | 3684 EXPECT(instanceOf); |
3736 type2_obj = Dart_Invoke(lib, NewString("getMyClass2Type"), 0, NULL); | 3685 type2_obj = Dart_Invoke(lib, NewString("getMyClass2Type"), 0, NULL); |
3737 EXPECT_VALID(type2_obj); | 3686 EXPECT_VALID(type2_obj); |
3738 EXPECT(Dart_IdentityEquals(type2, type2_obj)); | 3687 EXPECT(Dart_IdentityEquals(type2, type2_obj)); |
3739 } | 3688 } |
3740 | 3689 |
3741 | 3690 |
3742 TEST_CASE(TypeGetParameterizedTypes) { | 3691 TEST_CASE(TypeGetParameterizedTypes) { |
3743 const char* kScriptChars = | 3692 const char* kScriptChars = |
3744 "class MyClass0<A, B> {\n" | 3693 "class MyClass0<A, B> {\n" |
3745 "}\n" | 3694 "}\n" |
(...skipping 18 matching lines...) Expand all Loading... |
3764 "Type getMyClass0_1Type() {\n" | 3713 "Type getMyClass0_1Type() {\n" |
3765 " return new MyClass0<double, int>().runtimeType;\n" | 3714 " return new MyClass0<double, int>().runtimeType;\n" |
3766 "}\n" | 3715 "}\n" |
3767 "MyClass1 getMyClass1_1() {\n" | 3716 "MyClass1 getMyClass1_1() {\n" |
3768 " return new MyClass1<List<int>, List<double>>();\n" | 3717 " return new MyClass1<List<int>, List<double>>();\n" |
3769 "}\n" | 3718 "}\n" |
3770 "Type getMyClass1_1Type() {\n" | 3719 "Type getMyClass1_1Type() {\n" |
3771 " return new MyClass1<List<int>, List<double>>().runtimeType;\n" | 3720 " return new MyClass1<List<int>, List<double>>().runtimeType;\n" |
3772 "}\n"; | 3721 "}\n"; |
3773 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3722 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3774 bool instanceof = false; | 3723 bool instanceOf = false; |
3775 | 3724 |
3776 // First get type objects of some of the basic types used in the test. | 3725 // First get type objects of some of the basic types used in the test. |
3777 Dart_Handle int_type = Dart_GetType(lib, NewString("int"), 0, NULL); | 3726 Dart_Handle int_type = Dart_GetType(lib, NewString("int"), 0, NULL); |
3778 EXPECT_VALID(int_type); | 3727 EXPECT_VALID(int_type); |
3779 Dart_Handle double_type = Dart_GetType(lib, NewString("double"), 0, NULL); | 3728 Dart_Handle double_type = Dart_GetType(lib, NewString("double"), 0, NULL); |
3780 EXPECT_VALID(double_type); | 3729 EXPECT_VALID(double_type); |
3781 Dart_Handle list_type = Dart_GetType(lib, NewString("List"), 0, NULL); | 3730 Dart_Handle list_type = Dart_GetType(lib, NewString("List"), 0, NULL); |
3782 EXPECT_VALID(list_type); | 3731 EXPECT_VALID(list_type); |
3783 Dart_Handle type_args = Dart_NewList(1); | 3732 Dart_Handle type_args = Dart_NewList(1); |
3784 EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type)); | 3733 EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type)); |
3785 Dart_Handle list_int_type = Dart_GetType(lib, | 3734 Dart_Handle list_int_type = |
3786 NewString("List"), | 3735 Dart_GetType(lib, NewString("List"), 1, &type_args); |
3787 1, | |
3788 &type_args); | |
3789 EXPECT_VALID(list_int_type); | 3736 EXPECT_VALID(list_int_type); |
3790 | 3737 |
3791 // Now instantiate MyClass0 and MyClass1 types with the same type arguments | 3738 // Now instantiate MyClass0 and MyClass1 types with the same type arguments |
3792 // used in the code above. | 3739 // used in the code above. |
3793 type_args = Dart_NewList(2); | 3740 type_args = Dart_NewList(2); |
3794 EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type)); | 3741 EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type)); |
3795 EXPECT_VALID(Dart_ListSetAt(type_args, 1, double_type)); | 3742 EXPECT_VALID(Dart_ListSetAt(type_args, 1, double_type)); |
3796 Dart_Handle myclass0_type = Dart_GetType(lib, | 3743 Dart_Handle myclass0_type = |
3797 NewString("MyClass0"), | 3744 Dart_GetType(lib, NewString("MyClass0"), 2, &type_args); |
3798 2, | |
3799 &type_args); | |
3800 EXPECT_VALID(myclass0_type); | 3745 EXPECT_VALID(myclass0_type); |
3801 | 3746 |
3802 type_args = Dart_NewList(2); | 3747 type_args = Dart_NewList(2); |
3803 EXPECT_VALID(Dart_ListSetAt(type_args, 0, list_int_type)); | 3748 EXPECT_VALID(Dart_ListSetAt(type_args, 0, list_int_type)); |
3804 EXPECT_VALID(Dart_ListSetAt(type_args, 1, list_type)); | 3749 EXPECT_VALID(Dart_ListSetAt(type_args, 1, list_type)); |
3805 Dart_Handle myclass1_type = Dart_GetType(lib, | 3750 Dart_Handle myclass1_type = |
3806 NewString("MyClass1"), | 3751 Dart_GetType(lib, NewString("MyClass1"), 2, &type_args); |
3807 2, | |
3808 &type_args); | |
3809 EXPECT_VALID(myclass1_type); | 3752 EXPECT_VALID(myclass1_type); |
3810 | 3753 |
3811 // Now create objects of the type and validate the object type matches | 3754 // Now create objects of the type and validate the object type matches |
3812 // the one returned above. Also get the runtime type of the object and | 3755 // the one returned above. Also get the runtime type of the object and |
3813 // verify that it matches the type returned above. | 3756 // verify that it matches the type returned above. |
3814 // MyClass0<int, double> type. | 3757 // MyClass0<int, double> type. |
3815 Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL); | 3758 Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL); |
3816 EXPECT_VALID(type0_obj); | 3759 EXPECT_VALID(type0_obj); |
3817 EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceof)); | 3760 EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceOf)); |
3818 EXPECT(instanceof); | 3761 EXPECT(instanceOf); |
3819 type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL); | 3762 type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL); |
3820 EXPECT_VALID(type0_obj); | 3763 EXPECT_VALID(type0_obj); |
3821 EXPECT(Dart_IdentityEquals(type0_obj, myclass0_type)); | 3764 EXPECT(Dart_IdentityEquals(type0_obj, myclass0_type)); |
3822 | 3765 |
3823 // MyClass1<List<int>, List> type. | 3766 // MyClass1<List<int>, List> type. |
3824 Dart_Handle type1_obj = Dart_Invoke(lib, NewString("getMyClass1"), 0, NULL); | 3767 Dart_Handle type1_obj = Dart_Invoke(lib, NewString("getMyClass1"), 0, NULL); |
3825 EXPECT_VALID(type1_obj); | 3768 EXPECT_VALID(type1_obj); |
3826 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceof)); | 3769 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceOf)); |
3827 EXPECT(instanceof); | 3770 EXPECT(instanceOf); |
3828 type1_obj = Dart_Invoke(lib, NewString("getMyClass1Type"), 0, NULL); | 3771 type1_obj = Dart_Invoke(lib, NewString("getMyClass1Type"), 0, NULL); |
3829 EXPECT_VALID(type1_obj); | 3772 EXPECT_VALID(type1_obj); |
3830 EXPECT(Dart_IdentityEquals(type1_obj, myclass1_type)); | 3773 EXPECT(Dart_IdentityEquals(type1_obj, myclass1_type)); |
3831 | 3774 |
3832 // MyClass0<double, int> type. | 3775 // MyClass0<double, int> type. |
3833 type0_obj = Dart_Invoke(lib, NewString("getMyClass0_1"), 0, NULL); | 3776 type0_obj = Dart_Invoke(lib, NewString("getMyClass0_1"), 0, NULL); |
3834 EXPECT_VALID(type0_obj); | 3777 EXPECT_VALID(type0_obj); |
3835 EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceof)); | 3778 EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceOf)); |
3836 EXPECT(!instanceof); | 3779 EXPECT(!instanceOf); |
3837 type0_obj = Dart_Invoke(lib, NewString("getMyClass0_1Type"), 0, NULL); | 3780 type0_obj = Dart_Invoke(lib, NewString("getMyClass0_1Type"), 0, NULL); |
3838 EXPECT_VALID(type0_obj); | 3781 EXPECT_VALID(type0_obj); |
3839 EXPECT(!Dart_IdentityEquals(type0_obj, myclass0_type)); | 3782 EXPECT(!Dart_IdentityEquals(type0_obj, myclass0_type)); |
3840 | 3783 |
3841 // MyClass1<List<int>, List<double>> type. | 3784 // MyClass1<List<int>, List<double>> type. |
3842 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1"), 0, NULL); | 3785 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1"), 0, NULL); |
3843 EXPECT_VALID(type1_obj); | 3786 EXPECT_VALID(type1_obj); |
3844 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceof)); | 3787 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceOf)); |
3845 EXPECT(instanceof); | 3788 EXPECT(instanceOf); |
3846 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1Type"), 0, NULL); | 3789 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1Type"), 0, NULL); |
3847 EXPECT_VALID(type1_obj); | 3790 EXPECT_VALID(type1_obj); |
3848 EXPECT(!Dart_IdentityEquals(type1_obj, myclass1_type)); | 3791 EXPECT(!Dart_IdentityEquals(type1_obj, myclass1_type)); |
3849 } | 3792 } |
3850 | 3793 |
3851 | 3794 |
3852 static void TestFieldOk(Dart_Handle container, | 3795 static void TestFieldOk(Dart_Handle container, |
3853 Dart_Handle name, | 3796 Dart_Handle name, |
3854 bool final, | 3797 bool final, |
3855 const char* initial_value) { | 3798 const char* initial_value) { |
(...skipping 24 matching lines...) Expand all Loading... |
3880 EXPECT_VALID(result); | 3823 EXPECT_VALID(result); |
3881 EXPECT_VALID(Dart_StringToCString(result, &value)); | 3824 EXPECT_VALID(Dart_StringToCString(result, &value)); |
3882 if (final) { | 3825 if (final) { |
3883 EXPECT_STREQ(initial_value, value); | 3826 EXPECT_STREQ(initial_value, value); |
3884 } else { | 3827 } else { |
3885 EXPECT_STREQ(buffer, value); | 3828 EXPECT_STREQ(buffer, value); |
3886 } | 3829 } |
3887 } | 3830 } |
3888 | 3831 |
3889 | 3832 |
3890 static void TestFieldNotFound(Dart_Handle container, | 3833 static void TestFieldNotFound(Dart_Handle container, Dart_Handle name) { |
3891 Dart_Handle name) { | |
3892 EXPECT(Dart_IsError(Dart_GetField(container, name))); | 3834 EXPECT(Dart_IsError(Dart_GetField(container, name))); |
3893 EXPECT(Dart_IsError(Dart_SetField(container, name, Dart_Null()))); | 3835 EXPECT(Dart_IsError(Dart_SetField(container, name, Dart_Null()))); |
3894 } | 3836 } |
3895 | 3837 |
3896 | 3838 |
3897 TEST_CASE(FieldAccess) { | 3839 TEST_CASE(FieldAccess) { |
3898 const char* kScriptChars = | 3840 const char* kScriptChars = |
3899 "class BaseFields {\n" | 3841 "class BaseFields {\n" |
3900 " BaseFields()\n" | 3842 " BaseFields()\n" |
3901 " : this.inherited_fld = 'inherited' {\n" | 3843 " : this.inherited_fld = 'inherited' {\n" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4140 | 4082 |
4141 // Hidden imported top-level get/set field. Not found at any level. | 4083 // Hidden imported top-level get/set field. Not found at any level. |
4142 name = NewString("_imported_getset_fld"); | 4084 name = NewString("_imported_getset_fld"); |
4143 TestFieldNotFound(type, name); | 4085 TestFieldNotFound(type, name); |
4144 TestFieldNotFound(instance, name); | 4086 TestFieldNotFound(instance, name); |
4145 TestFieldNotFound(lib, name); | 4087 TestFieldNotFound(lib, name); |
4146 } | 4088 } |
4147 | 4089 |
4148 | 4090 |
4149 TEST_CASE(SetField_FunnyValue) { | 4091 TEST_CASE(SetField_FunnyValue) { |
4150 const char* kScriptChars = | 4092 const char* kScriptChars = "var top;\n"; |
4151 "var top;\n"; | |
4152 | 4093 |
4153 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4094 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4154 Dart_Handle name = NewString("top"); | 4095 Dart_Handle name = NewString("top"); |
4155 bool value; | 4096 bool value; |
4156 | 4097 |
4157 // Test that you can set the field to a good value. | 4098 // Test that you can set the field to a good value. |
4158 EXPECT_VALID(Dart_SetField(lib, name, Dart_True())); | 4099 EXPECT_VALID(Dart_SetField(lib, name, Dart_True())); |
4159 Dart_Handle result = Dart_GetField(lib, name); | 4100 Dart_Handle result = Dart_GetField(lib, name); |
4160 EXPECT_VALID(result); | 4101 EXPECT_VALID(result); |
4161 EXPECT(Dart_IsBoolean(result)); | 4102 EXPECT(Dart_IsBoolean(result)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4206 "}\n" | 4147 "}\n" |
4207 "NativeFields testMain() {\n" | 4148 "NativeFields testMain() {\n" |
4208 " NativeFields obj = new NativeFields(10, 20);\n" | 4149 " NativeFields obj = new NativeFields(10, 20);\n" |
4209 " return obj;\n" | 4150 " return obj;\n" |
4210 "}\n"; | 4151 "}\n"; |
4211 Dart_Handle result; | 4152 Dart_Handle result; |
4212 | 4153 |
4213 const int kNumNativeFields = 4; | 4154 const int kNumNativeFields = 4; |
4214 | 4155 |
4215 // Create a test library. | 4156 // Create a test library. |
4216 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL, | 4157 Dart_Handle lib = |
4217 USER_TEST_URI, false); | 4158 TestCase::LoadTestScript(kScriptChars, NULL, USER_TEST_URI, false); |
4218 | 4159 |
4219 // Create a native wrapper class with native fields. | 4160 // Create a native wrapper class with native fields. |
4220 result = Dart_CreateNativeWrapperClass( | 4161 result = Dart_CreateNativeWrapperClass(lib, NewString("NativeFieldsWrapper"), |
4221 lib, | 4162 kNumNativeFields); |
4222 NewString("NativeFieldsWrapper"), | |
4223 kNumNativeFields); | |
4224 EXPECT_VALID(result); | 4163 EXPECT_VALID(result); |
4225 result = Dart_FinalizeLoading(false); | 4164 result = Dart_FinalizeLoading(false); |
4226 EXPECT_VALID(result); | 4165 EXPECT_VALID(result); |
4227 | 4166 |
4228 // Load up a test script in the test library. | 4167 // Load up a test script in the test library. |
4229 | 4168 |
4230 // Invoke a function which returns an object of type NativeFields. | 4169 // Invoke a function which returns an object of type NativeFields. |
4231 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4170 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4232 EXPECT_VALID(result); | 4171 EXPECT_VALID(result); |
4233 CHECK_API_SCOPE(thread); | 4172 CHECK_API_SCOPE(thread); |
4234 HANDLESCOPE(thread); | 4173 HANDLESCOPE(thread); |
4235 Instance& obj = Instance::Handle(); | 4174 Instance& obj = Instance::Handle(); |
4236 obj ^= Api::UnwrapHandle(result); | 4175 obj ^= Api::UnwrapHandle(result); |
4237 const Class& cls = Class::Handle(obj.clazz()); | 4176 const Class& cls = Class::Handle(obj.clazz()); |
4238 // We expect the newly created "NativeFields" object to have | 4177 // We expect the newly created "NativeFields" object to have |
4239 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4178 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
4240 // Hence the size of an instance of "NativeFields" should be | 4179 // Hence the size of an instance of "NativeFields" should be |
4241 // (1 + 2) * kWordSize + size of object header. | 4180 // (1 + 2) * kWordSize + size of object header. |
4242 // We check to make sure the instance size computed by the VM matches | 4181 // We check to make sure the instance size computed by the VM matches |
4243 // our expectations. | 4182 // our expectations. |
4244 intptr_t header_size = sizeof(RawObject); | 4183 intptr_t header_size = sizeof(RawObject); |
4245 EXPECT_EQ(Utils::RoundUp(((1 + 2) * kWordSize) + header_size, | 4184 EXPECT_EQ( |
4246 kObjectAlignment), | 4185 Utils::RoundUp(((1 + 2) * kWordSize) + header_size, kObjectAlignment), |
4247 cls.instance_size()); | 4186 cls.instance_size()); |
4248 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); | 4187 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); |
4249 } | 4188 } |
4250 | 4189 |
4251 | 4190 |
4252 TEST_CASE(InjectNativeFields2) { | 4191 TEST_CASE(InjectNativeFields2) { |
4253 const char* kScriptChars = | 4192 const char* kScriptChars = |
4254 "class NativeFields extends NativeFieldsWrapper {\n" | 4193 "class NativeFields extends NativeFieldsWrapper {\n" |
4255 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4194 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4256 " int fld1;\n" | 4195 " int fld1;\n" |
4257 " final int fld2;\n" | 4196 " final int fld2;\n" |
4258 " static int fld3;\n" | 4197 " static int fld3;\n" |
4259 " static const int fld4 = 10;\n" | 4198 " static const int fld4 = 10;\n" |
4260 "}\n" | 4199 "}\n" |
4261 "NativeFields testMain() {\n" | 4200 "NativeFields testMain() {\n" |
4262 " NativeFields obj = new NativeFields(10, 20);\n" | 4201 " NativeFields obj = new NativeFields(10, 20);\n" |
4263 " return obj;\n" | 4202 " return obj;\n" |
4264 "}\n"; | 4203 "}\n"; |
4265 Dart_Handle result; | 4204 Dart_Handle result; |
4266 // Create a test library and Load up a test script in it. | 4205 // Create a test library and Load up a test script in it. |
4267 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL, | 4206 Dart_Handle lib = |
4268 USER_TEST_URI, false); | 4207 TestCase::LoadTestScript(kScriptChars, NULL, USER_TEST_URI, false); |
4269 | 4208 |
4270 // Invoke a function which returns an object of type NativeFields. | 4209 // Invoke a function which returns an object of type NativeFields. |
4271 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4210 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4272 | 4211 |
4273 // We expect this to fail as class "NativeFields" extends | 4212 // We expect this to fail as class "NativeFields" extends |
4274 // "NativeFieldsWrapper" and there is no definition of it either | 4213 // "NativeFieldsWrapper" and there is no definition of it either |
4275 // in the dart code or through the native field injection mechanism. | 4214 // in the dart code or through the native field injection mechanism. |
4276 EXPECT(Dart_IsError(result)); | 4215 EXPECT(Dart_IsError(result)); |
4277 } | 4216 } |
4278 | 4217 |
4279 | 4218 |
4280 TEST_CASE(InjectNativeFields3) { | 4219 TEST_CASE(InjectNativeFields3) { |
4281 const char* kScriptChars = | 4220 const char* kScriptChars = |
4282 "import 'dart:nativewrappers';" | 4221 "import 'dart:nativewrappers';" |
4283 "class NativeFields extends NativeFieldWrapperClass2 {\n" | 4222 "class NativeFields extends NativeFieldWrapperClass2 {\n" |
4284 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4223 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4285 " int fld1;\n" | 4224 " int fld1;\n" |
4286 " final int fld2;\n" | 4225 " final int fld2;\n" |
4287 " static int fld3;\n" | 4226 " static int fld3;\n" |
4288 " static const int fld4 = 10;\n" | 4227 " static const int fld4 = 10;\n" |
4289 "}\n" | 4228 "}\n" |
4290 "NativeFields testMain() {\n" | 4229 "NativeFields testMain() {\n" |
4291 " NativeFields obj = new NativeFields(10, 20);\n" | 4230 " NativeFields obj = new NativeFields(10, 20);\n" |
4292 " return obj;\n" | 4231 " return obj;\n" |
4293 "}\n"; | 4232 "}\n"; |
4294 Dart_Handle result; | 4233 Dart_Handle result; |
4295 const int kNumNativeFields = 2; | 4234 const int kNumNativeFields = 2; |
4296 | 4235 |
4297 // Load up a test script in the test library. | 4236 // Load up a test script in the test library. |
4298 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4237 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); |
4299 native_field_lookup); | |
4300 | 4238 |
4301 // Invoke a function which returns an object of type NativeFields. | 4239 // Invoke a function which returns an object of type NativeFields. |
4302 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4240 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4303 EXPECT_VALID(result); | 4241 EXPECT_VALID(result); |
4304 CHECK_API_SCOPE(thread); | 4242 CHECK_API_SCOPE(thread); |
4305 HANDLESCOPE(thread); | 4243 HANDLESCOPE(thread); |
4306 Instance& obj = Instance::Handle(); | 4244 Instance& obj = Instance::Handle(); |
4307 obj ^= Api::UnwrapHandle(result); | 4245 obj ^= Api::UnwrapHandle(result); |
4308 const Class& cls = Class::Handle(obj.clazz()); | 4246 const Class& cls = Class::Handle(obj.clazz()); |
4309 // We expect the newly created "NativeFields" object to have | 4247 // We expect the newly created "NativeFields" object to have |
4310 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4248 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
4311 // Hence the size of an instance of "NativeFields" should be | 4249 // Hence the size of an instance of "NativeFields" should be |
4312 // (1 + 2) * kWordSize + size of object header. | 4250 // (1 + 2) * kWordSize + size of object header. |
4313 // We check to make sure the instance size computed by the VM matches | 4251 // We check to make sure the instance size computed by the VM matches |
4314 // our expectations. | 4252 // our expectations. |
4315 intptr_t header_size = sizeof(RawObject); | 4253 intptr_t header_size = sizeof(RawObject); |
4316 EXPECT_EQ(Utils::RoundUp(((1 + 2) * kWordSize) + header_size, | 4254 EXPECT_EQ( |
4317 kObjectAlignment), | 4255 Utils::RoundUp(((1 + 2) * kWordSize) + header_size, kObjectAlignment), |
4318 cls.instance_size()); | 4256 cls.instance_size()); |
4319 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); | 4257 EXPECT_EQ(kNumNativeFields, cls.num_native_fields()); |
4320 } | 4258 } |
4321 | 4259 |
4322 | 4260 |
4323 TEST_CASE(InjectNativeFields4) { | 4261 TEST_CASE(InjectNativeFields4) { |
4324 const char* kScriptChars = | 4262 const char* kScriptChars = |
4325 "import 'dart:nativewrappers';" | 4263 "import 'dart:nativewrappers';" |
4326 "class NativeFields extends NativeFieldWrapperClass2 {\n" | 4264 "class NativeFields extends NativeFieldWrapperClass2 {\n" |
4327 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" | 4265 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" |
4328 " int fld1;\n" | 4266 " int fld1;\n" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4362 | 4300 |
4363 void TestNativeFieldsAccess_init(Dart_NativeArguments args) { | 4301 void TestNativeFieldsAccess_init(Dart_NativeArguments args) { |
4364 Dart_Handle receiver = Dart_GetNativeArgument(args, 0); | 4302 Dart_Handle receiver = Dart_GetNativeArgument(args, 0); |
4365 Dart_SetNativeInstanceField(receiver, 0, kNativeField1Value); | 4303 Dart_SetNativeInstanceField(receiver, 0, kNativeField1Value); |
4366 Dart_SetNativeInstanceField(receiver, 1, kNativeField2Value); | 4304 Dart_SetNativeInstanceField(receiver, 1, kNativeField2Value); |
4367 } | 4305 } |
4368 | 4306 |
4369 | 4307 |
4370 void TestNativeFieldsAccess_access(Dart_NativeArguments args) { | 4308 void TestNativeFieldsAccess_access(Dart_NativeArguments args) { |
4371 intptr_t field_values[kTestNumNativeFields]; | 4309 intptr_t field_values[kTestNumNativeFields]; |
4372 Dart_Handle result = Dart_GetNativeFieldsOfArgument(args, | 4310 Dart_Handle result = Dart_GetNativeFieldsOfArgument( |
4373 0, | 4311 args, 0, kTestNumNativeFields, field_values); |
4374 kTestNumNativeFields, | |
4375 field_values); | |
4376 EXPECT_VALID(result); | 4312 EXPECT_VALID(result); |
4377 EXPECT_EQ(kNativeField1Value, field_values[0]); | 4313 EXPECT_EQ(kNativeField1Value, field_values[0]); |
4378 EXPECT_EQ(kNativeField2Value, field_values[1]); | 4314 EXPECT_EQ(kNativeField2Value, field_values[1]); |
4379 result = Dart_GetNativeFieldsOfArgument(args, | 4315 result = Dart_GetNativeFieldsOfArgument(args, 1, kTestNumNativeFields, |
4380 1, | |
4381 kTestNumNativeFields, | |
4382 field_values); | 4316 field_values); |
4383 EXPECT_VALID(result); | 4317 EXPECT_VALID(result); |
4384 EXPECT_EQ(0, field_values[0]); | 4318 EXPECT_EQ(0, field_values[0]); |
4385 EXPECT_EQ(0, field_values[1]); | 4319 EXPECT_EQ(0, field_values[1]); |
4386 } | 4320 } |
4387 | 4321 |
4388 | 4322 |
4389 static Dart_NativeFunction TestNativeFieldsAccess_lookup(Dart_Handle name, | 4323 static Dart_NativeFunction TestNativeFieldsAccess_lookup(Dart_Handle name, |
4390 int argument_count, | 4324 int argument_count, |
4391 bool* auto_scope) { | 4325 bool* auto_scope) { |
(...skipping 29 matching lines...) Expand all Loading... |
4421 " int accessNativeFlds(int i) native 'TestNativeFieldsAccess_access';\n" | 4355 " int accessNativeFlds(int i) native 'TestNativeFieldsAccess_access';\n" |
4422 "}\n" | 4356 "}\n" |
4423 "NativeFields testMain() {\n" | 4357 "NativeFields testMain() {\n" |
4424 " NativeFields obj = new NativeFields(10, 20);\n" | 4358 " NativeFields obj = new NativeFields(10, 20);\n" |
4425 " obj.initNativeFlds();\n" | 4359 " obj.initNativeFlds();\n" |
4426 " obj.accessNativeFlds(null);\n" | 4360 " obj.accessNativeFlds(null);\n" |
4427 " return obj;\n" | 4361 " return obj;\n" |
4428 "}\n"; | 4362 "}\n"; |
4429 | 4363 |
4430 // Load up a test script in the test library. | 4364 // Load up a test script in the test library. |
4431 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4365 Dart_Handle lib = |
4432 TestNativeFieldsAccess_lookup); | 4366 TestCase::LoadTestScript(kScriptChars, TestNativeFieldsAccess_lookup); |
4433 | 4367 |
4434 // Invoke a function which returns an object of type NativeFields. | 4368 // Invoke a function which returns an object of type NativeFields. |
4435 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4369 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4436 EXPECT_VALID(result); | 4370 EXPECT_VALID(result); |
4437 } | 4371 } |
4438 | 4372 |
4439 | 4373 |
4440 TEST_CASE(InjectNativeFieldsSuperClass) { | 4374 TEST_CASE(InjectNativeFieldsSuperClass) { |
4441 const char* kScriptChars = | 4375 const char* kScriptChars = |
4442 "import 'dart:nativewrappers';" | 4376 "import 'dart:nativewrappers';" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4476 EXPECT(Dart_IsNull(result)); | 4410 EXPECT(Dart_IsNull(result)); |
4477 result = Dart_GetField(retobj, NewString("fld1")); | 4411 result = Dart_GetField(retobj, NewString("fld1")); |
4478 EXPECT_VALID(result); | 4412 EXPECT_VALID(result); |
4479 int64_t value = 0; | 4413 int64_t value = 0; |
4480 result = Dart_IntegerToInt64(result, &value); | 4414 result = Dart_IntegerToInt64(result, &value); |
4481 EXPECT_EQ(10, value); | 4415 EXPECT_EQ(10, value); |
4482 result = Dart_GetField(retobj, NewString("fld2")); | 4416 result = Dart_GetField(retobj, NewString("fld2")); |
4483 EXPECT_VALID(result); | 4417 EXPECT_VALID(result); |
4484 result = Dart_IntegerToInt64(result, &value); | 4418 result = Dart_IntegerToInt64(result, &value); |
4485 EXPECT_EQ(20, value); | 4419 EXPECT_EQ(20, value); |
4486 result = Dart_SetField(retobj, | 4420 result = Dart_SetField(retobj, NewString("fld2"), Dart_NewInteger(40)); |
4487 NewString("fld2"), | |
4488 Dart_NewInteger(40)); | |
4489 EXPECT(Dart_IsError(result)); | 4421 EXPECT(Dart_IsError(result)); |
4490 result = Dart_SetField(retobj, | 4422 result = Dart_SetField(retobj, NewString("fld1"), Dart_NewInteger(40)); |
4491 NewString("fld1"), | |
4492 Dart_NewInteger(40)); | |
4493 EXPECT_VALID(result); | 4423 EXPECT_VALID(result); |
4494 result = Dart_GetField(retobj, NewString("fld1")); | 4424 result = Dart_GetField(retobj, NewString("fld1")); |
4495 EXPECT_VALID(result); | 4425 EXPECT_VALID(result); |
4496 result = Dart_IntegerToInt64(result, &value); | 4426 result = Dart_IntegerToInt64(result, &value); |
4497 EXPECT_EQ(40, value); | 4427 EXPECT_EQ(40, value); |
4498 | 4428 |
4499 // Now access and set various native instance fields of the returned object. | 4429 // Now access and set various native instance fields of the returned object. |
4500 const int kNativeFld0 = 0; | 4430 const int kNativeFld0 = 0; |
4501 const int kNativeFld1 = 1; | 4431 const int kNativeFld1 = 1; |
4502 const int kNativeFld2 = 2; | 4432 const int kNativeFld2 = 2; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4557 " static int fld3;\n" | 4487 " static int fld3;\n" |
4558 " static const int fld4 = 10;\n" | 4488 " static const int fld4 = 10;\n" |
4559 "}\n" | 4489 "}\n" |
4560 "NativeFields testMain() {\n" | 4490 "NativeFields testMain() {\n" |
4561 " NativeFields obj = new NativeFields(10, 20);\n" | 4491 " NativeFields obj = new NativeFields(10, 20);\n" |
4562 " return obj;\n" | 4492 " return obj;\n" |
4563 "}\n"; | 4493 "}\n"; |
4564 const int kNumNativeFields = 4; | 4494 const int kNumNativeFields = 4; |
4565 | 4495 |
4566 // Create a test library. | 4496 // Create a test library. |
4567 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4497 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup, |
4568 native_field_lookup, | 4498 USER_TEST_URI, false); |
4569 USER_TEST_URI, | |
4570 false); | |
4571 | 4499 |
4572 // Create a native wrapper class with native fields. | 4500 // Create a native wrapper class with native fields. |
4573 Dart_Handle result = Dart_CreateNativeWrapperClass( | 4501 Dart_Handle result = Dart_CreateNativeWrapperClass( |
4574 lib, | 4502 lib, NewString("NativeFieldsWrapper"), kNumNativeFields); |
4575 NewString("NativeFieldsWrapper"), | |
4576 kNumNativeFields); | |
4577 EXPECT_VALID(result); | 4503 EXPECT_VALID(result); |
4578 result = Dart_FinalizeLoading(false); | 4504 result = Dart_FinalizeLoading(false); |
4579 EXPECT_VALID(result); | 4505 EXPECT_VALID(result); |
4580 | 4506 |
4581 // Load up a test script in it. | 4507 // Load up a test script in it. |
4582 | 4508 |
4583 // Invoke a function which returns an object of type NativeFields. | 4509 // Invoke a function which returns an object of type NativeFields. |
4584 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4510 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4585 EXPECT_VALID(retobj); | 4511 EXPECT_VALID(retobj); |
4586 | 4512 |
(...skipping 23 matching lines...) Expand all Loading... |
4610 " int fld1;\n" | 4536 " int fld1;\n" |
4611 " final int fld2;\n" | 4537 " final int fld2;\n" |
4612 " static int fld3;\n" | 4538 " static int fld3;\n" |
4613 " static const int fld4 = 10;\n" | 4539 " static const int fld4 = 10;\n" |
4614 "}\n" | 4540 "}\n" |
4615 "NativeFields testMain() {\n" | 4541 "NativeFields testMain() {\n" |
4616 " NativeFields obj = new NativeFields(10, 20);\n" | 4542 " NativeFields obj = new NativeFields(10, 20);\n" |
4617 " return obj;\n" | 4543 " return obj;\n" |
4618 "}\n"; | 4544 "}\n"; |
4619 // Load up a test script in the test library. | 4545 // Load up a test script in the test library. |
4620 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4546 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); |
4621 native_field_lookup); | |
4622 | 4547 |
4623 // Invoke a function which returns an object of type NativeFields. | 4548 // Invoke a function which returns an object of type NativeFields. |
4624 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4549 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4625 EXPECT_VALID(retobj); | 4550 EXPECT_VALID(retobj); |
4626 | 4551 |
4627 // Now access and set various instance fields of the returned object. | 4552 // Now access and set various instance fields of the returned object. |
4628 TestNativeFields(retobj); | 4553 TestNativeFields(retobj); |
4629 } | 4554 } |
4630 | 4555 |
4631 | 4556 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4763 int64_t value = 0; | 4688 int64_t value = 0; |
4764 result = Dart_IntegerToInt64(result, &value); | 4689 result = Dart_IntegerToInt64(result, &value); |
4765 EXPECT_EQ(7, value); | 4690 EXPECT_EQ(7, value); |
4766 | 4691 |
4767 result = Dart_GetField(type, NewString("fld2")); | 4692 result = Dart_GetField(type, NewString("fld2")); |
4768 EXPECT_VALID(result); | 4693 EXPECT_VALID(result); |
4769 result = Dart_IntegerToInt64(result, &value); | 4694 result = Dart_IntegerToInt64(result, &value); |
4770 EXPECT_EQ(11, value); | 4695 EXPECT_EQ(11, value); |
4771 | 4696 |
4772 // Overwrite fld2 | 4697 // Overwrite fld2 |
4773 result = Dart_SetField(type, | 4698 result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13)); |
4774 NewString("fld2"), | |
4775 Dart_NewInteger(13)); | |
4776 EXPECT_VALID(result); | 4699 EXPECT_VALID(result); |
4777 | 4700 |
4778 // We now get the new value for fld2, not the initializer | 4701 // We now get the new value for fld2, not the initializer |
4779 result = Dart_GetField(type, NewString("fld2")); | 4702 result = Dart_GetField(type, NewString("fld2")); |
4780 EXPECT_VALID(result); | 4703 EXPECT_VALID(result); |
4781 result = Dart_IntegerToInt64(result, &value); | 4704 result = Dart_IntegerToInt64(result, &value); |
4782 EXPECT_EQ(13, value); | 4705 EXPECT_EQ(13, value); |
4783 } | 4706 } |
4784 | 4707 |
4785 | 4708 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4864 Dart_Handle intf = Dart_GetType(lib, NewString("MyInterface"), 0, NULL); | 4787 Dart_Handle intf = Dart_GetType(lib, NewString("MyInterface"), 0, NULL); |
4865 EXPECT_VALID(intf); | 4788 EXPECT_VALID(intf); |
4866 Dart_Handle args[1]; | 4789 Dart_Handle args[1]; |
4867 args[0] = Dart_NewInteger(11); | 4790 args[0] = Dart_NewInteger(11); |
4868 Dart_Handle bad_args[1]; | 4791 Dart_Handle bad_args[1]; |
4869 bad_args[0] = Dart_NewApiError("myerror"); | 4792 bad_args[0] = Dart_NewApiError("myerror"); |
4870 | 4793 |
4871 // Allocate and Invoke the unnamed constructor passing in Dart_Null. | 4794 // Allocate and Invoke the unnamed constructor passing in Dart_Null. |
4872 Dart_Handle result = Dart_New(type, Dart_Null(), 0, NULL); | 4795 Dart_Handle result = Dart_New(type, Dart_Null(), 0, NULL); |
4873 EXPECT_VALID(result); | 4796 EXPECT_VALID(result); |
4874 bool instanceof = false; | 4797 bool instanceOf = false; |
4875 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4798 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
4876 EXPECT(instanceof); | 4799 EXPECT(instanceOf); |
4877 int64_t int_value = 0; | 4800 int64_t int_value = 0; |
4878 Dart_Handle foo = Dart_GetField(result, NewString("foo")); | 4801 Dart_Handle foo = Dart_GetField(result, NewString("foo")); |
4879 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4802 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4880 EXPECT_EQ(7, int_value); | 4803 EXPECT_EQ(7, int_value); |
4881 | 4804 |
4882 // Allocate without a constructor. | 4805 // Allocate without a constructor. |
4883 Dart_Handle obj = Dart_Allocate(type); | 4806 Dart_Handle obj = Dart_Allocate(type); |
4884 EXPECT_VALID(obj); | 4807 EXPECT_VALID(obj); |
4885 instanceof = false; | 4808 instanceOf = false; |
4886 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof)); | 4809 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceOf)); |
4887 EXPECT(instanceof); | 4810 EXPECT(instanceOf); |
4888 foo = Dart_GetField(obj, NewString("foo")); | 4811 foo = Dart_GetField(obj, NewString("foo")); |
4889 EXPECT(Dart_IsNull(foo)); | 4812 EXPECT(Dart_IsNull(foo)); |
4890 | 4813 |
4891 // Allocate and Invoke the unnamed constructor passing in an empty string. | 4814 // Allocate and Invoke the unnamed constructor passing in an empty string. |
4892 result = Dart_New(type, Dart_EmptyString(), 0, NULL); | 4815 result = Dart_New(type, Dart_EmptyString(), 0, NULL); |
4893 EXPECT_VALID(result); | 4816 EXPECT_VALID(result); |
4894 instanceof = false; | 4817 instanceOf = false; |
4895 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4818 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
4896 EXPECT(instanceof); | 4819 EXPECT(instanceOf); |
4897 int_value = 0; | 4820 int_value = 0; |
4898 foo = Dart_GetField(result, NewString("foo")); | 4821 foo = Dart_GetField(result, NewString("foo")); |
4899 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4822 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4900 EXPECT_EQ(7, int_value); | 4823 EXPECT_EQ(7, int_value); |
4901 | 4824 |
4902 // Allocate object and invoke the unnamed constructor with an empty string. | 4825 // Allocate object and invoke the unnamed constructor with an empty string. |
4903 obj = Dart_Allocate(type); | 4826 obj = Dart_Allocate(type); |
4904 EXPECT_VALID(obj); | 4827 EXPECT_VALID(obj); |
4905 instanceof = false; | 4828 instanceOf = false; |
4906 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof)); | 4829 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceOf)); |
4907 EXPECT(instanceof); | 4830 EXPECT(instanceOf); |
4908 // Use the empty string to invoke the unnamed constructor. | 4831 // Use the empty string to invoke the unnamed constructor. |
4909 result = Dart_InvokeConstructor(obj, Dart_EmptyString(), 0, NULL); | 4832 result = Dart_InvokeConstructor(obj, Dart_EmptyString(), 0, NULL); |
4910 EXPECT_VALID(result); | 4833 EXPECT_VALID(result); |
4911 int_value = 0; | 4834 int_value = 0; |
4912 foo = Dart_GetField(result, NewString("foo")); | 4835 foo = Dart_GetField(result, NewString("foo")); |
4913 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4836 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4914 EXPECT_EQ(7, int_value); | 4837 EXPECT_EQ(7, int_value); |
4915 // use Dart_Null to invoke the unnamed constructor. | 4838 // use Dart_Null to invoke the unnamed constructor. |
4916 result = Dart_InvokeConstructor(obj, Dart_Null(), 0, NULL); | 4839 result = Dart_InvokeConstructor(obj, Dart_Null(), 0, NULL); |
4917 EXPECT_VALID(result); | 4840 EXPECT_VALID(result); |
4918 int_value = 0; | 4841 int_value = 0; |
4919 foo = Dart_GetField(result, NewString("foo")); | 4842 foo = Dart_GetField(result, NewString("foo")); |
4920 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4843 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4921 EXPECT_EQ(7, int_value); | 4844 EXPECT_EQ(7, int_value); |
4922 | 4845 |
4923 // Invoke a named constructor. | 4846 // Invoke a named constructor. |
4924 result = Dart_New(type, NewString("named"), 1, args); | 4847 result = Dart_New(type, NewString("named"), 1, args); |
4925 EXPECT_VALID(result); | 4848 EXPECT_VALID(result); |
4926 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4849 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
4927 EXPECT(instanceof); | 4850 EXPECT(instanceOf); |
4928 int_value = 0; | 4851 int_value = 0; |
4929 foo = Dart_GetField(result, NewString("foo")); | 4852 foo = Dart_GetField(result, NewString("foo")); |
4930 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4853 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4931 EXPECT_EQ(11, int_value); | 4854 EXPECT_EQ(11, int_value); |
4932 | 4855 |
4933 // Allocate object and invoke a named constructor. | 4856 // Allocate object and invoke a named constructor. |
4934 obj = Dart_Allocate(type); | 4857 obj = Dart_Allocate(type); |
4935 EXPECT_VALID(obj); | 4858 EXPECT_VALID(obj); |
4936 instanceof = false; | 4859 instanceOf = false; |
4937 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof)); | 4860 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceOf)); |
4938 EXPECT(instanceof); | 4861 EXPECT(instanceOf); |
4939 result = Dart_InvokeConstructor(obj, NewString("named"), 1, args); | 4862 result = Dart_InvokeConstructor(obj, NewString("named"), 1, args); |
4940 EXPECT_VALID(result); | 4863 EXPECT_VALID(result); |
4941 int_value = 0; | 4864 int_value = 0; |
4942 foo = Dart_GetField(result, NewString("foo")); | 4865 foo = Dart_GetField(result, NewString("foo")); |
4943 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4866 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4944 EXPECT_EQ(11, int_value); | 4867 EXPECT_EQ(11, int_value); |
4945 | 4868 |
4946 // Invoke a hidden named constructor. | 4869 // Invoke a hidden named constructor. |
4947 result = Dart_New(type, NewString("_hidden"), 1, args); | 4870 result = Dart_New(type, NewString("_hidden"), 1, args); |
4948 EXPECT_VALID(result); | 4871 EXPECT_VALID(result); |
4949 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4872 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
4950 EXPECT(instanceof); | 4873 EXPECT(instanceOf); |
4951 int_value = 0; | 4874 int_value = 0; |
4952 foo = Dart_GetField(result, NewString("foo")); | 4875 foo = Dart_GetField(result, NewString("foo")); |
4953 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4876 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4954 EXPECT_EQ(-11, int_value); | 4877 EXPECT_EQ(-11, int_value); |
4955 | 4878 |
4956 // Allocate object and invoke a hidden named constructor. | 4879 // Allocate object and invoke a hidden named constructor. |
4957 obj = Dart_Allocate(type); | 4880 obj = Dart_Allocate(type); |
4958 EXPECT_VALID(obj); | 4881 EXPECT_VALID(obj); |
4959 instanceof = false; | 4882 instanceOf = false; |
4960 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof)); | 4883 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceOf)); |
4961 EXPECT(instanceof); | 4884 EXPECT(instanceOf); |
4962 result = Dart_InvokeConstructor(obj, NewString("_hidden"), 1, args); | 4885 result = Dart_InvokeConstructor(obj, NewString("_hidden"), 1, args); |
4963 EXPECT_VALID(result); | 4886 EXPECT_VALID(result); |
4964 int_value = 0; | 4887 int_value = 0; |
4965 foo = Dart_GetField(result, NewString("foo")); | 4888 foo = Dart_GetField(result, NewString("foo")); |
4966 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4889 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4967 EXPECT_EQ(-11, int_value); | 4890 EXPECT_EQ(-11, int_value); |
4968 | 4891 |
4969 // Allocate object and Invoke a constructor which throws an exception. | 4892 // Allocate object and Invoke a constructor which throws an exception. |
4970 obj = Dart_Allocate(type); | 4893 obj = Dart_Allocate(type); |
4971 EXPECT_VALID(obj); | 4894 EXPECT_VALID(obj); |
4972 instanceof = false; | 4895 instanceOf = false; |
4973 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceof)); | 4896 EXPECT_VALID(Dart_ObjectIsType(obj, type, &instanceOf)); |
4974 EXPECT(instanceof); | 4897 EXPECT(instanceOf); |
4975 result = Dart_InvokeConstructor(obj, NewString("exception"), 1, args); | 4898 result = Dart_InvokeConstructor(obj, NewString("exception"), 1, args); |
4976 EXPECT_ERROR(result, "ConstructorDeath"); | 4899 EXPECT_ERROR(result, "ConstructorDeath"); |
4977 | 4900 |
4978 // Invoke a factory constructor. | 4901 // Invoke a factory constructor. |
4979 result = Dart_New(type, NewString("multiply"), 1, args); | 4902 result = Dart_New(type, NewString("multiply"), 1, args); |
4980 EXPECT_VALID(result); | 4903 EXPECT_VALID(result); |
4981 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4904 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
4982 EXPECT(instanceof); | 4905 EXPECT(instanceOf); |
4983 int_value = 0; | 4906 int_value = 0; |
4984 foo = Dart_GetField(result, NewString("foo")); | 4907 foo = Dart_GetField(result, NewString("foo")); |
4985 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4908 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
4986 EXPECT_EQ(1100, int_value); | 4909 EXPECT_EQ(1100, int_value); |
4987 | 4910 |
4988 // Invoke a factory constructor which returns null. | 4911 // Invoke a factory constructor which returns null. |
4989 result = Dart_New(type, NewString("nullo"), 0, NULL); | 4912 result = Dart_New(type, NewString("nullo"), 0, NULL); |
4990 EXPECT_VALID(result); | 4913 EXPECT_VALID(result); |
4991 EXPECT(Dart_IsNull(result)); | 4914 EXPECT(Dart_IsNull(result)); |
4992 | 4915 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5026 EXPECT_ERROR(result, | 4949 EXPECT_ERROR(result, |
5027 "Dart_New: could not find constructor 'MyClass.missing'."); | 4950 "Dart_New: could not find constructor 'MyClass.missing'."); |
5028 | 4951 |
5029 // Invoke a constructor which throws an exception. | 4952 // Invoke a constructor which throws an exception. |
5030 result = Dart_New(type, NewString("exception"), 1, args); | 4953 result = Dart_New(type, NewString("exception"), 1, args); |
5031 EXPECT_ERROR(result, "ConstructorDeath"); | 4954 EXPECT_ERROR(result, "ConstructorDeath"); |
5032 | 4955 |
5033 // Invoke two-hop redirecting factory constructor. | 4956 // Invoke two-hop redirecting factory constructor. |
5034 result = Dart_New(intf, NewString("named"), 1, args); | 4957 result = Dart_New(intf, NewString("named"), 1, args); |
5035 EXPECT_VALID(result); | 4958 EXPECT_VALID(result); |
5036 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4959 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
5037 EXPECT(instanceof); | 4960 EXPECT(instanceOf); |
5038 int_value = 0; | 4961 int_value = 0; |
5039 foo = Dart_GetField(result, NewString("foo")); | 4962 foo = Dart_GetField(result, NewString("foo")); |
5040 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4963 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
5041 EXPECT_EQ(11, int_value); | 4964 EXPECT_EQ(11, int_value); |
5042 | 4965 |
5043 // Invoke one-hop redirecting factory constructor. | 4966 // Invoke one-hop redirecting factory constructor. |
5044 result = Dart_New(intf, NewString("multiply"), 1, args); | 4967 result = Dart_New(intf, NewString("multiply"), 1, args); |
5045 EXPECT_VALID(result); | 4968 EXPECT_VALID(result); |
5046 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4969 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
5047 EXPECT(instanceof); | 4970 EXPECT(instanceOf); |
5048 int_value = 0; | 4971 int_value = 0; |
5049 foo = Dart_GetField(result, NewString("foo")); | 4972 foo = Dart_GetField(result, NewString("foo")); |
5050 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); | 4973 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); |
5051 EXPECT_EQ(1100, int_value); | 4974 EXPECT_EQ(1100, int_value); |
5052 | 4975 |
5053 // Invoke a constructor that is missing in the interface. | 4976 // Invoke a constructor that is missing in the interface. |
5054 result = Dart_New(intf, Dart_Null(), 0, NULL); | 4977 result = Dart_New(intf, Dart_Null(), 0, NULL); |
5055 EXPECT_ERROR(result, | 4978 EXPECT_ERROR(result, "Dart_New: could not find constructor 'MyInterface.'."); |
5056 "Dart_New: could not find constructor 'MyInterface.'."); | |
5057 | 4979 |
5058 // Invoke abstract constructor that is present in the interface. | 4980 // Invoke abstract constructor that is present in the interface. |
5059 result = Dart_New(intf, NewString("notfound"), 1, args); | 4981 result = Dart_New(intf, NewString("notfound"), 1, args); |
5060 EXPECT_VALID(result); | 4982 EXPECT_VALID(result); |
5061 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof)); | 4983 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceOf)); |
5062 EXPECT(!instanceof); | 4984 EXPECT(!instanceOf); |
5063 } | 4985 } |
5064 | 4986 |
5065 | 4987 |
5066 TEST_CASE(New_Issue2971) { | 4988 TEST_CASE(New_Issue2971) { |
5067 // Issue 2971: We were unable to use Dart_New to construct an | 4989 // Issue 2971: We were unable to use Dart_New to construct an |
5068 // instance of List, due to problems implementing interface | 4990 // instance of List, due to problems implementing interface |
5069 // factories. | 4991 // factories. |
5070 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); | 4992 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); |
5071 EXPECT_VALID(core_lib); | 4993 EXPECT_VALID(core_lib); |
5072 Dart_Handle list_type = Dart_GetType(core_lib, NewString("List"), 0, NULL); | 4994 Dart_Handle list_type = Dart_GetType(core_lib, NewString("List"), 0, NULL); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5230 result = Dart_Invoke(type, name, 1, args); | 5152 result = Dart_Invoke(type, name, 1, args); |
5231 EXPECT_VALID(result); | 5153 EXPECT_VALID(result); |
5232 | 5154 |
5233 const char* str = NULL; | 5155 const char* str = NULL; |
5234 result = Dart_StringToCString(result, &str); | 5156 result = Dart_StringToCString(result, &str); |
5235 EXPECT_STREQ("hidden static !!!", str); | 5157 EXPECT_STREQ("hidden static !!!", str); |
5236 } | 5158 } |
5237 | 5159 |
5238 | 5160 |
5239 TEST_CASE(Invoke_FunnyArgs) { | 5161 TEST_CASE(Invoke_FunnyArgs) { |
5240 const char* kScriptChars = | 5162 const char* kScriptChars = "test(arg) => 'hello $arg';\n"; |
5241 "test(arg) => 'hello $arg';\n"; | |
5242 | 5163 |
5243 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5164 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
5244 Dart_Handle func_name = NewString("test"); | 5165 Dart_Handle func_name = NewString("test"); |
5245 Dart_Handle args[1]; | 5166 Dart_Handle args[1]; |
5246 const char* str; | 5167 const char* str; |
5247 | 5168 |
5248 // Make sure that valid args yield valid results. | 5169 // Make sure that valid args yield valid results. |
5249 args[0] = NewString("!!!"); | 5170 args[0] = NewString("!!!"); |
5250 Dart_Handle result = Dart_Invoke(lib, func_name, 1, args); | 5171 Dart_Handle result = Dart_Invoke(lib, func_name, 1, args); |
5251 EXPECT_VALID(result); | 5172 EXPECT_VALID(result); |
5252 result = Dart_StringToCString(result, &str); | 5173 result = Dart_StringToCString(result, &str); |
5253 EXPECT_STREQ("hello !!!", str); | 5174 EXPECT_STREQ("hello !!!", str); |
5254 | 5175 |
5255 // Make sure that null is legal. | 5176 // Make sure that null is legal. |
5256 args[0] = Dart_Null(); | 5177 args[0] = Dart_Null(); |
5257 result = Dart_Invoke(lib, func_name, 1, args); | 5178 result = Dart_Invoke(lib, func_name, 1, args); |
5258 EXPECT_VALID(result); | 5179 EXPECT_VALID(result); |
5259 result = Dart_StringToCString(result, &str); | 5180 result = Dart_StringToCString(result, &str); |
5260 EXPECT_STREQ("hello null", str); | 5181 EXPECT_STREQ("hello null", str); |
5261 | 5182 |
5262 // Pass an error handle as the target. The error is propagated. | 5183 // Pass an error handle as the target. The error is propagated. |
5263 result = Dart_Invoke(Api::NewError("myerror"), | 5184 result = Dart_Invoke(Api::NewError("myerror"), func_name, 1, args); |
5264 func_name, 1, args); | |
5265 EXPECT(Dart_IsError(result)); | 5185 EXPECT(Dart_IsError(result)); |
5266 EXPECT_STREQ("myerror", Dart_GetError(result)); | 5186 EXPECT_STREQ("myerror", Dart_GetError(result)); |
5267 | 5187 |
5268 // Pass an error handle as the function name. The error is propagated. | 5188 // Pass an error handle as the function name. The error is propagated. |
5269 result = Dart_Invoke(lib, Api::NewError("myerror"), 1, args); | 5189 result = Dart_Invoke(lib, Api::NewError("myerror"), 1, args); |
5270 EXPECT(Dart_IsError(result)); | 5190 EXPECT(Dart_IsError(result)); |
5271 EXPECT_STREQ("myerror", Dart_GetError(result)); | 5191 EXPECT_STREQ("myerror", Dart_GetError(result)); |
5272 | 5192 |
5273 // Pass a non-instance handle as a parameter.. | 5193 // Pass a non-instance handle as a parameter.. |
5274 args[0] = lib; | 5194 args[0] = lib; |
5275 result = Dart_Invoke(lib, func_name, 1, args); | 5195 result = Dart_Invoke(lib, func_name, 1, args); |
5276 EXPECT(Dart_IsError(result)); | 5196 EXPECT(Dart_IsError(result)); |
5277 EXPECT_STREQ("Dart_Invoke expects arguments[0] to be an Instance handle.", | 5197 EXPECT_STREQ("Dart_Invoke expects arguments[0] to be an Instance handle.", |
5278 Dart_GetError(result)); | 5198 Dart_GetError(result)); |
5279 | 5199 |
5280 // Pass an error handle as a parameter. The error is propagated. | 5200 // Pass an error handle as a parameter. The error is propagated. |
5281 args[0] = Api::NewError("myerror"); | 5201 args[0] = Api::NewError("myerror"); |
5282 result = Dart_Invoke(lib, func_name, 1, args); | 5202 result = Dart_Invoke(lib, func_name, 1, args); |
5283 EXPECT(Dart_IsError(result)); | 5203 EXPECT(Dart_IsError(result)); |
5284 EXPECT_STREQ("myerror", Dart_GetError(result)); | 5204 EXPECT_STREQ("myerror", Dart_GetError(result)); |
5285 } | 5205 } |
5286 | 5206 |
5287 | 5207 |
5288 TEST_CASE(Invoke_Null) { | 5208 TEST_CASE(Invoke_Null) { |
5289 Dart_Handle result = Dart_Invoke(Dart_Null(), | 5209 Dart_Handle result = Dart_Invoke(Dart_Null(), NewString("toString"), 0, NULL); |
5290 NewString("toString"), | |
5291 0, | |
5292 NULL); | |
5293 EXPECT_VALID(result); | 5210 EXPECT_VALID(result); |
5294 EXPECT(Dart_IsString(result)); | 5211 EXPECT(Dart_IsString(result)); |
5295 | 5212 |
5296 const char* value = ""; | 5213 const char* value = ""; |
5297 EXPECT_VALID(Dart_StringToCString(result, &value)); | 5214 EXPECT_VALID(Dart_StringToCString(result, &value)); |
5298 EXPECT_STREQ("null", value); | 5215 EXPECT_STREQ("null", value); |
5299 | 5216 |
5300 Dart_Handle function_name = NewString("NoNoNo"); | 5217 Dart_Handle function_name = NewString("NoNoNo"); |
5301 result = Dart_Invoke(Dart_Null(), | 5218 result = Dart_Invoke(Dart_Null(), function_name, 0, NULL); |
5302 function_name, | |
5303 0, | |
5304 NULL); | |
5305 EXPECT(Dart_IsError(result)); | 5219 EXPECT(Dart_IsError(result)); |
5306 EXPECT(Dart_ErrorHasException(result)); | 5220 EXPECT(Dart_ErrorHasException(result)); |
5307 } | 5221 } |
5308 | 5222 |
5309 | 5223 |
5310 TEST_CASE(InvokeNoSuchMethod) { | 5224 TEST_CASE(InvokeNoSuchMethod) { |
5311 const char* kScriptChars = | 5225 const char* kScriptChars = |
5312 "import 'dart:_internal' as _internal;\n" | 5226 "import 'dart:_internal' as _internal;\n" |
5313 "class Expect {\n" | 5227 "class Expect {\n" |
5314 " static equals(a, b) {\n" | 5228 " static equals(a, b) {\n" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5488 static Dart_NativeFunction native_lookup(Dart_Handle name, | 5402 static Dart_NativeFunction native_lookup(Dart_Handle name, |
5489 int argument_count, | 5403 int argument_count, |
5490 bool* auto_setup_scope) { | 5404 bool* auto_setup_scope) { |
5491 ASSERT(auto_setup_scope != NULL); | 5405 ASSERT(auto_setup_scope != NULL); |
5492 *auto_setup_scope = true; | 5406 *auto_setup_scope = true; |
5493 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); | 5407 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); |
5494 } | 5408 } |
5495 | 5409 |
5496 | 5410 |
5497 TEST_CASE(ThrowException) { | 5411 TEST_CASE(ThrowException) { |
5498 const char* kScriptChars = | 5412 const char* kScriptChars = "int test() native \"ThrowException_native\";"; |
5499 "int test() native \"ThrowException_native\";"; | |
5500 Dart_Handle result; | 5413 Dart_Handle result; |
5501 intptr_t size = thread->ZoneSizeInBytes(); | 5414 intptr_t size = thread->ZoneSizeInBytes(); |
5502 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 5415 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
5503 | 5416 |
5504 // Load up a test script which extends the native wrapper class. | 5417 // Load up a test script which extends the native wrapper class. |
5505 Dart_Handle lib = TestCase::LoadTestScript( | 5418 Dart_Handle lib = TestCase::LoadTestScript( |
5506 kScriptChars, | 5419 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
5507 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | |
5508 | 5420 |
5509 // Throwing an exception here should result in an error. | 5421 // Throwing an exception here should result in an error. |
5510 result = Dart_ThrowException(NewString("This doesn't work")); | 5422 result = Dart_ThrowException(NewString("This doesn't work")); |
5511 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); | 5423 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); |
5512 EXPECT(!Dart_ErrorHasException(result)); | 5424 EXPECT(!Dart_ErrorHasException(result)); |
5513 | 5425 |
5514 // Invoke 'test' and check for an uncaught exception. | 5426 // Invoke 'test' and check for an uncaught exception. |
5515 result = Dart_Invoke(lib, NewString("test"), 0, NULL); | 5427 result = Dart_Invoke(lib, NewString("test"), 0, NULL); |
5516 EXPECT_ERROR(result, "Hello from ExceptionNative!"); | 5428 EXPECT_ERROR(result, "Hello from ExceptionNative!"); |
5517 EXPECT(Dart_ErrorHasException(result)); | 5429 EXPECT(Dart_ErrorHasException(result)); |
5518 | 5430 |
5519 Dart_ExitScope(); // Exit the Dart API scope. | 5431 Dart_ExitScope(); // Exit the Dart API scope. |
5520 EXPECT_EQ(size, thread->ZoneSizeInBytes()); | 5432 EXPECT_EQ(size, thread->ZoneSizeInBytes()); |
5521 } | 5433 } |
5522 | 5434 |
5523 | 5435 |
5524 static intptr_t kNativeArgumentNativeField1Value = 30; | 5436 static intptr_t kNativeArgumentNativeField1Value = 30; |
5525 static intptr_t kNativeArgumentNativeField2Value = 40; | 5437 static intptr_t kNativeArgumentNativeField2Value = 40; |
5526 static intptr_t native_arg_str_peer = 100; | 5438 static intptr_t native_arg_str_peer = 100; |
5527 static void NativeArgumentCreate(Dart_NativeArguments args) { | 5439 static void NativeArgumentCreate(Dart_NativeArguments args) { |
5528 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 5440 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
5529 Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL); | 5441 Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL); |
5530 EXPECT_VALID(type); | 5442 EXPECT_VALID(type); |
5531 | 5443 |
5532 // Allocate without a constructor. | 5444 // Allocate without a constructor. |
5533 const int num_native_fields = 2; | 5445 const int num_native_fields = 2; |
5534 const intptr_t native_fields[] = { | 5446 const intptr_t native_fields[] = {kNativeArgumentNativeField1Value, |
5535 kNativeArgumentNativeField1Value, | 5447 kNativeArgumentNativeField2Value}; |
5536 kNativeArgumentNativeField2Value | |
5537 }; | |
5538 // Allocate and Setup native fields. | 5448 // Allocate and Setup native fields. |
5539 Dart_Handle obj = Dart_AllocateWithNativeFields(type, | 5449 Dart_Handle obj = |
5540 num_native_fields, | 5450 Dart_AllocateWithNativeFields(type, num_native_fields, native_fields); |
5541 native_fields); | |
5542 EXPECT_VALID(obj); | 5451 EXPECT_VALID(obj); |
5543 | 5452 |
5544 kNativeArgumentNativeField1Value *= 2; | 5453 kNativeArgumentNativeField1Value *= 2; |
5545 kNativeArgumentNativeField2Value *= 2; | 5454 kNativeArgumentNativeField2Value *= 2; |
5546 Dart_SetReturnValue(args, obj); | 5455 Dart_SetReturnValue(args, obj); |
5547 } | 5456 } |
5548 | 5457 |
5549 | 5458 |
5550 static void NativeArgumentAccess(Dart_NativeArguments args) { | 5459 static void NativeArgumentAccess(Dart_NativeArguments args) { |
5551 const int kNumNativeFields = 2; | 5460 const int kNumNativeFields = 2; |
5552 | 5461 |
5553 // Test different argument types with a valid descriptor set. | 5462 // Test different argument types with a valid descriptor set. |
5554 { | 5463 { |
5555 const char* cstr = NULL; | 5464 const char* cstr = NULL; |
5556 intptr_t native_fields1[kNumNativeFields]; | 5465 intptr_t native_fields1[kNumNativeFields]; |
5557 intptr_t native_fields2[kNumNativeFields]; | 5466 intptr_t native_fields2[kNumNativeFields]; |
5558 const Dart_NativeArgument_Descriptor arg_descriptors[9] = { | 5467 const Dart_NativeArgument_Descriptor arg_descriptors[9] = { |
5559 { Dart_NativeArgument_kNativeFields, 0 }, | 5468 {Dart_NativeArgument_kNativeFields, 0}, |
5560 { Dart_NativeArgument_kInt32, 1 }, | 5469 {Dart_NativeArgument_kInt32, 1}, |
5561 { Dart_NativeArgument_kUint64, 2 }, | 5470 {Dart_NativeArgument_kUint64, 2}, |
5562 { Dart_NativeArgument_kBool, 3 }, | 5471 {Dart_NativeArgument_kBool, 3}, |
5563 { Dart_NativeArgument_kDouble, 4 }, | 5472 {Dart_NativeArgument_kDouble, 4}, |
5564 { Dart_NativeArgument_kString, 5 }, | 5473 {Dart_NativeArgument_kString, 5}, |
5565 { Dart_NativeArgument_kString, 6 }, | 5474 {Dart_NativeArgument_kString, 6}, |
5566 { Dart_NativeArgument_kNativeFields, 7 }, | 5475 {Dart_NativeArgument_kNativeFields, 7}, |
5567 { Dart_NativeArgument_kInstance, 7 }, | 5476 {Dart_NativeArgument_kInstance, 7}, |
5568 }; | 5477 }; |
5569 Dart_NativeArgument_Value arg_values[9]; | 5478 Dart_NativeArgument_Value arg_values[9]; |
5570 arg_values[0].as_native_fields.num_fields = kNumNativeFields; | 5479 arg_values[0].as_native_fields.num_fields = kNumNativeFields; |
5571 arg_values[0].as_native_fields.values = native_fields1; | 5480 arg_values[0].as_native_fields.values = native_fields1; |
5572 arg_values[7].as_native_fields.num_fields = kNumNativeFields; | 5481 arg_values[7].as_native_fields.num_fields = kNumNativeFields; |
5573 arg_values[7].as_native_fields.values = native_fields2; | 5482 arg_values[7].as_native_fields.values = native_fields2; |
5574 Dart_Handle result = Dart_GetNativeArguments(args, | 5483 Dart_Handle result = |
5575 9, | 5484 Dart_GetNativeArguments(args, 9, arg_descriptors, arg_values); |
5576 arg_descriptors, | |
5577 arg_values); | |
5578 EXPECT_VALID(result); | 5485 EXPECT_VALID(result); |
5579 | 5486 |
5580 EXPECT(arg_values[0].as_native_fields.values[0] == 30); | 5487 EXPECT(arg_values[0].as_native_fields.values[0] == 30); |
5581 EXPECT(arg_values[0].as_native_fields.values[1] == 40); | 5488 EXPECT(arg_values[0].as_native_fields.values[1] == 40); |
5582 | 5489 |
5583 EXPECT(arg_values[1].as_int32 == 77); | 5490 EXPECT(arg_values[1].as_int32 == 77); |
5584 | 5491 |
5585 EXPECT(arg_values[2].as_uint64 == 0xffffffffffffffffLL); | 5492 EXPECT(arg_values[2].as_uint64 == 0xffffffffffffffffLL); |
5586 | 5493 |
5587 EXPECT(arg_values[3].as_bool == true); | 5494 EXPECT(arg_values[3].as_bool == true); |
5588 | 5495 |
5589 EXPECT(arg_values[4].as_double == 3.14); | 5496 EXPECT(arg_values[4].as_double == 3.14); |
5590 | 5497 |
5591 EXPECT_VALID(arg_values[5].as_string.dart_str); | 5498 EXPECT_VALID(arg_values[5].as_string.dart_str); |
5592 EXPECT(Dart_IsString(arg_values[5].as_string.dart_str)); | 5499 EXPECT(Dart_IsString(arg_values[5].as_string.dart_str)); |
5593 EXPECT_VALID(Dart_StringToCString(arg_values[5].as_string.dart_str, &cstr)); | 5500 EXPECT_VALID(Dart_StringToCString(arg_values[5].as_string.dart_str, &cstr)); |
5594 EXPECT_STREQ("abcdefg", cstr); | 5501 EXPECT_STREQ("abcdefg", cstr); |
5595 EXPECT(arg_values[5].as_string.peer == NULL); | 5502 EXPECT(arg_values[5].as_string.peer == NULL); |
5596 | 5503 |
5597 EXPECT(arg_values[6].as_string.dart_str == NULL); | 5504 EXPECT(arg_values[6].as_string.dart_str == NULL); |
5598 EXPECT(arg_values[6].as_string.peer == | 5505 EXPECT(arg_values[6].as_string.peer == |
5599 reinterpret_cast<void*>(&native_arg_str_peer)); | 5506 reinterpret_cast<void*>(&native_arg_str_peer)); |
5600 | 5507 |
5601 EXPECT(arg_values[7].as_native_fields.values[0] == 60); | 5508 EXPECT(arg_values[7].as_native_fields.values[0] == 60); |
5602 EXPECT(arg_values[7].as_native_fields.values[1] == 80); | 5509 EXPECT(arg_values[7].as_native_fields.values[1] == 80); |
5603 | 5510 |
5604 EXPECT_VALID(arg_values[8].as_instance); | 5511 EXPECT_VALID(arg_values[8].as_instance); |
5605 EXPECT(Dart_IsInstance(arg_values[8].as_instance)); | 5512 EXPECT(Dart_IsInstance(arg_values[8].as_instance)); |
5606 int field_count = 0; | 5513 int field_count = 0; |
5607 EXPECT_VALID(Dart_GetNativeInstanceFieldCount( | 5514 EXPECT_VALID(Dart_GetNativeInstanceFieldCount(arg_values[8].as_instance, |
5608 arg_values[8].as_instance, &field_count)); | 5515 &field_count)); |
5609 EXPECT(field_count == 2); | 5516 EXPECT(field_count == 2); |
5610 } | 5517 } |
5611 | 5518 |
5612 // Test with an invalid descriptor set (invalid type). | 5519 // Test with an invalid descriptor set (invalid type). |
5613 { | 5520 { |
5614 const Dart_NativeArgument_Descriptor arg_descriptors[8] = { | 5521 const Dart_NativeArgument_Descriptor arg_descriptors[8] = { |
5615 { Dart_NativeArgument_kInt32, 1 }, | 5522 {Dart_NativeArgument_kInt32, 1}, |
5616 { Dart_NativeArgument_kUint64, 2 }, | 5523 {Dart_NativeArgument_kUint64, 2}, |
5617 { Dart_NativeArgument_kString, 3 }, | 5524 {Dart_NativeArgument_kString, 3}, |
5618 { Dart_NativeArgument_kDouble, 4 }, | 5525 {Dart_NativeArgument_kDouble, 4}, |
5619 { Dart_NativeArgument_kString, 5 }, | 5526 {Dart_NativeArgument_kString, 5}, |
5620 { Dart_NativeArgument_kString, 6 }, | 5527 {Dart_NativeArgument_kString, 6}, |
5621 { Dart_NativeArgument_kNativeFields, 0 }, | 5528 {Dart_NativeArgument_kNativeFields, 0}, |
5622 { Dart_NativeArgument_kNativeFields, 7 }, | 5529 {Dart_NativeArgument_kNativeFields, 7}, |
5623 }; | 5530 }; |
5624 Dart_NativeArgument_Value arg_values[8]; | 5531 Dart_NativeArgument_Value arg_values[8]; |
5625 Dart_Handle result = Dart_GetNativeArguments(args, | 5532 Dart_Handle result = |
5626 8, | 5533 Dart_GetNativeArguments(args, 8, arg_descriptors, arg_values); |
5627 arg_descriptors, | |
5628 arg_values); | |
5629 EXPECT(Dart_IsError(result)); | 5534 EXPECT(Dart_IsError(result)); |
5630 } | 5535 } |
5631 | 5536 |
5632 // Test with an invalid range error. | 5537 // Test with an invalid range error. |
5633 { | 5538 { |
5634 const Dart_NativeArgument_Descriptor arg_descriptors[8] = { | 5539 const Dart_NativeArgument_Descriptor arg_descriptors[8] = { |
5635 { Dart_NativeArgument_kInt32, 2 }, | 5540 {Dart_NativeArgument_kInt32, 2}, |
5636 { Dart_NativeArgument_kUint64, 2 }, | 5541 {Dart_NativeArgument_kUint64, 2}, |
5637 { Dart_NativeArgument_kBool, 3 }, | 5542 {Dart_NativeArgument_kBool, 3}, |
5638 { Dart_NativeArgument_kDouble, 4 }, | 5543 {Dart_NativeArgument_kDouble, 4}, |
5639 { Dart_NativeArgument_kString, 5 }, | 5544 {Dart_NativeArgument_kString, 5}, |
5640 { Dart_NativeArgument_kString, 6 }, | 5545 {Dart_NativeArgument_kString, 6}, |
5641 { Dart_NativeArgument_kNativeFields, 0 }, | 5546 {Dart_NativeArgument_kNativeFields, 0}, |
5642 { Dart_NativeArgument_kNativeFields, 7 }, | 5547 {Dart_NativeArgument_kNativeFields, 7}, |
5643 }; | 5548 }; |
5644 Dart_NativeArgument_Value arg_values[8]; | 5549 Dart_NativeArgument_Value arg_values[8]; |
5645 Dart_Handle result = Dart_GetNativeArguments(args, | 5550 Dart_Handle result = |
5646 8, | 5551 Dart_GetNativeArguments(args, 8, arg_descriptors, arg_values); |
5647 arg_descriptors, | |
5648 arg_values); | |
5649 EXPECT(Dart_IsError(result)); | 5552 EXPECT(Dart_IsError(result)); |
5650 } | 5553 } |
5651 | 5554 |
5652 Dart_SetIntegerReturnValue(args, 0); | 5555 Dart_SetIntegerReturnValue(args, 0); |
5653 } | 5556 } |
5654 | 5557 |
5655 | 5558 |
5656 static Dart_NativeFunction native_args_lookup(Dart_Handle name, | 5559 static Dart_NativeFunction native_args_lookup(Dart_Handle name, |
5657 int argument_count, | 5560 int argument_count, |
5658 bool* auto_scope_setup) { | 5561 bool* auto_scope_setup) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5705 Dart_Handle lib = TestCase::LoadTestScript( | 5608 Dart_Handle lib = TestCase::LoadTestScript( |
5706 kScriptChars, | 5609 kScriptChars, |
5707 reinterpret_cast<Dart_NativeEntryResolver>(native_args_lookup)); | 5610 reinterpret_cast<Dart_NativeEntryResolver>(native_args_lookup)); |
5708 | 5611 |
5709 intptr_t size; | 5612 intptr_t size; |
5710 Dart_Handle ascii_str = NewString("string"); | 5613 Dart_Handle ascii_str = NewString("string"); |
5711 EXPECT_VALID(ascii_str); | 5614 EXPECT_VALID(ascii_str); |
5712 EXPECT_VALID(Dart_StringStorageSize(ascii_str, &size)); | 5615 EXPECT_VALID(Dart_StringStorageSize(ascii_str, &size)); |
5713 uint8_t ext_ascii_str[10]; | 5616 uint8_t ext_ascii_str[10]; |
5714 Dart_Handle extstr = Dart_MakeExternalString( | 5617 Dart_Handle extstr = Dart_MakeExternalString( |
5715 ascii_str, | 5618 ascii_str, ext_ascii_str, size, |
5716 ext_ascii_str, | 5619 reinterpret_cast<void*>(&native_arg_str_peer), NULL); |
5717 size, | |
5718 reinterpret_cast<void*>(&native_arg_str_peer), | |
5719 NULL); | |
5720 | 5620 |
5721 Dart_Handle args[1]; | 5621 Dart_Handle args[1]; |
5722 args[0] = extstr; | 5622 args[0] = extstr; |
5723 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, args); | 5623 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, args); |
5724 EXPECT_VALID(result); | 5624 EXPECT_VALID(result); |
5725 EXPECT(Dart_IsInteger(result)); | 5625 EXPECT(Dart_IsInteger(result)); |
5726 | 5626 |
5727 FLAG_support_externalizable_strings = saved_flag; | 5627 FLAG_support_externalizable_strings = saved_flag; |
5728 } | 5628 } |
5729 | 5629 |
(...skipping 19 matching lines...) Expand all Loading... |
5749 const char* kScriptChars = | 5649 const char* kScriptChars = |
5750 "class MyObject {" | 5650 "class MyObject {" |
5751 " int method1(int i, int j) native 'Name_Does_Not_Matter';" | 5651 " int method1(int i, int j) native 'Name_Does_Not_Matter';" |
5752 "}" | 5652 "}" |
5753 "testMain() {" | 5653 "testMain() {" |
5754 " MyObject obj = new MyObject();" | 5654 " MyObject obj = new MyObject();" |
5755 " return obj.method1(77, 125);" | 5655 " return obj.method1(77, 125);" |
5756 "}"; | 5656 "}"; |
5757 | 5657 |
5758 Dart_Handle lib = TestCase::LoadTestScript( | 5658 Dart_Handle lib = TestCase::LoadTestScript( |
5759 kScriptChars, | 5659 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); |
5760 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); | |
5761 | 5660 |
5762 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 5661 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
5763 EXPECT_VALID(result); | 5662 EXPECT_VALID(result); |
5764 EXPECT(Dart_IsInteger(result)); | 5663 EXPECT(Dart_IsInteger(result)); |
5765 | 5664 |
5766 int64_t value = 0; | 5665 int64_t value = 0; |
5767 result = Dart_IntegerToInt64(result, &value); | 5666 result = Dart_IntegerToInt64(result, &value); |
5768 EXPECT_VALID(result); | 5667 EXPECT_VALID(result); |
5769 EXPECT_EQ(3, value); | 5668 EXPECT_EQ(3, value); |
5770 } | 5669 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5852 | 5751 |
5853 // Fetch OtherClass and check if instanceOfTestObj is instance of it. | 5752 // Fetch OtherClass and check if instanceOfTestObj is instance of it. |
5854 Dart_Handle otherType = Dart_GetType(lib, NewString("OtherClass"), 0, NULL); | 5753 Dart_Handle otherType = Dart_GetType(lib, NewString("OtherClass"), 0, NULL); |
5855 EXPECT_VALID(otherType); | 5754 EXPECT_VALID(otherType); |
5856 | 5755 |
5857 result = Dart_ObjectIsType(instanceOfTestObj, otherType, &is_instance); | 5756 result = Dart_ObjectIsType(instanceOfTestObj, otherType, &is_instance); |
5858 EXPECT_VALID(result); | 5757 EXPECT_VALID(result); |
5859 EXPECT(!is_instance); | 5758 EXPECT(!is_instance); |
5860 | 5759 |
5861 // Check that primitives are not instances of InstanceOfTest class. | 5760 // Check that primitives are not instances of InstanceOfTest class. |
5862 result = Dart_ObjectIsType(NewString("a string"), otherType, | 5761 result = Dart_ObjectIsType(NewString("a string"), otherType, &is_instance); |
5863 &is_instance); | |
5864 EXPECT_VALID(result); | 5762 EXPECT_VALID(result); |
5865 EXPECT(!is_instance); | 5763 EXPECT(!is_instance); |
5866 | 5764 |
5867 result = Dart_ObjectIsType(Dart_NewInteger(42), otherType, &is_instance); | 5765 result = Dart_ObjectIsType(Dart_NewInteger(42), otherType, &is_instance); |
5868 EXPECT_VALID(result); | 5766 EXPECT_VALID(result); |
5869 EXPECT(!is_instance); | 5767 EXPECT(!is_instance); |
5870 | 5768 |
5871 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherType, &is_instance); | 5769 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherType, &is_instance); |
5872 EXPECT_VALID(result); | 5770 EXPECT_VALID(result); |
5873 EXPECT(!is_instance); | 5771 EXPECT(!is_instance); |
5874 | 5772 |
5875 // Check that null is not an instance of InstanceOfTest class. | 5773 // Check that null is not an instance of InstanceOfTest class. |
5876 Dart_Handle null = Dart_Invoke(otherType, | 5774 Dart_Handle null = Dart_Invoke(otherType, NewString("returnNull"), 0, NULL); |
5877 NewString("returnNull"), | |
5878 0, | |
5879 NULL); | |
5880 EXPECT_VALID(null); | 5775 EXPECT_VALID(null); |
5881 | 5776 |
5882 result = Dart_ObjectIsType(null, otherType, &is_instance); | 5777 result = Dart_ObjectIsType(null, otherType, &is_instance); |
5883 EXPECT_VALID(result); | 5778 EXPECT_VALID(result); |
5884 EXPECT(!is_instance); | 5779 EXPECT(!is_instance); |
5885 | 5780 |
5886 // Check that error is returned if null is passed as a class argument. | 5781 // Check that error is returned if null is passed as a class argument. |
5887 result = Dart_ObjectIsType(null, null, &is_instance); | 5782 result = Dart_ObjectIsType(null, null, &is_instance); |
5888 EXPECT(Dart_IsError(result)); | 5783 EXPECT(Dart_IsError(result)); |
5889 } | 5784 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5959 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 5854 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
5960 EXPECT_VALID(result); | 5855 EXPECT_VALID(result); |
5961 EXPECT(Dart_IsInteger(result)); | 5856 EXPECT(Dart_IsInteger(result)); |
5962 int64_t value = 0; | 5857 int64_t value = 0; |
5963 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5858 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
5964 EXPECT_EQ(12345, value); | 5859 EXPECT_EQ(12345, value); |
5965 | 5860 |
5966 // Further calls to LoadScript are errors. | 5861 // Further calls to LoadScript are errors. |
5967 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5862 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
5968 EXPECT(Dart_IsError(result)); | 5863 EXPECT(Dart_IsError(result)); |
5969 EXPECT_STREQ("Dart_LoadScript: " | 5864 EXPECT_STREQ( |
5970 "A script has already been loaded from 'test-lib'.", | 5865 "Dart_LoadScript: " |
5971 Dart_GetError(result)); | 5866 "A script has already been loaded from 'test-lib'.", |
| 5867 Dart_GetError(result)); |
5972 } | 5868 } |
5973 | 5869 |
5974 | 5870 |
5975 TEST_CASE(RootLibrary) { | 5871 TEST_CASE(RootLibrary) { |
5976 const char* kScriptChars = | 5872 const char* kScriptChars = |
5977 "library testlib;" | 5873 "library testlib;" |
5978 "main() {" | 5874 "main() {" |
5979 " return 12345;" | 5875 " return 12345;" |
5980 "}"; | 5876 "}"; |
5981 | 5877 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6061 default: | 5957 default: |
6062 EXPECT(false); | 5958 EXPECT(false); |
6063 return Api::NewError("invalid callback"); | 5959 return Api::NewError("invalid callback"); |
6064 } | 5960 } |
6065 index += 1; | 5961 index += 1; |
6066 return Api::Success(); | 5962 return Api::Success(); |
6067 } | 5963 } |
6068 | 5964 |
6069 | 5965 |
6070 TEST_CASE(LoadScript_CompileError) { | 5966 TEST_CASE(LoadScript_CompileError) { |
6071 const char* kScriptChars = | 5967 const char* kScriptChars = ")"; |
6072 ")"; | |
6073 Dart_Handle url = NewString(TestCase::url()); | 5968 Dart_Handle url = NewString(TestCase::url()); |
6074 Dart_Handle source = NewString(kScriptChars); | 5969 Dart_Handle source = NewString(kScriptChars); |
6075 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 5970 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
6076 EXPECT_VALID(result); | 5971 EXPECT_VALID(result); |
6077 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 5972 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
6078 EXPECT(Dart_IsError(result)); | 5973 EXPECT(Dart_IsError(result)); |
6079 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 5974 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
6080 } | 5975 } |
6081 | 5976 |
6082 | 5977 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6121 | 6016 |
6122 url = NewString("noodles.dart"); | 6017 url = NewString("noodles.dart"); |
6123 result = Dart_LookupLibrary(url); | 6018 result = Dart_LookupLibrary(url); |
6124 EXPECT(Dart_IsError(result)); | 6019 EXPECT(Dart_IsError(result)); |
6125 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", | 6020 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", |
6126 Dart_GetError(result)); | 6021 Dart_GetError(result)); |
6127 } | 6022 } |
6128 | 6023 |
6129 | 6024 |
6130 TEST_CASE(LibraryName) { | 6025 TEST_CASE(LibraryName) { |
6131 const char* kLibrary1Chars = | 6026 const char* kLibrary1Chars = "library library1_name;"; |
6132 "library library1_name;"; | |
6133 Dart_Handle url = NewString("library1_url"); | 6027 Dart_Handle url = NewString("library1_url"); |
6134 Dart_Handle source = NewString(kLibrary1Chars); | 6028 Dart_Handle source = NewString(kLibrary1Chars); |
6135 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6029 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6136 Dart_Handle error = Dart_NewApiError("incoming error"); | 6030 Dart_Handle error = Dart_NewApiError("incoming error"); |
6137 EXPECT_VALID(lib); | 6031 EXPECT_VALID(lib); |
6138 | 6032 |
6139 Dart_Handle result = Dart_LibraryName(Dart_Null()); | 6033 Dart_Handle result = Dart_LibraryName(Dart_Null()); |
6140 EXPECT(Dart_IsError(result)); | 6034 EXPECT(Dart_IsError(result)); |
6141 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.", | 6035 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.", |
6142 Dart_GetError(result)); | 6036 Dart_GetError(result)); |
(...skipping 14 matching lines...) Expand all Loading... |
6157 const char* cstr = NULL; | 6051 const char* cstr = NULL; |
6158 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 6052 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
6159 EXPECT_STREQ("library1_name", cstr); | 6053 EXPECT_STREQ("library1_name", cstr); |
6160 } | 6054 } |
6161 | 6055 |
6162 | 6056 |
6163 #ifndef PRODUCT | 6057 #ifndef PRODUCT |
6164 | 6058 |
6165 | 6059 |
6166 TEST_CASE(LibraryId) { | 6060 TEST_CASE(LibraryId) { |
6167 const char* kLibrary1Chars = | 6061 const char* kLibrary1Chars = "library library1_name;"; |
6168 "library library1_name;"; | |
6169 Dart_Handle url = NewString("library1_url"); | 6062 Dart_Handle url = NewString("library1_url"); |
6170 Dart_Handle source = NewString(kLibrary1Chars); | 6063 Dart_Handle source = NewString(kLibrary1Chars); |
6171 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6064 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6172 Dart_Handle error = Dart_NewApiError("incoming error"); | 6065 Dart_Handle error = Dart_NewApiError("incoming error"); |
6173 EXPECT_VALID(lib); | 6066 EXPECT_VALID(lib); |
6174 intptr_t libraryId = -1; | 6067 intptr_t libraryId = -1; |
6175 | 6068 |
6176 Dart_Handle result = Dart_LibraryId(Dart_Null(), &libraryId); | 6069 Dart_Handle result = Dart_LibraryId(Dart_Null(), &libraryId); |
6177 EXPECT(Dart_IsError(result)); | 6070 EXPECT(Dart_IsError(result)); |
6178 EXPECT_STREQ("Dart_LibraryId expects argument 'library' to be non-null.", | 6071 EXPECT_STREQ("Dart_LibraryId expects argument 'library' to be non-null.", |
(...skipping 18 matching lines...) Expand all Loading... |
6197 const char* cstr = NULL; | 6090 const char* cstr = NULL; |
6198 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 6091 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
6199 EXPECT_STREQ("library1_name", cstr); | 6092 EXPECT_STREQ("library1_name", cstr); |
6200 } | 6093 } |
6201 | 6094 |
6202 | 6095 |
6203 #endif // !PRODUCT | 6096 #endif // !PRODUCT |
6204 | 6097 |
6205 | 6098 |
6206 TEST_CASE(LibraryUrl) { | 6099 TEST_CASE(LibraryUrl) { |
6207 const char* kLibrary1Chars = | 6100 const char* kLibrary1Chars = "library library1_name;"; |
6208 "library library1_name;"; | |
6209 Dart_Handle url = NewString("library1_url"); | 6101 Dart_Handle url = NewString("library1_url"); |
6210 Dart_Handle source = NewString(kLibrary1Chars); | 6102 Dart_Handle source = NewString(kLibrary1Chars); |
6211 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6103 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6212 Dart_Handle error = Dart_NewApiError("incoming error"); | 6104 Dart_Handle error = Dart_NewApiError("incoming error"); |
6213 EXPECT_VALID(lib); | 6105 EXPECT_VALID(lib); |
6214 | 6106 |
6215 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); | 6107 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); |
6216 EXPECT(Dart_IsError(result)); | 6108 EXPECT(Dart_IsError(result)); |
6217 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", | 6109 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", |
6218 Dart_GetError(result)); | 6110 Dart_GetError(result)); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6341 // Check list contents. | 6233 // Check list contents. |
6342 list_string = Dart_ToString(list); | 6234 list_string = Dart_ToString(list); |
6343 EXPECT_VALID(list_string); | 6235 EXPECT_VALID(list_string); |
6344 list_cstr = ""; | 6236 list_cstr = ""; |
6345 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); | 6237 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
6346 EXPECT_STREQ("[A2, B2, C2=, MyClass, _A2, _B2, _C2=]", list_cstr); | 6238 EXPECT_STREQ("[A2, B2, C2=, MyClass, _A2, _B2, _C2=]", list_cstr); |
6347 } | 6239 } |
6348 | 6240 |
6349 | 6241 |
6350 TEST_CASE(LibraryImportLibrary) { | 6242 TEST_CASE(LibraryImportLibrary) { |
6351 const char* kLibrary1Chars = | 6243 const char* kLibrary1Chars = "library library1_name;"; |
6352 "library library1_name;"; | 6244 const char* kLibrary2Chars = "library library2_name;"; |
6353 const char* kLibrary2Chars = | |
6354 "library library2_name;"; | |
6355 Dart_Handle error = Dart_NewApiError("incoming error"); | 6245 Dart_Handle error = Dart_NewApiError("incoming error"); |
6356 Dart_Handle result; | 6246 Dart_Handle result; |
6357 | 6247 |
6358 Dart_Handle url = NewString("library1_url"); | 6248 Dart_Handle url = NewString("library1_url"); |
6359 Dart_Handle source = NewString(kLibrary1Chars); | 6249 Dart_Handle source = NewString(kLibrary1Chars); |
6360 Dart_Handle lib1 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6250 Dart_Handle lib1 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6361 EXPECT_VALID(lib1); | 6251 EXPECT_VALID(lib1); |
6362 | 6252 |
6363 url = NewString("library2_url"); | 6253 url = NewString("library2_url"); |
6364 source = NewString(kLibrary2Chars); | 6254 source = NewString(kLibrary2Chars); |
6365 Dart_Handle lib2 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6255 Dart_Handle lib2 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6366 EXPECT_VALID(lib2); | 6256 EXPECT_VALID(lib2); |
6367 | 6257 |
6368 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, Dart_Null()); | 6258 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, Dart_Null()); |
6369 EXPECT(Dart_IsError(result)); | 6259 EXPECT(Dart_IsError(result)); |
6370 EXPECT_STREQ( | 6260 EXPECT_STREQ( |
6371 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", | 6261 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", |
6372 Dart_GetError(result)); | 6262 Dart_GetError(result)); |
6373 | 6263 |
6374 result = Dart_LibraryImportLibrary(Dart_True(), lib2, Dart_Null()); | 6264 result = Dart_LibraryImportLibrary(Dart_True(), lib2, Dart_Null()); |
6375 EXPECT(Dart_IsError(result)); | 6265 EXPECT(Dart_IsError(result)); |
6376 EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'library' to be of " | 6266 EXPECT_STREQ( |
6377 "type Library.", | 6267 "Dart_LibraryImportLibrary expects argument 'library' to be of " |
6378 Dart_GetError(result)); | 6268 "type Library.", |
| 6269 Dart_GetError(result)); |
6379 | 6270 |
6380 result = Dart_LibraryImportLibrary(error, lib2, Dart_Null()); | 6271 result = Dart_LibraryImportLibrary(error, lib2, Dart_Null()); |
6381 EXPECT(Dart_IsError(result)); | 6272 EXPECT(Dart_IsError(result)); |
6382 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6273 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6383 | 6274 |
6384 result = Dart_LibraryImportLibrary(lib1, Dart_Null(), Dart_Null()); | 6275 result = Dart_LibraryImportLibrary(lib1, Dart_Null(), Dart_Null()); |
6385 EXPECT(Dart_IsError(result)); | 6276 EXPECT(Dart_IsError(result)); |
6386 EXPECT_STREQ( | 6277 EXPECT_STREQ( |
6387 "Dart_LibraryImportLibrary expects argument 'import' to be non-null.", | 6278 "Dart_LibraryImportLibrary expects argument 'import' to be non-null.", |
6388 Dart_GetError(result)); | 6279 Dart_GetError(result)); |
6389 | 6280 |
6390 result = Dart_LibraryImportLibrary(lib1, Dart_True(), Dart_Null()); | 6281 result = Dart_LibraryImportLibrary(lib1, Dart_True(), Dart_Null()); |
6391 EXPECT(Dart_IsError(result)); | 6282 EXPECT(Dart_IsError(result)); |
6392 EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'import' to be of " | 6283 EXPECT_STREQ( |
6393 "type Library.", | 6284 "Dart_LibraryImportLibrary expects argument 'import' to be of " |
6394 Dart_GetError(result)); | 6285 "type Library.", |
| 6286 Dart_GetError(result)); |
6395 | 6287 |
6396 result = Dart_LibraryImportLibrary(lib1, error, Dart_Null()); | 6288 result = Dart_LibraryImportLibrary(lib1, error, Dart_Null()); |
6397 EXPECT(Dart_IsError(result)); | 6289 EXPECT(Dart_IsError(result)); |
6398 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6290 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6399 | 6291 |
6400 result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); | 6292 result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); |
6401 EXPECT_VALID(result); | 6293 EXPECT_VALID(result); |
6402 } | 6294 } |
6403 | 6295 |
6404 | 6296 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6437 method_name = NewString("foobar"); | 6329 method_name = NewString("foobar"); |
6438 result = Dart_Invoke(lib2, method_name, 0, NULL); | 6330 result = Dart_Invoke(lib2, method_name, 0, NULL); |
6439 EXPECT_VALID(result); | 6331 EXPECT_VALID(result); |
6440 EXPECT(Dart_IsInteger(result)); | 6332 EXPECT(Dart_IsInteger(result)); |
6441 int64_t value = 0; | 6333 int64_t value = 0; |
6442 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6334 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
6443 EXPECT_EQ(42, value); | 6335 EXPECT_EQ(42, value); |
6444 } | 6336 } |
6445 | 6337 |
6446 | 6338 |
6447 | |
6448 TEST_CASE(LoadLibrary) { | 6339 TEST_CASE(LoadLibrary) { |
6449 const char* kLibrary1Chars = | 6340 const char* kLibrary1Chars = "library library1_name;"; |
6450 "library library1_name;"; | |
6451 Dart_Handle error = Dart_NewApiError("incoming error"); | 6341 Dart_Handle error = Dart_NewApiError("incoming error"); |
6452 Dart_Handle result; | 6342 Dart_Handle result; |
6453 | 6343 |
6454 Dart_Handle url = NewString("library1_url"); | 6344 Dart_Handle url = NewString("library1_url"); |
6455 Dart_Handle source = NewString(kLibrary1Chars); | 6345 Dart_Handle source = NewString(kLibrary1Chars); |
6456 | 6346 |
6457 result = Dart_LoadLibrary(Dart_Null(), Dart_Null(), source, 0, 0); | 6347 result = Dart_LoadLibrary(Dart_Null(), Dart_Null(), source, 0, 0); |
6458 EXPECT(Dart_IsError(result)); | 6348 EXPECT(Dart_IsError(result)); |
6459 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", | 6349 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", |
6460 Dart_GetError(result)); | 6350 Dart_GetError(result)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6513 ")"; | 6403 ")"; |
6514 Dart_Handle url = NewString("library1_url"); | 6404 Dart_Handle url = NewString("library1_url"); |
6515 Dart_Handle source = NewString(kLibrary1Chars); | 6405 Dart_Handle source = NewString(kLibrary1Chars); |
6516 Dart_Handle result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6406 Dart_Handle result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6517 EXPECT(Dart_IsError(result)); | 6407 EXPECT(Dart_IsError(result)); |
6518 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 6408 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
6519 } | 6409 } |
6520 | 6410 |
6521 | 6411 |
6522 TEST_CASE(LoadSource) { | 6412 TEST_CASE(LoadSource) { |
6523 const char* kLibrary1Chars = | 6413 const char* kLibrary1Chars = "library library1_name;"; |
6524 "library library1_name;"; | 6414 const char* kSourceChars = "part of library1_name;\n// Something innocuous"; |
6525 const char* kSourceChars = | 6415 const char* kBadSourceChars = ")"; |
6526 "part of library1_name;\n// Something innocuous"; | |
6527 const char* kBadSourceChars = | |
6528 ")"; | |
6529 Dart_Handle error = Dart_NewApiError("incoming error"); | 6416 Dart_Handle error = Dart_NewApiError("incoming error"); |
6530 Dart_Handle result; | 6417 Dart_Handle result; |
6531 | 6418 |
6532 // Load up a library. | 6419 // Load up a library. |
6533 Dart_Handle url = NewString("library1_url"); | 6420 Dart_Handle url = NewString("library1_url"); |
6534 Dart_Handle source = NewString(kLibrary1Chars); | 6421 Dart_Handle source = NewString(kLibrary1Chars); |
6535 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6422 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6536 EXPECT_VALID(lib); | 6423 EXPECT_VALID(lib); |
6537 EXPECT(Dart_IsLibrary(lib)); | 6424 EXPECT(Dart_IsLibrary(lib)); |
6538 | 6425 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6656 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); | 6543 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); |
6657 EXPECT_VALID(result); | 6544 EXPECT_VALID(result); |
6658 EXPECT(Dart_IsString(result)); | 6545 EXPECT(Dart_IsString(result)); |
6659 result_cstr = ""; | 6546 result_cstr = ""; |
6660 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 6547 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
6661 EXPECT_STREQ("bar", result_cstr); | 6548 EXPECT_STREQ("bar", result_cstr); |
6662 } | 6549 } |
6663 | 6550 |
6664 | 6551 |
6665 TEST_CASE(LoadPatch) { | 6552 TEST_CASE(LoadPatch) { |
6666 const char* kLibrary1Chars = | 6553 const char* kLibrary1Chars = "library library1_name;"; |
6667 "library library1_name;"; | |
6668 const char* kSourceChars = | 6554 const char* kSourceChars = |
6669 "part of library1_name;\n" | 6555 "part of library1_name;\n" |
6670 "external int foo();"; | 6556 "external int foo();"; |
6671 const char* kPatchChars = | 6557 const char* kPatchChars = "@patch int foo() => 42;"; |
6672 "@patch int foo() => 42;"; | |
6673 | 6558 |
6674 // Load up a library. | 6559 // Load up a library. |
6675 Dart_Handle url = NewString("library1_url"); | 6560 Dart_Handle url = NewString("library1_url"); |
6676 Dart_Handle source = NewString(kLibrary1Chars); | 6561 Dart_Handle source = NewString(kLibrary1Chars); |
6677 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6562 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6678 EXPECT_VALID(lib); | 6563 EXPECT_VALID(lib); |
6679 EXPECT(Dart_IsLibrary(lib)); | 6564 EXPECT(Dart_IsLibrary(lib)); |
6680 | 6565 |
6681 url = NewString("source_url"); | 6566 url = NewString("source_url"); |
6682 source = NewString(kSourceChars); | 6567 source = NewString(kSourceChars); |
(...skipping 14 matching lines...) Expand all Loading... |
6697 EXPECT(Dart_IsInteger(result)); | 6582 EXPECT(Dart_IsInteger(result)); |
6698 int64_t value = 0; | 6583 int64_t value = 0; |
6699 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6584 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
6700 EXPECT_EQ(42, value); | 6585 EXPECT_EQ(42, value); |
6701 } | 6586 } |
6702 | 6587 |
6703 TEST_CASE(LoadPatchSignatureMismatch) { | 6588 TEST_CASE(LoadPatchSignatureMismatch) { |
6704 // This tests the sort of APIs with intentional signature mismatches we need | 6589 // This tests the sort of APIs with intentional signature mismatches we need |
6705 // for typed Dart-JavaScript interop where we emulated JavaScript semantics | 6590 // for typed Dart-JavaScript interop where we emulated JavaScript semantics |
6706 // for optional arguments. | 6591 // for optional arguments. |
6707 const char* kLibrary1Chars = | 6592 const char* kLibrary1Chars = "library library1_name;"; |
6708 "library library1_name;"; | |
6709 const char* kSourceChars = | 6593 const char* kSourceChars = |
6710 "part of library1_name;\n" | 6594 "part of library1_name;\n" |
6711 "external int foo([int x]);\n" | 6595 "external int foo([int x]);\n" |
6712 "class Foo<T extends Foo> {\n" | 6596 "class Foo<T extends Foo> {\n" |
6713 " external static int addDefault10([int x, int y]);\n" | 6597 " external static int addDefault10([int x, int y]);\n" |
6714 "}"; | 6598 "}"; |
6715 const char* kPatchChars = | 6599 const char* kPatchChars = |
6716 "const _UNDEFINED = const Object();\n" | 6600 "const _UNDEFINED = const Object();\n" |
6717 "@patch foo([x=_UNDEFINED]) => identical(x, _UNDEFINED) ? 42 : x;\n" | 6601 "@patch foo([x=_UNDEFINED]) => identical(x, _UNDEFINED) ? 42 : x;\n" |
6718 "@patch class Foo<T> {\n" | 6602 "@patch class Foo<T> {\n" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6827 int arg_count, | 6711 int arg_count, |
6828 bool* auto_setup_scope) { | 6712 bool* auto_setup_scope) { |
6829 ASSERT(auto_setup_scope != NULL); | 6713 ASSERT(auto_setup_scope != NULL); |
6830 *auto_setup_scope = false; | 6714 *auto_setup_scope = false; |
6831 return &PatchNativeFunction; | 6715 return &PatchNativeFunction; |
6832 } | 6716 } |
6833 | 6717 |
6834 | 6718 |
6835 TEST_CASE(ParsePatchLibrary) { | 6719 TEST_CASE(ParsePatchLibrary) { |
6836 const char* kLibraryChars = | 6720 const char* kLibraryChars = |
6837 "library patched_library;\n" | 6721 "library patched_library;\n" |
6838 "class A {\n" | 6722 "class A {\n" |
6839 " final fvalue;\n" | 6723 " final fvalue;\n" |
6840 " var _f;\n" | 6724 " var _f;\n" |
6841 " callFunc(x, y) => x(y);\n" | 6725 " callFunc(x, y) => x(y);\n" |
6842 " external void method(var value);\n" | 6726 " external void method(var value);\n" |
6843 " get field => _field;\n" | 6727 " get field => _field;\n" |
6844 "}\n" | 6728 "}\n" |
6845 "class B {\n" | 6729 "class B {\n" |
6846 " var val;\n" | 6730 " var val;\n" |
6847 " external B.named(x);\n" | 6731 " external B.named(x);\n" |
6848 " external B(v);\n" | 6732 " external B(v);\n" |
6849 "}\n" | 6733 "}\n" |
6850 "class C {\n" | 6734 "class C {\n" |
6851 " external int method();\n" | 6735 " external int method();\n" |
6852 "}\n" | 6736 "}\n" |
6853 "\n" | 6737 "\n" |
6854 "external int unpatched();\n" | 6738 "external int unpatched();\n" |
6855 "external int topLevel(var value);\n" | 6739 "external int topLevel(var value);\n" |
6856 "external int topLevel2(var value);\n" | 6740 "external int topLevel2(var value);\n" |
6857 "external int get topLevelGetter;\n" | 6741 "external int get topLevelGetter;\n" |
6858 "external void set topLevelSetter(int value);\n"; | 6742 "external void set topLevelSetter(int value);\n"; |
6859 | 6743 |
6860 const char* kPatchChars = | 6744 const char* kPatchChars = |
6861 "@patch class A {\n" | 6745 "@patch class A {\n" |
6862 " var _g;\n" | 6746 " var _g;\n" |
6863 " A() : fvalue = 13;\n" | 6747 " A() : fvalue = 13;\n" |
6864 " get _field => _g;\n" | 6748 " get _field => _g;\n" |
6865 " @patch void method(var value) {\n" | 6749 " @patch void method(var value) {\n" |
6866 " int closeYourEyes(var eggs) { return eggs * -1; }\n" | 6750 " int closeYourEyes(var eggs) { return eggs * -1; }\n" |
6867 " value = callFunc(closeYourEyes, value);\n" | 6751 " value = callFunc(closeYourEyes, value);\n" |
6868 " _g = value * 5;\n" | 6752 " _g = value * 5;\n" |
6869 " }\n" | 6753 " }\n" |
6870 "}\n" | 6754 "}\n" |
6871 "@patch class B {\n" | 6755 "@patch class B {\n" |
6872 " B._internal(x) : val = x;\n" | 6756 " B._internal(x) : val = x;\n" |
6873 " @patch factory B.named(x) { return new B._internal(x); }\n" | 6757 " @patch factory B.named(x) { return new B._internal(x); }\n" |
6874 " @patch factory B(v) native \"const_B_factory\";\n" | 6758 " @patch factory B(v) native \"const_B_factory\";\n" |
6875 "}\n" | 6759 "}\n" |
6876 "var _topLevelValue = -1;\n" | 6760 "var _topLevelValue = -1;\n" |
6877 "@patch int topLevel(var value) => value * value;\n" | 6761 "@patch int topLevel(var value) => value * value;\n" |
6878 "@patch int set topLevelSetter(value) { _topLevelValue = value; }\n" | 6762 "@patch int set topLevelSetter(value) { _topLevelValue = value; }\n" |
6879 "@patch int get topLevelGetter => 2 * _topLevelValue;\n" | 6763 "@patch int get topLevelGetter => 2 * _topLevelValue;\n" |
6880 // Allow top level methods named patch. | 6764 // Allow top level methods named patch. |
6881 "patch(x) => x*3;\n" | 6765 "patch(x) => x*3;\n"; // NOLINT |
6882 ; // NOLINT | |
6883 | 6766 |
6884 const char* kPatchClassOnlyChars = | 6767 const char* kPatchClassOnlyChars = |
6885 "@patch class C {\n" | 6768 "@patch class C {\n" |
6886 " @patch int method() {\n" | 6769 " @patch int method() {\n" |
6887 " return 42;\n" | 6770 " return 42;\n" |
6888 " }\n" | 6771 " }\n" |
6889 "}\n" | 6772 "}\n"; // NOLINT |
6890 ; // NOLINT | |
6891 | 6773 |
6892 const char* kPatchNoClassChars = | 6774 const char* kPatchNoClassChars = "@patch topLevel2(x) => x * 2;\n"; |
6893 "@patch topLevel2(x) => x * 2;\n"; | |
6894 | 6775 |
6895 const char* kScriptChars = | 6776 const char* kScriptChars = |
6896 "import 'theLibrary';\n" | 6777 "import 'theLibrary';\n" |
6897 "e1() => unpatched();\n" | 6778 "e1() => unpatched();\n" |
6898 "m1() => topLevel(2);\n" | 6779 "m1() => topLevel(2);\n" |
6899 "m2() {\n" | 6780 "m2() {\n" |
6900 " topLevelSetter = 20;\n" | 6781 " topLevelSetter = 20;\n" |
6901 " return topLevelGetter;\n" | 6782 " return topLevelGetter;\n" |
6902 "}\n" | 6783 "}\n" |
6903 "m3() => patch(7);\n" | 6784 "m3() => patch(7);\n" |
6904 "m4() {\n" | 6785 "m4() {\n" |
6905 " var a = new A();\n" | 6786 " var a = new A();\n" |
6906 " a.method(5);\n" | 6787 " a.method(5);\n" |
6907 " return a.field;\n" | 6788 " return a.field;\n" |
6908 "}\n" | 6789 "}\n" |
6909 "m5() => new B(3);\n" | 6790 "m5() => new B(3);\n" |
6910 "m6() {\n" | 6791 "m6() {\n" |
6911 " var b = new B.named(8);\n" | 6792 " var b = new B.named(8);\n" |
6912 " return b.val;\n" | 6793 " return b.val;\n" |
6913 "}\n" | 6794 "}\n"; // NOLINT |
6914 ; // NOLINT | |
6915 | 6795 |
6916 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 6796 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
6917 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 6797 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
6918 | 6798 |
6919 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); | 6799 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); |
6920 EXPECT_VALID(result); | 6800 EXPECT_VALID(result); |
6921 | 6801 |
6922 Dart_Handle url = NewString("theLibrary"); | 6802 Dart_Handle url = NewString("theLibrary"); |
6923 Dart_Handle source = NewString(kLibraryChars); | 6803 Dart_Handle source = NewString(kLibraryChars); |
6924 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 6804 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6925 EXPECT_VALID(result); | 6805 EXPECT_VALID(result); |
6926 | 6806 |
6927 const char* patchNames[] = { "main library patch", | 6807 const char* patchNames[] = {"main library patch", "patch class only", |
6928 "patch class only", | 6808 "patch no class"}; |
6929 "patch no class" }; | 6809 const char* patches[] = {kPatchChars, kPatchClassOnlyChars, |
6930 const char* patches[] = { kPatchChars, | 6810 kPatchNoClassChars}; |
6931 kPatchClassOnlyChars, | |
6932 kPatchNoClassChars }; | |
6933 const String& lib_url = String::Handle(String::New("theLibrary")); | 6811 const String& lib_url = String::Handle(String::New("theLibrary")); |
6934 | 6812 |
6935 const Library& lib = Library::Handle(Library::LookupLibrary(thread, lib_url)); | 6813 const Library& lib = Library::Handle(Library::LookupLibrary(thread, lib_url)); |
6936 | 6814 |
6937 for (int i = 0; i < 3; i++) { | 6815 for (int i = 0; i < 3; i++) { |
6938 const String& patch_url = String::Handle(String::New(patchNames[i])); | 6816 const String& patch_url = String::Handle(String::New(patchNames[i])); |
6939 const String& patch_source = String::Handle(String::New(patches[i])); | 6817 const String& patch_source = String::Handle(String::New(patches[i])); |
6940 const Script& patch_script = Script::Handle(Script::New( | 6818 const Script& patch_script = Script::Handle( |
6941 patch_url, patch_source, RawScript::kPatchTag)); | 6819 Script::New(patch_url, patch_source, RawScript::kPatchTag)); |
6942 | 6820 |
6943 const Error& err = Error::Handle(lib.Patch(patch_script)); | 6821 const Error& err = Error::Handle(lib.Patch(patch_script)); |
6944 if (!err.IsNull()) { | 6822 if (!err.IsNull()) { |
6945 OS::Print("Patching error: %s\n", err.ToErrorCString()); | 6823 OS::Print("Patching error: %s\n", err.ToErrorCString()); |
6946 EXPECT(false); | 6824 EXPECT(false); |
6947 } | 6825 } |
6948 } | 6826 } |
6949 result = Dart_SetNativeResolver(result, &PatchNativeResolver, NULL); | 6827 result = Dart_SetNativeResolver(result, &PatchNativeResolver, NULL); |
6950 EXPECT_VALID(result); | 6828 EXPECT_VALID(result); |
6951 | 6829 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7065 EXPECT_VALID(type); | 6943 EXPECT_VALID(type); |
7066 | 6944 |
7067 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); | 6945 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); |
7068 EXPECT(Dart_IsError(result)); | 6946 EXPECT(Dart_IsError(result)); |
7069 EXPECT_STREQ( | 6947 EXPECT_STREQ( |
7070 "Dart_SetNativeResolver expects argument 'library' to be non-null.", | 6948 "Dart_SetNativeResolver expects argument 'library' to be non-null.", |
7071 Dart_GetError(result)); | 6949 Dart_GetError(result)); |
7072 | 6950 |
7073 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1, NULL); | 6951 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1, NULL); |
7074 EXPECT(Dart_IsError(result)); | 6952 EXPECT(Dart_IsError(result)); |
7075 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of " | 6953 EXPECT_STREQ( |
7076 "type Library.", | 6954 "Dart_SetNativeResolver expects argument 'library' to be of " |
7077 Dart_GetError(result)); | 6955 "type Library.", |
| 6956 Dart_GetError(result)); |
7078 | 6957 |
7079 result = Dart_SetNativeResolver(error, &MyNativeResolver1, NULL); | 6958 result = Dart_SetNativeResolver(error, &MyNativeResolver1, NULL); |
7080 EXPECT(Dart_IsError(result)); | 6959 EXPECT(Dart_IsError(result)); |
7081 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6960 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
7082 | 6961 |
7083 result = Dart_SetNativeResolver(lib, &MyNativeResolver1, NULL); | 6962 result = Dart_SetNativeResolver(lib, &MyNativeResolver1, NULL); |
7084 EXPECT_VALID(result); | 6963 EXPECT_VALID(result); |
7085 | 6964 |
7086 // Call a function and make sure native resolution works. | 6965 // Call a function and make sure native resolution works. |
7087 result = Dart_Invoke(type, NewString("foo"), 0, NULL); | 6966 result = Dart_Invoke(type, NewString("foo"), 0, NULL); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7260 url = NewString("lib.dart"); | 7139 url = NewString("lib.dart"); |
7261 source = NewString(kLibraryChars); | 7140 source = NewString(kLibraryChars); |
7262 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 7141 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7263 Dart_FinalizeLoading(false); | 7142 Dart_FinalizeLoading(false); |
7264 | 7143 |
7265 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 7144 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7266 EXPECT_VALID(result); | 7145 EXPECT_VALID(result); |
7267 } | 7146 } |
7268 | 7147 |
7269 | 7148 |
7270 void NewNativePort_send123(Dart_Port dest_port_id, | 7149 void NewNativePort_send123(Dart_Port dest_port_id, Dart_CObject* message) { |
7271 Dart_CObject *message) { | |
7272 // Gets a send port message. | 7150 // Gets a send port message. |
7273 EXPECT_NOTNULL(message); | 7151 EXPECT_NOTNULL(message); |
7274 EXPECT_EQ(Dart_CObject_kArray, message->type); | 7152 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7275 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 7153 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7276 | 7154 |
7277 // Post integer value. | 7155 // Post integer value. |
7278 Dart_CObject* response = | 7156 Dart_CObject* response = |
7279 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 7157 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
7280 response->type = Dart_CObject_kInt32; | 7158 response->type = Dart_CObject_kInt32; |
7281 response->value.as_int32 = 123; | 7159 response->value.as_int32 = 123; |
7282 Dart_PostCObject( | 7160 Dart_PostCObject(message->value.as_array.values[0]->value.as_send_port.id, |
7283 message->value.as_array.values[0]->value.as_send_port.id, response); | 7161 response); |
7284 } | 7162 } |
7285 | 7163 |
7286 | 7164 |
7287 void NewNativePort_send321(Dart_Port dest_port_id, | 7165 void NewNativePort_send321(Dart_Port dest_port_id, Dart_CObject* message) { |
7288 Dart_CObject* message) { | |
7289 // Gets a null message. | 7166 // Gets a null message. |
7290 EXPECT_NOTNULL(message); | 7167 EXPECT_NOTNULL(message); |
7291 EXPECT_EQ(Dart_CObject_kArray, message->type); | 7168 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7292 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 7169 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7293 | 7170 |
7294 // Post integer value. | 7171 // Post integer value. |
7295 Dart_CObject* response = | 7172 Dart_CObject* response = |
7296 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 7173 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
7297 response->type = Dart_CObject_kInt32; | 7174 response->type = Dart_CObject_kInt32; |
7298 response->value.as_int32 = 321; | 7175 response->value.as_int32 = 321; |
7299 Dart_PostCObject( | 7176 Dart_PostCObject(message->value.as_array.values[0]->value.as_send_port.id, |
7300 message->value.as_array.values[0]->value.as_send_port.id, response); | 7177 response); |
7301 } | 7178 } |
7302 | 7179 |
7303 | 7180 |
7304 TEST_CASE(IllegalNewSendPort) { | 7181 TEST_CASE(IllegalNewSendPort) { |
7305 Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT); | 7182 Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT); |
7306 EXPECT(Dart_IsError(error)); | 7183 EXPECT(Dart_IsError(error)); |
7307 EXPECT(Dart_IsApiError(error)); | 7184 EXPECT(Dart_IsApiError(error)); |
7308 } | 7185 } |
7309 | 7186 |
7310 | 7187 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7344 Dart_NewNativePort("Port321", NewNativePort_send321, true); | 7221 Dart_NewNativePort("Port321", NewNativePort_send321, true); |
7345 | 7222 |
7346 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 7223 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
7347 EXPECT_VALID(send_port1); | 7224 EXPECT_VALID(send_port1); |
7348 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); | 7225 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); |
7349 EXPECT_VALID(send_port2); | 7226 EXPECT_VALID(send_port2); |
7350 | 7227 |
7351 // Test first port. | 7228 // Test first port. |
7352 Dart_Handle dart_args[1]; | 7229 Dart_Handle dart_args[1]; |
7353 dart_args[0] = send_port1; | 7230 dart_args[0] = send_port1; |
7354 Dart_Handle result = | 7231 Dart_Handle result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
7355 Dart_Invoke(lib, NewString("callPort"), 1, dart_args); | |
7356 EXPECT_VALID(result); | 7232 EXPECT_VALID(result); |
7357 result = Dart_RunLoop(); | 7233 result = Dart_RunLoop(); |
7358 EXPECT(Dart_IsError(result)); | 7234 EXPECT(Dart_IsError(result)); |
7359 EXPECT(Dart_ErrorHasException(result)); | 7235 EXPECT(Dart_ErrorHasException(result)); |
7360 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 7236 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
7361 | 7237 |
7362 // result second port. | 7238 // result second port. |
7363 dart_args[0] = send_port2; | 7239 dart_args[0] = send_port2; |
7364 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); | 7240 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
7365 EXPECT_VALID(result); | 7241 EXPECT_VALID(result); |
7366 result = Dart_RunLoop(); | 7242 result = Dart_RunLoop(); |
7367 EXPECT(Dart_IsError(result)); | 7243 EXPECT(Dart_IsError(result)); |
7368 EXPECT(Dart_ErrorHasException(result)); | 7244 EXPECT(Dart_ErrorHasException(result)); |
7369 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 7245 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
7370 | 7246 |
7371 Dart_ExitScope(); | 7247 Dart_ExitScope(); |
7372 | 7248 |
7373 // Delete the native ports. | 7249 // Delete the native ports. |
7374 EXPECT(Dart_CloseNativePort(port_id1)); | 7250 EXPECT(Dart_CloseNativePort(port_id1)); |
7375 EXPECT(Dart_CloseNativePort(port_id2)); | 7251 EXPECT(Dart_CloseNativePort(port_id2)); |
7376 } | 7252 } |
7377 | 7253 |
7378 | 7254 |
7379 void NewNativePort_sendInteger123(Dart_Port dest_port_id, | 7255 void NewNativePort_sendInteger123(Dart_Port dest_port_id, |
7380 Dart_CObject *message) { | 7256 Dart_CObject* message) { |
7381 // Gets a send port message. | 7257 // Gets a send port message. |
7382 EXPECT_NOTNULL(message); | 7258 EXPECT_NOTNULL(message); |
7383 EXPECT_EQ(Dart_CObject_kArray, message->type); | 7259 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7384 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 7260 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7385 | 7261 |
7386 // Post integer value. | 7262 // Post integer value. |
7387 Dart_PostInteger( | 7263 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7388 message->value.as_array.values[0]->value.as_send_port.id, 123); | 7264 123); |
7389 } | 7265 } |
7390 | 7266 |
7391 | 7267 |
7392 void NewNativePort_sendInteger321(Dart_Port dest_port_id, | 7268 void NewNativePort_sendInteger321(Dart_Port dest_port_id, |
7393 Dart_CObject* message) { | 7269 Dart_CObject* message) { |
7394 // Gets a null message. | 7270 // Gets a null message. |
7395 EXPECT_NOTNULL(message); | 7271 EXPECT_NOTNULL(message); |
7396 EXPECT_EQ(Dart_CObject_kArray, message->type); | 7272 EXPECT_EQ(Dart_CObject_kArray, message->type); |
7397 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | 7273 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
7398 | 7274 |
7399 // Post integer value. | 7275 // Post integer value. |
7400 Dart_PostInteger( | 7276 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7401 message->value.as_array.values[0]->value.as_send_port.id, 321); | 7277 321); |
7402 } | 7278 } |
7403 | 7279 |
7404 | 7280 |
7405 TEST_CASE(NativePortPostInteger) { | 7281 TEST_CASE(NativePortPostInteger) { |
7406 const char* kScriptChars = | 7282 const char* kScriptChars = |
7407 "import 'dart:isolate';\n" | 7283 "import 'dart:isolate';\n" |
7408 "void callPort(SendPort port) {\n" | 7284 "void callPort(SendPort port) {\n" |
7409 " var receivePort = new RawReceivePort();\n" | 7285 " var receivePort = new RawReceivePort();\n" |
7410 " var replyPort = receivePort.sendPort;\n" | 7286 " var replyPort = receivePort.sendPort;\n" |
7411 " port.send([replyPort]);\n" | 7287 " port.send([replyPort]);\n" |
(...skipping 11 matching lines...) Expand all Loading... |
7423 Dart_NewNativePort("Port321", NewNativePort_sendInteger321, true); | 7299 Dart_NewNativePort("Port321", NewNativePort_sendInteger321, true); |
7424 | 7300 |
7425 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 7301 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
7426 EXPECT_VALID(send_port1); | 7302 EXPECT_VALID(send_port1); |
7427 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); | 7303 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); |
7428 EXPECT_VALID(send_port2); | 7304 EXPECT_VALID(send_port2); |
7429 | 7305 |
7430 // Test first port. | 7306 // Test first port. |
7431 Dart_Handle dart_args[1]; | 7307 Dart_Handle dart_args[1]; |
7432 dart_args[0] = send_port1; | 7308 dart_args[0] = send_port1; |
7433 Dart_Handle result = | 7309 Dart_Handle result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
7434 Dart_Invoke(lib, NewString("callPort"), 1, dart_args); | |
7435 EXPECT_VALID(result); | 7310 EXPECT_VALID(result); |
7436 result = Dart_RunLoop(); | 7311 result = Dart_RunLoop(); |
7437 EXPECT(Dart_IsError(result)); | 7312 EXPECT(Dart_IsError(result)); |
7438 EXPECT(Dart_ErrorHasException(result)); | 7313 EXPECT(Dart_ErrorHasException(result)); |
7439 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 7314 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
7440 | 7315 |
7441 // result second port. | 7316 // result second port. |
7442 dart_args[0] = send_port2; | 7317 dart_args[0] = send_port2; |
7443 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); | 7318 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
7444 EXPECT_VALID(result); | 7319 EXPECT_VALID(result); |
7445 result = Dart_RunLoop(); | 7320 result = Dart_RunLoop(); |
7446 EXPECT(Dart_IsError(result)); | 7321 EXPECT(Dart_IsError(result)); |
7447 EXPECT(Dart_ErrorHasException(result)); | 7322 EXPECT(Dart_ErrorHasException(result)); |
7448 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 7323 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
7449 | 7324 |
7450 Dart_ExitScope(); | 7325 Dart_ExitScope(); |
7451 | 7326 |
7452 // Delete the native ports. | 7327 // Delete the native ports. |
7453 EXPECT(Dart_CloseNativePort(port_id1)); | 7328 EXPECT(Dart_CloseNativePort(port_id1)); |
7454 EXPECT(Dart_CloseNativePort(port_id2)); | 7329 EXPECT(Dart_CloseNativePort(port_id2)); |
7455 } | 7330 } |
7456 | 7331 |
7457 | 7332 |
7458 void NewNativePort_nativeReceiveNull(Dart_Port dest_port_id, | 7333 void NewNativePort_nativeReceiveNull(Dart_Port dest_port_id, |
7459 Dart_CObject *message) { | 7334 Dart_CObject* message) { |
7460 EXPECT_NOTNULL(message); | 7335 EXPECT_NOTNULL(message); |
7461 | 7336 |
7462 if ((message->type == Dart_CObject_kArray) && | 7337 if ((message->type == Dart_CObject_kArray) && |
7463 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { | 7338 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { |
7464 // Post integer value. | 7339 // Post integer value. |
7465 Dart_PostInteger( | 7340 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7466 message->value.as_array.values[0]->value.as_send_port.id, 123); | 7341 123); |
7467 } else { | 7342 } else { |
7468 EXPECT_EQ(message->type, Dart_CObject_kNull); | 7343 EXPECT_EQ(message->type, Dart_CObject_kNull); |
7469 } | 7344 } |
7470 } | 7345 } |
7471 | 7346 |
7472 | 7347 |
7473 TEST_CASE(NativePortReceiveNull) { | 7348 TEST_CASE(NativePortReceiveNull) { |
7474 const char* kScriptChars = | 7349 const char* kScriptChars = |
7475 "import 'dart:isolate';\n" | 7350 "import 'dart:isolate';\n" |
7476 "void callPort(SendPort port) {\n" | 7351 "void callPort(SendPort port) {\n" |
(...skipping 10 matching lines...) Expand all Loading... |
7487 Dart_EnterScope(); | 7362 Dart_EnterScope(); |
7488 | 7363 |
7489 Dart_Port port_id1 = | 7364 Dart_Port port_id1 = |
7490 Dart_NewNativePort("PortNull", NewNativePort_nativeReceiveNull, true); | 7365 Dart_NewNativePort("PortNull", NewNativePort_nativeReceiveNull, true); |
7491 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 7366 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
7492 EXPECT_VALID(send_port1); | 7367 EXPECT_VALID(send_port1); |
7493 | 7368 |
7494 // Test first port. | 7369 // Test first port. |
7495 Dart_Handle dart_args[1]; | 7370 Dart_Handle dart_args[1]; |
7496 dart_args[0] = send_port1; | 7371 dart_args[0] = send_port1; |
7497 Dart_Handle result = | 7372 Dart_Handle result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
7498 Dart_Invoke(lib, NewString("callPort"), 1, dart_args); | |
7499 EXPECT_VALID(result); | 7373 EXPECT_VALID(result); |
7500 result = Dart_RunLoop(); | 7374 result = Dart_RunLoop(); |
7501 EXPECT(Dart_IsError(result)); | 7375 EXPECT(Dart_IsError(result)); |
7502 EXPECT(Dart_ErrorHasException(result)); | 7376 EXPECT(Dart_ErrorHasException(result)); |
7503 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 7377 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
7504 | 7378 |
7505 Dart_ExitScope(); | 7379 Dart_ExitScope(); |
7506 | 7380 |
7507 // Delete the native ports. | 7381 // Delete the native ports. |
7508 EXPECT(Dart_CloseNativePort(port_id1)); | 7382 EXPECT(Dart_CloseNativePort(port_id1)); |
7509 } | 7383 } |
7510 | 7384 |
7511 | 7385 |
7512 void NewNativePort_nativeReceiveInteger(Dart_Port dest_port_id, | 7386 void NewNativePort_nativeReceiveInteger(Dart_Port dest_port_id, |
7513 Dart_CObject *message) { | 7387 Dart_CObject* message) { |
7514 EXPECT_NOTNULL(message); | 7388 EXPECT_NOTNULL(message); |
7515 | 7389 |
7516 if ((message->type == Dart_CObject_kArray) && | 7390 if ((message->type == Dart_CObject_kArray) && |
7517 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { | 7391 (message->value.as_array.values[0]->type == Dart_CObject_kSendPort)) { |
7518 // Post integer value. | 7392 // Post integer value. |
7519 Dart_PostInteger( | 7393 Dart_PostInteger(message->value.as_array.values[0]->value.as_send_port.id, |
7520 message->value.as_array.values[0]->value.as_send_port.id, 123); | 7394 123); |
7521 } else { | 7395 } else { |
7522 EXPECT_EQ(message->type, Dart_CObject_kInt32); | 7396 EXPECT_EQ(message->type, Dart_CObject_kInt32); |
7523 EXPECT_EQ(message->value.as_int32, 321); | 7397 EXPECT_EQ(message->value.as_int32, 321); |
7524 } | 7398 } |
7525 } | 7399 } |
7526 | 7400 |
7527 | 7401 |
7528 TEST_CASE(NativePortReceiveInteger) { | 7402 TEST_CASE(NativePortReceiveInteger) { |
7529 const char* kScriptChars = | 7403 const char* kScriptChars = |
7530 "import 'dart:isolate';\n" | 7404 "import 'dart:isolate';\n" |
(...skipping 11 matching lines...) Expand all Loading... |
7542 Dart_EnterScope(); | 7416 Dart_EnterScope(); |
7543 | 7417 |
7544 Dart_Port port_id1 = | 7418 Dart_Port port_id1 = |
7545 Dart_NewNativePort("PortNull", NewNativePort_nativeReceiveInteger, true); | 7419 Dart_NewNativePort("PortNull", NewNativePort_nativeReceiveInteger, true); |
7546 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 7420 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
7547 EXPECT_VALID(send_port1); | 7421 EXPECT_VALID(send_port1); |
7548 | 7422 |
7549 // Test first port. | 7423 // Test first port. |
7550 Dart_Handle dart_args[1]; | 7424 Dart_Handle dart_args[1]; |
7551 dart_args[0] = send_port1; | 7425 dart_args[0] = send_port1; |
7552 Dart_Handle result = | 7426 Dart_Handle result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
7553 Dart_Invoke(lib, NewString("callPort"), 1, dart_args); | |
7554 EXPECT_VALID(result); | 7427 EXPECT_VALID(result); |
7555 result = Dart_RunLoop(); | 7428 result = Dart_RunLoop(); |
7556 EXPECT(Dart_IsError(result)); | 7429 EXPECT(Dart_IsError(result)); |
7557 EXPECT(Dart_ErrorHasException(result)); | 7430 EXPECT(Dart_ErrorHasException(result)); |
7558 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); | 7431 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
7559 | 7432 |
7560 Dart_ExitScope(); | 7433 Dart_ExitScope(); |
7561 | 7434 |
7562 // Delete the native ports. | 7435 // Delete the native ports. |
7563 EXPECT(Dart_CloseNativePort(port_id1)); | 7436 EXPECT(Dart_CloseNativePort(port_id1)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7607 bool retval = Dart_IsolateMakeRunnable(isolate); | 7480 bool retval = Dart_IsolateMakeRunnable(isolate); |
7608 EXPECT(retval); | 7481 EXPECT(retval); |
7609 return isolate; | 7482 return isolate; |
7610 } | 7483 } |
7611 | 7484 |
7612 | 7485 |
7613 // Common code for RunLoop_Success/RunLoop_Failure. | 7486 // Common code for RunLoop_Success/RunLoop_Failure. |
7614 static void RunLoopTest(bool throw_exception) { | 7487 static void RunLoopTest(bool throw_exception) { |
7615 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 7488 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
7616 Isolate::SetCreateCallback(RunLoopTestCallback); | 7489 Isolate::SetCreateCallback(RunLoopTestCallback); |
7617 Dart_Isolate isolate = RunLoopTestCallback( | 7490 Dart_Isolate isolate = |
7618 NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 7491 RunLoopTestCallback(NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
7619 | 7492 |
7620 Dart_EnterIsolate(isolate); | 7493 Dart_EnterIsolate(isolate); |
7621 Dart_EnterScope(); | 7494 Dart_EnterScope(); |
7622 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 7495 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
7623 EXPECT_VALID(lib); | 7496 EXPECT_VALID(lib); |
7624 | 7497 |
7625 Dart_Handle result; | 7498 Dart_Handle result; |
7626 Dart_Handle args[1]; | 7499 Dart_Handle args[1]; |
7627 args[0] = (throw_exception ? Dart_True() : Dart_False()); | 7500 args[0] = (throw_exception ? Dart_True() : Dart_False()); |
7628 result = Dart_Invoke(lib, NewString("main"), 1, args); | 7501 result = Dart_Invoke(lib, NewString("main"), 1, args); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7664 MonitorLocker ml(sync); | 7537 MonitorLocker ml(sync); |
7665 main_entered = true; | 7538 main_entered = true; |
7666 ml.Notify(); | 7539 ml.Notify(); |
7667 } | 7540 } |
7668 Dart_SetReturnValue(args, Dart_Null()); | 7541 Dart_SetReturnValue(args, Dart_Null()); |
7669 Dart_ExitScope(); | 7542 Dart_ExitScope(); |
7670 } | 7543 } |
7671 | 7544 |
7672 | 7545 |
7673 static Dart_NativeFunction IsolateInterruptTestNativeLookup( | 7546 static Dart_NativeFunction IsolateInterruptTestNativeLookup( |
7674 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 7547 Dart_Handle name, |
| 7548 int argument_count, |
| 7549 bool* auto_setup_scope) { |
7675 ASSERT(auto_setup_scope != NULL); | 7550 ASSERT(auto_setup_scope != NULL); |
7676 *auto_setup_scope = false; | 7551 *auto_setup_scope = false; |
7677 return reinterpret_cast<Dart_NativeFunction>(&MarkMainEntered); | 7552 return reinterpret_cast<Dart_NativeFunction>(&MarkMainEntered); |
7678 } | 7553 } |
7679 | 7554 |
7680 | 7555 |
7681 void BusyLoop_start(uword unused) { | 7556 void BusyLoop_start(uword unused) { |
7682 const char* kScriptChars = | 7557 const char* kScriptChars = |
7683 "class Native {\n" | 7558 "class Native {\n" |
7684 " static void markMainEntered() native 'MarkMainEntered';\n" | 7559 " static void markMainEntered() native 'MarkMainEntered';\n" |
7685 "}\n" | 7560 "}\n" |
7686 "\n" | 7561 "\n" |
7687 "void main() {\n" | 7562 "void main() {\n" |
7688 " Native.markMainEntered();\n" | 7563 " Native.markMainEntered();\n" |
7689 " while (true) {\n" // Infinite empty loop. | 7564 " while (true) {\n" // Infinite empty loop. |
7690 " }\n" | 7565 " }\n" |
7691 "}\n"; | 7566 "}\n"; |
7692 | 7567 |
7693 // Tell the other thread that shared_isolate is created. | 7568 // Tell the other thread that shared_isolate is created. |
7694 Dart_Handle lib; | 7569 Dart_Handle lib; |
7695 { | 7570 { |
7696 MonitorLocker ml(sync); | 7571 MonitorLocker ml(sync); |
7697 char* error = NULL; | 7572 char* error = NULL; |
7698 shared_isolate = Dart_CreateIsolate(NULL, NULL, | 7573 shared_isolate = Dart_CreateIsolate( |
7699 bin::isolate_snapshot_buffer, | 7574 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, &error); |
7700 NULL, | |
7701 NULL, &error); | |
7702 EXPECT(shared_isolate != NULL); | 7575 EXPECT(shared_isolate != NULL); |
7703 Dart_EnterScope(); | 7576 Dart_EnterScope(); |
7704 Dart_Handle url = NewString(TestCase::url()); | 7577 Dart_Handle url = NewString(TestCase::url()); |
7705 Dart_Handle source = NewString(kScriptChars); | 7578 Dart_Handle source = NewString(kScriptChars); |
7706 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 7579 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
7707 EXPECT_VALID(result); | 7580 EXPECT_VALID(result); |
7708 lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); | 7581 lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7709 EXPECT_VALID(lib); | 7582 EXPECT_VALID(lib); |
7710 result = Dart_FinalizeLoading(false); | 7583 result = Dart_FinalizeLoading(false); |
7711 EXPECT_VALID(result); | 7584 EXPECT_VALID(result); |
7712 result = | 7585 result = |
7713 Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup, NULL); | 7586 Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup, NULL); |
7714 DART_CHECK_VALID(result); | 7587 DART_CHECK_VALID(result); |
7715 | 7588 |
7716 ml.Notify(); | 7589 ml.Notify(); |
7717 } | 7590 } |
7718 | 7591 |
7719 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 7592 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
7720 EXPECT(Dart_IsError(result)); | 7593 EXPECT(Dart_IsError(result)); |
7721 EXPECT(Dart_ErrorHasException(result)); | 7594 EXPECT(Dart_ErrorHasException(result)); |
7722 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", | 7595 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", Dart_GetError(result)); |
7723 Dart_GetError(result)); | |
7724 | 7596 |
7725 Dart_ExitScope(); | 7597 Dart_ExitScope(); |
7726 Dart_ShutdownIsolate(); | 7598 Dart_ShutdownIsolate(); |
7727 | 7599 |
7728 // Tell the other thread that we are done. | 7600 // Tell the other thread that we are done. |
7729 { | 7601 { |
7730 MonitorLocker ml(sync); | 7602 MonitorLocker ml(sync); |
7731 shared_isolate = NULL; | 7603 shared_isolate = NULL; |
7732 ml.Notify(); | 7604 ml.Notify(); |
7733 } | 7605 } |
7734 } | 7606 } |
7735 | 7607 |
7736 | 7608 |
7737 static void* saved_callback_data; | 7609 static void* saved_callback_data; |
7738 static void IsolateShutdownTestCallback(void* callback_data) { | 7610 static void IsolateShutdownTestCallback(void* callback_data) { |
7739 saved_callback_data = callback_data; | 7611 saved_callback_data = callback_data; |
7740 } | 7612 } |
7741 | 7613 |
7742 UNIT_TEST_CASE(IsolateShutdown) { | 7614 UNIT_TEST_CASE(IsolateShutdown) { |
7743 Dart_IsolateShutdownCallback saved = Isolate::ShutdownCallback(); | 7615 Dart_IsolateShutdownCallback saved = Isolate::ShutdownCallback(); |
7744 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); | 7616 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); |
7745 | 7617 |
7746 saved_callback_data = NULL; | 7618 saved_callback_data = NULL; |
7747 | 7619 |
7748 void* my_data = reinterpret_cast<void*>(12345); | 7620 void* my_data = reinterpret_cast<void*>(12345); |
7749 | 7621 |
7750 // Create an isolate. | 7622 // Create an isolate. |
7751 char* err; | 7623 char* err; |
7752 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, | 7624 Dart_Isolate isolate = Dart_CreateIsolate( |
7753 bin::isolate_snapshot_buffer, | 7625 NULL, NULL, bin::isolate_snapshot_buffer, NULL, my_data, &err); |
7754 NULL, | |
7755 my_data, &err); | |
7756 if (isolate == NULL) { | 7626 if (isolate == NULL) { |
7757 OS::Print("Creation of isolate failed '%s'\n", err); | 7627 OS::Print("Creation of isolate failed '%s'\n", err); |
7758 free(err); | 7628 free(err); |
7759 } | 7629 } |
7760 EXPECT(isolate != NULL); | 7630 EXPECT(isolate != NULL); |
7761 | 7631 |
7762 // The shutdown callback has not been called. | 7632 // The shutdown callback has not been called. |
7763 EXPECT_EQ(0, reinterpret_cast<intptr_t>(saved_callback_data)); | 7633 EXPECT_EQ(0, reinterpret_cast<intptr_t>(saved_callback_data)); |
7764 | 7634 |
7765 // Shutdown the isolate. | 7635 // Shutdown the isolate. |
7766 Dart_ShutdownIsolate(); | 7636 Dart_ShutdownIsolate(); |
7767 | 7637 |
7768 // The shutdown callback has been called. | 7638 // The shutdown callback has been called. |
7769 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); | 7639 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); |
7770 | 7640 |
7771 Isolate::SetShutdownCallback(saved); | 7641 Isolate::SetShutdownCallback(saved); |
7772 } | 7642 } |
7773 | 7643 |
7774 static int64_t add_result = 0; | 7644 static int64_t add_result = 0; |
7775 static void IsolateShutdownRunDartCodeTestCallback(void* callback_data) { | 7645 static void IsolateShutdownRunDartCodeTestCallback(void* callback_data) { |
7776 Dart_EnterScope(); | 7646 Dart_EnterScope(); |
7777 Dart_Handle lib = Dart_RootLibrary(); | 7647 Dart_Handle lib = Dart_RootLibrary(); |
7778 EXPECT_VALID(lib); | 7648 EXPECT_VALID(lib); |
7779 Dart_Handle arg1 = Dart_NewInteger(90); | 7649 Dart_Handle arg1 = Dart_NewInteger(90); |
7780 EXPECT_VALID(arg1); | 7650 EXPECT_VALID(arg1); |
7781 Dart_Handle arg2 = Dart_NewInteger(9); | 7651 Dart_Handle arg2 = Dart_NewInteger(9); |
7782 EXPECT_VALID(arg2); | 7652 EXPECT_VALID(arg2); |
7783 Dart_Handle dart_args[2] = { arg1, arg2 }; | 7653 Dart_Handle dart_args[2] = {arg1, arg2}; |
7784 Dart_Handle result = Dart_Invoke(lib, NewString("add"), 2, dart_args); | 7654 Dart_Handle result = Dart_Invoke(lib, NewString("add"), 2, dart_args); |
7785 EXPECT_VALID(result); | 7655 EXPECT_VALID(result); |
7786 result = Dart_IntegerToInt64(result, &add_result); | 7656 result = Dart_IntegerToInt64(result, &add_result); |
7787 EXPECT_VALID(result); | 7657 EXPECT_VALID(result); |
7788 Dart_ExitScope(); | 7658 Dart_ExitScope(); |
7789 } | 7659 } |
7790 | 7660 |
7791 UNIT_TEST_CASE(IsolateShutdownRunDartCode) { | 7661 UNIT_TEST_CASE(IsolateShutdownRunDartCode) { |
7792 const char* kScriptChars = | 7662 const char* kScriptChars = |
7793 "int add(int a, int b) {\n" | 7663 "int add(int a, int b) {\n" |
7794 " return a + b;\n" | 7664 " return a + b;\n" |
7795 "}\n" | 7665 "}\n" |
7796 "\n" | 7666 "\n" |
7797 "void main() {\n" | 7667 "void main() {\n" |
7798 " add(4, 5);\n" | 7668 " add(4, 5);\n" |
7799 "}\n"; | 7669 "}\n"; |
7800 | 7670 |
7801 // Create an isolate. | 7671 // Create an isolate. |
7802 char* err; | 7672 char* err; |
7803 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, | 7673 Dart_Isolate isolate = Dart_CreateIsolate( |
7804 bin::isolate_snapshot_buffer, | 7674 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, &err); |
7805 NULL, | |
7806 NULL, &err); | |
7807 if (isolate == NULL) { | 7675 if (isolate == NULL) { |
7808 OS::Print("Creation of isolate failed '%s'\n", err); | 7676 OS::Print("Creation of isolate failed '%s'\n", err); |
7809 free(err); | 7677 free(err); |
7810 } | 7678 } |
7811 EXPECT(isolate != NULL); | 7679 EXPECT(isolate != NULL); |
7812 | 7680 |
7813 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); | 7681 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); |
7814 | 7682 |
7815 { | 7683 { |
7816 Dart_EnterScope(); | 7684 Dart_EnterScope(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7861 | 7729 |
7862 static void NativeFoo2(Dart_NativeArguments args) { | 7730 static void NativeFoo2(Dart_NativeArguments args) { |
7863 Dart_EnterScope(); | 7731 Dart_EnterScope(); |
7864 intptr_t i = Dart_GetNativeArgumentCount(args); | 7732 intptr_t i = Dart_GetNativeArgumentCount(args); |
7865 EXPECT_EQ(2, i); | 7733 EXPECT_EQ(2, i); |
7866 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); | 7734 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); |
7867 EXPECT_VALID(arg1); | 7735 EXPECT_VALID(arg1); |
7868 int64_t value = 0; | 7736 int64_t value = 0; |
7869 EXPECT_VALID(Dart_IntegerToInt64(arg1, &value)); | 7737 EXPECT_VALID(Dart_IntegerToInt64(arg1, &value)); |
7870 int64_t integer_value = 0; | 7738 int64_t integer_value = 0; |
7871 Dart_Handle result = Dart_GetNativeIntegerArgument(args, | 7739 Dart_Handle result = Dart_GetNativeIntegerArgument(args, 1, &integer_value); |
7872 1, | |
7873 &integer_value); | |
7874 EXPECT_VALID(result); | 7740 EXPECT_VALID(result); |
7875 EXPECT_EQ(value, integer_value); | 7741 EXPECT_EQ(value, integer_value); |
7876 double double_value; | 7742 double double_value; |
7877 result = Dart_GetNativeDoubleArgument(args, 1, &double_value); | 7743 result = Dart_GetNativeDoubleArgument(args, 1, &double_value); |
7878 EXPECT_VALID(result); | 7744 EXPECT_VALID(result); |
7879 bool bool_value; | 7745 bool bool_value; |
7880 result = Dart_GetNativeBooleanArgument(args, 1, &bool_value); | 7746 result = Dart_GetNativeBooleanArgument(args, 1, &bool_value); |
7881 EXPECT(Dart_IsError(result)); | 7747 EXPECT(Dart_IsError(result)); |
7882 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1))); | 7748 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1))); |
7883 Dart_ExitScope(); | 7749 Dart_ExitScope(); |
(...skipping 11 matching lines...) Expand all Loading... |
7895 } | 7761 } |
7896 | 7762 |
7897 | 7763 |
7898 static void NativeFoo4(Dart_NativeArguments args) { | 7764 static void NativeFoo4(Dart_NativeArguments args) { |
7899 Dart_EnterScope(); | 7765 Dart_EnterScope(); |
7900 intptr_t i = Dart_GetNativeArgumentCount(args); | 7766 intptr_t i = Dart_GetNativeArgumentCount(args); |
7901 EXPECT_EQ(4, i); | 7767 EXPECT_EQ(4, i); |
7902 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); | 7768 Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); |
7903 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); | 7769 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); |
7904 Dart_Handle arg3 = Dart_GetNativeArgument(args, 3); | 7770 Dart_Handle arg3 = Dart_GetNativeArgument(args, 3); |
7905 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1) + | 7771 Dart_SetReturnValue( |
7906 GetValue(arg2) + | 7772 args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2) + GetValue(arg3))); |
7907 GetValue(arg3))); | |
7908 Dart_ExitScope(); | 7773 Dart_ExitScope(); |
7909 } | 7774 } |
7910 | 7775 |
7911 | 7776 |
7912 static Dart_NativeFunction MyNativeClosureResolver(Dart_Handle name, | 7777 static Dart_NativeFunction MyNativeClosureResolver(Dart_Handle name, |
7913 int arg_count, | 7778 int arg_count, |
7914 bool* auto_setup_scope) { | 7779 bool* auto_setup_scope) { |
7915 ASSERT(auto_setup_scope != NULL); | 7780 ASSERT(auto_setup_scope != NULL); |
7916 *auto_setup_scope = false; | 7781 *auto_setup_scope = false; |
7917 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 7782 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8044 } | 7909 } |
8045 | 7910 |
8046 | 7911 |
8047 static void StaticNativeFoo4(Dart_NativeArguments args) { | 7912 static void StaticNativeFoo4(Dart_NativeArguments args) { |
8048 Dart_EnterScope(); | 7913 Dart_EnterScope(); |
8049 intptr_t i = Dart_GetNativeArgumentCount(args); | 7914 intptr_t i = Dart_GetNativeArgumentCount(args); |
8050 EXPECT_EQ(3, i); | 7915 EXPECT_EQ(3, i); |
8051 Dart_Handle arg1 = Dart_GetNativeArgument(args, 0); | 7916 Dart_Handle arg1 = Dart_GetNativeArgument(args, 0); |
8052 Dart_Handle arg2 = Dart_GetNativeArgument(args, 1); | 7917 Dart_Handle arg2 = Dart_GetNativeArgument(args, 1); |
8053 Dart_Handle arg3 = Dart_GetNativeArgument(args, 2); | 7918 Dart_Handle arg3 = Dart_GetNativeArgument(args, 2); |
8054 Dart_SetReturnValue(args, Dart_NewInteger(GetValue(arg1) + | 7919 Dart_SetReturnValue( |
8055 GetValue(arg2) + | 7920 args, Dart_NewInteger(GetValue(arg1) + GetValue(arg2) + GetValue(arg3))); |
8056 GetValue(arg3))); | |
8057 Dart_ExitScope(); | 7921 Dart_ExitScope(); |
8058 } | 7922 } |
8059 | 7923 |
8060 | 7924 |
8061 static Dart_NativeFunction MyStaticNativeClosureResolver( | 7925 static Dart_NativeFunction MyStaticNativeClosureResolver( |
8062 Dart_Handle name, int arg_count, bool* auto_setup_scope) { | 7926 Dart_Handle name, |
| 7927 int arg_count, |
| 7928 bool* auto_setup_scope) { |
8063 ASSERT(auto_setup_scope != NULL); | 7929 ASSERT(auto_setup_scope != NULL); |
8064 *auto_setup_scope = false; | 7930 *auto_setup_scope = false; |
8065 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 7931 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
8066 if (!obj.IsString()) { | 7932 if (!obj.IsString()) { |
8067 return NULL; | 7933 return NULL; |
8068 } | 7934 } |
8069 const char* function_name = obj.ToCString(); | 7935 const char* function_name = obj.ToCString(); |
8070 const char* kNativeFoo1 = "StaticNativeFoo1"; | 7936 const char* kNativeFoo1 = "StaticNativeFoo1"; |
8071 const char* kNativeFoo2 = "StaticNativeFoo2"; | 7937 const char* kNativeFoo2 = "StaticNativeFoo2"; |
8072 const char* kNativeFoo3 = "StaticNativeFoo3"; | 7938 const char* kNativeFoo3 = "StaticNativeFoo3"; |
(...skipping 12 matching lines...) Expand all Loading... |
8085 } | 7951 } |
8086 } | 7952 } |
8087 | 7953 |
8088 | 7954 |
8089 TEST_CASE(NativeStaticFunctionClosure) { | 7955 TEST_CASE(NativeStaticFunctionClosure) { |
8090 const char* kScriptChars = | 7956 const char* kScriptChars = |
8091 "class Test {" | 7957 "class Test {" |
8092 " static int foo1() native \"StaticNativeFoo1\";\n" | 7958 " static int foo1() native \"StaticNativeFoo1\";\n" |
8093 " static int foo2(int i) native \"StaticNativeFoo2\";\n" | 7959 " static int foo2(int i) native \"StaticNativeFoo2\";\n" |
8094 " static int foo3([int k = 10000, int l = 1])" | 7960 " static int foo3([int k = 10000, int l = 1])" |
8095 " native \"StaticNativeFoo3\";\n" | 7961 " native \"StaticNativeFoo3\";\n" |
8096 " static int foo4(int i, [int j = 10, int k = 1])" | 7962 " static int foo4(int i, [int j = 10, int k = 1])" |
8097 " native \"StaticNativeFoo4\";\n" | 7963 " native \"StaticNativeFoo4\";\n" |
8098 " int bar1() { var func = foo1; return func(); }\n" | 7964 " int bar1() { var func = foo1; return func(); }\n" |
8099 " int bar2(int i) { var func = foo2; return func(i); }\n" | 7965 " int bar2(int i) { var func = foo2; return func(i); }\n" |
8100 " int bar30() { var func = foo3; return func(); }\n" | 7966 " int bar30() { var func = foo3; return func(); }\n" |
8101 " int bar31(int i) { var func = foo3; return func(i); }\n" | 7967 " int bar31(int i) { var func = foo3; return func(i); }\n" |
8102 " int bar32(int i, int j) { var func = foo3; return func(i, j); }\n" | 7968 " int bar32(int i, int j) { var func = foo3; return func(i, j); }\n" |
8103 " int bar41(int i) {\n" | 7969 " int bar41(int i) {\n" |
8104 " var func = foo4; return func(i); }\n" | 7970 " var func = foo4; return func(i); }\n" |
8105 " int bar42(int i, int j) {\n" | 7971 " int bar42(int i, int j) {\n" |
8106 " var func = foo4; return func(i, j); }\n" | 7972 " var func = foo4; return func(i, j); }\n" |
8107 " int bar43(int i, int j, int k) {\n" | 7973 " int bar43(int i, int j, int k) {\n" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8163 } | 8029 } |
8164 | 8030 |
8165 | 8031 |
8166 TEST_CASE(RangeLimits) { | 8032 TEST_CASE(RangeLimits) { |
8167 uint8_t chars8[1] = {'a'}; | 8033 uint8_t chars8[1] = {'a'}; |
8168 uint16_t chars16[1] = {'a'}; | 8034 uint16_t chars16[1] = {'a'}; |
8169 int32_t chars32[1] = {'a'}; | 8035 int32_t chars32[1] = {'a'}; |
8170 | 8036 |
8171 EXPECT_ERROR(Dart_NewList(-1), | 8037 EXPECT_ERROR(Dart_NewList(-1), |
8172 "expects argument 'length' to be in the range"); | 8038 "expects argument 'length' to be in the range"); |
8173 EXPECT_ERROR(Dart_NewList(Array::kMaxElements+1), | 8039 EXPECT_ERROR(Dart_NewList(Array::kMaxElements + 1), |
8174 "expects argument 'length' to be in the range"); | 8040 "expects argument 'length' to be in the range"); |
8175 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, -1), | 8041 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, -1), |
8176 "expects argument 'length' to be in the range"); | 8042 "expects argument 'length' to be in the range"); |
8177 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, OneByteString::kMaxElements+1), | 8043 EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, OneByteString::kMaxElements + 1), |
8178 "expects argument 'length' to be in the range"); | 8044 "expects argument 'length' to be in the range"); |
8179 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, -1), | 8045 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, -1), |
8180 "expects argument 'length' to be in the range"); | 8046 "expects argument 'length' to be in the range"); |
8181 EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, TwoByteString::kMaxElements+1), | 8047 EXPECT_ERROR( |
8182 "expects argument 'length' to be in the range"); | 8048 Dart_NewStringFromUTF16(chars16, TwoByteString::kMaxElements + 1), |
| 8049 "expects argument 'length' to be in the range"); |
8183 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, -1), | 8050 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, -1), |
8184 "expects argument 'length' to be in the range"); | 8051 "expects argument 'length' to be in the range"); |
8185 EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, TwoByteString::kMaxElements+1), | 8052 EXPECT_ERROR( |
8186 "expects argument 'length' to be in the range"); | 8053 Dart_NewStringFromUTF32(chars32, TwoByteString::kMaxElements + 1), |
| 8054 "expects argument 'length' to be in the range"); |
8187 } | 8055 } |
8188 | 8056 |
8189 | 8057 |
8190 TEST_CASE(NewString_Null) { | 8058 TEST_CASE(NewString_Null) { |
8191 Dart_Handle str = Dart_NewStringFromUTF8(NULL, 0); | 8059 Dart_Handle str = Dart_NewStringFromUTF8(NULL, 0); |
8192 EXPECT_VALID(str); | 8060 EXPECT_VALID(str); |
8193 EXPECT(Dart_IsString(str)); | 8061 EXPECT(Dart_IsString(str)); |
8194 intptr_t len = -1; | 8062 intptr_t len = -1; |
8195 EXPECT_VALID(Dart_StringLength(str, &len)); | 8063 EXPECT_VALID(Dart_StringLength(str, &len)); |
8196 EXPECT_EQ(0, len); | 8064 EXPECT_EQ(0, len); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8642 | 8510 |
8643 static int peer8 = 40; | 8511 static int peer8 = 40; |
8644 static int peer16 = 41; | 8512 static int peer16 = 41; |
8645 static int canonical_str_peer = 42; | 8513 static int canonical_str_peer = 42; |
8646 intptr_t length = 0; | 8514 intptr_t length = 0; |
8647 intptr_t expected_length = 0; | 8515 intptr_t expected_length = 0; |
8648 { | 8516 { |
8649 Dart_EnterScope(); | 8517 Dart_EnterScope(); |
8650 | 8518 |
8651 // First test some negative conditions. | 8519 // First test some negative conditions. |
8652 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; | 8520 uint8_t data8[] = {'h', 'e', 'l', 'l', 'o'}; |
8653 const char* err = "string"; | 8521 const char* err = "string"; |
8654 Dart_Handle err_str = NewString(err); | 8522 Dart_Handle err_str = NewString(err); |
8655 Dart_Handle ext_err_str = Dart_NewExternalLatin1String( | 8523 Dart_Handle ext_err_str = |
8656 data8, ARRAY_SIZE(data8), NULL, NULL); | 8524 Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), NULL, NULL); |
8657 Dart_Handle result = Dart_MakeExternalString(Dart_Null(), | 8525 Dart_Handle result = Dart_MakeExternalString(Dart_Null(), data8, |
8658 data8, | 8526 ARRAY_SIZE(data8), NULL, NULL); |
8659 ARRAY_SIZE(data8), | |
8660 NULL, | |
8661 NULL); | |
8662 EXPECT(Dart_IsError(result)); // Null string object passed in. | 8527 EXPECT(Dart_IsError(result)); // Null string object passed in. |
8663 result = Dart_MakeExternalString(err_str, | 8528 result = |
8664 NULL, | 8529 Dart_MakeExternalString(err_str, NULL, ARRAY_SIZE(data8), NULL, NULL); |
8665 ARRAY_SIZE(data8), | |
8666 NULL, | |
8667 NULL); | |
8668 EXPECT(Dart_IsError(result)); // Null array pointer passed in. | 8530 EXPECT(Dart_IsError(result)); // Null array pointer passed in. |
8669 result = Dart_MakeExternalString(err_str, | 8531 result = Dart_MakeExternalString(err_str, data8, 1, NULL, NULL); |
8670 data8, | |
8671 1, | |
8672 NULL, | |
8673 NULL); | |
8674 EXPECT(Dart_IsError(result)); // Invalid length passed in. | 8532 EXPECT(Dart_IsError(result)); // Invalid length passed in. |
8675 | 8533 |
8676 const intptr_t kLength = 10; | 8534 const intptr_t kLength = 10; |
8677 intptr_t size = 0; | 8535 intptr_t size = 0; |
8678 | 8536 |
8679 // Test with an external string. | 8537 // Test with an external string. |
8680 result = Dart_MakeExternalString(ext_err_str, | 8538 result = Dart_MakeExternalString(ext_err_str, data8, ARRAY_SIZE(data8), |
8681 data8, | 8539 NULL, NULL); |
8682 ARRAY_SIZE(data8), | |
8683 NULL, | |
8684 NULL); | |
8685 EXPECT(Dart_IsString(result)); | 8540 EXPECT(Dart_IsString(result)); |
8686 EXPECT(Dart_IsExternalString(result)); | 8541 EXPECT(Dart_IsExternalString(result)); |
8687 | 8542 |
8688 // Test with an empty string. | 8543 // Test with an empty string. |
8689 Dart_Handle empty_str = NewString(""); | 8544 Dart_Handle empty_str = NewString(""); |
8690 EXPECT(Dart_IsString(empty_str)); | 8545 EXPECT(Dart_IsString(empty_str)); |
8691 EXPECT(!Dart_IsExternalString(empty_str)); | 8546 EXPECT(!Dart_IsExternalString(empty_str)); |
8692 uint8_t ext_empty_str[kLength]; | 8547 uint8_t ext_empty_str[kLength]; |
8693 Dart_Handle str = Dart_MakeExternalString(empty_str, | 8548 Dart_Handle str = |
8694 ext_empty_str, | 8549 Dart_MakeExternalString(empty_str, ext_empty_str, kLength, NULL, NULL); |
8695 kLength, | |
8696 NULL, | |
8697 NULL); | |
8698 EXPECT(Dart_IsString(str)); | 8550 EXPECT(Dart_IsString(str)); |
8699 EXPECT(Dart_IsString(empty_str)); | 8551 EXPECT(Dart_IsString(empty_str)); |
8700 EXPECT(Dart_IsStringLatin1(str)); | 8552 EXPECT(Dart_IsStringLatin1(str)); |
8701 EXPECT(Dart_IsStringLatin1(empty_str)); | 8553 EXPECT(Dart_IsStringLatin1(empty_str)); |
8702 EXPECT(Dart_IsExternalString(str)); | 8554 EXPECT(Dart_IsExternalString(str)); |
8703 EXPECT(Dart_IsExternalString(empty_str)); | 8555 EXPECT(Dart_IsExternalString(empty_str)); |
8704 EXPECT_VALID(Dart_StringLength(str, &length)); | 8556 EXPECT_VALID(Dart_StringLength(str, &length)); |
8705 EXPECT_EQ(0, length); | 8557 EXPECT_EQ(0, length); |
8706 | 8558 |
8707 // Test with single character canonical string, it should not become | 8559 // Test with single character canonical string, it should not become |
8708 // external string but the peer should be setup for it. | 8560 // external string but the peer should be setup for it. |
8709 Dart_Handle canonical_str = Api::NewHandle(thread, Symbols::New(thread, | 8561 Dart_Handle canonical_str = |
8710 "*")); | 8562 Api::NewHandle(thread, Symbols::New(thread, "*")); |
8711 EXPECT(Dart_IsString(canonical_str)); | 8563 EXPECT(Dart_IsString(canonical_str)); |
8712 EXPECT(!Dart_IsExternalString(canonical_str)); | 8564 EXPECT(!Dart_IsExternalString(canonical_str)); |
8713 uint8_t ext_canonical_str[kLength]; | 8565 uint8_t ext_canonical_str[kLength]; |
8714 str = Dart_MakeExternalString(canonical_str, | 8566 str = Dart_MakeExternalString(canonical_str, ext_canonical_str, kLength, |
8715 ext_canonical_str, | 8567 &canonical_str_peer, MakeExternalCback); |
8716 kLength, | |
8717 &canonical_str_peer, | |
8718 MakeExternalCback); | |
8719 EXPECT(Dart_IsString(str)); | 8568 EXPECT(Dart_IsString(str)); |
8720 EXPECT(!Dart_IsExternalString(canonical_str)); | 8569 EXPECT(!Dart_IsExternalString(canonical_str)); |
8721 EXPECT_EQ(canonical_str, str); | 8570 EXPECT_EQ(canonical_str, str); |
8722 EXPECT(Dart_IsString(canonical_str)); | 8571 EXPECT(Dart_IsString(canonical_str)); |
8723 EXPECT(!Dart_IsExternalString(canonical_str)); | 8572 EXPECT(!Dart_IsExternalString(canonical_str)); |
8724 void* peer; | 8573 void* peer; |
8725 EXPECT_VALID(Dart_StringGetProperties(str, &size, &length, &peer)); | 8574 EXPECT_VALID(Dart_StringGetProperties(str, &size, &length, &peer)); |
8726 EXPECT_EQ(1, size); | 8575 EXPECT_EQ(1, size); |
8727 EXPECT_EQ(1, length); | 8576 EXPECT_EQ(1, length); |
8728 EXPECT_EQ(reinterpret_cast<void*>(&canonical_str_peer), peer); | 8577 EXPECT_EQ(reinterpret_cast<void*>(&canonical_str_peer), peer); |
8729 | 8578 |
8730 // Test with a one byte ascii string. | 8579 // Test with a one byte ascii string. |
8731 const char* ascii = "?unseen"; | 8580 const char* ascii = "?unseen"; |
8732 expected_length = strlen(ascii); | 8581 expected_length = strlen(ascii); |
8733 Dart_Handle ascii_str = NewString(ascii); | 8582 Dart_Handle ascii_str = NewString(ascii); |
8734 EXPECT_VALID(ascii_str); | 8583 EXPECT_VALID(ascii_str); |
8735 EXPECT(Dart_IsString(ascii_str)); | 8584 EXPECT(Dart_IsString(ascii_str)); |
8736 EXPECT(Dart_IsStringLatin1(ascii_str)); | 8585 EXPECT(Dart_IsStringLatin1(ascii_str)); |
8737 EXPECT(!Dart_IsExternalString(ascii_str)); | 8586 EXPECT(!Dart_IsExternalString(ascii_str)); |
8738 EXPECT_VALID(Dart_StringLength(ascii_str, &length)); | 8587 EXPECT_VALID(Dart_StringLength(ascii_str, &length)); |
8739 EXPECT_EQ(expected_length, length); | 8588 EXPECT_EQ(expected_length, length); |
8740 | 8589 |
8741 uint8_t ext_ascii_str[kLength]; | 8590 uint8_t ext_ascii_str[kLength]; |
8742 EXPECT_VALID(Dart_StringStorageSize(ascii_str, &size)); | 8591 EXPECT_VALID(Dart_StringStorageSize(ascii_str, &size)); |
8743 str = Dart_MakeExternalString(ascii_str, | 8592 str = Dart_MakeExternalString(ascii_str, ext_ascii_str, size, &peer8, |
8744 ext_ascii_str, | |
8745 size, | |
8746 &peer8, | |
8747 MakeExternalCback); | 8593 MakeExternalCback); |
8748 EXPECT(Dart_IsString(str)); | 8594 EXPECT(Dart_IsString(str)); |
8749 EXPECT(Dart_IsString(ascii_str)); | 8595 EXPECT(Dart_IsString(ascii_str)); |
8750 EXPECT(Dart_IsStringLatin1(str)); | 8596 EXPECT(Dart_IsStringLatin1(str)); |
8751 EXPECT(Dart_IsStringLatin1(ascii_str)); | 8597 EXPECT(Dart_IsStringLatin1(ascii_str)); |
8752 EXPECT(Dart_IsExternalString(str)); | 8598 EXPECT(Dart_IsExternalString(str)); |
8753 EXPECT(Dart_IsExternalString(ascii_str)); | 8599 EXPECT(Dart_IsExternalString(ascii_str)); |
8754 EXPECT_VALID(Dart_StringLength(str, &length)); | 8600 EXPECT_VALID(Dart_StringLength(str, &length)); |
8755 EXPECT_EQ(expected_length, length); | 8601 EXPECT_EQ(expected_length, length); |
8756 EXPECT_VALID(Dart_StringLength(ascii_str, &length)); | 8602 EXPECT_VALID(Dart_StringLength(ascii_str, &length)); |
8757 EXPECT_EQ(expected_length, length); | 8603 EXPECT_EQ(expected_length, length); |
8758 EXPECT(Dart_IdentityEquals(str, ascii_str)); | 8604 EXPECT(Dart_IdentityEquals(str, ascii_str)); |
8759 for (intptr_t i = 0; i < length; i++) { | 8605 for (intptr_t i = 0; i < length; i++) { |
8760 EXPECT_EQ(ascii[i], ext_ascii_str[i]); | 8606 EXPECT_EQ(ascii[i], ext_ascii_str[i]); |
8761 } | 8607 } |
8762 | 8608 |
8763 uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. | 8609 uint8_t data[] = {0xE4, 0xBA, 0x8c}; // U+4E8C. |
8764 expected_length = 1; | 8610 expected_length = 1; |
8765 Dart_Handle utf16_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | 8611 Dart_Handle utf16_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); |
8766 EXPECT_VALID(utf16_str); | 8612 EXPECT_VALID(utf16_str); |
8767 EXPECT(Dart_IsString(utf16_str)); | 8613 EXPECT(Dart_IsString(utf16_str)); |
8768 EXPECT(!Dart_IsStringLatin1(utf16_str)); | 8614 EXPECT(!Dart_IsStringLatin1(utf16_str)); |
8769 EXPECT(!Dart_IsExternalString(utf16_str)); | 8615 EXPECT(!Dart_IsExternalString(utf16_str)); |
8770 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); | 8616 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); |
8771 EXPECT_EQ(expected_length, length); | 8617 EXPECT_EQ(expected_length, length); |
8772 | 8618 |
8773 // Test with a two byte string. | 8619 // Test with a two byte string. |
8774 uint16_t ext_utf16_str[kLength]; | 8620 uint16_t ext_utf16_str[kLength]; |
8775 EXPECT_VALID(Dart_StringStorageSize(utf16_str, &size)); | 8621 EXPECT_VALID(Dart_StringStorageSize(utf16_str, &size)); |
8776 str = Dart_MakeExternalString(utf16_str, | 8622 str = Dart_MakeExternalString(utf16_str, ext_utf16_str, size, &peer16, |
8777 ext_utf16_str, | |
8778 size, | |
8779 &peer16, | |
8780 MakeExternalCback); | 8623 MakeExternalCback); |
8781 EXPECT(Dart_IsString(str)); | 8624 EXPECT(Dart_IsString(str)); |
8782 EXPECT(Dart_IsString(utf16_str)); | 8625 EXPECT(Dart_IsString(utf16_str)); |
8783 EXPECT(!Dart_IsStringLatin1(str)); | 8626 EXPECT(!Dart_IsStringLatin1(str)); |
8784 EXPECT(!Dart_IsStringLatin1(utf16_str)); | 8627 EXPECT(!Dart_IsStringLatin1(utf16_str)); |
8785 EXPECT(Dart_IsExternalString(str)); | 8628 EXPECT(Dart_IsExternalString(str)); |
8786 EXPECT(Dart_IsExternalString(utf16_str)); | 8629 EXPECT(Dart_IsExternalString(utf16_str)); |
8787 EXPECT_VALID(Dart_StringLength(str, &length)); | 8630 EXPECT_VALID(Dart_StringLength(str, &length)); |
8788 EXPECT_EQ(expected_length, length); | 8631 EXPECT_EQ(expected_length, length); |
8789 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); | 8632 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); |
8790 EXPECT_EQ(expected_length, length); | 8633 EXPECT_EQ(expected_length, length); |
8791 EXPECT(Dart_IdentityEquals(str, utf16_str)); | 8634 EXPECT(Dart_IdentityEquals(str, utf16_str)); |
8792 for (intptr_t i = 0; i < length; i++) { | 8635 for (intptr_t i = 0; i < length; i++) { |
8793 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); | 8636 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); |
8794 } | 8637 } |
8795 | 8638 |
8796 Zone* zone = thread->zone(); | 8639 Zone* zone = thread->zone(); |
8797 // Test with a symbol (hash value should be preserved on externalization). | 8640 // Test with a symbol (hash value should be preserved on externalization). |
8798 const char* symbol_ascii = "?unseen"; | 8641 const char* symbol_ascii = "?unseen"; |
8799 expected_length = strlen(symbol_ascii); | 8642 expected_length = strlen(symbol_ascii); |
8800 Dart_Handle symbol_str = Api::NewHandle(thread, | 8643 Dart_Handle symbol_str = Api::NewHandle( |
8801 Symbols::New(thread, symbol_ascii, expected_length)); | 8644 thread, Symbols::New(thread, symbol_ascii, expected_length)); |
8802 EXPECT_VALID(symbol_str); | 8645 EXPECT_VALID(symbol_str); |
8803 EXPECT(Dart_IsString(symbol_str)); | 8646 EXPECT(Dart_IsString(symbol_str)); |
8804 EXPECT(Dart_IsStringLatin1(symbol_str)); | 8647 EXPECT(Dart_IsStringLatin1(symbol_str)); |
8805 EXPECT(!Dart_IsExternalString(symbol_str)); | 8648 EXPECT(!Dart_IsExternalString(symbol_str)); |
8806 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); | 8649 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); |
8807 EXPECT_EQ(expected_length, length); | 8650 EXPECT_EQ(expected_length, length); |
8808 EXPECT(Api::UnwrapStringHandle(zone, symbol_str).HasHash()); | 8651 EXPECT(Api::UnwrapStringHandle(zone, symbol_str).HasHash()); |
8809 | 8652 |
8810 uint8_t ext_symbol_ascii[kLength]; | 8653 uint8_t ext_symbol_ascii[kLength]; |
8811 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); | 8654 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); |
8812 str = Dart_MakeExternalString(symbol_str, | 8655 str = Dart_MakeExternalString(symbol_str, ext_symbol_ascii, size, &peer8, |
8813 ext_symbol_ascii, | |
8814 size, | |
8815 &peer8, | |
8816 MakeExternalCback); | 8656 MakeExternalCback); |
8817 EXPECT(Api::UnwrapStringHandle(zone, str).HasHash()); | 8657 EXPECT(Api::UnwrapStringHandle(zone, str).HasHash()); |
8818 EXPECT(Api::UnwrapStringHandle(zone, str).Hash() == | 8658 EXPECT(Api::UnwrapStringHandle(zone, str).Hash() == |
8819 Api::UnwrapStringHandle(zone, symbol_str).Hash()); | 8659 Api::UnwrapStringHandle(zone, symbol_str).Hash()); |
8820 EXPECT(Dart_IsString(str)); | 8660 EXPECT(Dart_IsString(str)); |
8821 EXPECT(Dart_IsString(symbol_str)); | 8661 EXPECT(Dart_IsString(symbol_str)); |
8822 EXPECT(Dart_IsStringLatin1(str)); | 8662 EXPECT(Dart_IsStringLatin1(str)); |
8823 EXPECT(Dart_IsStringLatin1(symbol_str)); | 8663 EXPECT(Dart_IsStringLatin1(symbol_str)); |
8824 EXPECT(Dart_IsExternalString(str)); | 8664 EXPECT(Dart_IsExternalString(str)); |
8825 EXPECT(Dart_IsExternalString(symbol_str)); | 8665 EXPECT(Dart_IsExternalString(symbol_str)); |
(...skipping 27 matching lines...) Expand all Loading... |
8853 TEST_CASE(ExternalizeConstantStrings) { | 8693 TEST_CASE(ExternalizeConstantStrings) { |
8854 const bool saved_flag = FLAG_support_externalizable_strings; | 8694 const bool saved_flag = FLAG_support_externalizable_strings; |
8855 FLAG_support_externalizable_strings = true; | 8695 FLAG_support_externalizable_strings = true; |
8856 | 8696 |
8857 const char* kScriptChars = | 8697 const char* kScriptChars = |
8858 "String testMain() {\n" | 8698 "String testMain() {\n" |
8859 " return 'constant string';\n" | 8699 " return 'constant string';\n" |
8860 "}\n"; | 8700 "}\n"; |
8861 | 8701 |
8862 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 8702 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
8863 Dart_Handle result = Dart_Invoke(lib, | 8703 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
8864 NewString("testMain"), | |
8865 0, | |
8866 NULL); | |
8867 const char* expected_str = "constant string"; | 8704 const char* expected_str = "constant string"; |
8868 const intptr_t kExpectedLen = 15; | 8705 const intptr_t kExpectedLen = 15; |
8869 uint8_t ext_str[kExpectedLen]; | 8706 uint8_t ext_str[kExpectedLen]; |
8870 Dart_Handle str = Dart_MakeExternalString(result, | 8707 Dart_Handle str = |
8871 ext_str, | 8708 Dart_MakeExternalString(result, ext_str, kExpectedLen, NULL, NULL); |
8872 kExpectedLen, | |
8873 NULL, | |
8874 NULL); | |
8875 | 8709 |
8876 EXPECT(Dart_IsExternalString(str)); | 8710 EXPECT(Dart_IsExternalString(str)); |
8877 for (intptr_t i = 0; i < kExpectedLen; i++) { | 8711 for (intptr_t i = 0; i < kExpectedLen; i++) { |
8878 EXPECT_EQ(expected_str[i], ext_str[i]); | 8712 EXPECT_EQ(expected_str[i], ext_str[i]); |
8879 } | 8713 } |
8880 | 8714 |
8881 FLAG_support_externalizable_strings = saved_flag; | 8715 FLAG_support_externalizable_strings = saved_flag; |
8882 } | 8716 } |
8883 | 8717 |
8884 | 8718 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8938 void* peer; | 8772 void* peer; |
8939 Dart_Handle str_arg = Dart_GetNativeStringArgument(args, 0, &peer); | 8773 Dart_Handle str_arg = Dart_GetNativeStringArgument(args, 0, &peer); |
8940 EXPECT(Dart_IsString(str_arg)); | 8774 EXPECT(Dart_IsString(str_arg)); |
8941 EXPECT(!peer); | 8775 EXPECT(!peer); |
8942 intptr_t size = 0; | 8776 intptr_t size = 0; |
8943 EXPECT_VALID(Dart_StringStorageSize(str, &size)); | 8777 EXPECT_VALID(Dart_StringStorageSize(str, &size)); |
8944 intptr_t arg_size = 0; | 8778 intptr_t arg_size = 0; |
8945 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size)); | 8779 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size)); |
8946 EXPECT_EQ(size, arg_size); | 8780 EXPECT_EQ(size, arg_size); |
8947 char* str_data = new char[size]; | 8781 char* str_data = new char[size]; |
8948 Dart_Handle result = | 8782 Dart_Handle result = Dart_MakeExternalString( |
8949 Dart_MakeExternalString(str, | 8783 str, str_data, size, str_data, &ExternalStringDeoptimize_Finalize); |
8950 str_data, | |
8951 size, | |
8952 str_data, | |
8953 &ExternalStringDeoptimize_Finalize); | |
8954 EXPECT_VALID(result); | 8784 EXPECT_VALID(result); |
8955 EXPECT(Dart_IsExternalString(result)); | 8785 EXPECT(Dart_IsExternalString(result)); |
8956 Dart_ExitScope(); | 8786 Dart_ExitScope(); |
8957 } | 8787 } |
8958 | 8788 |
8959 | 8789 |
8960 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( | 8790 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( |
8961 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 8791 Dart_Handle name, |
| 8792 int argument_count, |
| 8793 bool* auto_setup_scope) { |
8962 ASSERT(auto_setup_scope != NULL); | 8794 ASSERT(auto_setup_scope != NULL); |
8963 *auto_setup_scope = true; | 8795 *auto_setup_scope = true; |
8964 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); | 8796 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); |
8965 } | 8797 } |
8966 | 8798 |
8967 | 8799 |
8968 // Do not use guarding mechanism on externalizable classes, since their class | 8800 // Do not use guarding mechanism on externalizable classes, since their class |
8969 // can change on the fly, | 8801 // can change on the fly, |
8970 TEST_CASE(GuardExternalizedString) { | 8802 TEST_CASE(GuardExternalizedString) { |
8971 const bool saved_flag = FLAG_support_externalizable_strings; | 8803 const bool saved_flag = FLAG_support_externalizable_strings; |
(...skipping 16 matching lines...) Expand all Loading... |
8988 " }\n" | 8820 " }\n" |
8989 " }\n" | 8821 " }\n" |
8990 " return sum;\n" | 8822 " return sum;\n" |
8991 "}\n" | 8823 "}\n" |
8992 "class A {\n" | 8824 "class A {\n" |
8993 " var f;\n" | 8825 " var f;\n" |
8994 " A(this.f);\n" | 8826 " A(this.f);\n" |
8995 "}\n" | 8827 "}\n" |
8996 "change_str(String s) native 'A_change_str';\n" | 8828 "change_str(String s) native 'A_change_str';\n" |
8997 ""; | 8829 ""; |
8998 Dart_Handle lib = | 8830 Dart_Handle lib = TestCase::LoadTestScript( |
8999 TestCase::LoadTestScript(kScriptChars, | 8831 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9000 &ExternalStringDeoptimize_native_lookup); | 8832 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9001 Dart_Handle result = Dart_Invoke(lib, | |
9002 NewString("main"), | |
9003 0, | |
9004 NULL); | |
9005 int64_t value = 0; | 8833 int64_t value = 0; |
9006 result = Dart_IntegerToInt64(result, &value); | 8834 result = Dart_IntegerToInt64(result, &value); |
9007 EXPECT_VALID(result); | 8835 EXPECT_VALID(result); |
9008 EXPECT_EQ(10640000, value); | 8836 EXPECT_EQ(10640000, value); |
9009 | 8837 |
9010 FLAG_support_externalizable_strings = saved_flag; | 8838 FLAG_support_externalizable_strings = saved_flag; |
9011 } | 8839 } |
9012 | 8840 |
9013 | 8841 |
9014 TEST_CASE(ExternalStringDeoptimize) { | 8842 TEST_CASE(ExternalStringDeoptimize) { |
(...skipping 13 matching lines...) Expand all Loading... |
9028 " }\n" | 8856 " }\n" |
9029 " return result;\n" | 8857 " return result;\n" |
9030 "}\n" | 8858 "}\n" |
9031 "main() {\n" | 8859 "main() {\n" |
9032 " str = '$str$str';\n" | 8860 " str = '$str$str';\n" |
9033 " for (var i = 0; i < 2000; i++) sum_chars(str, false);\n" | 8861 " for (var i = 0; i < 2000; i++) sum_chars(str, false);\n" |
9034 " var x = sum_chars(str, false);\n" | 8862 " var x = sum_chars(str, false);\n" |
9035 " var y = sum_chars(str, true);\n" | 8863 " var y = sum_chars(str, true);\n" |
9036 " return x + y;\n" | 8864 " return x + y;\n" |
9037 "}\n"; | 8865 "}\n"; |
9038 Dart_Handle lib = | 8866 Dart_Handle lib = TestCase::LoadTestScript( |
9039 TestCase::LoadTestScript(kScriptChars, | 8867 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9040 &ExternalStringDeoptimize_native_lookup); | 8868 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9041 Dart_Handle result = Dart_Invoke(lib, | |
9042 NewString("main"), | |
9043 0, | |
9044 NULL); | |
9045 int64_t value = 0; | 8869 int64_t value = 0; |
9046 result = Dart_IntegerToInt64(result, &value); | 8870 result = Dart_IntegerToInt64(result, &value); |
9047 EXPECT_VALID(result); | 8871 EXPECT_VALID(result); |
9048 EXPECT_EQ(260, value); | 8872 EXPECT_EQ(260, value); |
9049 | 8873 |
9050 FLAG_support_externalizable_strings = saved_flag; | 8874 FLAG_support_externalizable_strings = saved_flag; |
9051 } | 8875 } |
9052 | 8876 |
9053 | 8877 |
9054 TEST_CASE(ExternalStringPolymorphicDeoptimize) { | 8878 TEST_CASE(ExternalStringPolymorphicDeoptimize) { |
(...skipping 13 matching lines...) Expand all Loading... |
9068 "}\n" | 8892 "}\n" |
9069 "main() {\n" | 8893 "main() {\n" |
9070 " var externalA = 'AA' + 'AA';\n" | 8894 " var externalA = 'AA' + 'AA';\n" |
9071 " A.change_str(externalA);\n" | 8895 " A.change_str(externalA);\n" |
9072 " compare('AA' + 'AA', strA);\n" | 8896 " compare('AA' + 'AA', strA);\n" |
9073 " compare(externalA, strA);\n" | 8897 " compare(externalA, strA);\n" |
9074 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | 8898 " for (var i = 0; i < 10000; i++) compareA(strA);\n" |
9075 " A.change_str(strA);\n" | 8899 " A.change_str(strA);\n" |
9076 " return compareA('AA' + 'AA');\n" | 8900 " return compareA('AA' + 'AA');\n" |
9077 "}\n"; | 8901 "}\n"; |
9078 Dart_Handle lib = | 8902 Dart_Handle lib = TestCase::LoadTestScript( |
9079 TestCase::LoadTestScript(kScriptChars, | 8903 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9080 &ExternalStringDeoptimize_native_lookup); | 8904 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9081 Dart_Handle result = Dart_Invoke(lib, | |
9082 NewString("main"), | |
9083 0, | |
9084 NULL); | |
9085 EXPECT_VALID(result); | 8905 EXPECT_VALID(result); |
9086 bool value = false; | 8906 bool value = false; |
9087 result = Dart_BooleanValue(result, &value); | 8907 result = Dart_BooleanValue(result, &value); |
9088 EXPECT_VALID(result); | 8908 EXPECT_VALID(result); |
9089 EXPECT(value); | 8909 EXPECT(value); |
9090 | 8910 |
9091 FLAG_support_externalizable_strings = saved_flag; | 8911 FLAG_support_externalizable_strings = saved_flag; |
9092 } | 8912 } |
9093 | 8913 |
9094 | 8914 |
9095 TEST_CASE(ExternalStringLoadElimination) { | 8915 TEST_CASE(ExternalStringLoadElimination) { |
9096 const bool saved_flag = FLAG_support_externalizable_strings; | 8916 const bool saved_flag = FLAG_support_externalizable_strings; |
9097 FLAG_support_externalizable_strings = true; | 8917 FLAG_support_externalizable_strings = true; |
9098 | 8918 |
9099 const char* kScriptChars = | 8919 const char* kScriptChars = |
9100 "class A {\n" | 8920 "class A {\n" |
9101 " static change_str(String s) native 'A_change_str';\n" | 8921 " static change_str(String s) native 'A_change_str';\n" |
9102 "}\n" | 8922 "}\n" |
9103 "double_char0(str) {\n" | 8923 "double_char0(str) {\n" |
9104 " return str.codeUnitAt(0) + str.codeUnitAt(0);\n" | 8924 " return str.codeUnitAt(0) + str.codeUnitAt(0);\n" |
9105 "}\n" | 8925 "}\n" |
9106 "main() {\n" | 8926 "main() {\n" |
9107 " var externalA = 'AA' + 'AA';\n" | 8927 " var externalA = 'AA' + 'AA';\n" |
9108 " A.change_str(externalA);\n" | 8928 " A.change_str(externalA);\n" |
9109 " for (var i = 0; i < 10000; i++) double_char0(externalA);\n" | 8929 " for (var i = 0; i < 10000; i++) double_char0(externalA);\n" |
9110 " var result = double_char0(externalA);\n" | 8930 " var result = double_char0(externalA);\n" |
9111 " return result == 130;\n" | 8931 " return result == 130;\n" |
9112 "}\n"; | 8932 "}\n"; |
9113 Dart_Handle lib = | 8933 Dart_Handle lib = TestCase::LoadTestScript( |
9114 TestCase::LoadTestScript(kScriptChars, | 8934 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9115 &ExternalStringDeoptimize_native_lookup); | 8935 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9116 Dart_Handle result = Dart_Invoke(lib, | |
9117 NewString("main"), | |
9118 0, | |
9119 NULL); | |
9120 EXPECT_VALID(result); | 8936 EXPECT_VALID(result); |
9121 bool value = false; | 8937 bool value = false; |
9122 result = Dart_BooleanValue(result, &value); | 8938 result = Dart_BooleanValue(result, &value); |
9123 EXPECT_VALID(result); | 8939 EXPECT_VALID(result); |
9124 EXPECT(value); | 8940 EXPECT(value); |
9125 | 8941 |
9126 FLAG_support_externalizable_strings = saved_flag; | 8942 FLAG_support_externalizable_strings = saved_flag; |
9127 } | 8943 } |
9128 | 8944 |
9129 | 8945 |
(...skipping 19 matching lines...) Expand all Loading... |
9149 " return compare(strA, b, i);\n" | 8965 " return compare(strA, b, i);\n" |
9150 "}\n" | 8966 "}\n" |
9151 "main() {\n" | 8967 "main() {\n" |
9152 " var externalA = 'AA' + 'AA';\n" | 8968 " var externalA = 'AA' + 'AA';\n" |
9153 " A.change_str(externalA);\n" | 8969 " A.change_str(externalA);\n" |
9154 " compare('AA' + 'AA', strA);\n" | 8970 " compare('AA' + 'AA', strA);\n" |
9155 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | 8971 " for (var i = 0; i < 10000; i++) compareA(strA);\n" |
9156 " shouldExternalize = true;\n" | 8972 " shouldExternalize = true;\n" |
9157 " return compareA('AA' + 'AA');\n" | 8973 " return compareA('AA' + 'AA');\n" |
9158 "}\n"; | 8974 "}\n"; |
9159 Dart_Handle lib = | 8975 Dart_Handle lib = TestCase::LoadTestScript( |
9160 TestCase::LoadTestScript(kScriptChars, | 8976 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9161 &ExternalStringDeoptimize_native_lookup); | 8977 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9162 Dart_Handle result = Dart_Invoke(lib, | |
9163 NewString("main"), | |
9164 0, | |
9165 NULL); | |
9166 EXPECT_VALID(result); | 8978 EXPECT_VALID(result); |
9167 bool value = false; | 8979 bool value = false; |
9168 result = Dart_BooleanValue(result, &value); | 8980 result = Dart_BooleanValue(result, &value); |
9169 EXPECT_VALID(result); | 8981 EXPECT_VALID(result); |
9170 EXPECT(value); | 8982 EXPECT(value); |
9171 | 8983 |
9172 FLAG_support_externalizable_strings = saved_flag; | 8984 FLAG_support_externalizable_strings = saved_flag; |
9173 } | 8985 } |
9174 | 8986 |
9175 | 8987 |
(...skipping 14 matching lines...) Expand all Loading... |
9190 " return compare(G.f, b, i);\n" | 9002 " return compare(G.f, b, i);\n" |
9191 "}\n" | 9003 "}\n" |
9192 "main() {\n" | 9004 "main() {\n" |
9193 " var externalA = 'AA' + 'AA';\n" | 9005 " var externalA = 'AA' + 'AA';\n" |
9194 " A.change_str(externalA);\n" | 9006 " A.change_str(externalA);\n" |
9195 " compare('AA' + 'AA', strA);\n" | 9007 " compare('AA' + 'AA', strA);\n" |
9196 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | 9008 " for (var i = 0; i < 10000; i++) compareA(strA);\n" |
9197 " A.change_str(G.f);" | 9009 " A.change_str(G.f);" |
9198 " return compareA('AA' + 'AA');\n" | 9010 " return compareA('AA' + 'AA');\n" |
9199 "}\n"; | 9011 "}\n"; |
9200 Dart_Handle lib = | 9012 Dart_Handle lib = TestCase::LoadTestScript( |
9201 TestCase::LoadTestScript(kScriptChars, | 9013 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9202 &ExternalStringDeoptimize_native_lookup); | 9014 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9203 Dart_Handle result = Dart_Invoke(lib, | |
9204 NewString("main"), | |
9205 0, | |
9206 NULL); | |
9207 EXPECT_VALID(result); | 9015 EXPECT_VALID(result); |
9208 bool value = false; | 9016 bool value = false; |
9209 result = Dart_BooleanValue(result, &value); | 9017 result = Dart_BooleanValue(result, &value); |
9210 EXPECT_VALID(result); | 9018 EXPECT_VALID(result); |
9211 EXPECT(value); | 9019 EXPECT(value); |
9212 | 9020 |
9213 FLAG_support_externalizable_strings = saved_flag; | 9021 FLAG_support_externalizable_strings = saved_flag; |
9214 } | 9022 } |
9215 | 9023 |
9216 | 9024 |
9217 TEST_CASE(ExternalStringTrimDoubleParse) { | 9025 TEST_CASE(ExternalStringTrimDoubleParse) { |
9218 const bool saved_flag = FLAG_support_externalizable_strings; | 9026 const bool saved_flag = FLAG_support_externalizable_strings; |
9219 FLAG_support_externalizable_strings = true; | 9027 FLAG_support_externalizable_strings = true; |
9220 | 9028 |
9221 const char* kScriptChars = | 9029 const char* kScriptChars = |
9222 "String str = 'A';\n" | 9030 "String str = 'A';\n" |
9223 "class A {\n" | 9031 "class A {\n" |
9224 " static change_str(String s) native 'A_change_str';\n" | 9032 " static change_str(String s) native 'A_change_str';\n" |
9225 "}\n" | 9033 "}\n" |
9226 "main() {\n" | 9034 "main() {\n" |
9227 " var externalOneByteString = ' 0.2\\xA0 ';\n;" | 9035 " var externalOneByteString = ' 0.2\\xA0 ';\n;" |
9228 " A.change_str(externalOneByteString);\n" | 9036 " A.change_str(externalOneByteString);\n" |
9229 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" | 9037 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" |
9230 " A.change_str(externalTwoByteString);\n" | 9038 " A.change_str(externalTwoByteString);\n" |
9231 " var x = double.parse(externalOneByteString);\n" | 9039 " var x = double.parse(externalOneByteString);\n" |
9232 " var y = double.parse(externalTwoByteString);\n" | 9040 " var y = double.parse(externalTwoByteString);\n" |
9233 " return ((x + y) * 10).toInt();\n" | 9041 " return ((x + y) * 10).toInt();\n" |
9234 "}\n"; | 9042 "}\n"; |
9235 Dart_Handle lib = | 9043 Dart_Handle lib = TestCase::LoadTestScript( |
9236 TestCase::LoadTestScript(kScriptChars, | 9044 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9237 &ExternalStringDeoptimize_native_lookup); | 9045 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9238 Dart_Handle result = Dart_Invoke(lib, | |
9239 NewString("main"), | |
9240 0, | |
9241 NULL); | |
9242 int64_t value = 0; | 9046 int64_t value = 0; |
9243 result = Dart_IntegerToInt64(result, &value); | 9047 result = Dart_IntegerToInt64(result, &value); |
9244 EXPECT_VALID(result); | 9048 EXPECT_VALID(result); |
9245 EXPECT_EQ(8, value); | 9049 EXPECT_EQ(8, value); |
9246 | 9050 |
9247 FLAG_support_externalizable_strings = saved_flag; | 9051 FLAG_support_externalizable_strings = saved_flag; |
9248 } | 9052 } |
9249 | 9053 |
9250 | 9054 |
9251 TEST_CASE(ExternalStringDoubleParse) { | 9055 TEST_CASE(ExternalStringDoubleParse) { |
9252 const bool saved_flag = FLAG_support_externalizable_strings; | 9056 const bool saved_flag = FLAG_support_externalizable_strings; |
9253 FLAG_support_externalizable_strings = true; | 9057 FLAG_support_externalizable_strings = true; |
9254 | 9058 |
9255 const char* kScriptChars = | 9059 const char* kScriptChars = |
9256 "String str = 'A';\n" | 9060 "String str = 'A';\n" |
9257 "class A {\n" | 9061 "class A {\n" |
9258 " static change_str(String s) native 'A_change_str';\n" | 9062 " static change_str(String s) native 'A_change_str';\n" |
9259 "}\n" | 9063 "}\n" |
9260 "main() {\n" | 9064 "main() {\n" |
9261 " var externalOneByteString = '0.2';\n;" | 9065 " var externalOneByteString = '0.2';\n;" |
9262 " A.change_str(externalOneByteString);\n" | 9066 " A.change_str(externalOneByteString);\n" |
9263 " var externalTwoByteString = '0.6';\n" | 9067 " var externalTwoByteString = '0.6';\n" |
9264 " A.change_str(externalTwoByteString);\n" | 9068 " A.change_str(externalTwoByteString);\n" |
9265 " var x = double.parse(externalOneByteString);\n" | 9069 " var x = double.parse(externalOneByteString);\n" |
9266 " var y = double.parse(externalTwoByteString);\n" | 9070 " var y = double.parse(externalTwoByteString);\n" |
9267 " return ((x + y) * 10).toInt();\n" | 9071 " return ((x + y) * 10).toInt();\n" |
9268 "}\n"; | 9072 "}\n"; |
9269 Dart_Handle lib = | 9073 Dart_Handle lib = TestCase::LoadTestScript( |
9270 TestCase::LoadTestScript(kScriptChars, | 9074 kScriptChars, &ExternalStringDeoptimize_native_lookup); |
9271 &ExternalStringDeoptimize_native_lookup); | 9075 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9272 Dart_Handle result = Dart_Invoke(lib, | |
9273 NewString("main"), | |
9274 0, | |
9275 NULL); | |
9276 int64_t value = 0; | 9076 int64_t value = 0; |
9277 result = Dart_IntegerToInt64(result, &value); | 9077 result = Dart_IntegerToInt64(result, &value); |
9278 EXPECT_VALID(result); | 9078 EXPECT_VALID(result); |
9279 EXPECT_EQ(8, value); | 9079 EXPECT_EQ(8, value); |
9280 | 9080 |
9281 FLAG_support_externalizable_strings = saved_flag; | 9081 FLAG_support_externalizable_strings = saved_flag; |
9282 } | 9082 } |
9283 | 9083 |
9284 | 9084 |
9285 TEST_CASE(ExternalStringIndexOf) { | 9085 TEST_CASE(ExternalStringIndexOf) { |
9286 const char* kScriptChars = | 9086 const char* kScriptChars = |
9287 "main(String pattern) {\n" | 9087 "main(String pattern) {\n" |
9288 " var str = 'Hello World';\n" | 9088 " var str = 'Hello World';\n" |
9289 " return str.indexOf(pattern);\n" | 9089 " return str.indexOf(pattern);\n" |
9290 "}\n"; | 9090 "}\n"; |
9291 Dart_Handle lib = | 9091 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9292 TestCase::LoadTestScript(kScriptChars, NULL); | |
9293 | 9092 |
9294 uint8_t data8[] = { 'W' }; | 9093 uint8_t data8[] = {'W'}; |
9295 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), | 9094 Dart_Handle ext8 = |
9296 data8, NULL); | 9095 Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), data8, NULL); |
9297 EXPECT_VALID(ext8); | 9096 EXPECT_VALID(ext8); |
9298 EXPECT(Dart_IsString(ext8)); | 9097 EXPECT(Dart_IsString(ext8)); |
9299 EXPECT(Dart_IsExternalString(ext8)); | 9098 EXPECT(Dart_IsExternalString(ext8)); |
9300 | 9099 |
9301 Dart_Handle dart_args[1]; | 9100 Dart_Handle dart_args[1]; |
9302 dart_args[0] = ext8; | 9101 dart_args[0] = ext8; |
9303 Dart_Handle result = Dart_Invoke(lib, | 9102 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 1, dart_args); |
9304 NewString("main"), | |
9305 1, | |
9306 dart_args); | |
9307 int64_t value = 0; | 9103 int64_t value = 0; |
9308 result = Dart_IntegerToInt64(result, &value); | 9104 result = Dart_IntegerToInt64(result, &value); |
9309 EXPECT_VALID(result); | 9105 EXPECT_VALID(result); |
9310 EXPECT_EQ(6, value); | 9106 EXPECT_EQ(6, value); |
9311 } | 9107 } |
9312 | 9108 |
9313 | 9109 |
9314 TEST_CASE(StringFromExternalTypedData) { | 9110 TEST_CASE(StringFromExternalTypedData) { |
9315 const char* kScriptChars = | 9111 const char* kScriptChars = |
9316 "test(external) {\n" | 9112 "test(external) {\n" |
9317 " var str1 = new String.fromCharCodes(external);\n" | 9113 " var str1 = new String.fromCharCodes(external);\n" |
9318 " var str2 = new String.fromCharCodes(new List.from(external));\n" | 9114 " var str2 = new String.fromCharCodes(new List.from(external));\n" |
9319 " if (str2 != str1) throw 'FAIL';\n" | 9115 " if (str2 != str1) throw 'FAIL';\n" |
9320 " return str1;\n" | 9116 " return str1;\n" |
9321 "}\n" | 9117 "}\n" |
9322 "testView8(external) {\n" | 9118 "testView8(external) {\n" |
9323 " return test(external.buffer.asUint8List());\n" | 9119 " return test(external.buffer.asUint8List());\n" |
9324 "}\n" | 9120 "}\n" |
9325 "testView16(external) {\n" | 9121 "testView16(external) {\n" |
9326 " return test(external.buffer.asUint16List());\n" | 9122 " return test(external.buffer.asUint16List());\n" |
9327 "}\n"; | 9123 "}\n"; |
9328 Dart_Handle lib = | 9124 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9329 TestCase::LoadTestScript(kScriptChars, NULL); | |
9330 | 9125 |
9331 { | 9126 { |
9332 uint8_t data[64]; | 9127 uint8_t data[64]; |
9333 for (int i = 0; i < 64; i++) { | 9128 for (int i = 0; i < 64; i++) { |
9334 data[i] = i * 4; | 9129 data[i] = i * 4; |
9335 } | 9130 } |
9336 // LATIN-1 in external Uint8List. | 9131 // LATIN-1 in external Uint8List. |
9337 Dart_Handle external = Dart_NewExternalTypedData( | 9132 Dart_Handle external = |
9338 Dart_TypedData_kUint8, data, 64); | 9133 Dart_NewExternalTypedData(Dart_TypedData_kUint8, data, 64); |
9339 EXPECT_VALID(external); | 9134 EXPECT_VALID(external); |
9340 Dart_Handle dart_args[1]; | 9135 Dart_Handle dart_args[1]; |
9341 dart_args[0] = external; | 9136 dart_args[0] = external; |
9342 Dart_Handle result = Dart_Invoke(lib, | 9137 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 1, dart_args); |
9343 NewString("test"), | |
9344 1, | |
9345 dart_args); | |
9346 EXPECT_VALID(result); | 9138 EXPECT_VALID(result); |
9347 EXPECT(Dart_IsString(result)); | 9139 EXPECT(Dart_IsString(result)); |
9348 | 9140 |
9349 result = Dart_Invoke(lib, | 9141 result = Dart_Invoke(lib, NewString("testView8"), 1, dart_args); |
9350 NewString("testView8"), | |
9351 1, | |
9352 dart_args); | |
9353 EXPECT_VALID(result); | 9142 EXPECT_VALID(result); |
9354 EXPECT(Dart_IsString(result)); | 9143 EXPECT(Dart_IsString(result)); |
9355 } | 9144 } |
9356 | 9145 |
9357 { | 9146 { |
9358 uint16_t data[64]; | 9147 uint16_t data[64]; |
9359 for (int i = 0; i < 64; i++) { | 9148 for (int i = 0; i < 64; i++) { |
9360 data[i] = i * 4; | 9149 data[i] = i * 4; |
9361 } | 9150 } |
9362 // LATIN-1 in external Uint16List. | 9151 // LATIN-1 in external Uint16List. |
9363 Dart_Handle external = Dart_NewExternalTypedData( | 9152 Dart_Handle external = |
9364 Dart_TypedData_kUint16, data, 64); | 9153 Dart_NewExternalTypedData(Dart_TypedData_kUint16, data, 64); |
9365 EXPECT_VALID(external); | 9154 EXPECT_VALID(external); |
9366 Dart_Handle dart_args[1]; | 9155 Dart_Handle dart_args[1]; |
9367 dart_args[0] = external; | 9156 dart_args[0] = external; |
9368 Dart_Handle result = Dart_Invoke(lib, | 9157 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 1, dart_args); |
9369 NewString("test"), | |
9370 1, | |
9371 dart_args); | |
9372 EXPECT_VALID(result); | 9158 EXPECT_VALID(result); |
9373 EXPECT(Dart_IsString(result)); | 9159 EXPECT(Dart_IsString(result)); |
9374 | 9160 |
9375 result = Dart_Invoke(lib, | 9161 result = Dart_Invoke(lib, NewString("testView16"), 1, dart_args); |
9376 NewString("testView16"), | |
9377 1, | |
9378 dart_args); | |
9379 EXPECT_VALID(result); | 9162 EXPECT_VALID(result); |
9380 EXPECT(Dart_IsString(result)); | 9163 EXPECT(Dart_IsString(result)); |
9381 } | 9164 } |
9382 | 9165 |
9383 { | 9166 { |
9384 uint16_t data[64]; | 9167 uint16_t data[64]; |
9385 for (int i = 0; i < 64; i++) { | 9168 for (int i = 0; i < 64; i++) { |
9386 data[i] = 0x2000 + i * 4; | 9169 data[i] = 0x2000 + i * 4; |
9387 } | 9170 } |
9388 // Non-LATIN-1 in external Uint16List. | 9171 // Non-LATIN-1 in external Uint16List. |
9389 Dart_Handle external = Dart_NewExternalTypedData( | 9172 Dart_Handle external = |
9390 Dart_TypedData_kUint16, data, 64); | 9173 Dart_NewExternalTypedData(Dart_TypedData_kUint16, data, 64); |
9391 EXPECT_VALID(external); | 9174 EXPECT_VALID(external); |
9392 Dart_Handle dart_args[1]; | 9175 Dart_Handle dart_args[1]; |
9393 dart_args[0] = external; | 9176 dart_args[0] = external; |
9394 Dart_Handle result = Dart_Invoke(lib, | 9177 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 1, dart_args); |
9395 NewString("test"), | |
9396 1, | |
9397 dart_args); | |
9398 EXPECT_VALID(result); | 9178 EXPECT_VALID(result); |
9399 EXPECT(Dart_IsString(result)); | 9179 EXPECT(Dart_IsString(result)); |
9400 | 9180 |
9401 result = Dart_Invoke(lib, | 9181 result = Dart_Invoke(lib, NewString("testView16"), 1, dart_args); |
9402 NewString("testView16"), | |
9403 1, | |
9404 dart_args); | |
9405 EXPECT_VALID(result); | 9182 EXPECT_VALID(result); |
9406 EXPECT(Dart_IsString(result)); | 9183 EXPECT(Dart_IsString(result)); |
9407 } | 9184 } |
9408 } | 9185 } |
9409 | 9186 |
9410 | 9187 |
9411 #ifndef PRODUCT | 9188 #ifndef PRODUCT |
9412 | 9189 |
9413 | 9190 |
9414 TEST_CASE(Timeline_Dart_TimelineDuration) { | 9191 TEST_CASE(Timeline_Dart_TimelineDuration) { |
9415 Isolate* isolate = Isolate::Current(); | 9192 Isolate* isolate = Isolate::Current(); |
9416 // Grab embedder stream. | 9193 // Grab embedder stream. |
9417 TimelineStream* stream = Timeline::GetEmbedderStream(); | 9194 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9418 // Make sure it is enabled. | 9195 // Make sure it is enabled. |
9419 stream->set_enabled(true); | 9196 stream->set_enabled(true); |
9420 // Add a duration event. | 9197 // Add a duration event. |
9421 Dart_TimelineEvent("testDurationEvent", | 9198 Dart_TimelineEvent("testDurationEvent", 0, 1, Dart_Timeline_Event_Duration, 0, |
9422 0, | 9199 NULL, NULL); |
9423 1, | |
9424 Dart_Timeline_Event_Duration, | |
9425 0, NULL, NULL); | |
9426 // Check that it is in the output. | 9200 // Check that it is in the output. |
9427 TimelineEventRecorder* recorder = Timeline::recorder(); | 9201 TimelineEventRecorder* recorder = Timeline::recorder(); |
9428 Timeline::ReclaimCachedBlocksFromThreads(); | 9202 Timeline::ReclaimCachedBlocksFromThreads(); |
9429 JSONStream js; | 9203 JSONStream js; |
9430 IsolateTimelineEventFilter filter(isolate->main_port()); | 9204 IsolateTimelineEventFilter filter(isolate->main_port()); |
9431 recorder->PrintJSON(&js, &filter); | 9205 recorder->PrintJSON(&js, &filter); |
9432 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); | 9206 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); |
9433 } | 9207 } |
9434 | 9208 |
9435 | 9209 |
9436 TEST_CASE(Timeline_Dart_TimelineInstant) { | 9210 TEST_CASE(Timeline_Dart_TimelineInstant) { |
9437 Isolate* isolate = Isolate::Current(); | 9211 Isolate* isolate = Isolate::Current(); |
9438 // Grab embedder stream. | 9212 // Grab embedder stream. |
9439 TimelineStream* stream = Timeline::GetEmbedderStream(); | 9213 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9440 // Make sure it is enabled. | 9214 // Make sure it is enabled. |
9441 stream->set_enabled(true); | 9215 stream->set_enabled(true); |
9442 Dart_TimelineEvent("testInstantEvent", | 9216 Dart_TimelineEvent("testInstantEvent", 0, 1, Dart_Timeline_Event_Instant, 0, |
9443 0, | 9217 NULL, NULL); |
9444 1, | |
9445 Dart_Timeline_Event_Instant, | |
9446 0, NULL, NULL); | |
9447 // Check that it is in the output. | 9218 // Check that it is in the output. |
9448 TimelineEventRecorder* recorder = Timeline::recorder(); | 9219 TimelineEventRecorder* recorder = Timeline::recorder(); |
9449 Timeline::ReclaimCachedBlocksFromThreads(); | 9220 Timeline::ReclaimCachedBlocksFromThreads(); |
9450 JSONStream js; | 9221 JSONStream js; |
9451 IsolateTimelineEventFilter filter(isolate->main_port()); | 9222 IsolateTimelineEventFilter filter(isolate->main_port()); |
9452 recorder->PrintJSON(&js, &filter); | 9223 recorder->PrintJSON(&js, &filter); |
9453 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); | 9224 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); |
9454 } | 9225 } |
9455 | 9226 |
9456 | 9227 |
9457 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { | 9228 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { |
9458 // Grab embedder stream. | 9229 // Grab embedder stream. |
9459 TimelineStream* stream = Timeline::GetEmbedderStream(); | 9230 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9460 // Make sure it is disabled. | 9231 // Make sure it is disabled. |
9461 stream->set_enabled(false); | 9232 stream->set_enabled(false); |
9462 int64_t async_id = 99; | 9233 int64_t async_id = 99; |
9463 Dart_TimelineEvent("testAsyncEvent", | 9234 Dart_TimelineEvent("testAsyncEvent", 0, async_id, |
9464 0, | 9235 Dart_Timeline_Event_Async_Begin, 0, NULL, NULL); |
9465 async_id, | |
9466 Dart_Timeline_Event_Async_Begin, | |
9467 0, NULL, NULL); | |
9468 // Check that testAsync is not in the output. | 9236 // Check that testAsync is not in the output. |
9469 TimelineEventRecorder* recorder = Timeline::recorder(); | 9237 TimelineEventRecorder* recorder = Timeline::recorder(); |
9470 Timeline::ReclaimCachedBlocksFromThreads(); | 9238 Timeline::ReclaimCachedBlocksFromThreads(); |
9471 JSONStream js; | 9239 JSONStream js; |
9472 TimelineEventFilter filter; | 9240 TimelineEventFilter filter; |
9473 recorder->PrintJSON(&js, &filter); | 9241 recorder->PrintJSON(&js, &filter); |
9474 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); | 9242 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); |
9475 } | 9243 } |
9476 | 9244 |
9477 | 9245 |
9478 TEST_CASE(Timeline_Dart_TimelineAsync) { | 9246 TEST_CASE(Timeline_Dart_TimelineAsync) { |
9479 Isolate* isolate = Isolate::Current(); | 9247 Isolate* isolate = Isolate::Current(); |
9480 // Grab embedder stream. | 9248 // Grab embedder stream. |
9481 TimelineStream* stream = Timeline::GetEmbedderStream(); | 9249 TimelineStream* stream = Timeline::GetEmbedderStream(); |
9482 // Make sure it is enabled. | 9250 // Make sure it is enabled. |
9483 stream->set_enabled(true); | 9251 stream->set_enabled(true); |
9484 int64_t async_id = 99; | 9252 int64_t async_id = 99; |
9485 Dart_TimelineEvent("testAsyncEvent", | 9253 Dart_TimelineEvent("testAsyncEvent", 0, async_id, |
9486 0, | 9254 Dart_Timeline_Event_Async_Begin, 0, NULL, NULL); |
9487 async_id, | |
9488 Dart_Timeline_Event_Async_Begin, | |
9489 0, NULL, NULL); | |
9490 | 9255 |
9491 // Check that it is in the output. | 9256 // Check that it is in the output. |
9492 TimelineEventRecorder* recorder = Timeline::recorder(); | 9257 TimelineEventRecorder* recorder = Timeline::recorder(); |
9493 Timeline::ReclaimCachedBlocksFromThreads(); | 9258 Timeline::ReclaimCachedBlocksFromThreads(); |
9494 JSONStream js; | 9259 JSONStream js; |
9495 IsolateTimelineEventFilter filter(isolate->main_port()); | 9260 IsolateTimelineEventFilter filter(isolate->main_port()); |
9496 recorder->PrintJSON(&js, &filter); | 9261 recorder->PrintJSON(&js, &filter); |
9497 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); | 9262 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); |
9498 } | 9263 } |
9499 | 9264 |
(...skipping 18 matching lines...) Expand all Loading... |
9518 data->buffer = NULL; | 9283 data->buffer = NULL; |
9519 data->buffer_length = 0; | 9284 data->buffer_length = 0; |
9520 return; | 9285 return; |
9521 } | 9286 } |
9522 ASSERT(state == Dart_StreamConsumer_kData); | 9287 ASSERT(state == Dart_StreamConsumer_kData); |
9523 | 9288 |
9524 // Grow buffer. | 9289 // Grow buffer. |
9525 data->buffer = reinterpret_cast<uint8_t*>( | 9290 data->buffer = reinterpret_cast<uint8_t*>( |
9526 realloc(data->buffer, data->buffer_length + buffer_length)); | 9291 realloc(data->buffer, data->buffer_length + buffer_length)); |
9527 // Copy new data. | 9292 // Copy new data. |
9528 memmove(&data->buffer[data->buffer_length], | 9293 memmove(&data->buffer[data->buffer_length], buffer, buffer_length); |
9529 buffer, | |
9530 buffer_length); | |
9531 // Update length. | 9294 // Update length. |
9532 data->buffer_length += buffer_length; | 9295 data->buffer_length += buffer_length; |
9533 } | 9296 } |
9534 | 9297 |
9535 | 9298 |
9536 TEST_CASE(Timeline_Dart_TimelineGetTrace) { | 9299 TEST_CASE(Timeline_Dart_TimelineGetTrace) { |
9537 const char* kScriptChars = | 9300 const char* kScriptChars = |
9538 "foo() => 'a';\n" | 9301 "foo() => 'a';\n" |
9539 "main() => foo();\n"; | 9302 "main() => foo();\n"; |
9540 | 9303 |
9541 Dart_Handle lib = | 9304 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9542 TestCase::LoadTestScript(kScriptChars, NULL); | |
9543 | 9305 |
9544 const char* buffer = NULL; | 9306 const char* buffer = NULL; |
9545 intptr_t buffer_length = 0; | 9307 intptr_t buffer_length = 0; |
9546 bool success = false; | 9308 bool success = false; |
9547 | 9309 |
9548 // Enable recording of all streams. | 9310 // Enable recording of all streams. |
9549 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | 9311 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); |
9550 | 9312 |
9551 // Invoke main, which will be compiled resulting in a compiler event in | 9313 // Invoke main, which will be compiled resulting in a compiler event in |
9552 // the timeline. | 9314 // the timeline. |
9553 Dart_Handle result = Dart_Invoke(lib, | 9315 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9554 NewString("main"), | |
9555 0, | |
9556 NULL); | |
9557 EXPECT_VALID(result); | 9316 EXPECT_VALID(result); |
9558 | 9317 |
9559 // Grab the trace. | 9318 // Grab the trace. |
9560 AppendData data; | 9319 AppendData data; |
9561 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9320 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
9562 EXPECT(success); | 9321 EXPECT(success); |
9563 buffer = reinterpret_cast<char*>(data.buffer); | 9322 buffer = reinterpret_cast<char*>(data.buffer); |
9564 buffer_length = data.buffer_length; | 9323 buffer_length = data.buffer_length; |
9565 EXPECT(buffer_length > 0); | 9324 EXPECT(buffer_length > 0); |
9566 EXPECT(buffer != NULL); | 9325 EXPECT(buffer != NULL); |
9567 | 9326 |
9568 // Response starts with a '{' character and not a '['. | 9327 // Response starts with a '{' character and not a '['. |
9569 EXPECT(buffer[0] == '{'); | 9328 EXPECT(buffer[0] == '{'); |
9570 // Response ends with a '}' character and not a ']'. | 9329 // Response ends with a '}' character and not a ']'. |
9571 EXPECT(buffer[buffer_length - 1] == '\0'); | 9330 EXPECT(buffer[buffer_length - 1] == '\0'); |
9572 EXPECT(buffer[buffer_length - 2] == '}'); | 9331 EXPECT(buffer[buffer_length - 2] == '}'); |
9573 | 9332 |
9574 // Heartbeat test. | 9333 // Heartbeat test. |
9575 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9334 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9576 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9335 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9577 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9336 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9578 | 9337 |
9579 // Free buffer allocated by AppendStreamConsumer | 9338 // Free buffer allocated by AppendStreamConsumer |
9580 free(data.buffer); | 9339 free(data.buffer); |
9581 } | 9340 } |
9582 | 9341 |
9583 | 9342 |
9584 TEST_CASE(Timeline_Dart_TimelineGetTraceOnlyDartEvents) { | 9343 TEST_CASE(Timeline_Dart_TimelineGetTraceOnlyDartEvents) { |
9585 const char* kScriptChars = | 9344 const char* kScriptChars = |
9586 "import 'dart:developer';\n" | 9345 "import 'dart:developer';\n" |
9587 "" | 9346 "" |
9588 "main() {\n" | 9347 "main() {\n" |
9589 " Timeline.startSync('DART_NAME');\n" | 9348 " Timeline.startSync('DART_NAME');\n" |
9590 " Timeline.finishSync();\n" | 9349 " Timeline.finishSync();\n" |
9591 "}\n"; | 9350 "}\n"; |
9592 | 9351 |
9593 Dart_Handle lib = | 9352 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9594 TestCase::LoadTestScript(kScriptChars, NULL); | |
9595 | 9353 |
9596 const char* buffer = NULL; | 9354 const char* buffer = NULL; |
9597 intptr_t buffer_length = 0; | 9355 intptr_t buffer_length = 0; |
9598 bool success = false; | 9356 bool success = false; |
9599 | 9357 |
9600 // Enable recording of the Dart stream. | 9358 // Enable recording of the Dart stream. |
9601 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART); | 9359 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART); |
9602 | 9360 |
9603 // Invoke main, which will add a new timeline event from Dart. | 9361 // Invoke main, which will add a new timeline event from Dart. |
9604 Dart_Handle result = Dart_Invoke(lib, | 9362 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9605 NewString("main"), | |
9606 0, | |
9607 NULL); | |
9608 EXPECT_VALID(result); | 9363 EXPECT_VALID(result); |
9609 | 9364 |
9610 // Grab the trace. | 9365 // Grab the trace. |
9611 AppendData data; | 9366 AppendData data; |
9612 data.buffer = NULL; | 9367 data.buffer = NULL; |
9613 data.buffer_length = 0; | 9368 data.buffer_length = 0; |
9614 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9369 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
9615 EXPECT(success); | 9370 EXPECT(success); |
9616 buffer = reinterpret_cast<char*>(data.buffer); | 9371 buffer = reinterpret_cast<char*>(data.buffer); |
9617 buffer_length = data.buffer_length; | 9372 buffer_length = data.buffer_length; |
(...skipping 10 matching lines...) Expand all Loading... |
9628 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer); | 9383 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer); |
9629 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); | 9384 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); |
9630 | 9385 |
9631 // Free buffer allocated by AppendStreamConsumer | 9386 // Free buffer allocated by AppendStreamConsumer |
9632 free(data.buffer); | 9387 free(data.buffer); |
9633 } | 9388 } |
9634 | 9389 |
9635 | 9390 |
9636 TEST_CASE(Timeline_Dart_TimelineGetTraceWithDartEvents) { | 9391 TEST_CASE(Timeline_Dart_TimelineGetTraceWithDartEvents) { |
9637 const char* kScriptChars = | 9392 const char* kScriptChars = |
9638 "import 'dart:developer';\n" | 9393 "import 'dart:developer';\n" |
9639 "\n" | 9394 "\n" |
9640 "main() {\n" | 9395 "main() {\n" |
9641 " Timeline.startSync('DART_NAME');\n" | 9396 " Timeline.startSync('DART_NAME');\n" |
9642 " Timeline.finishSync();\n" | 9397 " Timeline.finishSync();\n" |
9643 "}\n"; | 9398 "}\n"; |
9644 | 9399 |
9645 Dart_Handle lib = | 9400 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9646 TestCase::LoadTestScript(kScriptChars, NULL); | |
9647 | 9401 |
9648 const char* buffer = NULL; | 9402 const char* buffer = NULL; |
9649 intptr_t buffer_length = 0; | 9403 intptr_t buffer_length = 0; |
9650 bool success = false; | 9404 bool success = false; |
9651 | 9405 |
9652 // Enable recording of all streams. | 9406 // Enable recording of all streams. |
9653 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | 9407 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); |
9654 | 9408 |
9655 // Invoke main, which will be compiled resulting in a compiler event in | 9409 // Invoke main, which will be compiled resulting in a compiler event in |
9656 // the timeline. | 9410 // the timeline. |
9657 Dart_Handle result = Dart_Invoke(lib, | 9411 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9658 NewString("main"), | |
9659 0, | |
9660 NULL); | |
9661 EXPECT_VALID(result); | 9412 EXPECT_VALID(result); |
9662 | 9413 |
9663 // Grab the trace. | 9414 // Grab the trace. |
9664 AppendData data; | 9415 AppendData data; |
9665 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9416 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
9666 EXPECT(success); | 9417 EXPECT(success); |
9667 buffer = reinterpret_cast<char*>(data.buffer); | 9418 buffer = reinterpret_cast<char*>(data.buffer); |
9668 buffer_length = data.buffer_length; | 9419 buffer_length = data.buffer_length; |
9669 EXPECT(buffer_length > 0); | 9420 EXPECT(buffer_length > 0); |
9670 EXPECT(buffer != NULL); | 9421 EXPECT(buffer != NULL); |
(...skipping 10 matching lines...) Expand all Loading... |
9681 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9432 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9682 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer); | 9433 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer); |
9683 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); | 9434 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); |
9684 | 9435 |
9685 // Free buffer allocated by AppendStreamConsumer | 9436 // Free buffer allocated by AppendStreamConsumer |
9686 free(data.buffer); | 9437 free(data.buffer); |
9687 } | 9438 } |
9688 | 9439 |
9689 TEST_CASE(Timeline_Dart_TimelineGetTraceGlobalOverride) { | 9440 TEST_CASE(Timeline_Dart_TimelineGetTraceGlobalOverride) { |
9690 const char* kScriptChars = | 9441 const char* kScriptChars = |
9691 "foo() => 'a';\n" | 9442 "foo() => 'a';\n" |
9692 "main() => foo();\n"; | 9443 "main() => foo();\n"; |
9693 | 9444 |
9694 Dart_Handle lib = | 9445 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9695 TestCase::LoadTestScript(kScriptChars, NULL); | |
9696 | 9446 |
9697 const char* buffer = NULL; | 9447 const char* buffer = NULL; |
9698 intptr_t buffer_length = 0; | 9448 intptr_t buffer_length = 0; |
9699 bool success = false; | 9449 bool success = false; |
9700 | 9450 |
9701 // Enable recording of all streams across the entire vm. | 9451 // Enable recording of all streams across the entire vm. |
9702 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | 9452 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); |
9703 | 9453 |
9704 // Invoke main, which will be compiled resulting in a compiler event in | 9454 // Invoke main, which will be compiled resulting in a compiler event in |
9705 // the timeline. | 9455 // the timeline. |
9706 Dart_Handle result = Dart_Invoke(lib, | 9456 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9707 NewString("main"), | |
9708 0, | |
9709 NULL); | |
9710 EXPECT_VALID(result); | 9457 EXPECT_VALID(result); |
9711 | 9458 |
9712 // Grab the trace. | 9459 // Grab the trace. |
9713 AppendData data; | 9460 AppendData data; |
9714 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9461 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
9715 EXPECT(success); | 9462 EXPECT(success); |
9716 buffer = reinterpret_cast<char*>(data.buffer); | 9463 buffer = reinterpret_cast<char*>(data.buffer); |
9717 buffer_length = data.buffer_length; | 9464 buffer_length = data.buffer_length; |
9718 EXPECT(buffer_length > 0); | 9465 EXPECT(buffer_length > 0); |
9719 EXPECT(buffer != NULL); | 9466 EXPECT(buffer != NULL); |
9720 | 9467 |
9721 // Response starts with a '{' character and not a '['. | 9468 // Response starts with a '{' character and not a '['. |
9722 EXPECT(buffer[0] == '{'); | 9469 EXPECT(buffer[0] == '{'); |
9723 // Response ends with a '}' character and not a ']'. | 9470 // Response ends with a '}' character and not a ']'. |
9724 EXPECT(buffer[buffer_length - 1] == '\0'); | 9471 EXPECT(buffer[buffer_length - 1] == '\0'); |
9725 EXPECT(buffer[buffer_length - 2] == '}'); | 9472 EXPECT(buffer[buffer_length - 2] == '}'); |
9726 | 9473 |
9727 // Heartbeat test. | 9474 // Heartbeat test. |
9728 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9475 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9729 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9476 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9730 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9477 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9731 | 9478 |
9732 // Free buffer allocated by AppendStreamConsumer | 9479 // Free buffer allocated by AppendStreamConsumer |
9733 free(data.buffer); | 9480 free(data.buffer); |
9734 } | 9481 } |
9735 | 9482 |
9736 | 9483 |
9737 static const char* arg_names[] = { | 9484 static const char* arg_names[] = {"arg0"}; |
9738 "arg0" | |
9739 }; | |
9740 | 9485 |
9741 | 9486 |
9742 static const char* arg_values[] = { | 9487 static const char* arg_values[] = {"value0"}; |
9743 "value0" | |
9744 }; | |
9745 | 9488 |
9746 | 9489 |
9747 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { | 9490 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { |
9748 const char* kScriptChars = | 9491 const char* kScriptChars = |
9749 "bar() => 'z';\n" | 9492 "bar() => 'z';\n" |
9750 "foo() => 'a';\n" | 9493 "foo() => 'a';\n" |
9751 "main() => foo();\n"; | 9494 "main() => foo();\n"; |
9752 | 9495 |
9753 // Enable all streams. | 9496 // Enable all streams. |
9754 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | | 9497 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | |
9755 DART_TIMELINE_STREAM_VM); | 9498 DART_TIMELINE_STREAM_VM); |
9756 Dart_Handle lib; | 9499 Dart_Handle lib; |
9757 { | 9500 { |
9758 // Add something to the VM stream. | 9501 // Add something to the VM stream. |
9759 TimelineDurationScope tds(Timeline::GetVMStream(), | 9502 TimelineDurationScope tds(Timeline::GetVMStream(), "TestVMDuration"); |
9760 "TestVMDuration"); | |
9761 lib = TestCase::LoadTestScript(kScriptChars, NULL); | 9503 lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9762 } | 9504 } |
9763 | 9505 |
9764 { | 9506 { |
9765 // Add something to the embedder stream. | 9507 // Add something to the embedder stream. |
9766 Dart_TimelineEvent("TRACE_EVENT", | 9508 Dart_TimelineEvent("TRACE_EVENT", Dart_TimelineGetMicros(), 0, |
9767 Dart_TimelineGetMicros(), | 9509 Dart_Timeline_Event_Begin, 1, &arg_names[0], |
9768 0, | |
9769 Dart_Timeline_Event_Begin, | |
9770 1, | |
9771 &arg_names[0], | |
9772 &arg_values[0]); | 9510 &arg_values[0]); |
9773 // Add counter to the embedder stream. | 9511 // Add counter to the embedder stream. |
9774 Dart_TimelineEvent("COUNTER_EVENT", | 9512 Dart_TimelineEvent("COUNTER_EVENT", Dart_TimelineGetMicros(), 0, |
9775 Dart_TimelineGetMicros(), | 9513 Dart_Timeline_Event_Counter, 0, NULL, NULL); |
9776 0, | |
9777 Dart_Timeline_Event_Counter, | |
9778 0, | |
9779 NULL, | |
9780 NULL); | |
9781 Dart_SetThreadName("CUSTOM THREAD NAME"); | 9514 Dart_SetThreadName("CUSTOM THREAD NAME"); |
9782 } | 9515 } |
9783 | 9516 |
9784 // Invoke main, which will be compiled resulting in a compiler event in | 9517 // Invoke main, which will be compiled resulting in a compiler event in |
9785 // the timeline. | 9518 // the timeline. |
9786 Dart_Handle result = Dart_Invoke(lib, | 9519 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9787 NewString("main"), | |
9788 0, | |
9789 NULL); | |
9790 EXPECT_VALID(result); | 9520 EXPECT_VALID(result); |
9791 | 9521 |
9792 const char* buffer = NULL; | 9522 const char* buffer = NULL; |
9793 intptr_t buffer_length = 0; | 9523 intptr_t buffer_length = 0; |
9794 bool success = false; | 9524 bool success = false; |
9795 | 9525 |
9796 // Grab the global trace. | 9526 // Grab the global trace. |
9797 AppendData data; | 9527 AppendData data; |
9798 { | 9528 { |
9799 Thread* T = Thread::Current(); | 9529 Thread* T = Thread::Current(); |
(...skipping 29 matching lines...) Expand all Loading... |
9829 // Free buffer allocated by AppendStreamConsumer | 9559 // Free buffer allocated by AppendStreamConsumer |
9830 free(data.buffer); | 9560 free(data.buffer); |
9831 data.buffer = NULL; | 9561 data.buffer = NULL; |
9832 data.buffer_length = 0; | 9562 data.buffer_length = 0; |
9833 | 9563 |
9834 // Retrieving the global trace resulted in all open blocks being reclaimed. | 9564 // Retrieving the global trace resulted in all open blocks being reclaimed. |
9835 // Add some new events and verify that both sets of events are present | 9565 // Add some new events and verify that both sets of events are present |
9836 // in the resulting trace. | 9566 // in the resulting trace. |
9837 { | 9567 { |
9838 // Add something to the VM stream. | 9568 // Add something to the VM stream. |
9839 TimelineDurationScope tds(Timeline::GetVMStream(), | 9569 TimelineDurationScope tds(Timeline::GetVMStream(), "TestVMDuration2"); |
9840 "TestVMDuration2"); | |
9841 // Invoke bar, which will be compiled resulting in a compiler event in | 9570 // Invoke bar, which will be compiled resulting in a compiler event in |
9842 // the timeline. | 9571 // the timeline. |
9843 result = Dart_Invoke(lib, | 9572 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
9844 NewString("bar"), | |
9845 0, | |
9846 NULL); | |
9847 } | 9573 } |
9848 | 9574 |
9849 // Grab the global trace. | 9575 // Grab the global trace. |
9850 { | 9576 { |
9851 Thread* T = Thread::Current(); | 9577 Thread* T = Thread::Current(); |
9852 StackZone zone(T); | 9578 StackZone zone(T); |
9853 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9579 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
9854 EXPECT(success); | 9580 EXPECT(success); |
9855 EXPECT(zone.SizeInBytes() == 0); | 9581 EXPECT(zone.SizeInBytes() == 0); |
9856 } | 9582 } |
(...skipping 18 matching lines...) Expand all Loading... |
9875 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9601 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9876 | 9602 |
9877 // Free buffer allocated by AppendStreamConsumer | 9603 // Free buffer allocated by AppendStreamConsumer |
9878 free(data.buffer); | 9604 free(data.buffer); |
9879 } | 9605 } |
9880 | 9606 |
9881 | 9607 |
9882 class GlobalTimelineThreadData { | 9608 class GlobalTimelineThreadData { |
9883 public: | 9609 public: |
9884 GlobalTimelineThreadData() | 9610 GlobalTimelineThreadData() |
9885 : monitor_(new Monitor()), | 9611 : monitor_(new Monitor()), data_(new AppendData()), running_(true) {} |
9886 data_(new AppendData()), | |
9887 running_(true) { | |
9888 } | |
9889 | 9612 |
9890 ~GlobalTimelineThreadData() { | 9613 ~GlobalTimelineThreadData() { |
9891 delete monitor_; | 9614 delete monitor_; |
9892 monitor_ = NULL; | 9615 monitor_ = NULL; |
9893 free(data_->buffer); | 9616 free(data_->buffer); |
9894 data_->buffer = NULL; | 9617 data_->buffer = NULL; |
9895 data_->buffer_length = 0; | 9618 data_->buffer_length = 0; |
9896 delete data_; | 9619 delete data_; |
9897 data_ = NULL; | 9620 data_ = NULL; |
9898 } | 9621 } |
(...skipping 29 matching lines...) Expand all Loading... |
9928 } | 9651 } |
9929 } | 9652 } |
9930 | 9653 |
9931 | 9654 |
9932 // This test is the same as the one above except that the calls to | 9655 // This test is the same as the one above except that the calls to |
9933 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that | 9656 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that |
9934 // we can call the function from a thread for which we have not set up a | 9657 // we can call the function from a thread for which we have not set up a |
9935 // Thread object. | 9658 // Thread object. |
9936 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) { | 9659 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) { |
9937 const char* kScriptChars = | 9660 const char* kScriptChars = |
9938 "bar() => 'z';\n" | 9661 "bar() => 'z';\n" |
9939 "foo() => 'a';\n" | 9662 "foo() => 'a';\n" |
9940 "main() => foo();\n"; | 9663 "main() => foo();\n"; |
9941 | 9664 |
9942 // Enable all streams. | 9665 // Enable all streams. |
9943 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | | 9666 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | |
9944 DART_TIMELINE_STREAM_VM); | 9667 DART_TIMELINE_STREAM_VM); |
9945 Dart_Handle lib; | 9668 Dart_Handle lib; |
9946 { | 9669 { |
9947 // Add something to the VM stream. | 9670 // Add something to the VM stream. |
9948 TimelineDurationScope tds(Timeline::GetVMStream(), | 9671 TimelineDurationScope tds(Timeline::GetVMStream(), "TestVMDuration"); |
9949 "TestVMDuration"); | |
9950 lib = TestCase::LoadTestScript(kScriptChars, NULL); | 9672 lib = TestCase::LoadTestScript(kScriptChars, NULL); |
9951 } | 9673 } |
9952 | 9674 |
9953 // Invoke main, which will be compiled resulting in a compiler event in | 9675 // Invoke main, which will be compiled resulting in a compiler event in |
9954 // the timeline. | 9676 // the timeline. |
9955 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 9677 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
9956 EXPECT_VALID(result); | 9678 EXPECT_VALID(result); |
9957 | 9679 |
9958 const char* buffer = NULL; | 9680 const char* buffer = NULL; |
9959 intptr_t buffer_length = 0; | 9681 intptr_t buffer_length = 0; |
9960 | 9682 |
9961 // Run Dart_GlobalTimelineGetTrace on a fresh thread. | 9683 // Run Dart_GlobalTimelineGetTrace on a fresh thread. |
9962 GlobalTimelineThreadData data; | 9684 GlobalTimelineThreadData data; |
9963 int err = OSThread::Start("Timeline test thread", | 9685 int err = OSThread::Start("Timeline test thread", GlobalTimelineThread, |
9964 GlobalTimelineThread, reinterpret_cast<uword>(&data)); | 9686 reinterpret_cast<uword>(&data)); |
9965 EXPECT(err == 0); | 9687 EXPECT(err == 0); |
9966 { | 9688 { |
9967 MonitorLocker ml(data.monitor()); | 9689 MonitorLocker ml(data.monitor()); |
9968 while (data.running()) { | 9690 while (data.running()) { |
9969 ml.Wait(); | 9691 ml.Wait(); |
9970 } | 9692 } |
9971 buffer = reinterpret_cast<char*>(data.buffer()); | 9693 buffer = reinterpret_cast<char*>(data.buffer()); |
9972 buffer_length = data.buffer_length(); | 9694 buffer_length = data.buffer_length(); |
9973 } | 9695 } |
9974 EXPECT(buffer_length > 0); | 9696 EXPECT(buffer_length > 0); |
(...skipping 10 matching lines...) Expand all Loading... |
9985 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9707 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9986 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9708 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9987 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9709 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9988 EXPECT_NOTSUBSTRING("\"function\":\"::_bar\"", buffer); | 9710 EXPECT_NOTSUBSTRING("\"function\":\"::_bar\"", buffer); |
9989 | 9711 |
9990 // Retrieving the global trace resulted in all open blocks being reclaimed. | 9712 // Retrieving the global trace resulted in all open blocks being reclaimed. |
9991 // Add some new events and verify that both sets of events are present | 9713 // Add some new events and verify that both sets of events are present |
9992 // in the resulting trace. | 9714 // in the resulting trace. |
9993 { | 9715 { |
9994 // Add something to the VM stream. | 9716 // Add something to the VM stream. |
9995 TimelineDurationScope tds(Timeline::GetVMStream(), | 9717 TimelineDurationScope tds(Timeline::GetVMStream(), "TestVMDuration2"); |
9996 "TestVMDuration2"); | |
9997 // Invoke bar, which will be compiled resulting in a compiler event in | 9718 // Invoke bar, which will be compiled resulting in a compiler event in |
9998 // the timeline. | 9719 // the timeline. |
9999 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); | 9720 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
10000 } | 9721 } |
10001 | 9722 |
10002 // Grab the global trace. | 9723 // Grab the global trace. |
10003 GlobalTimelineThreadData data2; | 9724 GlobalTimelineThreadData data2; |
10004 err = OSThread::Start("Timeline test thread", | 9725 err = OSThread::Start("Timeline test thread", GlobalTimelineThread, |
10005 GlobalTimelineThread, reinterpret_cast<uword>(&data2)); | 9726 reinterpret_cast<uword>(&data2)); |
10006 EXPECT(err == 0); | 9727 EXPECT(err == 0); |
10007 { | 9728 { |
10008 MonitorLocker ml(data2.monitor()); | 9729 MonitorLocker ml(data2.monitor()); |
10009 while (data2.running()) { | 9730 while (data2.running()) { |
10010 ml.Wait(); | 9731 ml.Wait(); |
10011 } | 9732 } |
10012 buffer = reinterpret_cast<char*>(data2.buffer()); | 9733 buffer = reinterpret_cast<char*>(data2.buffer()); |
10013 buffer_length = data2.buffer_length(); | 9734 buffer_length = data2.buffer_length(); |
10014 } | 9735 } |
10015 | 9736 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10074 "foozoo() { new A().zoo(); }\n" | 9795 "foozoo() { new A().zoo(); }\n" |
10075 "foomoo() { A.moo(); }\n"; | 9796 "foomoo() { A.moo(); }\n"; |
10076 | 9797 |
10077 const char* kScriptChars2 = | 9798 const char* kScriptChars2 = |
10078 "@patch class A {\n" | 9799 "@patch class A {\n" |
10079 " @patch int zoo() { return 1; }\n" | 9800 " @patch int zoo() { return 1; }\n" |
10080 " @patch static int moo() { return 1; }\n" | 9801 " @patch static int moo() { return 1; }\n" |
10081 "}\n"; | 9802 "}\n"; |
10082 | 9803 |
10083 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 9804 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10084 Dart_Handle result = Dart_Invoke(lib, | 9805 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
10085 NewString("main"), | |
10086 0, | |
10087 NULL); | |
10088 EXPECT_VALID(result); | 9806 EXPECT_VALID(result); |
10089 Dart_Handle url = NewString("test-lib-patch"); | 9807 Dart_Handle url = NewString("test-lib-patch"); |
10090 Dart_Handle source = NewString(kScriptChars2); | 9808 Dart_Handle source = NewString(kScriptChars2); |
10091 result = Dart_LibraryLoadPatch(lib, url, source); | 9809 result = Dart_LibraryLoadPatch(lib, url, source); |
10092 EXPECT_VALID(result); | 9810 EXPECT_VALID(result); |
10093 result = Dart_FinalizeLoading(false); | 9811 result = Dart_FinalizeLoading(false); |
10094 EXPECT_VALID(result); | 9812 EXPECT_VALID(result); |
10095 result = Dart_Invoke(lib, | 9813 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
10096 NewString("foozoo"), | |
10097 0, | |
10098 NULL); | |
10099 EXPECT_VALID(result); | 9814 EXPECT_VALID(result); |
10100 result = Dart_Invoke(lib, | 9815 result = Dart_Invoke(lib, NewString("foomoo"), 0, NULL); |
10101 NewString("foomoo"), | |
10102 0, | |
10103 NULL); | |
10104 EXPECT_VALID(result); | 9816 EXPECT_VALID(result); |
10105 } | 9817 } |
10106 | 9818 |
10107 | 9819 |
10108 TEST_CASE(Dart_LoadLibraryPatch_Error1) { | 9820 TEST_CASE(Dart_LoadLibraryPatch_Error1) { |
10109 const char* kScriptChars1 = | 9821 const char* kScriptChars1 = |
10110 "class A {\n" | 9822 "class A {\n" |
10111 " int foo() { return 10; }\n" | 9823 " int foo() { return 10; }\n" |
10112 " external int zoo();\n" | 9824 " external int zoo();\n" |
10113 "}\n" | 9825 "}\n" |
10114 "main() { new A().foo(); }\n" | 9826 "main() { new A().foo(); }\n" |
10115 "foozoo() { new A().zoo(); }\n"; | 9827 "foozoo() { new A().zoo(); }\n"; |
10116 | 9828 |
10117 const char* kScriptChars2 = | 9829 const char* kScriptChars2 = |
10118 "@patch class A {\n" | 9830 "@patch class A {\n" |
10119 " @patch int zoo() { return 1; }\n" | 9831 " @patch int zoo() { return 1; }\n" |
10120 " @patch int fld1;\n" | 9832 " @patch int fld1;\n" |
10121 "}\n"; | 9833 "}\n"; |
10122 | 9834 |
10123 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 9835 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10124 Dart_Handle result = Dart_Invoke(lib, | 9836 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
10125 NewString("main"), | |
10126 0, | |
10127 NULL); | |
10128 EXPECT_VALID(result); | 9837 EXPECT_VALID(result); |
10129 Dart_Handle url = NewString("test-lib-patch"); | 9838 Dart_Handle url = NewString("test-lib-patch"); |
10130 Dart_Handle source = NewString(kScriptChars2); | 9839 Dart_Handle source = NewString(kScriptChars2); |
10131 // We don't expect to be able to patch in this case as new fields | 9840 // We don't expect to be able to patch in this case as new fields |
10132 // are being added. | 9841 // are being added. |
10133 result = Dart_LibraryLoadPatch(lib, url, source); | 9842 result = Dart_LibraryLoadPatch(lib, url, source); |
10134 EXPECT_VALID(result); | 9843 EXPECT_VALID(result); |
10135 result = Dart_FinalizeLoading(false); | 9844 result = Dart_FinalizeLoading(false); |
10136 EXPECT_VALID(result); | 9845 EXPECT_VALID(result); |
10137 result = Dart_Invoke(lib, | 9846 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
10138 NewString("foozoo"), | |
10139 0, | |
10140 NULL); | |
10141 EXPECT(Dart_IsError(result)); | 9847 EXPECT(Dart_IsError(result)); |
10142 } | 9848 } |
10143 | 9849 |
10144 | 9850 |
10145 TEST_CASE(Dart_LoadLibraryPatch_Error2) { | 9851 TEST_CASE(Dart_LoadLibraryPatch_Error2) { |
10146 const char* kScriptChars1 = | 9852 const char* kScriptChars1 = |
10147 "class A {\n" | 9853 "class A {\n" |
10148 " int foo() { return 10; }\n" | 9854 " int foo() { return 10; }\n" |
10149 " int zoo() { return 20; }\n" | 9855 " int zoo() { return 20; }\n" |
10150 "}\n" | 9856 "}\n" |
10151 "main() { new A().foo(); }\n" | 9857 "main() { new A().foo(); }\n" |
10152 "foozoo() { new A().zoo(); }\n"; | 9858 "foozoo() { new A().zoo(); }\n"; |
10153 | 9859 |
10154 const char* kScriptChars2 = | 9860 const char* kScriptChars2 = |
10155 "@patch class A {\n" | 9861 "@patch class A {\n" |
10156 " @patch int zoo() { return 1; }\n" | 9862 " @patch int zoo() { return 1; }\n" |
10157 "}\n"; | 9863 "}\n"; |
10158 | 9864 |
10159 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 9865 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10160 Dart_Handle result = Dart_Invoke(lib, | 9866 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
10161 NewString("main"), | |
10162 0, | |
10163 NULL); | |
10164 EXPECT_VALID(result); | 9867 EXPECT_VALID(result); |
10165 Dart_Handle url = NewString("test-lib-patch"); | 9868 Dart_Handle url = NewString("test-lib-patch"); |
10166 Dart_Handle source = NewString(kScriptChars2); | 9869 Dart_Handle source = NewString(kScriptChars2); |
10167 // We don't expect to be able to patch in this case as a non external | 9870 // We don't expect to be able to patch in this case as a non external |
10168 // method is being patched. | 9871 // method is being patched. |
10169 result = Dart_LibraryLoadPatch(lib, url, source); | 9872 result = Dart_LibraryLoadPatch(lib, url, source); |
10170 EXPECT_VALID(result); | 9873 EXPECT_VALID(result); |
10171 result = Dart_FinalizeLoading(false); | 9874 result = Dart_FinalizeLoading(false); |
10172 EXPECT_VALID(result); | 9875 EXPECT_VALID(result); |
10173 result = Dart_Invoke(lib, | 9876 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
10174 NewString("foozoo"), | |
10175 0, | |
10176 NULL); | |
10177 EXPECT(Dart_IsError(result)); | 9877 EXPECT(Dart_IsError(result)); |
10178 OS::Print("Patched class executed\n"); | 9878 OS::Print("Patched class executed\n"); |
10179 } | 9879 } |
10180 | 9880 |
10181 | 9881 |
10182 TEST_CASE(Dart_LoadLibraryPatch_Error3) { | 9882 TEST_CASE(Dart_LoadLibraryPatch_Error3) { |
10183 const char* kScriptChars1 = | 9883 const char* kScriptChars1 = |
10184 "class A {\n" | 9884 "class A {\n" |
10185 " int foo() { return 10; }\n" | 9885 " int foo() { return 10; }\n" |
10186 " external int zoo();\n" | 9886 " external int zoo();\n" |
10187 "}\n" | 9887 "}\n" |
10188 "main() { new A().foo(); }\n" | 9888 "main() { new A().foo(); }\n" |
10189 "foozoo() { new A().zoo(); }\n"; | 9889 "foozoo() { new A().zoo(); }\n"; |
10190 | 9890 |
10191 const char* kScriptChars2 = | 9891 const char* kScriptChars2 = |
10192 "@patch class A {\n" | 9892 "@patch class A {\n" |
10193 " @patch int zoo() { return 1; }\n" | 9893 " @patch int zoo() { return 1; }\n" |
10194 "}\n"; | 9894 "}\n"; |
10195 | 9895 |
10196 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 9896 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10197 Dart_Handle result = Dart_Invoke(lib, | 9897 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
10198 NewString("main"), | |
10199 0, | |
10200 NULL); | |
10201 // We invoke the foozoo method to ensure that code for 'zoo' is generated | 9898 // We invoke the foozoo method to ensure that code for 'zoo' is generated |
10202 // which throws NoSuchMethod. | 9899 // which throws NoSuchMethod. |
10203 result = Dart_Invoke(lib, | 9900 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
10204 NewString("foozoo"), | |
10205 0, | |
10206 NULL); | |
10207 EXPECT(Dart_IsError(result)); | 9901 EXPECT(Dart_IsError(result)); |
10208 Dart_Handle url = NewString("test-lib-patch"); | 9902 Dart_Handle url = NewString("test-lib-patch"); |
10209 Dart_Handle source = NewString(kScriptChars2); | 9903 Dart_Handle source = NewString(kScriptChars2); |
10210 // We don't expect to be able to patch in this case as the function being | 9904 // We don't expect to be able to patch in this case as the function being |
10211 // patched has already executed. | 9905 // patched has already executed. |
10212 result = Dart_LibraryLoadPatch(lib, url, source); | 9906 result = Dart_LibraryLoadPatch(lib, url, source); |
10213 EXPECT_VALID(result); | 9907 EXPECT_VALID(result); |
10214 result = Dart_FinalizeLoading(false); | 9908 result = Dart_FinalizeLoading(false); |
10215 EXPECT_VALID(result); | 9909 EXPECT_VALID(result); |
10216 result = Dart_Invoke(lib, | 9910 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
10217 NewString("foozoo"), | |
10218 0, | |
10219 NULL); | |
10220 EXPECT(Dart_IsError(result)); | 9911 EXPECT(Dart_IsError(result)); |
10221 } | 9912 } |
10222 | 9913 |
10223 #endif // !PRODUCT | 9914 #endif // !PRODUCT |
10224 | 9915 |
10225 } // namespace dart | 9916 } // namespace dart |
OLD | NEW |