src_stop_using_deprecated_fields_of_fastapicallbackoptions.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/histogram.cc b/src/histogram.cc
  12. index 4dbdea9be5721486d71a9dda77311b4919d450a3..4aacaa2a5d12533a039b4b96cb7f1fd79063d50f 100644
  13. --- a/src/histogram.cc
  14. +++ b/src/histogram.cc
  15. @@ -193,7 +193,8 @@ void HistogramBase::FastRecord(Local<Value> receiver,
  16. const int64_t value,
  17. FastApiCallbackOptions& options) {
  18. if (value < 1) {
  19. - options.fallback = true;
  20. + Environment* env = Environment::GetCurrent(options.isolate);
  21. + THROW_ERR_OUT_OF_RANGE(env, "value is out of range");
  22. return;
  23. }
  24. HistogramBase* histogram;
  25. diff --git a/src/node_wasi.cc b/src/node_wasi.cc
  26. index ad1da44a01f437c97e06a3857eebd2edcebc83da..7123278e1a0942b61a76e9b1e7464eb8b5064079 100644
  27. --- a/src/node_wasi.cc
  28. +++ b/src/node_wasi.cc
  29. @@ -248,17 +248,18 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
  30. WASI* wasi = reinterpret_cast<WASI*>(BaseObject::FromJSObject(receiver));
  31. if (UNLIKELY(wasi == nullptr)) return EinvalError<R>();
  32. - if (UNLIKELY(options.wasm_memory == nullptr || wasi->memory_.IsEmpty())) {
  33. - // fallback to slow path which to throw an error about missing memory.
  34. - options.fallback = true;
  35. + v8::Isolate* isolate = receiver->GetIsolate();
  36. + v8::HandleScope handle_scope(isolate);
  37. + if (wasi->memory_.IsEmpty()) {
  38. + THROW_ERR_WASI_NOT_STARTED(isolate);
  39. return EinvalError<R>();
  40. }
  41. - uint8_t* memory = nullptr;
  42. - CHECK(LIKELY(options.wasm_memory->getStorageIfAligned(&memory)));
  43. + Local<ArrayBuffer> ab = wasi->memory_.Get(isolate)->Buffer();
  44. + size_t mem_size = ab->ByteLength();
  45. + char* mem_data = static_cast<char*>(ab->Data());
  46. + CHECK_NOT_NULL(mem_data);
  47. - return F(*wasi,
  48. - {reinterpret_cast<char*>(memory), options.wasm_memory->length()},
  49. - args...);
  50. + return F(*wasi, {mem_data, mem_size}, args...);
  51. }
  52. namespace {