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

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