-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a test, to showcase the bug-fix of Runtime
Run with "node fix1.js"
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
process.stdout.write("\u001b[2J\u001b[00H") // clear screen | ||
const { Sandbox, SandboxCluster } = require('../v8-sandbox') | ||
let sandbox = new Sandbox({ memory: 1000, require: __dirname + '/functions1.js' }) | ||
|
||
let code = ` | ||
async function test() { | ||
// always works! (water-fall/callback embedded) | ||
addNumbers(1, 2, function(result) { | ||
if(result.error) console.log('error1:', result.error) | ||
if(result.value) console.log('value1:', result.value) | ||
}) | ||
// only works with the runtime.js fix (standard await) | ||
// otherwise the last argument is removed, because it expects a callback (embedded) | ||
let {error, value} = await addNumbers(1, 2) | ||
if(error) console.log('error2:', error) | ||
if(value) console.log('value2:', value) | ||
} | ||
test() | ||
`; // always end with semicolon | ||
|
||
(async () => { | ||
|
||
// test 1 (runs in async) | ||
await sandbox.execute({ code }) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
// Create or require your own functions and libraries (more safe) | ||
|
||
// Async (water-fall method / callback) | ||
defineAsync('addNumbers', ([ value1, value2 ], { respond, callback }) => { | ||
respond() // always required! | ||
setTimeout(() => { | ||
callback({error: null, value: value1 + value2}) // send to sandbox | ||
}, 1000) // 1 sec delay (for testing) | ||
}) |