2018-06-04 19:37:54 +09:00
|
|
|
/* Copyright 2018 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
AbortException,
|
|
|
|
assert,
|
|
|
|
createPromiseCapability,
|
|
|
|
MissingPDFException,
|
2021-08-28 18:58:02 +09:00
|
|
|
PasswordException,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
UnexpectedResponseException,
|
|
|
|
UnknownErrorException,
|
2022-02-26 00:53:28 +09:00
|
|
|
unreachable,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./util.js";
|
2018-06-04 19:37:54 +09:00
|
|
|
|
2019-10-25 20:37:28 +09:00
|
|
|
const CallbackKind = {
|
|
|
|
UNKNOWN: 0,
|
|
|
|
DATA: 1,
|
|
|
|
ERROR: 2,
|
|
|
|
};
|
|
|
|
|
2019-08-30 20:26:39 +09:00
|
|
|
const StreamKind = {
|
|
|
|
UNKNOWN: 0,
|
|
|
|
CANCEL: 1,
|
|
|
|
CANCEL_COMPLETE: 2,
|
|
|
|
CLOSE: 3,
|
|
|
|
ENQUEUE: 4,
|
|
|
|
ERROR: 5,
|
|
|
|
PULL: 6,
|
|
|
|
PULL_COMPLETE: 7,
|
|
|
|
START_COMPLETE: 8,
|
|
|
|
};
|
|
|
|
|
2018-06-04 19:37:54 +09:00
|
|
|
function wrapReason(reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
2021-08-09 19:02:49 +09:00
|
|
|
!(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
reason instanceof Error ||
|
2021-08-09 19:02:49 +09:00
|
|
|
(typeof reason === "object" && reason !== null)
|
|
|
|
)
|
|
|
|
) {
|
2022-02-26 00:53:28 +09:00
|
|
|
unreachable(
|
|
|
|
'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
|
|
|
|
);
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
|
|
|
switch (reason.name) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "AbortException":
|
2018-06-04 19:37:54 +09:00
|
|
|
return new AbortException(reason.message);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "MissingPDFException":
|
2018-06-04 19:37:54 +09:00
|
|
|
return new MissingPDFException(reason.message);
|
2021-08-28 18:58:02 +09:00
|
|
|
case "PasswordException":
|
|
|
|
return new PasswordException(reason.message, reason.code);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UnexpectedResponseException":
|
2018-06-04 19:37:54 +09:00
|
|
|
return new UnexpectedResponseException(reason.message, reason.status);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UnknownErrorException":
|
2018-06-04 19:37:54 +09:00
|
|
|
return new UnknownErrorException(reason.message, reason.details);
|
2019-08-31 02:22:27 +09:00
|
|
|
default:
|
|
|
|
return new UnknownErrorException(reason.message, reason.toString());
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 06:05:25 +09:00
|
|
|
class MessageHandler {
|
|
|
|
constructor(sourceName, targetName, comObj) {
|
|
|
|
this.sourceName = sourceName;
|
|
|
|
this.targetName = targetName;
|
|
|
|
this.comObj = comObj;
|
|
|
|
this.callbackId = 1;
|
|
|
|
this.streamId = 1;
|
|
|
|
this.streamSinks = Object.create(null);
|
|
|
|
this.streamControllers = Object.create(null);
|
|
|
|
this.callbackCapabilities = Object.create(null);
|
|
|
|
this.actionHandler = Object.create(null);
|
2018-06-04 19:37:54 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._onComObjOnMessage = event => {
|
2019-10-31 06:05:25 +09:00
|
|
|
const data = event.data;
|
|
|
|
if (data.targetName !== this.sourceName) {
|
|
|
|
return;
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
2019-10-31 06:05:25 +09:00
|
|
|
if (data.stream) {
|
|
|
|
this._processStreamMessage(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data.callback) {
|
|
|
|
const callbackId = data.callbackId;
|
|
|
|
const capability = this.callbackCapabilities[callbackId];
|
|
|
|
if (!capability) {
|
|
|
|
throw new Error(`Cannot resolve callback ${callbackId}`);
|
|
|
|
}
|
|
|
|
delete this.callbackCapabilities[callbackId];
|
2019-10-30 20:12:50 +09:00
|
|
|
|
2019-10-31 06:05:25 +09:00
|
|
|
if (data.callback === CallbackKind.DATA) {
|
|
|
|
capability.resolve(data.data);
|
|
|
|
} else if (data.callback === CallbackKind.ERROR) {
|
|
|
|
capability.reject(wrapReason(data.reason));
|
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Unexpected callback case");
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
|
|
|
return;
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
2019-10-31 06:05:25 +09:00
|
|
|
const action = this.actionHandler[data.action];
|
|
|
|
if (!action) {
|
|
|
|
throw new Error(`Unknown action from worker: ${data.action}`);
|
|
|
|
}
|
|
|
|
if (data.callbackId) {
|
2020-03-25 17:42:50 +09:00
|
|
|
const cbSourceName = this.sourceName;
|
|
|
|
const cbTargetName = data.sourceName;
|
2021-09-21 18:21:43 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
new Promise(function (resolve) {
|
2019-10-31 06:05:25 +09:00
|
|
|
resolve(action(data.data));
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}).then(
|
2020-04-14 19:28:14 +09:00
|
|
|
function (result) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
2020-03-25 17:42:50 +09:00
|
|
|
sourceName: cbSourceName,
|
|
|
|
targetName: cbTargetName,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
callback: CallbackKind.DATA,
|
|
|
|
callbackId: data.callbackId,
|
|
|
|
data: result,
|
|
|
|
});
|
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
2020-03-25 17:42:50 +09:00
|
|
|
sourceName: cbSourceName,
|
|
|
|
targetName: cbTargetName,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
callback: CallbackKind.ERROR,
|
|
|
|
callbackId: data.callbackId,
|
|
|
|
reason: wrapReason(reason),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2019-10-31 06:05:25 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data.streamId) {
|
|
|
|
this._createStreamSink(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
action(data.data);
|
|
|
|
};
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.addEventListener("message", this._onComObjOnMessage);
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
|
2019-08-31 21:16:06 +09:00
|
|
|
on(actionName, handler) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
|
|
|
) {
|
|
|
|
assert(
|
|
|
|
typeof handler === "function",
|
|
|
|
'MessageHandler.on: Expected "handler" to be a function.'
|
|
|
|
);
|
2019-10-30 19:44:59 +09:00
|
|
|
}
|
|
|
|
const ah = this.actionHandler;
|
2018-06-04 19:37:54 +09:00
|
|
|
if (ah[actionName]) {
|
|
|
|
throw new Error(`There is already an actionName called "${actionName}"`);
|
|
|
|
}
|
2019-08-31 21:16:06 +09:00
|
|
|
ah[actionName] = handler;
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
|
|
|
|
2018-06-04 19:37:54 +09:00
|
|
|
/**
|
|
|
|
* Sends a message to the comObj to invoke the action with the supplied data.
|
2019-10-12 22:59:09 +09:00
|
|
|
* @param {string} actionName - Action to call.
|
2018-06-04 19:37:54 +09:00
|
|
|
* @param {JSON} data - JSON data to send.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
2018-06-04 19:37:54 +09:00
|
|
|
*/
|
|
|
|
send(actionName, data, transfers) {
|
2021-11-19 21:51:18 +09:00
|
|
|
this.comObj.postMessage(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
{
|
|
|
|
sourceName: this.sourceName,
|
|
|
|
targetName: this.targetName,
|
|
|
|
action: actionName,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
transfers
|
|
|
|
);
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
|
|
|
|
2018-06-04 19:37:54 +09:00
|
|
|
/**
|
|
|
|
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
|
|
* Expects that the other side will callback with the response.
|
2019-10-12 22:59:09 +09:00
|
|
|
* @param {string} actionName - Action to call.
|
2018-06-04 19:37:54 +09:00
|
|
|
* @param {JSON} data - JSON data to send.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
2018-06-04 19:37:54 +09:00
|
|
|
* @returns {Promise} Promise to be resolved with response data.
|
|
|
|
*/
|
|
|
|
sendWithPromise(actionName, data, transfers) {
|
2019-10-31 01:37:52 +09:00
|
|
|
const callbackId = this.callbackId++;
|
|
|
|
const capability = createPromiseCapability();
|
2019-10-30 19:44:59 +09:00
|
|
|
this.callbackCapabilities[callbackId] = capability;
|
2018-06-04 19:37:54 +09:00
|
|
|
try {
|
2021-11-19 21:51:18 +09:00
|
|
|
this.comObj.postMessage(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
{
|
|
|
|
sourceName: this.sourceName,
|
|
|
|
targetName: this.targetName,
|
|
|
|
action: actionName,
|
|
|
|
callbackId,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
transfers
|
|
|
|
);
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
} catch (ex) {
|
|
|
|
capability.reject(ex);
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
|
|
|
return capability.promise;
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
|
|
|
|
2018-06-04 19:37:54 +09:00
|
|
|
/**
|
|
|
|
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
|
|
* Expect that the other side will callback to signal 'start_complete'.
|
2019-10-12 22:59:09 +09:00
|
|
|
* @param {string} actionName - Action to call.
|
2018-06-04 19:37:54 +09:00
|
|
|
* @param {JSON} data - JSON data to send.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {Object} queueingStrategy - Strategy to signal backpressure based on
|
2018-06-04 19:37:54 +09:00
|
|
|
* internal queue.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
2019-10-13 01:14:29 +09:00
|
|
|
* @returns {ReadableStream} ReadableStream to read data in chunks.
|
2018-06-04 19:37:54 +09:00
|
|
|
*/
|
|
|
|
sendWithStream(actionName, data, queueingStrategy, transfers) {
|
2021-09-21 18:21:43 +09:00
|
|
|
const streamId = this.streamId++,
|
|
|
|
sourceName = this.sourceName,
|
|
|
|
targetName = this.targetName,
|
|
|
|
comObj = this.comObj;
|
2018-06-04 19:37:54 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return new ReadableStream(
|
|
|
|
{
|
|
|
|
start: controller => {
|
|
|
|
const startCapability = createPromiseCapability();
|
|
|
|
this.streamControllers[streamId] = {
|
|
|
|
controller,
|
|
|
|
startCall: startCapability,
|
|
|
|
pullCall: null,
|
|
|
|
cancelCall: null,
|
|
|
|
isClosed: false,
|
|
|
|
};
|
2021-11-19 21:51:18 +09:00
|
|
|
comObj.postMessage(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
{
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
action: actionName,
|
|
|
|
streamId,
|
|
|
|
data,
|
|
|
|
desiredSize: controller.desiredSize,
|
|
|
|
},
|
|
|
|
transfers
|
|
|
|
);
|
|
|
|
// Return Promise for Async process, to signal success/failure.
|
|
|
|
return startCapability.promise;
|
|
|
|
},
|
2018-06-04 19:37:54 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pull: controller => {
|
|
|
|
const pullCapability = createPromiseCapability();
|
|
|
|
this.streamControllers[streamId].pullCall = pullCapability;
|
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.PULL,
|
|
|
|
streamId,
|
|
|
|
desiredSize: controller.desiredSize,
|
|
|
|
});
|
|
|
|
// Returning Promise will not call "pull"
|
|
|
|
// again until current pull is resolved.
|
|
|
|
return pullCapability.promise;
|
|
|
|
},
|
2018-06-04 19:37:54 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
cancel: reason => {
|
|
|
|
assert(reason instanceof Error, "cancel must have a valid reason");
|
|
|
|
const cancelCapability = createPromiseCapability();
|
|
|
|
this.streamControllers[streamId].cancelCall = cancelCapability;
|
|
|
|
this.streamControllers[streamId].isClosed = true;
|
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.CANCEL,
|
|
|
|
streamId,
|
|
|
|
reason: wrapReason(reason),
|
|
|
|
});
|
|
|
|
// Return Promise to signal success or failure.
|
|
|
|
return cancelCapability.promise;
|
|
|
|
},
|
2018-06-04 19:37:54 +09:00
|
|
|
},
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
queueingStrategy
|
|
|
|
);
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
|
2019-10-31 06:05:25 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-06-04 19:37:54 +09:00
|
|
|
_createStreamSink(data) {
|
2021-09-21 18:21:43 +09:00
|
|
|
const streamId = data.streamId,
|
|
|
|
sourceName = this.sourceName,
|
|
|
|
targetName = data.sourceName,
|
|
|
|
comObj = this.comObj;
|
|
|
|
const self = this,
|
|
|
|
action = this.actionHandler[data.action];
|
2018-06-04 19:37:54 +09:00
|
|
|
|
2019-10-31 01:37:52 +09:00
|
|
|
const streamSink = {
|
2018-06-04 19:37:54 +09:00
|
|
|
enqueue(chunk, size = 1, transfers) {
|
|
|
|
if (this.isCancelled) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-31 01:37:52 +09:00
|
|
|
const lastDesiredSize = this.desiredSize;
|
2018-06-04 19:37:54 +09:00
|
|
|
this.desiredSize -= size;
|
|
|
|
// Enqueue decreases the desiredSize property of sink,
|
|
|
|
// so when it changes from positive to negative,
|
|
|
|
// set ready as unresolved promise.
|
|
|
|
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
|
|
|
this.sinkCapability = createPromiseCapability();
|
|
|
|
this.ready = this.sinkCapability.promise;
|
|
|
|
}
|
2021-11-19 21:51:18 +09:00
|
|
|
comObj.postMessage(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
{
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.ENQUEUE,
|
|
|
|
streamId,
|
|
|
|
chunk,
|
|
|
|
},
|
|
|
|
transfers
|
|
|
|
);
|
2018-06-04 19:37:54 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
close() {
|
|
|
|
if (this.isCancelled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isCancelled = true;
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
2019-08-30 20:26:39 +09:00
|
|
|
stream: StreamKind.CLOSE,
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
streamId,
|
|
|
|
});
|
2018-06-04 19:37:54 +09:00
|
|
|
delete self.streamSinks[streamId];
|
|
|
|
},
|
|
|
|
|
|
|
|
error(reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
assert(reason instanceof Error, "error must have a valid reason");
|
2018-06-04 19:37:54 +09:00
|
|
|
if (this.isCancelled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isCancelled = true;
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
2019-08-30 20:26:39 +09:00
|
|
|
stream: StreamKind.ERROR,
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
streamId,
|
2019-09-02 20:18:39 +09:00
|
|
|
reason: wrapReason(reason),
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
});
|
2018-06-04 19:37:54 +09:00
|
|
|
},
|
|
|
|
|
2019-10-31 01:37:52 +09:00
|
|
|
sinkCapability: createPromiseCapability(),
|
2018-06-04 19:37:54 +09:00
|
|
|
onPull: null,
|
|
|
|
onCancel: null,
|
|
|
|
isCancelled: false,
|
2019-10-31 01:37:52 +09:00
|
|
|
desiredSize: data.desiredSize,
|
2018-06-04 19:37:54 +09:00
|
|
|
ready: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
streamSink.sinkCapability.resolve();
|
|
|
|
streamSink.ready = streamSink.sinkCapability.promise;
|
|
|
|
this.streamSinks[streamId] = streamSink;
|
2021-09-21 18:21:43 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
new Promise(function (resolve) {
|
2019-09-01 19:25:31 +09:00
|
|
|
resolve(action(data.data, streamSink));
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}).then(
|
2020-04-14 19:28:14 +09:00
|
|
|
function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.START_COMPLETE,
|
|
|
|
streamId,
|
|
|
|
success: true,
|
|
|
|
});
|
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.START_COMPLETE,
|
|
|
|
streamId,
|
|
|
|
reason: wrapReason(reason),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
|
2019-10-31 06:05:25 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-06-04 19:37:54 +09:00
|
|
|
_processStreamMessage(data) {
|
2021-09-21 18:21:43 +09:00
|
|
|
const streamId = data.streamId,
|
|
|
|
sourceName = this.sourceName,
|
|
|
|
targetName = data.sourceName,
|
|
|
|
comObj = this.comObj;
|
|
|
|
const streamController = this.streamControllers[streamId],
|
|
|
|
streamSink = this.streamSinks[streamId];
|
2018-06-04 19:37:54 +09:00
|
|
|
|
|
|
|
switch (data.stream) {
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.START_COMPLETE:
|
2019-09-17 21:11:23 +09:00
|
|
|
if (data.success) {
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.startCall.resolve();
|
2019-09-17 21:11:23 +09:00
|
|
|
} else {
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.startCall.reject(wrapReason(data.reason));
|
2019-09-17 21:11:23 +09:00
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.PULL_COMPLETE:
|
2019-09-17 21:11:23 +09:00
|
|
|
if (data.success) {
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.pullCall.resolve();
|
2019-09-17 21:11:23 +09:00
|
|
|
} else {
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.pullCall.reject(wrapReason(data.reason));
|
2019-09-17 21:11:23 +09:00
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.PULL:
|
2018-06-04 19:37:54 +09:00
|
|
|
// Ignore any pull after close is called.
|
2021-09-21 18:21:43 +09:00
|
|
|
if (!streamSink) {
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
2019-08-30 20:26:39 +09:00
|
|
|
stream: StreamKind.PULL_COMPLETE,
|
Reduce the amount of unnecessary function calls and object allocations, in `MessageHandler`, when using Streams
With PR 11069 we're now using Streams for OperatorList parsing (in addition to just TextContent parsing), which brings the nice benefit of being able to easily abort parsing on the worker-thread thus saving resources.
However, since we're now creating many more `ReadableStream` there appears to be a tiny bit more overhead because of it (giving ~1% slower runtime of `browsertest` on the bots). In this case we're just going to have to accept such a small regression, since the benefits of using Streams clearly outweighs it.
What we *can* do here, is to try and make the Streams part of the `MessageHandler` implementation slightly more efficient by e.g. removing unnecessary function calls (which has been helpful in other parts of the code-base). To that end, this patch makes the following changes:
- Actually support `transfers` in `MessageHandler.sendWithStream`, since the parameter was being ignored.
- Inline the `sendStreamRequest`/`sendStreamResponse` helper functions at their respective call-sites. Obviously this causes some amount of code duplication, however I still think this change seems reasonable since for each call-site:
- It avoids making one unnecessary function call.
- It avoids allocating one temporary object.
- It avoids sending, and thus structure clone, various undefined object properties.
- Inline objects in the `MessageHandler.{send, sendWithPromise}` methods.
- Finally, directly call `comObj.postMessage` in various methods when `transfers` are *not* present, rather than calling `MessageHandler.postMessage`, to further reduce the amount of function calls.
2019-08-30 18:59:04 +09:00
|
|
|
streamId,
|
|
|
|
success: true,
|
|
|
|
});
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
|
|
|
}
|
2021-09-21 18:21:43 +09:00
|
|
|
// Pull increases the desiredSize property of sink, so when it changes
|
|
|
|
// from negative to positive, set ready property as resolved promise.
|
|
|
|
if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
|
|
|
|
streamSink.sinkCapability.resolve();
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
|
|
|
// Reset desiredSize property of sink on every pull.
|
2021-09-21 18:21:43 +09:00
|
|
|
streamSink.desiredSize = data.desiredSize;
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
new Promise(function (resolve) {
|
2021-09-21 18:21:43 +09:00
|
|
|
resolve(streamSink.onPull && streamSink.onPull());
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}).then(
|
2020-04-14 19:28:14 +09:00
|
|
|
function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.PULL_COMPLETE,
|
|
|
|
streamId,
|
|
|
|
success: true,
|
|
|
|
});
|
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.PULL_COMPLETE,
|
|
|
|
streamId,
|
|
|
|
reason: wrapReason(reason),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.ENQUEUE:
|
2021-09-21 18:21:43 +09:00
|
|
|
assert(streamController, "enqueue should have stream controller");
|
|
|
|
if (streamController.isClosed) {
|
2019-09-17 17:02:56 +09:00
|
|
|
break;
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.controller.enqueue(data.chunk);
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.CLOSE:
|
2021-09-21 18:21:43 +09:00
|
|
|
assert(streamController, "close should have stream controller");
|
|
|
|
if (streamController.isClosed) {
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
|
|
|
}
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.isClosed = true;
|
|
|
|
streamController.controller.close();
|
|
|
|
this._deleteStreamController(streamController, streamId);
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.ERROR:
|
2021-09-21 18:21:43 +09:00
|
|
|
assert(streamController, "error should have stream controller");
|
|
|
|
streamController.controller.error(wrapReason(data.reason));
|
|
|
|
this._deleteStreamController(streamController, streamId);
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.CANCEL_COMPLETE:
|
2019-09-17 21:11:23 +09:00
|
|
|
if (data.success) {
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.cancelCall.resolve();
|
2019-09-17 21:11:23 +09:00
|
|
|
} else {
|
2021-09-21 18:21:43 +09:00
|
|
|
streamController.cancelCall.reject(wrapReason(data.reason));
|
2019-09-17 21:11:23 +09:00
|
|
|
}
|
2021-09-21 18:21:43 +09:00
|
|
|
this._deleteStreamController(streamController, streamId);
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
2019-08-30 20:26:39 +09:00
|
|
|
case StreamKind.CANCEL:
|
2021-09-21 18:21:43 +09:00
|
|
|
if (!streamSink) {
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
|
|
|
}
|
2021-09-21 18:21:43 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
new Promise(function (resolve) {
|
2021-09-21 18:21:43 +09:00
|
|
|
resolve(
|
|
|
|
streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason))
|
|
|
|
);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}).then(
|
2020-04-14 19:28:14 +09:00
|
|
|
function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.CANCEL_COMPLETE,
|
|
|
|
streamId,
|
|
|
|
success: true,
|
|
|
|
});
|
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
comObj.postMessage({
|
|
|
|
sourceName,
|
|
|
|
targetName,
|
|
|
|
stream: StreamKind.CANCEL_COMPLETE,
|
|
|
|
streamId,
|
|
|
|
reason: wrapReason(reason),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2021-09-21 18:21:43 +09:00
|
|
|
streamSink.sinkCapability.reject(wrapReason(data.reason));
|
|
|
|
streamSink.isCancelled = true;
|
2019-09-17 17:02:56 +09:00
|
|
|
delete this.streamSinks[streamId];
|
2018-06-04 19:37:54 +09:00
|
|
|
break;
|
|
|
|
default:
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Unexpected stream case");
|
2018-06-04 19:37:54 +09:00
|
|
|
}
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
|
2019-10-31 06:05:25 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2021-09-21 18:21:43 +09:00
|
|
|
async _deleteStreamController(streamController, streamId) {
|
2019-10-06 20:52:25 +09:00
|
|
|
// Delete the `streamController` only when the start, pull, and cancel
|
|
|
|
// capabilities have settled, to prevent `TypeError`s.
|
2021-09-21 18:21:43 +09:00
|
|
|
await Promise.allSettled([
|
|
|
|
streamController.startCall && streamController.startCall.promise,
|
|
|
|
streamController.pullCall && streamController.pullCall.promise,
|
|
|
|
streamController.cancelCall && streamController.cancelCall.promise,
|
|
|
|
]);
|
2019-10-06 20:52:25 +09:00
|
|
|
delete this.streamControllers[streamId];
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
2019-10-06 20:52:25 +09:00
|
|
|
|
2018-06-04 19:37:54 +09:00
|
|
|
destroy() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
2019-10-31 06:05:25 +09:00
|
|
|
}
|
|
|
|
}
|
2018-06-04 19:37:54 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
export { MessageHandler };
|