Merge pull request #11111 from Snuffleupagus/MessageHandler-resolveCall
Inline the `resolveCall` helper function at its call-sites in `MessageHandler`
This commit is contained in:
commit
71477dc5b1
@ -30,13 +30,6 @@ const StreamKind = {
|
|||||||
START_COMPLETE: 8,
|
START_COMPLETE: 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function resolveCall(fn, args) {
|
|
||||||
if (!fn) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return fn.apply(null, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
function wrapReason(reason) {
|
function wrapReason(reason) {
|
||||||
if (typeof reason !== 'object') {
|
if (typeof reason !== 'object') {
|
||||||
return reason;
|
return reason;
|
||||||
@ -100,9 +93,9 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|||||||
if (data.callbackId) {
|
if (data.callbackId) {
|
||||||
let sourceName = this.sourceName;
|
let sourceName = this.sourceName;
|
||||||
let targetName = data.sourceName;
|
let targetName = data.sourceName;
|
||||||
Promise.resolve().then(function() {
|
new Promise(function(resolve) {
|
||||||
return action(data.data);
|
resolve(action(data.data));
|
||||||
}).then((result) => {
|
}).then(function(result) {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -110,7 +103,7 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|||||||
callbackId: data.callbackId,
|
callbackId: data.callbackId,
|
||||||
data: result,
|
data: result,
|
||||||
});
|
});
|
||||||
}, (reason) => {
|
}, function(reason) {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -318,7 +311,9 @@ MessageHandler.prototype = {
|
|||||||
streamSink.sinkCapability.resolve();
|
streamSink.sinkCapability.resolve();
|
||||||
streamSink.ready = streamSink.sinkCapability.promise;
|
streamSink.ready = streamSink.sinkCapability.promise;
|
||||||
this.streamSinks[streamId] = streamSink;
|
this.streamSinks[streamId] = streamSink;
|
||||||
resolveCall(action, [data.data, streamSink]).then(() => {
|
new Promise(function(resolve) {
|
||||||
|
resolve(action(data.data, streamSink));
|
||||||
|
}).then(function() {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -326,7 +321,7 @@ MessageHandler.prototype = {
|
|||||||
streamId,
|
streamId,
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
}, (reason) => {
|
}, function(reason) {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -385,7 +380,10 @@ MessageHandler.prototype = {
|
|||||||
}
|
}
|
||||||
// Reset desiredSize property of sink on every pull.
|
// Reset desiredSize property of sink on every pull.
|
||||||
this.streamSinks[data.streamId].desiredSize = data.desiredSize;
|
this.streamSinks[data.streamId].desiredSize = data.desiredSize;
|
||||||
resolveCall(this.streamSinks[data.streamId].onPull).then(() => {
|
const { onPull, } = this.streamSinks[data.streamId];
|
||||||
|
new Promise(function(resolve) {
|
||||||
|
resolve(onPull && onPull());
|
||||||
|
}).then(function() {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -393,7 +391,7 @@ MessageHandler.prototype = {
|
|||||||
streamId,
|
streamId,
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
}, (reason) => {
|
}, function(reason) {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -435,8 +433,10 @@ MessageHandler.prototype = {
|
|||||||
if (!this.streamSinks[data.streamId]) {
|
if (!this.streamSinks[data.streamId]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
resolveCall(this.streamSinks[data.streamId].onCancel,
|
const { onCancel, } = this.streamSinks[data.streamId];
|
||||||
[wrapReason(data.reason)]).then(() => {
|
new Promise(function(resolve) {
|
||||||
|
resolve(onCancel && onCancel(wrapReason(data.reason)));
|
||||||
|
}).then(function() {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
@ -444,7 +444,7 @@ MessageHandler.prototype = {
|
|||||||
streamId,
|
streamId,
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
}, (reason) => {
|
}, function(reason) {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName,
|
sourceName,
|
||||||
targetName,
|
targetName,
|
||||||
|
Loading…
Reference in New Issue
Block a user