Loading...
Searching...
No Matches
v8-container.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_CONTAINER_H_
6#define INCLUDE_V8_CONTAINER_H_
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include <functional>
12
13#include "v8-local-handle.h" // NOLINT(build/include_directory)
14#include "v8-object.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17namespace v8 {
18
19class Context;
20class Isolate;
21
25class V8_EXPORT Array : public Object {
26 public:
27 uint32_t Length() const;
28
33 static Local<Array> New(Isolate* isolate, int length = 0);
34
39 static Local<Array> New(Isolate* isolate, Local<Value>* elements,
40 size_t length);
41 V8_INLINE static Array* Cast(Value* value) {
42#ifdef V8_ENABLE_CHECKS
43 CheckCast(value);
44#endif
45 return static_cast<Array*>(value);
46 }
47
61 Local<Context> context, size_t length,
62 std::function<MaybeLocal<v8::Value>()> next_value_callback);
63
64 enum class CallbackResult {
65 kException,
66 kBreak,
67 kContinue,
68 };
69 using IterationCallback = CallbackResult (*)(uint32_t index,
70 Local<Value> element,
71 void* data);
72
89 void* callback_data);
90
91 private:
92 Array();
93 static void CheckCast(Value* obj);
94};
95
99class V8_EXPORT Map : public Object {
100 public:
101 size_t Size() const;
102 void Clear();
104 Local<Value> key);
106 Local<Value> key,
107 Local<Value> value);
109 Local<Value> key);
111 Local<Value> key);
112
118
122 static Local<Map> New(Isolate* isolate);
123
124 V8_INLINE static Map* Cast(Value* value) {
125#ifdef V8_ENABLE_CHECKS
126 CheckCast(value);
127#endif
128 return static_cast<Map*>(value);
129 }
130
131 private:
132 Map();
133 static void CheckCast(Value* obj);
134};
135
139class V8_EXPORT Set : public Object {
140 public:
141 size_t Size() const;
142 void Clear();
144 Local<Value> key);
146 Local<Value> key);
148 Local<Value> key);
149
154
158 static Local<Set> New(Isolate* isolate);
159
160 V8_INLINE static Set* Cast(Value* value) {
161#ifdef V8_ENABLE_CHECKS
162 CheckCast(value);
163#endif
164 return static_cast<Set*>(value);
165 }
166
167 private:
168 Set();
169 static void CheckCast(Value* obj);
170};
171
172} // namespace v8
173
174#endif // INCLUDE_V8_CONTAINER_H_
Definition: v8-container.h:25
static MaybeLocal< Array > New(Local< Context > context, size_t length, std::function< MaybeLocal< v8::Value >()> next_value_callback)
CallbackResult
Definition: v8-container.h:64
static Local< Array > New(Isolate *isolate, Local< Value > *elements, size_t length)
static Local< Array > New(Isolate *isolate, int length=0)
static Array * Cast(Value *value)
Definition: v8-container.h:41
uint32_t Length() const
CallbackResult(*)(uint32_t index, Local< Value > element, void *data) IterationCallback
Definition: v8-container.h:71
Maybe< void > Iterate(Local< Context > context, IterationCallback callback, void *callback_data)
Definition: v8-isolate.h:292
Definition: v8-local-handle.h:366
Definition: v8-container.h:99
void Clear()
Local< Array > AsArray() const
static Local< Map > New(Isolate *isolate)
Maybe< bool > Delete(Local< Context > context, Local< Value > key)
size_t Size() const
MaybeLocal< Value > Get(Local< Context > context, Local< Value > key)
Maybe< bool > Has(Local< Context > context, Local< Value > key)
MaybeLocal< Map > Set(Local< Context > context, Local< Value > key, Local< Value > value)
static Map * Cast(Value *value)
Definition: v8-container.h:124
Definition: v8-local-handle.h:734
Definition: v8-maybe.h:39
Definition: v8-object.h:267
Definition: v8-container.h:139
static Set * Cast(Value *value)
Definition: v8-container.h:160
static Local< Set > New(Isolate *isolate)
void Clear()
Maybe< bool > Delete(Local< Context > context, Local< Value > key)
Local< Array > AsArray() const
Maybe< bool > Has(Local< Context > context, Local< Value > key)
size_t Size() const
MaybeLocal< Set > Add(Local< Context > context, Local< Value > key)
Definition: v8-value.h:32
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:867
#define V8_INLINE
Definition: v8config.h:511
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:681