diff --git a/test/error.cc b/test/error.cc index f6a43984a..8225466e0 100644 --- a/test/error.cc +++ b/test/error.cc @@ -78,6 +78,13 @@ void ThrowJSError(const CallbackInfo& info) { throw Error::New(info.Env(), message); } +void ThrowTypeErrorCtor(const CallbackInfo& info) { + Napi::Value js_type_error = info[0]; + ReleaseAndWaitForChildProcess(info, 1); + + throw Napi::TypeError(info.Env(), js_type_error); +} + void ThrowTypeError(const CallbackInfo& info) { std::string message = info[0].As().Utf8Value(); @@ -85,6 +92,30 @@ void ThrowTypeError(const CallbackInfo& info) { throw TypeError::New(info.Env(), message); } +void ThrowTypeErrorCStr(const CallbackInfo& info) { + std::string message = info[0].As().Utf8Value(); + + ReleaseAndWaitForChildProcess(info, 1); + throw TypeError::New(info.Env(), message.c_str()); +} + +void ThrowRangeErrorCStr(const CallbackInfo& info) { + std::string message = info[0].As().Utf8Value(); + ReleaseAndWaitForChildProcess(info, 1); + throw RangeError::New(info.Env(), message.c_str()); +} + +void ThrowRangeErrorCtor(const CallbackInfo& info) { + Napi::Value js_range_err = info[0]; + ReleaseAndWaitForChildProcess(info, 1); + throw Napi::RangeError(info.Env(), js_range_err); +} + +void ThrowEmptyRangeError(const CallbackInfo& info) { + ReleaseAndWaitForChildProcess(info, 1); + throw RangeError(); +} + void ThrowRangeError(const CallbackInfo& info) { std::string message = info[0].As().Utf8Value(); @@ -156,6 +187,19 @@ void ThrowTypeError(const CallbackInfo& info) { TypeError::New(info.Env(), message).ThrowAsJavaScriptException(); } +void ThrowTypeErrorCtor(const CallbackInfo& info) { + Napi::Value js_type_error = info[0]; + ReleaseAndWaitForChildProcess(info, 1); + TypeError(info.Env(), js_type_error).ThrowAsJavaScriptException(); +} + +void ThrowTypeErrorCStr(const CallbackInfo& info) { + std::string message = info[0].As().Utf8Value(); + + ReleaseAndWaitForChildProcess(info, 1); + TypeError::New(info.Env(), message.c_str()).ThrowAsJavaScriptException(); +} + void ThrowRangeError(const CallbackInfo& info) { std::string message = info[0].As().Utf8Value(); @@ -163,6 +207,24 @@ void ThrowRangeError(const CallbackInfo& info) { RangeError::New(info.Env(), message).ThrowAsJavaScriptException(); } +void ThrowRangeErrorCtor(const CallbackInfo& info) { + Napi::Value js_range_err = info[0]; + ReleaseAndWaitForChildProcess(info, 1); + RangeError(info.Env(), js_range_err).ThrowAsJavaScriptException(); +} + +void ThrowRangeErrorCStr(const CallbackInfo& info) { + std::string message = info[0].As().Utf8Value(); + ReleaseAndWaitForChildProcess(info, 1); + RangeError::New(info.Env(), message.c_str()).ThrowAsJavaScriptException(); +} + +// TODO: Figure out the correct api for this +void ThrowEmptyRangeError(const CallbackInfo& info) { + ReleaseAndWaitForChildProcess(info, 1); + RangeError().ThrowAsJavaScriptException(); +} + Value CatchError(const CallbackInfo& info) { Function thrower = info[0].As(); thrower({}); @@ -270,7 +332,12 @@ Object InitError(Env env) { Function::New(env, LastExceptionErrorCode); exports["throwJSError"] = Function::New(env, ThrowJSError); exports["throwTypeError"] = Function::New(env, ThrowTypeError); + exports["throwTypeErrorCtor"] = Function::New(env, ThrowTypeErrorCtor); + exports["throwTypeErrorCStr"] = Function::New(env, ThrowTypeErrorCStr); exports["throwRangeError"] = Function::New(env, ThrowRangeError); + exports["throwRangeErrorCtor"] = Function::New(env, ThrowRangeErrorCtor); + exports["throwRangeErrorCStr"] = Function::New(env, ThrowRangeErrorCStr); + exports["throwEmptyRangeError"] = Function::New(env, ThrowEmptyRangeError); exports["catchError"] = Function::New(env, CatchError); exports["catchErrorMessage"] = Function::New(env, CatchErrorMessage); exports["doNotCatch"] = Function::New(env, DoNotCatch); diff --git a/test/error.js b/test/error.js index d1519ec8e..4d4a72b56 100644 --- a/test/error.js +++ b/test/error.js @@ -24,14 +24,26 @@ function test (bindingPath) { return err instanceof Error && err.message === 'test'; }); - assert.throws(() => binding.error.throwTypeError('test'), function (err) { + assert.throws(() => binding.error.throwTypeErrorCStr('test'), function (err) { return err instanceof TypeError && err.message === 'test'; }); + assert.throws(() => binding.error.throwRangeErrorCStr('test'), function (err) { + return err instanceof RangeError && err.message === 'test'; + }); + assert.throws(() => binding.error.throwRangeError('test'), function (err) { return err instanceof RangeError && err.message === 'test'; }); + assert.throws(() => binding.error.throwTypeErrorCtor(new TypeError('jsTypeError')), function (err) { + return err instanceof TypeError && err.message === 'jsTypeError'; + }); + + assert.throws(() => binding.error.throwRangeErrorCtor(new RangeError('rangeTypeError')), function (err) { + return err instanceof RangeError && err.message === 'rangeTypeError'; + }); + assert.throws( () => binding.error.doNotCatch( () => {