v8-primitive-object.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_PRIMITIVE_OBJECT_H_
  5. #define INCLUDE_V8_PRIMITIVE_OBJECT_H_
  6. #include "v8-local-handle.h" // NOLINT(build/include_directory)
  7. #include "v8-object.h" // NOLINT(build/include_directory)
  8. #include "v8config.h" // NOLINT(build/include_directory)
  9. namespace v8 {
  10. class Isolate;
  11. /**
  12. * A Number object (ECMA-262, 4.3.21).
  13. */
  14. class V8_EXPORT NumberObject : public Object {
  15. public:
  16. static Local<Value> New(Isolate* isolate, double value);
  17. double ValueOf() const;
  18. V8_INLINE static NumberObject* Cast(Value* value) {
  19. #ifdef V8_ENABLE_CHECKS
  20. CheckCast(value);
  21. #endif
  22. return static_cast<NumberObject*>(value);
  23. }
  24. private:
  25. static void CheckCast(Value* obj);
  26. };
  27. /**
  28. * A BigInt object (https://tc39.github.io/proposal-bigint)
  29. */
  30. class V8_EXPORT BigIntObject : public Object {
  31. public:
  32. static Local<Value> New(Isolate* isolate, int64_t value);
  33. Local<BigInt> ValueOf() const;
  34. V8_INLINE static BigIntObject* Cast(Value* value) {
  35. #ifdef V8_ENABLE_CHECKS
  36. CheckCast(value);
  37. #endif
  38. return static_cast<BigIntObject*>(value);
  39. }
  40. private:
  41. static void CheckCast(Value* obj);
  42. };
  43. /**
  44. * A Boolean object (ECMA-262, 4.3.15).
  45. */
  46. class V8_EXPORT BooleanObject : public Object {
  47. public:
  48. static Local<Value> New(Isolate* isolate, bool value);
  49. bool ValueOf() const;
  50. V8_INLINE static BooleanObject* Cast(Value* value) {
  51. #ifdef V8_ENABLE_CHECKS
  52. CheckCast(value);
  53. #endif
  54. return static_cast<BooleanObject*>(value);
  55. }
  56. private:
  57. static void CheckCast(Value* obj);
  58. };
  59. /**
  60. * A String object (ECMA-262, 4.3.18).
  61. */
  62. class V8_EXPORT StringObject : public Object {
  63. public:
  64. static Local<Value> New(Isolate* isolate, Local<String> value);
  65. Local<String> ValueOf() const;
  66. V8_INLINE static StringObject* Cast(Value* value) {
  67. #ifdef V8_ENABLE_CHECKS
  68. CheckCast(value);
  69. #endif
  70. return static_cast<StringObject*>(value);
  71. }
  72. private:
  73. static void CheckCast(Value* obj);
  74. };
  75. /**
  76. * A Symbol object (ECMA-262 edition 6).
  77. */
  78. class V8_EXPORT SymbolObject : public Object {
  79. public:
  80. static Local<Value> New(Isolate* isolate, Local<Symbol> value);
  81. Local<Symbol> ValueOf() const;
  82. V8_INLINE static SymbolObject* Cast(Value* value) {
  83. #ifdef V8_ENABLE_CHECKS
  84. CheckCast(value);
  85. #endif
  86. return static_cast<SymbolObject*>(value);
  87. }
  88. private:
  89. static void CheckCast(Value* obj);
  90. };
  91. } // namespace v8
  92. #endif // INCLUDE_V8_PRIMITIVE_OBJECT_H_