MCPcopy
hub / github.com/opentrace/opentrace / expose2

Function expose2

ui/public/lbug_wasm_worker.js:438–488  ·  view source on GitHub ↗
(exposed)

Source from the content-addressed store, hash-verified

436 });
437 }
438 function expose2(exposed) {
439 if (!implementation_1.default.isWorkerRuntime()) {
440 throw Error('expose() called in the master thread.');
441 }
442 if (exposeCalled) {
443 throw Error(
444 'expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.',
445 );
446 }
447 exposeCalled = true;
448 if (typeof exposed === 'function') {
449 implementation_1.default.subscribeToMasterMessages((messageData) => {
450 if (isMasterJobRunMessage(messageData) && !messageData.method) {
451 runFunction(
452 messageData.uid,
453 exposed,
454 messageData.args.map(common_1.deserialize),
455 );
456 }
457 });
458 postFunctionInitMessage();
459 } else if (typeof exposed === 'object' && exposed) {
460 implementation_1.default.subscribeToMasterMessages((messageData) => {
461 if (isMasterJobRunMessage(messageData) && messageData.method) {
462 runFunction(
463 messageData.uid,
464 exposed[messageData.method],
465 messageData.args.map(common_1.deserialize),
466 );
467 }
468 });
469 const methodNames = Object.keys(exposed).filter(
470 (key) => typeof exposed[key] === 'function',
471 );
472 postModuleInitMessage(methodNames);
473 } else {
474 throw Error(
475 `Invalid argument passed to expose(). Expected a function or an object, got: ${exposed}`,
476 );
477 }
478 implementation_1.default.subscribeToMasterMessages((messageData) => {
479 if (isMasterJobCancelMessage(messageData)) {
480 const jobUID = messageData.uid;
481 const subscription = activeSubscriptions.get(jobUID);
482 if (subscription) {
483 subscription.unsubscribe();
484 activeSubscriptions.delete(jobUID);
485 }
486 }
487 });
488 }
489 exports.expose = expose2;
490 if (
491 typeof self !== 'undefined' &&

Callers

nothing calls this directly

Calls 7

isMasterJobRunMessageFunction · 0.85
runFunctionFunction · 0.85
postFunctionInitMessageFunction · 0.85
postModuleInitMessageFunction · 0.85
isMasterJobCancelMessageFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected