Skip to content

Commit c342c5f

Browse files
committed
Add unit test for issue 50 (Object for loop should filter with obj.hasOwnProperty(key))
* When testing with with disable_native on, the test will return '{"apple":2,"key":"value","AWESOME":7}'
1 parent a7f4362 commit c342c5f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/jquery.json.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,25 @@ test( 'Undefined and null', function(){
168168

169169

170170
});
171+
test( 'Prototype inheritance', function(){
172+
173+
Object.prototype.AWESOME = 7;
174+
175+
testToJSON(
176+
{ apple: 2, key: 'value' },
177+
'{"apple":2,"key":"value"}',
178+
'Prototype values should not be included in the string'
179+
);
180+
181+
// Since prototypes are highly dangerous,
182+
// make sure to remove it as soon as possible
183+
// Lots of code in jQuery will fail as it is
184+
// in the policy of jQuery that Object prototypes
185+
// are not supported.
186+
try {
187+
// Might fail in IE. Make sure to not let any exception
188+
// get out.
189+
delete Object.prototype.AWESOME;
190+
} catch(e){}
191+
192+
})

0 commit comments

Comments
 (0)