-
Notifications
You must be signed in to change notification settings - Fork 44
/
node-index.js
32 lines (30 loc) · 1.24 KB
/
node-index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { createRequire } from 'module';
import { setRequire } from './open.js';
import { nativeAddon, setNativeFunctions } from './native.js';
export { nativeAddon } from './native.js'
let require = createRequire(import.meta.url);
setRequire(require);
export let v8AccelerationEnabled = false
let versions = process.versions;
if (!versions.deno && !process.isBun) {
let [ majorVersion, minorVersion ] = versions.node.split('.');
if (versions.v8 && +majorVersion == nativeAddon.version.nodeCompiledVersion) {
let v8Funcs = {};
let fastApiCalls = (majorVersion == 17 || majorVersion == 18 || majorVersion == 16 && minorVersion > 8) && !process.env.DISABLE_TURBO_CALLS;
if (fastApiCalls) {
require('v8').setFlagsFromString('--turbo-fast-api-calls');
}
nativeAddon.enableDirectV8(v8Funcs, fastApiCalls);
Object.assign(nativeAddon, v8Funcs);
v8AccelerationEnabled = true;
} else if (majorVersion == 14) {
// node v14 only has ABI compatibility with node v16 for zero-arg clearKeptObjects
let v8Funcs = {};
nativeAddon.enableDirectV8(v8Funcs, false);
nativeAddon.clearKeptObjects = v8Funcs.clearKeptObjects;
}
nativeAddon.enableThreadSafeCalls();
}
setNativeFunctions(nativeAddon);
export * from './index.js'
export { default } from './index.js'