11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../../common'); 41cb0ef41Sopenharmony_ciconst test_error = require(`./build/${common.buildType}/test_error`); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst theError = new Error('Some error'); 71cb0ef41Sopenharmony_ciconst theTypeError = new TypeError('Some type error'); 81cb0ef41Sopenharmony_ciconst theSyntaxError = new SyntaxError('Some syntax error'); 91cb0ef41Sopenharmony_ciconst theRangeError = new RangeError('Some type error'); 101cb0ef41Sopenharmony_ciconst theReferenceError = new ReferenceError('Some reference error'); 111cb0ef41Sopenharmony_ciconst theURIError = new URIError('Some URI error'); 121cb0ef41Sopenharmony_ciconst theEvalError = new EvalError('Some eval error'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciclass MyError extends Error { } 151cb0ef41Sopenharmony_ciconst myError = new MyError('Some MyError'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// Test that native error object is correctly classed 181cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theError), true); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci// Test that native type error object is correctly classed 211cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theTypeError), true); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci// Test that native syntax error object is correctly classed 241cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theSyntaxError), true); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// Test that native range error object is correctly classed 271cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theRangeError), true); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci// Test that native reference error object is correctly classed 301cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theReferenceError), true); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci// Test that native URI error object is correctly classed 331cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theURIError), true); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// Test that native eval error object is correctly classed 361cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(theEvalError), true); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci// Test that class derived from native error is correctly classed 391cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError(myError), true); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci// Test that non-error object is correctly classed 421cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError({}), false); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci// Test that non-error primitive is correctly classed 451cb0ef41Sopenharmony_ciassert.strictEqual(test_error.checkError('non-object'), false); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciassert.throws(() => { 481cb0ef41Sopenharmony_ci test_error.throwExistingError(); 491cb0ef41Sopenharmony_ci}, /^Error: existing error$/); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciassert.throws(() => { 521cb0ef41Sopenharmony_ci test_error.throwError(); 531cb0ef41Sopenharmony_ci}, /^Error: error$/); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ciassert.throws(() => { 561cb0ef41Sopenharmony_ci test_error.throwRangeError(); 571cb0ef41Sopenharmony_ci}, /^RangeError: range error$/); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciassert.throws(() => { 601cb0ef41Sopenharmony_ci test_error.throwTypeError(); 611cb0ef41Sopenharmony_ci}, /^TypeError: type error$/); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciassert.throws(() => { 641cb0ef41Sopenharmony_ci test_error.throwSyntaxError(); 651cb0ef41Sopenharmony_ci}, /^SyntaxError: syntax error$/); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci[42, {}, [], Symbol('xyzzy'), true, 'ball', undefined, null, NaN] 681cb0ef41Sopenharmony_ci .forEach((value) => assert.throws( 691cb0ef41Sopenharmony_ci () => test_error.throwArbitrary(value), 701cb0ef41Sopenharmony_ci (err) => { 711cb0ef41Sopenharmony_ci assert.strictEqual(err, value); 721cb0ef41Sopenharmony_ci return true; 731cb0ef41Sopenharmony_ci }, 741cb0ef41Sopenharmony_ci )); 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ciassert.throws( 771cb0ef41Sopenharmony_ci () => test_error.throwErrorCode(), 781cb0ef41Sopenharmony_ci { 791cb0ef41Sopenharmony_ci code: 'ERR_TEST_CODE', 801cb0ef41Sopenharmony_ci message: 'Error [error]', 811cb0ef41Sopenharmony_ci }); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ciassert.throws( 841cb0ef41Sopenharmony_ci () => test_error.throwRangeErrorCode(), 851cb0ef41Sopenharmony_ci { 861cb0ef41Sopenharmony_ci code: 'ERR_TEST_CODE', 871cb0ef41Sopenharmony_ci message: 'RangeError [range error]', 881cb0ef41Sopenharmony_ci }); 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ciassert.throws( 911cb0ef41Sopenharmony_ci () => test_error.throwTypeErrorCode(), 921cb0ef41Sopenharmony_ci { 931cb0ef41Sopenharmony_ci code: 'ERR_TEST_CODE', 941cb0ef41Sopenharmony_ci message: 'TypeError [type error]', 951cb0ef41Sopenharmony_ci }); 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ciassert.throws( 981cb0ef41Sopenharmony_ci () => test_error.throwSyntaxErrorCode(), 991cb0ef41Sopenharmony_ci { 1001cb0ef41Sopenharmony_ci code: 'ERR_TEST_CODE', 1011cb0ef41Sopenharmony_ci message: 'SyntaxError [syntax error]', 1021cb0ef41Sopenharmony_ci }); 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_cilet error = test_error.createError(); 1051cb0ef41Sopenharmony_ciassert.ok(error instanceof Error, 'expected error to be an instance of Error'); 1061cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'error'); 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_cierror = test_error.createRangeError(); 1091cb0ef41Sopenharmony_ciassert.ok(error instanceof RangeError, 1101cb0ef41Sopenharmony_ci 'expected error to be an instance of RangeError'); 1111cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'range error'); 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_cierror = test_error.createTypeError(); 1141cb0ef41Sopenharmony_ciassert.ok(error instanceof TypeError, 1151cb0ef41Sopenharmony_ci 'expected error to be an instance of TypeError'); 1161cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'type error'); 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_cierror = test_error.createSyntaxError(); 1191cb0ef41Sopenharmony_ciassert.ok(error instanceof SyntaxError, 1201cb0ef41Sopenharmony_ci 'expected error to be an instance of SyntaxError'); 1211cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'syntax error'); 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_cierror = test_error.createErrorCode(); 1241cb0ef41Sopenharmony_ciassert.ok(error instanceof Error, 'expected error to be an instance of Error'); 1251cb0ef41Sopenharmony_ciassert.strictEqual(error.code, 'ERR_TEST_CODE'); 1261cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'Error [error]'); 1271cb0ef41Sopenharmony_ciassert.strictEqual(error.name, 'Error'); 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_cierror = test_error.createRangeErrorCode(); 1301cb0ef41Sopenharmony_ciassert.ok(error instanceof RangeError, 1311cb0ef41Sopenharmony_ci 'expected error to be an instance of RangeError'); 1321cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'RangeError [range error]'); 1331cb0ef41Sopenharmony_ciassert.strictEqual(error.code, 'ERR_TEST_CODE'); 1341cb0ef41Sopenharmony_ciassert.strictEqual(error.name, 'RangeError'); 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_cierror = test_error.createTypeErrorCode(); 1371cb0ef41Sopenharmony_ciassert.ok(error instanceof TypeError, 1381cb0ef41Sopenharmony_ci 'expected error to be an instance of TypeError'); 1391cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'TypeError [type error]'); 1401cb0ef41Sopenharmony_ciassert.strictEqual(error.code, 'ERR_TEST_CODE'); 1411cb0ef41Sopenharmony_ciassert.strictEqual(error.name, 'TypeError'); 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_cierror = test_error.createSyntaxErrorCode(); 1441cb0ef41Sopenharmony_ciassert.ok(error instanceof SyntaxError, 1451cb0ef41Sopenharmony_ci 'expected error to be an instance of SyntaxError'); 1461cb0ef41Sopenharmony_ciassert.strictEqual(error.message, 'SyntaxError [syntax error]'); 1471cb0ef41Sopenharmony_ciassert.strictEqual(error.code, 'ERR_TEST_CODE'); 1481cb0ef41Sopenharmony_ciassert.strictEqual(error.name, 'SyntaxError'); 149