diff --git a/src/node_jsvmapi.cc b/src/node_jsvmapi.cc index d77fd54ec03a6c..26ecc0078c7a94 100644 --- a/src/node_jsvmapi.cc +++ b/src/node_jsvmapi.cc @@ -523,7 +523,7 @@ napi_value napi_get_global_scope(napi_env e) { return v8impl::JsValueFromV8LocalValue(context->Global()); } -void napi_throw_error(napi_env e, napi_value error) { +void napi_throw(napi_env e, napi_value error) { v8::Isolate *isolate = v8impl::V8IsolateFromJsEnv(e); isolate->ThrowException( diff --git a/src/node_jsvmapi.h b/src/node_jsvmapi.h index 9944f61e032d55..8131045277c1fb 100644 --- a/src/node_jsvmapi.h +++ b/src/node_jsvmapi.h @@ -137,7 +137,7 @@ NODE_EXTERN napi_value napi_escape_handle(napi_env e, napi_escapable_handle_scop // Methods to support error handling -NODE_EXTERN void napi_throw_error(napi_env e, napi_value error); +NODE_EXTERN void napi_throw(napi_env e, napi_value error); // TODO (ianhall): APIs for handling try catch semantics need serious design analysis, this is just a quick hack // One thing to note is that v8::TryCatch relies on the current stack pointer position, so it cannot be used diff --git a/test/addons-abi/1_hello_world/binding.cc b/test/addons-abi/1_hello_world/binding.cc index b6be25897951e5..63edcc4511bac2 100644 --- a/test/addons-abi/1_hello_world/binding.cc +++ b/test/addons-abi/1_hello_world/binding.cc @@ -1,16 +1,16 @@ #include -void Method(napi_env napi_env, napi_func_cb_info info) { +void Method(napi_env env, napi_func_cb_info info) { napi_set_return_value( - napi_env, + env, info, - napi_create_string(napi_env, "world")); + napi_create_string(env, "world")); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, exports, - napi_property_name(napi_env, "hello"), - napi_create_function(napi_env, Method)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, exports, + napi_property_name(env, "hello"), + napi_create_function(env, Method)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/2_function_arguments/binding.cc b/test/addons-abi/2_function_arguments/binding.cc index d205beb53ca657..f775d92757baec 100644 --- a/test/addons-abi/2_function_arguments/binding.cc +++ b/test/addons-abi/2_function_arguments/binding.cc @@ -1,40 +1,40 @@ #include -void Add(napi_env napi_env, napi_func_cb_info info) { - if (napi_get_cb_args_length(napi_env, info) < 2) { - napi_throw_error( - napi_env, +void Add(napi_env env, napi_func_cb_info info) { + if (napi_get_cb_args_length(env, info) < 2) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong number of arguments"))); + env, + napi_create_string(env, "Wrong number of arguments"))); return; } napi_value args[2]; - napi_get_cb_args(napi_env, info, args, 2); + napi_get_cb_args(env, info, args, 2); - if (napi_get_type_of_value(napi_env, args[0]) != napi_number || - napi_get_type_of_value(napi_env, args[1]) != napi_number) { - napi_throw_error( - napi_env, + if (napi_get_type_of_value(env, args[0]) != napi_number || + napi_get_type_of_value(env, args[1]) != napi_number) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong arguments"))); + env, + napi_create_string(env, "Wrong arguments"))); return; } - double value = napi_get_number_from_value(napi_env, args[0]) - + napi_get_number_from_value(napi_env, args[1]); - napi_value num = napi_create_number(napi_env, value); + double value = napi_get_number_from_value(env, args[0]) + + napi_get_number_from_value(env, args[1]); + napi_value num = napi_create_number(env, value); - napi_set_return_value(napi_env, info, num); + napi_set_return_value(env, info, num); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, exports, - napi_property_name(napi_env, "add"), - napi_create_function(napi_env, Add)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, exports, + napi_property_name(env, "add"), + napi_create_function(env, Add)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/3_callbacks/binding.cc b/test/addons-abi/3_callbacks/binding.cc index 9a728881e86c9d..9a65ebfc6ab508 100644 --- a/test/addons-abi/3_callbacks/binding.cc +++ b/test/addons-abi/3_callbacks/binding.cc @@ -1,19 +1,19 @@ #include -void RunCallback(napi_env napi_env, const napi_func_cb_info info) { +void RunCallback(napi_env env, const napi_func_cb_info info) { napi_value args[1]; - napi_get_cb_args(napi_env, info, args, 1); + napi_get_cb_args(env, info, args, 1); napi_value cb = args[0]; napi_value argv[1]; - argv[0] = napi_create_string(napi_env, "hello world"); - napi_call_function(napi_env, napi_get_global_scope(napi_env) , cb, 1, argv); + argv[0] = napi_create_string(env, "hello world"); + napi_call_function(env, napi_get_global_scope(env) , cb, 1, argv); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, module, - napi_property_name(napi_env, "exports"), - napi_create_function(napi_env, RunCallback)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, module, + napi_property_name(env, "exports"), + napi_create_function(env, RunCallback)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/4_object_factory/binding.cc b/test/addons-abi/4_object_factory/binding.cc index 03bf6a4316eef3..08b0776425b995 100644 --- a/test/addons-abi/4_object_factory/binding.cc +++ b/test/addons-abi/4_object_factory/binding.cc @@ -1,20 +1,20 @@ #include -void napi_create_object(napi_env napi_env, const napi_func_cb_info info) { +void napi_create_object(napi_env env, const napi_func_cb_info info) { napi_value args[1]; - napi_get_cb_args(napi_env, info, args, 1); + napi_get_cb_args(env, info, args, 1); - napi_value obj = napi_create_object(napi_env); - napi_set_property(napi_env, obj, napi_property_name(napi_env, "msg"), + napi_value obj = napi_create_object(env); + napi_set_property(env, obj, napi_property_name(env, "msg"), args[0]); - napi_set_return_value(napi_env, info, obj); + napi_set_return_value(env, info, obj); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, module, - napi_property_name(napi_env, "exports"), - napi_create_function(napi_env, napi_create_object)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, module, + napi_property_name(env, "exports"), + napi_create_function(env, napi_create_object)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/5_function_factory/binding.cc b/test/addons-abi/5_function_factory/binding.cc index 505359813a3c64..fd890ea43ef757 100644 --- a/test/addons-abi/5_function_factory/binding.cc +++ b/test/addons-abi/5_function_factory/binding.cc @@ -1,22 +1,22 @@ #include -void MyFunction(napi_env napi_env, napi_func_cb_info info) { - napi_set_return_value(napi_env, info, napi_create_string(napi_env, "hello world")); +void MyFunction(napi_env env, napi_func_cb_info info) { + napi_set_return_value(env, info, napi_create_string(env, "hello world")); } -void napi_create_function(napi_env napi_env, napi_func_cb_info info) { - napi_value fn = napi_create_function(napi_env, MyFunction); +void napi_create_function(napi_env env, napi_func_cb_info info) { + napi_value fn = napi_create_function(env, MyFunction); // omit this to make it anonymous - napi_set_function_name(napi_env, fn, napi_property_name(napi_env, "theFunction")); + napi_set_function_name(env, fn, napi_property_name(env, "theFunction")); - napi_set_return_value(napi_env, info, fn); + napi_set_return_value(env, info, fn); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, module, - napi_property_name(napi_env, "exports"), - napi_create_function(napi_env, napi_create_function)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, module, + napi_property_name(env, "exports"), + napi_create_function(env, napi_create_function)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/6_object_wrap/binding.cc b/test/addons-abi/6_object_wrap/binding.cc index 3d2d9b9f5b21be..8e435da8171841 100644 --- a/test/addons-abi/6_object_wrap/binding.cc +++ b/test/addons-abi/6_object_wrap/binding.cc @@ -1,7 +1,7 @@ #include "myobject.h" -void Init(napi_env napi_env, napi_value exports, napi_value module) { - MyObject::Init(napi_env, exports); +void Init(napi_env env, napi_value exports, napi_value module) { + MyObject::Init(env, exports); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/test_function/test_function.cc b/test/addons-abi/test_function/test_function.cc index de041fcf59387c..47c80d52962268 100644 --- a/test/addons-abi/test_function/test_function.cc +++ b/test/addons-abi/test_function/test_function.cc @@ -1,42 +1,42 @@ #include -void Test(napi_env napi_env, napi_func_cb_info info) { - if (napi_get_cb_args_length(napi_env, info) < 1) { - napi_throw_error( - napi_env, +void Test(napi_env env, napi_func_cb_info info) { + if (napi_get_cb_args_length(env, info) < 1) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong number of arguments"))); + env, + napi_create_string(env, "Wrong number of arguments"))); return; } napi_value args[10]; - napi_get_cb_args(napi_env, info, args, 10); + napi_get_cb_args(env, info, args, 10); - if (napi_get_type_of_value(napi_env, args[0]) != napi_function) { - napi_throw_error( - napi_env, + if (napi_get_type_of_value(env, args[0]) != napi_function) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong type of argments. Expects a function."))); + env, + napi_create_string(env, "Wrong type of argments. Expects a function."))); return; } napi_value function = args[0]; - int argc = napi_get_cb_args_length(napi_env, info) - 1; + int argc = napi_get_cb_args_length(env, info) - 1; napi_value* argv = args + 1; - napi_escapable_handle_scope scope = napi_open_escapable_handle_scope(napi_env); + napi_escapable_handle_scope scope = napi_open_escapable_handle_scope(env); napi_value scope_val = reinterpret_cast (scope); - napi_value output = napi_call_function(napi_env, scope_val, function, argc, argv); - napi_close_escapable_handle_scope(napi_env, scope); - napi_set_return_value(napi_env, info, output); + napi_value output = napi_call_function(env, scope_val, function, argc, argv); + napi_close_escapable_handle_scope(env, scope); + napi_set_return_value(env, info, output); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, exports, - napi_property_name(napi_env, "Test"), - napi_create_function(napi_env, Test)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, exports, + napi_property_name(env, "Test"), + napi_create_function(env, Test)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/test_number/test_number.cc b/test/addons-abi/test_number/test_number.cc index 8531c704061d70..947820f324bfb1 100644 --- a/test/addons-abi/test_number/test_number.cc +++ b/test/addons-abi/test_number/test_number.cc @@ -1,36 +1,36 @@ #include -void Test(napi_env napi_env, napi_func_cb_info info) { - if (napi_get_cb_args_length(napi_env, info) < 1) { - napi_throw_error( - napi_env, +void Test(napi_env env, napi_func_cb_info info) { + if (napi_get_cb_args_length(env, info) < 1) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong number of arguments"))); + env, + napi_create_string(env, "Wrong number of arguments"))); return; } napi_value args[1]; - napi_get_cb_args(napi_env, info, args, 1); + napi_get_cb_args(env, info, args, 1); - if (napi_get_type_of_value(napi_env, args[0]) != napi_number) { - napi_throw_error( - napi_env, + if (napi_get_type_of_value(env, args[0]) != napi_number) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong type of argments. Expects a number."))); + env, + napi_create_string(env, "Wrong type of argments. Expects a number."))); return; } - double input = napi_get_number_from_value(napi_env, args[0]); - napi_value output = napi_create_number(napi_env, input); - napi_set_return_value(napi_env, info, output); + double input = napi_get_number_from_value(env, args[0]); + napi_value output = napi_create_number(env, input); + napi_set_return_value(env, info, output); } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, exports, - napi_property_name(napi_env, "Test"), - napi_create_function(napi_env, Test)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, exports, + napi_property_name(env, "Test"), + napi_create_function(env, Test)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/test_object/test_object.cc b/test/addons-abi/test_object/test_object.cc index 154d32e1e7cf05..a19dbb0ae7a5c4 100644 --- a/test/addons-abi/test_object/test_object.cc +++ b/test/addons-abi/test_object/test_object.cc @@ -1,50 +1,50 @@ #include -void Test(napi_env napi_env, napi_func_cb_info info) { - if (napi_get_cb_args_length(napi_env, info) < 2) { - napi_throw_error( - napi_env, +void Test(napi_env env, napi_func_cb_info info) { + if (napi_get_cb_args_length(env, info) < 2) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong number of arguments"))); + env, + napi_create_string(env, "Wrong number of arguments"))); return; } napi_value args[2]; - napi_get_cb_args(napi_env, info, args, 2); + napi_get_cb_args(env, info, args, 2); - if (napi_get_type_of_value(napi_env, args[0]) != napi_object) { - napi_throw_error( - napi_env, + if (napi_get_type_of_value(env, args[0]) != napi_object) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong type of argments. Expects an object as first argument."))); + env, + napi_create_string(env, "Wrong type of argments. Expects an object as first argument."))); return; } - if (napi_get_type_of_value(napi_env, args[1]) != napi_string) { - napi_throw_error( - napi_env, + if (napi_get_type_of_value(env, args[1]) != napi_string) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong type of argments. Expects a string as second argument."))); + env, + napi_create_string(env, "Wrong type of argments. Expects a string as second argument."))); return; } napi_value object = args[0]; char buffer [128]; int buffer_size = 128; - bool success = napi_get_string_from_value(napi_env, args[1], buffer, buffer_size); + bool success = napi_get_string_from_value(env, args[1], buffer, buffer_size); if (success) { - napi_propertyname property_name = napi_property_name(napi_env, buffer); - napi_value output = napi_get_property(napi_env, object, property_name); - napi_set_return_value(napi_env, info, output); + napi_propertyname property_name = napi_property_name(env, buffer); + napi_value output = napi_get_property(env, object, property_name); + napi_set_return_value(env, info, output); } } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, exports, - napi_property_name(napi_env, "Test"), - napi_create_function(napi_env, Test)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, exports, + napi_property_name(env, "Test"), + napi_create_function(env, Test)); } NODE_MODULE_ABI(addon, Init) diff --git a/test/addons-abi/test_string/test_string.cc b/test/addons-abi/test_string/test_string.cc index 65a7c9f82b971b..6cd67865bf0cda 100644 --- a/test/addons-abi/test_string/test_string.cc +++ b/test/addons-abi/test_string/test_string.cc @@ -1,40 +1,40 @@ #include -void Test(napi_env napi_env, napi_func_cb_info info) { - if (napi_get_cb_args_length(napi_env, info) < 1) { - napi_throw_error( - napi_env, +void Test(napi_env env, napi_func_cb_info info) { + if (napi_get_cb_args_length(env, info) < 1) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong number of arguments"))); + env, + napi_create_string(env, "Wrong number of arguments"))); return; } napi_value args[1]; - napi_get_cb_args(napi_env, info, args, 1); + napi_get_cb_args(env, info, args, 1); - if (napi_get_type_of_value(napi_env, args[0]) != napi_string) { - napi_throw_error( - napi_env, + if (napi_get_type_of_value(env, args[0]) != napi_string) { + napi_throw( + env, napi_create_type_error( - napi_env, - napi_create_string(napi_env, "Wrong type of argments. Expects a string."))); + env, + napi_create_string(env, "Wrong type of argments. Expects a string."))); return; } char buffer[128]; int buffer_size = 128; - bool success = napi_get_string_from_value(napi_env, args[0], buffer, buffer_size); + bool success = napi_get_string_from_value(env, args[0], buffer, buffer_size); if (success) { - napi_value output = napi_create_string(napi_env, buffer); - napi_set_return_value(napi_env, info, output); + napi_value output = napi_create_string(env, buffer); + napi_set_return_value(env, info, output); } } -void Init(napi_env napi_env, napi_value exports, napi_value module) { - napi_set_property(napi_env, exports, - napi_property_name(napi_env, "Test"), - napi_create_function(napi_env, Test)); +void Init(napi_env env, napi_value exports, napi_value module) { + napi_set_property(env, exports, + napi_property_name(env, "Test"), + napi_create_function(env, Test)); } NODE_MODULE_ABI(addon, Init)