From b04ba6df2372160fe5b9a14e0a1a9a166577ed61 Mon Sep 17 00:00:00 2001 From: rickyes Date: Fri, 10 Apr 2020 17:18:40 +0800 Subject: [PATCH 1/2] lib: replace charCodeAt with fixed Unicode --- lib/internal/console/constructor.js | 12 ++++++++---- lib/internal/trace_events_async_hooks.js | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index dc8dcaa1d054ed..b5825163c04985 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -44,10 +44,14 @@ const { const kCounts = Symbol('counts'); const kTraceConsoleCategory = 'node,node.console'; -const kTraceCount = 'C'.charCodeAt(0); -const kTraceBegin = 'b'.charCodeAt(0); -const kTraceEnd = 'e'.charCodeAt(0); -const kTraceInstant = 'n'.charCodeAt(0); +// `C` Unicode +const kTraceCount = 67; +// `b` Unicode +const kTraceBegin = 98; +// `e` Unicode +const kTraceEnd = 101; +// `n` Unicode +const kTraceInstant = 110; const kSecond = 1000; const kMinute = 60 * kSecond; diff --git a/lib/internal/trace_events_async_hooks.js b/lib/internal/trace_events_async_hooks.js index 84c7745e47368f..411b9caab9568e 100644 --- a/lib/internal/trace_events_async_hooks.js +++ b/lib/internal/trace_events_async_hooks.js @@ -14,8 +14,11 @@ const async_hooks = require('async_hooks'); // Use small letters such that chrome://tracing groups by the name. // The behavior is not only useful but the same as the events emitted using // the specific C++ macros. -const kBeforeEvent = 'b'.charCodeAt(0); -const kEndEvent = 'e'.charCodeAt(0); + +// `b` Unicode +const kBeforeEvent = 98; +// `e` Unicode +const kEndEvent = 101; const kTraceEventCategory = 'node,node.async_hooks'; const kEnabled = Symbol('enabled'); From dd9e5108e45ea7ce3ce80ebdb7acd7c6d274cefd Mon Sep 17 00:00:00 2001 From: rickyes Date: Fri, 10 Apr 2020 18:33:28 +0800 Subject: [PATCH 2/2] lib: replace charCodeAt with fixed Unicode --- lib/internal/console/constructor.js | 18 ++++++++++-------- lib/internal/constants.js | 4 ++++ lib/internal/trace_events_async_hooks.js | 11 ++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index b5825163c04985..c2ce919854de27 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -41,17 +41,19 @@ const { const { isTypedArray, isSet, isMap, isSetIterator, isMapIterator, } = require('internal/util/types'); +const { + CHAR_LOWERCASE_B, + CHAR_LOWERCASE_E, + CHAR_LOWERCASE_N, + CHAR_UPPERCASE_C, +} = require('internal/constants'); const kCounts = Symbol('counts'); const kTraceConsoleCategory = 'node,node.console'; -// `C` Unicode -const kTraceCount = 67; -// `b` Unicode -const kTraceBegin = 98; -// `e` Unicode -const kTraceEnd = 101; -// `n` Unicode -const kTraceInstant = 110; +const kTraceCount = CHAR_UPPERCASE_C; +const kTraceBegin = CHAR_LOWERCASE_B; +const kTraceEnd = CHAR_LOWERCASE_E; +const kTraceInstant = CHAR_LOWERCASE_N; const kSecond = 1000; const kMinute = 60 * kSecond; diff --git a/lib/internal/constants.js b/lib/internal/constants.js index dfa30bea306e65..bf539a9f37d134 100644 --- a/lib/internal/constants.js +++ b/lib/internal/constants.js @@ -8,6 +8,10 @@ module.exports = { CHAR_LOWERCASE_A: 97, /* a */ CHAR_UPPERCASE_Z: 90, /* Z */ CHAR_LOWERCASE_Z: 122, /* z */ + CHAR_UPPERCASE_C: 67, /* C */ + CHAR_LOWERCASE_B: 98, /* b */ + CHAR_LOWERCASE_E: 101, /* e */ + CHAR_LOWERCASE_N: 110, /* n */ // Non-alphabetic chars. CHAR_DOT: 46, /* . */ diff --git a/lib/internal/trace_events_async_hooks.js b/lib/internal/trace_events_async_hooks.js index 411b9caab9568e..9796f6866d96c8 100644 --- a/lib/internal/trace_events_async_hooks.js +++ b/lib/internal/trace_events_async_hooks.js @@ -10,15 +10,16 @@ const { const { trace } = internalBinding('trace_events'); const async_wrap = internalBinding('async_wrap'); const async_hooks = require('async_hooks'); +const { + CHAR_LOWERCASE_B, + CHAR_LOWERCASE_E, +} = require('internal/constants'); // Use small letters such that chrome://tracing groups by the name. // The behavior is not only useful but the same as the events emitted using // the specific C++ macros. - -// `b` Unicode -const kBeforeEvent = 98; -// `e` Unicode -const kEndEvent = 101; +const kBeforeEvent = CHAR_LOWERCASE_B; +const kEndEvent = CHAR_LOWERCASE_E; const kTraceEventCategory = 'node,node.async_hooks'; const kEnabled = Symbol('enabled');