MCPcopy Index your code
hub / github.com/devote/HTML5-History-API / redefineProperty

Function redefineProperty

history.js:576–704  ·  view source on GitHub ↗

* This method is implemented to override the built-in(native) * properties in the browser, unfortunately some browsers are * not allowed to override all the properties and even add. * For this reason, this was written by a method that tries to * do everything necessary to get the desired

(object, prop, descriptor, onWrapped)

Source from the content-addressed store, hash-verified

574 * @return {Object|Boolean} Returns an object on success, otherwise returns false
575 */
576 function redefineProperty(object, prop, descriptor, onWrapped) {
577 var testOnly = 0;
578 // test only if descriptor is undefined
579 if (!descriptor) {
580 descriptor = {set: emptyFunction};
581 testOnly = 1;
582 }
583 // variable will have a value of true the success of attempts to set descriptors
584 var isDefinedSetter = !descriptor.set;
585 var isDefinedGetter = !descriptor.get;
586 // for tests of attempts to set descriptors
587 var test = {configurable: true, set: function() {
588 isDefinedSetter = 1;
589 }, get: function() {
590 isDefinedGetter = 1;
591 }};
592
593 try {
594 // testing for the possibility of overriding/adding properties
595 defineProperty(object, prop, test);
596 // running the test
597 object[prop] = object[prop];
598 // attempt to override property using the standard method
599 defineProperty(object, prop, descriptor);
600 } catch(_e_) {
601 }
602
603 // If the variable 'isDefined' has a false value, it means that need to try other methods
604 if (!isDefinedSetter || !isDefinedGetter) {
605 // try to override/add the property, using deprecated functions
606 if (object.__defineGetter__) {
607 // testing for the possibility of overriding/adding properties
608 object.__defineGetter__(prop, test.get);
609 object.__defineSetter__(prop, test.set);
610 // running the test
611 object[prop] = object[prop];
612 // attempt to override property using the deprecated functions
613 descriptor.get && object.__defineGetter__(prop, descriptor.get);
614 descriptor.set && object.__defineSetter__(prop, descriptor.set);
615 }
616
617 // Browser refused to override the property, using the standard and deprecated methods
618 if (!isDefinedSetter || !isDefinedGetter) {
619 if (testOnly) {
620 return false;
621 } else if (object === global) {
622 // try override global properties
623 try {
624 // save original value from this property
625 var originalValue = object[prop];
626 // set null to built-in(native) property
627 object[prop] = null;
628 } catch(_e_) {
629 }
630 // This rule for Internet Explorer 8
631 if ('execScript' in global) {
632 /**
633 * to IE8 override the global properties using

Callers 4

history.jsFile · 0.70
dispatchEventFunction · 0.70
onLoadFunction · 0.70
initializeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected