isolated-function 0.1.4 → 0.1.5
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/README.md +2 -2
- package/package.json +1 -1
- package/src/index.js +4 -3
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ const [sum, teardown] = isolatedFunction((y, z) => y + z, {
|
|
|
53
53
|
})
|
|
54
54
|
|
|
55
55
|
/* interact with the isolated-function */
|
|
56
|
-
const
|
|
56
|
+
const { value, profiling } = await sum(3, 2)
|
|
57
57
|
console.log({ value, profiling })
|
|
58
58
|
|
|
59
59
|
/* close resources associated with the isolated-function initialization */
|
|
@@ -120,7 +120,7 @@ const [fn, teardown] = isolatedFunction(() => {
|
|
|
120
120
|
})
|
|
121
121
|
t.teardown(cleanup)
|
|
122
122
|
|
|
123
|
-
const
|
|
123
|
+
const { value, profiling } = await fn()
|
|
124
124
|
console.log(profiling)
|
|
125
125
|
// {
|
|
126
126
|
// memory: 128204800,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "isolated-function",
|
|
3
3
|
"description": "Runs untrusted code in a Node.js v8 sandbox.",
|
|
4
4
|
"homepage": "https://github.com/Kikobeats/isolated-function",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.5",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js"
|
package/src/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const flags = ({ filename, memory }) => {
|
|
|
20
20
|
return flags.join(' ')
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
module.exports = (snippet, { timeout = 0, memory } = {}) => {
|
|
23
|
+
module.exports = (snippet, { timeout = 0, memory, throwError = true } = {}) => {
|
|
24
24
|
if (!['function', 'string'].includes(typeof snippet)) throw new TypeError('Expected a function')
|
|
25
25
|
const compilePromise = compile(snippet)
|
|
26
26
|
|
|
@@ -41,8 +41,9 @@ module.exports = (snippet, { timeout = 0, memory } = {}) => {
|
|
|
41
41
|
})
|
|
42
42
|
const { isFulfilled, value, profiling } = JSON.parse(stdout)
|
|
43
43
|
profiling.duration = duration()
|
|
44
|
-
if (isFulfilled) return
|
|
45
|
-
throw deserializeError(value)
|
|
44
|
+
if (isFulfilled) return { isFulfilled, value, profiling }
|
|
45
|
+
if (throwError) throw deserializeError(value)
|
|
46
|
+
return { isFulfilled: false, value: deserializeError(value), profiling }
|
|
46
47
|
} catch (error) {
|
|
47
48
|
if (error.signalCode === 'SIGTRAP') {
|
|
48
49
|
throw createError({
|