node/test/parallel/test-wrap-js-stream-exceptions.js
Anna Henningsen 36daf1d634
src: harden JSStream callbacks
Since these are executing JS code, and in particular parts of that
code may be provided by userland, handle such exceptions in C++.

Refs: https://github.com/nodejs/node/pull/17938#issuecomment-354683850
PR-URL: https://github.com/nodejs/node/pull/18028
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-01-14 14:54:53 +01:00

20 lines
556 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const JSStreamWrap = require('internal/wrap_js_stream');
const { Duplex } = require('stream');
process.once('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err.message, 'exception!');
}));
const socket = new JSStreamWrap(new Duplex({
read: common.mustCall(),
write: common.mustCall((buffer, data, cb) => {
throw new Error('exception!');
})
}));
assert.throws(() => socket.end('foo'), /Error: write EPROTO/);