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

Side by Side Diff: runtime/lib/bool.cc

Issue 186393004: Fix fromEnvironment when called from isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/integers.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) 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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
11 #include "vm/exceptions.h" 11 #include "vm/exceptions.h"
12 #include "vm/isolate.h" 12 #include "vm/isolate.h"
13 #include "vm/native_entry.h" 13 #include "vm/native_entry.h"
14 #include "vm/object.h" 14 #include "vm/object.h"
15 #include "vm/object_store.h" 15 #include "vm/object_store.h"
16 #include "vm/symbols.h" 16 #include "vm/symbols.h"
17 17
18 namespace dart { 18 namespace dart {
19 19
20 DEFINE_NATIVE_ENTRY(Bool_fromEnvironment, 3) { 20 DEFINE_NATIVE_ENTRY(Bool_fromEnvironment, 3) {
21 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); 21 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1));
22 GET_NATIVE_ARGUMENT(Bool, default_value, arguments->NativeArgAt(2)); 22 GET_NATIVE_ARGUMENT(Bool, default_value, arguments->NativeArgAt(2));
23 // Call the embedder to supply us with the environment. 23 // Call the embedder to supply us with the environment.
24 Dart_EnterScope();
24 Dart_EnvironmentCallback callback = isolate->environment_callback(); 25 Dart_EnvironmentCallback callback = isolate->environment_callback();
25 if (callback != NULL) { 26 if (callback != NULL) {
26 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw())); 27 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw()));
27 if (Dart_IsString(result)) { 28 if (Dart_IsString(result)) {
28 const char *chars; 29 const char *chars;
29 Dart_StringToCString(result, &chars); 30 Dart_StringToCString(result, &chars);
30 if (strcmp("true", chars) == 0) return Bool::True().raw(); 31 if (strcmp("true", chars) == 0) return Bool::True().raw();
31 if (strcmp("false", chars) == 0) return Bool::False().raw(); 32 if (strcmp("false", chars) == 0) return Bool::False().raw();
32 } else if (Dart_IsError(result)) { 33 } else if (Dart_IsError(result)) {
33 const Object& error = 34 const Object& error =
34 Object::Handle(isolate, Api::UnwrapHandle(result)); 35 Object::Handle(isolate, Api::UnwrapHandle(result));
35 Exceptions::ThrowArgumentError( 36 Exceptions::ThrowArgumentError(
36 String::Handle( 37 String::Handle(
37 String::New(Error::Cast(error).ToErrorCString()))); 38 String::New(Error::Cast(error).ToErrorCString())));
38 } else if (!Dart_IsNull(result)) { 39 } else if (!Dart_IsNull(result)) {
39 Exceptions::ThrowArgumentError( 40 Exceptions::ThrowArgumentError(
40 String::Handle(String::New("Illegal environment value"))); 41 String::Handle(String::New("Illegal environment value")));
41 } 42 }
42 } 43 }
44 Dart_ExitScope();
43 return default_value.raw(); 45 return default_value.raw();
44 } 46 }
45 47
46 } // namespace dart 48 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/integers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698