@abaplint/runtime 2.14.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/compare/instance_of.js +23 -17
- package/package.json +1 -1
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.instance_of = instance_of;
|
|
4
|
+
/** true when the class or interface is the target or a subtype of it:
|
|
5
|
+
* superclasses, implemented interfaces and interfaces they include */
|
|
6
|
+
function isSubtype(start, cname) {
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
const matches = (source) => {
|
|
9
|
+
if (source == null || seen.has(source)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
else if (source === cname) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
seen.add(source);
|
|
16
|
+
const internalName = source.INTERNAL_NAME || "";
|
|
17
|
+
const prefix = internalName.substring(0, internalName.lastIndexOf("-") + 1);
|
|
18
|
+
const interfaces = source.IMPLEMENTED_INTERFACES || [];
|
|
19
|
+
return interfaces.some(i => matches(abap.Classes[prefix + i] || abap.Classes[i]))
|
|
20
|
+
|| matches(Object.getPrototypeOf(source));
|
|
21
|
+
};
|
|
22
|
+
return matches(start);
|
|
23
|
+
}
|
|
4
24
|
function instance_of(val, cname) {
|
|
5
25
|
const obj = val.get();
|
|
6
26
|
if (obj === undefined) {
|
|
@@ -11,29 +31,15 @@ function instance_of(val, cname) {
|
|
|
11
31
|
else if (cname === "OBJECT") {
|
|
12
32
|
return true;
|
|
13
33
|
}
|
|
14
|
-
const seen = new Set();
|
|
15
|
-
const matches = (source) => {
|
|
16
|
-
if (source == null || seen.has(source)) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
else if (source === cname) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
seen.add(source);
|
|
23
|
-
const internalName = source.INTERNAL_NAME || "";
|
|
24
|
-
const prefix = internalName.substring(0, internalName.lastIndexOf("-") + 1);
|
|
25
|
-
const interfaces = source.IMPLEMENTED_INTERFACES || [];
|
|
26
|
-
return interfaces.some(i => matches(abap.Classes[prefix + i] || abap.Classes[i]))
|
|
27
|
-
|| matches(Object.getPrototypeOf(source));
|
|
28
|
-
};
|
|
29
34
|
// Local qualified names are short; RTTI carries the declaring program or class pool.
|
|
30
35
|
const scope = val.getRTTIName()?.toUpperCase().match(/^\\(PROGRAM|CLASS-POOL)=([^\\]+)/);
|
|
31
36
|
const prefix = scope ? (scope[1] === "PROGRAM" ? "PROG" : "CLAS") + "-" + scope[2] + "-" : "";
|
|
32
|
-
return
|
|
37
|
+
return isSubtype(abap.Classes[prefix + name] || abap.Classes[name], cname);
|
|
33
38
|
}
|
|
34
39
|
else if (cname === "OBJECT") {
|
|
35
40
|
return true;
|
|
36
41
|
}
|
|
37
|
-
|
|
42
|
+
// an interface is not on the prototype chain of the classes implementing it
|
|
43
|
+
return obj instanceof cname || isSubtype(obj.constructor, cname);
|
|
38
44
|
}
|
|
39
45
|
//# sourceMappingURL=instance_of.js.map
|