Skip to content

Instantly share code, notes, and snippets.

@jow-
Created November 22, 2019 18:43
Show Gist options
  • Save jow-/1c6b195f98e6db8c08b35388351f095b to your computer and use it in GitHub Desktop.
Save jow-/1c6b195f98e6db8c08b35388351f095b to your computer and use it in GitHub Desktop.
Fixing concurrent super() calls
diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js
index 7c1831376..3433da396 100644
--- a/modules/luci-base/htdocs/luci-static/resources/luci.js
+++ b/modules/luci-base/htdocs/luci-static/resources/luci.js
@@ -67,7 +67,7 @@
* It provides simple means to create subclasses of given classes and
* implements prototypal inheritance.
*/
- var superContext = null, Class = Object.assign(function() {}, {
+ var superContext = {}, Class = Object.assign(function() {}, {
/**
* Extends this base class with the properties described in
* `properties` and returns a new subclassed Class instance
@@ -265,19 +265,26 @@
* superclass method returned `null`.
*/
super: function(key, callArgs) {
- for (superContext = Object.getPrototypeOf(superContext ||
+ if (key == null)
+ return null;
+
+ for (superContext[key] = Object.getPrototypeOf(superContext[key] ||
Object.getPrototypeOf(this));
- superContext && !superContext.hasOwnProperty(key);
- superContext = Object.getPrototypeOf(superContext)) { }
+ superContext[key] && !superContext[key].hasOwnProperty(key);
+ superContext[key] = Object.getPrototypeOf(superContext[key])) {}
- if (!superContext)
+ if (!superContext[key]) {
+ delete superContext[key];
return null;
+ }
- var res = superContext[key];
+ var res = superContext[key][key];
if (arguments.length > 1) {
- if (typeof(res) != 'function')
+ if (typeof(res) != 'function') {
+ delete superContext[key];
throw new ReferenceError(key + ' is not a function in base class');
+ }
if (typeof(callArgs) != 'object')
callArgs = this.varargs(arguments, 1);
@@ -285,8 +292,7 @@
res = res.apply(this, callArgs);
}
- superContext = null;
-
+ delete superContext[key];
return res;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment