Given an object obj
, how can I assert that its property prop
is not configurable?
First, I thought I could use getOwnPropertyDescriptor
:
if(Object.getOwnPropertyDescriptor(obj, prop).configurable)
throw Error('The property is configurable');
But that isn't foolproof, because it could have been modified:
var getDescr = Object.getOwnPropertyDescriptor;
Object.getOwnPropertyDescriptor = function() {
var ret = getDescr.apply(this, arguments);
ret.configurable = false;
return ret;
};
Is there a foolproof way?