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

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

Issue 3007703002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Remove namespace_unsupported.cc Created 3 years, 3 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
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/directory.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 "bin/crypto.h" 7 #include "bin/crypto.h"
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 #include "bin/extensions.h" 9 #include "bin/extensions.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
11 #include "bin/io_buffer.h" 11 #include "bin/io_buffer.h"
12 #include "bin/namespace.h"
12 #include "bin/platform.h" 13 #include "bin/platform.h"
13 #include "bin/utils.h" 14 #include "bin/utils.h"
14 15
15 #include "include/dart_api.h" 16 #include "include/dart_api.h"
16 #include "include/dart_native_api.h" 17 #include "include/dart_native_api.h"
17 #include "include/dart_tools_api.h" 18 #include "include/dart_tools_api.h"
18 19
19 #include "platform/assert.h" 20 #include "platform/assert.h"
20 #include "platform/globals.h" 21 #include "platform/globals.h"
21 #include "platform/memory_sanitizer.h" 22 #include "platform/memory_sanitizer.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 char* DartUtils::DirName(const char* url) { 189 char* DartUtils::DirName(const char* url) {
189 const char* slash = strrchr(url, File::PathSeparator()[0]); 190 const char* slash = strrchr(url, File::PathSeparator()[0]);
190 if (slash == NULL) { 191 if (slash == NULL) {
191 return strdup(url); 192 return strdup(url);
192 } else { 193 } else {
193 return StringUtils::StrNDup(url, slash - url + 1); 194 return StringUtils::StrNDup(url, slash - url + 1);
194 } 195 }
195 } 196 }
196 197
197 void* DartUtils::OpenFile(const char* name, bool write) { 198 void* DartUtils::OpenFile(const char* name, bool write) {
198 File* file = File::Open(name, write ? File::kWriteTruncate : File::kRead); 199 File* file =
200 File::Open(NULL, name, write ? File::kWriteTruncate : File::kRead);
199 return reinterpret_cast<void*>(file); 201 return reinterpret_cast<void*>(file);
200 } 202 }
201 203
202 void DartUtils::ReadFile(const uint8_t** data, intptr_t* len, void* stream) { 204 void DartUtils::ReadFile(const uint8_t** data, intptr_t* len, void* stream) {
203 ASSERT(data != NULL); 205 ASSERT(data != NULL);
204 ASSERT(len != NULL); 206 ASSERT(len != NULL);
205 ASSERT(stream != NULL); 207 ASSERT(stream != NULL);
206 File* file_stream = reinterpret_cast<File*>(stream); 208 File* file_stream = reinterpret_cast<File*>(stream);
207 int64_t file_len = file_stream->Length(); 209 int64_t file_len = file_stream->Length();
208 if ((file_len < 0) || (file_len > kIntptrMax)) { 210 if ((file_len < 0) || (file_len > kIntptrMax)) {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 trace_loading); 523 trace_loading);
522 RETURN_IF_ERROR(result); 524 RETURN_IF_ERROR(result);
523 525
524 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); 526 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib));
525 RETURN_IF_ERROR(PrepareCoreLibrary(core_lib, io_lib, is_service_isolate)); 527 RETURN_IF_ERROR(PrepareCoreLibrary(core_lib, io_lib, is_service_isolate));
526 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); 528 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib));
527 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); 529 RETURN_IF_ERROR(PrepareIOLibrary(io_lib));
528 return result; 530 return result;
529 } 531 }
530 532
531 Dart_Handle DartUtils::SetupIOLibrary(const char* script_uri) { 533 Dart_Handle DartUtils::SetupIOLibrary(const char* namespc_path,
534 const char* script_uri) {
532 Dart_Handle io_lib_url = NewString(kIOLibURL); 535 Dart_Handle io_lib_url = NewString(kIOLibURL);
533 RETURN_IF_ERROR(io_lib_url); 536 RETURN_IF_ERROR(io_lib_url);
534 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); 537 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
535 RETURN_IF_ERROR(io_lib); 538 RETURN_IF_ERROR(io_lib);
539
540 if (namespc_path != NULL) {
541 Dart_Handle namespc_type = GetDartType(DartUtils::kIOLibURL, "_Namespace");
542 RETURN_IF_ERROR(namespc_type);
543 Dart_Handle args[1];
544 args[0] = NewString(namespc_path);
545 RETURN_IF_ERROR(args[0]);
546 Dart_Handle result =
547 Dart_Invoke(namespc_type, NewString("_setupNamespace"), 1, args);
548 RETURN_IF_ERROR(result);
549 }
550
536 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform"); 551 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform");
537 RETURN_IF_ERROR(platform_type); 552 RETURN_IF_ERROR(platform_type);
538 Dart_Handle script_name = NewString("_nativeScript"); 553 Dart_Handle script_name = NewString("_nativeScript");
539 RETURN_IF_ERROR(script_name); 554 RETURN_IF_ERROR(script_name);
540 Dart_Handle dart_script = NewString(script_uri); 555 Dart_Handle dart_script = NewString(script_uri);
541 RETURN_IF_ERROR(dart_script); 556 RETURN_IF_ERROR(dart_script);
542 Dart_Handle set_script_name = 557 Dart_Handle set_script_name =
543 Dart_SetField(platform_type, script_name, dart_script); 558 Dart_SetField(platform_type, script_name, dart_script);
544 RETURN_IF_ERROR(set_script_name); 559 RETURN_IF_ERROR(set_script_name);
545 return Dart_Null(); 560 return Dart_Null();
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 new CObjectString(CObject::NewString(os_error->message())); 964 new CObjectString(CObject::NewString(os_error->message()));
950 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 965 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
951 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 966 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
952 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 967 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
953 result->SetAt(2, error_message); 968 result->SetAt(2, error_message);
954 return result; 969 return result;
955 } 970 }
956 971
957 } // namespace bin 972 } // namespace bin
958 } // namespace dart 973 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/directory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698