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

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

Issue 10867032: Beginning support for library prefixes in the dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comment. Created 8 years, 3 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
OLDNEW
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 2616 matching lines...) Expand 10 before | Expand all | Expand 10 after
2627 2627
2628 // Case 2. Lookup the function without the external setter suffix 2628 // Case 2. Lookup the function without the external setter suffix
2629 // '='. Make sure to do this check after the regular lookup, so 2629 // '='. Make sure to do this check after the regular lookup, so
2630 // that we don't interfere with operator lookups (like ==). 2630 // that we don't interfere with operator lookups (like ==).
2631 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { 2631 if (func.IsNull() && HasExternalSetterSuffix(func_name)) {
2632 tmp_name = RemoveExternalSetterSuffix(func_name); 2632 tmp_name = RemoveExternalSetterSuffix(func_name);
2633 tmp_name = Field::SetterName(tmp_name); 2633 tmp_name = Field::SetterName(tmp_name);
2634 func = lib.LookupFunctionAllowPrivate(tmp_name); 2634 func = lib.LookupFunctionAllowPrivate(tmp_name);
2635 } 2635 }
2636 2636
2637 // Case 3. Lookup the funciton with the getter prefix prepended. 2637 // Case 3. Lookup the function with the getter prefix prepended.
2638 if (func.IsNull()) { 2638 if (func.IsNull()) {
2639 tmp_name = Field::GetterName(func_name); 2639 tmp_name = Field::GetterName(func_name);
2640 func = lib.LookupFunctionAllowPrivate(tmp_name); 2640 func = lib.LookupFunctionAllowPrivate(tmp_name);
2641 } 2641 }
2642 } else { 2642 } else {
2643 return Api::NewError( 2643 return Api::NewError(
2644 "%s expects argument 'target' to be a class or library.", 2644 "%s expects argument 'target' to be a class or library.",
2645 CURRENT_FUNC); 2645 CURRENT_FUNC);
2646 } 2646 }
2647 2647
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
4027 const char* msg = CheckIsolateState(isolate); 4027 const char* msg = CheckIsolateState(isolate);
4028 if (msg != NULL) { 4028 if (msg != NULL) {
4029 return Api::NewError(msg); 4029 return Api::NewError(msg);
4030 } 4030 }
4031 } 4031 }
4032 return result; 4032 return result;
4033 } 4033 }
4034 4034
4035 4035
4036 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, 4036 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
4037 Dart_Handle import) { 4037 Dart_Handle import,
4038 Dart_Handle prefix) {
4038 Isolate* isolate = Isolate::Current(); 4039 Isolate* isolate = Isolate::Current();
4039 DARTSCOPE(isolate); 4040 DARTSCOPE(isolate);
4040 const Library& library_vm = Api::UnwrapLibraryHandle(isolate, library); 4041 const Library& library_vm = Api::UnwrapLibraryHandle(isolate, library);
4041 if (library_vm.IsNull()) { 4042 if (library_vm.IsNull()) {
4042 RETURN_TYPE_ERROR(isolate, library, Library); 4043 RETURN_TYPE_ERROR(isolate, library, Library);
4043 } 4044 }
4044 const Library& import_vm = Api::UnwrapLibraryHandle(isolate, import); 4045 const Library& import_vm = Api::UnwrapLibraryHandle(isolate, import);
4045 if (import_vm.IsNull()) { 4046 if (import_vm.IsNull()) {
4046 RETURN_TYPE_ERROR(isolate, import, Library); 4047 RETURN_TYPE_ERROR(isolate, import, Library);
4047 } 4048 }
4048 library_vm.AddImport(import_vm); 4049 const String& prefix_vm = Api::UnwrapStringHandle(isolate, prefix);
4050 if (prefix_vm.IsNull()) {
4051 RETURN_TYPE_ERROR(isolate, prefix, String);
4052 }
4053 const String& prefix_symbol =
4054 String::Handle(isolate, Symbols::New(prefix_vm));
4055 if (prefix_vm.Length() == 0) {
4056 library_vm.AddImport(import_vm);
4057 } else {
4058 LibraryPrefix& library_prefix = LibraryPrefix::Handle();
4059 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol);
4060 if (!library_prefix.IsNull()) {
4061 library_prefix.AddLibrary(import_vm);
4062 } else {
4063 library_prefix = LibraryPrefix::New(prefix_symbol, import_vm);
4064 library_vm.AddObject(library_prefix, prefix_symbol);
4065 }
4066 }
4049 return Api::Success(isolate); 4067 return Api::Success(isolate);
4050 } 4068 }
4051 4069
4052 4070
4053 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, 4071 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
4054 Dart_Handle url, 4072 Dart_Handle url,
4055 Dart_Handle source) { 4073 Dart_Handle source) {
4056 TIMERSCOPE(time_script_loading); 4074 TIMERSCOPE(time_script_loading);
4057 Isolate* isolate = Isolate::Current(); 4075 Isolate* isolate = Isolate::Current();
4058 DARTSCOPE(isolate); 4076 DARTSCOPE(isolate);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4146 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4129 Dart::set_perf_events_writer(function); 4147 Dart::set_perf_events_writer(function);
4130 } 4148 }
4131 4149
4132 4150
4133 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4151 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4134 Dart::set_flow_graph_writer(function); 4152 Dart::set_flow_graph_writer(function);
4135 } 4153 }
4136 4154
4137 } // namespace dart 4155 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698