This commit is contained in:
Pierre Ossman 2018-09-17 13:50:59 +02:00
commit 9881899e7b
43 changed files with 568 additions and 520 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
**/xtscancodes.js

View File

@ -8,6 +8,8 @@
},
"extends": "eslint:recommended",
"rules": {
// Unsafe or confusing stuff that we forbid
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
"no-constant-condition": ["error", { "checkLoops": false }],
"no-var": "error",
@ -18,5 +20,29 @@
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
"arrow-spacing": ["error"],
"no-confusing-arrow": ["error", { "allowParens": true }],
// Enforced coding style
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"indent": ["error", 4, { "SwitchCase": 1,
"CallExpression": { "arguments": "first" },
"ArrayExpression": "first",
"ObjectExpression": "first",
"ignoreComments": true }],
"comma-spacing": ["error"],
"comma-style": ["error"],
"curly": ["error", "multi-line"],
"func-call-spacing": ["error"],
"func-names": ["error"],
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"key-spacing": ["error"],
"keyword-spacing": ["error"],
"no-trailing-spaces": ["error"],
"semi": ["error"],
"space-before-blocks": ["error"],
"space-before-function-paren": ["error", { "anonymous": "always",
"named": "never",
"asyncArrow": "always" }],
"switch-colon-spacing": ["error"],
}
}

View File

@ -5,7 +5,7 @@
// No ES6 can be used in this file since it's used for the translation
/* eslint-disable prefer-arrow-callback */
(function() {
(function _scope() {
"use strict";
// Fallback for all uncought errors
@ -53,6 +53,6 @@
// from being printed to the browser console.
return false;
}
window.addEventListener('error', function (evt) { handleError(evt, evt.error); });
window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); });
window.addEventListener('error', function onerror(evt) { handleError(evt, evt.error); });
window.addEventListener('unhandledrejection', function onreject(evt) { handleError(evt.reason, evt.reason); });
})();

View File

