2023-12-18 13:12:25 +08:00
|
|
|
'use strict';
|
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
var hasOwn = require('hasown');
|
2023-12-18 13:12:25 +08:00
|
|
|
|
|
|
|
// data descriptor properties
|
|
|
|
var data = {
|
2024-01-16 21:26:16 +08:00
|
|
|
__proto__: null,
|
|
|
|
configurable: 'boolean',
|
|
|
|
enumerable: 'boolean',
|
|
|
|
writable: 'boolean',
|
2023-12-18 13:12:25 +08:00
|
|
|
};
|
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
module.exports = function isDataDescriptor(obj, prop) {
|
|
|
|
if (!obj || typeof obj !== 'object') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof prop === 'string') {
|
|
|
|
var val = Object.getOwnPropertyDescriptor(obj, prop);
|
|
|
|
return typeof val !== 'undefined';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
(!('value' in obj) && !('writable' in obj))
|
|
|
|
|| 'get' in obj
|
|
|
|
|| 'set' in obj
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var key in obj) { // eslint-disable-line no-restricted-syntax
|
|
|
|
if (
|
|
|
|
key !== 'value'
|
|
|
|
&& hasOwn(obj, key)
|
|
|
|
&& hasOwn(data, key)
|
|
|
|
&& typeof obj[key] !== data[key]
|
|
|
|
&& typeof obj[key] !== 'undefined'
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|