diff options
author | Anna Henningsen <anna@addaleax.net> | 2021-06-12 00:43:48 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-06-14 14:34:39 +0300 |
commit | 10370c5e8a22134c75f82c54e8f042ed2ca18792 (patch) | |
tree | ba5a9cef7ac26cd25dbc107c4a7e3df7873bcef1 /test | |
parent | ded83350a01882df7bb6115ebf25edf8ab76c098 (diff) |
src: fix multiple AddLinkedBinding() calls
Singly-linked lists are extended at their tail, not their head.
This fixes using more than 2 linked addons at a time.
PR-URL: https://github.com/nodejs/node/pull/39012
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/cctest/test_linked_binding.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/cctest/test_linked_binding.cc b/test/cctest/test_linked_binding.cc index 17c020429f0..7e40068b5db 100644 --- a/test/cctest/test_linked_binding.cc +++ b/test/cctest/test_linked_binding.cc @@ -190,3 +190,35 @@ TEST_F(LinkedBindingTest, LocallyDefinedLinkedBindingNapiInstanceDataTest) { CHECK_EQ(*instance_data, 1); delete instance_data; } + +TEST_F(LinkedBindingTest, ManyBindingsTest) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env test_env {handle_scope, argv}; + + int calls = 0; + AddLinkedBinding(*test_env, "local_linked1", InitializeLocalBinding, &calls); + AddLinkedBinding(*test_env, "local_linked2", InitializeLocalBinding, &calls); + AddLinkedBinding(*test_env, "local_linked3", InitializeLocalBinding, &calls); + AddLinkedBinding(*test_env, local_linked_napi); // Add a N-API addon as well. + AddLinkedBinding(*test_env, "local_linked4", InitializeLocalBinding, &calls); + AddLinkedBinding(*test_env, "local_linked5", InitializeLocalBinding, &calls); + + v8::Local<v8::Context> context = isolate_->GetCurrentContext(); + + const char* run_script = + "for (let i = 1; i <= 5; i++)process._linkedBinding(`local_linked${i}`);" + "process._linkedBinding('local_linked_napi').hello"; + v8::Local<v8::Script> script = v8::Script::Compile( + context, + v8::String::NewFromOneByte(isolate_, + reinterpret_cast<const uint8_t*>(run_script)) + .ToLocalChecked()) + .ToLocalChecked(); + v8::Local<v8::Value> completion_value = script->Run(context).ToLocalChecked(); + v8::String::Utf8Value utf8val(isolate_, completion_value); + CHECK_NOT_NULL(*utf8val); + CHECK_EQ(strcmp(*utf8val, "world"), 0); + CHECK_EQ(calls, 5); +} + |