This commit is contained in:
Jarred Sumner
2024-06-20 16:14:14 -07:00
committed by GitHub
parent 3908ac073b
commit c082ec5c9d
6 changed files with 88 additions and 29 deletions

View File

@@ -107,11 +107,26 @@ test_napi_get_value_string_utf8_with_buffer(const Napi::CallbackInfo &info) {
return ok(env);
}
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
Napi::Value RunCallback(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Function cb = info[0].As<Napi::Function>();
return cb.Call(env.Global(), {Napi::String::New(env, "hello world")});
}
Napi::Object Init2(Napi::Env env, Napi::Object exports) {
return Napi::Function::New(env, RunCallback);
}
Napi::Object InitAll(Napi::Env env, Napi::Object exports1) {
// check that these symbols are defined
auto *isolate = v8::Isolate::GetCurrent();
node::AddEnvironmentCleanupHook(isolate, [](void *) {}, isolate);
node::RemoveEnvironmentCleanupHook(isolate, [](void *) {}, isolate);
Napi::Object exports = Init2(env, exports1);
node::AddEnvironmentCleanupHook(
isolate, [](void *) {}, isolate);
node::RemoveEnvironmentCleanupHook(
isolate, [](void *) {}, isolate);
exports.Set("test_issue_7685", Napi::Function::New(env, test_issue_7685));
exports.Set("test_issue_11949", Napi::Function::New(env, test_issue_11949));

View File

@@ -1,4 +1,12 @@
const tests = require("./build/Release/napitests.node");
if (process.argv[2] === "self") {
console.log(
tests(function (str) {
return str + "!";
}),
);
process.exit(0);
}
const fn = tests[process.argv[2]];
if (typeof fn !== "function") {
throw new Error("Unknown test:", process.argv[2]);

View File

@@ -58,6 +58,11 @@ describe("napi", () => {
expect(result).toEndWith("str:");
});
});
it("#1288", async () => {
const result = checkSameOutput("self", []);
expect(result).toBe("hello world!");
});
});
function checkSameOutput(test: string, args: any[]) {