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

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

Issue 1640853004: Support 'dart.library.X' env variables in the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebase and fix typo. Created 4 years, 9 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/vm/dart_api_impl.h ('k') | runtime/vm/parser.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 "lib/stacktrace.h" 10 #include "lib/stacktrace.h"
(...skipping 4946 matching lines...) Expand 10 before | Expand all | Expand 10 after
4957 Isolate* isolate = arguments->thread()->isolate(); 4957 Isolate* isolate = arguments->thread()->isolate();
4958 ASSERT(isolate == Isolate::Current()); 4958 ASSERT(isolate == Isolate::Current());
4959 ASSERT(isolate->api_state() != NULL && 4959 ASSERT(isolate->api_state() != NULL &&
4960 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); 4960 (isolate->api_state()->IsValidWeakPersistentHandle(rval)));
4961 #endif 4961 #endif
4962 Api::SetWeakHandleReturnValue(arguments, rval); 4962 Api::SetWeakHandleReturnValue(arguments, rval);
4963 } 4963 }
4964 4964
4965 4965
4966 // --- Environment --- 4966 // --- Environment ---
4967 RawString* Api::GetEnvironmentValue(Thread* thread, const String& name) {
4968 String& result = String::Handle(CallEnvironmentCallback(thread, name));
4969 if (result.IsNull()) {
4970 // Every 'dart:X' library introduces an environment variable
4971 // 'dart.library.X' that is set to 'true'.
4972 // We just need to make sure to hide private libraries (starting with
4973 // "_", and the mirrors library, if it is not supported.
4974
4975 if (!FLAG_enable_mirrors && name.Equals(Symbols::DartLibraryMirrors())) {
4976 return Symbols::False().raw();
4977 }
4978
4979 const String& prefix = Symbols::DartLibrary();
4980 if (name.StartsWith(prefix)) {
4981 const String& library_name =
4982 String::Handle(String::SubString(name, prefix.Length()));
4983
4984 // Private libraries (starting with "_") are not exposed to the user.
4985 if (!library_name.IsNull() && library_name.CharAt(0) != '_') {
4986 const String& dart_library_name =
4987 String::Handle(String::Concat(Symbols::DartScheme(), library_name));
4988 const Library& library =
4989 Library::Handle(Library::LookupLibrary(dart_library_name));
4990 if (!library.IsNull()) {
4991 return Symbols::True().raw();
4992 }
4993 }
4994 }
4995 // Check for default VM provided values. If it was not overriden on the
4996 // command line.
4997 if (Symbols::DartIsVM().Equals(name)) {
4998 return Symbols::True().raw();
4999 }
5000 }
5001 return result.raw();
5002 }
5003
5004
4967 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { 5005 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) {
4968 Isolate* isolate = thread->isolate(); 5006 Isolate* isolate = thread->isolate();
4969 Dart_EnvironmentCallback callback = isolate->environment_callback(); 5007 Dart_EnvironmentCallback callback = isolate->environment_callback();
4970 String& result = String::Handle(thread->zone()); 5008 String& result = String::Handle(thread->zone());
4971 if (callback != NULL) { 5009 if (callback != NULL) {
4972 TransitionVMToNative transition(thread); 5010 TransitionVMToNative transition(thread);
4973 Scope api_scope(thread); 5011 Scope api_scope(thread);
4974 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); 5012 Dart_Handle response = callback(Api::NewHandle(thread, name.raw()));
4975 if (::Dart_IsString(response)) { 5013 if (::Dart_IsString(response)) {
4976 result ^= Api::UnwrapHandle(response); 5014 result ^= Api::UnwrapHandle(response);
4977 } else if (::Dart_IsError(response)) { 5015 } else if (::Dart_IsError(response)) {
4978 const Object& error = Object::Handle( 5016 const Object& error = Object::Handle(
4979 thread->zone(), Api::UnwrapHandle(response)); 5017 thread->zone(), Api::UnwrapHandle(response));
4980 Exceptions::ThrowArgumentError( 5018 Exceptions::ThrowArgumentError(
4981 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); 5019 String::Handle(String::New(Error::Cast(error).ToErrorCString())));
4982 } else if (!::Dart_IsNull(response)) { 5020 } else if (!::Dart_IsNull(response)) {
4983 // At this point everything except null are invalid environment values. 5021 // At this point everything except null are invalid environment values.
4984 Exceptions::ThrowArgumentError( 5022 Exceptions::ThrowArgumentError(
4985 String::Handle(String::New("Illegal environment value"))); 5023 String::Handle(String::New("Illegal environment value")));
4986 } 5024 }
4987 } 5025 }
4988 if (result.IsNull()) {
4989 // TODO(iposva): Determine whether builtin values can be overriden by the
4990 // embedder.
4991 // Check for default VM provided values. If it was not overriden on the
4992 // command line.
4993 if (Symbols::DartIsVM().Equals(name)) {
4994 return Symbols::True().raw();
4995 }
4996 }
4997 return result.raw(); 5026 return result.raw();
4998 } 5027 }
4999 5028
5000 5029
5001 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( 5030 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback(
5002 Dart_EnvironmentCallback callback) { 5031 Dart_EnvironmentCallback callback) {
5003 Isolate* isolate = Isolate::Current(); 5032 Isolate* isolate = Isolate::Current();
5004 CHECK_ISOLATE(isolate); 5033 CHECK_ISOLATE(isolate);
5005 isolate->set_environment_callback(callback); 5034 isolate->set_environment_callback(callback);
5006 return Api::Success(); 5035 return Api::Success();
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
6165 return Api::Success(); 6194 return Api::Success();
6166 } 6195 }
6167 #endif // DART_PRECOMPILER 6196 #endif // DART_PRECOMPILER
6168 6197
6169 6198
6170 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 6199 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
6171 return Dart::IsRunningPrecompiledCode(); 6200 return Dart::IsRunningPrecompiledCode();
6172 } 6201 }
6173 6202
6174 } // namespace dart 6203 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698