v8-data.h 1.6 KB

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