Skip to content

Commit 8d64c16

Browse files
committed
// BH 6/28/2018 7:34:58 AM
fix for Array.clone not copying array in the case of objects
1 parent 529d6d8 commit 8d64c16

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 6/28/2018 7:34:58 AM fix for Array.clone not copying array in the case of objects
1011
// BH 6/27/2018 3:11:50 PM fix for class String not indicating its name
1112
// BH 6/25/2018 3:06:30 PM adds String.concat$S
1213
// BH 6/25/2018 12:10:25 PM Character.toTitleCase, isTitleCase as ...UpperCase
@@ -85,7 +86,7 @@ Clazz._assertFunction = null;
8586

8687
//////// 16 methods called from code created by the transpiler ////////
8788

88-
Clazz.array = function(baseClass, paramType, ndims, params) {
89+
Clazz.array = function(baseClass, paramType, ndims, params, isClone) {
8990
// int[][].class Clazz.array(Integer.TYPE, -2)
9091
// new int[] {3, 4, 5} Clazz.array(Integer.TYPE, -1, [3, 4, 5])
9192
// new int[][]{new int[] {3, 4, 5}, {new int[] {3, 4, 5}}
@@ -194,7 +195,7 @@ Clazz.array = function(baseClass, paramType, ndims, params) {
194195
break;
195196
}
196197
}
197-
return newTypedA(baseClass, params, nbits, (dofill ? ndims : -ndims));
198+
return newTypedA(baseClass, params, nbits, (dofill ? ndims : -ndims), isClone);
198199
}
199200

200201
Clazz.assert = function(clazz, obj, tf, msg) {
@@ -222,7 +223,7 @@ Clazz.assert = function(clazz, obj, tf, msg) {
222223

223224
Clazz.clone = function(me) {
224225
// BH allows @j2sNative access without super constructor
225-
return appendMap(me.__ARRAYTYPE ? Clazz.array(me.__BASECLASS, me.__ARRAYTYPE, -1, me)
226+
return appendMap(me.__ARRAYTYPE ? Clazz.array(me.__BASECLASS, me.__ARRAYTYPE, -1, me, true)
226227
: new me.constructor(inheritArgs), me);
227228
}
228229

@@ -839,7 +840,7 @@ var getParamCode = Clazz._getParamCode = function(cl) {
839840
return cl.__PARAMCODE || (cl.__PARAMCODE = cl.__CLASS_NAME__.replace(/java\.lang\./, "").replace(/\./g, '_'));
840841
}
841842

842-
var newTypedA = function(baseClass, args, nBits, ndims) {
843+
var newTypedA = function(baseClass, args, nBits, ndims, isClone) {
843844
var dim = args[0];
844845
if (typeof dim == "string")
845846
dim = dim.charCodeAt(0); // int[] a = new int['\3'] ???
@@ -886,7 +887,7 @@ var newTypedA = function(baseClass, args, nBits, ndims) {
886887
var arr = new Float64Array(dim);
887888
break;
888889
default:
889-
var arr = (dim < 0 ? val : new Array(dim));
890+
var arr = (isClone ? new Array(dim = val.length) : dim < 0 ? val : new Array(dim));
890891
nBits = 0;
891892
if (dim > 0 && val != null)
892893
for (var i = dim; --i >= 0;)

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13084,6 +13084,7 @@ J2S._getResourcePath = function(path, isJavaPath) {
1308413084

1308513085
// Google closure compiler cannot handle Clazz.new or Clazz.super
1308613086

13087+
// BH 6/28/2018 7:34:58 AM fix for Array.clone not copying array in the case of objects
1308713088
// BH 6/27/2018 3:11:50 PM fix for class String not indicating its name
1308813089
// BH 6/25/2018 3:06:30 PM adds String.concat$S
1308913090
// BH 6/25/2018 12:10:25 PM Character.toTitleCase, isTitleCase as ...UpperCase
@@ -13162,7 +13163,7 @@ Clazz._assertFunction = null;
1316213163

1316313164
//////// 16 methods called from code created by the transpiler ////////
1316413165

13165-
Clazz.array = function(baseClass, paramType, ndims, params) {
13166+
Clazz.array = function(baseClass, paramType, ndims, params, isClone) {
1316613167
// int[][].class Clazz.array(Integer.TYPE, -2)
1316713168
// new int[] {3, 4, 5} Clazz.array(Integer.TYPE, -1, [3, 4, 5])
1316813169
// new int[][]{new int[] {3, 4, 5}, {new int[] {3, 4, 5}}
@@ -13271,7 +13272,7 @@ Clazz.array = function(baseClass, paramType, ndims, params) {
1327113272
break;
1327213273
}
1327313274
}
13274-
return newTypedA(baseClass, params, nbits, (dofill ? ndims : -ndims));
13275+
return newTypedA(baseClass, params, nbits, (dofill ? ndims : -ndims), isClone);
1327513276
}
1327613277

1327713278
Clazz.assert = function(clazz, obj, tf, msg) {
@@ -13299,7 +13300,7 @@ Clazz.assert = function(clazz, obj, tf, msg) {
1329913300

1330013301
Clazz.clone = function(me) {
1330113302
// BH allows @j2sNative access without super constructor
13302-
return appendMap(me.__ARRAYTYPE ? Clazz.array(me.__BASECLASS, me.__ARRAYTYPE, -1, me)
13303+
return appendMap(me.__ARRAYTYPE ? Clazz.array(me.__BASECLASS, me.__ARRAYTYPE, -1, me, true)
1330313304
: new me.constructor(inheritArgs), me);
1330413305
}
1330513306

@@ -13916,7 +13917,7 @@ var getParamCode = Clazz._getParamCode = function(cl) {
1391613917
return cl.__PARAMCODE || (cl.__PARAMCODE = cl.__CLASS_NAME__.replace(/java\.lang\./, "").replace(/\./g, '_'));
1391713918
}
1391813919

13919-
var newTypedA = function(baseClass, args, nBits, ndims) {
13920+
var newTypedA = function(baseClass, args, nBits, ndims, isClone) {
1392013921
var dim = args[0];
1392113922
if (typeof dim == "string")
1392213923
dim = dim.charCodeAt(0); // int[] a = new int['\3'] ???
@@ -13963,7 +13964,7 @@ var newTypedA = function(baseClass, args, nBits, ndims) {
1396313964
var arr = new Float64Array(dim);
1396413965
break;
1396513966
default:
13966-
var arr = (dim < 0 ? val : new Array(dim));
13967+
var arr = (isClone ? new Array(dim = val.length) : dim < 0 ? val : new Array(dim));
1396713968
nBits = 0;
1396813969
if (dim > 0 && val != null)
1396913970
for (var i = dim; --i >= 0;)

0 commit comments

Comments
 (0)