]> git.proxmox.com Git - mirror_novnc.git/blame - core/util/polyfill.js
Use fat arrow functions `const foo = () => { ... };` for callbacks
[mirror_novnc.git] / core / util / polyfill.js
CommitLineData
e89eef94
PO
1/*
2 * noVNC: HTML5 VNC client
3 * Copyright 2017 Pierre Ossman for noVNC
4 * Licensed under MPL 2.0 or any later version (see LICENSE.txt)
5 */
6
7/* Polyfills to provide new APIs in old browsers */
8
9/* Object.assign() (taken from MDN) */
10if (typeof Object.assign != 'function') {
11 // Must be writable: true, enumerable: false, configurable: true
12 Object.defineProperty(Object, "assign", {
13 value: function assign(target, varArgs) { // .length of function is 2
14 'use strict';
15 if (target == null) { // TypeError if undefined or null
16 throw new TypeError('Cannot convert undefined or null to object');
17 }
18
2b5f94fa 19 const to = Object(target);
e89eef94 20
2b5f94fa
JD
21 for (let index = 1; index < arguments.length; index++) {
22 const nextSource = arguments[index];
e89eef94
PO
23
24 if (nextSource != null) { // Skip over if undefined or null
2b5f94fa 25 for (let nextKey in nextSource) {
e89eef94
PO
26 // Avoid bugs when hasOwnProperty is shadowed
27 if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
28 to[nextKey] = nextSource[nextKey];
29 }
30 }
31 }
32 }
33 return to;
34 },
35 writable: true,
36 configurable: true
37 });
38}
39
40/* CustomEvent constructor (taken from MDN) */
651c23ec
JD
41(() => {
42 function CustomEvent (event, params) {
e89eef94 43 params = params || { bubbles: false, cancelable: false, detail: undefined };
2b5f94fa 44 const evt = document.createEvent( 'CustomEvent' );
e89eef94
PO
45 evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
46 return evt;
47 }
48
49 CustomEvent.prototype = window.Event.prototype;
50
51 if (typeof window.CustomEvent !== "function") {
52 window.CustomEvent = CustomEvent;
53 }
54})();