]> git.proxmox.com Git - mirror_novnc.git/blobdiff - vendor/browser-es-module-loader/src/browser-es-module-loader.js
Avoid nested function declarations
[mirror_novnc.git] / vendor / browser-es-module-loader / src / browser-es-module-loader.js
index dc7d0853bb528b97c18ca68da29544fea120588c..a0c189e963ba7cfe90ed0edc23fe52e2705c8d92 100644 (file)
@@ -9,7 +9,7 @@ var loader;
 // <script type="module"> support
 var anonSources = {};
 if (typeof document != 'undefined' && document.getElementsByTagName) {
-  function handleError(err) {
+  var handleError = function(err) {
     // dispatch an error event so that we can display in errors in browsers
     // that don't yet support unhandledrejection
     if (window.onunhandledrejection === undefined) {
@@ -37,7 +37,7 @@ if (typeof document != 'undefined' && document.getElementsByTagName) {
     throw err;
   }
 
-  function ready() {
+  var ready = function() {
     document.removeEventListener('DOMContentLoaded', ready, false );
 
     var anonCnt = 0;
@@ -103,10 +103,10 @@ BrowserESModuleLoader.prototype[RegisterLoader.resolve] = function(key, parent)
 
 function xhrFetch(url, resolve, reject) {
   var xhr = new XMLHttpRequest();
-  function load(source) {
+  var load = function(source) {
     resolve(xhr.responseText);
   }
-  function error() {
+  var error = function() {
     reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText  : '') + ')' : '') + ' loading ' + url));
   }
 
@@ -231,12 +231,12 @@ BrowserESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, proc
   })
   .then(function(source) {
     // check our cache first
-    const cacheEntryTrans = localStorage.getItem(key+'!transpiled');
-    if (cacheEntryTrans) {
-      const cacheEntryRaw = localStorage.getItem(key+'!raw');
+    var cacheEntry = localStorage.getItem(key);
+    if (cacheEntry) {
+      cacheEntry = JSON.parse(cacheEntry);
       // TODO: store a hash instead
-      if (cacheEntryRaw === source) {
-        return Promise.resolve({key: key, code: cacheEntryTrans, source: source});
+      if (cacheEntry.source === source) {
+        return Promise.resolve({key: key, code: cacheEntry.code, source: cacheEntry.source});
       }
     }
     return new Promise(function (resolve, reject) {
@@ -247,8 +247,8 @@ BrowserESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, proc
     // evaluate without require, exports and module variables
     // we leave module in for now to allow module.require access
     try {
-      localStorage.setItem(key+'!raw', data.source);
-      localStorage.setItem(data.key+'!transpiled', data.code);
+      var cacheEntry = JSON.stringify({source: data.source, code: data.code});
+      localStorage.setItem(key, cacheEntry);
     } catch (e) {
       if (window.console) {
         window.console.warn('Unable to cache transpiled version of ' + key + ': ' + e);