@ -53,10 +53,12 @@ export class Localizer {
.replace("_", "-")
.split("-");
if (userLang[0] !== supLang[0])
if (userLang[0] !== supLang[0]) {
continue;
if (userLang[1] !== supLang[1])
}
if (userLang[1] !== supLang[1]) {
continue;
}
this.language = supportedLanguages[j];
return;
@ -69,10 +71,12 @@ export class Localizer {
.replace("_", "-")
.split("-");
if (userLang[0] !== supLang[0])
if (userLang[0] !== supLang[0]) {
continue;
if (supLang[1] !== undefined)
}
if (supLang[1] !== undefined) {
continue;
}
this.language = supportedLanguages[j];
return;

View File

@ -147,8 +147,7 @@ const UI = {
if (!port) {
if (window.location.protocol.substring(0, 5) == 'https') {
port = 443;
}
else if (window.location.protocol.substring(0,4) == 'http') {
} else if (window.location.protocol.substring(0, 4) == 'http') {
port = 80;
}
}

View File

@ -43,6 +43,7 @@ export default {
},
/* Convert Base64 data to a string */
/* eslint-disable comma-spacing */
toBinaryTable: [
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
@ -53,6 +54,7 @@ export default {
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
],
/* eslint-enable comma-spacing */
decode(data, offset) {
offset = typeof(offset) !== 'undefined' ? offset : 0;

View File

@ -34,7 +34,7 @@ export default class RawDecoder {
// Convert data if needed
if (depth == 8) {
const pixels = width * curr_height
const pixels = width * curr_height;
const newdata = new Uint8Array(pixels * 4);
for (let i = 0; i < pixels; i++) {
newdata[i * 4 + 0] = ((data[index + i] >> 0) & 0x3) * 255 / 3;

View File

@ -75,6 +75,8 @@
* fine Java utilities: http://www.acme.com/java/
*/
/* eslint-disable comma-spacing */
export default function DES(passwd) {
"use strict";

View File

@ -15,23 +15,20 @@ import KeyTable from "./keysym.js";
const DOMKeyTable = {};
function addStandard(key, standard)
{
function addStandard(key, standard) {
if (standard === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
DOMKeyTable[key] = [standard, standard, standard, standard];
}
function addLeftRight(key, left, right)
{
function addLeftRight(key, left, right) {
if (left === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (right === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
DOMKeyTable[key] = [left, left, right, left];
}
function addNumpad(key, standard, numpad)
{
function addNumpad(key, standard, numpad) {
if (standard === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (numpad === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";

View File

@ -14,6 +14,8 @@
* See https://www.w3.org/TR/uievents-key/ for possible values.
*/
/* eslint-disable key-spacing */
export default {
// 3.1.1.1. Writing System Keys

View File

@ -249,10 +249,11 @@ export default class Keyboard {
// Character (A-Z)
let char = String.fromCharCode(e.keyCode);
// A feeble attempt at the correct case
if (e.shiftKey)
if (e.shiftKey) {
char = char.toUpperCase();
else
} else {
char = char.toLowerCase();
}
keysym = char.charCodeAt();
} else {
// Unknown, give up

View File

@ -1,3 +1,5 @@
/* eslint-disable key-spacing */
export default {
XK_VoidSymbol: 0xffffff, /* Void symbol */

View File

@ -2036,11 +2036,13 @@ RFB.cursors = {
},
dot: {
/* eslint-disable indent */
rgbaPixels: new Uint8Array([
255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255,
0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255,
255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255,
]),
/* eslint-enable indent */
w: 3, h: 3,
hotx: 1, hoty: 1,
}

View File

@ -174,39 +174,45 @@ export default class Cursor {
}
_showCursor() {
if (this._canvas.style.visibility === 'hidden')
if (this._canvas.style.visibility === 'hidden') {
this._canvas.style.visibility = '';
}
}
_hideCursor() {
if (this._canvas.style.visibility !== 'hidden')
if (this._canvas.style.visibility !== 'hidden') {
this._canvas.style.visibility = 'hidden';
}
}
// Should we currently display the cursor?
// (i.e. are we over the target, or a child of the target without a
// different cursor set)
_shouldShowCursor(target) {
// Easy case
if (target === this._target)
if (target === this._target) {
return true;
}
// Other part of the DOM?
if (!this._target.contains(target))
if (!this._target.contains(target)) {
return false;
}
// Has the child its own cursor?
// FIXME: How can we tell that a sub element has an
// explicit "cursor: none;"?
if (window.getComputedStyle(target).cursor !== 'none')
if (window.getComputedStyle(target).cursor !== 'none') {
return false;
}
return true;
}
_updateVisibility(target) {
if (this._shouldShowCursor(target))
if (this._shouldShowCursor(target)) {
this._showCursor();
else
} else {
this._hideCursor();
}
}
_updatePosition() {
this._canvas.style.left = this._position.x + "px";

View File

@ -8,6 +8,8 @@
"sinon": false
},
"rules": {
"prefer-arrow-callback": 0
"prefer-arrow-callback": 0,
// Too many anonymous callbacks
"func-names": "off",
}
}

View File

@ -35,8 +35,9 @@ document.body.appendChild(script);
function fallback() {
if (!window._noVNC_has_module_support) {
/* eslint-disable no-console */
if (console)
if (console) {
console.log("No module support detected. Loading fallback...");
}
/* eslint-enable no-console */
let loader = document.createElement("script");
loader.src = "base/vendor/browser-es-module-loader/dist/browser-es-module-loader.js";

View File

@ -49,9 +49,10 @@ function enableUI() {
frames = VNC_frame_data;
// Only present in older recordings
if (window.VNC_frame_encoding)
if (window.VNC_frame_encoding) {
encoding = VNC_frame_encoding;
}
}
class IterationPlayer {
constructor(iterations, frames, encoding) {

View File

@ -422,7 +422,7 @@ describe('Display/Canvas Helper', function () {
});
it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () {
const img = { complete: false, addEventListener: sinon.spy() }
const img = { complete: false, addEventListener: sinon.spy() };
display._renderQ = [{ type: 'img', x: 3, y: 4, img: img },
{ type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5 }];
display.drawImage = sinon.spy();

View File

@ -195,7 +195,7 @@ describe('Websock', function() {
it('should actually send on the websocket', function () {
sock._websocket.bufferedAmount = 8;
sock._websocket.readyState = WebSocket.OPEN
sock._websocket.readyState = WebSocket.OPEN;
sock._sQ = new Uint8Array([1, 2, 3]);
sock._sQlen = 3;
const encoded = sock._encode_message();

View File

@ -43,7 +43,7 @@ no_copy_files.forEach(file => no_transform_files.add(file));
// util.promisify requires Node.js 8.x, so we have our own
function promisify(original) {
return function () {
return function promise_wrap() {
const args = Array.prototype.slice.call(arguments);
return new Promise((resolve, reject) => {
original.apply(this, args.concat((err, value) => {
@ -51,7 +51,7 @@ function promisify(original) {
resolve(value);
}));
});
}
};
}
const readFile = promisify(fs.readFile);
@ -199,7 +199,7 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
.then(() => {
console.log(`Writing ${out_path}`);
return copy(filename, out_path);
})
});
})
.then(() => ensureDir(path.dirname(legacy_path)))
.then(() => {

View File

@ -4,7 +4,7 @@ const path = require('path');
// util.promisify requires Node.js 8.x, so we have our own
function promisify(original) {
return function () {
return function promise_wrap() {
const args = Array.prototype.slice.call(arguments);
return new Promise((resolve, reject) => {
original.apply(this, args.concat((err, value) => {
@ -12,7 +12,7 @@ function promisify(original) {
resolve(value);
}));
});
}
};
}
const writeFile = promisify(fs.writeFile);
@ -27,7 +27,7 @@ module.exports = {
.then(() => {
console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
const require_path = path.relative(base_out_path,
path.join(script_base_path, 'require.js'))
path.join(script_base_path, 'require.js'));
return [ require_path ];
});
},
@ -57,9 +57,9 @@ module.exports = {
console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
// FIXME: Should probably be in the legacy directory
const promise_path = path.relative(base_out_path,
path.join(base_out_path, 'vendor', 'promise.js'))
path.join(base_out_path, 'vendor', 'promise.js'));
const systemjs_path = path.relative(base_out_path,
path.join(script_base_path, 'system-production.js'))
path.join(script_base_path, 'system-production.js'));
return [ promise_path, systemjs_path ];
});
},
@ -73,4 +73,4 @@ module.exports = {
opts.plugins.unshift("add-module-exports");
},
},
}
};