From 508984b7ff9529906be282375d36fdbada66b8e6 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Thu, 12 Jan 2017 21:23:34 +0100 Subject: [PATCH] CLI: Replace all occurencies of types[%d].values in static code, see #641; Fixed: Use Type.toObject/Message.toObject within converters, see #641 --- cli/targets/static.js | 4 ++-- src/converter.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/targets/static.js b/cli/targets/static.js index 869979ba1..3f95dde62 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -174,8 +174,8 @@ function beautify(code) { function buildFunction(type, functionName, gen, scope) { var code = gen.str(functionName) - .replace("(this.ctor)", " $root" + type.fullName) // types: construct directly instead of using reflected ctor - .replace(/(types\[\d+])(\.values)/,"$1"); // enums: use types[N] instead of reflected types[N].values + .replace(/\(this.ctor\)/g, " $root" + type.fullName) // types: construct directly instead of using reflected ctor + .replace(/(types\[\d+])(\.values)/g,"$1"); // enums: use types[N] instead of reflected types[N].values if (config.beautify) code = beautify(code); diff --git a/src/converter.js b/src/converter.js index 6c62dde98..b23c27ead 100644 --- a/src/converter.js +++ b/src/converter.js @@ -148,7 +148,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) { if (field.resolvedType instanceof Enum) gen ("d%s=o.enums===String?types[%d].values[m%s]:m%s", prop, fieldIndex, prop, prop); else gen - ("d%s=types[%d].ctor.prototype.toObject.call(m%s,o)", prop, fieldIndex, prop); + ("d%s=types[%d].toObject(m%s,o)", prop, fieldIndex, prop); } else { var isUnsigned = false; switch (field.type) {