Skip to content

Commit

Permalink
napi: RangeError (nodejs#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin authored Feb 10, 2017
1 parent 6f9070d commit 758fde2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/node_jsvmapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,17 @@ napi_status napi_create_type_error(napi_env e, napi_value msg, napi_value* resul
return GET_RETURN_STATUS();
}

napi_status napi_create_range_error(napi_env e, napi_value msg, napi_value* result) {
NAPI_PREAMBLE(e);
CHECK_ARG(result);

*result = v8impl::JsValueFromV8LocalValue(
v8::Exception::RangeError(
v8impl::V8LocalValueFromJsValue(msg).As<v8::String>()));

return GET_RETURN_STATUS();
}

napi_status napi_get_type_of_value(napi_env e, napi_value vv, napi_valuetype* result) {
NAPI_PREAMBLE(e);
CHECK_ARG(result);
Expand Down Expand Up @@ -1324,6 +1335,19 @@ napi_status napi_throw_type_error(napi_env e, const char* msg) {
return napi_ok;
}

napi_status napi_throw_range_error(napi_env e, const char* msg) {
NAPI_PREAMBLE(e);

v8::Isolate *isolate = v8impl::V8IsolateFromJsEnv(e);
v8::Local<v8::String> str;
CHECK_NEW_FROM_UTF8(isolate, str, msg);

isolate->ThrowException(v8::Exception::RangeError(str));
// any VM calls after this point and before returning
// to the javascript invoker will fail
return napi_ok;
}

napi_status napi_get_value_double(napi_env e, napi_value v, double* result) {
NAPI_PREAMBLE(e);
CHECK_ARG(result);
Expand Down
2 changes: 2 additions & 0 deletions src/node_jsvmapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ NODE_EXTERN napi_status napi_create_function(napi_env e, napi_callback cb,
void* data, napi_value* result);
NODE_EXTERN napi_status napi_create_error(napi_env e, napi_value msg, napi_value* result);
NODE_EXTERN napi_status napi_create_type_error(napi_env e, napi_value msg, napi_value* result);
NODE_EXTERN napi_status napi_create_range_error(napi_env e, napi_value msg, napi_value* result);

// Methods to get the the native napi_value from Primitive type
NODE_EXTERN napi_status napi_get_type_of_value(napi_env e, napi_value vv, napi_valuetype* result);
Expand Down Expand Up @@ -297,6 +298,7 @@ NODE_EXTERN napi_status napi_escape_handle(napi_env e,
NODE_EXTERN napi_status napi_throw(napi_env e, napi_value error);
NODE_EXTERN napi_status napi_throw_error(napi_env e, const char* msg);
NODE_EXTERN napi_status napi_throw_type_error(napi_env e, const char* msg);
NODE_EXTERN napi_status napi_throw_range_error(napi_env e, const char* msg);

// Methods to support catching exceptions
NODE_EXTERN napi_status napi_is_exception_pending(napi_env e, bool* result);
Expand Down

0 comments on commit 758fde2

Please sign in to comment.