1 |
3a515b92
|
cagy
|
var inspect = require('../');
|
2 |
|
|
var test = require('tape');
|
3 |
|
|
|
4 |
|
|
function withoutProperty(object, property, fn) {
|
5 |
|
|
var original;
|
6 |
|
|
if (Object.getOwnPropertyDescriptor) {
|
7 |
|
|
original = Object.getOwnPropertyDescriptor(object, property);
|
8 |
|
|
} else {
|
9 |
|
|
original = object[property];
|
10 |
|
|
}
|
11 |
|
|
delete object[property];
|
12 |
|
|
try {
|
13 |
|
|
fn();
|
14 |
|
|
} finally {
|
15 |
|
|
if (Object.getOwnPropertyDescriptor) {
|
16 |
|
|
Object.defineProperty(object, property, original);
|
17 |
|
|
} else {
|
18 |
|
|
object[property] = original;
|
19 |
|
|
}
|
20 |
|
|
}
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
test('when Object#hasOwnProperty is deleted', function (t) {
|
24 |
|
|
t.plan(1);
|
25 |
|
|
var arr = [1, , 3]; // eslint-disable-line no-sparse-arrays
|
26 |
|
|
|
27 |
|
|
// eslint-disable-next-line no-extend-native
|
28 |
|
|
Array.prototype[1] = 2; // this is needed to account for "in" vs "hasOwnProperty"
|
29 |
|
|
|
30 |
|
|
withoutProperty(Object.prototype, 'hasOwnProperty', function () {
|
31 |
|
|
t.equal(inspect(arr), '[ 1, , 3 ]');
|
32 |
|
|
});
|
33 |
|
|
delete Array.prototype[1];
|
34 |
|
|
});
|