Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 21ce62e

Browse files
danielkweonchase
andauthored
Backport index.js and shared.d.ts fixes (#103)
* backport index.js and shared.d.ts fixes * bump version to 2.2 * Revert VERSION Don't need a version bump, only needed for next time * Update shared.d.ts --------- Co-authored-by: Chase Colman <[email protected]>
1 parent f245caf commit 21ce62e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

libreoffice-core/desktop/wasm/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type CallbackHandlers = {
9292
const subscribedEvents: { [K: number]: CallbackHandlers } = {};
9393
const subscribedPaint: Map<number, Set<() => any>> = new Map();
9494
const subscribedIdle: Map<number, Set<() => any>> = new Map();
95+
const subscribedUncaughtError: Set<() => any> = new Set();
9596

9697
type IdleMessage = { f: 'idle_'; d: DocumentRef };
9798
type PaintMesasge = { f: 'paint_'; d: DocumentRef };
@@ -135,6 +136,10 @@ function messageIsKeys<K extends keyof Message = keyof Message>(
135136
return data.f === '_keys';
136137
}
137138

139+
function messageIsUncaughtError(data) {
140+
return data.uncaughtError === true;
141+
}
142+
138143
const clientBase: DocumentClientBase = {
139144
ref: -1,
140145
viewId: -1,
@@ -201,6 +206,12 @@ const clientBase: DocumentClientBase = {
201206
handlers.delete(callback);
202207
};
203208
},
209+
afterUncaughtError: function (callback) {
210+
subscribedUncaughtError.add(callback);
211+
return () => {
212+
subscribedUncaughtError.delete(callback);
213+
};
214+
},
204215
};
205216

206217
type ForwardedBase = {
@@ -299,6 +310,11 @@ async function handleMessage<K extends keyof Message = keyof Message>({
299310
cb();
300311
}
301312
}
313+
} else if (messageIsUncaughtError(data)) {
314+
console.log('handling uncaught error');
315+
for (const cb of subscribedUncaughtError) {
316+
cb();
317+
}
302318
} else if (data.i !== UNUSED_ID) {
303319
callIdToFuture[data.i].resolve(data.r);
304320
callIdToFuture[data.i] = undefined;

libreoffice-core/desktop/wasm/shared.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ export type DocumentClientBase = {
340340
afterIdle(callback: () => any): () => void;
341341
/** !!!USE SPARINGLY: Impacts performance!!! Calls the callback, returns the method to unregister the callback */
342342
afterPaint(callback: () => any): () => void;
343+
afterUncaughtError(callback: () => any): () => void;
343344
};
344345

345346
export type AsyncFunctions<T extends { [K: string]: (...args: any) => any }> = {

0 commit comments

Comments
 (0)