From e23bf8f771aa0bd60e25ff079985fc29b5846403 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 18 Dec 2019 15:28:24 +0100 Subject: [PATCH] tools,src: forbid usage of v8::Persistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `v8::Persistent` comes with the surprising catch that it requires manual cleanup. `v8::Global` doesn’t, making it easier to use, and additionally provides move semantics. New code should always use `v8::Global`. PR-URL: https://github.com/nodejs/node/pull/31018 Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: David Carlier Reviewed-By: Rich Trott Reviewed-By: Gus Caplan Reviewed-By: Joyee Cheung Reviewed-By: Ben Noordhuis Reviewed-By: Stephen Belanger --- src/node_object_wrap.h | 2 ++ tools/cpplint.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/node_object_wrap.h b/src/node_object_wrap.h index 9dce684892a2d8..cb13d84388bcc6 100644 --- a/src/node_object_wrap.h +++ b/src/node_object_wrap.h @@ -65,6 +65,7 @@ class ObjectWrap { } + // NOLINTNEXTLINE(runtime/v8_persistent) inline v8::Persistent& persistent() { return handle_; } @@ -122,6 +123,7 @@ class ObjectWrap { delete wrap; } + // NOLINTNEXTLINE(runtime/v8_persistent) v8::Persistent handle_; }; diff --git a/tools/cpplint.py b/tools/cpplint.py index 40564789549aba..4ea91c0dc04a54 100755 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -321,6 +321,7 @@ 'runtime/string', 'runtime/threadsafe_fn', 'runtime/vlog', + 'runtime/v8_persistent', 'whitespace/blank_line', 'whitespace/braces', 'whitespace/comma', @@ -627,6 +628,8 @@ _NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b') +_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b') + _RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]' r'(?= 0 or line.find('*/') >= 0: + return + + for match in _V8_PERSISTENT_PATTERN.finditer(line): + error(filename, linenum, 'runtime/v8_persistent', 2, + 'Use v8::Global instead of v8::Persistent') + def CheckLeftLeaningPointer(filename, clean_lines, linenum, error): """Check for left-leaning pointer placement. @@ -4723,6 +4748,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, CheckCheck(filename, clean_lines, linenum, error) CheckAltTokens(filename, clean_lines, linenum, error) CheckNullTokens(filename, clean_lines, linenum, error) + CheckV8PersistentTokens(filename, clean_lines, linenum, error) CheckLeftLeaningPointer(filename, clean_lines, linenum, error) classinfo = nesting_state.InnermostClass() if classinfo: