Skip to content

Commit

Permalink
[DOMInstr] add Element.remove & Element.innerText
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Dec 20, 2016
1 parent b00f09d commit 3d5a271
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions test/dominstr.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,44 @@
var isIE = navigator.userAgent.indexOf("Trident/") !== -1;
var isMS = isEdge || isIE;

var getDescr = Object.getOwnPropertyDescriptor;
var defProp = Object.defineProperty;

var nodeProto = Node.prototype;
var textContent = Object.getOwnPropertyDescriptor(nodeProto, "textContent");
var nodeValue = Object.getOwnPropertyDescriptor(nodeProto, "nodeValue");
var textContent = getDescr(nodeProto, "textContent");
var nodeValue = getDescr(nodeProto, "nodeValue");

var htmlProto = HTMLElement.prototype;
// var innerText = Object.getOwnPropertyDescriptor(htmlProto, "innerText");
var innerText = getDescr(htmlProto, "innerText");

var elemProto = Element.prototype;
var innerHTML = Object.getOwnPropertyDescriptor(!isIE ? elemProto : htmlProto, "innerHTML");
var className = Object.getOwnPropertyDescriptor(!isIE ? elemProto : htmlProto, "className");
var id = Object.getOwnPropertyDescriptor(!isIE ? elemProto : htmlProto, "id");
var innerHTML = getDescr(!isIE ? elemProto : htmlProto, "innerHTML");
var className = getDescr(!isIE ? elemProto : htmlProto, "className");
var id = getDescr(!isIE ? elemProto : htmlProto, "id");

var styleProto = CSSStyleDeclaration.prototype;

var cssText = Object.getOwnPropertyDescriptor(styleProto, "cssText");
var cssText = getDescr(styleProto, "cssText");

var inpProto = HTMLInputElement.prototype;
var areaProto = HTMLTextAreaElement.prototype;
var selProto = HTMLSelectElement.prototype;
var optProto = HTMLOptionElement.prototype;

var inpChecked = Object.getOwnPropertyDescriptor(inpProto, "checked");
var inpVal = Object.getOwnPropertyDescriptor(inpProto, "value");
var inpChecked = getDescr(inpProto, "checked");
var inpVal = getDescr(inpProto, "value");

var areaVal = Object.getOwnPropertyDescriptor(areaProto, "value");
var areaVal = getDescr(areaProto, "value");

var selVal = Object.getOwnPropertyDescriptor(selProto, "value");
var selIndex = Object.getOwnPropertyDescriptor(selProto, "selectedIndex");
var selVal = getDescr(selProto, "value");
var selIndex = getDescr(selProto, "selectedIndex");

var optSel = Object.getOwnPropertyDescriptor(optProto, "selected");
var optSel = getDescr(optProto, "selected");

// onclick, onkey*, etc..

// var styleProto = CSSStyleDeclaration.prototype;
// var setProperty = Object.getOwnPropertyDescriptor(styleProto, "setProperty");
// var setProperty = getDescr(styleProto, "setProperty");

