src_stop_using_deprecated_fields_of_fastapicallbackoptions.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Andreas Haas <[email protected]>
  3. Date: Sun, 28 Jul 2024 09:20:12 +0200
  4. Subject: src: stop using deprecated fields of `v8::FastApiCallbackOptions`
  5. Two fields on the `v8::FastApiCallbackOptions` struct were deprecated
  6. recently: `fallback` and `wasm_memory`. This PR removes uses of these
  7. two fields in node.js.
  8. (This is a subset of upstream commit d0000b118 from the `canary-base`
  9. branch of Node.js. This patch can be removed when Electron upgrades to
  10. a stable Node release that contains the change. -- Charles)
  11. diff --git a/src/crypto/crypto_timing.cc b/src/crypto/crypto_timing.cc
  12. index 3d8ccc77b5952a999c5fe48792259d32b402c460..867a1c4aca54b9d41490d23a5eb55088b7e941cc 100644
  13. --- a/src/crypto/crypto_timing.cc
  14. +++ b/src/crypto/crypto_timing.cc
  15. @@ -59,7 +59,8 @@ bool FastTimingSafeEqual(Local<Value> receiver,
  16. if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) ||
  17. !b.getStorageIfAligned(&data_b)) {
  18. TRACK_V8_FAST_API_CALL("crypto.timingSafeEqual.error");
  19. - options.fallback = true;
  20. + v8::HandleScope scope(options.isolate);
  21. + THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(options.isolate);
  22. return false;
  23. }
  24. diff --git a/src/histogram.cc b/src/histogram.cc
  25. index c62a5b8952400ff0dd8818c31a3e07622b63725c..36f61f57e951e1abfeb2fedb831b55c61363bcbc 100644
  26. --- a/src/histogram.cc
  27. +++ b/src/histogram.cc
  28. @@ -195,7 +195,8 @@ void HistogramBase::FastRecord(Local<Value> unused,
  29. const int64_t value,
  30. FastApiCallbackOptions& options) {
  31. if (value < 1) {
  32. - options.fallback = true;
  33. + Environment* env = Environment::GetCurrent(options.isolate);
  34. + THROW_ERR_OUT_OF_RANGE(env, "value is out of range");
  35. return;
  36. }
  37. HistogramBase* histogram;
  38. diff --git a/src/node_file.cc b/src/node_file.cc
  39. index 4bdbfa1be2c22f6a823acc380efe15c8d72f66ce..83f482612fae2d7ebf9bfd6817d334c239f8a218 100644
  40. --- a/src/node_file.cc
  41. +++ b/src/node_file.cc
  42. @@ -1060,13 +1060,8 @@ static int32_t FastInternalModuleStat(
  43. // NOLINTNEXTLINE(runtime/references) This is V8 api.
  44. FastApiCallbackOptions& options) {
  45. // This needs a HandleScope which needs an isolate.
  46. - Isolate* isolate = Isolate::TryGetCurrent();
  47. - if (!isolate) {
  48. - options.fallback = true;
  49. - return -1;
  50. - }
  51. -
  52. - HandleScope scope(isolate);
  53. + Environment* env = Environment::GetCurrent(options.isolate);
  54. + HandleScope scope(env->isolate());
  55. auto path = std::filesystem::path(input.data, input.data + input.length);
  56. diff --git a/src/node_wasi.cc b/src/node_wasi.cc
  57. index 468c2e59903fefe58d9c178d3afac3ef5b09f611..23a376e52e08a8af49dd47c47488552e01287426 100644
  58. --- a/src/node_wasi.cc
  59. +++ b/src/node_wasi.cc
  60. @@ -251,17 +251,19 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
  61. return EinvalError<R>();
  62. }
  63. - if (options.wasm_memory == nullptr || wasi->memory_.IsEmpty()) [[unlikely]] {
  64. - // fallback to slow path which to throw an error about missing memory.
  65. - options.fallback = true;
  66. + v8::Isolate* isolate = receiver->GetIsolate();
  67. + v8::HandleScope handle_scope(isolate);
  68. + if (wasi->memory_.IsEmpty()) {
  69. + THROW_ERR_WASI_NOT_STARTED(isolate);
  70. return EinvalError<R>();
  71. }
  72. - uint8_t* memory = nullptr;
  73. - CHECK(options.wasm_memory->getStorageIfAligned(&memory));
  74. - return F(*wasi,
  75. - {reinterpret_cast<char*>(memory), options.wasm_memory->length()},
  76. - args...);
  77. + Local<ArrayBuffer> ab = wasi->memory_.Get(isolate)->Buffer();
  78. + size_t mem_size = ab->ByteLength();
  79. + char* mem_data = static_cast<char*>(ab->Data());
  80. + CHECK_NOT_NULL(mem_data);
  81. +
  82. + return F(*wasi, {mem_data, mem_size}, args...);
  83. }
  84. namespace {