summaryrefslogtreecommitdiff
path: root/test/cctest
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-03-05 20:09:43 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-09 00:29:35 +0100
commitdb2a5b05dfb3634e8fdb965ef5d4c75f73094e9e (patch)
treedf3787238da814aecee2cbeab3973a58c45dbd69 /test/cctest
parent58b00f4cca79ac61864009e3c24194c4bc5c8de2 (diff)
downloadandroid-node-v8-db2a5b05dfb3634e8fdb965ef5d4c75f73094e9e.tar.gz
android-node-v8-db2a5b05dfb3634e8fdb965ef5d4c75f73094e9e.tar.bz2
android-node-v8-db2a5b05dfb3634e8fdb965ef5d4c75f73094e9e.zip
src: add public API for linked bindings
(Re-?)add a public API for creating linked bindings (access to `NM_F_LINKED` as a constant was previously removed in d6ac8a4db0c0a588258f594dc21fbd8018bef7c2), and add a test for the functionality. PR-URL: https://github.com/nodejs/node/pull/26457 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/cctest')
-rw-r--r--test/cctest/test_linked_binding.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/cctest/test_linked_binding.cc b/test/cctest/test_linked_binding.cc
new file mode 100644
index 0000000000..e0b46d3822
--- /dev/null
+++ b/test/cctest/test_linked_binding.cc
@@ -0,0 +1,42 @@
+#include "node_test_fixture.h"
+#include "node_internals.h" // RunBootstrapping()
+
+void InitializeBinding(v8::Local<v8::Object> exports,
+ v8::Local<v8::Value> module,
+ v8::Local<v8::Context> context) {
+ v8::Isolate* isolate = context->GetIsolate();
+ exports->Set(
+ context,
+ v8::String::NewFromOneByte(isolate,
+ reinterpret_cast<const uint8_t*>("key"),
+ v8::NewStringType::kNormal).ToLocalChecked(),
+ v8::String::NewFromOneByte(isolate,
+ reinterpret_cast<const uint8_t*>("value"),
+ v8::NewStringType::kNormal).ToLocalChecked())
+ .FromJust();
+}
+
+NODE_MODULE_LINKED(cctest_linkedbinding, InitializeBinding);
+
+class LinkedBindingTest : public EnvironmentTestFixture {};
+
+TEST_F(LinkedBindingTest, SimpleTest) {
+ const v8::HandleScope handle_scope(isolate_);
+ const Argv argv;
+ Env test_env {handle_scope, argv};
+
+ v8::Local<v8::Context> context = isolate_->GetCurrentContext();
+
+ const char* run_script =
+ "process._linkedBinding('cctest_linkedbinding').key";
+ v8::Local<v8::Script> script = v8::Script::Compile(
+ context,
+ v8::String::NewFromOneByte(isolate_,
+ reinterpret_cast<const uint8_t*>(run_script),
+ v8::NewStringType::kNormal).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, "value"), 0);
+}