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

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

Issue 429013002: Make Dart_LoadLibrary and Dart_LoadSource take line and column offsets like Dart_LoadScript. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « runtime/include/dart_api.h ('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 "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 4785 matching lines...) Expand 10 before | Expand all | Expand 10 after
4796 // Compilation errors are not Dart instances, so just mark the library 4796 // Compilation errors are not Dart instances, so just mark the library
4797 // as having failed to load without providing an error instance. 4797 // as having failed to load without providing an error instance.
4798 lib.SetLoadError(Instance::Handle()); 4798 lib.SetLoadError(Instance::Handle());
4799 } 4799 }
4800 } 4800 }
4801 4801
4802 4802
4803 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 4803 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
4804 Dart_Handle source, 4804 Dart_Handle source,
4805 intptr_t line_offset, 4805 intptr_t line_offset,
4806 intptr_t col_offset) { 4806 intptr_t column_offset) {
4807 Isolate* isolate = Isolate::Current(); 4807 Isolate* isolate = Isolate::Current();
4808 DARTSCOPE(isolate); 4808 DARTSCOPE(isolate);
4809 TIMERSCOPE(isolate, time_script_loading); 4809 TIMERSCOPE(isolate, time_script_loading);
4810 const String& url_str = Api::UnwrapStringHandle(isolate, url); 4810 const String& url_str = Api::UnwrapStringHandle(isolate, url);
4811 if (url_str.IsNull()) { 4811 if (url_str.IsNull()) {
4812 RETURN_TYPE_ERROR(isolate, url, String); 4812 RETURN_TYPE_ERROR(isolate, url, String);
4813 } 4813 }
4814 const String& source_str = Api::UnwrapStringHandle(isolate, source); 4814 const String& source_str = Api::UnwrapStringHandle(isolate, source);
4815 if (source_str.IsNull()) { 4815 if (source_str.IsNull()) {
4816 RETURN_TYPE_ERROR(isolate, source, String); 4816 RETURN_TYPE_ERROR(isolate, source, String);
4817 } 4817 }
4818 Library& library = 4818 Library& library =
4819 Library::Handle(isolate, isolate->object_store()->root_library()); 4819 Library::Handle(isolate, isolate->object_store()->root_library());
4820 if (!library.IsNull()) { 4820 if (!library.IsNull()) {
4821 const String& library_url = String::Handle(isolate, library.url()); 4821 const String& library_url = String::Handle(isolate, library.url());
4822 return Api::NewError("%s: A script has already been loaded from '%s'.", 4822 return Api::NewError("%s: A script has already been loaded from '%s'.",
4823 CURRENT_FUNC, library_url.ToCString()); 4823 CURRENT_FUNC, library_url.ToCString());
4824 } 4824 }
4825 if (line_offset < 0) { 4825 if (line_offset < 0) {
4826 return Api::NewError("%s: argument 'line_offset' must be positive number", 4826 return Api::NewError("%s: argument 'line_offset' must be positive number",
4827 CURRENT_FUNC); 4827 CURRENT_FUNC);
4828 } 4828 }
4829 if (col_offset < 0) { 4829 if (column_offset < 0) {
4830 return Api::NewError("%s: argument 'col_offset' must be positive number", 4830 return Api::NewError("%s: argument 'column_offset' must be positive number",
4831 CURRENT_FUNC); 4831 CURRENT_FUNC);
4832 } 4832 }
4833 CHECK_CALLBACK_STATE(isolate); 4833 CHECK_CALLBACK_STATE(isolate);
4834 4834
4835 NoHeapGrowthControlScope no_growth_control; 4835 NoHeapGrowthControlScope no_growth_control;
4836 4836
4837 library = Library::New(url_str); 4837 library = Library::New(url_str);
4838 library.set_debuggable(true); 4838 library.set_debuggable(true);
4839 library.Register(); 4839 library.Register();
4840 isolate->object_store()->set_root_library(library); 4840 isolate->object_store()->set_root_library(library);
4841 4841
4842 const Script& script = Script::Handle( 4842 const Script& script = Script::Handle(
4843 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); 4843 isolate, Script::New(url_str, source_str, RawScript::kScriptTag));
4844 script.SetLocationOffset(line_offset, col_offset); 4844 script.SetLocationOffset(line_offset, column_offset);
4845 Dart_Handle result; 4845 Dart_Handle result;
4846 CompileSource(isolate, library, script, &result); 4846 CompileSource(isolate, library, script, &result);
4847 return result; 4847 return result;
4848 } 4848 }
4849 4849
4850 4850
4851 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, 4851 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
4852 intptr_t buffer_len) { 4852 intptr_t buffer_len) {
4853 Isolate* isolate = Isolate::Current(); 4853 Isolate* isolate = Isolate::Current();
4854 DARTSCOPE(isolate); 4854 DARTSCOPE(isolate);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
5052 if (pending_deferred_loads.At(i) == lib.raw()) { 5052 if (pending_deferred_loads.At(i) == lib.raw()) {
5053 lib.SetLoadError(err); 5053 lib.SetLoadError(err);
5054 return Api::Null(); 5054 return Api::Null();
5055 } 5055 }
5056 } 5056 }
5057 return error_in; 5057 return error_in;
5058 } 5058 }
5059 5059
5060 5060
5061 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 5061 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
5062 Dart_Handle source) { 5062 Dart_Handle source,
5063 intptr_t line_offset,
5064 intptr_t column_offset) {
5063 Isolate* isolate = Isolate::Current(); 5065 Isolate* isolate = Isolate::Current();
5064 DARTSCOPE(isolate); 5066 DARTSCOPE(isolate);
5065 TIMERSCOPE(isolate, time_script_loading); 5067 TIMERSCOPE(isolate, time_script_loading);
5066 const String& url_str = Api::UnwrapStringHandle(isolate, url); 5068 const String& url_str = Api::UnwrapStringHandle(isolate, url);
5067 if (url_str.IsNull()) { 5069 if (url_str.IsNull()) {
5068 RETURN_TYPE_ERROR(isolate, url, String); 5070 RETURN_TYPE_ERROR(isolate, url, String);
5069 } 5071 }
5070 const String& source_str = Api::UnwrapStringHandle(isolate, source); 5072 const String& source_str = Api::UnwrapStringHandle(isolate, source);
5071 if (source_str.IsNull()) { 5073 if (source_str.IsNull()) {
5072 RETURN_TYPE_ERROR(isolate, source, String); 5074 RETURN_TYPE_ERROR(isolate, source, String);
5073 } 5075 }
5076 if (line_offset < 0) {
5077 return Api::NewError("%s: argument 'line_offset' must be positive number",
5078 CURRENT_FUNC);
5079 }
5080 if (column_offset < 0) {
5081 return Api::NewError("%s: argument 'column_offset' must be positive number",
5082 CURRENT_FUNC);
5083 }
5074 CHECK_CALLBACK_STATE(isolate); 5084 CHECK_CALLBACK_STATE(isolate);
5075 5085
5076 NoHeapGrowthControlScope no_growth_control; 5086 NoHeapGrowthControlScope no_growth_control;
5077 5087
5078 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); 5088 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str));
5079 if (library.IsNull()) { 5089 if (library.IsNull()) {
5080 library = Library::New(url_str); 5090 library = Library::New(url_str);
5081 library.Register(); 5091 library.Register();
5082 } else if (library.LoadInProgress() || 5092 } else if (library.LoadInProgress() ||
5083 library.Loaded() || 5093 library.Loaded() ||
5084 library.LoadFailed()) { 5094 library.LoadFailed()) {
5085 // The source for this library has either been loaded or is in the 5095 // The source for this library has either been loaded or is in the
5086 // process of loading. Return an error. 5096 // process of loading. Return an error.
5087 return Api::NewError("%s: library '%s' has already been loaded.", 5097 return Api::NewError("%s: library '%s' has already been loaded.",
5088 CURRENT_FUNC, url_str.ToCString()); 5098 CURRENT_FUNC, url_str.ToCString());
5089 } 5099 }
5090 const Script& script = Script::Handle( 5100 const Script& script = Script::Handle(
5091 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); 5101 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag));
5102 script.SetLocationOffset(line_offset, column_offset);
5092 Dart_Handle result; 5103 Dart_Handle result;
5093 CompileSource(isolate, library, script, &result); 5104 CompileSource(isolate, library, script, &result);
5094 // Propagate the error out right now. 5105 // Propagate the error out right now.
5095 if (::Dart_IsError(result)) { 5106 if (::Dart_IsError(result)) {
5096 return result; 5107 return result;
5097 } 5108 }
5098 5109
5099 // If this is the dart:_builtin library, register it with the VM. 5110 // If this is the dart:_builtin library, register it with the VM.
5100 if (url_str.Equals("dart:_builtin")) { 5111 if (url_str.Equals("dart:_builtin")) {
5101 isolate->object_store()->set_builtin_library(library); 5112 isolate->object_store()->set_builtin_library(library);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5147 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); 5158 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm);
5148 library_vm.AddObject(library_prefix, prefix_symbol); 5159 library_vm.AddObject(library_prefix, prefix_symbol);
5149 } 5160 }
5150 } 5161 }
5151 return Api::Success(); 5162 return Api::Success();
5152 } 5163 }
5153 5164
5154 5165
5155 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, 5166 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
5156 Dart_Handle url, 5167 Dart_Handle url,
5157 Dart_Handle source) { 5168 Dart_Handle source,
5169 intptr_t line_offset,
5170 intptr_t column_offset) {
5158 Isolate* isolate = Isolate::Current(); 5171 Isolate* isolate = Isolate::Current();
5159 DARTSCOPE(isolate); 5172 DARTSCOPE(isolate);
5160 TIMERSCOPE(isolate, time_script_loading); 5173 TIMERSCOPE(isolate, time_script_loading);
5161 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); 5174 const Library& lib = Api::UnwrapLibraryHandle(isolate, library);
5162 if (lib.IsNull()) { 5175 if (lib.IsNull()) {
5163 RETURN_TYPE_ERROR(isolate, library, Library); 5176 RETURN_TYPE_ERROR(isolate, library, Library);
5164 } 5177 }
5165 const String& url_str = Api::UnwrapStringHandle(isolate, url); 5178 const String& url_str = Api::UnwrapStringHandle(isolate, url);
5166 if (url_str.IsNull()) { 5179 if (url_str.IsNull()) {
5167 RETURN_TYPE_ERROR(isolate, url, String); 5180 RETURN_TYPE_ERROR(isolate, url, String);
5168 } 5181 }
5169 const String& source_str = Api::UnwrapStringHandle(isolate, source); 5182 const String& source_str = Api::UnwrapStringHandle(isolate, source);
5170 if (source_str.IsNull()) { 5183 if (source_str.IsNull()) {
5171 RETURN_TYPE_ERROR(isolate, source, String); 5184 RETURN_TYPE_ERROR(isolate, source, String);
5172 } 5185 }
5186 if (line_offset < 0) {
5187 return Api::NewError("%s: argument 'line_offset' must be positive number",
5188 CURRENT_FUNC);
5189 }
5190 if (column_offset < 0) {
5191 return Api::NewError("%s: argument 'column_offset' must be positive number",
5192 CURRENT_FUNC);
5193 }
5173 CHECK_CALLBACK_STATE(isolate); 5194 CHECK_CALLBACK_STATE(isolate);
5174 5195
5175 NoHeapGrowthControlScope no_growth_control; 5196 NoHeapGrowthControlScope no_growth_control;
5176 5197
5177 const Script& script = Script::Handle( 5198 const Script& script = Script::Handle(
5178 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); 5199 isolate, Script::New(url_str, source_str, RawScript::kSourceTag));
5200 script.SetLocationOffset(line_offset, column_offset);
5179 Dart_Handle result; 5201 Dart_Handle result;
5180 CompileSource(isolate, lib, script, &result); 5202 CompileSource(isolate, lib, script, &result);
5181 return result; 5203 return result;
5182 } 5204 }
5183 5205
5184 5206
5185 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, 5207 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library,
5186 Dart_Handle url, 5208 Dart_Handle url,
5187 Dart_Handle patch_source) { 5209 Dart_Handle patch_source) {
5188 Isolate* isolate = Isolate::Current(); 5210 Isolate* isolate = Isolate::Current();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
5333 5355
5334 5356
5335 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5357 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5336 const char* name, 5358 const char* name,
5337 Dart_ServiceRequestCallback callback, 5359 Dart_ServiceRequestCallback callback,
5338 void* user_data) { 5360 void* user_data) {
5339 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5361 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5340 } 5362 }
5341 5363
5342 } // namespace dart 5364 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698