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

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: Two new lines between functions. Created 4 years, 10 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 "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 4799 matching lines...) Expand 10 before | Expand all | Expand 10 after
4810 Isolate* isolate = arguments->thread()->isolate(); 4810 Isolate* isolate = arguments->thread()->isolate();
4811 ASSERT(isolate == Isolate::Current()); 4811 ASSERT(isolate == Isolate::Current());
4812 ASSERT(isolate->api_state() != NULL && 4812 ASSERT(isolate->api_state() != NULL &&
4813 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); 4813 (isolate->api_state()->IsValidWeakPersistentHandle(rval)));
4814 #endif 4814 #endif
4815 Api::SetWeakHandleReturnValue(arguments, rval); 4815 Api::SetWeakHandleReturnValue(arguments, rval);
4816 } 4816 }
4817 4817
4818 4818
4819 // --- Environment --- 4819 // --- Environment ---
4820 RawString* Api::GetEnvironmentValue(Thread* thread, const String& name) {
4821 String& result = String::Handle(CallEnvironmentCallback(thread, name));
4822 if (result.IsNull()) {
4823 // Every 'dart:X' library introduces an environment variable
4824 // 'dart.library.X' that is set to 'true'.
4825 const String& prefix = Symbols::DartLibrary();
4826 if (name.StartsWith(prefix)) {
4827 const String& library_name =
4828 String::Handle(String::SubString(name, prefix.Length()));
4829 if (!library_name.IsNull()) {
4830 const String& dart_library_name =
4831 String::Handle(String::Concat(Symbols::DartScheme(), library_name));
4832 const Library& library =
4833 Library::Handle(Library::LookupLibrary(dart_library_name));
4834 if (!library.IsNull()) {
4835 return Symbols::True().raw();
4836 }
4837 }
4838 }
4839 // TODO(iposva): Determine whether builtin values can be overriden by the
Ivan Posva 2016/01/29 21:29:49 Please remove this TODO as obviously above you are
floitsch 2016/02/01 16:56:34 Done.
4840 // embedder.
4841 // Check for default VM provided values. If it was not overriden on the
4842 // command line.
4843 if (Symbols::DartIsVM().Equals(name)) {
4844 return Symbols::True().raw();
4845 }
4846 }
4847 return result.raw();
4848 }
4849
4850
4820 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { 4851 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) {
4821 Isolate* isolate = thread->isolate(); 4852 Isolate* isolate = thread->isolate();
4822 Scope api_scope(thread); 4853 Scope api_scope(thread);
4823 Dart_EnvironmentCallback callback = isolate->environment_callback(); 4854 Dart_EnvironmentCallback callback = isolate->environment_callback();
4824 String& result = String::Handle(thread->zone()); 4855 String& result = String::Handle(thread->zone());
4825 if (callback != NULL) { 4856 if (callback != NULL) {
4826 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); 4857 Dart_Handle response = callback(Api::NewHandle(thread, name.raw()));
4827 if (::Dart_IsString(response)) { 4858 if (::Dart_IsString(response)) {
4828 result ^= Api::UnwrapHandle(response); 4859 result ^= Api::UnwrapHandle(response);
4829 } else if (::Dart_IsError(response)) { 4860 } else if (::Dart_IsError(response)) {
4830 const Object& error = Object::Handle( 4861 const Object& error = Object::Handle(
4831 thread->zone(), Api::UnwrapHandle(response)); 4862 thread->zone(), Api::UnwrapHandle(response));
4832 Exceptions::ThrowArgumentError( 4863 Exceptions::ThrowArgumentError(
4833 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); 4864 String::Handle(String::New(Error::Cast(error).ToErrorCString())));
4834 } else if (!::Dart_IsNull(response)) { 4865 } else if (!::Dart_IsNull(response)) {
4835 // At this point everything except null are invalid environment values. 4866 // At this point everything except null are invalid environment values.
4836 Exceptions::ThrowArgumentError( 4867 Exceptions::ThrowArgumentError(
4837 String::Handle(String::New("Illegal environment value"))); 4868 String::Handle(String::New("Illegal environment value")));
4838 } 4869 }
4839 } 4870 }
4840 if (result.IsNull()) {
4841 // TODO(iposva): Determine whether builtin values can be overriden by the
4842 // embedder.
4843 // Check for default VM provided values. If it was not overriden on the
4844 // command line.
4845 if (Symbols::DartIsVM().Equals(name)) {
4846 return Symbols::True().raw();
4847 }
4848 }
4849 return result.raw(); 4871 return result.raw();
4850 } 4872 }
4851 4873
4852 4874
4853 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( 4875 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback(
4854 Dart_EnvironmentCallback callback) { 4876 Dart_EnvironmentCallback callback) {
4855 Isolate* isolate = Isolate::Current(); 4877 Isolate* isolate = Isolate::Current();
4856 CHECK_ISOLATE(isolate); 4878 CHECK_ISOLATE(isolate);
4857 isolate->set_environment_callback(callback); 4879 isolate->set_environment_callback(callback);
4858 return Api::Success(); 4880 return Api::Success();
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5969 return Api::Success(); 5991 return Api::Success();
5970 } 5992 }
5971 #endif // DART_PRECOMPILED_RUNTIME 5993 #endif // DART_PRECOMPILED_RUNTIME
5972 5994
5973 5995
5974 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 5996 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
5975 return Dart::IsRunningPrecompiledCode(); 5997 return Dart::IsRunningPrecompiledCode();
5976 } 5998 }
5977 5999
5978 } // namespace dart 6000 } // 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