From 1f97b7af05b49ef69bd6e9d54906d1b7583f42c4 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Thu, 23 Mar 2017 03:10:42 +0100 Subject: [PATCH] New: Constructors/.create always initialize proper mutable objects/arrays, see #700 --- src/class.js | 5 +---- src/converter.js | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/class.js b/src/class.js index 51cbb31d0..5ef00b5b5 100644 --- a/src/class.js +++ b/src/class.js @@ -77,15 +77,12 @@ function Class(type, ctor) { Class.generate = function generate(type) { // eslint-disable-line no-unused-vars /* eslint-disable no-unexpected-multiline */ var gen = util.codegen("p"); - // see issue #700: the following would add explicitly initialized mutable object/array fields - // so that these aren't just inherited from the prototype. will break test cases. - /* + // explicitly initialize mutable object/array fields so that these aren't just inherited from the prototype for (var i = 0, field; i < type.fieldsArray.length; ++i) if ((field = type._fieldsArray[i]).map) gen ("this%s={}", util.safeProp(field.name)); else if (field.repeated) gen ("this%s=[]", util.safeProp(field.name)); - */ return gen ("if(p){") ("for(var ks=Object.keys(p),i=0;i