-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 d6ac8a4), and add a test for the functionality. PR-URL: #26457 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |