polyfill.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2018 The noVNC Authors
  4. * Licensed under MPL 2.0 or any later version (see LICENSE.txt)
  5. */
  6. /* Polyfills to provide new APIs in old browsers */
  7. /* Object.assign() (taken from MDN) */
  8. if (typeof Object.assign != 'function') {
  9. // Must be writable: true, enumerable: false, configurable: true
  10. Object.defineProperty(Object, "assign", {
  11. value: function assign(target, varArgs) { // .length of function is 2
  12. 'use strict';
  13. if (target == null) { // TypeError if undefined or null
  14. throw new TypeError('Cannot convert undefined or null to object');
  15. }
  16. const to = Object(target);
  17. for (let index = 1; index < arguments.length; index++) {
  18. const nextSource = arguments[index];
  19. if (nextSource != null) { // Skip over if undefined or null
  20. for (let nextKey in nextSource) {
  21. // Avoid bugs when hasOwnProperty is shadowed
  22. if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
  23. to[nextKey] = nextSource[nextKey];
  24. }
  25. }
  26. }
  27. }
  28. return to;
  29. },
  30. writable: true,
  31. configurable: true
  32. });
  33. }
  34. /* CustomEvent constructor (taken from MDN) */
  35. (() => {
  36. function CustomEvent(event, params) {
  37. params = params || { bubbles: false, cancelable: false, detail: undefined };
  38. const evt = document.createEvent( 'CustomEvent' );
  39. evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
  40. return evt;
  41. }
  42. CustomEvent.prototype = window.Event.prototype;
  43. if (typeof window.CustomEvent !== "function") {
  44. window.CustomEvent = CustomEvent;
  45. }
  46. })();