function DOMInstr(withTime) {
var origOps = {
Expand All @@ -64,6 +67,7 @@
"Element.prototype.removeChild": null,
"Element.prototype.insertBefore": null,
"Element.prototype.replaceChild": null,
"Element.prototype.remove": null,

"Element.prototype.setAttribute": null,
"Element.prototype.setAttributeNS": null,
Expand Down Expand Up @@ -105,99 +109,99 @@
}

counts.textContent = 0;
Object.defineProperty(nodeProto, "textContent", {
defProp(nodeProto, "textContent", {
set: function(s) {
counts.textContent++;
textContent.set.call(this, s);
},
});

counts.nodeValue = 0;
Object.defineProperty(nodeProto, "nodeValue", {
defProp(nodeProto, "nodeValue", {
set: function(s) {
counts.nodeValue++;
nodeValue.set.call(this, s);
},
});
/*

counts.innerText = 0;
Object.defineProperty(htmlProto, "innerText", {
defProp(htmlProto, "innerText", {
set: function(s) {
counts.innerText++;
innerText.set.call(this, s);
},
});
*/

counts.innerHTML = 0;
Object.defineProperty(!isIE ? elemProto : htmlProto, "innerHTML", {
defProp(!isIE ? elemProto : htmlProto, "innerHTML", {
set: function(s) {
counts.innerHTML++;
innerHTML.set.call(this, s);
},
});

counts.className = 0;
Object.defineProperty(!isIE ? elemProto : htmlProto, "className", {
defProp(!isIE ? elemProto : htmlProto, "className", {
set: function(s) {
counts.className++;
className.set.call(this, s);
},
});

counts.cssText = 0;
Object.defineProperty(styleProto, "cssText", {
defProp(styleProto, "cssText", {
set: function(s) {
counts.cssText++;
cssText.set.call(this, s);
},
});

counts.id = 0;
Object.defineProperty(!isIE ? elemProto : htmlProto, "id", {
defProp(!isIE ? elemProto : htmlProto, "id", {
set: function(s) {
counts.id++;
id.set.call(this, s);
},
});

counts.checked = 0;
Object.defineProperty(inpProto, "checked", {
defProp(inpProto, "checked", {
set: function(s) {
counts.checked++;
inpChecked.set.call(this, s);
},
});

counts.value = 0;
Object.defineProperty(inpProto, "value", {
defProp(inpProto, "value", {
set: function(s) {
counts.value++;
inpVal.set.call(this, s);
},
});
Object.defineProperty(areaProto, "value", {
defProp(areaProto, "value", {
set: function(s) {
counts.value++;
areaVal.set.call(this, s);
},
});
Object.defineProperty(selProto, "value", {
defProp(selProto, "value", {
set: function(s) {
counts.value++;
selVal.set.call(this, s);
},
});

counts.selectedIndex = 0;
Object.defineProperty(selProto, "selectedIndex", {
defProp(selProto, "selectedIndex", {
set: function(s) {
counts.selectedIndex++;
selIndex.set.call(this, s);
},
});

counts.selected = 0;
Object.defineProperty(optProto, "selected", {
defProp(optProto, "selected", {
set: function(s) {
counts.selected++;
optSel.set.call(this, s);
Expand All @@ -206,7 +210,7 @@

/*
counts.setProperty = 0;
Object.defineProperty(styleProto, "setProperty", {
defProp(styleProto, "setProperty", {
set: function(s) {
counts.setProperty++;
setProperty.set.call(this, s);
Expand All @@ -226,20 +230,20 @@
p.ctx[p.last] = origOps[opName];
}

Object.defineProperty(nodeProto, "textContent", textContent);
Object.defineProperty(nodeProto, "nodeValue", nodeValue);
// Object.defineProperty(htmlProto, "innerText", innerText);
Object.defineProperty(!isIE ? elemProto : htmlProto, "innerHTML", innerHTML);
Object.defineProperty(!isIE ? elemProto : htmlProto, "className", className);
Object.defineProperty(!isIE ? elemProto : htmlProto, "id", id);
Object.defineProperty(inpProto, "checked", inpChecked);
Object.defineProperty(inpProto, "value", inpVal);
Object.defineProperty(areaProto, "value", areaVal);
Object.defineProperty(selProto, "value", selVal);
Object.defineProperty(selProto, "selectedIndex", selIndex);
Object.defineProperty(optProto, "selected", optSel);
// Object.defineProperty(styleProto, "setProperty", setProperty);
Object.defineProperty(styleProto, "cssText", cssText);
defProp(nodeProto, "textContent", textContent);
defProp(nodeProto, "nodeValue", nodeValue);
defProp(htmlProto, "innerText", innerText);
defProp(!isIE ? elemProto : htmlProto, "innerHTML", innerHTML);
defProp(!isIE ? elemProto : htmlProto, "className", className);
defProp(!isIE ? elemProto : htmlProto, "id", id);
defProp(inpProto, "checked", inpChecked);
defProp(inpProto, "value", inpVal);
defProp(areaProto, "value", areaVal);
defProp(selProto, "value", selVal);
defProp(selProto, "selectedIndex", selIndex);
defProp(optProto, "selected", optSel);
// defProp(styleProto, "setProperty", setProperty);
defProp(styleProto, "cssText", cssText);

var out = {};

Expand Down

0 comments on commit 3d5a271

Please sign in to comment.