Comparing version 4.1.2 to 4.1.3
@@ -38,3 +38,3 @@ // Generated by CoffeeScript 1.10.0 | ||
this['test type_of'] = function(T) { | ||
this["test type_of"] = function(T) { | ||
T.eq(CND.type_of(new WeakMap()), 'weakmap'); | ||
@@ -68,3 +68,3 @@ T.eq(CND.type_of(new Map()), 'map'); | ||
this['test size_of'] = function(T) { | ||
this["test size_of"] = function(T) { | ||
T.eq(CND.size_of([1, 2, 3, 4]), 4); | ||
@@ -117,3 +117,3 @@ T.eq(CND.size_of(new Buffer([1, 2, 3, 4])), 4); | ||
this['XJSON'] = function(T) { | ||
this["XJSON (1)"] = function(T) { | ||
var d, e; | ||
@@ -124,12 +124,39 @@ CND.XJSON = require('./XJSON'); | ||
d = ['A', 'B', e]; | ||
help(d); | ||
info(CND.XJSON.stringify(d)); | ||
info(CND.XJSON.parse(CND.XJSON.stringify(d))); | ||
T.eq(CND.XJSON.stringify(d), "[\"A\",\"B\",{\"~isa\":\"set\",\"%self\":[\"x\",\"y\",{\"~isa\":\"set\",\"%self\":[\"a\",\"b\",\"c\"]}]}]"); | ||
T.eq(CND.XJSON.stringify(d), "[\"A\",\"B\",{\"~isa\":\"-x-set\",\"%self\":[\"x\",\"y\",{\"~isa\":\"-x-set\",\"%self\":[\"a\",\"b\",\"c\"]}]}]"); | ||
/* TAINT doing string comparison here to avoid implicit test that T.eq deals with sets correctly */ | ||
return T.eq(rpr(CND.XJSON.parse(CND.XJSON.stringify(d))), "[ 'A', 'B', Set { 'x', 'y', Set { 'a', 'b', 'c' } } ]"); | ||
T.eq(rpr(CND.XJSON.parse(CND.XJSON.stringify(d))), "[ 'A', 'B', Set { 'x', 'y', Set { 'a', 'b', 'c' } } ]"); | ||
return null; | ||
}; | ||
this['is_subset'] = function(T) { | ||
this["XJSON (2)"] = function(T) { | ||
var d, d_json, d_ng, d_ng_json, f, m, s; | ||
CND.XJSON = require('./XJSON'); | ||
s = new Set(Array.from('Popular Mechanics')); | ||
m = new Map([['a', 1], ['b', 2]]); | ||
f = function(x) { | ||
return Math.pow(x, 2); | ||
}; | ||
d = { | ||
s: s, | ||
m: m, | ||
f: f | ||
}; | ||
d_json = CND.XJSON.stringify(d); | ||
d_ng = CND.XJSON.parse(d_json); | ||
d_ng_json = CND.XJSON.stringify(d_ng); | ||
T.eq(d_json, d_ng_json); | ||
/* TAINT using T.eq directly on values, not their alternative serialization would implicitly test whether | ||
CND.equals accepts sets and maps | ||
*/ | ||
T.eq(rpr(d_ng['s']), rpr(d['s'])); | ||
T.eq(rpr(d_ng['m']), rpr(d['m'])); | ||
T.eq(d_ng['f'], d['f']); | ||
T.eq(d_ng['f'](12), d['f'](12)); | ||
T.eq(d_ng['f'](12), 144); | ||
return null; | ||
}; | ||
this["is_subset"] = function(T) { | ||
T.eq(false, CND.is_subset(Array.from('abcde'), Array.from('abcd'))); | ||
@@ -148,20 +175,28 @@ T.eq(false, CND.is_subset(Array.from('abcx'), Array.from('abcd'))); | ||
T.eq(true, CND.is_subset(new Set(), new Set('abcd'))); | ||
return T.eq(true, CND.is_subset(new Set(), new Set())); | ||
T.eq(true, CND.is_subset(new Set(), new Set())); | ||
return null; | ||
}; | ||
this['deep_copy'] = function(T) { | ||
var probe, result; | ||
probe = [ | ||
'foo', 42, [ | ||
'bar', (function() { | ||
return 'xxx'; | ||
}) | ||
], { | ||
q: 'Q', | ||
s: 'S' | ||
} | ||
this["deep_copy"] = function(T) { | ||
/* TAINT set comparison doesn't work */ | ||
var i, len, probe, probes, result; | ||
probes = [ | ||
[ | ||
'foo', 42, [ | ||
'bar', (function() { | ||
return 'xxx'; | ||
}) | ||
], { | ||
q: 'Q', | ||
s: 'S' | ||
} | ||
] | ||
]; | ||
result = CND.deep_copy(probe); | ||
T.eq(result, probe); | ||
T.ok(result !== probe); | ||
for (i = 0, len = probes.length; i < len; i++) { | ||
probe = probes[i]; | ||
result = CND.deep_copy(probe); | ||
T.eq(result, probe); | ||
T.ok(result !== probe); | ||
} | ||
return null; | ||
@@ -191,3 +226,4 @@ }; | ||
if (module.parent == null) { | ||
include = ['XJSON']; | ||
include = ["test type_of", "test size_of", "XJSON (1)", "XJSON (2)", "is_subset", "deep_copy"]; | ||
this._prune(); | ||
this._main(); | ||
@@ -194,0 +230,0 @@ } |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var CND, rpr; | ||
var CND, log, rpr; | ||
@@ -9,11 +9,28 @@ CND = require('./main'); | ||
log = console.log; | ||
this.replacer = function(key, value) { | ||
var R; | ||
if ((CND.type_of(value)) !== 'set') { | ||
return value; | ||
var R, type; | ||
switch (type = CND.type_of(value)) { | ||
case 'set': | ||
R = { | ||
'~isa': '-x-set', | ||
'%self': Array.from(value) | ||
}; | ||
break; | ||
case 'map': | ||
R = { | ||
'~isa': '-x-map', | ||
'%self': Array.from(value) | ||
}; | ||
break; | ||
case 'function': | ||
R = { | ||
'~isa': '-x-function', | ||
'%self': value.toString() | ||
}; | ||
break; | ||
default: | ||
R = value; | ||
} | ||
R = { | ||
'~isa': 'set', | ||
'%self': Array.from(value) | ||
}; | ||
return R; | ||
@@ -23,6 +40,17 @@ }; | ||
this.reviver = function(key, value) { | ||
if (!((CND.isa_pod(value)) && (value['~isa'] === 'set'))) { | ||
return value; | ||
var R, type; | ||
switch (type = CND.type_of(value)) { | ||
case '-x-set': | ||
R = new Set(value['%self']); | ||
break; | ||
case '-x-map': | ||
R = new Map(value['%self']); | ||
break; | ||
case '-x-function': | ||
R = (eval("[ " + value['%self'] + " ]"))[0]; | ||
break; | ||
default: | ||
R = value; | ||
} | ||
return new Set(value['%self']); | ||
return R; | ||
}; | ||
@@ -29,0 +57,0 @@ |
{ | ||
"name": "cnd", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"description": "a grab-bag NodeJS package mainly for functionalities that used to live in coffeenode-trm, coffeenode-bitsnpieces, and coffeenode-types", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
240737
2401
2