Skip to content

Commit 0c32428

Browse files
addaleaxtargos
authored andcommitted
src: make FIXED_ONE_BYTE_STRING an inline fn
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]>
1 parent d5e9801 commit 0c32428

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/node_api.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -2173,11 +2173,11 @@ static napi_status set_error_code(napi_env env,
21732173
}
21742174
}
21752175
name_string = v8::String::Concat(
2176-
isolate, name_string, FIXED_ONE_BYTE_STRING(isolate, " ["));
2176+
isolate, name_string, node::FIXED_ONE_BYTE_STRING(isolate, " ["));
21772177
name_string =
21782178
v8::String::Concat(isolate, name_string, code_value.As<v8::String>());
21792179
name_string = v8::String::Concat(
2180-
isolate, name_string, FIXED_ONE_BYTE_STRING(isolate, "]"));
2180+
isolate, name_string, node::FIXED_ONE_BYTE_STRING(isolate, "]"));
21812181

21822182
set_maybe = err_object->Set(context, name_key, name_string);
21832183
RETURN_STATUS_IF_FALSE(env,

src/util.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ NO_RETURN void Abort();
8989
NO_RETURN void Assert(const char* const (*args)[4]);
9090
void DumpBacktrace(FILE* fp);
9191

92-
#define FIXED_ONE_BYTE_STRING(isolate, string) \
93-
(node::OneByteString((isolate), (string), sizeof(string) - 1))
94-
9592
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
9693
void operator=(const TypeName&) = delete; \
9794
void operator=(TypeName&&) = delete; \
@@ -248,6 +245,15 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
248245
const unsigned char* data,
249246
int length = -1);
250247

248+
// Used to be a macro, hence the uppercase name.
249+
template <int N>
250+
inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(
251+
v8::Isolate* isolate,
252+
const char(&data)[N]) {
253+
return OneByteString(isolate, data, N - 1);
254+
}
255+
256+
251257
// Swaps bytes in place. nbytes is the number of bytes to swap and must be a
252258
// multiple of the word size (checked by function).
253259
inline void SwapBytes16(char* data, size_t nbytes);

0 commit comments

Comments
 (0)