lib,src,test,doc: add node:ffi module#62072
Conversation
|
Review requested:
|
|
Yes |
Qard
left a comment
There was a problem hiding this comment.
Looks very cool! I'm glad to see someone has picked this back up. 🙂
I did a quick review and it all looks good. My only comment is there seems to be a bunch of static strings and a private symbol which we might want to define in env_properties.h.
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Failed to start CI⚠ No approving reviews found ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/23272564448 |
|
@anonrig I cancelled that CI run to save resources. I started https://ci.nodejs.org/job/node-test-pull-request/71877/ manually, and it's currently running. |
given that this is still draft and @cjihrig indicated it's not ready for review, a sign off is not yet appropriate.
given that this is still draft and @cjihrig indicated it's not ready for review, a sign off is not yet appropriate.
* src,deps,test: various improvements Signed-off-by: Paolo Insogna <paolo@cowtech.it> * deps,test: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> * deps,test: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> * deps,test: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> * deps,test: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> * doc,lib: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> * deps: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> * test: fixed failures Signed-off-by: Paolo Insogna <paolo@cowtech.it> --------- Signed-off-by: Paolo Insogna <paolo@cowtech.it>
* test: fixed build on Windows Signed-off-by: Paolo Insogna <paolo@cowtech.it> * test: fixed build on Windows Signed-off-by: Paolo Insogna <paolo@cowtech.it> * test: fixed build on Windows Signed-off-by: Paolo Insogna <paolo@cowtech.it> * test: fixed build on Windows Signed-off-by: Paolo Insogna <paolo@cowtech.it> * test: removed useless file Signed-off-by: Paolo Insogna <paolo@cowtech.it> --------- Signed-off-by: Paolo Insogna <paolo@cowtech.it>
|
@cjihrig @ShogunPanda this now conflicts, can you rebase? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62072 +/- ##
==========================================
- Coverage 89.70% 89.18% -0.53%
==========================================
Files 695 702 +7
Lines 214213 216018 +1805
Branches 41021 41395 +374
==========================================
+ Hits 192167 192657 +490
- Misses 14113 15415 +1302
- Partials 7933 7946 +13
🚀 New features to boost your workflow:
|
|
|
||
| bool ValidateBufferLength(Environment* env, size_t len) { | ||
| if (len > Buffer::kMaxLength) { | ||
| env->isolate()->ThrowException(ERR_BUFFER_TOO_LARGE(env->isolate())); |
There was a problem hiding this comment.
Does THROW_ERR_BUFFER_TOO_LARGE(env) not work here?
| } else if (value->IsNumber()) { | ||
| uint64_t validated; | ||
| if (!GetValidatedUnsignedInt( | ||
| env, value, 9007199254740991ULL, "uint64", &validated)) { |
There was a problem hiding this comment.
Can this be a constant to avoid the inline magic number?
| return; | ||
| } | ||
|
|
||
| converted = static_cast<T>(number.ToLocalChecked()->Value()); |
There was a problem hiding this comment.
We should avoid using ToLocalChecked
| THROW_IF_INSUFFICIENT_PERMISSIONS(env, permission::PermissionScope::kFFI, ""); | ||
|
|
||
| if (args.Length() < 1 || !args[0]->IsBigInt()) { | ||
| env->ThrowTypeError("The first argument must be a bigint"); |
There was a problem hiding this comment.
These should be proper ERR_* errors.
| Local<External> data = External::New(isolate, info); | ||
| Local<Function> ret = | ||
| Function::New(env->context(), DynamicLibrary::InvokeFunction, data) | ||
| .ToLocalChecked(); |
There was a problem hiding this comment.
There's a few ToLocalChecked and Check uses that should be cleaned up.
| Local<Object> object, | ||
| Local<String> key, | ||
| bool* out) { | ||
| v8::Maybe<bool> has = object->Has(context, key); |
There was a problem hiding this comment.
v8::Maybe in the using list above
| Local<String> parameters_key = | ||
| String::NewFromUtf8Literal(env->isolate(), "parameters"); | ||
| Local<String> arguments_key = | ||
| String::NewFromUtf8Literal(env->isolate(), "arguments"); |
There was a problem hiding this comment.
These could be added to env-properties.h
|
|
||
| *static_cast<double*>(ret) = arg->NumberValue(context).FromJust(); | ||
| } else if (type == &ffi_type_pointer) { | ||
| if (arg->IsNull() || arg->IsUndefined()) { |
| String::NewFromUtf8(isolate, name.c_str(), NewStringType::kNormal) | ||
| .ToLocalChecked()); | ||
| ret->Set(env->context(), | ||
| FIXED_ONE_BYTE_STRING(env->isolate(), "pointer"), |
| info, DynamicLibrary::CleanupFunctionInfo, WeakCallbackType::kParameter); | ||
| ret->SetName( | ||
| String::NewFromUtf8(isolate, name.c_str(), NewStringType::kNormal) | ||
| .ToLocalChecked()); |
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
|
@jasnell Thanks for the review, tomorrow (CEST) I'll address all of them. |
This is not ready for review yet. Just opening to see if this is something the project is still interested in.