2017-03-20 14:55:26 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../../common');
|
2018-01-23 21:49:25 +11:00
|
|
|
const test_exception = require(`./build/${common.buildType}/test_exception`);
|
2017-03-20 14:55:26 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
const theError = new Error('Some error');
|
2017-04-27 17:27:05 -07:00
|
|
|
function throwTheError() {
|
2017-03-20 14:55:26 -07:00
|
|
|
throw theError;
|
2017-04-27 17:27:05 -07:00
|
|
|
}
|
2017-03-20 14:55:26 -07:00
|
|
|
let caughtError;
|
|
|
|
|
|
|
|
// Test that the native side successfully captures the exception
|
|
|
|
let returnedError = test_exception.returnException(throwTheError);
|
2017-10-06 11:51:17 -07:00
|
|
|
assert.strictEqual(theError, returnedError);
|
2017-03-20 14:55:26 -07:00
|
|
|
|
|
|
|
// Test that the native side passes the exception through
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
test_exception.allowException(throwTheError);
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
return err === theError;
|
|
|
|
},
|
|
|
|
'Thrown exception was allowed to pass through unhindered'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test that the exception thrown above was marked as pending
|
|
|
|
// before it was handled on the JS side
|
|
|
|
assert.strictEqual(test_exception.wasPending(), true,
|
|
|
|
'VM was marked as having an exception pending' +
|
|
|
|
' when it was allowed through');
|
|
|
|
|
|
|
|
// Test that the native side does not capture a non-existing exception
|
2017-05-10 19:37:25 -07:00
|
|
|
returnedError = test_exception.returnException(common.mustCall());
|
2017-03-20 14:55:26 -07:00
|
|
|
assert.strictEqual(undefined, returnedError,
|
2017-11-06 16:27:05 +01:00
|
|
|
'Returned error should be undefined when no exception is' +
|
|
|
|
` thrown, but ${returnedError} was passed`);
|
2017-03-20 14:55:26 -07:00
|
|
|
|
|
|
|
// Test that no exception appears that was not thrown by us
|
|
|
|
try {
|
2017-05-10 19:37:25 -07:00
|
|
|
test_exception.allowException(common.mustCall());
|
2017-03-20 14:55:26 -07:00
|
|
|
} catch (anError) {
|
|
|
|
caughtError = anError;
|
|
|
|
}
|
|
|
|
assert.strictEqual(undefined, caughtError,
|
2017-11-06 16:27:05 +01:00
|
|
|
'No exception originated on the native side, but' +
|
|
|
|
` ${caughtError} was passed`);
|
2017-03-20 14:55:26 -07:00
|
|
|
|
|
|
|
// Test that the exception state remains clear when no exception is thrown
|
|
|
|
assert.strictEqual(test_exception.wasPending(), false,
|
|
|
|
'VM was not marked as having an exception pending' +
|
|
|
|
' when none was allowed through');
|