nan_scriptorigin.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*********************************************************************
  2. * NAN - Native Abstractions for Node.js
  3. *
  4. * Copyright (c) 2021 NAN contributors
  5. *
  6. * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
  7. ********************************************************************/
  8. #ifndef NAN_SCRIPTORIGIN_H_
  9. #define NAN_SCRIPTORIGIN_H_
  10. class ScriptOrigin : public v8::ScriptOrigin {
  11. public:
  12. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 11 \
  13. && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 7)
  14. explicit ScriptOrigin(v8::Local<v8::Value> name) :
  15. v8::ScriptOrigin(name) {}
  16. ScriptOrigin(v8::Local<v8::Value> name
  17. , v8::Local<v8::Integer> line) :
  18. v8::ScriptOrigin(name
  19. , To<int32_t>(line).FromMaybe(0)) {}
  20. ScriptOrigin(v8::Local<v8::Value> name
  21. , v8::Local<v8::Integer> line
  22. , v8::Local<v8::Integer> column) :
  23. v8::ScriptOrigin(name
  24. , To<int32_t>(line).FromMaybe(0)
  25. , To<int32_t>(column).FromMaybe(0)) {}
  26. #elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \
  27. (V8_MAJOR_VERSION == 9 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 0\
  28. || (V8_MINOR_VERSION == 0 && defined(V8_BUILD_NUMBER) \
  29. && V8_BUILD_NUMBER >= 1)))))
  30. explicit ScriptOrigin(v8::Local<v8::Value> name) :
  31. v8::ScriptOrigin(v8::Isolate::GetCurrent(), name) {}
  32. ScriptOrigin(v8::Local<v8::Value> name
  33. , v8::Local<v8::Integer> line) :
  34. v8::ScriptOrigin(v8::Isolate::GetCurrent()
  35. , name
  36. , To<int32_t>(line).FromMaybe(0)) {}
  37. ScriptOrigin(v8::Local<v8::Value> name
  38. , v8::Local<v8::Integer> line
  39. , v8::Local<v8::Integer> column) :
  40. v8::ScriptOrigin(v8::Isolate::GetCurrent()
  41. , name
  42. , To<int32_t>(line).FromMaybe(0)
  43. , To<int32_t>(column).FromMaybe(0)) {}
  44. #elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 8 || \
  45. (V8_MAJOR_VERSION == 8 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 9\
  46. || (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) \
  47. && V8_BUILD_NUMBER >= 45)))))
  48. explicit ScriptOrigin(v8::Local<v8::Value> name) : v8::ScriptOrigin(name) {}
  49. ScriptOrigin(v8::Local<v8::Value> name
  50. , v8::Local<v8::Integer> line) :
  51. v8::ScriptOrigin(name, To<int32_t>(line).FromMaybe(0)) {}
  52. ScriptOrigin(v8::Local<v8::Value> name
  53. , v8::Local<v8::Integer> line
  54. , v8::Local<v8::Integer> column) :
  55. v8::ScriptOrigin(name
  56. , To<int32_t>(line).FromMaybe(0)
  57. , To<int32_t>(column).FromMaybe(0)) {}
  58. #else
  59. explicit ScriptOrigin(v8::Local<v8::Value> name) : v8::ScriptOrigin(name) {}
  60. ScriptOrigin(v8::Local<v8::Value> name
  61. , v8::Local<v8::Integer> line) : v8::ScriptOrigin(name, line) {}
  62. ScriptOrigin(v8::Local<v8::Value> name
  63. , v8::Local<v8::Integer> line
  64. , v8::Local<v8::Integer> column) :
  65. v8::ScriptOrigin(name, line, column) {}
  66. #endif
  67. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 8 || \
  68. (V8_MAJOR_VERSION == 8 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 9\
  69. || (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) \
  70. && V8_BUILD_NUMBER >= 45)))))
  71. v8::Local<v8::Integer> ResourceLineOffset() const {
  72. return New(LineOffset());
  73. }
  74. v8::Local<v8::Integer> ResourceColumnOffset() const {
  75. return New(ColumnOffset());
  76. }
  77. #endif
  78. };
  79. #endif // NAN_SCRIPTORIGIN_H_