jsdom-se
Version:
jsdom fork for silent errors - A JavaScript implementation of the DOM and HTML standards
209 lines (184 loc) • 5.43 kB
JavaScript
;
const conversions = require("webidl-conversions");
const utils = require("../events/utils.js");
const Impl = require(".//Users/diego/Projects/diego/jsdom-se/lib/jsdom/living/events/KeyboardEvent-impl.js");
const UIEvent = require("./UIEvent.js");
const impl = utils.implSymbols["KeyboardEvent"];
function KeyboardEvent(typeArg) {
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'KeyboardEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
module.exports.setup(this, args);
}
KeyboardEvent.prototype.getModifierState = function getModifierState(keyArg) {
if (!this || !this[impl] || !(this instanceof KeyboardEvent)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'getModifierState' on 'KeyboardEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 1; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
return this[impl].getModifierState.apply(this[impl], args);
};
KeyboardEvent.prototype.initKeyboardEvent = function initKeyboardEvent(typeArg, bubblesArg, cancelableArg, viewArg, keyArg, locationArg, modifiersListArg, repeat, locale) {
if (!this || !this[impl] || !(this instanceof KeyboardEvent)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 9) {
throw new TypeError("Failed to execute 'initKeyboardEvent' on 'KeyboardEvent': 9 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 9; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
args[4] = conversions["DOMString"](args[4]);
args[5] = conversions["unsigned long"](args[5]);
args[6] = conversions["DOMString"](args[6]);
args[7] = conversions["boolean"](args[7]);
args[8] = conversions["DOMString"](args[8]);
return this[impl].initKeyboardEvent.apply(this[impl], args);
};
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_STANDARD", {
value: 0,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_STANDARD", {
value: 0,
enumerable: true
});
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_LEFT", {
value: 1,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_LEFT", {
value: 1,
enumerable: true
});
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_RIGHT", {
value: 2,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_RIGHT", {
value: 2,
enumerable: true
});
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_NUMPAD", {
value: 3,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_NUMPAD", {
value: 3,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "key", {
get() {
return this[impl].key
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "code", {
get() {
return this[impl].code
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "location", {
get() {
return this[impl].location
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "ctrlKey", {
get() {
return this[impl].ctrlKey
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "shiftKey", {
get() {
return this[impl].shiftKey
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "altKey", {
get() {
return this[impl].altKey
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "metaKey", {
get() {
return this[impl].metaKey
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "repeat", {
get() {
return this[impl].repeat
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "isComposing", {
get() {
return this[impl].isComposing
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "charCode", {
get() {
return this[impl].charCode
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "keyCode", {
get() {
return this[impl].keyCode
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "which", {
get() {
return this[impl].which
},
enumerable: true,
configurable: true
});
module.exports = {
create(constructorArgs, privateData) {
let obj = Object.create(KeyboardEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
UIEvent.setup(obj, constructorArgs, privateData);
},
interface: KeyboardEvent,
expose: {
Window: { KeyboardEvent: KeyboardEvent }
}
};