Skip to content

Commit f968c32

Browse files
cjihrigShogunPanda
authored andcommitted
fix lint
1 parent d0251c4 commit f968c32

File tree

14 files changed

+356
-376
lines changed

14 files changed

+356
-376
lines changed

doc/api/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ following permissions are restricted:
22242224
* Worker Threads - manageable through [`--allow-worker`][] flag
22252225
* WASI - manageable through [`--allow-wasi`][] flag
22262226
* Addons - manageable through [`--allow-addons`][] flag
2227-
* FFI - manageable through [`--allow-ffi`][] flag
2227+
* FFI - manageable through \[`--allow-ffi`]\[] flag
22282228

22292229
### `--permission-audit`
22302230

doc/api/ffi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ When `copy` is `false`, the returned `ArrayBuffer` references the original
476476
native memory directly.
477477

478478
The same lifetime and bounds requirements described for
479-
[`ffi.toBuffer(pointer, length[, copy])`][] apply here. With `copy: false`, the
479+
[`ffi.toBuffer()`][] apply here. With `copy: false`, the
480480
returned `ArrayBuffer` is a zero-copy view of foreign memory and is only safe
481481
while that memory remains allocated, unchanged in layout, and valid for the
482482
entire exposed range.
@@ -545,4 +545,4 @@ and keep callback and pointer lifetimes explicit on the native side.
545545

546546
[Permission Model]: permissions.md#permission-model
547547
[`--allow-ffi`]: cli.md#--allow-ffi
548-
[`ffi.toBuffer(pointer, length[, copy])`]: #ffitobufferpointer-length-copy
548+
[`ffi.toBuffer()`]: #ffitobufferpointer-length-copy

doc/api/permissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ using the [`--allow-child-process`][] and [`--allow-worker`][] respectively.
7171
To allow network access, use [`--allow-net`][] and for allowing native addons
7272
when using permission model, use the [`--allow-addons`][]
7373
flag. For WASI, use the [`--allow-wasi`][] flag. For FFI, use the
74-
[`--allow-ffi`][] flag. The [`node:ffi`][] module also requires the
74+
[`--allow-ffi`][] flag. The \[`node:ffi`]\[] module also requires the
7575
`--experimental-ffi` flag and is only available in builds with FFI support.
7676

7777
#### Runtime API

