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).
This commit is contained in:
David Glasser
2013-05-14 11:16:37 -07:00
parent d36de8253d
commit ded617f0c8
2 changed files with 5 additions and 24 deletions

View File

@@ -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') {

View File

@@ -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]);
});