From 6817618b4ea66d029b04b35ead4d32ee5d9e77f3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sun, 5 Nov 2017 12:29:02 +0300 Subject: [PATCH] Make primivive[].clone() work in older browsers and in Rhino --- .../resources/org/teavm/backend/javascript/runtime.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index 98e1a2525..d480b68c9 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -140,6 +140,15 @@ function $rt_arraycls(cls) { return str; }; $rt_setCloneMethod(arraycls.prototype, function () { + var dataCopy; + if ('slice' in this.data) { + dataCopy = this.data.slice(); + } else { + dataCopy = new this.data.constructor(this.data.length); + for (var i = 0; i < dataCopy.length; ++i) { + dataCopy[i] = this.data[i]; + } + } return new arraycls(this.data.slice()); }); var name = "[" + cls.$meta.binaryName;