Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
db1b2a06
Commit
db1b2a06
authored
Jul 16, 2016
by
Nikolai Vavilov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nits
parent
970a4fda
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
32 deletions
+21
-32
js_generator.cc
src/google/protobuf/compiler/js/js_generator.cc
+21
-32
No files found.
src/google/protobuf/compiler/js/js_generator.cc
View file @
db1b2a06
...
...
@@ -1257,11 +1257,14 @@ string GetPivot(const Descriptor* desc) {
// Returns true for fields that represent "null" as distinct from the default
// value. See http://go/proto3#heading=h.kozewqqcqhuz for more information.
bool
HasFieldPresence
(
const
FieldDescriptor
*
field
)
{
if
(
field
->
is_repeated
())
{
return
false
;
}
return
!
field
->
is_repeated
()
&&
((
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
)
||
(
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
)
||
(
field
->
containing_oneof
()
!=
NULL
)
||
(
field
->
file
()
->
syntax
()
!=
FileDescriptor
::
SYNTAX_PROTO3
)
)
;
(
field
->
file
()
->
syntax
()
!=
FileDescriptor
::
SYNTAX_PROTO3
);
}
// For proto3 fields without presence, returns a string representing the default
...
...
@@ -2322,20 +2325,6 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"clearedvalue"
,
(
field
->
is_repeated
()
?
"[]"
:
"undefined"
),
"returnvalue"
,
JSReturnClause
(
field
));
printer
->
Print
(
"/**
\n
"
" * Returns whether this field is set.
\n
"
" * @return{!boolean}
\n
"
" */
\n
"
"$class$.prototype.has$name$ = function() {
\n
"
" return jspb.Message.getField(this, $index$) != null;
\n
"
"};
\n
"
"
\n
"
"
\n
"
,
"class"
,
GetPath
(
options
,
field
->
containing_type
()),
"name"
,
JSGetterName
(
options
,
field
),
"index"
,
JSFieldIndex
(
field
));
}
else
{
bool
untyped
=
false
;
...
...
@@ -2497,22 +2486,22 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"clearedvalue"
,
(
field
->
is_repeated
()
?
"[]"
:
"undefined"
),
"returnvalue"
,
JSReturnClause
(
field
));
}
}
if
(
HasFieldPresence
(
field
))
{
printer
->
Print
(
"/**
\n
"
" * Returns whether this field is set.
\n
"
" * @return{!boolean}
\n
"
" */
\n
"
"$class$.prototype.has$name$ = function() {
\n
"
" return jspb.Message.getField(this, $index$) != null;
\n
"
"};
\n
"
"
\n
"
"
\n
"
,
"class"
,
GetPath
(
options
,
field
->
containing_type
()),
"name"
,
JSGetterName
(
options
,
field
),
"index"
,
JSFieldIndex
(
field
));
}
if
(
HasFieldPresence
(
field
))
{
printer
->
Print
(
"/**
\n
"
" * Returns whether this field is set.
\n
"
" * @return{!boolean}
\n
"
" */
\n
"
"$class$.prototype.has$name$ = function() {
\n
"
" return jspb.Message.getField(this, $index$) != null;
\n
"
"};
\n
"
"
\n
"
"
\n
"
,
"class"
,
GetPath
(
options
,
field
->
containing_type
()),
"name"
,
JSGetterName
(
options
,
field
),
"index"
,
JSFieldIndex
(
field
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment