Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/extensions.h" | 7 #include "bin/extensions.h" |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 #include "bin/file.h" | 9 #include "bin/file.h" |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 } | 73 } |
| 74 if (!valid) return false; | 74 if (!valid) return false; |
| 75 Dart_Handle result = Dart_IntegerToInt64(value_obj, value); | 75 Dart_Handle result = Dart_IntegerToInt64(value_obj, value); |
| 76 ASSERT(!Dart_IsError(result)); | 76 ASSERT(!Dart_IsError(result)); |
| 77 return true; | 77 return true; |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 const char* DartUtils::GetStringValue(Dart_Handle str_obj) { | 81 const char* DartUtils::GetStringValue(Dart_Handle str_obj) { |
| 82 const char* cstring = NULL; | 82 const char* cstring = NULL; |
| 83 Dart_Handle result = Dart_StringToCString(str_obj, &cstring); | 83 Dart_Handle result = Dart_StringAsCString(str_obj, &cstring); |
| 84 ASSERT(!Dart_IsError(result)); | 84 ASSERT(!Dart_IsError(result)); |
| 85 return cstring; | 85 return cstring; |
| 86 } | 86 } |
| 87 | 87 |
| 88 | 88 |
| 89 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { | 89 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { |
| 90 bool value = false; | 90 bool value = false; |
| 91 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); | 91 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); |
| 92 ASSERT(!Dart_IsError(result)); | 92 ASSERT(!Dart_IsError(result)); |
| 93 return value; | 93 return value; |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 void DartUtils::SetIntegerField(Dart_Handle handle, | 97 void DartUtils::SetIntegerField(Dart_Handle handle, |
| 98 const char* name, | 98 const char* name, |
| 99 intptr_t val) { | 99 intptr_t val) { |
| 100 Dart_Handle result = Dart_SetField(handle, | 100 Dart_Handle result = Dart_SetField(handle, |
| 101 Dart_NewString(name), | 101 NewString(name), |
| 102 Dart_NewInteger(val)); | 102 Dart_NewInteger(val)); |
| 103 ASSERT(!Dart_IsError(result)); | 103 ASSERT(!Dart_IsError(result)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 intptr_t DartUtils::GetIntegerField(Dart_Handle handle, | 107 intptr_t DartUtils::GetIntegerField(Dart_Handle handle, |
| 108 const char* name) { | 108 const char* name) { |
|
cshapiro
2012/10/24 23:52:29
Not sure what caused this change. Either way, the
siva
2012/10/26 21:38:29
There was an indentation issue before which I fixe
| |
| 109 Dart_Handle result = Dart_GetField(handle, Dart_NewString(name)); | 109 Dart_Handle result = Dart_GetField(handle, NewString(name)); |
| 110 ASSERT(!Dart_IsError(result)); | 110 ASSERT(!Dart_IsError(result)); |
| 111 intptr_t value = DartUtils::GetIntegerValue(result); | 111 intptr_t value = DartUtils::GetIntegerValue(result); |
| 112 return value; | 112 return value; |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 void DartUtils::SetStringField(Dart_Handle handle, | 116 void DartUtils::SetStringField(Dart_Handle handle, |
| 117 const char* name, | 117 const char* name, |
| 118 const char* val) { | 118 const char* val) { |
| 119 Dart_Handle result = Dart_SetField(handle, | 119 Dart_Handle result = Dart_SetField(handle, NewString(name), NewString(val)); |
| 120 Dart_NewString(name), | |
| 121 Dart_NewString(val)); | |
| 122 ASSERT(!Dart_IsError(result)); | 120 ASSERT(!Dart_IsError(result)); |
| 123 } | 121 } |
| 124 | 122 |
| 125 | 123 |
| 126 bool DartUtils::IsDartSchemeURL(const char* url_name) { | 124 bool DartUtils::IsDartSchemeURL(const char* url_name) { |
| 127 static const intptr_t kDartSchemeLen = strlen(kDartScheme); | 125 static const intptr_t kDartSchemeLen = strlen(kDartScheme); |
| 128 // If the URL starts with "dart:" then it is considered as a special | 126 // If the URL starts with "dart:" then it is considered as a special |
| 129 // library URL which is handled differently from other URLs. | 127 // library URL which is handled differently from other URLs. |
| 130 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); | 128 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); |
| 131 } | 129 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 | 164 |
| 167 | 165 |
| 168 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, | 166 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, |
| 169 Dart_Handle library, | 167 Dart_Handle library, |
| 170 const char* url_str) { | 168 const char* url_str) { |
| 171 // Get the url of the including library. | 169 // Get the url of the including library. |
| 172 Dart_Handle library_url = Dart_LibraryUrl(library); | 170 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 173 if (Dart_IsError(library_url)) { | 171 if (Dart_IsError(library_url)) { |
| 174 return Dart_Error("accessing library url failed"); | 172 return Dart_Error("accessing library url failed"); |
| 175 } | 173 } |
| 176 if (!Dart_IsString8(library_url)) { | 174 if (!Dart_IsString(library_url)) { |
| 177 return Dart_Error("library url is not a string"); | 175 return Dart_Error("library url is not a string"); |
| 178 } | 176 } |
| 179 const char* library_url_str = NULL; | 177 const char* library_url_str = NULL; |
| 180 Dart_Handle result = Dart_StringToCString(library_url, &library_url_str); | 178 Dart_Handle result = Dart_StringAsCString(library_url, &library_url_str); |
| 181 if (Dart_IsError(result)) { | 179 if (Dart_IsError(result)) { |
| 182 return Dart_Error("accessing library url characters failed"); | 180 return Dart_Error("accessing library url characters failed"); |
| 183 } | 181 } |
| 184 if (url_mapping != NULL) { | 182 if (url_mapping != NULL) { |
| 185 const char* mapped_library_url_str = MapLibraryUrl(url_mapping, | 183 const char* mapped_library_url_str = MapLibraryUrl(url_mapping, |
| 186 library_url_str); | 184 library_url_str); |
| 187 if (mapped_library_url_str != NULL) { | 185 if (mapped_library_url_str != NULL) { |
| 188 library_url_str = mapped_library_url_str; | 186 library_url_str = mapped_library_url_str; |
| 189 } | 187 } |
| 190 } | 188 } |
| 191 // Calculate the canonical path. | 189 // Calculate the canonical path. |
| 192 const char* canon_url_str = GetCanonicalPath(library_url_str, url_str); | 190 const char* canon_url_str = GetCanonicalPath(library_url_str, url_str); |
| 193 Dart_Handle canon_url = Dart_NewString(canon_url_str); | 191 Dart_Handle canon_url = NewString(canon_url_str); |
| 194 free(const_cast<char*>(canon_url_str)); | 192 free(const_cast<char*>(canon_url_str)); |
| 195 | 193 |
| 196 return canon_url; | 194 return canon_url; |
| 197 } | 195 } |
| 198 | 196 |
| 199 | 197 |
| 200 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { | 198 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { |
| 201 File* file = File::Open(filename, File::kRead); | 199 File* file = File::Open(filename, File::kRead); |
| 202 if (file == NULL) { | 200 if (file == NULL) { |
| 203 const char* format = "Unable to open file: %s"; | 201 const char* format = "Unable to open file: %s"; |
| 204 intptr_t len = snprintf(NULL, 0, format, filename); | 202 intptr_t len = snprintf(NULL, 0, format, filename); |
| 205 // TODO(iposva): Allocate from the zone instead of leaking error string | 203 // TODO(iposva): Allocate from the zone instead of leaking error string |
| 206 // here. On the other hand the binary is about the exit anyway. | 204 // here. On the other hand the binary is about the exit anyway. |
| 207 char* error_msg = reinterpret_cast<char*>(malloc(len + 1)); | 205 char* error_msg = reinterpret_cast<char*>(malloc(len + 1)); |
| 208 snprintf(error_msg, len + 1, format, filename); | 206 snprintf(error_msg, len + 1, format, filename); |
| 209 return Dart_Error(error_msg); | 207 return Dart_Error(error_msg); |
| 210 } | 208 } |
| 211 intptr_t len = file->Length(); | 209 intptr_t len = file->Length(); |
| 212 char* text_buffer = reinterpret_cast<char*>(malloc(len + 1)); | 210 uint8_t* text_buffer = reinterpret_cast<uint8_t*>(malloc(len)); |
| 213 if (text_buffer == NULL) { | 211 if (text_buffer == NULL) { |
| 214 delete file; | 212 delete file; |
| 215 return Dart_Error("Unable to allocate buffer"); | 213 return Dart_Error("Unable to allocate buffer"); |
| 216 } | 214 } |
| 217 if (!file->ReadFully(text_buffer, len)) { | 215 if (!file->ReadFully(text_buffer, len)) { |
| 218 delete file; | 216 delete file; |
| 219 return Dart_Error("Unable to fully read contents"); | 217 return Dart_Error("Unable to fully read contents"); |
| 220 } | 218 } |
| 221 text_buffer[len] = '\0'; | |
| 222 delete file; | 219 delete file; |
| 223 Dart_Handle str = Dart_NewString(text_buffer); | 220 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); |
| 224 free(text_buffer); | 221 free(text_buffer); |
| 225 return str; | 222 return str; |
| 226 } | 223 } |
| 227 | 224 |
| 228 | 225 |
| 229 static Dart_Handle ResolveScriptUri(Dart_Handle script_uri, | 226 static Dart_Handle ResolveScriptUri(Dart_Handle script_uri, |
| 230 Dart_Handle builtin_lib) { | 227 Dart_Handle builtin_lib) { |
| 231 const int kNumArgs = 3; | 228 const int kNumArgs = 3; |
| 232 Dart_Handle dart_args[kNumArgs]; | 229 Dart_Handle dart_args[kNumArgs]; |
| 233 dart_args[0] = Dart_NewString(DartUtils::original_working_directory); | 230 dart_args[0] = DartUtils::NewString(DartUtils::original_working_directory); |
| 234 dart_args[1] = script_uri; | 231 dart_args[1] = script_uri; |
| 235 dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False()); | 232 dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False()); |
| 236 return Dart_Invoke( | 233 return Dart_Invoke(builtin_lib, |
| 237 builtin_lib, Dart_NewString("_resolveScriptUri"), kNumArgs, dart_args); | 234 DartUtils::NewString("_resolveScriptUri"), |
| 235 kNumArgs, | |
| 236 dart_args); | |
| 238 } | 237 } |
| 239 | 238 |
| 240 | 239 |
| 241 static Dart_Handle FilePathFromUri(Dart_Handle script_uri, | 240 static Dart_Handle FilePathFromUri(Dart_Handle script_uri, |
| 242 Dart_Handle builtin_lib) { | 241 Dart_Handle builtin_lib) { |
| 243 const int kNumArgs = 2; | 242 const int kNumArgs = 2; |
| 244 Dart_Handle dart_args[kNumArgs]; | 243 Dart_Handle dart_args[kNumArgs]; |
| 245 dart_args[0] = script_uri; | 244 dart_args[0] = script_uri; |
| 246 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); | 245 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); |
| 247 Dart_Handle script_path = Dart_Invoke( | 246 Dart_Handle script_path = Dart_Invoke( |
| 248 builtin_lib, Dart_NewString("_filePathFromUri"), kNumArgs, dart_args); | 247 builtin_lib, |
| 248 DartUtils::NewString("_filePathFromUri"), | |
| 249 kNumArgs, | |
| 250 dart_args); | |
| 249 return script_path; | 251 return script_path; |
| 250 } | 252 } |
| 251 | 253 |
| 252 | 254 |
| 253 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, | 255 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, |
| 254 Dart_Handle library, | 256 Dart_Handle library, |
| 255 Dart_Handle url) { | 257 Dart_Handle url) { |
| 256 if (!Dart_IsLibrary(library)) { | 258 if (!Dart_IsLibrary(library)) { |
| 257 return Dart_Error("not a library"); | 259 return Dart_Error("not a library"); |
| 258 } | 260 } |
| 259 if (!Dart_IsString8(url)) { | 261 if (!Dart_IsString(url)) { |
| 260 return Dart_Error("url is not a string"); | 262 return Dart_Error("url is not a string"); |
| 261 } | 263 } |
| 262 const char* url_string = NULL; | 264 const char* url_string = NULL; |
| 263 Dart_Handle result = Dart_StringToCString(url, &url_string); | 265 Dart_Handle result = Dart_StringAsCString(url, &url_string); |
| 264 if (Dart_IsError(result)) { | 266 if (Dart_IsError(result)) { |
| 265 return result; | 267 return result; |
| 266 } | 268 } |
| 267 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 269 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
| 268 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); | 270 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); |
| 269 if (tag == kCanonicalizeUrl) { | 271 if (tag == kCanonicalizeUrl) { |
| 270 // If this is a Dart Scheme URL then it is not modified as it will be | 272 // If this is a Dart Scheme URL then it is not modified as it will be |
| 271 // handled by the VM internally. | 273 // handled by the VM internally. |
| 272 if (is_dart_scheme_url) { | 274 if (is_dart_scheme_url) { |
| 273 return url; | 275 return url; |
| 274 } | 276 } |
| 275 // Resolve the url within the context of the library's URL. | 277 // Resolve the url within the context of the library's URL. |
| 276 Dart_Handle builtin_lib = | 278 Dart_Handle builtin_lib = |
| 277 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 279 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 278 Dart_Handle library_url = Dart_LibraryUrl(library); | 280 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 279 if (Dart_IsError(library_url)) { | 281 if (Dart_IsError(library_url)) { |
| 280 return library_url; | 282 return library_url; |
| 281 } | 283 } |
| 282 const int kNumArgs = 2; | 284 const int kNumArgs = 2; |
| 283 Dart_Handle dart_args[kNumArgs]; | 285 Dart_Handle dart_args[kNumArgs]; |
| 284 dart_args[0] = library_url; | 286 dart_args[0] = library_url; |
| 285 dart_args[1] = url; | 287 dart_args[1] = url; |
| 286 return Dart_Invoke( | 288 return Dart_Invoke( |
| 287 builtin_lib, Dart_NewString("_resolveUri"), kNumArgs, dart_args); | 289 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); |
| 288 } | 290 } |
| 289 if (is_dart_scheme_url) { | 291 if (is_dart_scheme_url) { |
| 290 ASSERT(tag == kImportTag); | 292 ASSERT(tag == kImportTag); |
| 291 // Handle imports of other built-in libraries present in the SDK. | 293 // Handle imports of other built-in libraries present in the SDK. |
| 292 Builtin::BuiltinLibraryId id; | 294 Builtin::BuiltinLibraryId id; |
| 293 if (DartUtils::IsDartCryptoLibURL(url_string)) { | 295 if (DartUtils::IsDartCryptoLibURL(url_string)) { |
| 294 id = Builtin::kCryptoLibrary; | 296 id = Builtin::kCryptoLibrary; |
| 295 } else if (DartUtils::IsDartIOLibURL(url_string)) { | 297 } else if (DartUtils::IsDartIOLibURL(url_string)) { |
| 296 id = Builtin::kIOLibrary; | 298 id = Builtin::kIOLibrary; |
| 297 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | 299 } else if (DartUtils::IsDartJsonLibURL(url_string)) { |
| 298 id = Builtin::kJsonLibrary; | 300 id = Builtin::kJsonLibrary; |
| 299 } else if (DartUtils::IsDartUriLibURL(url_string)) { | 301 } else if (DartUtils::IsDartUriLibURL(url_string)) { |
| 300 id = Builtin::kUriLibrary; | 302 id = Builtin::kUriLibrary; |
| 301 } else if (DartUtils::IsDartUtfLibURL(url_string)) { | 303 } else if (DartUtils::IsDartUtfLibURL(url_string)) { |
| 302 id = Builtin::kUtfLibrary; | 304 id = Builtin::kUtfLibrary; |
| 303 } else { | 305 } else { |
| 304 return Dart_Error("Do not know how to load '%s'", url_string); | 306 return Dart_Error("Do not know how to load '%s'", url_string); |
| 305 } | 307 } |
| 306 return Builtin::LoadAndCheckLibrary(id); | 308 return Builtin::LoadAndCheckLibrary(id); |
| 307 } else { | 309 } else { |
| 308 // Get the file path out of the url. | 310 // Get the file path out of the url. |
| 309 Dart_Handle builtin_lib = | 311 Dart_Handle builtin_lib = |
| 310 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 312 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 311 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); | 313 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); |
| 312 if (Dart_IsError(file_path)) { | 314 if (Dart_IsError(file_path)) { |
| 313 return file_path; | 315 return file_path; |
| 314 } | 316 } |
| 315 Dart_StringToCString(file_path, &url_string); | 317 Dart_StringAsCString(file_path, &url_string); |
| 316 } | 318 } |
| 317 if (is_dart_extension_url) { | 319 if (is_dart_extension_url) { |
| 318 if (tag != kImportTag) { | 320 if (tag != kImportTag) { |
| 319 return Dart_Error("Dart extensions must use import: '%s'", url_string); | 321 return Dart_Error("Dart extensions must use import: '%s'", url_string); |
| 320 } | 322 } |
| 321 return Extensions::LoadExtension(url_string, library); | 323 return Extensions::LoadExtension(url_string, library); |
| 322 } | 324 } |
| 323 result = DartUtils::LoadSource(NULL, | 325 result = DartUtils::LoadSource(NULL, |
| 324 library, | 326 library, |
| 325 url, | 327 url, |
| 326 tag, | 328 tag, |
| 327 url_string); | 329 url_string); |
| 328 return result; | 330 return result; |
| 329 } | 331 } |
| 330 | 332 |
| 331 | 333 |
| 332 static Dart_Handle ReadSource(Dart_Handle script_uri, | 334 static Dart_Handle ReadSource(Dart_Handle script_uri, |
| 333 Dart_Handle builtin_lib) { | 335 Dart_Handle builtin_lib) { |
| 334 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib); | 336 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib); |
| 335 if (Dart_IsError(script_path)) { | 337 if (Dart_IsError(script_path)) { |
| 336 return script_path; | 338 return script_path; |
| 337 } | 339 } |
| 338 const char* script_path_cstr; | 340 const char* script_path_cstr; |
| 339 Dart_StringToCString(script_path, &script_path_cstr); | 341 Dart_StringAsCString(script_path, &script_path_cstr); |
| 340 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); | 342 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); |
| 341 return source; | 343 return source; |
| 342 } | 344 } |
| 343 | 345 |
| 344 | 346 |
| 345 Dart_Handle DartUtils::LoadScript(const char* script_uri, | 347 Dart_Handle DartUtils::LoadScript(const char* script_uri, |
| 346 Dart_Handle builtin_lib) { | 348 Dart_Handle builtin_lib) { |
| 347 Dart_Handle resolved_script_uri; | 349 Dart_Handle resolved_script_uri; |
| 348 resolved_script_uri = ResolveScriptUri(Dart_NewString(script_uri), | 350 resolved_script_uri = ResolveScriptUri(NewString(script_uri), builtin_lib); |
| 349 builtin_lib); | |
| 350 if (Dart_IsError(resolved_script_uri)) { | 351 if (Dart_IsError(resolved_script_uri)) { |
| 351 return resolved_script_uri; | 352 return resolved_script_uri; |
| 352 } | 353 } |
| 353 Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib); | 354 Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib); |
| 354 if (Dart_IsError(source)) { | 355 if (Dart_IsError(source)) { |
| 355 return source; | 356 return source; |
| 356 } | 357 } |
| 357 return Dart_LoadScript(resolved_script_uri, source); | 358 return Dart_LoadScript(resolved_script_uri, source); |
| 358 } | 359 } |
| 359 | 360 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 384 } else if (tag == kSourceTag) { | 385 } else if (tag == kSourceTag) { |
| 385 return Dart_LoadSource(library, url, source); | 386 return Dart_LoadSource(library, url, source); |
| 386 } | 387 } |
| 387 return Dart_Error("wrong tag"); | 388 return Dart_Error("wrong tag"); |
| 388 } | 389 } |
| 389 | 390 |
| 390 | 391 |
| 391 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 392 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
| 392 Dart_Handle builtin_lib) { | 393 Dart_Handle builtin_lib) { |
| 393 // Setup the corelib 'print' function. | 394 // Setup the corelib 'print' function. |
| 394 Dart_Handle print = | 395 Dart_Handle print = Dart_Invoke( |
| 395 Dart_Invoke(builtin_lib, Dart_NewString("_getPrintClosure"), 0, 0); | 396 builtin_lib, NewString("_getPrintClosure"), 0, 0); |
| 396 Dart_Handle corelib = Dart_LookupLibrary(Dart_NewString("dart:core")); | 397 Dart_Handle corelib = Dart_LookupLibrary(NewString("dart:core")); |
| 397 Dart_Handle result = Dart_SetField(corelib, | 398 Dart_Handle result = Dart_SetField(corelib, |
| 398 Dart_NewString("_printClosure"), print); | 399 NewString("_printClosure"), |
| 400 print); | |
| 399 | 401 |
| 400 // Setup the 'timer' factory. | 402 // Setup the 'timer' factory. |
| 401 Dart_Handle url = Dart_NewString(kIsolateLibURL); | 403 Dart_Handle url = NewString(kIsolateLibURL); |
| 402 DART_CHECK_VALID(url); | 404 DART_CHECK_VALID(url); |
| 403 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 405 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
| 404 DART_CHECK_VALID(isolate_lib); | 406 DART_CHECK_VALID(isolate_lib); |
| 405 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 407 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 406 Dart_Handle timer_closure = | 408 Dart_Handle timer_closure = |
| 407 Dart_Invoke(io_lib, Dart_NewString("_getTimerFactoryClosure"), 0, NULL); | 409 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); |
| 408 Dart_Handle args[1]; | 410 Dart_Handle args[1]; |
| 409 args[0] = timer_closure; | 411 args[0] = timer_closure; |
| 410 DART_CHECK_VALID(Dart_Invoke(isolate_lib, | 412 DART_CHECK_VALID(Dart_Invoke( |
| 411 Dart_NewString("_setTimerFactoryClosure"), | 413 isolate_lib, NewString("_setTimerFactoryClosure"), 1, args)); |
| 412 1, args)); | |
| 413 | 414 |
| 414 // Set up package root if specified. | 415 // Set up package root if specified. |
| 415 if (package_root != NULL) { | 416 if (package_root != NULL) { |
| 416 result = Dart_NewString(package_root); | 417 result = NewString(package_root); |
| 417 if (!Dart_IsError(result)) { | 418 if (!Dart_IsError(result)) { |
| 418 const int kNumArgs = 1; | 419 const int kNumArgs = 1; |
| 419 Dart_Handle dart_args[kNumArgs]; | 420 Dart_Handle dart_args[kNumArgs]; |
| 420 dart_args[0] = result; | 421 dart_args[0] = result; |
| 421 return Dart_Invoke(builtin_lib, | 422 return Dart_Invoke(builtin_lib, |
| 422 Dart_NewString("_setPackageRoot"), | 423 NewString("_setPackageRoot"), |
| 423 kNumArgs, | 424 kNumArgs, |
| 424 dart_args); | 425 dart_args); |
| 425 } | 426 } |
| 426 } | 427 } |
| 427 return result; | 428 return result; |
| 428 } | 429 } |
| 429 | 430 |
| 430 | 431 |
| 431 const char* DartUtils::GetCanonicalPath(const char* reference_dir, | 432 const char* DartUtils::GetCanonicalPath(const char* reference_dir, |
| 432 const char* filename) { | 433 const char* filename) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 | 485 |
| 485 Dart_Handle DartUtils::NewDartOSError() { | 486 Dart_Handle DartUtils::NewDartOSError() { |
| 486 // Extract the current OS error. | 487 // Extract the current OS error. |
| 487 OSError os_error; | 488 OSError os_error; |
| 488 return NewDartOSError(&os_error); | 489 return NewDartOSError(&os_error); |
| 489 } | 490 } |
| 490 | 491 |
| 491 | 492 |
| 492 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { | 493 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { |
| 493 // Create a Dart OSError object with the information retrieved from the OS. | 494 // Create a Dart OSError object with the information retrieved from the OS. |
| 494 Dart_Handle url = Dart_NewString("dart:io"); | 495 Dart_Handle url = NewString("dart:io"); |
| 495 if (Dart_IsError(url)) return url; | 496 if (Dart_IsError(url)) return url; |
| 496 Dart_Handle lib = Dart_LookupLibrary(url); | 497 Dart_Handle lib = Dart_LookupLibrary(url); |
| 497 if (Dart_IsError(lib)) return lib; | 498 if (Dart_IsError(lib)) return lib; |
| 498 Dart_Handle class_name = Dart_NewString("OSError"); | 499 Dart_Handle class_name = NewString("OSError"); |
| 499 if (Dart_IsError(class_name)) return class_name; | 500 if (Dart_IsError(class_name)) return class_name; |
| 500 Dart_Handle clazz = Dart_GetClass(lib, class_name); | 501 Dart_Handle clazz = Dart_GetClass(lib, class_name); |
| 501 if (Dart_IsError(clazz)) return clazz; | 502 if (Dart_IsError(clazz)) return clazz; |
| 502 Dart_Handle args[2]; | 503 Dart_Handle args[2]; |
| 503 args[0] = Dart_NewString(os_error->message()); | 504 args[0] = NewString(os_error->message()); |
| 504 if (Dart_IsError(args[0])) return args[0]; | 505 if (Dart_IsError(args[0])) return args[0]; |
| 505 args[1] = Dart_NewInteger(os_error->code()); | 506 args[1] = Dart_NewInteger(os_error->code()); |
| 506 if (Dart_IsError(args[1])) return args[1]; | 507 if (Dart_IsError(args[1])) return args[1]; |
| 507 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); | 508 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); |
| 508 return err; | 509 return err; |
| 509 } | 510 } |
| 510 | 511 |
| 511 | 512 |
| 512 void DartUtils::SetOriginalWorkingDirectory() { | 513 void DartUtils::SetOriginalWorkingDirectory() { |
| 513 original_working_directory = Directory::Current(); | 514 original_working_directory = Directory::Current(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 | 656 |
| 656 CObject* CObject::NewOSError(OSError* os_error) { | 657 CObject* CObject::NewOSError(OSError* os_error) { |
| 657 CObject* error_message = | 658 CObject* error_message = |
| 658 new CObjectString(CObject::NewString(os_error->message())); | 659 new CObjectString(CObject::NewString(os_error->message())); |
| 659 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 660 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 660 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 661 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 661 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 662 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 662 result->SetAt(2, error_message); | 663 result->SetAt(2, error_message); |
| 663 return result; | 664 return result; |
| 664 } | 665 } |
| OLD | NEW |