Validate scancode via accessor.
This commit is contained in:
@@ -5,20 +5,25 @@ class KeystrokeAction implements Serializable {
|
|||||||
private static firstValidScancode = 1;
|
private static firstValidScancode = 1;
|
||||||
private static lastValidScancode = 231;
|
private static lastValidScancode = 231;
|
||||||
|
|
||||||
scancode: number;
|
_scancode: number;
|
||||||
modifierMask: 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) {
|
static isScancodeValid(scancode) {
|
||||||
return KeystrokeAction.firstValidScancode <= scancode &&
|
return KeystrokeAction.firstValidScancode <= scancode &&
|
||||||
scancode <= KeystrokeAction.lastValidScancode;
|
scancode <= KeystrokeAction.lastValidScancode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static checkScancode(scancode) {
|
|
||||||
if (!KeystrokeAction.isScancodeValid(scancode)) {
|
|
||||||
throw 'Scancode ${scancode} is invalid';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fromJsObject(jsObject: any) {
|
fromJsObject(jsObject: any) {
|
||||||
this.scancode = jsObject.scancode;
|
this.scancode = jsObject.scancode;
|
||||||
this.modifierMask = jsObject.modifierMask;
|
this.modifierMask = jsObject.modifierMask;
|
||||||
@@ -33,7 +38,6 @@ class KeystrokeAction implements Serializable {
|
|||||||
|
|
||||||
fromBinary(buffer: UhkBuffer) {
|
fromBinary(buffer: UhkBuffer) {
|
||||||
this.scancode = buffer.readUInt8();
|
this.scancode = buffer.readUInt8();
|
||||||
KeystrokeAction.checkScancode(this.scancode);
|
|
||||||
this.modifierMask = buffer.readUInt8();
|
this.modifierMask = buffer.readUInt8();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"out": "serializeConfig.js"
|
"out": "serializeConfig.js",
|
||||||
|
"target": "es5"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"typings/main.d.ts",
|
"typings/main.d.ts",
|
||||||
|
|||||||
+2
-1
@@ -83,7 +83,8 @@
|
|||||||
"variable-name": [
|
"variable-name": [
|
||||||
true,
|
true,
|
||||||
"ban-keywords",
|
"ban-keywords",
|
||||||
"check-format"
|
"check-format",
|
||||||
|
"allow-leading-underscore"
|
||||||
],
|
],
|
||||||
"whitespace": [
|
"whitespace": [
|
||||||
true,
|
true,
|
||||||
|
|||||||
Reference in New Issue
Block a user