mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Support EJSON.clone(arguments).
This enables (eg) Meteor.apply('foo', arguments). Fixes #946.
This commit is contained in:
@@ -301,11 +301,9 @@ EJSON.clone = function (v) {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (_.isArray(v)) {
|
// Clone arrays (and turn 'arguments' into an array).
|
||||||
ret = v.slice(0);
|
if (_.isArray(v) || _.isArguments(v)) {
|
||||||
for (var i = 0; i < v.length; i++)
|
return _.map(v, EJSON.clone);
|
||||||
ret[i] = EJSON.clone(ret[i]);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
// handle general user-defined typed Objects if they have a clone method
|
// handle general user-defined typed Objects if they have a clone method
|
||||||
if (typeof v.clone === 'function') {
|
if (typeof v.clone === 'function') {
|
||||||
|
|||||||
@@ -51,3 +51,24 @@ Tinytest.add("ejson - equality and falsiness", function (test) {
|
|||||||
test.isFalse(EJSON.equals(undefined, {foo: "foo"}));
|
test.isFalse(EJSON.equals(undefined, {foo: "foo"}));
|
||||||
test.isFalse(EJSON.equals({foo: "foo"}, undefined));
|
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]);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user