lib/ffi.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
'use strict';
2+
const {
3+
MathMin,
4+
} = primordials;
5+
const { Buffer } = require('buffer');
26
const { emitExperimentalWarning } = require('internal/util');
37
const {
48
codes: {
@@ -82,10 +86,10 @@ function exportString(str, data, len, encoding = 'utf8') {
8286

8387
const targetBuffer = toBuffer(data, len, false);
8488
const sourceBuffer = Buffer.from(str, encoding);
85-
const dataLength = Math.min(sourceBuffer.length, len - 1); // Reserve space for null terminator
89+
const dataLength = MathMin(sourceBuffer.length, len - 1); // Reserve space for null terminator
8690

8791
sourceBuffer.copy(targetBuffer, 0, 0, dataLength);
88-
targetBuffer[dataLength] = 0; // Null terminator
92+
targetBuffer[dataLength] = 0; // Null terminator
8993
}
9094

9195
function exportBuffer(buffer, data, len) {
@@ -102,7 +106,7 @@ function exportBuffer(buffer, data, len) {
102106
}
103107

104108
const targetBuffer = toBuffer(data, len, false);
105-
const dataLength = Math.min(buffer.length, len);
109+
const dataLength = MathMin(buffer.length, len);
106110
buffer.copy(targetBuffer, 0, 0, dataLength);
107111
}
108112

lib/internal/process/permission.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
Boolean,
45
ObjectFreeze,
56
} = primordials;
67

src/node_ffi.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void DynamicLibrary::New(const FunctionCallbackInfo<Value>& args) {
222222
}
223223

224224
DynamicLibrary* lib = new DynamicLibrary(env, args.This());
225-
node::Utf8Value filename(env->isolate(), args[0]);
225+
Utf8Value filename(env->isolate(), args[0]);
226226
lib->path_ = std::string(*filename);
227227

228228
// Open the library
@@ -277,7 +277,7 @@ void DynamicLibrary::InvokeFunction(const FunctionCallbackInfo<Value>& args) {
277277

278278
// The argument is a string, we need to copy
279279
if (res == 2) {
280-
String::Utf8Value str(env->isolate(), args[i]);
280+
Utf8Value str(env->isolate(), args[i]);
281281

282282
if (*str == nullptr) {
283283
env->ThrowTypeError(
@@ -399,7 +399,7 @@ void DynamicLibrary::GetFunction(const FunctionCallbackInfo<Value>& args) {
399399
}
400400

401401
DynamicLibrary* lib = Unwrap<DynamicLibrary>(args.This());
402-
node::Utf8Value name(isolate, args[0]);
402+
Utf8Value name(isolate, args[0]);
403403
std::shared_ptr<FFIFunction> fn;
404404

405405
Local<Object> signature = args[1].As<Object>();
@@ -444,14 +444,14 @@ void DynamicLibrary::GetFunctions(const FunctionCallbackInfo<Value>& args) {
444444
return;
445445
}
446446

447-
node::Utf8Value name(isolate, key);
447+
Utf8Value name(isolate, key);
448448

449449
if (!signatures->Get(env->context(), key).ToLocal(&signature)) {
450450
return;
451451
}
452452

453453
if (!signature->IsObject() || signature->IsArray()) {
454-
std::string msg = std::string("Signature of function ") + *name +
454+
std::string msg = std::string("Signature of function ") + name.out() +
455455
" must be an object";
456456
env->ThrowTypeError(msg.c_str());
457457
return;
@@ -499,7 +499,7 @@ void DynamicLibrary::GetSymbol(const FunctionCallbackInfo<Value>& args) {
499499
}
500500

501501
DynamicLibrary* lib = Unwrap<DynamicLibrary>(args.This());
502-
node::Utf8Value name(isolate, args[0]);
502+
Utf8Value name(isolate, args[0]);
503503
void* ptr;
504504

505505
if (!lib->FindOrCreateSymbol(env, *name, &ptr)) {

src/node_ffi.h

Lines changed: 80 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@
1414
#include <unordered_map>
1515
#include <vector>
1616

17-
using v8::Context;
18-
using v8::Function;
19-
using v8::FunctionCallbackInfo;
20-
using v8::FunctionTemplate;
21-
using v8::Global;
22-
using v8::Isolate;
23-
using v8::Local;
24-
using v8::Object;
25-
using v8::String;
26-
using v8::Value;
27-
using v8::WeakCallbackInfo;
28-
2917
namespace node::ffi {
3018

3119
class DynamicLibrary;
@@ -37,21 +25,23 @@ bool IsFFINarrowUnsignedInteger(ffi_type* type);
3725

3826
bool IsFFINarrowInteger(ffi_type* type);
3927

40-
bool HasProperty(Local<Context> context,
41-
Local<Object> object,
42-
Local<String> key,
28+
bool HasProperty(v8::Local<v8::Context> context,
29+
v8::Local<v8::Object> object,
30+
v8::Local<v8::String> key,
4331
bool* out);
4432

45-
bool GetStrictSignedInteger(Local<Value> value,
33+
bool GetStrictSignedInteger(v8::Local<v8::Value> value,
4634
int64_t min,
4735
int64_t max,
4836
int64_t* out);
4937

50-
bool GetStrictUnsignedInteger(Local<Value> value, uint64_t max, uint64_t* out);
38+
bool GetStrictUnsignedInteger(v8::Local<v8::Value> value,
39+
uint64_t max,
40+
uint64_t* out);
5141

5242
bool ParseFunctionSignature(Environment* env,
5343
const std::string& name,
54-
Local<Object> signature,
44+
v8::Local<v8::Object> signature,
5545
ffi_type** return_type,
5646
std::vector<ffi_type*>* args);
5747

@@ -64,59 +54,63 @@ bool ToFFIType(Environment* env, const std::string& type_str, ffi_type** ret);
6454
uint8_t ToFFIArgument(Environment* env,
6555
unsigned int index,
6656
ffi_type* type,
67-
Local<Value> arg,
57+
v8::Local<v8::Value> arg,
6858
void* ret);
6959

70-
Local<Value> ToJSArgument(Isolate* isolate, ffi_type* type, void* data);
60+
v8::Local<v8::Value> ToJSArgument(v8::Isolate* isolate,
61+
ffi_type* type,
62+
void* data);
7163

7264
bool ToJSReturnValue(Environment* env,
73-
const FunctionCallbackInfo<Value>& args,
65+
const v8::FunctionCallbackInfo<v8::Value>& args,
7466
ffi_type* type,
7567
void* result);
7668

77-
bool ToFFIReturnValue(Local<Value> result, ffi_type* type, void* ret);
69+
bool ToFFIReturnValue(v8::Local<v8::Value> result, ffi_type* type, void* ret);
7870

7971
size_t GetFFIReturnValueStorageSize(ffi_type* type);
8072

8173
bool GetValidatedSize(Environment* env,
82-
Local<Value> value,
74+
v8::Local<v8::Value> value,
8375
const char* label,
8476
size_t* out);
8577

8678
bool GetValidatedPointerAddress(Environment* env,
87-
Local<Value> value,
79+
v8::Local<v8::Value> value,
8880
const char* label,
8981
uintptr_t* out);
9082

9183
bool GetValidatedSignedInt(Environment* env,
92-
Local<Value> value,
84+
v8::Local<v8::Value> value,
9385
int64_t min,
9486
int64_t max,
9587
const char* type_name,
9688
int64_t* out);
9789

9890
bool GetValidatedUnsignedInt(Environment* env,
99-
Local<Value> value,
91+
v8::Local<v8::Value> value,
10092
uint64_t max,
10193
const char* type_name,
10294
uint64_t* out);
10395

104-
bool GetValidatedPointerAndOffset(Environment* env,
105-
const FunctionCallbackInfo<Value>& args,
106-
uint8_t** ptr,
107-
size_t* offset);
96+
bool GetValidatedPointerAndOffset(
97+
Environment* env,
98+
const v8::FunctionCallbackInfo<v8::Value>& args,
99+
uint8_t** ptr,
100+
size_t* offset);
108101

109-
bool GetValidatedPointerValueAndOffset(Environment* env,
110-
const FunctionCallbackInfo<Value>& args,
111-
uint8_t** ptr,
112-
Local<Value>* value,
113-
size_t* offset);
102+
bool GetValidatedPointerValueAndOffset(
103+
Environment* env,
104+
const v8::FunctionCallbackInfo<v8::Value>& args,
105+
uint8_t** ptr,
106+
v8::Local<v8::Value>* value,
107+
size_t* offset);
114108

115109
template <typename T>
116-
void GetValue(const FunctionCallbackInfo<Value>& args);
110+
void GetValue(const v8::FunctionCallbackInfo<v8::Value>& args);
117111

118112
template <typename T>
119-
void SetValue(const FunctionCallbackInfo<Value>& args);
113+
void SetValue(const v8::FunctionCallbackInfo<v8::Value>& args);
120114

121115
struct FFIFunction {
122116
bool closed;
@@ -129,14 +123,14 @@ struct FFIFunction {
129123

130124
struct FFIFunctionInfo {
131125
std::shared_ptr<FFIFunction> fn;
132-
Global<Function> self;
126+
v8::Global<v8::Function> self;
133127
};
134128

135129
struct FFICallback {
136130
DynamicLibrary* owner;
137131
Environment* env;
138132
std::thread::id thread_id;
139-
Global<Function> fn;
133+
v8::Global<v8::Function> fn;
140134
ffi_closure* closure;
141135

142136
void* ptr;
@@ -158,30 +152,32 @@ struct FFICallback {
158152

159153
class DynamicLibrary : public BaseObject {
160154
public:
161-
DynamicLibrary(Environment* env, Local<Object> object);
155+
DynamicLibrary(Environment* env, v8::Local<v8::Object> object);
162156
~DynamicLibrary() override;
163157

164158
void MemoryInfo(MemoryTracker* tracker) const override;
165159

166-
static Local<FunctionTemplate> GetConstructorTemplate(Environment* env);
167-
static void New(const FunctionCallbackInfo<Value>& args);
168-
static void Close(const FunctionCallbackInfo<Value>& args);
169-
static void InvokeFunction(const FunctionCallbackInfo<Value>& args);
160+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
161+
Environment* env);
162+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
163+
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
164+
static void InvokeFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
170165
static void InvokeCallback(ffi_cif* cif,
171166
void* ret,
172167
void** args,
173168
void* user_data);
174169

175-
static void GetPath(const FunctionCallbackInfo<Value>& args);
176-
static void GetFunction(const FunctionCallbackInfo<Value>& args);
177-
static void GetFunctions(const FunctionCallbackInfo<Value>& args);
178-
static void GetSymbol(const FunctionCallbackInfo<Value>& args);
179-
static void GetSymbols(const FunctionCallbackInfo<Value>& args);
170+
static void GetPath(const v8::FunctionCallbackInfo<v8::Value>& args);
171+
static void GetFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
172+
static void GetFunctions(const v8::FunctionCallbackInfo<v8::Value>& args);
173+
static void GetSymbol(const v8::FunctionCallbackInfo<v8::Value>& args);
174+
static void GetSymbols(const v8::FunctionCallbackInfo<v8::Value>& args);
180175

181-
static void RegisterCallback(const FunctionCallbackInfo<Value>& args);
182-
static void UnregisterCallback(const FunctionCallbackInfo<Value>& args);
183-
static void RefCallback(const FunctionCallbackInfo<Value>& args);
184-
static void UnrefCallback(const FunctionCallbackInfo<Value>& args);
176+
static void RegisterCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
177+
static void UnregisterCallback(
178+
const v8::FunctionCallbackInfo<v8::Value>& args);
179+
static void RefCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
180+
static void UnrefCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
185181

186182
SET_MEMORY_INFO_NAME(DynamicLibrary)
187183
SET_SELF_SIZE(DynamicLibrary)
@@ -193,13 +189,14 @@ class DynamicLibrary : public BaseObject {
193189
void** ptr);
194190
bool FindOrCreateFunction(Environment* env,
195191
const std::string& name,
196-
Local<Object> signature,
192+
v8::Local<v8::Object> signature,
197193
std::shared_ptr<FFIFunction>* ret);
198-
Local<Function> CreateFunction(Environment* env,
199-
const std::string& name,
200-
const std::shared_ptr<FFIFunction>& fn);
194+
v8::Local<v8::Function> CreateFunction(
195+
Environment* env,
196+
const std::string& name,
197+
const std::shared_ptr<FFIFunction>& fn);
201198
static void CleanupFunctionInfo(
202-
const WeakCallbackInfo<FFIFunctionInfo>& data);
199+
const v8::WeakCallbackInfo<FFIFunctionInfo>& data);
203200

204201
uv_lib_t lib_;
205202
void* handle_;
@@ -209,31 +206,31 @@ class DynamicLibrary : public BaseObject {
209206
std::unordered_map<void*, std::unique_ptr<FFICallback>> callbacks_;
210207
};
211208

212-
void GetInt8(const FunctionCallbackInfo<Value>& args);
213-
void GetUint8(const FunctionCallbackInfo<Value>& args);
214-
void GetInt16(const FunctionCallbackInfo<Value>& args);
215-
void GetUint16(const FunctionCallbackInfo<Value>& args);
216-
void GetInt32(const FunctionCallbackInfo<Value>& args);
217-
void GetUint32(const FunctionCallbackInfo<Value>& args);
218-
void GetInt64(const FunctionCallbackInfo<Value>& args);
219-
void GetUint64(const FunctionCallbackInfo<Value>& args);
220-
void GetFloat32(const FunctionCallbackInfo<Value>& args);
221-
void GetFloat64(const FunctionCallbackInfo<Value>& args);
222-
223-
void SetInt8(const FunctionCallbackInfo<Value>& args);
224-
void SetUint8(const FunctionCallbackInfo<Value>& args);
225-
void SetInt16(const FunctionCallbackInfo<Value>& args);
226-
void SetUint16(const FunctionCallbackInfo<Value>& args);
227-
void SetInt32(const FunctionCallbackInfo<Value>& args);
228-
void SetUint32(const FunctionCallbackInfo<Value>& args);
229-
void SetInt64(const FunctionCallbackInfo<Value>& args);
230-
void SetUint64(const FunctionCallbackInfo<Value>& args);
231-
void SetFloat32(const FunctionCallbackInfo<Value>& args);
232-
void SetFloat64(const FunctionCallbackInfo<Value>& args);
233-
234-
void ToString(const FunctionCallbackInfo<Value>& args);
235-
void ToBuffer(const FunctionCallbackInfo<Value>& args);
236-
void ToArrayBuffer(const FunctionCallbackInfo<Value>& args);
209+
void GetInt8(const v8::FunctionCallbackInfo<v8::Value>& args);
210+
void GetUint8(const v8::FunctionCallbackInfo<v8::Value>& args);
211+
void GetInt16(const v8::FunctionCallbackInfo<v8::Value>& args);
212+
void GetUint16(const v8::FunctionCallbackInfo<v8::Value>& args);
213+
void GetInt32(const v8::FunctionCallbackInfo<v8::Value>& args);
214+
void GetUint32(const v8::FunctionCallbackInfo<v8::Value>& args);
215+
void GetInt64(const v8::FunctionCallbackInfo<v8::Value>& args);
216+
void GetUint64(const v8::FunctionCallbackInfo<v8::Value>& args);
217+
void GetFloat32(const v8::FunctionCallbackInfo<v8::Value>& args);
218+
void GetFloat64(const v8::FunctionCallbackInfo<v8::Value>& args);
219+
220+
void SetInt8(const v8::FunctionCallbackInfo<v8::Value>& args);
221+
void SetUint8(const v8::FunctionCallbackInfo<v8::Value>& args);
222+
void SetInt16(const v8::FunctionCallbackInfo<v8::Value>& args);
223+
void SetUint16(const v8::FunctionCallbackInfo<v8::Value>& args);
224+
void SetInt32(const v8::FunctionCallbackInfo<v8::Value>& args);
225+
void SetUint32(const v8::FunctionCallbackInfo<v8::Value>& args);
226+
void SetInt64(const v8::FunctionCallbackInfo<v8::Value>& args);
227+
void SetUint64(const v8::FunctionCallbackInfo<v8::Value>& args);
228+
void SetFloat32(const v8::FunctionCallbackInfo<v8::Value>& args);
229+
void SetFloat64(const v8::FunctionCallbackInfo<v8::Value>& args);
230+
231+
void ToString(const v8::FunctionCallbackInfo<v8::Value>& args);
232+
void ToBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
233+
void ToArrayBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
237234

238235
} // namespace node::ffi
239236

0 commit comments

Comments
 (0)