From 1f18453c7bfcce65c258fa98a3e3d4577d2e550f Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Fri, 30 Dec 2016 01:57:19 +0100 Subject: [PATCH] New: Emit an error on resolveAll() if any extension fields cannot be resolved, see #595 + test case --- src/root.js | 11 +++++++++++ tests/data/extend.proto | 16 ++++++++++++++++ tests/extend.js | 15 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/data/extend.proto create mode 100644 tests/extend.js diff --git a/src/root.js b/src/root.js index d11bc005d..38bc15833 100644 --- a/src/root.js +++ b/src/root.js @@ -232,6 +232,17 @@ RootPrototype.loadSync = function loadSync(filename, options) { return this.load(filename, options, SYNC); }; +/** + * @override + */ +RootPrototype.resolveAll = function resolveAll() { + if (this.deferred.length) + throw Error("unresolvable extensions: " + this.deferred.map(function(field) { + return "'extend " + field.extend + "' in " + field.parent.getFullName(); + }).join(", ")); + return Namespace.prototype.resolveAll.call(this); +}; + /** * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type. * @param {Field} field Declaring extension field witin the declaring type diff --git a/tests/data/extend.proto b/tests/data/extend.proto new file mode 100644 index 000000000..7bbb48fcb --- /dev/null +++ b/tests/data/extend.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +message A { + message B { + message One { + extensions 1000 to max; + } + } + message C { + message Two { + extend B.One { + Two two = 1000; + } + } + } +} diff --git a/tests/extend.js b/tests/extend.js new file mode 100644 index 000000000..04c798b2e --- /dev/null +++ b/tests/extend.js @@ -0,0 +1,15 @@ +var tape = require("tape"); + +var protobuf = require(".."); + +tape.test("extensions", function(test) { + + protobuf.load("tests/data/extend.proto", function(err, root) { + if (err) + return test.fail(err.message); + root.resolveAll(); + test.pass("should parse and resolve without errors"); + test.end(); + }); + +}); \ No newline at end of file