summaryrefslogtreecommitdiff
path: root/src/node_api.cc
diff options
context:
space:
mode:
authorSampson Gao <sampsong@ca.ibm.com>2017-09-11 09:57:38 -0400
committerMichael Dawson <mdawson@devrus.com>2017-09-18 17:47:34 -0400
commit19766547fa2a783b8e7472c31ad246ee118230ee (patch)
treeed10e4408d30883de3ac60524b433920c7c2a68d /src/node_api.cc
parentc75f87cc4c8d3699e081d37bb5bf47a70d830fdb (diff)
downloadandroid-node-v8-19766547fa2a783b8e7472c31ad246ee118230ee.tar.gz
android-node-v8-19766547fa2a783b8e7472c31ad246ee118230ee.tar.bz2
android-node-v8-19766547fa2a783b8e7472c31ad246ee118230ee.zip
n-api: add optional string length parameters
PR-URL: https://github.com/nodejs/node/pull/15343 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r--src/node_api.cc26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/node_api.cc b/src/node_api.cc
index 724d5c3ee9..cedf5ad7a4 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -933,12 +933,29 @@ napi_status napi_get_last_error_info(napi_env env,
}
NAPI_NO_RETURN void napi_fatal_error(const char* location,
- const char* message) {
- node::FatalError(location, message);
+ size_t location_len,
+ const char* message,
+ size_t message_len) {
+ char* location_string = const_cast<char*>(location);
+ char* message_string = const_cast<char*>(message);
+ if (location_len != -1) {
+ location_string = reinterpret_cast<char*>(
+ malloc(location_len * sizeof(char) + 1));
+ strncpy(location_string, location, location_len);
+ location_string[location_len] = '\0';
+ }
+ if (message_len != -1) {
+ message_string = reinterpret_cast<char*>(
+ malloc(message_len * sizeof(char) + 1));
+ strncpy(message_string, message, message_len);
+ message_string[message_len] = '\0';
+ }
+ node::FatalError(location_string, message_string);
}
napi_status napi_create_function(napi_env env,
const char* utf8name,
+ size_t length,
napi_callback cb,
void* callback_data,
napi_value* result) {
@@ -965,7 +982,7 @@ napi_status napi_create_function(napi_env env,
if (utf8name != nullptr) {
v8::Local<v8::String> name_string;
- CHECK_NEW_FROM_UTF8(env, name_string, utf8name);
+ CHECK_NEW_FROM_UTF8_LEN(env, name_string, utf8name, length);
return_value->SetName(name_string);
}
@@ -976,6 +993,7 @@ napi_status napi_create_function(napi_env env,
napi_status napi_define_class(napi_env env,
const char* utf8name,
+ size_t length,
napi_callback constructor,
void* callback_data,
size_t property_count,
@@ -997,7 +1015,7 @@ napi_status napi_define_class(napi_env env,
isolate, v8impl::FunctionCallbackWrapper::Invoke, cbdata);
v8::Local<v8::String> name_string;
- CHECK_NEW_FROM_UTF8(env, name_string, utf8name);
+ CHECK_NEW_FROM_UTF8_LEN(env, name_string, utf8name, length);
tpl->SetClassName(name_string);
size_t static_property_count = 0;