Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef RUNTIME_BIN_NAMESPACE_H_ | |
| 6 #define RUNTIME_BIN_NAMESPACE_H_ | |
| 7 | |
| 8 #include "bin/builtin.h" | |
| 9 #include "bin/dartutils.h" | |
| 10 #include "bin/log.h" | |
| 11 #include "bin/reference_counting.h" | |
| 12 | |
| 13 namespace dart { | |
| 14 namespace bin { | |
| 15 | |
| 16 class Namespace : public ReferenceCounted<Namespace> { | |
| 17 public: | |
| 18 // Assumes napespc is a value that can be directly used as namespc_. | |
|
siva
2017/08/29 16:47:39
namespc
zra
2017/08/29 20:22:52
Done.
| |
| 19 static Namespace* Create(intptr_t namespc) { return new Namespace(namespc); } | |
| 20 | |
| 21 // Uses path to compute a value that can be used as namespc_. | |
| 22 static Namespace* Create(const char* path); | |
| 23 | |
| 24 // Gives a safe defautl value for namespc_ for the standalone Dart VM. | |
|
siva
2017/08/29 16:47:39
default
zra
2017/08/29 20:22:51
Done.
| |
| 25 static intptr_t Default(); | |
| 26 | |
| 27 // Tells whether the given namespace is the default namespace. | |
| 28 static bool IsDefault(Namespace* namespc); | |
| 29 | |
| 30 // Returns the native namespace wrapper if the argument at the supplied index | |
| 31 // is a _NamespaceImpl object. If it is not, calls Dart_PropagateError(). | |
| 32 static Namespace* GetNamespace(Dart_NativeArguments args, intptr_t index); | |
| 33 | |
| 34 // Get and set the current working directory through the namespace if there | |
| 35 // is one. | |
| 36 static const char* GetCurrent(Namespace* namespc); | |
| 37 static bool SetCurrent(Namespace* namespc, const char* path); | |
| 38 | |
| 39 intptr_t namespc() const { return namespc_; } | |
| 40 | |
| 41 private: | |
| 42 // When namespc_ has this value, it indicates that there is currently | |
| 43 // no namespace for resolving absolute paths. | |
| 44 static const intptr_t kNone = 0; | |
| 45 | |
| 46 explicit Namespace(intptr_t namespc) | |
| 47 : ReferenceCounted(), namespc_(namespc) {} | |
| 48 | |
| 49 ~Namespace(); | |
| 50 | |
| 51 // When the native argument at |index| is a _NamespaceImpl object, | |
| 52 // write the valueof its native field into |namespc|. | |
| 53 static Dart_Handle GetNativeNamespaceArgument(Dart_NativeArguments args, | |
| 54 intptr_t index, | |
| 55 Namespace** namespc); | |
| 56 | |
| 57 // Given a namespace and a path, computes the information needed to access the | |
| 58 // path relative to the namespace. This can include massaging the path and | |
| 59 // returning a platform specific value in dirfd that together are used to | |
| 60 // access the path. Returns true if the caller should take ownership of | |
| 61 // dirfd, and false if the namespace retains ownership of dirfd. | |
| 62 static bool ResolvePath(Namespace* namespc, | |
| 63 const char* path, | |
| 64 intptr_t* dirfd, | |
| 65 const char** resolved_path); | |
| 66 | |
| 67 intptr_t namespc_; | |
| 68 // TODO(zra): When Isolate-specific cwds are added, we'll need some more | |
| 69 // fields here to track them. | |
| 70 | |
| 71 friend class NamespaceScope; | |
| 72 friend class ReferenceCounted<Namespace>; | |
| 73 DISALLOW_COPY_AND_ASSIGN(Namespace); | |
| 74 }; | |
| 75 | |
| 76 class NamespaceScope { | |
| 77 public: | |
| 78 explicit NamespaceScope(Namespace* namespc, const char* path); | |
|
siva
2017/08/29 16:47:39
Why explicit for this constructor, seems to have 2
zra
2017/08/29 20:22:51
Oops. Leftover after a refactor. Removed.
| |
| 79 ~NamespaceScope(); | |
| 80 | |
| 81 intptr_t fd() const { return fd_; } | |
| 82 const char* path() const { return path_; } | |
| 83 | |
| 84 private: | |
| 85 intptr_t fd_; | |
| 86 const char* path_; | |
| 87 bool owns_fd_; | |
| 88 | |
| 89 DISALLOW_ALLOCATION(); | |
| 90 DISALLOW_COPY_AND_ASSIGN(NamespaceScope); | |
| 91 }; | |
| 92 | |
| 93 } // namespace bin | |
| 94 } // namespace dart | |
| 95 | |
| 96 #endif // RUNTIME_BIN_NAMESPACE_H_ | |
| OLD | NEW |