Skip to content

Commit

Permalink
src: make FIXED_ONE_BYTE_STRING an inline fn
Browse files Browse the repository at this point in the history
This prevents accidental usage on non-fixed strings.

PR-URL: #22725
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and targos committed Sep 10, 2018
1 parent d5e9801 commit 0c32428
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2173,11 +2173,11 @@ static napi_status set_error_code(napi_env env,
}
}
name_string = v8::String::Concat(
isolate, name_string, FIXED_ONE_BYTE_STRING(isolate, " ["));
isolate, name_string, node::FIXED_ONE_BYTE_STRING(isolate, " ["));
name_string =
v8::String::Concat(isolate, name_string, code_value.As<v8::String>());
name_string = v8::String::Concat(
isolate, name_string, FIXED_ONE_BYTE_STRING(isolate, "]"));
isolate, name_string, node::FIXED_ONE_BYTE_STRING(isolate, "]"));

set_maybe = err_object->Set(context, name_key, name_string);
RETURN_STATUS_IF_FALSE(env,
Expand Down
12 changes: 9 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ NO_RETURN void Abort();
NO_RETURN void Assert(const char* const (*args)[4]);
void DumpBacktrace(FILE* fp);

#define FIXED_ONE_BYTE_STRING(isolate, string) \
(node::OneByteString((isolate), (string), sizeof(string) - 1))

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
void operator=(const TypeName&) = delete; \
void operator=(TypeName&&) = delete; \
Expand Down Expand Up @@ -248,6 +245,15 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const unsigned char* data,
int length = -1);

// Used to be a macro, hence the uppercase name.
template <int N>
inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(
v8::Isolate* isolate,
const char(&data)[N]) {
return OneByteString(isolate, data, N - 1);
}


// Swaps bytes in place. nbytes is the number of bytes to swap and must be a
// multiple of the word size (checked by function).
inline void SwapBytes16(char* data, size_t nbytes);
Expand Down

0 comments on commit 0c32428

Please sign in to comment.