node/test/addons/make-callback-recurse/binding.cc
Michaël Zasso d9c47e9b5f
src: add missing TryCatch
Otherwise re-entering V8 doesn't work as expected after exceptions
were thrown.

Refs: https://chromium-review.googlesource.com/c/v8/v8/+/5050065

Co-Authored-By: Toon Verwaest <verwaest@chromium.org>
Co-Authored-By: deepak1556 <hop2deep@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/51362
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-03-31 15:37:22 +02:00

38 lines
849 B
C++

#include "node.h"
#include "v8.h"
#include <assert.h>
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::TryCatch;
using v8::Value;
namespace {
void MakeCallback(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsObject());
assert(args[1]->IsFunction());
Isolate* isolate = args.GetIsolate();
Local<Object> recv = args[0].As<Object>();
Local<Function> method = args[1].As<Function>();
TryCatch try_catch(isolate);
node::MakeCallback(isolate, recv, method, 0, nullptr,
node::async_context{0, 0});
if (try_catch.HasCaught()) {
try_catch.ReThrow();
}
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "makeCallback", MakeCallback);
}
} // anonymous namespace
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)