mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
tools,src: forbid usage of v8::Persistent
`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 <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
parent
62436c2fb3
commit
e23bf8f771
2 changed files with 28 additions and 0 deletions
26
tools/cpplint.py
vendored
26
tools/cpplint.py
vendored
|
@ -321,6 +321,7 @@ _ERROR_CATEGORIES = [
|
|||
'runtime/string',
|
||||
'runtime/threadsafe_fn',
|
||||
'runtime/vlog',
|
||||
'runtime/v8_persistent',
|
||||
'whitespace/blank_line',
|
||||
'whitespace/braces',
|
||||
'whitespace/comma',
|
||||
|
@ -627,6 +628,8 @@ _SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
|
|||
|
||||
_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'(?<!(sizeof|return))'
|
||||
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
|
||||
|
@ -4547,6 +4550,28 @@ def CheckNullTokens(filename, clean_lines, linenum, error):
|
|||
error(filename, linenum, 'readability/null_usage', 2,
|
||||
'Use nullptr instead of NULL')
|
||||
|
||||
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
|
||||
"""Check v8::Persistent usage.
|
||||
|
||||
Args:
|
||||
filename: The name of the current file.
|
||||
clean_lines: A CleansedLines instance containing the file.
|
||||
linenum: The number of the line to check.
|
||||
error: The function to call with any errors found.
|
||||
"""
|
||||
line = clean_lines.elided[linenum]
|
||||
|
||||
# Avoid preprocessor lines
|
||||
if Match(r'^\s*#', line):
|
||||
return
|
||||
|
||||
if line.find('/*') >= 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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue