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);
112 Local<Value> Get(Local<Value> key, bool* found) const;
114 Local<Value> key,
115 Local<Value> value);
117 Local<Value> key);
119 Local<Value> key);
120
126
130 static Local<Map> New(Isolate* isolate);
131
132 V8_INLINE static Map* Cast(Value* value) {
133#ifdef V8_ENABLE_CHECKS
134 CheckCast(value);
135#endif
136 return static_cast<Map*>(value);
137 }
138
139 private:
140 Map();
141 static void CheckCast(Value* obj);
142};
143
147class V8_EXPORT Set : public Object {
148 public:
149 size_t Size() const;
150 void Clear();
152 Local<Value> key);
154 Local<Value> key);
156 Local<Value> key);
157
162
166 static Local<Set> New(Isolate* isolate);
167
168 V8_INLINE static Set* Cast(Value* value) {
169#ifdef V8_ENABLE_CHECKS
170 CheckCast(value);
171#endif
172 return static_cast<Set*>(value);
173 }
174
175 private:
176 Set();
177 static void CheckCast(Value* obj);
178};
179
180} // namespace v8
181
182#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:305
Definition: v8-local-handle.h:359
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)
Local< Value > Get(Local< Value > key, bool *found) const
static Map * Cast(Value *value)
Definition: v8-container.h:132
Definition: v8-local-handle.h:730
Definition: v8-maybe.h:39
Definition: v8-object.h:265
Definition: v8-container.h:147
static Set * Cast(Value *value)
Definition: v8-container.h:168
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:875
#define V8_INLINE
Definition: v8config.h:519
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:689