1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-06-12 16:09:52 +02:00

DOMRect: further performance improvements

Total improvement compared to 0.5.8: 7.2 (For #253)
This commit is contained in:
kkapsner 2019-05-11 13:16:45 +02:00
parent 82ba61095a
commit 587bd5bca8

View File

@ -4,7 +4,7 @@
(function(){ (function(){
"use strict"; "use strict";
var scope; let scope;
if ((typeof exports) !== "undefined"){ if ((typeof exports) !== "undefined"){
scope = exports; scope = exports;
} }
@ -16,7 +16,7 @@
const {byteArrayToString: hash} = require("./hash"); const {byteArrayToString: hash} = require("./hash");
var randomSupply = null; let randomSupply = null;
scope.setRandomSupply = function(supply){ scope.setRandomSupply = function(supply){
randomSupply = supply; randomSupply = supply;
}; };
@ -93,8 +93,8 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function getClientRects(){ return function getClientRects(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
var {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
var ret = original.apply(this, window.Array.from(args)); const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
for (let i = 0; i < ret.length; i += 1){ for (let i = 0; i < ret.length; i += 1){
registerDOMRect(ret[i], notify, window, prefs); registerDOMRect(ret[i], notify, window, prefs);
} }
@ -108,8 +108,8 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function getBoundingClientRect(){ return function getBoundingClientRect(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
var {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
var ret = original.apply(this, window.Array.from(args)); const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
registerDOMRect(ret, notify, window, prefs); registerDOMRect(ret, notify, window, prefs);
return ret; return ret;
}); });
@ -122,8 +122,8 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function getBounds(){ return function getBounds(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
var {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
var ret = original.apply(this, window.Array.from(args)); const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
registerDOMRect(ret, notify, window, prefs); registerDOMRect(ret, notify, window, prefs);
return ret; return ret;
}); });
@ -135,8 +135,8 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function getBBox(){ return function getBBox(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
var {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
var ret = original.apply(this, window.Array.from(args)); const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
registerDOMRect(ret, notify, window, prefs); registerDOMRect(ret, notify, window, prefs);
return ret; return ret;
}); });
@ -148,8 +148,8 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function getBBox(){ return function getBBox(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
var {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
var ret = original.apply(this, window.Array.from(args)); const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this);
registerDOMRect(ret, notify, window, prefs); registerDOMRect(ret, notify, window, prefs);
return ret; return ret;
}); });
@ -236,7 +236,9 @@
get intersectionRect(){ get intersectionRect(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = args.length?
original.apply(this, window.Array.from(args)):
original.call(this);
registerDOMRect(originalValue, notify, window, prefs); registerDOMRect(originalValue, notify, window, prefs);
return originalValue; return originalValue;
}); });
@ -257,7 +259,9 @@
get boundingClientRect(){ get boundingClientRect(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = args.length?
original.apply(this, window.Array.from(args)):
original.call(this);
registerDOMRect(originalValue, notify, window, prefs); registerDOMRect(originalValue, notify, window, prefs);
return originalValue; return originalValue;
}); });
@ -278,7 +282,9 @@
get rootBounds(){ get rootBounds(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = args.length?
original.apply(this, window.Array.from(args)):
original.call(this);
registerDOMRect(originalValue, notify, window, prefs); registerDOMRect(originalValue, notify, window, prefs);
return originalValue; return originalValue;
}); });