235 lines
7.2 KiB
JavaScript
235 lines
7.2 KiB
JavaScript
// Metro module 40 (f41).
|
|
import _classCallCheck from "./_classCallCheck";
|
|
import _createClass from "./_createClass";
|
|
import { counterEvent, beginEvent, endEvent } from "./Module46";
|
|
import * as _Module47 from "./Module47";
|
|
import * as _stringifySafe from "./stringifySafe";
|
|
let env48 = {};
|
|
const MessageQueue = function MessageQueue() {
|
|
_classCallCheck(this, MessageQueue);
|
|
this._lazyCallableModules = {};
|
|
this._queue = [[], [], [], 0];
|
|
this._successCallbacks = new Map();
|
|
this._failureCallbacks = new Map();
|
|
this._callID = 0;
|
|
this._lastFlush = 0;
|
|
this._eventLoopStartTime = Date.now();
|
|
this._reactNativeMicrotasksCallback = null;
|
|
this.callFunctionReturnFlushedQueue = this.callFunctionReturnFlushedQueue.bind(this);
|
|
this.flushedQueue = this.flushedQueue.bind(this);
|
|
this.invokeCallbackAndReturnFlushedQueue = this.invokeCallbackAndReturnFlushedQueue.bind(this);
|
|
};
|
|
export default _createClass(MessageQueue, [{
|
|
key: "callFunctionReturnFlushedQueue",
|
|
value: function callFunctionReturnFlushedQueue(c23559_1, c23559_2, c23559_0) {
|
|
this.__guard(() => {
|
|
this.__callFunction(c23559_1, c23559_2, c23559_0);
|
|
});
|
|
return this.flushedQueue();
|
|
}
|
|
}, {
|
|
key: "invokeCallbackAndReturnFlushedQueue",
|
|
value: function invokeCallbackAndReturnFlushedQueue(c23560_1, c23560_0) {
|
|
this.__guard(() => {
|
|
this.__invokeCallback(c23560_1, c23560_0);
|
|
});
|
|
return this.flushedQueue();
|
|
}
|
|
}, {
|
|
key: "flushedQueue",
|
|
value: function flushedQueue() {
|
|
this.__guard(() => {
|
|
this.__callReactNativeMicrotasks();
|
|
});
|
|
const _queue = this._queue;
|
|
this._queue = [[], [], [], this._callID];
|
|
return _queue[0].length ? _queue : null;
|
|
}
|
|
}, {
|
|
key: "getEventLoopRunningTime",
|
|
value: function getEventLoopRunningTime() {
|
|
return Date.now() - this._eventLoopStartTime;
|
|
}
|
|
}, {
|
|
key: "registerCallableModule",
|
|
value: function registerCallableModule(a0, c23562_0) {
|
|
this._lazyCallableModules[a0] = () => c23562_0;
|
|
}
|
|
}, {
|
|
key: "registerLazyCallableModule",
|
|
value: function registerLazyCallableModule(a0, c23563_1) {
|
|
let c23563_0;
|
|
this._lazyCallableModules[a0] = () => {
|
|
const r2 = c23563_1;
|
|
if (r2) {
|
|
c23563_0 = r2();
|
|
c23563_1 = null;
|
|
}
|
|
return c23563_0;
|
|
};
|
|
}
|
|
}, {
|
|
key: "getCallableModule",
|
|
value: function getCallableModule(a0) {
|
|
const r4 = this._lazyCallableModules[a0];
|
|
return r4 ? r4() : null;
|
|
}
|
|
}, {
|
|
key: "callNativeSyncHook",
|
|
value: function callNativeSyncHook(a0, a1, a2, a3, a4) {
|
|
this.processCallbacks(a0, a1, a2, a3, a4);
|
|
return global.nativeCallSyncHook(a0, a1, a2);
|
|
}
|
|
}, {
|
|
key: "processCallbacks",
|
|
value: function processCallbacks(a0, a1, a2, a3, a4) {
|
|
if (a3 ? a3 : a4) {
|
|
if (a3) {
|
|
a2.push(this._callID << 1);
|
|
}
|
|
if (a4) {
|
|
a2.push(this._callID << 1 | 1);
|
|
}
|
|
this._successCallbacks.set(this._callID, a4);
|
|
this._failureCallbacks.set(this._callID, a3);
|
|
}
|
|
this._callID = this._callID + 1;
|
|
}
|
|
}, {
|
|
key: "enqueueNativeCall",
|
|
value: function enqueueNativeCall(a0, a1, a2, a3, a4) {
|
|
this.processCallbacks(a0, a1, a2, a3, a4);
|
|
this._queue[0].push(a0);
|
|
this._queue[1].push(a1);
|
|
this._queue[2].push(a2);
|
|
const _lastFlush = Date.now();
|
|
if (global.nativeFlushQueueImmediate && _lastFlush - this._lastFlush >= 5) {
|
|
const _queue = this._queue;
|
|
this._queue = [[], [], [], this._callID];
|
|
this._lastFlush = _lastFlush;
|
|
global.nativeFlushQueueImmediate(_queue);
|
|
}
|
|
counterEvent("pending_js_to_native_queue", this._queue[0].length);
|
|
if (this.__spy) {
|
|
this.__spy({
|
|
type: 1,
|
|
module: "" + a0,
|
|
method: a1,
|
|
args: a2
|
|
});
|
|
}
|
|
}
|
|
}, {
|
|
key: "createDebugLookup",
|
|
value: function createDebugLookup(a0, a1, a2) {}
|
|
}, {
|
|
key: "setReactNativeMicrotasksCallback",
|
|
value: function setReactNativeMicrotasksCallback(a0) {
|
|
this._reactNativeMicrotasksCallback = a0;
|
|
}
|
|
}, {
|
|
key: "__guard",
|
|
value: function __guard(a0) {
|
|
if (this.__shouldPauseOnThrow()) {
|
|
a0();
|
|
} else {
|
|
try {
|
|
a0();
|
|
} catch ($e) {
|
|
_Module47.default.reportFatalError($e);
|
|
}
|
|
}
|
|
}
|
|
}, {
|
|
key: "__shouldPauseOnThrow",
|
|
value: function __shouldPauseOnThrow() {
|
|
const DebuggerInternal2 = globalThis.DebuggerInternal;
|
|
return typeof DebuggerInternal2 !== "undefined" ? DebuggerInternal.shouldPauseOnThrow === true : typeof DebuggerInternal2 !== "undefined";
|
|
}
|
|
}, {
|
|
key: "__callReactNativeMicrotasks",
|
|
value: function __callReactNativeMicrotasks() {
|
|
beginEvent("JSTimers.callReactNativeMicrotasks()");
|
|
try {
|
|
if (this._reactNativeMicrotasksCallback != null) {
|
|
this._reactNativeMicrotasksCallback();
|
|
}
|
|
} catch (r18) {
|
|
endEvent();
|
|
throw r18;
|
|
}
|
|
endEvent();
|
|
}
|
|
}, {
|
|
key: "__callFunction",
|
|
value: function __callFunction(a0, a1, a2) {
|
|
let r40, r41;
|
|
this._lastFlush = Date.now();
|
|
this._eventLoopStartTime = this._lastFlush;
|
|
if (this.__spy) {
|
|
beginEvent(`${a0}.${a1}(${_stringifySafe.default(a2)})`);
|
|
r40 = dependencyMap;
|
|
r41 = require;
|
|
} else {
|
|
beginEvent(`${a0}.${a1}(...)`);
|
|
r40 = dependencyMap;
|
|
r41 = require;
|
|
}
|
|
try {
|
|
if (this.__spy) {
|
|
this.__spy({
|
|
type: 0,
|
|
module: a0,
|
|
method: a1,
|
|
args: a2
|
|
});
|
|
}
|
|
const callableModule = this.getCallableModule(a0);
|
|
if (!callableModule) {
|
|
const r62 = Object.keys(this._lazyCallableModules);
|
|
const length = r62.length;
|
|
const r66 = r62.join(", ");
|
|
const r18 = global.RN$Bridgeless === true ? "true" : "false";
|
|
r41(r40[5])(false, `Failed to call into JavaScript module method ${a0}.${a1}(). Module has not been registered as callable. Bridgeless Mode: ${r18}. Registered callable JavaScript modules (n = ${length}): ${r66}.
|
|
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.`);
|
|
}
|
|
if (!callableModule[a1]) {
|
|
r41(r40[5])(false, `Failed to call into JavaScript module method ${a0}.${a1}(). Module exists, but the method is undefined.`);
|
|
}
|
|
callableModule[a1].apply(callableModule, a2);
|
|
} catch (r106) {
|
|
r41(r40[2]).endEvent();
|
|
throw r106;
|
|
}
|
|
r41(r40[2]).endEvent();
|
|
}
|
|
}, {
|
|
key: "__invokeCallback",
|
|
value: function __invokeCallback(a0, a1) {
|
|
this._lastFlush = Date.now();
|
|
this._eventLoopStartTime = this._lastFlush;
|
|
const r4 = a0 >>> 1;
|
|
const r16 = 1 & a0 ? this._successCallbacks.get(r4) : this._failureCallbacks.get(r4);
|
|
L6: {
|
|
try {
|
|
if (r16) {
|
|
this._successCallbacks.delete(r4);
|
|
this._failureCallbacks.delete(r4);
|
|
r16.apply(void 0, [...a1]);
|
|
break L6;
|
|
}
|
|
} catch ($e) {
|
|
throw $e;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
}], [{
|
|
key: "spy",
|
|
value: function spy(a0) {
|
|
MessageQueue.prototype.__spy = a0 === true ? (a0) => {
|
|
console.log((a0.type === 0 ? "N->JS" : "JS->N") + " : " + `${a0.module != null ? a0.module + "." : ""}${a0.method}` + `(${JSON.stringify(a0.args)})`);
|
|
} : a0 !== false ? a0 : null;
|
|
}
|
|
}]);
|