• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SRC_NODE_URL_H_
2 #define SRC_NODE_URL_H_
3 
4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5 
6 #include <cinttypes>
7 #include "ada.h"
8 #include "aliased_buffer.h"
9 #include "node.h"
10 #include "node_snapshotable.h"
11 #include "util.h"
12 
13 #include <string>
14 
15 namespace node {
16 class ExternalReferenceRegistry;
17 
18 namespace url {
19 
20 enum url_update_action {
21   kProtocol = 0,
22   kHost = 1,
23   kHostname = 2,
24   kPort = 3,
25   kUsername = 4,
26   kPassword = 5,
27   kPathname = 6,
28   kSearch = 7,
29   kHash = 8,
30   kHref = 9,
31 };
32 
33 class BindingData : public SnapshotableObject {
34  public:
35   explicit BindingData(Realm* realm, v8::Local<v8::Object> obj);
36 
37   using InternalFieldInfo = InternalFieldInfoBase;
38 
SERIALIZABLE_OBJECT_METHODS()39   SERIALIZABLE_OBJECT_METHODS()
40   static constexpr FastStringKey type_name{"node::url::BindingData"};
41   static constexpr EmbedderObjectType type_int =
42       EmbedderObjectType::k_url_binding_data;
43 
44   void MemoryInfo(MemoryTracker* tracker) const override;
45   SET_SELF_SIZE(BindingData)
46   SET_MEMORY_INFO_NAME(BindingData)
47 
48   static void ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
49   static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);
50 
51   static void DomainToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
52   static void DomainToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);
53 
54   static void CanParse(const v8::FunctionCallbackInfo<v8::Value>& args);
55   static void Format(const v8::FunctionCallbackInfo<v8::Value>& args);
56   static void Parse(const v8::FunctionCallbackInfo<v8::Value>& args);
57   static void Update(const v8::FunctionCallbackInfo<v8::Value>& args);
58 
59   static void Initialize(v8::Local<v8::Object> target,
60                          v8::Local<v8::Value> unused,
61                          v8::Local<v8::Context> context,
62                          void* priv);
63   static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
64 
65  private:
66   static constexpr size_t kURLComponentsLength = 9;
67   AliasedUint32Array url_components_buffer_;
68 
69   void UpdateComponents(const ada::url_components& components,
70                         const ada::scheme::type type);
71 };
72 
73 std::string FromFilePath(const std::string_view file_path);
74 
75 }  // namespace url
76 
77 }  // namespace node
78 
79 #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
80 
81 #endif  // SRC_NODE_URL_H_
82