pdfjs-dist 2.0.550 → 2.3.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +21618 -14369
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +22758 -11399
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +11500 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +767 -258
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +428 -157
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +173 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +575 -272
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1032 -351
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +813 -196
- package/lib/core/function.js +253 -27
- package/lib/core/glyphlist.js +5 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +502 -72
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +293 -52
- package/lib/core/jpx.js +419 -12
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1368 -500
- package/lib/core/operator_list.js +159 -43
- package/lib/core/parser.js +544 -199
- package/lib/core/pattern.js +170 -21
- package/lib/core/pdf_manager.js +324 -134
- package/lib/core/primitives.js +169 -61
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +327 -34
- package/lib/core/type1_parser.js +148 -8
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +215 -229
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +618 -192
- package/lib/display/api.js +1798 -882
- package/lib/display/api_compatibility.js +5 -10
- package/lib/display/canvas.js +366 -45
- package/lib/display/content_disposition.js +71 -24
- package/lib/display/display_utils.js +777 -0
- package/lib/display/fetch_stream.js +205 -87
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +38 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +103 -36
- package/lib/display/svg.js +1232 -519
- package/lib/display/text_layer.js +208 -75
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +35 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +170 -572
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +216 -163
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/util.js +495 -385
- package/lib/test/unit/annotation_spec.js +1464 -401
- package/lib/test/unit/api_spec.js +718 -361
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +9 -10
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +59 -20
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/message_handler_spec.js +30 -13
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +22 -55
- package/lib/test/unit/network_utils_spec.js +105 -14
- package/lib/test/unit/node_stream_spec.js +58 -34
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +55 -22
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +9 -7
- package/lib/test/unit/ui_utils_spec.js +236 -36
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1252 -609
- package/lib/web/app_options.js +103 -65
- package/lib/web/base_viewer.js +522 -242
- package/lib/web/chromecom.js +259 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -12
- package/lib/web/firefox_print_service.js +27 -14
- package/lib/web/firefoxcom.js +318 -78
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +174 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +144 -79
- package/lib/web/pdf_outline_viewer.js +124 -47
- package/lib/web/pdf_page_view.js +194 -74
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +59 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +144 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +82 -87
- package/lib/web/preferences.js +284 -91
- package/lib/web/secondary_toolbar.js +132 -59
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +80 -43
- package/lib/web/ui_utils.js +400 -134
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +3 -8
- package/package.json +3 -2
- package/web/pdf_viewer.css +23 -15
- package/web/pdf_viewer.js +3429 -1245
- package/web/pdf_viewer.js.map +1 -1
- package/external/streams/streams-lib.js +0 -3962
- package/lib/display/dom_utils.js +0 -429
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,6 +19,6 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
module.exports = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : {};
|
package/lib/shared/is_node.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,10 +19,10 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
|
24
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
25
25
|
|
26
26
|
module.exports = function isNodeJS() {
|
27
|
-
return (typeof process ===
|
27
|
+
return (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process + '' === '[object process]' && !process.versions['nw'] && !process.versions['electron'];
|
28
28
|
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,58 +19,52 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.MessageHandler =
|
27
|
+
exports.MessageHandler = MessageHandler;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("./util");
|
30
30
|
|
31
|
-
|
31
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
var StreamKind = {
|
34
|
+
UNKNOWN: 0,
|
35
|
+
CANCEL: 1,
|
36
|
+
CANCEL_COMPLETE: 2,
|
37
|
+
CLOSE: 3,
|
38
|
+
ENQUEUE: 4,
|
39
|
+
ERROR: 5,
|
40
|
+
PULL: 6,
|
41
|
+
PULL_COMPLETE: 7,
|
42
|
+
START_COMPLETE: 8
|
43
|
+
};
|
35
44
|
|
36
|
-
if (!fn) {
|
37
|
-
return Promise.resolve(undefined);
|
38
|
-
}
|
39
|
-
return new Promise(function (resolve, reject) {
|
40
|
-
resolve(fn.apply(thisArg, args));
|
41
|
-
});
|
42
|
-
}
|
43
45
|
function wrapReason(reason) {
|
44
|
-
if (
|
46
|
+
if (_typeof(reason) !== 'object') {
|
45
47
|
return reason;
|
46
48
|
}
|
49
|
+
|
47
50
|
switch (reason.name) {
|
48
51
|
case 'AbortException':
|
49
52
|
return new _util.AbortException(reason.message);
|
53
|
+
|
50
54
|
case 'MissingPDFException':
|
51
55
|
return new _util.MissingPDFException(reason.message);
|
56
|
+
|
52
57
|
case 'UnexpectedResponseException':
|
53
58
|
return new _util.UnexpectedResponseException(reason.message, reason.status);
|
54
|
-
|
59
|
+
|
60
|
+
case 'UnknownErrorException':
|
55
61
|
return new _util.UnknownErrorException(reason.message, reason.details);
|
62
|
+
|
63
|
+
default:
|
64
|
+
return new _util.UnknownErrorException(reason.message, reason.toString());
|
56
65
|
}
|
57
66
|
}
|
58
|
-
|
59
|
-
if (!(reason instanceof Error) || reason instanceof _util.AbortException || reason instanceof _util.MissingPDFException || reason instanceof _util.UnexpectedResponseException || reason instanceof _util.UnknownErrorException) {
|
60
|
-
return reason;
|
61
|
-
}
|
62
|
-
return new _util.UnknownErrorException(reason.message, reason.toString());
|
63
|
-
}
|
64
|
-
function resolveOrReject(capability, success, reason) {
|
65
|
-
if (success) {
|
66
|
-
capability.resolve();
|
67
|
-
} else {
|
68
|
-
capability.reject(reason);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
function finalize(promise) {
|
72
|
-
return Promise.resolve(promise).catch(function () {});
|
73
|
-
}
|
67
|
+
|
74
68
|
function MessageHandler(sourceName, targetName, comObj) {
|
75
69
|
var _this = this;
|
76
70
|
|
@@ -84,33 +78,39 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|
84
78
|
this.streamControllers = Object.create(null);
|
85
79
|
var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
|
86
80
|
var ah = this.actionHandler = Object.create(null);
|
81
|
+
|
87
82
|
this._onComObjOnMessage = function (event) {
|
88
83
|
var data = event.data;
|
84
|
+
|
89
85
|
if (data.targetName !== _this.sourceName) {
|
90
86
|
return;
|
91
87
|
}
|
88
|
+
|
92
89
|
if (data.stream) {
|
93
90
|
_this._processStreamMessage(data);
|
94
91
|
} else if (data.isReply) {
|
95
92
|
var callbackId = data.callbackId;
|
93
|
+
|
96
94
|
if (data.callbackId in callbacksCapabilities) {
|
97
95
|
var callback = callbacksCapabilities[callbackId];
|
98
96
|
delete callbacksCapabilities[callbackId];
|
99
|
-
|
100
|
-
|
97
|
+
|
98
|
+
if ('reason' in data) {
|
99
|
+
callback.reject(wrapReason(data.reason));
|
101
100
|
} else {
|
102
101
|
callback.resolve(data.data);
|
103
102
|
}
|
104
103
|
} else {
|
105
|
-
throw new Error(
|
104
|
+
throw new Error("Cannot resolve callback ".concat(callbackId));
|
106
105
|
}
|
107
106
|
} else if (data.action in ah) {
|
108
107
|
var action = ah[data.action];
|
108
|
+
|
109
109
|
if (data.callbackId) {
|
110
110
|
var _sourceName = _this.sourceName;
|
111
111
|
var _targetName = data.sourceName;
|
112
|
-
Promise
|
113
|
-
|
112
|
+
new Promise(function (resolve) {
|
113
|
+
resolve(action(data.data));
|
114
114
|
}).then(function (result) {
|
115
115
|
comObj.postMessage({
|
116
116
|
sourceName: _sourceName,
|
@@ -125,53 +125,57 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|
125
125
|
targetName: _targetName,
|
126
126
|
isReply: true,
|
127
127
|
callbackId: data.callbackId,
|
128
|
-
|
128
|
+
reason: wrapReason(reason)
|
129
129
|
});
|
130
130
|
});
|
131
131
|
} else if (data.streamId) {
|
132
132
|
_this._createStreamSink(data);
|
133
133
|
} else {
|
134
|
-
action
|
134
|
+
action(data.data);
|
135
135
|
}
|
136
136
|
} else {
|
137
|
-
throw new Error(
|
137
|
+
throw new Error("Unknown action from worker: ".concat(data.action));
|
138
138
|
}
|
139
139
|
};
|
140
|
+
|
140
141
|
comObj.addEventListener('message', this._onComObjOnMessage);
|
141
142
|
}
|
143
|
+
|
142
144
|
MessageHandler.prototype = {
|
143
|
-
on: function on(actionName, handler
|
145
|
+
on: function on(actionName, handler) {
|
144
146
|
var ah = this.actionHandler;
|
147
|
+
|
145
148
|
if (ah[actionName]) {
|
146
|
-
throw new Error(
|
149
|
+
throw new Error("There is already an actionName called \"".concat(actionName, "\""));
|
147
150
|
}
|
148
|
-
|
151
|
+
|
152
|
+
ah[actionName] = handler;
|
149
153
|
},
|
150
154
|
send: function send(actionName, data, transfers) {
|
151
|
-
|
155
|
+
this.postMessage({
|
152
156
|
sourceName: this.sourceName,
|
153
157
|
targetName: this.targetName,
|
154
158
|
action: actionName,
|
155
159
|
data: data
|
156
|
-
};
|
157
|
-
this.postMessage(message, transfers);
|
160
|
+
}, transfers);
|
158
161
|
},
|
159
162
|
sendWithPromise: function sendWithPromise(actionName, data, transfers) {
|
160
163
|
var callbackId = this.callbackId++;
|
161
|
-
var message = {
|
162
|
-
sourceName: this.sourceName,
|
163
|
-
targetName: this.targetName,
|
164
|
-
action: actionName,
|
165
|
-
data: data,
|
166
|
-
callbackId: callbackId
|
167
|
-
};
|
168
164
|
var capability = (0, _util.createPromiseCapability)();
|
169
165
|
this.callbacksCapabilities[callbackId] = capability;
|
166
|
+
|
170
167
|
try {
|
171
|
-
this.postMessage(
|
172
|
-
|
173
|
-
|
168
|
+
this.postMessage({
|
169
|
+
sourceName: this.sourceName,
|
170
|
+
targetName: this.targetName,
|
171
|
+
action: actionName,
|
172
|
+
callbackId: callbackId,
|
173
|
+
data: data
|
174
|
+
}, transfers);
|
175
|
+
} catch (ex) {
|
176
|
+
capability.reject(ex);
|
174
177
|
}
|
178
|
+
|
175
179
|
return capability.promise;
|
176
180
|
},
|
177
181
|
sendWithStream: function sendWithStream(actionName, data, queueingStrategy, transfers) {
|
@@ -180,14 +184,18 @@ MessageHandler.prototype = {
|
|
180
184
|
var streamId = this.streamId++;
|
181
185
|
var sourceName = this.sourceName;
|
182
186
|
var targetName = this.targetName;
|
187
|
+
var comObj = this.comObj;
|
183
188
|
return new _util.ReadableStream({
|
184
189
|
start: function start(controller) {
|
185
190
|
var startCapability = (0, _util.createPromiseCapability)();
|
186
191
|
_this2.streamControllers[streamId] = {
|
187
192
|
controller: controller,
|
188
193
|
startCall: startCapability,
|
194
|
+
pullCall: null,
|
195
|
+
cancelCall: null,
|
189
196
|
isClosed: false
|
190
197
|
};
|
198
|
+
|
191
199
|
_this2.postMessage({
|
192
200
|
sourceName: sourceName,
|
193
201
|
targetName: targetName,
|
@@ -195,39 +203,39 @@ MessageHandler.prototype = {
|
|
195
203
|
streamId: streamId,
|
196
204
|
data: data,
|
197
205
|
desiredSize: controller.desiredSize
|
198
|
-
});
|
206
|
+
}, transfers);
|
207
|
+
|
199
208
|
return startCapability.promise;
|
200
209
|
},
|
201
210
|
pull: function pull(controller) {
|
202
211
|
var pullCapability = (0, _util.createPromiseCapability)();
|
203
212
|
_this2.streamControllers[streamId].pullCall = pullCapability;
|
204
|
-
|
213
|
+
comObj.postMessage({
|
205
214
|
sourceName: sourceName,
|
206
215
|
targetName: targetName,
|
207
|
-
stream:
|
216
|
+
stream: StreamKind.PULL,
|
208
217
|
streamId: streamId,
|
209
218
|
desiredSize: controller.desiredSize
|
210
219
|
});
|
211
220
|
return pullCapability.promise;
|
212
221
|
},
|
213
222
|
cancel: function cancel(reason) {
|
223
|
+
(0, _util.assert)(reason instanceof Error, 'cancel must have a valid reason');
|
214
224
|
var cancelCapability = (0, _util.createPromiseCapability)();
|
215
225
|
_this2.streamControllers[streamId].cancelCall = cancelCapability;
|
216
226
|
_this2.streamControllers[streamId].isClosed = true;
|
217
|
-
|
227
|
+
comObj.postMessage({
|
218
228
|
sourceName: sourceName,
|
219
229
|
targetName: targetName,
|
220
|
-
stream:
|
221
|
-
|
222
|
-
|
230
|
+
stream: StreamKind.CANCEL,
|
231
|
+
streamId: streamId,
|
232
|
+
reason: wrapReason(reason)
|
223
233
|
});
|
224
234
|
return cancelCapability.promise;
|
225
235
|
}
|
226
236
|
}, queueingStrategy);
|
227
237
|
},
|
228
238
|
_createStreamSink: function _createStreamSink(data) {
|
229
|
-
var _this3 = this;
|
230
|
-
|
231
239
|
var self = this;
|
232
240
|
var action = this.actionHandler[data.action];
|
233
241
|
var streamId = data.streamId;
|
@@ -235,62 +243,62 @@ MessageHandler.prototype = {
|
|
235
243
|
var sourceName = this.sourceName;
|
236
244
|
var targetName = data.sourceName;
|
237
245
|
var capability = (0, _util.createPromiseCapability)();
|
238
|
-
var
|
239
|
-
var stream = _ref.stream,
|
240
|
-
chunk = _ref.chunk,
|
241
|
-
transfers = _ref.transfers,
|
242
|
-
success = _ref.success,
|
243
|
-
reason = _ref.reason;
|
244
|
-
|
245
|
-
_this3.postMessage({
|
246
|
-
sourceName: sourceName,
|
247
|
-
targetName: targetName,
|
248
|
-
stream: stream,
|
249
|
-
streamId: streamId,
|
250
|
-
chunk: chunk,
|
251
|
-
success: success,
|
252
|
-
reason: reason
|
253
|
-
}, transfers);
|
254
|
-
};
|
246
|
+
var comObj = this.comObj;
|
255
247
|
var streamSink = {
|
256
248
|
enqueue: function enqueue(chunk) {
|
257
249
|
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
258
|
-
var transfers = arguments[2];
|
250
|
+
var transfers = arguments.length > 2 ? arguments[2] : undefined;
|
259
251
|
|
260
252
|
if (this.isCancelled) {
|
261
253
|
return;
|
262
254
|
}
|
255
|
+
|
263
256
|
var lastDesiredSize = this.desiredSize;
|
264
257
|
this.desiredSize -= size;
|
258
|
+
|
265
259
|
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
266
260
|
this.sinkCapability = (0, _util.createPromiseCapability)();
|
267
261
|
this.ready = this.sinkCapability.promise;
|
268
262
|
}
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
263
|
+
|
264
|
+
self.postMessage({
|
265
|
+
sourceName: sourceName,
|
266
|
+
targetName: targetName,
|
267
|
+
stream: StreamKind.ENQUEUE,
|
268
|
+
streamId: streamId,
|
269
|
+
chunk: chunk
|
270
|
+
}, transfers);
|
274
271
|
},
|
275
272
|
close: function close() {
|
276
273
|
if (this.isCancelled) {
|
277
274
|
return;
|
278
275
|
}
|
276
|
+
|
279
277
|
this.isCancelled = true;
|
280
|
-
|
278
|
+
comObj.postMessage({
|
279
|
+
sourceName: sourceName,
|
280
|
+
targetName: targetName,
|
281
|
+
stream: StreamKind.CLOSE,
|
282
|
+
streamId: streamId
|
283
|
+
});
|
281
284
|
delete self.streamSinks[streamId];
|
282
285
|
},
|
283
286
|
error: function error(reason) {
|
287
|
+
(0, _util.assert)(reason instanceof Error, 'error must have a valid reason');
|
288
|
+
|
284
289
|
if (this.isCancelled) {
|
285
290
|
return;
|
286
291
|
}
|
292
|
+
|
287
293
|
this.isCancelled = true;
|
288
|
-
|
289
|
-
|
290
|
-
|
294
|
+
comObj.postMessage({
|
295
|
+
sourceName: sourceName,
|
296
|
+
targetName: targetName,
|
297
|
+
stream: StreamKind.ERROR,
|
298
|
+
streamId: streamId,
|
299
|
+
reason: wrapReason(reason)
|
291
300
|
});
|
292
301
|
},
|
293
|
-
|
294
302
|
sinkCapability: capability,
|
295
303
|
onPull: null,
|
296
304
|
onCancel: null,
|
@@ -301,122 +309,168 @@ MessageHandler.prototype = {
|
|
301
309
|
streamSink.sinkCapability.resolve();
|
302
310
|
streamSink.ready = streamSink.sinkCapability.promise;
|
303
311
|
this.streamSinks[streamId] = streamSink;
|
304
|
-
|
305
|
-
|
306
|
-
|
312
|
+
new Promise(function (resolve) {
|
313
|
+
resolve(action(data.data, streamSink));
|
314
|
+
}).then(function () {
|
315
|
+
comObj.postMessage({
|
316
|
+
sourceName: sourceName,
|
317
|
+
targetName: targetName,
|
318
|
+
stream: StreamKind.START_COMPLETE,
|
319
|
+
streamId: streamId,
|
307
320
|
success: true
|
308
321
|
});
|
309
322
|
}, function (reason) {
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
323
|
+
comObj.postMessage({
|
324
|
+
sourceName: sourceName,
|
325
|
+
targetName: targetName,
|
326
|
+
stream: StreamKind.START_COMPLETE,
|
327
|
+
streamId: streamId,
|
328
|
+
reason: wrapReason(reason)
|
314
329
|
});
|
315
330
|
});
|
316
331
|
},
|
317
332
|
_processStreamMessage: function _processStreamMessage(data) {
|
318
|
-
var
|
333
|
+
var _this3 = this;
|
319
334
|
|
320
335
|
var sourceName = this.sourceName;
|
321
336
|
var targetName = data.sourceName;
|
322
337
|
var streamId = data.streamId;
|
323
|
-
var
|
324
|
-
var stream = _ref2.stream,
|
325
|
-
success = _ref2.success,
|
326
|
-
reason = _ref2.reason;
|
338
|
+
var comObj = this.comObj;
|
327
339
|
|
328
|
-
_this4.comObj.postMessage({
|
329
|
-
sourceName: sourceName,
|
330
|
-
targetName: targetName,
|
331
|
-
stream: stream,
|
332
|
-
success: success,
|
333
|
-
streamId: streamId,
|
334
|
-
reason: reason
|
335
|
-
});
|
336
|
-
};
|
337
340
|
var deleteStreamController = function deleteStreamController() {
|
338
|
-
Promise.all([
|
339
|
-
return capability &&
|
341
|
+
Promise.all([_this3.streamControllers[streamId].startCall, _this3.streamControllers[streamId].pullCall, _this3.streamControllers[streamId].cancelCall].map(function (capability) {
|
342
|
+
return capability && capability.promise["catch"](function () {});
|
340
343
|
})).then(function () {
|
341
|
-
delete
|
344
|
+
delete _this3.streamControllers[streamId];
|
342
345
|
});
|
343
346
|
};
|
347
|
+
|
344
348
|
switch (data.stream) {
|
345
|
-
case
|
346
|
-
|
349
|
+
case StreamKind.START_COMPLETE:
|
350
|
+
if (data.success) {
|
351
|
+
this.streamControllers[streamId].startCall.resolve();
|
352
|
+
} else {
|
353
|
+
this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
|
354
|
+
}
|
355
|
+
|
347
356
|
break;
|
348
|
-
|
349
|
-
|
357
|
+
|
358
|
+
case StreamKind.PULL_COMPLETE:
|
359
|
+
if (data.success) {
|
360
|
+
this.streamControllers[streamId].pullCall.resolve();
|
361
|
+
} else {
|
362
|
+
this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
|
363
|
+
}
|
364
|
+
|
350
365
|
break;
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
366
|
+
|
367
|
+
case StreamKind.PULL:
|
368
|
+
if (!this.streamSinks[streamId]) {
|
369
|
+
comObj.postMessage({
|
370
|
+
sourceName: sourceName,
|
371
|
+
targetName: targetName,
|
372
|
+
stream: StreamKind.PULL_COMPLETE,
|
373
|
+
streamId: streamId,
|
355
374
|
success: true
|
356
375
|
});
|
357
376
|
break;
|
358
377
|
}
|
359
|
-
|
360
|
-
|
378
|
+
|
379
|
+
if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
|
380
|
+
this.streamSinks[streamId].sinkCapability.resolve();
|
361
381
|
}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
382
|
+
|
383
|
+
this.streamSinks[streamId].desiredSize = data.desiredSize;
|
384
|
+
var onPull = this.streamSinks[data.streamId].onPull;
|
385
|
+
new Promise(function (resolve) {
|
386
|
+
resolve(onPull && onPull());
|
387
|
+
}).then(function () {
|
388
|
+
comObj.postMessage({
|
389
|
+
sourceName: sourceName,
|
390
|
+
targetName: targetName,
|
391
|
+
stream: StreamKind.PULL_COMPLETE,
|
392
|
+
streamId: streamId,
|
366
393
|
success: true
|
367
394
|
});
|
368
395
|
}, function (reason) {
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
396
|
+
comObj.postMessage({
|
397
|
+
sourceName: sourceName,
|
398
|
+
targetName: targetName,
|
399
|
+
stream: StreamKind.PULL_COMPLETE,
|
400
|
+
streamId: streamId,
|
401
|
+
reason: wrapReason(reason)
|
373
402
|
});
|
374
403
|
});
|
375
404
|
break;
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
405
|
+
|
406
|
+
case StreamKind.ENQUEUE:
|
407
|
+
(0, _util.assert)(this.streamControllers[streamId], 'enqueue should have stream controller');
|
408
|
+
|
409
|
+
if (this.streamControllers[streamId].isClosed) {
|
410
|
+
break;
|
380
411
|
}
|
412
|
+
|
413
|
+
this.streamControllers[streamId].controller.enqueue(data.chunk);
|
381
414
|
break;
|
382
|
-
|
383
|
-
|
384
|
-
|
415
|
+
|
416
|
+
case StreamKind.CLOSE:
|
417
|
+
(0, _util.assert)(this.streamControllers[streamId], 'close should have stream controller');
|
418
|
+
|
419
|
+
if (this.streamControllers[streamId].isClosed) {
|
385
420
|
break;
|
386
421
|
}
|
387
|
-
|
388
|
-
this.streamControllers[
|
422
|
+
|
423
|
+
this.streamControllers[streamId].isClosed = true;
|
424
|
+
this.streamControllers[streamId].controller.close();
|
389
425
|
deleteStreamController();
|
390
426
|
break;
|
391
|
-
|
392
|
-
|
393
|
-
this.streamControllers[
|
427
|
+
|
428
|
+
case StreamKind.ERROR:
|
429
|
+
(0, _util.assert)(this.streamControllers[streamId], 'error should have stream controller');
|
430
|
+
this.streamControllers[streamId].controller.error(wrapReason(data.reason));
|
394
431
|
deleteStreamController();
|
395
432
|
break;
|
396
|
-
|
397
|
-
|
433
|
+
|
434
|
+
case StreamKind.CANCEL_COMPLETE:
|
435
|
+
if (data.success) {
|
436
|
+
this.streamControllers[streamId].cancelCall.resolve();
|
437
|
+
} else {
|
438
|
+
this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
|
439
|
+
}
|
440
|
+
|
398
441
|
deleteStreamController();
|
399
442
|
break;
|
400
|
-
|
401
|
-
|
443
|
+
|
444
|
+
case StreamKind.CANCEL:
|
445
|
+
if (!this.streamSinks[streamId]) {
|
402
446
|
break;
|
403
447
|
}
|
404
|
-
|
405
|
-
|
406
|
-
|
448
|
+
|
449
|
+
var onCancel = this.streamSinks[data.streamId].onCancel;
|
450
|
+
new Promise(function (resolve) {
|
451
|
+
resolve(onCancel && onCancel(wrapReason(data.reason)));
|
452
|
+
}).then(function () {
|
453
|
+
comObj.postMessage({
|
454
|
+
sourceName: sourceName,
|
455
|
+
targetName: targetName,
|
456
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
457
|
+
streamId: streamId,
|
407
458
|
success: true
|
408
459
|
});
|
409
460
|
}, function (reason) {
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
461
|
+
comObj.postMessage({
|
462
|
+
sourceName: sourceName,
|
463
|
+
targetName: targetName,
|
464
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
465
|
+
streamId: streamId,
|
466
|
+
reason: wrapReason(reason)
|
414
467
|
});
|
415
468
|
});
|
416
|
-
this.streamSinks[
|
417
|
-
this.streamSinks[
|
418
|
-
delete this.streamSinks[
|
469
|
+
this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
|
470
|
+
this.streamSinks[streamId].isCancelled = true;
|
471
|
+
delete this.streamSinks[streamId];
|
419
472
|
break;
|
473
|
+
|
420
474
|
default:
|
421
475
|
throw new Error('Unexpected stream case');
|
422
476
|
}
|
@@ -431,5 +485,4 @@ MessageHandler.prototype = {
|
|
431
485
|
destroy: function destroy() {
|
432
486
|
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
433
487
|
}
|
434
|
-
};
|
435
|
-
exports.MessageHandler = MessageHandler;
|
488
|
+
};
|