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

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

Issue 9657001: Start using Dart_PropagateError in the runtime/bin directory. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
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 "bin/file.h" 7 #include "bin/file.h"
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 } 41 }
42 return NULL; // Did not find a mapping for this URL. 42 return NULL; // Did not find a mapping for this URL.
43 } 43 }
44 44
45 45
46 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) { 46 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) {
47 ASSERT(Dart_IsInteger(value_obj)); 47 ASSERT(Dart_IsInteger(value_obj));
48 int64_t value = 0; 48 int64_t value = 0;
49 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); 49 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value);
50 ASSERT(!Dart_IsError(result)); 50 if (Dart_IsError(result)) {
51 Dart_PropagateError(result);
52 }
51 return value; 53 return value;
52 } 54 }
53 55
54 56
55 const char* DartUtils::GetStringValue(Dart_Handle str_obj) { 57 const char* DartUtils::GetStringValue(Dart_Handle str_obj) {
56 const char* cstring = NULL; 58 const char* cstring = NULL;
57 Dart_Handle result = Dart_StringToCString(str_obj, &cstring); 59 Dart_Handle result = Dart_StringToCString(str_obj, &cstring);
58 ASSERT(!Dart_IsError(result)); 60 if (Dart_IsError(result)) {
61 Dart_PropagateError(result);
62 }
59 return cstring; 63 return cstring;
60 } 64 }
61 65
62 66
63 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { 67 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) {
64 bool value = false; 68 bool value = false;
65 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); 69 Dart_Handle result = Dart_BooleanValue(bool_obj, &value);
66 ASSERT(!Dart_IsError(result)); 70 if (Dart_IsError(result)) {
71 Dart_PropagateError(result);
72 }
67 return value; 73 return value;
68 } 74 }
69 75
70 76
71 void DartUtils::SetIntegerField(Dart_Handle handle, 77 void DartUtils::SetIntegerField(Dart_Handle handle,
72 const char* name, 78 const char* name,
73 intptr_t val) { 79 intptr_t val) {
74 Dart_Handle result = Dart_SetField(handle, 80 Dart_Handle result = Dart_SetField(handle,
75 Dart_NewString(name), 81 Dart_NewString(name),
76 Dart_NewInteger(val)); 82 Dart_NewInteger(val));
77 ASSERT(!Dart_IsError(result)); 83 if (Dart_IsError(result)) {
84 Dart_PropagateError(result);
85 }
78 } 86 }
79 87
80 88
81 intptr_t DartUtils::GetIntegerField(Dart_Handle handle, 89 intptr_t DartUtils::GetIntegerField(Dart_Handle handle,
82 const char* name) { 90 const char* name) {
83 Dart_Handle result = Dart_GetField(handle, Dart_NewString(name)); 91 Dart_Handle result = Dart_GetField(handle, Dart_NewString(name));
84 ASSERT(!Dart_IsError(result)); 92 if (Dart_IsError(result)) {
93 Dart_PropagateError(result);
94 }
85 intptr_t value = DartUtils::GetIntegerValue(result); 95 intptr_t value = DartUtils::GetIntegerValue(result);
86 return value; 96 return value;
87 } 97 }
88 98
89 99
90 void DartUtils::SetStringField(Dart_Handle handle, 100 void DartUtils::SetStringField(Dart_Handle handle,
91 const char* name, 101 const char* name,
92 const char* val) { 102 const char* val) {
93 Dart_Handle result = Dart_SetField(handle, 103 Dart_Handle result = Dart_SetField(handle,
94 Dart_NewString(name), 104 Dart_NewString(name),
95 Dart_NewString(val)); 105 Dart_NewString(val));
96 ASSERT(!Dart_IsError(result)); 106 if (Dart_IsError(result)) {
107 Dart_PropagateError(result);
108 }
97 } 109 }
98 110
99 111
100 bool DartUtils::IsDartSchemeURL(const char* url_name) { 112 bool DartUtils::IsDartSchemeURL(const char* url_name) {
101 static const intptr_t kDartSchemeLen = strlen(kDartScheme); 113 static const intptr_t kDartSchemeLen = strlen(kDartScheme);
102 // If the URL starts with "dart:" then it is considered as a special 114 // If the URL starts with "dart:" then it is considered as a special
103 // library URL which is handled differently from other URLs. 115 // library URL which is handled differently from other URLs.
104 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); 116 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0);
105 } 117 }
106 118
(...skipping 26 matching lines...) Expand all
133 return (strcmp(url_name, kUtfLibURL) == 0); 145 return (strcmp(url_name, kUtfLibURL) == 0);
134 } 146 }
135 147
136 148
137 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, 149 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping,
138 Dart_Handle library, 150 Dart_Handle library,
139 const char* url_str) { 151 const char* url_str) {
140 // Get the url of the including library. 152 // Get the url of the including library.
141 Dart_Handle library_url = Dart_LibraryUrl(library); 153 Dart_Handle library_url = Dart_LibraryUrl(library);
142 if (Dart_IsError(library_url)) { 154 if (Dart_IsError(library_url)) {
143 return Dart_Error("accessing library url failed"); 155 return library_url;
144 } 156 }
145 if (!Dart_IsString8(library_url)) { 157 if (!Dart_IsString8(library_url)) {
146 return Dart_Error("library url is not a string"); 158 return Dart_Error("library url is not a string");
147 } 159 }
148 const char* library_url_str = NULL; 160 const char* library_url_str = NULL;
149 Dart_Handle result = Dart_StringToCString(library_url, &library_url_str); 161 Dart_Handle result = Dart_StringToCString(library_url, &library_url_str);
150 if (Dart_IsError(result)) { 162 if (Dart_IsError(result)) {
151 return Dart_Error("accessing library url characters failed"); 163 return result;
152 } 164 }
153 if (url_mapping != NULL) { 165 if (url_mapping != NULL) {
154 const char* mapped_library_url_str = MapLibraryUrl(url_mapping, 166 const char* mapped_library_url_str = MapLibraryUrl(url_mapping,
155 library_url_str); 167 library_url_str);
156 if (mapped_library_url_str != NULL) { 168 if (mapped_library_url_str != NULL) {
157 library_url_str = mapped_library_url_str; 169 library_url_str = mapped_library_url_str;
158 } 170 }
159 } 171 }
160 // Calculate the canonical path. 172 // Calculate the canonical path.
161 const char* canon_url_str = GetCanonicalPath(library_url_str, url_str); 173 const char* canon_url_str = GetCanonicalPath(library_url_str, url_str);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return cobject; 383 return cobject;
372 } 384 }
373 385
374 386
375 Dart_CObject* CObject::NewByteArray(int length) { 387 Dart_CObject* CObject::NewByteArray(int length) {
376 Dart_CObject* cobject = New(Dart_CObject::kByteArray, length); 388 Dart_CObject* cobject = New(Dart_CObject::kByteArray, length);
377 cobject->value.as_byte_array.length = length; 389 cobject->value.as_byte_array.length = length;
378 cobject->value.as_byte_array.values = reinterpret_cast<uint8_t*>(cobject + 1); 390 cobject->value.as_byte_array.values = reinterpret_cast<uint8_t*>(cobject + 1);
379 return cobject; 391 return cobject;
380 } 392 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698