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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 91293002: Propagate errors from DartUtils helper functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated comments Created 7 years 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/bin/dartutils.h ('k') | no next file » | 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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 if (strlen(url_mapped_name) != 0) { 58 if (strlen(url_mapped_name) != 0) {
59 return url_mapped_name; // Found a mapping for this URL. 59 return url_mapped_name; // Found a mapping for this URL.
60 } 60 }
61 } 61 }
62 } 62 }
63 return NULL; // Did not find a mapping for this URL. 63 return NULL; // Did not find a mapping for this URL.
64 } 64 }
65 65
66 66
67 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) { 67 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) {
68 ASSERT(Dart_IsInteger(value_obj));
69 int64_t value = 0; 68 int64_t value = 0;
70 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); 69 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value);
71 ASSERT(!Dart_IsError(result)); 70 if (Dart_IsError(result)) Dart_PropagateError(result);
72 return value; 71 return value;
73 } 72 }
74 73
75 74
76 intptr_t DartUtils::GetIntptrValue(Dart_Handle value_obj) { 75 intptr_t DartUtils::GetIntptrValue(Dart_Handle value_obj) {
77 ASSERT(Dart_IsInteger(value_obj));
78 int64_t value = 0; 76 int64_t value = 0;
79 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); 77 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value);
80 ASSERT(!Dart_IsError(result)); 78 if (Dart_IsError(result)) Dart_PropagateError(result);
79 if (value < kIntptrMin || kIntptrMax < value) {
80 Dart_PropagateError(Dart_NewApiError("Value outside intptr:t range"));
81 }
81 return static_cast<intptr_t>(value); 82 return static_cast<intptr_t>(value);
82 } 83 }
83 84
84 85
85 bool DartUtils::GetInt64Value(Dart_Handle value_obj, int64_t* value) { 86 bool DartUtils::GetInt64Value(Dart_Handle value_obj, int64_t* value) {
86 bool valid = Dart_IsInteger(value_obj); 87 bool valid = Dart_IsInteger(value_obj);
87 if (valid) { 88 if (valid) {
88 Dart_Handle result = Dart_IntegerFitsIntoInt64(value_obj, &valid); 89 Dart_Handle result = Dart_IntegerFitsIntoInt64(value_obj, &valid);
89 ASSERT(!Dart_IsError(result)); 90 if (Dart_IsError(result)) Dart_PropagateError(result);
90 } 91 }
91 if (!valid) return false; 92 if (!valid) return false;
92 Dart_Handle result = Dart_IntegerToInt64(value_obj, value); 93 Dart_Handle result = Dart_IntegerToInt64(value_obj, value);
93 ASSERT(!Dart_IsError(result)); 94 if (Dart_IsError(result)) Dart_PropagateError(result);
94 return true; 95 return true;
95 } 96 }
96 97
97 98
98 const char* DartUtils::GetStringValue(Dart_Handle str_obj) { 99 const char* DartUtils::GetStringValue(Dart_Handle str_obj) {
99 const char* cstring = NULL; 100 const char* cstring = NULL;
100 Dart_Handle result = Dart_StringToCString(str_obj, &cstring); 101 Dart_Handle result = Dart_StringToCString(str_obj, &cstring);
101 ASSERT(!Dart_IsError(result)); 102 if (Dart_IsError(result)) Dart_PropagateError(result);
102 return cstring; 103 return cstring;
103 } 104 }
104 105
105 106
106 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { 107 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) {
107 bool value = false; 108 bool value = false;
108 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); 109 Dart_Handle result = Dart_BooleanValue(bool_obj, &value);
109 ASSERT(!Dart_IsError(result)); 110 if (Dart_IsError(result)) Dart_PropagateError(result);
110 return value; 111 return value;
111 } 112 }
112 113
113 114
114 void DartUtils::SetIntegerField(Dart_Handle handle, 115 void DartUtils::SetIntegerField(Dart_Handle handle,
115 const char* name, 116 const char* name,
116 intptr_t val) { 117 intptr_t val) {
117 Dart_Handle result = Dart_SetField(handle, 118 Dart_Handle result = Dart_SetField(handle,
118 NewString(name), 119 NewString(name),
119 Dart_NewInteger(val)); 120 Dart_NewInteger(val));
120 ASSERT(!Dart_IsError(result)); 121 if (Dart_IsError(result)) Dart_PropagateError(result);
121 } 122 }
122 123
123 124
124 intptr_t DartUtils::GetIntegerField(Dart_Handle handle, 125 intptr_t DartUtils::GetIntegerField(Dart_Handle handle,
125 const char* name) { 126 const char* name) {
126 Dart_Handle result = Dart_GetField(handle, NewString(name)); 127 Dart_Handle result = Dart_GetField(handle, NewString(name));
127 ASSERT(!Dart_IsError(result)); 128 if (Dart_IsError(result)) Dart_PropagateError(result);
128 intptr_t value = DartUtils::GetIntegerValue(result); 129 intptr_t value = DartUtils::GetIntegerValue(result);
129 return value; 130 return value;
130 } 131 }
131 132
132 133
133 void DartUtils::SetStringField(Dart_Handle handle, 134 void DartUtils::SetStringField(Dart_Handle handle,
134 const char* name, 135 const char* name,
135 const char* val) { 136 const char* val) {
136 Dart_Handle result = Dart_SetField(handle, NewString(name), NewString(val)); 137 Dart_Handle result = Dart_SetField(handle, NewString(name), NewString(val));
137 ASSERT(!Dart_IsError(result)); 138 if (Dart_IsError(result)) Dart_PropagateError(result);
138 } 139 }
139 140
140 141
141 bool DartUtils::IsDartSchemeURL(const char* url_name) { 142 bool DartUtils::IsDartSchemeURL(const char* url_name) {
142 static const intptr_t kDartSchemeLen = strlen(kDartScheme); 143 static const intptr_t kDartSchemeLen = strlen(kDartScheme);
143 // If the URL starts with "dart:" then it is considered as a special 144 // If the URL starts with "dart:" then it is considered as a special
144 // library URL which is handled differently from other URLs. 145 // library URL which is handled differently from other URLs.
145 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); 146 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0);
146 } 147 }
147 148
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 new CObjectString(CObject::NewString(os_error->message())); 1049 new CObjectString(CObject::NewString(os_error->message()));
1049 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1050 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
1050 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1051 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
1051 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1052 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
1052 result->SetAt(2, error_message); 1053 result->SetAt(2, error_message);
1053 return result; 1054 return result;
1054 } 1055 }
1055 1056
1056 } // namespace bin 1057 } // namespace bin
1057 } // namespace dart 1058 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698