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
98 void* callback_data);
99
100 private:
101 Array();
102 static void CheckCast(Value* obj);
103};
104
108class V8_EXPORT Map : public Object {
109 public:
110 size_t Size() const;
111 void Clear();
113 Local<Value> key);
115 Local<Value> key,
116 Local<Value> value);
118 Local<Value> key);
120 Local<Value> key);
121
127
131 static Local<Map> New(Isolate* isolate);
132
133 V8_INLINE static Map* Cast(Value* value) {
134#ifdef V8_ENABLE_CHECKS
135 CheckCast(value);
136#endif
137 return static_cast<Map*>(value);
138 }
139
140 private:
141 Map();
142 static void CheckCast(Value* obj);
143};
144
148class V8_EXPORT Set : public Object {
149 public:
150 size_t Size() const;
151 void Clear();
153 Local<Value> key);
155 Local<Value> key);
157 Local<Value> key);
158
163
167 static Local<Set> New(Isolate* isolate);
168
169 V8_INLINE static Set* Cast(Value* value) {
170#ifdef V8_ENABLE_CHECKS
171 CheckCast(value);
172#endif
173 return static_cast<Set*>(value);
174 }
175
176 private:
177 Set();
178 static void CheckCast(Value* obj);
179};
180
181} // namespace v8
182
183#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:261
Definition: v8-local-handle.h:266
Definition: v8-container.h:108
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:133
Definition: v8-local-handle.h:632
Definition: v8-maybe.h:32
Definition: v8-object.h:233
Definition: v8-container.h:148
static Set * Cast(Value *value)
Definition: v8-container.h:169
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:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:660