-
-
Notifications
You must be signed in to change notification settings - Fork 601
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (23 loc) · 788 Bytes
/
index.js
File metadata and controls
30 lines (23 loc) · 788 Bytes
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
'use strict'
/**
* @type {import('./type')}
*/
const { NativeAddon } = require('bindings')('addon')
function JSFnRef() {
console.log('Hi! I\'m a JS function reference!')
}
function JSFn() {
console.log('Hi! I\'m a JS function!')
}
const ITERATIONS = 5
const addon = new NativeAddon(JSFnRef, JSFn)
for (let i = 0; i < ITERATIONS; i++) {
addon.tryCallByStoredReference()
}
try {
addon.tryCallByStoredFunction()
} catch (err) {
console.error('This code crashes because JSFn is valid only inside the constructor function.')
console.error('The lifespan of the JSFn function is limited to the execution of the constructor function.')
console.error('After that, the function stored in JSFn is ready to be garbage collected and it cannot be used anymore.')
}