]> git.proxmox.com Git - mirror_novnc.git/blob - core/util/polyfill.js
Use fat arrow functions `const foo = () => { ... };` for callbacks
[mirror_novnc.git] / core / util / polyfill.js
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) */
10 if (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
19 const to = Object(target);
20
21 for (let index = 1; index < arguments.length; index++) {
22 const nextSource = arguments[index];
23
24 if (nextSource != null) { // Skip over if undefined or null
25 for (let nextKey in nextSource) {
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) */
41 (() => {
42 function CustomEvent (event, params) {
43 params = params || { bubbles: false, cancelable: false, detail: undefined };
44 const evt = document.createEvent( 'CustomEvent' );
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 })();