Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c32428

Browse filesBrowse 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 <daniel.bevenius@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d5e9801 commit 0c32428
Copy full SHA for 0c32428

File tree

Expand file treeCollapse file tree

2 files changed

+11
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-5
lines changed
Open diff view settings
Collapse file

‎src/node_api.cc‎

Copy file name to clipboardExpand all lines: src/node_api.cc
+2-2Lines changed: 2 additions & 2 deletions
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,
Collapse file

‎src/util.h‎

Copy file name to clipboardExpand all lines: src/util.h
+9-3Lines changed: 9 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.