-
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.
There was a bug that didn't allow you to run execute multiple times, especially after something like a delay. A flag was being reset. Being able to run .execute multiple times is part of the charm. Includes a test. Run with "node fix2.js"
- Loading branch information
Showing
2 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
|
||
process.stdout.write("\u001b[2J\u001b[00H") // clear screen | ||
const { Sandbox, SandboxCluster } = require('../v8-sandbox') | ||
let sandbox = new Sandbox({ memory: 1000 }) | ||
|
||
let code1 = ` | ||
let t = 1 | ||
console.log(t) // works | ||
`; // always end with semicolon | ||
|
||
let code2 = ` // repeated executes STACK and should keep their values | ||
t++ | ||
console.log(t) | ||
`; | ||
|
||
(async () => { | ||
|
||
const RUN = 4 | ||
console.log('Test no.' + RUN) | ||
|
||
// test 1 (runs in sync) (works) | ||
if(RUN === 1) { | ||
sandbox.execute({ code: code1 }) | ||
sandbox.execute({ code: code2 }) | ||
} | ||
|
||
////////////////////////////////////////// | ||
|
||
// test 2 (runs first in async/second sync) (doesn't work, even though it should!) | ||
if(RUN === 2) { | ||
await sandbox.execute({ code: code1 }) | ||
sandbox.execute({ code: code2 }) | ||
} | ||
|
||
////////////////////////////////////////// | ||
|
||
// test 3 (run in async) (doesn't work, even though it should!) | ||
if(RUN === 3) { | ||
await sandbox.execute({ code: code1 }) | ||
await sandbox.execute({ code: code2 }) | ||
} | ||
|
||
////////////////////////////////////////// | ||
|
||
// test 4 (promise result also doesn't work, even though it should!) | ||
if(RUN === 4) { | ||
sandbox.execute({ code: code1 }).then(() => | ||
// doesn't work, even though it should! | ||
// because of a flag being reset in sandbox.js code | ||
// this is fixed now. | ||
setTimeout(async() => { | ||
sandbox.execute({ code: code2 }) // should display '2' (after fix) | ||
}, 2000) | ||
) | ||
} | ||
})() |