From ded617f0c8eca7c7319f00a54cebe0d35fb0b99b Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 14 May 2013 11:16:37 -0700 Subject: [PATCH] Fix Opera test failures by reverting unnecessary part of 583508e. Opera seems to have some consistent but difficult to diagnose bugs related to using _.map in this context. (As in, minifying the test was difficult because there seemed to be some odd action at a distance, but a given test failure was fully reproducible.) This appears to work while still preserving the feature added in 583508e. Also fix a missing var (which does not appear to be the original problem). --- packages/ejson/ejson.js | 8 +++++--- packages/ejson/ejson_test.js | 21 --------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/packages/ejson/ejson.js b/packages/ejson/ejson.js index 02c7a8f603..68e5218e82 100644 --- a/packages/ejson/ejson.js +++ b/packages/ejson/ejson.js @@ -296,14 +296,16 @@ EJSON.clone = function (v) { return new Date(v.getTime()); if (EJSON.isBinary(v)) { ret = EJSON.newBinary(v.length); - for (i = 0; i < v.length; i++) { + for (var i = 0; i < v.length; i++) { ret[i] = v[i]; } return ret; } - // Clone arrays (and turn 'arguments' into an array). if (_.isArray(v) || _.isArguments(v)) { - return _.map(v, EJSON.clone); + ret = v.slice(0); + for (i = 0; i < v.length; i++) + ret[i] = EJSON.clone(ret[i]); + return ret; } // handle general user-defined typed Objects if they have a clone method if (typeof v.clone === 'function') { diff --git a/packages/ejson/ejson_test.js b/packages/ejson/ejson_test.js index bd3e5d6310..4f1e6b6ac6 100644 --- a/packages/ejson/ejson_test.js +++ b/packages/ejson/ejson_test.js @@ -51,24 +51,3 @@ Tinytest.add("ejson - equality and falsiness", function (test) { test.isFalse(EJSON.equals(undefined, {foo: "foo"})); test.isFalse(EJSON.equals({foo: "foo"}, undefined)); }); - -Tinytest.add("ejson - clone", function (test) { - var cloneTest = function (x, identical) { - var y = EJSON.clone(x); - test.isTrue(EJSON.equals(x, y)); - test.equal(x === y, !!identical); - }; - cloneTest(null, true); - cloneTest(undefined, true); - cloneTest(42, true); - cloneTest("asdf", true); - cloneTest([1, 2, 3]); - cloneTest([1, "fasdf", {foo: 42}]); - cloneTest({x: 42, y: "asdf"}); - - var testCloneArgs = function (/*arguments*/) { - var clonedArgs = EJSON.clone(arguments); - test.equal(clonedArgs, [1, 2, "foo", [4]]); - }; - testCloneArgs(1, 2, "foo", [4]); -});