| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2043ce3 commit 2a1ebae
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,3 +52,23 @@ const fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} }); | |||
| 52 | 52 | global.gc(); | |
| 53 | 53 | fn(); | |
| 54 | 54 | // Should not crash | |
| 55 | + | ||
| 56 | + { | ||
| 57 | + // Verify that providing a custom filename as a string argument works. | ||
| 58 | + const code = 'throw new Error("foo");'; | ||
| 59 | + const file = 'test_file.vm'; | ||
| 60 | + | ||
| 61 | + assert.throws(() => { | ||
| 62 | + vm.runInNewContext(code, {}, file); | ||
| 63 | + }, (err) => { | ||
| 64 | + const lines = err.stack.split('\n'); | ||
| 65 | + | ||
| 66 | + assert.strictEqual(lines[0].trim(), `${file}:1`); | ||
| 67 | + assert.strictEqual(lines[1].trim(), code); | ||
| 68 | + // Skip lines[2] and lines[3]. They're just a ^ and blank line. | ||
| 69 | + assert.strictEqual(lines[4].trim(), 'Error: foo'); | ||
| 70 | + assert.strictEqual(lines[5].trim(), `at ${file}:1:7`); | ||
| 71 | + // The rest of the stack is uninteresting. | ||
| 72 | + return true; | ||
| 73 | + }); | ||
| 74 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments