node-v8-clone
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "node-v8-clone", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "UNSTABLE yet. Exposed v8 clone function for node.js.", | ||
@@ -5,0 +5,0 @@ "main": "build/Release/clone", |
@@ -25,6 +25,15 @@ var assert = require("assert") | ||
assert.equal(b, 1); | ||
a = 2; | ||
a += 1; | ||
assert.equal(a, 2); | ||
assert.equal(b, 1); | ||
}); | ||
it('should clone strings', function(){ | ||
var a = 'aaa'; | ||
var b = clone(a); | ||
assert.equal(a, 'aaa'); | ||
assert.equal(b, 'aaa'); | ||
a += 'bbb'; | ||
assert.equal(a, 'aaabbb'); | ||
assert.equal(b, 'aaa'); | ||
}); | ||
it('should clone number objects', function(){ | ||
@@ -60,2 +69,67 @@ var a = new Number(1); | ||
}); | ||
it('should clone instances', function(){ | ||
function clazz (c) { this.c = c; this.d = 2 }; | ||
clazz.prototype.getC = function() { return this.c; }; | ||
var a = new clazz(1); | ||
var b = clone(a); | ||
assert.equal(a.c, 1); | ||
assert.equal(a.getC(), 1); | ||
assert.equal(a.d, 2); | ||
assert.equal(b.c, 1); | ||
assert.equal(b.getC(), 1); | ||
assert.equal(b.d, 2); | ||
a.c = 3; | ||
assert.equal(a.c, 3); | ||
assert.equal(a.getC(), 3); | ||
assert.equal(a.d, 2); | ||
assert.equal(b.c, 1); | ||
assert.equal(b.getC(), 1); | ||
assert.equal(b.d, 2); | ||
}); | ||
it('should clone Date instances', function(){ | ||
var a = new Date(1980,2,3,4,5,6); | ||
var b = clone(a); | ||
assert.equal(a.getFullYear(), 1980); | ||
assert.equal(b.getFullYear(), 1980); | ||
a.setFullYear(1981); | ||
assert.equal(a.getFullYear(), 1981); | ||
assert.equal(b.getFullYear(), 1980); | ||
}); | ||
it('should clone RegExp instances', function(){ | ||
var a = new RegExp('a+', 'g'); | ||
var b = clone(a); | ||
assert.ok(a instanceof RegExp); | ||
assert.ok(b instanceof RegExp); | ||
assert.equal(a.lastIndex, 0); | ||
assert.equal(b.lastIndex, 0); | ||
a.exec('bba'); | ||
assert.equal(a.lastIndex, 3); | ||
assert.equal(b.lastIndex, 0); | ||
}); | ||
it('should clone Arguments', function(){ | ||
function getargs() { return arguments; }; | ||
var a = getargs(1, 2, 3); | ||
var b = clone(a); | ||
assert.deepEqual(a, getargs(1, 2, 3)); | ||
assert.deepEqual(b, getargs(1, 2, 3)); | ||
a[0] = 4; | ||
assert.deepEqual(a, getargs(4, 2, 3)); | ||
assert.deepEqual(b, getargs(1, 2, 3)); | ||
}); | ||
it('should clone Functions', function(){ | ||
var a = function(a, b, c) {}; | ||
var b = clone(a); | ||
assert.equal(a.toString(), b.toString()); | ||
}); | ||
it('should clone closures', function(){ | ||
var generator = function () { var i = 0; return function() { return ++i; }; }; | ||
var a = generator(); | ||
assert.equal(a(), 1); | ||
assert.equal(a(), 2); | ||
var b = clone(a); | ||
assert.equal(a(), 3); | ||
assert.equal(a(), 4); | ||
assert.equal(b(), 5); | ||
assert.equal(b(), 6); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11111
11
284