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

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

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix 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/namespace.h ('k') | runtime/bin/namespace_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 #if !defined(DART_IO_DISABLED)
6
7 #include "bin/namespace.h"
8
9 #include "bin/builtin.h"
10 #include "bin/dartutils.h"
11 #include "include/dart_api.h"
12 #include "platform/globals.h"
13
14 namespace dart {
15 namespace bin {
16
17 static const int kNamespaceNativeFieldIndex = 0;
18
19 static void ReleaseNamespace(void* isolate_callback_data,
20 Dart_WeakPersistentHandle handle,
21 void* peer) {
22 Namespace* namespc = reinterpret_cast<Namespace*>(peer);
23 namespc->Release();
24 }
25
26 static void AssertIsNamespace(Dart_Handle namespc_obj) {
27 #if defined(DEBUG)
28 Dart_Handle namespc_type =
29 DartUtils::GetDartType("dart:io", "_NamespaceImpl");
30 ASSERT(!Dart_IsError(namespc_type));
31 bool isinstance = false;
32 Dart_Handle result = Dart_ObjectIsType(
33 namespc_obj, namespc_type, &isinstance);
34 ASSERT(!Dart_IsError(result));
35 ASSERT(isinstance);
36 #endif
37 }
38
39 void FUNCTION_NAME(Namespace_Create)(Dart_NativeArguments args) {
40 Dart_Handle namespc_obj = Dart_GetNativeArgument(args, 0);
41 if (Dart_IsError(namespc_obj)) {
42 Dart_PropagateError(namespc_obj);
43 }
44 AssertIsNamespace(namespc_obj);
45
46 // Allocate a native wrapper for the platform namespc bits.
47 Namespace* namespc = NULL;
48 Dart_Handle result;
49 Dart_Handle native_namespc = Dart_GetNativeArgument(args, 1);
50 if (Dart_IsInteger(native_namespc)) {
51 int64_t namespc_val;
52 result = Dart_IntegerToInt64(native_namespc, &namespc_val);
53 if (Dart_IsError(result)) {
54 Dart_PropagateError(result);
55 }
56 namespc = Namespace::Create(namespc_val);
57 } else if (Dart_IsString(native_namespc)) {
58 const char* namespc_path;
59 result = Dart_StringToCString(native_namespc, &namespc_path);
60 if (Dart_IsError(result)) {
61 Dart_PropagateError(result);
62 }
63 namespc = Namespace::Create(namespc_path);
64 } else {
65 // Propagate a type error.
66 Dart_ThrowException(DartUtils::NewDartArgumentError(
67 "Argument must be an int or a String"));
68 }
69
70 // We were unable to create a native Namespace wrapper object due to some
71 // OS-level error.
72 if (namespc == NULL) {
73 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
74 }
75
76 // Set the Dart objects native field to the native wrapper.
77 result = Dart_SetNativeInstanceField(
78 namespc_obj,
79 kNamespaceNativeFieldIndex,
80 reinterpret_cast<intptr_t>(namespc));
81 if (Dart_IsError(result)) {
82 namespc->Release();
83 Dart_PropagateError(result);
84 }
85
86 // Set up a finalizer for the Dart object so that we can do any necessary
87 // platform-specific cleanup for the namespc.
88 Dart_NewWeakPersistentHandle(namespc_obj,
89 reinterpret_cast<void*>(namespc),
90 sizeof(*namespc),
91 ReleaseNamespace);
92 Dart_SetReturnValue(args, namespc_obj);
93 }
94
95 void FUNCTION_NAME(Namespace_GetDefault)(Dart_NativeArguments args) {
96 Dart_SetIntegerReturnValue(args, Namespace::Default());
97 }
98
99 void FUNCTION_NAME(Namespace_GetPointer)(Dart_NativeArguments args) {
100 Namespace* namespc = Namespace::GetNamespace(args, 0);
101 ASSERT(namespc != NULL);
102 namespc->Retain();
103 const intptr_t namespc_pointer = reinterpret_cast<intptr_t>(namespc);
104 Dart_SetIntegerReturnValue(args, namespc_pointer);
105 }
106
107 Namespace* Namespace::GetNamespace(Dart_NativeArguments args, intptr_t index) {
108 Namespace* namespc;
109 Dart_Handle status = Namespace::GetNativeNamespaceArgument(
110 args, index, &namespc);
111 if (Dart_IsError(status)) {
112 Dart_PropagateError(status);
113 }
114 return namespc;
115 }
116
117 bool Namespace::IsDefault(Namespace* namespc) {
118 return (namespc == NULL) || (namespc->namespc() == Namespace::Default());
119 }
120
121 Dart_Handle Namespace::GetNativeNamespaceArgument(Dart_NativeArguments args,
122 intptr_t index,
123 Namespace** namespc) {
124 Dart_Handle namespc_obj = Dart_GetNativeArgument(args, index);
125 if (Dart_IsError(namespc_obj)) {
126 Dart_PropagateError(namespc_obj);
127 }
128 AssertIsNamespace(namespc_obj);
129
130 Dart_Handle result = Dart_GetNativeInstanceField(
131 namespc_obj,
132 kNamespaceNativeFieldIndex,
133 reinterpret_cast<intptr_t*>(namespc));
134 if (Dart_IsError(result)) {
135 return result;
136 }
137 return Dart_Null();
138 }
139
140 } // namespace bin
141 } // namespace dart
142
143 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/namespace.h ('k') | runtime/bin/namespace_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698