Skip to content

Commit

Permalink
Merge pull request #149 from canjs/haskeynull
Browse files Browse the repository at this point in the history
Make hasOwnKey work on null derived objects
  • Loading branch information
matthewp authored Nov 13, 2018
2 parents b387b14 + d5feaae commit 804c5ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions reflections/shape/shape-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ QUnit.test("toArray", function(){
QUnit.module('can-reflect: shape reflections: own');

QUnit.test("hasOwnKey", function(){


var map;
// Defined on something

Expand All @@ -204,6 +202,16 @@ QUnit.test("hasOwnKey", function(){
});


QUnit.test("hasOwnKey on null derived object", function(){
var obj = Object.create(null);
obj.foo = "bar";

QUnit.ok( shapeReflections.hasOwnKey(obj, "foo") , "obj" );
QUnit.ok( !shapeReflections.hasOwnKey(obj, "bar") , "obj" );

});


QUnit.test("getOwnKeys", function(){
var obj = Object.create(null,{
foo: {value: "1", enumerable: true},
Expand Down
6 changes: 4 additions & 2 deletions reflections/shape/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ if(typeof Map === "function") {
// IE-remove-end
}

var hasOwnProperty = Object.prototype.hasOwnProperty;

var shapeReflections;

var shiftFirstArgumentToThis = function(func){
Expand Down Expand Up @@ -556,7 +558,7 @@ shapeReflections = {
});
return found;
}
return obj.hasOwnProperty(key);
return hasOwnProperty.call(obj, key);
},
/**
* @function can-reflect.getOwnEnumerableKeys getOwnEnumerableKeys
Expand Down Expand Up @@ -1057,7 +1059,7 @@ shapeReflections = {
return false;
}
if (typeReflections.isPrimitive(obj)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if (hasOwnProperty.call(obj, key)) {
return true;
} else {
var proto;
Expand Down

0 comments on commit 804c5ee

Please sign in to comment.