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 b9c057c

Browse filesBrowse files
addaleaxtargos
authored andcommitted
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: #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>
1 parent ea5be29 commit b9c057c
Copy full SHA for b9c057c

File tree

Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Open diff view settings
Collapse file

‎src/node_object_wrap.h‎

Copy file name to clipboardExpand all lines: src/node_object_wrap.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ObjectWrap {
6565
}
6666

6767

68+
// NOLINTNEXTLINE(runtime/v8_persistent)
6869
inline v8::Persistent<v8::Object>& persistent() {
6970
return handle_;
7071
}
@@ -122,6 +123,7 @@ class ObjectWrap {
122123
delete wrap;
123124
}
124125

126+
// NOLINTNEXTLINE(runtime/v8_persistent)
125127
v8::Persistent<v8::Object> handle_;
126128
};
127129

Collapse file

‎tools/cpplint.py‎

Copy file name to clipboardExpand all lines: tools/cpplint.py
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
'runtime/string',
322322
'runtime/threadsafe_fn',
323323
'runtime/vlog',
324+
'runtime/v8_persistent',
324325
'whitespace/blank_line',
325326
'whitespace/braces',
326327
'whitespace/comma',
@@ -627,6 +628,8 @@
627628

628629
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
629630

631+
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
632+
630633
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
631634
r'(?<!(sizeof|return))'
632635
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
@@ -4547,6 +4550,28 @@ def CheckNullTokens(filename, clean_lines, linenum, error):
45474550
error(filename, linenum, 'readability/null_usage', 2,
45484551
'Use nullptr instead of NULL')
45494552

4553+
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4554+
"""Check v8::Persistent usage.
4555+
4556+
Args:
4557+
filename: The name of the current file.
4558+
clean_lines: A CleansedLines instance containing the file.
4559+
linenum: The number of the line to check.
4560+
error: The function to call with any errors found.
4561+
"""
4562+
line = clean_lines.elided[linenum]
4563+
4564+
# Avoid preprocessor lines
4565+
if Match(r'^\s*#', line):
4566+
return
4567+
4568+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4569+
return
4570+
4571+
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4572+
error(filename, linenum, 'runtime/v8_persistent', 2,
4573+
'Use v8::Global instead of v8::Persistent')
4574+
45504575
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
45514576
"""Check for left-leaning pointer placement.
45524577
@@ -4723,6 +4748,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
47234748
CheckCheck(filename, clean_lines, linenum, error)
47244749
CheckAltTokens(filename, clean_lines, linenum, error)
47254750
CheckNullTokens(filename, clean_lines, linenum, error)
4751+
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
47264752
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
47274753
classinfo = nesting_state.InnermostClass()
47284754
if classinfo:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.