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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 2948273002: Correctly set root_library based on the application script URI instead of looking for the library t… (Closed)
Patch Set: Integrate cl from Siggi for front end change to not require a 'main' method when using the memory f… Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "lib/stacktrace.h" 9 #include "lib/stacktrace.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "vm/version.h" 55 #include "vm/version.h"
56 56
57 namespace dart { 57 namespace dart {
58 58
59 // Facilitate quick access to the current zone once we have the current thread. 59 // Facilitate quick access to the current zone once we have the current thread.
60 #define Z (T->zone()) 60 #define Z (T->zone())
61 61
62 DECLARE_FLAG(bool, use_dart_frontend); 62 DECLARE_FLAG(bool, use_dart_frontend);
63 DECLARE_FLAG(bool, print_class_table); 63 DECLARE_FLAG(bool, print_class_table);
64 DECLARE_FLAG(bool, verify_handles); 64 DECLARE_FLAG(bool, verify_handles);
65 DECLARE_FLAG(bool, use_dart_frontend);
65 #if defined(DART_NO_SNAPSHOT) 66 #if defined(DART_NO_SNAPSHOT)
66 DEFINE_FLAG(bool, 67 DEFINE_FLAG(bool,
67 check_function_fingerprints, 68 check_function_fingerprints,
68 true, 69 true,
69 "Check function fingerprints"); 70 "Check function fingerprints");
70 #endif // defined(DART_NO_SNAPSHOT). 71 #endif // defined(DART_NO_SNAPSHOT).
71 DEFINE_FLAG(bool, 72 DEFINE_FLAG(bool,
72 verify_acquired_data, 73 verify_acquired_data,
73 false, 74 false,
74 "Verify correct API acquire/release of typed data."); 75 "Verify correct API acquire/release of typed data.");
(...skipping 4924 matching lines...) Expand 10 before | Expand all | Expand 10 after
4999 if (error.IsNull()) { 5000 if (error.IsNull()) {
5000 *result = Api::NewHandle(thread, lib.raw()); 5001 *result = Api::NewHandle(thread, lib.raw());
5001 } else { 5002 } else {
5002 *result = Api::NewHandle(thread, error.raw()); 5003 *result = Api::NewHandle(thread, error.raw());
5003 // Compilation errors are not Dart instances, so just mark the library 5004 // Compilation errors are not Dart instances, so just mark the library
5004 // as having failed to load without providing an error instance. 5005 // as having failed to load without providing an error instance.
5005 lib.SetLoadError(Object::null_instance()); 5006 lib.SetLoadError(Object::null_instance());
5006 } 5007 }
5007 } 5008 }
5008 5009
5010 #if !defined(DART_PRECOMPILED_RUNTIME)
5011 static Dart_Handle LoadKernelProgram(Thread* T,
5012 const String& url,
5013 void* kernel) {
5014 // NOTE: Now the VM owns the [kernel_program] memory! Currently we do not
5015 // free it because (similar to the token stream) it will be used to repeatedly
5016 // run the `kernel::FlowGraphBuilder()`.
5017 kernel::KernelReader reader(reinterpret_cast<kernel::Program*>(kernel));
5018 const Object& tmp = reader.ReadProgram();
5019 if (tmp.IsError()) {
5020 return Api::NewHandle(T, tmp.raw());
5021 }
5022 return Dart_Null();
5023 }
5024 #endif
5025
5009 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 5026 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
5010 Dart_Handle resolved_url, 5027 Dart_Handle resolved_url,
5011 Dart_Handle source, 5028 Dart_Handle source,
5012 intptr_t line_offset, 5029 intptr_t line_offset,
5013 intptr_t column_offset) { 5030 intptr_t column_offset) {
5014 API_TIMELINE_DURATION; 5031 API_TIMELINE_DURATION;
5015 DARTSCOPE(Thread::Current()); 5032 DARTSCOPE(Thread::Current());
5016 Isolate* I = T->isolate(); 5033 Isolate* I = T->isolate();
5017 const String& url_str = Api::UnwrapStringHandle(Z, url); 5034 const String& url_str = Api::UnwrapStringHandle(Z, url);
5018 if (url_str.IsNull()) { 5035 if (url_str.IsNull()) {
5019 RETURN_TYPE_ERROR(Z, url, String); 5036 RETURN_TYPE_ERROR(Z, url, String);
5020 } 5037 }
5021 if (::Dart_IsNull(resolved_url)) { 5038 if (::Dart_IsNull(resolved_url)) {
5022 resolved_url = url; 5039 resolved_url = url;
5023 } 5040 }
5024 const String& resolved_url_str = Api::UnwrapStringHandle(Z, resolved_url); 5041 const String& resolved_url_str = Api::UnwrapStringHandle(Z, resolved_url);
5025 if (resolved_url_str.IsNull()) { 5042 if (resolved_url_str.IsNull()) {
5026 RETURN_TYPE_ERROR(Z, resolved_url, String); 5043 RETURN_TYPE_ERROR(Z, resolved_url, String);
5027 } 5044 }
5028 const String& source_str = Api::UnwrapStringHandle(Z, source);
5029 if (source_str.IsNull()) {
5030 RETURN_TYPE_ERROR(Z, source, String);
5031 }
5032 Library& library = Library::Handle(Z, I->object_store()->root_library()); 5045 Library& library = Library::Handle(Z, I->object_store()->root_library());
5033 if (!library.IsNull()) { 5046 if (!library.IsNull()) {
5034 const String& library_url = String::Handle(Z, library.url()); 5047 const String& library_url = String::Handle(Z, library.url());
5035 return Api::NewError("%s: A script has already been loaded from '%s'.", 5048 return Api::NewError("%s: A script has already been loaded from '%s'.",
5036 CURRENT_FUNC, library_url.ToCString()); 5049 CURRENT_FUNC, library_url.ToCString());
5037 } 5050 }
5038 if (line_offset < 0) { 5051 if (line_offset < 0) {
5039 return Api::NewError("%s: argument 'line_offset' must be positive number", 5052 return Api::NewError("%s: argument 'line_offset' must be positive number",
5040 CURRENT_FUNC); 5053 CURRENT_FUNC);
5041 } 5054 }
5042 if (column_offset < 0) { 5055 if (column_offset < 0) {
5043 return Api::NewError("%s: argument 'column_offset' must be positive number", 5056 return Api::NewError("%s: argument 'column_offset' must be positive number",
5044 CURRENT_FUNC); 5057 CURRENT_FUNC);
5045 } 5058 }
5046 CHECK_CALLBACK_STATE(T); 5059 CHECK_CALLBACK_STATE(T);
5047 CHECK_COMPILATION_ALLOWED(I); 5060 CHECK_COMPILATION_ALLOWED(I);
5048 5061
5062 Dart_Handle result;
5063 #if !defined(DART_PRECOMPILED_RUNTIME)
5064 if (FLAG_use_dart_frontend && !KernelIsolate::IsKernelIsolate(I)) {
5065 if ((source == Api::Null()) || (source == NULL)) {
5066 RETURN_NULL_ERROR(source);
5067 }
5068 void* kernel_pgm = reinterpret_cast<void*>(source);
5069 result = LoadKernelProgram(T, resolved_url_str, kernel_pgm);
5070 if (Dart_IsError(result)) {
5071 return result;
5072 }
5073 library ^= Library::LookupLibrary(T, resolved_url_str);
5074 if (library.IsNull()) {
5075 return Api::NewError("%s: Unable to load script '%s' correctly.",
5076 CURRENT_FUNC, resolved_url_str.ToCString());
5077 }
5078 I->object_store()->set_root_library(library);
5079 return Api::NewHandle(T, library.raw());
5080 }
5081 #endif
5082
5083 const String& source_str = Api::UnwrapStringHandle(Z, source);
5084 if (source_str.IsNull()) {
5085 RETURN_TYPE_ERROR(Z, source, String);
5086 }
5087
5049 NoHeapGrowthControlScope no_growth_control; 5088 NoHeapGrowthControlScope no_growth_control;
5050 5089
5051 library = Library::New(url_str); 5090 library = Library::New(url_str);
5052 library.set_debuggable(true); 5091 library.set_debuggable(true);
5053 library.Register(T); 5092 library.Register(T);
5054 I->object_store()->set_root_library(library); 5093 I->object_store()->set_root_library(library);
5055 5094
5056 const Script& script = 5095 const Script& script =
5057 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, 5096 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str,
5058 RawScript::kScriptTag)); 5097 RawScript::kScriptTag));
5059 script.SetLocationOffset(line_offset, column_offset); 5098 script.SetLocationOffset(line_offset, column_offset);
5060 Dart_Handle result;
5061 CompileSource(T, library, script, &result); 5099 CompileSource(T, library, script, &result);
5062 return result; 5100 return result;
5063 } 5101 }
5064 5102
5065 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, 5103 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
5066 intptr_t buffer_len) { 5104 intptr_t buffer_len) {
5067 API_TIMELINE_DURATION; 5105 API_TIMELINE_DURATION;
5068 DARTSCOPE(Thread::Current()); 5106 DARTSCOPE(Thread::Current());
5069 Isolate* I = T->isolate(); 5107 Isolate* I = T->isolate();
5070 StackZone zone(T); 5108 StackZone zone(T);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
5355 I->object_store()->pending_deferred_loads()); 5393 I->object_store()->pending_deferred_loads());
5356 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { 5394 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) {
5357 if (pending_deferred_loads.At(i) == lib.raw()) { 5395 if (pending_deferred_loads.At(i) == lib.raw()) {
5358 lib.SetLoadError(err); 5396 lib.SetLoadError(err);
5359 return Api::Null(); 5397 return Api::Null();
5360 } 5398 }
5361 } 5399 }
5362 return error_in; 5400 return error_in;
5363 } 5401 }
5364 5402
5365 #if !defined(DART_PRECOMPILED_RUNTIME)
5366 static Dart_Handle LoadKernelProgram(Dart_Handle url, Thread* T, void* kernel) {
5367 kernel::KernelReader reader(reinterpret_cast<kernel::Program*>(kernel));
5368 const Object& tmp = reader.ReadProgram();
5369 if (tmp.IsError()) {
5370 return Api::NewHandle(T, tmp.raw());
5371 }
5372
5373 const String& url_str = Api::UnwrapStringHandle(Z, url);
5374 Library& library =
5375 Library::Handle(T->zone(), Library::LookupLibrary(T, url_str));
5376 return Api::NewHandle(T, library.raw());
5377 }
5378 #endif
5379
5380 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 5403 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
5381 Dart_Handle resolved_url, 5404 Dart_Handle resolved_url,
5382 Dart_Handle source, 5405 Dart_Handle source,
5383 intptr_t line_offset, 5406 intptr_t line_offset,
5384 intptr_t column_offset) { 5407 intptr_t column_offset) {
5385 API_TIMELINE_DURATION; 5408 API_TIMELINE_DURATION;
5386 DARTSCOPE(Thread::Current()); 5409 DARTSCOPE(Thread::Current());
5387 Isolate* I = T->isolate(); 5410 Isolate* I = T->isolate();
5388 5411
5412 const String& url_str = Api::UnwrapStringHandle(Z, url);
5413 if (url_str.IsNull()) {
5414 RETURN_TYPE_ERROR(Z, url, String);
5415 }
5416 Dart_Handle result;
5389 #if !defined(DART_PRECOMPILED_RUNTIME) 5417 #if !defined(DART_PRECOMPILED_RUNTIME)
5390 // Kernel isolate is loaded from script in case of dart_bootstrap 5418 // Kernel isolate is loaded from script in case of dart_bootstrap
5391 // even when FLAG_use_dart_frontend is true. Hence, do not interpret 5419 // even when FLAG_use_dart_frontend is true. Hence, do not interpret
5392 // |source| as a kernel if the current isolate is the kernel isolate. 5420 // |source| as a kernel if the current isolate is the kernel isolate.
5393 if (FLAG_use_dart_frontend && !KernelIsolate::IsKernelIsolate(I)) { 5421 if (FLAG_use_dart_frontend && !KernelIsolate::IsKernelIsolate(I)) {
5394 return LoadKernelProgram(url, T, reinterpret_cast<void*>(source)); 5422 result = LoadKernelProgram(T, url_str, reinterpret_cast<void*>(source));
5423 if (Dart_IsError(result)) {
5424 return result;
5425 }
5426 return Api::NewHandle(T, Library::LookupLibrary(T, url_str));
5395 } 5427 }
5396 #endif 5428 #endif
5397
5398 const String& url_str = Api::UnwrapStringHandle(Z, url);
5399 if (url_str.IsNull()) {
5400 RETURN_TYPE_ERROR(Z, url, String);
5401 }
5402 if (::Dart_IsNull(resolved_url)) { 5429 if (::Dart_IsNull(resolved_url)) {
5403 resolved_url = url; 5430 resolved_url = url;
5404 } 5431 }
5405 const String& resolved_url_str = Api::UnwrapStringHandle(Z, resolved_url); 5432 const String& resolved_url_str = Api::UnwrapStringHandle(Z, resolved_url);
5406 if (resolved_url_str.IsNull()) { 5433 if (resolved_url_str.IsNull()) {
5407 RETURN_TYPE_ERROR(Z, resolved_url, String); 5434 RETURN_TYPE_ERROR(Z, resolved_url, String);
5408 } 5435 }
5409 const String& source_str = Api::UnwrapStringHandle(Z, source); 5436 const String& source_str = Api::UnwrapStringHandle(Z, source);
5410 if (source_str.IsNull()) { 5437 if (source_str.IsNull()) {
5411 RETURN_TYPE_ERROR(Z, source, String); 5438 RETURN_TYPE_ERROR(Z, source, String);
(...skipping 19 matching lines...) Expand all
5431 library.LoadFailed()) { 5458 library.LoadFailed()) {
5432 // The source for this library has either been loaded or is in the 5459 // The source for this library has either been loaded or is in the
5433 // process of loading. Return an error. 5460 // process of loading. Return an error.
5434 return Api::NewError("%s: library '%s' has already been loaded.", 5461 return Api::NewError("%s: library '%s' has already been loaded.",
5435 CURRENT_FUNC, url_str.ToCString()); 5462 CURRENT_FUNC, url_str.ToCString());
5436 } 5463 }
5437 const Script& script = 5464 const Script& script =
5438 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, 5465 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str,
5439 RawScript::kLibraryTag)); 5466 RawScript::kLibraryTag));
5440 script.SetLocationOffset(line_offset, column_offset); 5467 script.SetLocationOffset(line_offset, column_offset);
5441 Dart_Handle result;
5442 CompileSource(T, library, script, &result); 5468 CompileSource(T, library, script, &result);
5443 // Propagate the error out right now. 5469 // Propagate the error out right now.
5444 if (::Dart_IsError(result)) { 5470 if (::Dart_IsError(result)) {
5445 return result; 5471 return result;
5446 } 5472 }
5447 5473
5448 // If this is the dart:_builtin library, register it with the VM. 5474 // If this is the dart:_builtin library, register it with the VM.
5449 if (url_str.Equals("dart:_builtin")) { 5475 if (url_str.Equals("dart:_builtin")) {
5450 I->object_store()->set_builtin_library(library); 5476 I->object_store()->set_builtin_library(library);
5451 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); 5477 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
6670 #endif 6696 #endif
6671 } 6697 }
6672 6698
6673 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { 6699 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) {
6674 #ifndef PRODUCT 6700 #ifndef PRODUCT
6675 Profiler::DumpStackTrace(context); 6701 Profiler::DumpStackTrace(context);
6676 #endif 6702 #endif
6677 } 6703 }
6678 6704
6679 } // namespace dart 6705 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698