Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply isInheritanceFromInterface patch to kotlin.js
- Loading branch information
Showing
3 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...korge-gradle-plugin/src/main/resources/patches/isInheritanceFromInterface.kotlin.js.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function isInheritanceFromInterface(ctor, iface) { | ||
if (ctor === iface) | ||
return true; | ||
var metadata = ctor.$metadata$; | ||
if (metadata != null) { | ||
var interfaces = metadata.interfaces; | ||
for (var i = 0; i < interfaces.length; i++) { | ||
if (isInheritanceFromInterface(interfaces[i], iface)) { | ||
return true; | ||
} | ||
} | ||
} | ||
var superPrototype = ctor.prototype != null ? Object.getPrototypeOf(ctor.prototype) : null; | ||
var superConstructor = superPrototype != null ? superPrototype.constructor : null; | ||
return superConstructor != null && isInheritanceFromInterface(superConstructor, iface); | ||
} | ||
-------------------------------- | ||
function getAllInterfaces(ctor) { | ||
if (ctor.$metadata$ == null) ctor.$metadata$ = {}; | ||
var metadata = ctor.$metadata$; | ||
if (metadata._allInterfaces === undefined) { | ||
var allInterfaces = metadata._allInterfaces = []; | ||
|
||
allInterfaces.push(ctor); | ||
|
||
var interfaces = metadata.interfaces; | ||
if (interfaces !== undefined) { | ||
for (var i = 0; i < interfaces.length; i++) { | ||
allInterfaces.push.apply(allInterfaces, getAllInterfaces(interfaces[i])); | ||
} | ||
} | ||
|
||
var superPrototype = ctor.prototype != null ? Object.getPrototypeOf(ctor.prototype) : null; | ||
var superConstructor = superPrototype != null ? superPrototype.constructor : null; | ||
if (superConstructor != null) { | ||
allInterfaces.push.apply(allInterfaces, getAllInterfaces(superConstructor)); | ||
} | ||
// @TODO: faster duplicate removal | ||
metadata._allInterfaces = metadata._allInterfaces.filter(function(item, pos, self) { return self.indexOf(item) === pos; }); | ||
} | ||
return metadata._allInterfaces; | ||
} | ||
|
||
function isInheritanceFromInterface(ctor, iface) { | ||
if (ctor === iface) return true; | ||
return getAllInterfaces(ctor).indexOf(iface) >= 0; | ||
} |