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

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

Issue 15966002: Add support for loading scripts from http (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | « runtime/bin/dartutils.h ('k') | runtime/bin/socket.h » ('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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
11 11
12 #include "bin/extensions.h" 12 #include "bin/extensions.h"
13 #include "bin/directory.h" 13 #include "bin/directory.h"
14 #include "bin/file.h" 14 #include "bin/file.h"
15 #include "bin/io_buffer.h" 15 #include "bin/io_buffer.h"
16 #include "bin/utils.h" 16 #include "bin/utils.h"
17 #include "bin/socket.h"
17 18
18 namespace dart { 19 namespace dart {
19 namespace bin { 20 namespace bin {
20 21
21 const char* DartUtils::original_working_directory = NULL; 22 const char* DartUtils::original_working_directory = NULL;
22 const char* DartUtils::kDartScheme = "dart:"; 23 const char* DartUtils::kDartScheme = "dart:";
23 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; 24 const char* DartUtils::kDartExtensionScheme = "dart-ext:";
24 const char* DartUtils::kAsyncLibURL = "dart:async"; 25 const char* DartUtils::kAsyncLibURL = "dart:async";
25 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; 26 const char* DartUtils::kBuiltinLibURL = "dart:builtin";
26 const char* DartUtils::kCoreLibURL = "dart:core"; 27 const char* DartUtils::kCoreLibURL = "dart:core";
27 const char* DartUtils::kIOLibURL = "dart:io"; 28 const char* DartUtils::kIOLibURL = "dart:io";
28 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; 29 const char* DartUtils::kIOLibPatchURL = "dart:io-patch";
30 const char* DartUtils::kUriLibURL = "dart:uri";
31 const char* DartUtils::kHttpScheme = "http:";
29 32
30 const char* DartUtils::kIdFieldName = "_id"; 33 const char* DartUtils::kIdFieldName = "_id";
31 34
32 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; 35 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc };
33 36
34 static bool IsWindowsHost() { 37 static bool IsWindowsHost() {
35 #if defined(TARGET_OS_WINDOWS) 38 #if defined(TARGET_OS_WINDOWS)
36 return true; 39 return true;
37 #else // defined(TARGET_OS_WINDOWS) 40 #else // defined(TARGET_OS_WINDOWS)
38 return false; 41 return false;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 137
135 138
136 bool DartUtils::IsDartSchemeURL(const char* url_name) { 139 bool DartUtils::IsDartSchemeURL(const char* url_name) {
137 static const intptr_t kDartSchemeLen = strlen(kDartScheme); 140 static const intptr_t kDartSchemeLen = strlen(kDartScheme);
138 // If the URL starts with "dart:" then it is considered as a special 141 // If the URL starts with "dart:" then it is considered as a special
139 // library URL which is handled differently from other URLs. 142 // library URL which is handled differently from other URLs.
140 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); 143 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0);
141 } 144 }
142 145
143 146
147 bool DartUtils::IsHttpSchemeURL(const char* url_name) {
148 static const intptr_t kHttpSchemeLen = strlen(kHttpScheme);
149 return (strncmp(url_name, kHttpScheme, kHttpSchemeLen) == 0);
150 }
151
152
144 bool DartUtils::IsDartExtensionSchemeURL(const char* url_name) { 153 bool DartUtils::IsDartExtensionSchemeURL(const char* url_name) {
145 static const intptr_t kDartExtensionSchemeLen = strlen(kDartExtensionScheme); 154 static const intptr_t kDartExtensionSchemeLen = strlen(kDartExtensionScheme);
146 // If the URL starts with "dartext:" then it is considered as a special 155 // If the URL starts with "dartext:" then it is considered as a special
147 // extension library URL which is handled differently from other URLs. 156 // extension library URL which is handled differently from other URLs.
148 return 157 return
149 (strncmp(url_name, kDartExtensionScheme, kDartExtensionSchemeLen) == 0); 158 (strncmp(url_name, kDartExtensionScheme, kDartExtensionSchemeLen) == 0);
150 } 159 }
151 160
152 161
153 bool DartUtils::IsDartIOLibURL(const char* url_name) { 162 bool DartUtils::IsDartIOLibURL(const char* url_name) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 bool bytes_written = file_stream->WriteFully(buffer, num_bytes); 235 bool bytes_written = file_stream->WriteFully(buffer, num_bytes);
227 ASSERT(bytes_written); 236 ASSERT(bytes_written);
228 } 237 }
229 238
230 239
231 void DartUtils::CloseFile(void* stream) { 240 void DartUtils::CloseFile(void* stream) {
232 delete reinterpret_cast<File*>(stream); 241 delete reinterpret_cast<File*>(stream);
233 } 242 }
234 243
235 244
245 // Writes string into socket.
246 // Return < 0 indicates an error.
247 // Return >= 0 number of bytes written.
248 static intptr_t SocketWriteString(intptr_t socket, const char* str,
249 intptr_t len) {
250 int r;
251 intptr_t cursor = 0;
252 do {
253 r = Socket::Write(socket, &str[cursor], len);
254 if (r < 0) {
255 return r;
256 }
257 cursor += r;
258 len -= r;
259 } while (len > 0);
260 ASSERT(len == 0);
261 return cursor;
262 }
263
264
265 static uint8_t* SocketReadUntilEOF(intptr_t socket, intptr_t* response_len) {
266 const intptr_t kInitialBufferSize = 16 * KB;
267 intptr_t buffer_size = kInitialBufferSize;
268 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(buffer_size));
269 ASSERT(buffer != NULL);
270 intptr_t buffer_cursor = 0;
271 do {
272 ssize_t bytes_read = Socket::Read(socket, &buffer[buffer_cursor],
273 buffer_size - buffer_cursor - 1);
274 if (bytes_read < 0) {
275 free(buffer);
276 return NULL;
277 }
278
279 buffer_cursor += bytes_read;
280
281 if (bytes_read == 0) {
282 *response_len = buffer_cursor;
283 buffer[buffer_cursor] = '\0';
284 break;
285 }
286
287 // There is still more data to be read, check that we have room in the
288 // buffer for more data.
289 if (buffer_cursor == buffer_size - 1) {
290 // Buffer is full. Increase buffer size.
291 buffer_size *= 2;
292 buffer = reinterpret_cast<uint8_t*>(realloc(buffer, buffer_size));
293 ASSERT(buffer != NULL);
294 }
295 } while (true);
296 return buffer;
297 }
298
299
300 static bool HttpGetRequestOkay(const char* response) {
301 static const char* kOkayReply = "HTTP/1.0 200 OK";
302 static const intptr_t kOkayReplyLen = strlen(kOkayReply);
303 return (strncmp(response, kOkayReply, kOkayReplyLen) == 0);
304 }
305
306
307 static const uint8_t* HttpRequestGetPayload(const char* response) {
308 const char* split = strstr(response, "\r\n\r\n");
309 if (split != NULL) {
310 return reinterpret_cast<const uint8_t*>(split+4);
311 }
312 return NULL;
313 }
314
315
316 // TODO(iposva): Allocate from the zone instead of leaking error string
317 // here. On the other hand the binary is about the exit anyway.
318 #define SET_ERROR_MSG(error_msg, format, ...) \
319 intptr_t len = snprintf(NULL, 0, format, __VA_ARGS__); \
320 char *msg = reinterpret_cast<char*>(malloc(len + 1)); \
321 snprintf(msg, len + 1, format, __VA_ARGS__); \
322 *error_msg = msg
323
324
325 static const uint8_t* HttpGetRequest(const char* host, const char* path,
326 int port, intptr_t* response_len,
327 const char** error_msg) {
328 OSError* error = NULL;
329 SocketAddresses* addresses = Socket::LookupAddress(host, -1, &error);
330 if (addresses == NULL || addresses->count() == 0) {
331 SET_ERROR_MSG(error_msg, "Unable to resolve %s", host);
332 return NULL;
333 }
334
335 int preferred_address = 0;
336 for (int i = 0; i < addresses->count(); i++) {
337 SocketAddress* address = addresses->GetAt(i);
338 if (address->GetType() == SocketAddress::ADDRESS_LOOPBACK_IP_V4) {
339 // Prefer the IP_V4 loop back.
340 preferred_address = i;
341 break;
342 }
343 }
344
345 RawAddr addr = addresses->GetAt(preferred_address)->addr();
346 intptr_t tcp_client = Socket::Create(addr);
347 if (tcp_client < 0) {
348 SET_ERROR_MSG(error_msg, "Unable to create socket to %s:%d", host, port);
349 return NULL;
350 }
351 Socket::Connect(tcp_client, addr, port);
352 if (tcp_client < 0) {
353 SET_ERROR_MSG(error_msg, "Unable to connect to %s:%d", host, port);
354 return NULL;
355 }
356 // Send get request.
357 {
358 const char* format =
359 "GET %s HTTP/1.0\r\nUser-Agent: Dart VM\r\nHost: %s\r\n\r\n";
360 intptr_t len = snprintf(NULL, 0, format, path, host);
361 char* get_request = reinterpret_cast<char*>(malloc(len + 1));
362 snprintf(get_request, len + 1, format, path, host);
363 intptr_t r = SocketWriteString(tcp_client, get_request, len);
364 free(get_request);
365 if (r < len) {
366 SET_ERROR_MSG(error_msg, "Unable to write to %s:%d - %d", host, port,
367 static_cast<int>(r));
368 Socket::Close(tcp_client);
369 return NULL;
370 }
371 ASSERT(r == len);
372 }
373 // Consume response.
374 uint8_t* response = SocketReadUntilEOF(tcp_client, response_len);
375 // Close socket.
376 Socket::Close(tcp_client);
377 if (response == NULL) {
378 SET_ERROR_MSG(error_msg, "Unable to read from %s:%d", host, port);
379 return NULL;
380 }
381 if (HttpGetRequestOkay(reinterpret_cast<const char*>(response)) == false) {
382 SET_ERROR_MSG(error_msg, "Invalid HTTP response from %s:%d", host, port);
383 free(response);
384 return NULL;
385 }
386 return response;
387 }
388
389
390 static Dart_Handle ParseHttpUri(const char* script_uri, const char** host_str,
391 int64_t* port_int, const char** path_str) {
392 ASSERT(script_uri != NULL);
393 ASSERT(host_str != NULL);
394 ASSERT(port_int != NULL);
395 ASSERT(path_str != NULL);
396 Dart_Handle result;
397 Dart_Handle uri = DartUtils::NewString(script_uri);
398 Dart_Handle builtin_lib =
399 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
400 Dart_Handle path = DartUtils::PathFromUri(uri, builtin_lib);
401 if (Dart_IsError(path)) {
402 return path;
403 }
404 Dart_Handle host = DartUtils::DomainFromUri(uri, builtin_lib);
405 if (Dart_IsError(host)) {
406 return host;
407 }
408 Dart_Handle port = DartUtils::PortFromUri(uri, builtin_lib);
409 if (Dart_IsError(port)) {
410 return port;
411 }
412 result = Dart_StringToCString(path, path_str);
413 if (Dart_IsError(result)) {
414 return result;
415 }
416 result = Dart_StringToCString(host, host_str);
417 if (Dart_IsError(result)) {
418 return result;
419 }
420 if (DartUtils::GetInt64Value(port, port_int) == false) {
421 return Dart_Error("Invalid port");
422 }
423 return result;
424 }
425
426
427 Dart_Handle DartUtils::ReadStringFromHttp(const char* script_uri) {
428 const char* host_str = NULL;
429 int64_t port_int = 0;
430 const char* path_str = NULL;
431 Dart_Handle result = ParseHttpUri(script_uri, &host_str, &port_int,
432 &path_str);
433 if (Dart_IsError(result)) {
434 return result;
435 }
436 const char* error_msg = NULL;
437 intptr_t len;
438 const uint8_t* text_buffer = HttpGetRequest(host_str, path_str, port_int,
439 &len, &error_msg);
440 if (text_buffer == NULL) {
441 return Dart_Error(error_msg);
442 }
443 const uint8_t* payload = HttpRequestGetPayload(
444 reinterpret_cast<const char*>(text_buffer));
445 if (payload == NULL) {
446 return Dart_Error("Invalid HTTP response.");
447 }
448 // Subtract HTTP response from length.
449 len -= (payload-text_buffer);
450 ASSERT(len >= 0);
451 Dart_Handle str = Dart_NewStringFromUTF8(payload, len);
452 return str;
453 }
454
455
236 static const uint8_t* ReadFileFully(const char* filename, 456 static const uint8_t* ReadFileFully(const char* filename,
237 intptr_t* file_len, 457 intptr_t* file_len,
238 const char** error_msg) { 458 const char** error_msg) {
239 void* stream = DartUtils::OpenFile(filename, false); 459 void* stream = DartUtils::OpenFile(filename, false);
240 if (stream == NULL) { 460 if (stream == NULL) {
241 const char* format = "Unable to open file: %s"; 461 SET_ERROR_MSG(error_msg, "Unable to open file: %s", filename);
242 intptr_t len = snprintf(NULL, 0, format, filename);
243 // TODO(iposva): Allocate from the zone instead of leaking error string
244 // here. On the other hand the binary is about the exit anyway.
245 char* msg = reinterpret_cast<char*>(malloc(len + 1));
246 snprintf(msg, len + 1, format, filename);
247 *error_msg = msg;
248 return NULL; 462 return NULL;
249 } 463 }
250 *file_len = -1; 464 *file_len = -1;
251 const uint8_t* text_buffer = NULL; 465 const uint8_t* text_buffer = NULL;
252 DartUtils::ReadFile(&text_buffer, file_len, stream); 466 DartUtils::ReadFile(&text_buffer, file_len, stream);
253 if (text_buffer == NULL || *file_len == -1) { 467 if (text_buffer == NULL || *file_len == -1) {
254 *error_msg = "Unable to read file contents"; 468 *error_msg = "Unable to read file contents";
255 text_buffer = NULL; 469 text_buffer = NULL;
256 } 470 }
257 DartUtils::CloseFile(stream); 471 DartUtils::CloseFile(stream);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 Dart_Handle dart_args[kNumArgs]; 505 Dart_Handle dart_args[kNumArgs];
292 dart_args[0] = script_uri; 506 dart_args[0] = script_uri;
293 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); 507 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False());
294 return Dart_Invoke(builtin_lib, 508 return Dart_Invoke(builtin_lib,
295 NewString("_filePathFromUri"), 509 NewString("_filePathFromUri"),
296 kNumArgs, 510 kNumArgs,
297 dart_args); 511 dart_args);
298 } 512 }
299 513
300 514
515 static Dart_Handle SingleArgDart_Invoke(Dart_Handle arg, Dart_Handle lib,
516 const char* method) {
517 const int kNumArgs = 1;
518 Dart_Handle dart_args[kNumArgs];
519 dart_args[0] = arg;
520 return Dart_Invoke(lib, DartUtils::NewString(method), kNumArgs, dart_args);
521 }
522
523 Dart_Handle DartUtils::PathFromUri(Dart_Handle script_uri,
524 Dart_Handle builtin_lib) {
525 return SingleArgDart_Invoke(script_uri, builtin_lib, "_pathFromHttpUri");
526 }
527
528
529 Dart_Handle DartUtils::DomainFromUri(Dart_Handle script_uri,
530 Dart_Handle builtin_lib) {
531 return SingleArgDart_Invoke(script_uri, builtin_lib, "_domainFromHttpUri");
532 }
533
534
535 Dart_Handle DartUtils::PortFromUri(Dart_Handle script_uri,
536 Dart_Handle builtin_lib) {
537 return SingleArgDart_Invoke(script_uri, builtin_lib, "_portFromHttpUri");
538 }
539
540
301 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, 541 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url,
302 Dart_Handle url, 542 Dart_Handle url,
303 Dart_Handle builtin_lib) { 543 Dart_Handle builtin_lib) {
304 const int kNumArgs = 2; 544 const int kNumArgs = 2;
305 Dart_Handle dart_args[kNumArgs]; 545 Dart_Handle dart_args[kNumArgs];
306 dart_args[0] = library_url; 546 dart_args[0] = library_url;
307 dart_args[1] = url; 547 dart_args[1] = url;
308 return Dart_Invoke( 548 return Dart_Invoke(
309 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); 549 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args);
310 } 550 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 658 }
419 659
420 660
421 void DartUtils::WriteMagicNumber(File* file) { 661 void DartUtils::WriteMagicNumber(File* file) {
422 // Write a magic number and version information into the snapshot file. 662 // Write a magic number and version information into the snapshot file.
423 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); 663 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number));
424 ASSERT(bytes_written); 664 ASSERT(bytes_written);
425 } 665 }
426 666
427 667
668 Dart_Handle DartUtils::LoadScriptHttp(const char* script_uri,
669 Dart_Handle builtin_lib) {
670 Dart_Handle uri = NewString(script_uri);
671 if (Dart_IsError(uri)) {
672 return uri;
673 }
674 const char* host_str = NULL;
675 int64_t port_int = 0;
676 const char* path_str = NULL;
677 Dart_Handle result = ParseHttpUri(script_uri, &host_str, &port_int,
678 &path_str);
679 if (Dart_IsError(result)) {
680 return result;
681 }
682 const char* error_msg = NULL;
683 intptr_t len;
684 const uint8_t* text_buffer;
685 text_buffer = HttpGetRequest(host_str, path_str, port_int, &len,
686 &error_msg);
687 if (text_buffer == NULL) {
688 return Dart_Error(error_msg);
689 }
690 const uint8_t* payload = HttpRequestGetPayload(
691 reinterpret_cast<const char*>(text_buffer));
692 if (payload == NULL) {
693 return Dart_Error("Invalid HTTP response.");
694 }
695 // Subtract HTTP response from length.
696 len -= (payload-text_buffer);
697 ASSERT(len >= 0);
698 // At this point we have received a valid HTTP 200 reply and
699 // payload points at the beginning of the script or snapshot.
700 bool is_snapshot = false;
701 payload = SniffForMagicNumber(payload, &len, &is_snapshot);
702 if (is_snapshot) {
703 return Dart_LoadScriptFromSnapshot(payload, len);
704 } else {
705 Dart_Handle source = Dart_NewStringFromUTF8(payload, len);
706 if (Dart_IsError(source)) {
707 return source;
708 }
709 return Dart_LoadScript(uri, source, 0, 0);
710 }
711 }
712
713
428 Dart_Handle DartUtils::LoadScript(const char* script_uri, 714 Dart_Handle DartUtils::LoadScript(const char* script_uri,
429 Dart_Handle builtin_lib) { 715 Dart_Handle builtin_lib) {
716 if (DartUtils::IsHttpSchemeURL(script_uri)) {
717 return LoadScriptHttp(script_uri, builtin_lib);
718 }
430 Dart_Handle resolved_script_uri; 719 Dart_Handle resolved_script_uri;
431 resolved_script_uri = ResolveScriptUri(NewString(script_uri), builtin_lib); 720 resolved_script_uri = ResolveScriptUri(NewString(script_uri), builtin_lib);
432 if (Dart_IsError(resolved_script_uri)) { 721 if (Dart_IsError(resolved_script_uri)) {
433 return resolved_script_uri; 722 return resolved_script_uri;
434 } 723 }
435 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri, 724 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri,
436 builtin_lib); 725 builtin_lib);
437 if (Dart_IsError(script_path)) { 726 if (Dart_IsError(script_path)) {
438 return script_path; 727 return script_path;
439 } 728 }
(...skipping 19 matching lines...) Expand all
459 return Dart_LoadScript(resolved_script_uri, source, 0, 0); 748 return Dart_LoadScript(resolved_script_uri, source, 0, 0);
460 } 749 }
461 } 750 }
462 751
463 752
464 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping, 753 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping,
465 Dart_Handle library, 754 Dart_Handle library,
466 Dart_Handle url, 755 Dart_Handle url,
467 Dart_LibraryTag tag, 756 Dart_LibraryTag tag,
468 const char* url_string) { 757 const char* url_string) {
758 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string);
469 if (url_mapping != NULL && IsDartSchemeURL(url_string)) { 759 if (url_mapping != NULL && IsDartSchemeURL(url_string)) {
470 const char* mapped_url_string = MapLibraryUrl(url_mapping, url_string); 760 const char* mapped_url_string = MapLibraryUrl(url_mapping, url_string);
471 if (mapped_url_string == NULL) { 761 if (mapped_url_string == NULL) {
472 return Dart_Error("Do not know how to load %s", url_string); 762 return Dart_Error("Do not know how to load %s", url_string);
473 } 763 }
474 // We have a URL mapping specified, just read the file that the 764 // We have a URL mapping specified, just read the file that the
475 // URL mapping specifies and load it. 765 // URL mapping specifies and load it.
476 url_string = mapped_url_string; 766 url_string = mapped_url_string;
477 } 767 }
478 // The tag is either an import or a source tag. 768 Dart_Handle source;
479 // Read the file and load it according to the specified tag. 769 if (is_http_scheme_url) {
480 Dart_Handle source = DartUtils::ReadStringFromFile(url_string); 770 // Read the file over http.
771 source = DartUtils::ReadStringFromHttp(url_string);
772 } else {
773 // Read the file.
774 source = DartUtils::ReadStringFromFile(url_string);
775 }
481 if (Dart_IsError(source)) { 776 if (Dart_IsError(source)) {
482 return source; // source contains the error string. 777 return source; // source contains the error string.
483 } 778 }
779 // The tag is either an import or a source tag.
780 // Load it according to the specified tag.
484 if (tag == kImportTag) { 781 if (tag == kImportTag) {
485 // Return library object or an error string. 782 // Return library object or an error string.
486 return Dart_LoadLibrary(url, source); 783 return Dart_LoadLibrary(url, source);
487 } else if (tag == kSourceTag) { 784 } else if (tag == kSourceTag) {
488 return Dart_LoadSource(library, url, source); 785 return Dart_LoadSource(library, url, source);
489 } 786 }
490 return Dart_Error("wrong tag"); 787 return Dart_Error("wrong tag");
491 } 788 }
492 789
493 790
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 new CObjectString(CObject::NewString(os_error->message())); 1103 new CObjectString(CObject::NewString(os_error->message()));
807 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1104 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
808 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1105 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
809 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1106 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
810 result->SetAt(2, error_message); 1107 result->SetAt(2, error_message);
811 return result; 1108 return result;
812 } 1109 }
813 1110
814 } // namespace bin 1111 } // namespace bin
815 } // namespace dart 1112 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698