From 32646f36168307d4488e5a624f17cb8d4c4171fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Fri, 25 Mar 2016 21:53:30 +0100 Subject: [PATCH] Validate scancode via accessor. --- model/KeystrokeAction.ts | 20 ++++++++++++-------- model/tsconfig.json | 3 ++- model/tslint.json | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/model/KeystrokeAction.ts b/model/KeystrokeAction.ts index 1d55fd7a..87da0e9b 100644 --- a/model/KeystrokeAction.ts +++ b/model/KeystrokeAction.ts @@ -5,20 +5,25 @@ class KeystrokeAction implements Serializable { private static firstValidScancode = 1; private static lastValidScancode = 231; - scancode: number; + _scancode: number; modifierMask: number; + get scancode() { + return this._scancode; + } + + set scancode(value) { + if (!KeystrokeAction.isScancodeValid(value)) { + throw 'Scancode ${scancode} is invalid!'; + } + this._scancode = value; + } + static isScancodeValid(scancode) { return KeystrokeAction.firstValidScancode <= scancode && scancode <= KeystrokeAction.lastValidScancode; } - private static checkScancode(scancode) { - if (!KeystrokeAction.isScancodeValid(scancode)) { - throw 'Scancode ${scancode} is invalid'; - } - } - fromJsObject(jsObject: any) { this.scancode = jsObject.scancode; this.modifierMask = jsObject.modifierMask; @@ -33,7 +38,6 @@ class KeystrokeAction implements Serializable { fromBinary(buffer: UhkBuffer) { this.scancode = buffer.readUInt8(); - KeystrokeAction.checkScancode(this.scancode); this.modifierMask = buffer.readUInt8(); } diff --git a/model/tsconfig.json b/model/tsconfig.json index 668b733a..d7bd2173 100644 --- a/model/tsconfig.json +++ b/model/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { - "out": "serializeConfig.js" + "out": "serializeConfig.js", + "target": "es5" }, "files": [ "typings/main.d.ts", diff --git a/model/tslint.json b/model/tslint.json index c008a8b7..1a65cc37 100644 --- a/model/tslint.json +++ b/model/tslint.json @@ -83,7 +83,8 @@ "variable-name": [ true, "ban-keywords", - "check-format" + "check-format", + "allow-leading-underscore" ], "whitespace": [ true,