v8  10.1.124 (node 18.2.0)
V8 is Google's open source JavaScript engine
v8-data.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_DATA_H_
6 #define INCLUDE_V8_DATA_H_
7 
8 #include "v8-local-handle.h" // NOLINT(build/include_directory)
9 #include "v8config.h" // NOLINT(build/include_directory)
10 
11 namespace v8 {
12 
13 class Context;
14 
15 /**
16  * The superclass of objects that can reside on V8's heap.
17  */
18 class V8_EXPORT Data {
19  public:
20  /**
21  * Returns true if this data is a |v8::Value|.
22  */
23  bool IsValue() const;
24 
25  /**
26  * Returns true if this data is a |v8::Module|.
27  */
28  bool IsModule() const;
29 
30  /**
31  * Returns tru if this data is a |v8::FixedArray|
32  */
33  bool IsFixedArray() const;
34 
35  /**
36  * Returns true if this data is a |v8::Private|.
37  */
38  bool IsPrivate() const;
39 
40  /**
41  * Returns true if this data is a |v8::ObjectTemplate|.
42  */
43  bool IsObjectTemplate() const;
44 
45  /**
46  * Returns true if this data is a |v8::FunctionTemplate|.
47  */
48  bool IsFunctionTemplate() const;
49 
50  /**
51  * Returns true if this data is a |v8::Context|.
52  */
53  bool IsContext() const;
54 
55  private:
56  Data();
57 };
58 
59 /**
60  * A fixed-sized array with elements of type Data.
61  */
62 class V8_EXPORT FixedArray : public Data {
63  public:
64  int Length() const;
65  Local<Data> Get(Local<Context> context, int i) const;
66 
67  V8_INLINE static FixedArray* Cast(Data* data) {
68 #ifdef V8_ENABLE_CHECKS
69  CheckCast(data);
70 #endif
71  return reinterpret_cast<FixedArray*>(data);
72  }
73 
74  private:
75  static void CheckCast(Data* obj);
76 };
77 
78 } // namespace v8
79 
80 #endif // INCLUDE_V8_DATA_H_