1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-03 12:06:31 +02:00

Big linting

This commit is contained in:
kkapsner 2019-11-28 01:26:35 +01:00
parent b5e6d049ce
commit aef6bd3d59
58 changed files with 2074 additions and 1856 deletions

View file

@ -43,7 +43,8 @@
crypto.subtle.digest("SHA-256", data).then(function(hash){
hashNode.textContent = byteArrayToHex(hash);
}, function(error){
return;
}).catch(function(error){
hashNode.textContent = error;
});
hashSets[set].appendChild(container);

View file

@ -1,4 +1,3 @@
/* eslint no-console: off, max-lines: off */
var addTest = (function(){
"use strict";
@ -18,8 +17,9 @@ var addTest = (function(){
try {
status = func(log)? 1: 2;
}
catch (e){
console.log(e);
catch (error){
// eslint-disable-next-line no-console
console.log(error);
status = 3;
}
var li = document.createElement("li");
@ -214,6 +214,7 @@ addTest("property descriptor", function(log){
object: CanvasRenderingContext2D.prototype,
name: "getImageData",
descriptor: {
// eslint-disable-next-line no-unused-vars
value: function getImageData(x, y, w, h){},
writable: true,
enumerable: true,
@ -255,12 +256,12 @@ addTest("error provocation 1", function(log){
try{
ctx.getImageData(0, 0, 0, 0);
}
catch (err){
catch (error){
try {
log(err.name);
log(err.toString());
log(error.name);
log(error.toString());
}
catch (e){
catch (error){
canvasBlocker = true;
}
}
@ -277,12 +278,12 @@ addTest("error provocation 2", function(log){
ctx.getImageData(0, 0, 1, 1);
log("no error provoked");
}
catch (err){
catch (error){
try {
log(err.name);
log(err.toString());
log(error.name);
log(error.toString());
}
catch (e){
catch (error){
canvasBlocker = true;
}
}
@ -295,12 +296,12 @@ addTest("error provocation 3", function(log){
try{
CanvasRenderingContext2D.prototype.getImageData.apply(undefined, [0, 0, 1, 1]);
}
catch (err){
catch (error){
try {
log(err.name);
log(err.toString());
log(error.name);
log(error.toString());
}
catch (e){
catch (error){
canvasBlocker = true;
}
}
@ -313,26 +314,26 @@ addTest("error properties", function(log){
try{
CanvasRenderingContext2D.prototype.getImageData.apply(undefined, [0, 0, 1, 1]);
}
catch (err){
catch (error){
try {
var name = "TypeError";
if (err.name !== name && err instanceof TypeError){
log("Error name wrong. Expected: ", name, "- got:", err.name);
if (error.name !== name && error instanceof TypeError){
log("Error name wrong. Expected: ", name, "- got:", error.name);
canvasBlocker = true;
}
var start = "@" + location.href.replace(/\.html$/, ".js");
if (!err.stack.startsWith(start)){
log("Error stack starts wrong. Expected:", start, "- got :", err.stack.split(/\n/g, 2)[0]);
if (!error.stack.startsWith(start)){
log("Error stack starts wrong. Expected:", start, "- got :", error.stack.split(/\n/g, 2)[0]);
canvasBlocker = true;
}
var message = "'getImageData' called on an object that " +
"does not implement interface CanvasRenderingContext2D.";
if (err.message !== message){
log("Error message wrong. Expected: ", message, "- got:", err.message);
if (error.message !== message){
log("Error message wrong. Expected: ", message, "- got:", error.message);
canvasBlocker = true;
}
}
catch (e){
catch (error){
canvasBlocker = true;
}
}

View file

@ -21,66 +21,78 @@
return Array.from(doc.querySelectorAll(".testRect"));
}
function formatNumber(number){
const str = number.toString();
return "<span class=small>" + str.substring(0, str.length - 2) + "</span>" +
str.substring(str.length - 2);
}
const properties = ["x", "y", "width", "height", "top", "left", "right", "bottom"];
function performTest(output, callback){
const rects = getElements().map(function(element){
return {
name: element.dataset.name,
data: callback(element)
};
});
const data = new Float64Array(rects.length * properties.length);
rects.forEach(function(rect, i){
properties.forEach(function(property, j){
data[i * properties.length + j] = rect.data[property];
});
});
crypto.subtle.digest("SHA-256", data)
.then(function(hash){
output.querySelector(".hash").textContent = byteArrayToHex(hash);
return;
}).catch(function(error){
output.querySelector(".hash").textContent = "Unable to compute hash: " + error;
});
var dataNode = output.querySelector(".data");
dataNode.innerHTML = "<table><tr><th></th>" +
rects.map(function(rect){
return "<th>" + rect.name + "</th>";
}).join("") +
"</tr><tr><th>hash</th>" +
rects.map(function(rect){
return "<td class=\"rectHash\" data-name=\"" + rect.name + "\"></td>";
}).join("") +
"</tr>" +
properties.map(function(property){
return "<tr><th>" + property + "</th>" + rects.map(function(rect){
return "<td class=\"value\" title=\"" + rect.data[property] + "\">" +
formatNumber(rect.data[property]) +
"</td>";
}).join("") + "</tr>";
}).join("") +
"</table>";
rects.forEach(function(rect){
const data = new Float64Array(properties.length);
properties.forEach(function(property, i){
data[i] = rect.data[property];
});
crypto.subtle.digest("SHA-256", data).then(function(hash){
dataNode.querySelector(
".rectHash[data-name=\"" + rect.name + "\"]"
).textContent = byteArrayToHex(hash);
return;
}).catch(function(error){
dataNode.querySelector(
".rectHash[data-name=\"" + rect.name + "\"]"
).textContent = "Unable to compute hash: " + error;
});
});
}
function createTest(title, callback){
const properties = ["x", "y", "width", "height", "top", "left", "right", "bottom"];
function performTest(){
const rects = getElements().map(function(element){
return {
name: element.dataset.name,
data: callback(element)
};
});
const data = new Float64Array(rects.length * properties.length);
rects.forEach(function(rect, i){
properties.forEach(function(property, j){
data[i * properties.length + j] = rect.data[property];
});
});
crypto.subtle.digest("SHA-256", data)
.then(function(hash){
output.querySelector(".hash").textContent = byteArrayToHex(hash);
});
function formatNumber(number){
const str = number.toString();
return "<span class=small>" + str.substring(0, str.length - 2) + "</span>" +
str.substring(str.length - 2);
}
var dataNode = output.querySelector(".data");
dataNode.innerHTML = "<table><tr><th></th>" +
rects.map(function(rect){
return "<th>" + rect.name + "</th>";
}).join("") +
"</tr><tr><th>hash</th>" +
rects.map(function(rect){
return "<td class=\"rectHash\" data-name=\"" + rect.name + "\"></td>";
}).join("") +
"</tr>" +
properties.map(function(property){
return "<tr><th>" + property + "</th>" + rects.map(function(rect){
return "<td class=\"value\" title=\"" + rect.data[property] + "\">" +
formatNumber(rect.data[property]) +
"</td>";
}).join("") + "</tr>";
}).join("") +
"</table>";
rects.forEach(function(rect){
const data = new Float64Array(properties.length);
properties.forEach(function(property, i){
data[i] = rect.data[property];
});
crypto.subtle.digest("SHA-256", data).then(function(hash){
dataNode.querySelector(
".rectHash[data-name=\"" + rect.name + "\"]"
).textContent = byteArrayToHex(hash);
});
});
}
const output = template.cloneNode(true);
output.querySelector(".title").textContent = title;
output.querySelector(".refresh").addEventListener("click", performTest);
output.querySelector(".refresh").addEventListener("click", function(){
performTest(output, callback);
});
output.querySelector(".performance").addEventListener("click", function(){
let count = 200;
let totalCount = 0;
@ -122,7 +134,7 @@
}());
container.appendChild(output);
performTest();
performTest(output, callback);
}
iframe.addEventListener("load", function(){
createTest("Element.getClientRects", function(element){

View file

@ -1,2 +1,2 @@
/* eslint no-console: off */
// eslint-disable-next-line no-console
console.log("first possible call");

View file

@ -1,6 +1,14 @@
var log = function(){
"use strict";
return function log(...str){
if (str[str.length - 1] === "match"){
str.unshift("color: green");
str.unshift("%cOK");
}
else if (str[str.length - 1].substr(0, 9) === "missmatch"){
str.unshift("color: red");
str.unshift("%cX");
}
// eslint-disable-next-line no-console
console.log(...str);
};
@ -32,7 +40,7 @@ function test(window){
// create window canvas
var canvas = document.createElement("canvas");
// draw image in window canvas
var ctx = draw(canvas);
draw(canvas);
return window.HTMLCanvasElement.prototype.toDataURL.call(canvas);
}
@ -55,12 +63,13 @@ function hash(string){
function compare(string1, string2, alwaysOutputHashes){
"use strict";
function outputHashes(message){
Promise.all([
return Promise.all([
hash(string1),
hash(string2)
]).then(function(hashes){
// eslint-disable-next-line no-console
console.log(message, ...hashes);
return;
});
}
@ -98,4 +107,9 @@ hash(reference).then(function(hash){
"use strict";
log("reference hash:", hash);
return;
}).catch(function(error){
"use strict";
log("%cX", "color: red", "Unable to compute reference hash:", error);
});

View file

@ -36,6 +36,7 @@ var performTest = function(){
var log = createLog();
log.createLine("test " + name, "h3");
var line = log.createLine("");
var line2;
var time = 0;
var time2 = 0;
var min = Number.POSITIVE_INFINITY;
@ -80,7 +81,7 @@ var performTest = function(){
}
window.setTimeout(run, 10);
});
var line2 = log.createLine("");
line2 = log.createLine("");
};
}();

View file

@ -34,6 +34,7 @@ function addConsistencyTest(title, callback){
consistent.textContent = "computing";
callback().then(function(value){
consistent.textContent = value? "OK": "not OK";
return;
}).catch(function(error){
consistent.classList.add("failed");
if (Array.isArray(error)){
@ -141,6 +142,7 @@ function addResolutionTest(title, callback){
number.textContent = "computing";
callback(type).then(function(value){
number.textContent = value;
return;
}).catch(function(error){
number.classList.add("failed");
number.textContent = error;
@ -214,15 +216,14 @@ function searchValue(tester){
return minValue;
}
else {
// eslint-disable-next-line promise/no-nesting
return tester(maxValue).then(function(testResult){
if (testResult.isEqual){
return maxValue;
}
else {
return Promise.reject(
"Search could not find exact value." +
" It's between " + minValue + " and " + maxValue + "."
);
throw "Search could not find exact value." +
" It's between " + minValue + " and " + maxValue + ".";
}
});
}

View file

@ -42,8 +42,8 @@
try {
var firstFingerprint = fingerPrint();
}
catch (e){
console.log(new Date(), e);
catch (error){
console.log(new Date(), error);
var firstFingerprint = false;
}
</script>

View file

@ -1,4 +1,3 @@
/* eslint no-console: off */
(function(){
"use strict";
@ -24,25 +23,35 @@
container.querySelector(".hash").textContent =
hashToString(hashes[0]) + " / " +
hashToString(hashes[1]);
return;
}).catch(function(error){
container.querySelector(".hash").textContent = "Error while calculating hash: " + error;
});
container.querySelector(".isPointInPath").textContent = isPointInPath;
}
if (location.search !== "?notInitial"){
try {show(document.getElementById("top"), topTest());}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
try {show(document.getElementById("iframe"), iframeTest(document.querySelector("#iframe iframe")));}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
try {show(document.getElementById("iframe2"), iframeTest(document.querySelector("#iframe2 iframe")));}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
try {show(document.getElementById("iframe3"), iframeTest(document.querySelector("#iframe3 iframe")));}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
try {show(document.getElementById("iframe4"), dynamicIframeTest1());}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
try {show(document.getElementById("iframe5"), dynamicIframeTest2());}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
try {show(document.getElementById("iframe6"), dynamicIframeTest3());}
catch (e){console.error(e);}
// eslint-disable-next-line no-console
catch (error){console.error(error);}
}
document.querySelector("#top button").addEventListener("click", function(){
show(document.getElementById("top"), topTest());

View file

@ -1,6 +1,50 @@
(function(){
"use strict";
function getParameters(context){
const parameters = [];
for (var name in context){
if (name.toUpperCase() === name){
var value = context.getParameter(context[name]);
if (value !== null){
parameters.push({name: name, value: value});
}
}
}
const debugExtension = context.getExtension("WEBGL_debug_renderer_info");
for (name in debugExtension){
if (name.toUpperCase() === name){
value = context.getParameter(debugExtension[name]);
if (value !== null){
parameters.push({name: name, value: value});
}
}
}
var frontParameters = ["VENDOR", "RENDERER", "UNMASKED_VENDOR_WEBGL", "UNMASKED_RENDERER_WEBGL"];
parameters.sort(function(a, b){
var frontA = frontParameters.indexOf(a.name);
var frontB = frontParameters.indexOf(b.name);
if (frontA !== -1){
if (frontB !== -1){
return frontA - frontB;
}
else {
return -1;
}
}
else {
if (frontB !== -1){
return 1;
}
else {
return a.name < b.name? -1: 1;
}
}
});
return parameters;
}
["webgl", "webgl2"].forEach(function(context, index){
var output = document.createElement("div");
document.getElementById("output").appendChild(output);
@ -22,46 +66,8 @@
values[pixels[i]] = (values[pixels[i]] || 0) + 1;
max = Math.max(max, values[pixels[i]]);
}
const parameters = [];
for (var name in gl){
if (name.toUpperCase() === name){
var value = gl.getParameter(gl[name]);
if (value !== null){
parameters.push({name: name, value: value});
}
}
}
const debugExtension = gl.getExtension("WEBGL_debug_renderer_info");
for (name in debugExtension){
if (name.toUpperCase() === name){
value = gl.getParameter(debugExtension[name]);
if (value !== null){
parameters.push({name: name, value: value});
}
}
}
var frontParameters = ["VENDOR", "RENDERER", "UNMASKED_VENDOR_WEBGL", "UNMASKED_RENDERER_WEBGL"];
parameters.sort(function(a, b){
var frontA = frontParameters.indexOf(a.name);
var frontB = frontParameters.indexOf(b.name);
if (frontA !== -1){
if (frontB !== -1){
return frontA - frontB;
}
else {
return -1;
}
}
else {
if (frontB !== -1){
return 1;
}
else {
return a.name < b.name? -1: 1;
}
}
});
const parameters = getParameters(gl);
if (context === "webgl2"){
var parameterOutput = document.createElement("table");
document.getElementById("parameters").appendChild(parameterOutput);
@ -87,11 +93,14 @@
(max !== 3 * values[255]? "": "not ") + "supported " +
"(parameter hash: " + hash + ")";
output.title = JSON.stringify(values);
return;
}).catch(function(error){
output.textContent = "Error while calculating hash: " + error;
});
}
catch (e){
catch (error){
output.textContent = context + ": ERROR";
output.title = e;
output.title = error;
}
});
}());