Skip to content

Commit

Permalink
Add GenerateClassFromObject to Javascript gen
Browse files Browse the repository at this point in the history
Adds the fromObject helper to the public API of generated pb classes.

This closes a 5-year-old open issue: https://github.com/protocolbuffers/protobuf/issues/1591 
by rebasing this 1-year-old open PR: protocolbuffers/protobuf#8488
based on this 4-year-old workaround: https://github.com/protocolbuffers/protobuf/issues/1591#issuecomment-414778829
  • Loading branch information
psigen committed May 4, 2022
1 parent 3561b05 commit fa1b0a8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions generator/js_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,8 @@ void Generator::GenerateClass(const GeneratorOptions& options,
GenerateClassFieldInfo(options, printer, desc);

GenerateClassToObject(options, printer, desc);
GenerateClassFromObject(options, printer, desc);
printer->Print("\ngoog.isDef = goog.isDef || function(a) { if (a === undefined || a === null) { return false; }; return true; }; goog.array = { map: function(arr, func) { return arr.map(func); }; }\n");
// These must come *before* the extension-field info generation in
// GenerateClassRegistration so that references to the binary
// serialization/deserialization functions may be placed in the extension
Expand Down

0 comments on commit fa1b0a8

Please sign in to comment.