can-reflect
Advanced tools
Comparing version 1.16.3 to 1.16.4
{ | ||
"name": "can-reflect", | ||
"version": "1.16.3", | ||
"version": "1.16.4", | ||
"description": "reflection on unknown data types", | ||
@@ -5,0 +5,0 @@ "homepage": "http://canjs.com", |
@@ -93,1 +93,16 @@ var QUnit = require('steal-qunit'); | ||
}); | ||
QUnit.test("splice", function(){ | ||
var arr = ["a","b"]; | ||
getSetReflections.splice(arr, 0, 1); | ||
QUnit.deepEqual(arr, ["b"], "removes item with no additions"); | ||
arr = ["a","b"]; | ||
getSetReflections.splice(arr, 0, 1, ["c", "d"]); | ||
QUnit.deepEqual(arr, ["c","d","b"], "removes item with no additions"); | ||
}); |
@@ -194,2 +194,6 @@ var canSymbol = require("can-symbol"); | ||
if(arguments.length <= 3){ | ||
adding = []; | ||
} | ||
var splice = obj[canSymbol.for("can.splice")]; | ||
@@ -196,0 +200,0 @@ if(splice) { |
@@ -521,3 +521,3 @@ var QUnit = require('steal-qunit'); | ||
QUnit.test("hasKey", function() { | ||
var objHasKey = {}; | ||
/*var objHasKey = {}; | ||
Object.defineProperty(objHasKey, "_keys", { | ||
@@ -543,3 +543,10 @@ value: { foo: true } | ||
objHasOwnKey.bar = "baz"; | ||
QUnit.ok(shapeReflections.hasKey(objHasOwnKey, "bar") , "returns true when hasOwnKey Symbol returns false but `in` returns true"); | ||
QUnit.ok(shapeReflections.hasKey(objHasOwnKey, "bar") , "returns true when hasOwnKey Symbol returns false but `in` returns true");*/ | ||
debugger; | ||
QUnit.ok(shapeReflections.hasKey(55, "toFixed") , "works on primitives"); | ||
QUnit.ok(shapeReflections.hasKey(true, "valueOf") , "works on primitives"); | ||
QUnit.ok(shapeReflections.hasKey('foo', "length") , "works on primitives"); | ||
QUnit.notOk(shapeReflections.hasKey(null, "length") , "works on null"); | ||
QUnit.notOk(shapeReflections.hasKey(undefined, "length") , "works on undefined"); | ||
}); | ||
@@ -546,0 +553,0 @@ |
@@ -6,2 +6,12 @@ var canSymbol = require("can-symbol"); | ||
var getPrototypeOfWorksWithPrimitives = true; | ||
try { | ||
Object.getPrototypeOf(1); | ||
} catch(e) { | ||
getPrototypeOfWorksWithPrimitives = false; | ||
} | ||
var ArrayMap; | ||
@@ -986,3 +996,18 @@ if(typeof Map === "function") { | ||
*/ | ||
"hasKey": function(obj, key) { | ||
hasKey: function(obj, key) { | ||
if( obj == null ) { | ||
return false; | ||
} | ||
if (typeReflections.isPrimitive(obj)) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
return true; | ||
} else { | ||
var proto = (getPrototypeOfWorksWithPrimitives ? Object.getPrototypeOf(obj) : obj.__proto__); | ||
if(proto !== undefined) { | ||
return key in proto; | ||
} else { | ||
return obj[key] !== undefined; | ||
} | ||
} | ||
} | ||
var hasKey = obj[canSymbol.for("can.hasKey")]; | ||
@@ -989,0 +1014,0 @@ if(hasKey) { |
@@ -85,2 +85,5 @@ var QUnit = require('steal-qunit'); | ||
QUnit.equal(typeReflections.isMoreListLikeThanMapLike([]), true, "Array"); | ||
QUnit.equal(typeReflections.isMoreListLikeThanMapLike(null), false, "null"); | ||
QUnit.equal(typeReflections.isMoreListLikeThanMapLike(undefined), false, "undefined"); | ||
}); | ||
@@ -87,0 +90,0 @@ |
@@ -439,3 +439,3 @@ var canSymbol = require("can-symbol"); | ||
* canReflect.isMoreListLikeThanMapLike([]); // -> true | ||
* canReflect.isMoreListLikeThanMapLike(null); // -> undefined | ||
* canReflect.isMoreListLikeThanMapLike(null); // -> false | ||
* canReflect.isMoreListLikeThanMapLike({}); // -> false | ||
@@ -457,2 +457,5 @@ * canReflect.isMoreListLikeThanMapLike(new DefineList()); // -> true | ||
} | ||
if( obj == null ) { | ||
return false; | ||
} | ||
var value = obj[canSymbol.for("can.isMoreListLikeThanMapLike")]; | ||
@@ -459,0 +462,0 @@ if(value !== undefined) { |
173725
4697