Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-v8-clone

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-v8-clone - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

bench/arrays.js

2

package.json
{
"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);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc