Internal code sync

This commit is contained in:
Stanley Cheung 2020-11-20 20:41:01 -08:00 committed by Stanley Cheung
parent eecc629b00
commit 2e3e8d2c50
2 changed files with 17 additions and 3 deletions

View File

@ -1027,8 +1027,11 @@ void PrintMethodDescriptorFile(Printer* printer,
printer->Print( printer->Print(
vars, vars,
"/**\n" "/**\n"
" * @fileoverview gRPC-Web generated MethodDescriptors for $package$\n" " * @fileoverview gRPC-Web generated MethodDescriptors for $package$\n");
" * @enhanceable\n" if (vars["plugins"].empty()) {
printer->Print(" * @enhanceable\n");
}
printer->Print(
" * @public\n" " * @public\n"
" */\n\n" " */\n\n"
"// GENERATED CODE -- DO NOT EDIT!\n\n\n" "// GENERATED CODE -- DO NOT EDIT!\n\n\n"
@ -1038,6 +1041,11 @@ void PrintMethodDescriptorFile(Printer* printer,
printer->Print(vars, printer->Print(vars,
"goog.provide('proto.$package_dot$$class_name$.$" "goog.provide('proto.$package_dot$$class_name$.$"
"method_name$MethodDescriptor');\n\n"); "method_name$MethodDescriptor');\n\n");
if (!vars["plugins"].empty()) {
printer->Print(vars,
"goog.require('$plugins$.$package_dot$$class_name$.$"
"method_name$MethodDescriptor');\n");
}
printer->Print(vars, "goog.require('grpc.web.MethodDescriptor');\n"); printer->Print(vars, "goog.require('grpc.web.MethodDescriptor');\n");
printer->Print(vars, "goog.require('grpc.web.MethodType');\n"); printer->Print(vars, "goog.require('grpc.web.MethodType');\n");
printer->Print(vars, "goog.require('$in_type$');\n"); printer->Print(vars, "goog.require('$in_type$');\n");
@ -1507,6 +1515,7 @@ class GeneratorOptions {
string OutputFile(const string& proto_file) const; string OutputFile(const string& proto_file) const;
string mode() const { return mode_; } string mode() const { return mode_; }
string plugins() const { return plugins_; }
ImportStyle import_style() const { return import_style_; } ImportStyle import_style() const { return import_style_; }
bool generate_dts() const { return generate_dts_; } bool generate_dts() const { return generate_dts_; }
bool generate_closure_es6() const { return generate_closure_es6_; } bool generate_closure_es6() const { return generate_closure_es6_; }
@ -1516,6 +1525,7 @@ class GeneratorOptions {
private: private:
string file_name_; string file_name_;
string mode_; string mode_;
string plugins_;
ImportStyle import_style_; ImportStyle import_style_;
bool generate_dts_; bool generate_dts_;
bool generate_closure_es6_; bool generate_closure_es6_;
@ -1526,6 +1536,7 @@ class GeneratorOptions {
GeneratorOptions::GeneratorOptions() GeneratorOptions::GeneratorOptions()
: file_name_(""), : file_name_(""),
mode_(""), mode_(""),
plugins_(""),
import_style_(ImportStyle::CLOSURE), import_style_(ImportStyle::CLOSURE),
generate_dts_(false), generate_dts_(false),
generate_closure_es6_(false), generate_closure_es6_(false),
@ -1566,6 +1577,8 @@ bool GeneratorOptions::ParseFromOptions(
} }
} else if ("multiple_files" == option.first) { } else if ("multiple_files" == option.first) {
multiple_files_ = "True" == option.second; multiple_files_ = "True" == option.second;
} else if ("plugins" == option.first) {
plugins_ = option.second;
} else if ("goog_promise" == option.first) { } else if ("goog_promise" == option.first) {
goog_promise_ = "True" == option.second; goog_promise_ = "True" == option.second;
} else { } else {
@ -1620,6 +1633,7 @@ class GrpcCodeGenerator : public CodeGenerator {
vars["package"] = package; vars["package"] = package;
vars["package_dot"] = package.empty() ? "" : package + '.'; vars["package_dot"] = package.empty() ? "" : package + '.';
vars["promise"] = "Promise"; vars["promise"] = "Promise";
vars["plugins"] = generator_options.plugins();
if ("binary" == generator_options.mode()) { if ("binary" == generator_options.mode()) {
vars["mode"] = GetModeVar(Mode::OP); vars["mode"] = GetModeVar(Mode::OP);

View File

@ -139,8 +139,8 @@ class StreamBodyClientReadableStream {
const responseMessage = this.grpcResponseDeserializeFn_(response); const responseMessage = this.grpcResponseDeserializeFn_(response);
const grpcStatus = StatusCode.fromHttpStatus(this.xhr_.getStatus()); const grpcStatus = StatusCode.fromHttpStatus(this.xhr_.getStatus());
if (grpcStatus == StatusCode.OK) { if (grpcStatus == StatusCode.OK) {
this.sendDataCallbacks_(responseMessage);
this.sendMetadataCallbacks_(this.readHeaders_()); this.sendMetadataCallbacks_(this.readHeaders_());
this.sendDataCallbacks_(responseMessage);
} else { } else {
this.sendErrorCallbacks_( this.sendErrorCallbacks_(
/** @type {!GrpcWebError} */ ({ /** @type {!GrpcWebError} */ ({