OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/unit_test.h" | 5 #include "vm/unit_test.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 using dart::bin::Builtin; | 26 using dart::bin::Builtin; |
27 using dart::bin::DartUtils; | 27 using dart::bin::DartUtils; |
28 | 28 |
29 namespace dart { | 29 namespace dart { |
30 | 30 |
31 DECLARE_FLAG(bool, use_dart_frontend); | 31 DECLARE_FLAG(bool, use_dart_frontend); |
32 | 32 |
33 TestCaseBase* TestCaseBase::first_ = NULL; | 33 TestCaseBase* TestCaseBase::first_ = NULL; |
34 TestCaseBase* TestCaseBase::tail_ = NULL; | 34 TestCaseBase* TestCaseBase::tail_ = NULL; |
35 | 35 |
36 | |
37 TestCaseBase::TestCaseBase(const char* name) | 36 TestCaseBase::TestCaseBase(const char* name) |
38 : raw_test_(false), next_(NULL), name_(name) { | 37 : raw_test_(false), next_(NULL), name_(name) { |
39 if (first_ == NULL) { | 38 if (first_ == NULL) { |
40 first_ = this; | 39 first_ = this; |
41 } else { | 40 } else { |
42 tail_->next_ = this; | 41 tail_->next_ = this; |
43 } | 42 } |
44 tail_ = this; | 43 tail_ = this; |
45 } | 44 } |
46 | 45 |
47 | |
48 void TestCaseBase::RunAllRaw() { | 46 void TestCaseBase::RunAllRaw() { |
49 TestCaseBase* test = first_; | 47 TestCaseBase* test = first_; |
50 while (test != NULL) { | 48 while (test != NULL) { |
51 if (test->raw_test_) { | 49 if (test->raw_test_) { |
52 test->RunTest(); | 50 test->RunTest(); |
53 } | 51 } |
54 test = test->next_; | 52 test = test->next_; |
55 } | 53 } |
56 } | 54 } |
57 | 55 |
58 | |
59 void TestCaseBase::RunAll() { | 56 void TestCaseBase::RunAll() { |
60 TestCaseBase* test = first_; | 57 TestCaseBase* test = first_; |
61 while (test != NULL) { | 58 while (test != NULL) { |
62 if (!test->raw_test_) { | 59 if (!test->raw_test_) { |
63 test->RunTest(); | 60 test->RunTest(); |
64 } | 61 } |
65 test = test->next_; | 62 test = test->next_; |
66 } | 63 } |
67 } | 64 } |
68 | 65 |
69 | |
70 Dart_Isolate TestCase::CreateIsolate(const uint8_t* buffer, const char* name) { | 66 Dart_Isolate TestCase::CreateIsolate(const uint8_t* buffer, const char* name) { |
71 char* err; | 67 char* err; |
72 Dart_Isolate isolate = | 68 Dart_Isolate isolate = |
73 Dart_CreateIsolate(name, NULL, buffer, NULL, NULL, NULL, &err); | 69 Dart_CreateIsolate(name, NULL, buffer, NULL, NULL, NULL, &err); |
74 if (isolate == NULL) { | 70 if (isolate == NULL) { |
75 OS::Print("Creation of isolate failed '%s'\n", err); | 71 OS::Print("Creation of isolate failed '%s'\n", err); |
76 free(err); | 72 free(err); |
77 } | 73 } |
78 EXPECT(isolate != NULL); | 74 EXPECT(isolate != NULL); |
79 return isolate; | 75 return isolate; |
80 } | 76 } |
81 | 77 |
82 | |
83 static const char* kPackageScheme = "package:"; | 78 static const char* kPackageScheme = "package:"; |
84 | 79 |
85 | |
86 static bool IsPackageSchemeURL(const char* url_name) { | 80 static bool IsPackageSchemeURL(const char* url_name) { |
87 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); | 81 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); |
88 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); | 82 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); |
89 } | 83 } |
90 | 84 |
91 | |
92 struct TestLibEntry { | 85 struct TestLibEntry { |
93 const char* url; | 86 const char* url; |
94 const char* source; | 87 const char* source; |
95 }; | 88 }; |
96 | 89 |
97 | |
98 static MallocGrowableArray<TestLibEntry>* test_libs_ = NULL; | 90 static MallocGrowableArray<TestLibEntry>* test_libs_ = NULL; |
99 | 91 |
100 | |
101 void TestCase::AddTestLib(const char* url, const char* source) { | 92 void TestCase::AddTestLib(const char* url, const char* source) { |
102 if (test_libs_ == NULL) { | 93 if (test_libs_ == NULL) { |
103 test_libs_ = new MallocGrowableArray<TestLibEntry>(); | 94 test_libs_ = new MallocGrowableArray<TestLibEntry>(); |
104 } | 95 } |
105 // If the test lib is already added, replace the source. | 96 // If the test lib is already added, replace the source. |
106 for (intptr_t i = 0; i < test_libs_->length(); i++) { | 97 for (intptr_t i = 0; i < test_libs_->length(); i++) { |
107 if (strcmp(url, (*test_libs_)[i].url) == 0) { | 98 if (strcmp(url, (*test_libs_)[i].url) == 0) { |
108 (*test_libs_)[i].source = source; | 99 (*test_libs_)[i].source = source; |
109 return; | 100 return; |
110 } | 101 } |
111 } | 102 } |
112 TestLibEntry entry; | 103 TestLibEntry entry; |
113 entry.url = url; | 104 entry.url = url; |
114 entry.source = source; | 105 entry.source = source; |
115 test_libs_->Add(entry); | 106 test_libs_->Add(entry); |
116 } | 107 } |
117 | 108 |
118 | |
119 const char* TestCase::GetTestLib(const char* url) { | 109 const char* TestCase::GetTestLib(const char* url) { |
120 if (test_libs_ == NULL) { | 110 if (test_libs_ == NULL) { |
121 return NULL; | 111 return NULL; |
122 } | 112 } |
123 for (intptr_t i = 0; i < test_libs_->length(); i++) { | 113 for (intptr_t i = 0; i < test_libs_->length(); i++) { |
124 if (strcmp(url, (*test_libs_)[i].url) == 0) { | 114 if (strcmp(url, (*test_libs_)[i].url) == 0) { |
125 return (*test_libs_)[i].source; | 115 return (*test_libs_)[i].source; |
126 } | 116 } |
127 } | 117 } |
128 return NULL; | 118 return NULL; |
129 } | 119 } |
130 | 120 |
131 #ifndef PRODUCT | 121 #ifndef PRODUCT |
132 static bool IsIsolateReloadTestLib(const char* url_name) { | 122 static bool IsIsolateReloadTestLib(const char* url_name) { |
133 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper"; | 123 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper"; |
134 static const intptr_t kIsolateReloadTestLibUriLen = | 124 static const intptr_t kIsolateReloadTestLibUriLen = |
135 strlen(kIsolateReloadTestLibUri); | 125 strlen(kIsolateReloadTestLibUri); |
136 return (strncmp(url_name, kIsolateReloadTestLibUri, | 126 return (strncmp(url_name, kIsolateReloadTestLibUri, |
137 kIsolateReloadTestLibUriLen) == 0); | 127 kIsolateReloadTestLibUriLen) == 0); |
138 } | 128 } |
139 | 129 |
140 | |
141 static Dart_Handle IsolateReloadTestLibSource() { | 130 static Dart_Handle IsolateReloadTestLibSource() { |
142 // Special library with one function. | 131 // Special library with one function. |
143 return DartUtils::NewString("void reloadTest() native 'Reload_Test';\n"); | 132 return DartUtils::NewString("void reloadTest() native 'Reload_Test';\n"); |
144 } | 133 } |
145 | 134 |
146 | |
147 static void ReloadTest(Dart_NativeArguments native_args) { | 135 static void ReloadTest(Dart_NativeArguments native_args) { |
148 DART_CHECK_VALID(TestCase::TriggerReload()); | 136 DART_CHECK_VALID(TestCase::TriggerReload()); |
149 } | 137 } |
150 | 138 |
151 | |
152 static Dart_NativeFunction IsolateReloadTestNativeResolver( | 139 static Dart_NativeFunction IsolateReloadTestNativeResolver( |
153 Dart_Handle name, | 140 Dart_Handle name, |
154 int num_of_arguments, | 141 int num_of_arguments, |
155 bool* auto_setup_scope) { | 142 bool* auto_setup_scope) { |
156 return ReloadTest; | 143 return ReloadTest; |
157 } | 144 } |
158 #endif // !PRODUCT | 145 #endif // !PRODUCT |
159 | 146 |
160 | |
161 static Dart_Handle ResolvePackageUri(const char* uri_chars) { | 147 static Dart_Handle ResolvePackageUri(const char* uri_chars) { |
162 const int kNumArgs = 1; | 148 const int kNumArgs = 1; |
163 Dart_Handle dart_args[kNumArgs]; | 149 Dart_Handle dart_args[kNumArgs]; |
164 dart_args[0] = DartUtils::NewString(uri_chars); | 150 dart_args[0] = DartUtils::NewString(uri_chars); |
165 return Dart_Invoke(DartUtils::BuiltinLib(), | 151 return Dart_Invoke(DartUtils::BuiltinLib(), |
166 DartUtils::NewString("_filePathFromUri"), kNumArgs, | 152 DartUtils::NewString("_filePathFromUri"), kNumArgs, |
167 dart_args); | 153 dart_args); |
168 } | 154 } |
169 | 155 |
170 | |
171 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey; | 156 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey; |
172 | 157 |
173 static char* CompileTestScriptWithDFE(const char* url, | 158 static char* CompileTestScriptWithDFE(const char* url, |
174 const char* source, | 159 const char* source, |
175 void** kernel_pgm) { | 160 void** kernel_pgm) { |
176 Zone* zone = Thread::Current()->zone(); | 161 Zone* zone = Thread::Current()->zone(); |
177 char* filename = OS::SCreate(zone, "file:///%s", url); | 162 char* filename = OS::SCreate(zone, "file:///%s", url); |
178 // clang-format off | 163 // clang-format off |
179 Dart_SourceFile sourcefiles[] = { | 164 Dart_SourceFile sourcefiles[] = { |
180 { | 165 { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (!FLAG_use_dart_frontend) { | 347 if (!FLAG_use_dart_frontend) { |
363 return LoadTestScriptWithVMParser(script, resolver, lib_url, | 348 return LoadTestScriptWithVMParser(script, resolver, lib_url, |
364 finalize_classes); | 349 finalize_classes); |
365 } else { | 350 } else { |
366 return LoadTestScriptWithDFE(script, resolver, lib_url, finalize_classes); | 351 return LoadTestScriptWithDFE(script, resolver, lib_url, finalize_classes); |
367 } | 352 } |
368 } | 353 } |
369 | 354 |
370 #ifndef PRODUCT | 355 #ifndef PRODUCT |
371 | 356 |
372 | |
373 void TestCase::SetReloadTestScript(const char* script) { | 357 void TestCase::SetReloadTestScript(const char* script) { |
374 if (script_reload_key == kUnsetThreadLocalKey) { | 358 if (script_reload_key == kUnsetThreadLocalKey) { |
375 script_reload_key = OSThread::CreateThreadLocal(); | 359 script_reload_key = OSThread::CreateThreadLocal(); |
376 } | 360 } |
377 ASSERT(script_reload_key != kUnsetThreadLocalKey); | 361 ASSERT(script_reload_key != kUnsetThreadLocalKey); |
378 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0); | 362 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0); |
379 // Store the new script in TLS. | 363 // Store the new script in TLS. |
380 OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script)); | 364 OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script)); |
381 } | 365 } |
382 | 366 |
383 | |
384 Dart_Handle TestCase::TriggerReload() { | 367 Dart_Handle TestCase::TriggerReload() { |
385 Isolate* isolate = Isolate::Current(); | 368 Isolate* isolate = Isolate::Current(); |
386 JSONStream js; | 369 JSONStream js; |
387 bool success = false; | 370 bool success = false; |
388 { | 371 { |
389 TransitionNativeToVM transition(Thread::Current()); | 372 TransitionNativeToVM transition(Thread::Current()); |
390 success = isolate->ReloadSources(&js, | 373 success = isolate->ReloadSources(&js, |
391 false, // force_reload | 374 false, // force_reload |
392 NULL, NULL, | 375 NULL, NULL, |
393 true); // dont_delete_reload_context | 376 true); // dont_delete_reload_context |
394 OS::PrintErr("RELOAD REPORT:\n%s\n", js.ToCString()); | 377 OS::PrintErr("RELOAD REPORT:\n%s\n", js.ToCString()); |
395 } | 378 } |
396 | 379 |
397 if (success) { | 380 if (success) { |
398 return Dart_FinalizeLoading(false); | 381 return Dart_FinalizeLoading(false); |
399 } else { | 382 } else { |
400 return Dart_Null(); | 383 return Dart_Null(); |
401 } | 384 } |
402 } | 385 } |
403 | 386 |
404 | |
405 Dart_Handle TestCase::GetReloadErrorOrRootLibrary() { | 387 Dart_Handle TestCase::GetReloadErrorOrRootLibrary() { |
406 Isolate* isolate = Isolate::Current(); | 388 Isolate* isolate = Isolate::Current(); |
407 | 389 |
408 if (isolate->reload_context() != NULL && | 390 if (isolate->reload_context() != NULL && |
409 isolate->reload_context()->reload_aborted()) { | 391 isolate->reload_context()->reload_aborted()) { |
410 // Return a handle to the error. | 392 // Return a handle to the error. |
411 return Api::NewHandle(Thread::Current(), | 393 return Api::NewHandle(Thread::Current(), |
412 isolate->reload_context()->error()); | 394 isolate->reload_context()->error()); |
413 } | 395 } |
414 return Dart_RootLibrary(); | 396 return Dart_RootLibrary(); |
415 } | 397 } |
416 | 398 |
417 | |
418 Dart_Handle TestCase::ReloadTestScript(const char* script) { | 399 Dart_Handle TestCase::ReloadTestScript(const char* script) { |
419 SetReloadTestScript(script); | 400 SetReloadTestScript(script); |
420 | 401 |
421 Dart_Handle result = TriggerReload(); | 402 Dart_Handle result = TriggerReload(); |
422 if (Dart_IsError(result)) { | 403 if (Dart_IsError(result)) { |
423 return result; | 404 return result; |
424 } | 405 } |
425 | 406 |
426 result = GetReloadErrorOrRootLibrary(); | 407 result = GetReloadErrorOrRootLibrary(); |
427 | 408 |
428 { | 409 { |
429 Thread* thread = Thread::Current(); | 410 Thread* thread = Thread::Current(); |
430 TransitionNativeToVM transition(thread); | 411 TransitionNativeToVM transition(thread); |
431 Isolate* isolate = thread->isolate(); | 412 Isolate* isolate = thread->isolate(); |
432 if (isolate->reload_context() != NULL) { | 413 if (isolate->reload_context() != NULL) { |
433 isolate->DeleteReloadContext(); | 414 isolate->DeleteReloadContext(); |
434 } | 415 } |
435 } | 416 } |
436 | 417 |
437 return result; | 418 return result; |
438 } | 419 } |
439 | 420 |
440 | |
441 #endif // !PRODUCT | 421 #endif // !PRODUCT |
442 | 422 |
443 | |
444 Dart_Handle TestCase::LoadCoreTestScript(const char* script, | 423 Dart_Handle TestCase::LoadCoreTestScript(const char* script, |
445 Dart_NativeEntryResolver resolver) { | 424 Dart_NativeEntryResolver resolver) { |
446 return LoadTestScript(script, resolver, CORELIB_TEST_URI); | 425 return LoadTestScript(script, resolver, CORELIB_TEST_URI); |
447 } | 426 } |
448 | 427 |
449 | |
450 Dart_Handle TestCase::lib() { | 428 Dart_Handle TestCase::lib() { |
451 Dart_Handle url = NewString(TestCase::url()); | 429 Dart_Handle url = NewString(TestCase::url()); |
452 Dart_Handle lib = Dart_LookupLibrary(url); | 430 Dart_Handle lib = Dart_LookupLibrary(url); |
453 DART_CHECK_VALID(lib); | 431 DART_CHECK_VALID(lib); |
454 ASSERT(Dart_IsLibrary(lib)); | 432 ASSERT(Dart_IsLibrary(lib)); |
455 return lib; | 433 return lib; |
456 } | 434 } |
457 | 435 |
458 | |
459 Dart_Handle TestCase::library_handler(Dart_LibraryTag tag, | 436 Dart_Handle TestCase::library_handler(Dart_LibraryTag tag, |
460 Dart_Handle library, | 437 Dart_Handle library, |
461 Dart_Handle url) { | 438 Dart_Handle url) { |
462 if (tag == Dart_kCanonicalizeUrl) { | 439 if (tag == Dart_kCanonicalizeUrl) { |
463 return url; | 440 return url; |
464 } | 441 } |
465 return Api::Success(); | 442 return Api::Success(); |
466 } | 443 } |
467 | 444 |
468 | |
469 char* TestCase::BigintToHexValue(Dart_CObject* bigint) { | 445 char* TestCase::BigintToHexValue(Dart_CObject* bigint) { |
470 return bin::CObject::BigintToHexValue(bigint); | 446 return bin::CObject::BigintToHexValue(bigint); |
471 } | 447 } |
472 | 448 |
473 | |
474 void AssemblerTest::Assemble() { | 449 void AssemblerTest::Assemble() { |
475 const String& function_name = | 450 const String& function_name = |
476 String::ZoneHandle(Symbols::New(Thread::Current(), name_)); | 451 String::ZoneHandle(Symbols::New(Thread::Current(), name_)); |
477 | 452 |
478 // We make a dummy script so that exception objects can be composed for | 453 // We make a dummy script so that exception objects can be composed for |
479 // assembler instructions that do runtime calls, in particular on DBC. | 454 // assembler instructions that do runtime calls, in particular on DBC. |
480 const char* kDummyScript = "assembler_test_dummy_function() {}"; | 455 const char* kDummyScript = "assembler_test_dummy_function() {}"; |
481 const Script& script = Script::Handle( | 456 const Script& script = Script::Handle( |
482 Script::New(function_name, String::Handle(String::New(kDummyScript)), | 457 Script::New(function_name, String::Handle(String::New(kDummyScript)), |
483 RawScript::kSourceTag)); | 458 RawScript::kSourceTag)); |
(...skipping 12 matching lines...) Expand all Loading... |
496 OS::Print("Code for test '%s' {\n", name_); | 471 OS::Print("Code for test '%s' {\n", name_); |
497 const Instructions& instructions = | 472 const Instructions& instructions = |
498 Instructions::Handle(code_.instructions()); | 473 Instructions::Handle(code_.instructions()); |
499 uword start = instructions.PayloadStart(); | 474 uword start = instructions.PayloadStart(); |
500 Disassembler::Disassemble(start, start + assembler_->CodeSize()); | 475 Disassembler::Disassemble(start, start + assembler_->CodeSize()); |
501 OS::Print("}\n"); | 476 OS::Print("}\n"); |
502 } | 477 } |
503 #endif // !PRODUCT | 478 #endif // !PRODUCT |
504 } | 479 } |
505 | 480 |
506 | |
507 CodeGenTest::CodeGenTest(const char* name) | 481 CodeGenTest::CodeGenTest(const char* name) |
508 : function_(Function::ZoneHandle()), | 482 : function_(Function::ZoneHandle()), |
509 node_sequence_(new SequenceNode(TokenPosition::kMinSource, | 483 node_sequence_(new SequenceNode(TokenPosition::kMinSource, |
510 new LocalScope(NULL, 0, 0))), | 484 new LocalScope(NULL, 0, 0))), |
511 default_parameter_values_(new ZoneGrowableArray<const Instance*>()) { | 485 default_parameter_values_(new ZoneGrowableArray<const Instance*>()) { |
512 ASSERT(name != NULL); | 486 ASSERT(name != NULL); |
513 const String& function_name = | 487 const String& function_name = |
514 String::ZoneHandle(Symbols::New(Thread::Current(), name)); | 488 String::ZoneHandle(Symbols::New(Thread::Current(), name)); |
515 // Add function to a class and that class to the class dictionary so that | 489 // Add function to a class and that class to the class dictionary so that |
516 // frame walking can be used. | 490 // frame walking can be used. |
517 Library& lib = Library::Handle(Library::CoreLibrary()); | 491 Library& lib = Library::Handle(Library::CoreLibrary()); |
518 const Class& cls = Class::ZoneHandle(Class::New( | 492 const Class& cls = Class::ZoneHandle(Class::New( |
519 lib, function_name, Script::Handle(), TokenPosition::kMinSource)); | 493 lib, function_name, Script::Handle(), TokenPosition::kMinSource)); |
520 function_ = | 494 function_ = |
521 Function::New(function_name, RawFunction::kRegularFunction, true, false, | 495 Function::New(function_name, RawFunction::kRegularFunction, true, false, |
522 false, false, false, cls, TokenPosition::kMinSource); | 496 false, false, false, cls, TokenPosition::kMinSource); |
523 function_.set_result_type(Type::Handle(Type::DynamicType())); | 497 function_.set_result_type(Type::Handle(Type::DynamicType())); |
524 const Array& functions = Array::Handle(Array::New(1)); | 498 const Array& functions = Array::Handle(Array::New(1)); |
525 functions.SetAt(0, function_); | 499 functions.SetAt(0, function_); |
526 cls.SetFunctions(functions); | 500 cls.SetFunctions(functions); |
527 lib.AddClass(cls); | 501 lib.AddClass(cls); |
528 } | 502 } |
529 | 503 |
530 | |
531 void CodeGenTest::Compile() { | 504 void CodeGenTest::Compile() { |
532 if (function_.HasCode()) return; | 505 if (function_.HasCode()) return; |
533 ParsedFunction* parsed_function = | 506 ParsedFunction* parsed_function = |
534 new ParsedFunction(Thread::Current(), function_); | 507 new ParsedFunction(Thread::Current(), function_); |
535 parsed_function->SetNodeSequence(node_sequence_); | 508 parsed_function->SetNodeSequence(node_sequence_); |
536 parsed_function->set_default_parameter_values(default_parameter_values_); | 509 parsed_function->set_default_parameter_values(default_parameter_values_); |
537 node_sequence_->scope()->AddVariable(parsed_function->current_context_var()); | 510 node_sequence_->scope()->AddVariable(parsed_function->current_context_var()); |
538 parsed_function->EnsureExpressionTemp(); | 511 parsed_function->EnsureExpressionTemp(); |
539 node_sequence_->scope()->AddVariable(parsed_function->expression_temp_var()); | 512 node_sequence_->scope()->AddVariable(parsed_function->expression_temp_var()); |
540 parsed_function->AllocateVariables(); | 513 parsed_function->AllocateVariables(); |
541 const Error& error = | 514 const Error& error = |
542 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); | 515 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); |
543 EXPECT(error.IsNull()); | 516 EXPECT(error.IsNull()); |
544 } | 517 } |
545 | 518 |
546 | |
547 bool CompilerTest::TestCompileScript(const Library& library, | 519 bool CompilerTest::TestCompileScript(const Library& library, |
548 const Script& script) { | 520 const Script& script) { |
549 Isolate* isolate = Isolate::Current(); | 521 Isolate* isolate = Isolate::Current(); |
550 ASSERT(isolate != NULL); | 522 ASSERT(isolate != NULL); |
551 const Error& error = Error::Handle(Compiler::Compile(library, script)); | 523 const Error& error = Error::Handle(Compiler::Compile(library, script)); |
552 if (!error.IsNull()) { | 524 if (!error.IsNull()) { |
553 OS::Print("Error compiling test script:\n%s\n", error.ToErrorCString()); | 525 OS::Print("Error compiling test script:\n%s\n", error.ToErrorCString()); |
554 } | 526 } |
555 return error.IsNull(); | 527 return error.IsNull(); |
556 } | 528 } |
557 | 529 |
558 | |
559 bool CompilerTest::TestCompileFunction(const Function& function) { | 530 bool CompilerTest::TestCompileFunction(const Function& function) { |
560 Thread* thread = Thread::Current(); | 531 Thread* thread = Thread::Current(); |
561 ASSERT(thread != NULL); | 532 ASSERT(thread != NULL); |
562 ASSERT(ClassFinalizer::AllClassesFinalized()); | 533 ASSERT(ClassFinalizer::AllClassesFinalized()); |
563 const Object& result = | 534 const Object& result = |
564 Object::Handle(Compiler::CompileFunction(thread, function)); | 535 Object::Handle(Compiler::CompileFunction(thread, function)); |
565 return result.IsCode(); | 536 return result.IsCode(); |
566 } | 537 } |
567 | 538 |
568 | |
569 void ElideJSONSubstring(const char* prefix, const char* in, char* out) { | 539 void ElideJSONSubstring(const char* prefix, const char* in, char* out) { |
570 const char* pos = strstr(in, prefix); | 540 const char* pos = strstr(in, prefix); |
571 while (pos != NULL) { | 541 while (pos != NULL) { |
572 // Copy up to pos into the output buffer. | 542 // Copy up to pos into the output buffer. |
573 while (in < pos) { | 543 while (in < pos) { |
574 *out++ = *in++; | 544 *out++ = *in++; |
575 } | 545 } |
576 | 546 |
577 // Skip to the close quote. | 547 // Skip to the close quote. |
578 in += strcspn(in, "\""); | 548 in += strcspn(in, "\""); |
579 pos = strstr(in, prefix); | 549 pos = strstr(in, prefix); |
580 } | 550 } |
581 // Copy the remainder of in to out. | 551 // Copy the remainder of in to out. |
582 while (*in != '\0') { | 552 while (*in != '\0') { |
583 *out++ = *in++; | 553 *out++ = *in++; |
584 } | 554 } |
585 *out = '\0'; | 555 *out = '\0'; |
586 } | 556 } |
587 | 557 |
588 | |
589 } // namespace dart | 558 } // namespace dart |
OLD | NEW |