koffi 2.7.2 → 2.7.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm32hf/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/misc.md +1 -1
- package/index.js +2 -2
- package/indirect.js +2 -2
- package/package.json +2 -2
- package/src/koffi/src/abi_arm32.cc +4 -4
- package/src/koffi/src/abi_arm64.cc +4 -4
- package/src/koffi/src/abi_riscv64.cc +4 -4
- package/src/koffi/src/abi_x64_sysv.cc +4 -4
- package/src/koffi/src/abi_x64_win.cc +4 -4
- package/src/koffi/src/abi_x86.cc +4 -4
- package/src/koffi/src/call.cc +6 -6
- package/src/koffi/src/call.hh +2 -2
- package/src/koffi/src/ffi.cc +0 -9
- package/src/koffi/src/ffi.hh +0 -1
- package/src/koffi/src/util.cc +7 -13
- package/src/koffi/src/util.hh +9 -1
- package/vendor/node-addon-api/CHANGELOG.md +76 -0
- package/vendor/node-addon-api/LICENSE.md +2 -6
- package/vendor/node-addon-api/README.md +10 -9
- package/vendor/node-addon-api/benchmark/binding.gyp +4 -4
- package/vendor/node-addon-api/common.gypi +1 -2
- package/vendor/node-addon-api/doc/array.md +1 -1
- package/vendor/node-addon-api/doc/async_worker_variants.md +16 -16
- package/vendor/node-addon-api/doc/cmake-js.md +1 -1
- package/vendor/node-addon-api/doc/env.md +11 -0
- package/vendor/node-addon-api/doc/hierarchy.md +2 -0
- package/vendor/node-addon-api/doc/setup.md +53 -71
- package/vendor/node-addon-api/doc/syntax_error.md +66 -0
- package/vendor/node-addon-api/doc/value.md +2 -0
- package/vendor/node-addon-api/index.js +2 -1
- package/vendor/node-addon-api/napi-inl.h +68 -65
- package/vendor/node-addon-api/napi.h +15 -5
- package/vendor/node-addon-api/node_addon_api.gyp +32 -0
- package/vendor/node-addon-api/package.json +14 -3
- package/vendor/node-addon-api/test/addon.cc +7 -1
- package/vendor/node-addon-api/test/addon.js +5 -9
- package/vendor/node-addon-api/test/addon_data.cc +3 -3
- package/vendor/node-addon-api/test/addon_data.js +16 -38
- package/vendor/node-addon-api/test/bigint.cc +0 -1
- package/vendor/node-addon-api/test/binding.cc +12 -1
- package/vendor/node-addon-api/test/binding.gyp +10 -8
- package/vendor/node-addon-api/test/child_processes/addon.js +11 -0
- package/vendor/node-addon-api/test/child_processes/addon_data.js +24 -0
- package/vendor/node-addon-api/test/child_processes/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/child_processes/threadsafe_function_exception.js +33 -0
- package/vendor/node-addon-api/test/child_processes/typed_threadsafe_function_exception.js +19 -0
- package/vendor/node-addon-api/test/common/index.js +57 -3
- package/vendor/node-addon-api/test/env_misc.cc +25 -0
- package/vendor/node-addon-api/test/env_misc.js +12 -0
- package/vendor/node-addon-api/test/error.cc +47 -0
- package/vendor/node-addon-api/test/error.js +16 -0
- package/vendor/node-addon-api/test/index.js +5 -0
- package/vendor/node-addon-api/test/objectwrap_function.cc +10 -12
- package/vendor/node-addon-api/test/objectwrap_function.js +4 -20
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.cc +50 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.js +20 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.cc +39 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.js +13 -0
|
@@ -153,6 +153,27 @@ void ThrowRangeError(const CallbackInfo& info) {
|
|
|
153
153
|
throw RangeError::New(info.Env(), message);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
#if NAPI_VERSION > 8
|
|
157
|
+
void ThrowSyntaxErrorCStr(const CallbackInfo& info) {
|
|
158
|
+
std::string message = info[0].As<String>().Utf8Value();
|
|
159
|
+
ReleaseAndWaitForChildProcess(info, 1);
|
|
160
|
+
throw SyntaxError::New(info.Env(), message.c_str());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
void ThrowSyntaxErrorCtor(const CallbackInfo& info) {
|
|
164
|
+
Napi::Value js_range_err = info[0];
|
|
165
|
+
ReleaseAndWaitForChildProcess(info, 1);
|
|
166
|
+
throw Napi::SyntaxError(info.Env(), js_range_err);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
void ThrowSyntaxError(const CallbackInfo& info) {
|
|
170
|
+
std::string message = info[0].As<String>().Utf8Value();
|
|
171
|
+
|
|
172
|
+
ReleaseAndWaitForChildProcess(info, 1);
|
|
173
|
+
throw SyntaxError::New(info.Env(), message);
|
|
174
|
+
}
|
|
175
|
+
#endif // NAPI_VERSION > 8
|
|
176
|
+
|
|
156
177
|
Value CatchError(const CallbackInfo& info) {
|
|
157
178
|
Function thrower = info[0].As<Function>();
|
|
158
179
|
try {
|
|
@@ -255,6 +276,27 @@ void ThrowEmptyRangeError(const CallbackInfo& info) {
|
|
|
255
276
|
RangeError().ThrowAsJavaScriptException();
|
|
256
277
|
}
|
|
257
278
|
|
|
279
|
+
#if NAPI_VERSION > 8
|
|
280
|
+
void ThrowSyntaxError(const CallbackInfo& info) {
|
|
281
|
+
std::string message = info[0].As<String>().Utf8Value();
|
|
282
|
+
|
|
283
|
+
ReleaseAndWaitForChildProcess(info, 1);
|
|
284
|
+
SyntaxError::New(info.Env(), message).ThrowAsJavaScriptException();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
void ThrowSyntaxErrorCtor(const CallbackInfo& info) {
|
|
288
|
+
Napi::Value js_range_err = info[0];
|
|
289
|
+
ReleaseAndWaitForChildProcess(info, 1);
|
|
290
|
+
SyntaxError(info.Env(), js_range_err).ThrowAsJavaScriptException();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
void ThrowSyntaxErrorCStr(const CallbackInfo& info) {
|
|
294
|
+
std::string message = info[0].As<String>().Utf8Value();
|
|
295
|
+
ReleaseAndWaitForChildProcess(info, 1);
|
|
296
|
+
SyntaxError::New(info.Env(), message.c_str()).ThrowAsJavaScriptException();
|
|
297
|
+
}
|
|
298
|
+
#endif // NAPI_VERSION > 8
|
|
299
|
+
|
|
258
300
|
Value CatchError(const CallbackInfo& info) {
|
|
259
301
|
Function thrower = info[0].As<Function>();
|
|
260
302
|
thrower({});
|
|
@@ -372,6 +414,11 @@ Object InitError(Env env) {
|
|
|
372
414
|
exports["throwRangeErrorCtor"] = Function::New(env, ThrowRangeErrorCtor);
|
|
373
415
|
exports["throwRangeErrorCStr"] = Function::New(env, ThrowRangeErrorCStr);
|
|
374
416
|
exports["throwEmptyRangeError"] = Function::New(env, ThrowEmptyRangeError);
|
|
417
|
+
#if NAPI_VERSION > 8
|
|
418
|
+
exports["throwSyntaxError"] = Function::New(env, ThrowSyntaxError);
|
|
419
|
+
exports["throwSyntaxErrorCtor"] = Function::New(env, ThrowSyntaxErrorCtor);
|
|
420
|
+
exports["throwSyntaxErrorCStr"] = Function::New(env, ThrowSyntaxErrorCStr);
|
|
421
|
+
#endif // NAPI_VERSION > 8
|
|
375
422
|
exports["catchError"] = Function::New(env, CatchError);
|
|
376
423
|
exports["catchErrorMessage"] = Function::New(env, CatchErrorMessage);
|
|
377
424
|
exports["doNotCatch"] = Function::New(env, DoNotCatch);
|
|
@@ -9,6 +9,8 @@ if (process.argv[2] === 'fatal') {
|
|
|
9
9
|
|
|
10
10
|
module.exports = require('./common').runTestWithBindingPath(test);
|
|
11
11
|
|
|
12
|
+
const napiVersion = Number(process.env.NAPI_VERSION ?? process.versions.napi);
|
|
13
|
+
|
|
12
14
|
function test (bindingPath) {
|
|
13
15
|
const binding = require(bindingPath);
|
|
14
16
|
binding.error.testErrorCopySemantics();
|
|
@@ -46,6 +48,20 @@ function test (bindingPath) {
|
|
|
46
48
|
return err instanceof RangeError && err.message === 'rangeTypeError';
|
|
47
49
|
});
|
|
48
50
|
|
|
51
|
+
if (napiVersion > 8) {
|
|
52
|
+
assert.throws(() => binding.error.throwSyntaxErrorCStr('test'), function (err) {
|
|
53
|
+
return err instanceof SyntaxError && err.message === 'test';
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
assert.throws(() => binding.error.throwSyntaxError('test'), function (err) {
|
|
57
|
+
return err instanceof SyntaxError && err.message === 'test';
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
assert.throws(() => binding.error.throwSyntaxErrorCtor(new SyntaxError('syntaxTypeError')), function (err) {
|
|
61
|
+
return err instanceof SyntaxError && err.message === 'syntaxTypeError';
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
assert.throws(
|
|
50
66
|
() => binding.error.doNotCatch(
|
|
51
67
|
() => {
|
|
@@ -60,6 +60,7 @@ function loadTestModules (currentDirectory = __dirname, pre = '') {
|
|
|
60
60
|
file === 'binding.gyp' ||
|
|
61
61
|
file === 'build' ||
|
|
62
62
|
file === 'common' ||
|
|
63
|
+
file === 'child_processes' ||
|
|
63
64
|
file === 'napi_child.js' ||
|
|
64
65
|
file === 'testUtil.js' ||
|
|
65
66
|
file === 'thunking_manual.cc' ||
|
|
@@ -137,6 +138,10 @@ if (napiVersion < 8 && !filterConditionsProvided) {
|
|
|
137
138
|
testModules.splice(testModules.indexOf('type_taggable'), 1);
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
if (napiVersion < 9 && !filterConditionsProvided) {
|
|
142
|
+
testModules.splice(testModules.indexOf('env_misc'), 1);
|
|
143
|
+
}
|
|
144
|
+
|
|
140
145
|
(async function () {
|
|
141
146
|
console.log(`Testing with Node-API Version '${napiVersion}'.`);
|
|
142
147
|
|
|
@@ -18,28 +18,26 @@ class FunctionTest : public Napi::ObjectWrap<FunctionTest> {
|
|
|
18
18
|
return MaybeUnwrap(GetConstructor(info.Env()).New(args));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// Constructor-per-env map in a static member because env.SetInstanceData()
|
|
22
|
-
// would interfere with Napi::Addon<T>
|
|
23
|
-
static std::unordered_map<napi_env, Napi::FunctionReference> constructors;
|
|
24
|
-
|
|
25
21
|
static void Initialize(Napi::Env env, Napi::Object exports) {
|
|
26
22
|
const char* name = "FunctionTest";
|
|
27
23
|
Napi::Function func = DefineClass(env, name, {});
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
Napi::FunctionReference* ctor = new Napi::FunctionReference();
|
|
25
|
+
*ctor = Napi::Persistent(func);
|
|
26
|
+
env.SetInstanceData(ctor);
|
|
30
27
|
exports.Set(name, func);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
static Napi::Function GetConstructor(Napi::Env env) {
|
|
34
|
-
return
|
|
31
|
+
return env.GetInstanceData<Napi::FunctionReference>()->Value();
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
Napi::Value ObjectWrapFunctionFactory(const Napi::CallbackInfo& info) {
|
|
36
|
+
Napi::Object exports = Napi::Object::New(info.Env());
|
|
37
|
+
FunctionTest::Initialize(info.Env(), exports);
|
|
38
|
+
return exports;
|
|
39
|
+
}
|
|
40
40
|
|
|
41
41
|
Napi::Object InitObjectWrapFunction(Napi::Env env) {
|
|
42
|
-
|
|
43
|
-
FunctionTest::Initialize(env, exports);
|
|
44
|
-
return exports;
|
|
42
|
+
return Napi::Function::New<ObjectWrapFunctionFactory>(env, "FunctionFactory");
|
|
45
43
|
}
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return testUtil.runGCTests([
|
|
8
|
-
'objectwrap function',
|
|
9
|
-
() => {
|
|
10
|
-
const { FunctionTest } = binding.objectwrap_function;
|
|
11
|
-
const newConstructed = new FunctionTest();
|
|
12
|
-
const functionConstructed = FunctionTest();
|
|
13
|
-
assert(newConstructed instanceof FunctionTest);
|
|
14
|
-
assert(functionConstructed instanceof FunctionTest);
|
|
15
|
-
assert.throws(() => (FunctionTest(true)), /an exception/);
|
|
16
|
-
},
|
|
17
|
-
// Do on gc before returning.
|
|
18
|
-
() => {}
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = require('./common').runTest(test);
|
|
3
|
+
module.exports = require('./common').runTestInChildProcess({
|
|
4
|
+
suite: 'objectwrap_function',
|
|
5
|
+
testName: 'runTest'
|
|
6
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#include <cstdlib>
|
|
2
|
+
#include "napi.h"
|
|
3
|
+
#include "test_helper.h"
|
|
4
|
+
|
|
5
|
+
#if (NAPI_VERSION > 3)
|
|
6
|
+
|
|
7
|
+
using namespace Napi;
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
void CallJS(napi_env env, napi_value /* callback */, void* /*data*/) {
|
|
12
|
+
Napi::Error error = Napi::Error::New(env, "test-from-native");
|
|
13
|
+
NAPI_THROW_VOID(error);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void TestCall(const CallbackInfo& info) {
|
|
17
|
+
Napi::Env env = info.Env();
|
|
18
|
+
|
|
19
|
+
ThreadSafeFunction wrapped =
|
|
20
|
+
ThreadSafeFunction::New(env,
|
|
21
|
+
info[0].As<Napi::Function>(),
|
|
22
|
+
Object::New(env),
|
|
23
|
+
String::New(env, "Test"),
|
|
24
|
+
0,
|
|
25
|
+
1);
|
|
26
|
+
wrapped.BlockingCall(static_cast<void*>(nullptr));
|
|
27
|
+
wrapped.Release();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void TestCallWithNativeCallback(const CallbackInfo& info) {
|
|
31
|
+
Napi::Env env = info.Env();
|
|
32
|
+
|
|
33
|
+
ThreadSafeFunction wrapped = ThreadSafeFunction::New(
|
|
34
|
+
env, Napi::Function(), Object::New(env), String::New(env, "Test"), 0, 1);
|
|
35
|
+
wrapped.BlockingCall(static_cast<void*>(nullptr), CallJS);
|
|
36
|
+
wrapped.Release();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
} // namespace
|
|
40
|
+
|
|
41
|
+
Object InitThreadSafeFunctionException(Env env) {
|
|
42
|
+
Object exports = Object::New(env);
|
|
43
|
+
exports["testCall"] = Function::New(env, TestCall);
|
|
44
|
+
exports["testCallWithNativeCallback"] =
|
|
45
|
+
Function::New(env, TestCallWithNativeCallback);
|
|
46
|
+
|
|
47
|
+
return exports;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#endif
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const common = require('../common');
|
|
4
|
+
|
|
5
|
+
module.exports = common.runTest(test);
|
|
6
|
+
|
|
7
|
+
const execArgv = ['--force-node-api-uncaught-exceptions-policy=true'];
|
|
8
|
+
async function test () {
|
|
9
|
+
await common.runTestInChildProcess({
|
|
10
|
+
suite: 'threadsafe_function_exception',
|
|
11
|
+
testName: 'testCall',
|
|
12
|
+
execArgv
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await common.runTestInChildProcess({
|
|
16
|
+
suite: 'threadsafe_function_exception',
|
|
17
|
+
testName: 'testCallWithNativeCallback',
|
|
18
|
+
execArgv
|
|
19
|
+
});
|
|
20
|
+
}
|
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.cc
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#include <cstdlib>
|
|
2
|
+
#include "napi.h"
|
|
3
|
+
#include "test_helper.h"
|
|
4
|
+
|
|
5
|
+
#if (NAPI_VERSION > 3)
|
|
6
|
+
|
|
7
|
+
using namespace Napi;
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
void CallJS(Napi::Env env,
|
|
12
|
+
Napi::Function /* callback */,
|
|
13
|
+
std::nullptr_t* /* context */,
|
|
14
|
+
void* /*data*/) {
|
|
15
|
+
Napi::Error error = Napi::Error::New(env, "test-from-native");
|
|
16
|
+
NAPI_THROW_VOID(error);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
using TSFN = TypedThreadSafeFunction<std::nullptr_t, void, CallJS>;
|
|
20
|
+
|
|
21
|
+
void TestCall(const CallbackInfo& info) {
|
|
22
|
+
Napi::Env env = info.Env();
|
|
23
|
+
|
|
24
|
+
TSFN wrapped = TSFN::New(
|
|
25
|
+
env, Napi::Function(), Object::New(env), String::New(env, "Test"), 0, 1);
|
|
26
|
+
wrapped.BlockingCall(static_cast<void*>(nullptr));
|
|
27
|
+
wrapped.Release();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace
|
|
31
|
+
|
|
32
|
+
Object InitTypedThreadSafeFunctionException(Env env) {
|
|
33
|
+
Object exports = Object::New(env);
|
|
34
|
+
exports["testCall"] = Function::New(env, TestCall);
|
|
35
|
+
|
|
36
|
+
return exports;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#endif
|
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const common = require('../common');
|
|
4
|
+
|
|
5
|
+
module.exports = common.runTest(test);
|
|
6
|
+
|
|
7
|
+
async function test () {
|
|
8
|
+
await common.runTestInChildProcess({
|
|
9
|
+
suite: 'typed_threadsafe_function_exception',
|
|
10
|
+
testName: 'testCall',
|
|
11
|
+
execArgv: ['--force-node-api-uncaught-exceptions-policy=true']
|
|
12
|
+
});
|
|
13
|
+
}
|