forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename napi_throw_error to napi_throw
napi_throw_error is misleading since you can legitimately throw any napi_value (any javascript value). So renamed to napi_throw to clarify. This also leaves room for a napi_throw_error which would be a helper that creates a new error from a string and throws it for you, to collapse the otherwise three calls that would be needed into one. Also renamed a bunch of parameters named napi_env to just env for clarity.
- Loading branch information
Ian Halliday
committed
Jul 14, 2016
1 parent
77e2a6a
commit 0d92cf5
Showing
12 changed files
with
143 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
#include <node_jsvmapi.h> | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
#include <node_jsvmapi.h> | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
#include <node_jsvmapi.h> | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
#include <node_jsvmapi.h> | ||
|
||
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<napi_value> (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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
#include <node_jsvmapi.h> | ||
|
||
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) |
Oops, something went wrong.