@abaplint/runtime 2.13.53 → 2.13.55

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.
@@ -3,10 +3,12 @@ export type ABAPEventReference = {
3
3
  EVENT_NAME: string;
4
4
  EVENT_CLASS: string;
5
5
  };
6
- type HandlerMethod = (parameters?: any) => Promise<void>;
6
+ export type HandlerMethod = {
7
+ method: (parameters?: any) => Promise<void>;
8
+ receiver: object;
9
+ };
7
10
  export declare class ABAPEventing {
8
11
  private readonly registrations;
9
12
  setHandler(event: ABAPEventReference, methods: HandlerMethod[], forObject: ABAPObject | "ALL", activation: boolean): any;
10
13
  raiseEvent(event: ABAPEventReference, me: ABAPObject, parameters: object): Promise<void>;
11
14
  }
12
- export {};
@@ -13,21 +13,27 @@ class ABAPEventing {
13
13
  if (!this.registrations[event.EVENT_CLASS][event.EVENT_NAME]) {
14
14
  this.registrations[event.EVENT_CLASS][event.EVENT_NAME] = [];
15
15
  }
16
- const ref = forObject === "ALL" ? "ALL" : new WeakRef(forObject);
16
+ const target = forObject === "ALL" ? "ALL" : forObject.get();
17
17
  const handlers = this.registrations[event.EVENT_CLASS][event.EVENT_NAME];
18
18
  if (activation === true) {
19
19
  // todo: tackle duplicates
20
20
  handlers.push({
21
21
  handlers: methods,
22
- forObject: ref,
22
+ forObject: target === "ALL" ? "ALL" : new WeakRef(target),
23
23
  });
24
24
  }
25
25
  else {
26
26
  if (methods.length > 1) {
27
27
  throw new Error("ABAPEventing.setHandler: deactivation of multiple methods not supported, todo");
28
28
  }
29
- // todo: comparing the functions via toString might give the wrong result
30
- const index = handlers.findIndex(handler => handler.forObject === ref && handler.handlers[0].toString() === methods[0].toString());
29
+ const index = handlers.findIndex(handler => {
30
+ const sameObject = handler.forObject === "ALL"
31
+ ? target === "ALL"
32
+ : target !== "ALL" && handler.forObject.deref() === target;
33
+ const sameMethod = handler.handlers[0].method === methods[0].method
34
+ && handler.handlers[0].receiver === methods[0].receiver;
35
+ return sameObject && sameMethod;
36
+ });
31
37
  if (index !== -1) {
32
38
  handlers.splice(index, 1);
33
39
  }
@@ -42,12 +48,12 @@ class ABAPEventing {
42
48
  for (const handler of handlers) {
43
49
  if (handler.forObject === "ALL") {
44
50
  for (const method of handler.handlers) {
45
- await method(parameters);
51
+ await method.method.call(method.receiver, parameters);
46
52
  }
47
53
  }
48
- else if (handler.forObject.deref() === me) {
54
+ else if (handler.forObject.deref() === me.get()) {
49
55
  for (const method of handler.handlers) {
50
- await method(parameters);
56
+ await method.method.call(method.receiver, parameters);
51
57
  }
52
58
  }
53
59
  }
@@ -1,4 +1,4 @@
1
- import { ABAPEventReference } from "../abap_eventing";
1
+ import { ABAPEventReference, HandlerMethod } from "../abap_eventing";
2
2
  import { ABAPObject, FieldSymbol } from "../types";
3
3
  import { ICharacter } from "../types/_character";
4
- export declare function setHandler(eventReference: ABAPEventReference, methods: any[], forObject: ABAPObject | FieldSymbol, activation?: ICharacter): void;
4
+ export declare function setHandler(eventReference: ABAPEventReference, methods: HandlerMethod[], forObject: ABAPObject | FieldSymbol, activation?: ICharacter): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.13.53",
3
+ "version": "2.13.55",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",