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.

Files changed (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. 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 2017 Mozilla Foundation
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,65 +19,45 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
24
+ var _encodings = require("../../core/encodings");
25
25
 
26
- var _encodings = require('../../core/encodings');
26
+ 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); }
27
27
 
28
28
  describe('encodings', function () {
29
29
  describe('getEncoding', function () {
30
30
  it('fetches a valid array for known encoding names', function () {
31
31
  var knownEncodingNames = ['ExpertEncoding', 'MacExpertEncoding', 'MacRomanEncoding', 'StandardEncoding', 'SymbolSetEncoding', 'WinAnsiEncoding', 'ZapfDingbatsEncoding'];
32
- var _iteratorNormalCompletion = true;
33
- var _didIteratorError = false;
34
- var _iteratorError = undefined;
35
32
 
36
- try {
37
- for (var _iterator = knownEncodingNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
38
- var knownEncodingName = _step.value;
39
-
40
- var encoding = (0, _encodings.getEncoding)(knownEncodingName);
41
- expect(Array.isArray(encoding)).toEqual(true);
42
- expect(encoding.length).toEqual(256);
43
- var _iteratorNormalCompletion2 = true;
44
- var _didIteratorError2 = false;
45
- var _iteratorError2 = undefined;
33
+ for (var _i = 0, _knownEncodingNames = knownEncodingNames; _i < _knownEncodingNames.length; _i++) {
34
+ var knownEncodingName = _knownEncodingNames[_i];
35
+ var encoding = (0, _encodings.getEncoding)(knownEncodingName);
36
+ expect(Array.isArray(encoding)).toEqual(true);
37
+ expect(encoding.length).toEqual(256);
38
+ var _iteratorNormalCompletion = true;
39
+ var _didIteratorError = false;
40
+ var _iteratorError = undefined;
46
41
 
42
+ try {
43
+ for (var _iterator = encoding[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
44
+ var item = _step.value;
45
+ expect(_typeof(item)).toEqual('string');
46
+ }
47
+ } catch (err) {
48
+ _didIteratorError = true;
49
+ _iteratorError = err;
50
+ } finally {
47
51
  try {
48
- for (var _iterator2 = encoding[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
49
- var item = _step2.value;
50
-
51
- expect(typeof item === 'undefined' ? 'undefined' : _typeof(item)).toEqual('string');
52
+ if (!_iteratorNormalCompletion && _iterator["return"] != null) {
53
+ _iterator["return"]();
52
54
  }
53
- } catch (err) {
54
- _didIteratorError2 = true;
55
- _iteratorError2 = err;
56
55
  } finally {
57
- try {
58
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
59
- _iterator2.return();
60
- }
61
- } finally {
62
- if (_didIteratorError2) {
63
- throw _iteratorError2;
64
- }
56
+ if (_didIteratorError) {
57
+ throw _iteratorError;
65
58
  }
66
59
  }
67
60
  }
68
- } catch (err) {
69
- _didIteratorError = true;
70
- _iteratorError = err;
71
- } finally {
72
- try {
73
- if (!_iteratorNormalCompletion && _iterator.return) {
74
- _iterator.return();
75
- }
76
- } finally {
77
- if (_didIteratorError) {
78
- throw _iteratorError;
79
- }
80
- }
81
61
  }
82
62
  });
83
63
  it('fetches `null` for unknown encoding names', function () {
@@ -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 2017 Mozilla Foundation
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,26 +19,33 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _primitives = require('../../core/primitives');
24
+ var _test_utils = require("./test_utils");
25
25
 
26
- var _util = require('../../shared/util');
26
+ var _primitives = require("../../core/primitives");
27
27
 
28
- var _stream = require('../../core/stream');
28
+ var _util = require("../../shared/util");
29
29
 
30
- var _operator_list = require('../../core/operator_list');
30
+ var _stream = require("../../core/stream");
31
31
 
32
- var _evaluator = require('../../core/evaluator');
32
+ var _operator_list = require("../../core/operator_list");
33
33
 
34
- var _worker = require('../../core/worker');
34
+ var _evaluator = require("../../core/evaluator");
35
35
 
36
- var _test_utils = require('./test_utils');
36
+ var _worker = require("../../core/worker");
37
+
38
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
39
+
40
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
41
+
42
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
37
43
 
38
44
  describe('evaluator', function () {
39
45
  function HandlerMock() {
40
46
  this.inputs = [];
41
47
  }
48
+
42
49
  HandlerMock.prototype = {
43
50
  send: function send(name, data) {
44
51
  this.inputs.push({
@@ -47,13 +54,15 @@ describe('evaluator', function () {
47
54
  });
48
55
  }
49
56
  };
57
+
50
58
  function ResourcesMock() {}
59
+
51
60
  ResourcesMock.prototype = {
52
61
  get: function get(name) {
53
62
  return this[name];
54
63
  }
55
64
  };
56
- function PdfManagerMock() {}
65
+
57
66
  function runOperatorListCheck(evaluator, stream, resources, callback) {
58
67
  var result = new _operator_list.OperatorList();
59
68
  var task = new _worker.WorkerTask('OperatorListCheck');
@@ -68,13 +77,14 @@ describe('evaluator', function () {
68
77
  callback(reason);
69
78
  });
70
79
  }
80
+
71
81
  var partialEvaluator;
72
82
  beforeAll(function (done) {
73
83
  partialEvaluator = new _evaluator.PartialEvaluator({
74
- pdfManager: new PdfManagerMock(),
75
84
  xref: new _test_utils.XRefMock(),
76
85
  handler: new HandlerMock(),
77
- pageIndex: 0
86
+ pageIndex: 0,
87
+ idFactory: (0, _test_utils.createIdFactory)(0)
78
88
  });
79
89
  done();
80
90
  });
@@ -209,6 +219,24 @@ describe('evaluator', function () {
209
219
  done();
210
220
  });
211
221
  });
222
+ it('should error if (many) path operators have too few arguments ' + '(bug 1443140)', function (done) {
223
+ var NUM_INVALID_OPS = 25;
224
+ var tempArr = new Array(NUM_INVALID_OPS + 1);
225
+ var invalidMoveText = tempArr.join('10 Td\n');
226
+ var moveTextStream = new _stream.StringStream(invalidMoveText);
227
+ runOperatorListCheck(partialEvaluator, moveTextStream, new ResourcesMock(), function (result) {
228
+ expect(result.argsArray).toEqual([]);
229
+ expect(result.fnArray).toEqual([]);
230
+ done();
231
+ });
232
+ var invalidLineTo = tempArr.join('20 l\n');
233
+ var lineToStream = new _stream.StringStream(invalidLineTo);
234
+ runOperatorListCheck(partialEvaluator, lineToStream, new ResourcesMock(), function (error) {
235
+ expect(error instanceof _util.FormatError).toEqual(true);
236
+ expect(error.message).toEqual('Invalid command l: expected 2 args, but received 1 args.');
237
+ done();
238
+ });
239
+ });
212
240
  it('should close opened saves', function (done) {
213
241
  var stream = new _stream.StringStream('qq');
214
242
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
@@ -221,7 +249,7 @@ describe('evaluator', function () {
221
249
  done();
222
250
  });
223
251
  });
224
- it('should skip paintXObject if name is missing', function (done) {
252
+ it('should error on paintXObject if name is missing', function (done) {
225
253
  var stream = new _stream.StringStream('/ Do');
226
254
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
227
255
  expect(result instanceof _util.FormatError).toEqual(true);
@@ -257,7 +285,7 @@ describe('evaluator', function () {
257
285
  task: task,
258
286
  resources: resources,
259
287
  operatorList: result
260
- }).catch(function () {
288
+ })["catch"](function () {
261
289
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
262
290
  expect(result.fnArray.length).toEqual(0);
263
291
  done();
@@ -272,19 +300,30 @@ describe('evaluator', function () {
272
300
  stream: stream,
273
301
  task: task,
274
302
  resources: resources
275
- }).catch(function () {
303
+ })["catch"](function () {
276
304
  expect(true).toEqual(true);
277
305
  done();
278
306
  });
279
307
  });
280
308
  });
281
309
  describe('operator list', function () {
282
- function MessageHandlerMock() {}
283
- MessageHandlerMock.prototype = {
284
- send: function send() {}
285
- };
310
+ var StreamSinkMock =
311
+ /*#__PURE__*/
312
+ function () {
313
+ function StreamSinkMock() {
314
+ _classCallCheck(this, StreamSinkMock);
315
+ }
316
+
317
+ _createClass(StreamSinkMock, [{
318
+ key: "enqueue",
319
+ value: function enqueue() {}
320
+ }]);
321
+
322
+ return StreamSinkMock;
323
+ }();
324
+
286
325
  it('should get correct total length after flushing', function () {
287
- var operatorList = new _operator_list.OperatorList(null, new MessageHandlerMock());
326
+ var operatorList = new _operator_list.OperatorList(null, new StreamSinkMock());
288
327
  operatorList.addOp(_util.OPS.save, null);
289
328
  operatorList.addOp(_util.OPS.restore, null);
290
329
  expect(operatorList.totalLength).toEqual(2);
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * Javascript code in this page
4
+ *
5
+ * Copyright 2019 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * Javascript code in this page
21
+ */
22
+ "use strict";
23
+
24
+ var _util = require("../../shared/util");
25
+
26
+ var _fetch_stream = require("../../display/fetch_stream");
27
+
28
+ describe('fetch_stream', function () {
29
+ var pdfUrl = new URL('../pdfs/tracemonkey.pdf', window.location).href;
30
+ var pdfLength = 1016315;
31
+ it('read with streaming', function (done) {
32
+ var stream = new _fetch_stream.PDFFetchStream({
33
+ url: pdfUrl,
34
+ disableStream: false,
35
+ disableRange: true
36
+ });
37
+ var fullReader = stream.getFullReader();
38
+ var isStreamingSupported, isRangeSupported;
39
+ var promise = fullReader.headersReady.then(function () {
40
+ isStreamingSupported = fullReader.isStreamingSupported;
41
+ isRangeSupported = fullReader.isRangeSupported;
42
+ });
43
+ var len = 0;
44
+
45
+ var read = function read() {
46
+ return fullReader.read().then(function (result) {
47
+ if (result.done) {
48
+ return undefined;
49
+ }
50
+
51
+ len += result.value.byteLength;
52
+ return read();
53
+ });
54
+ };
55
+
56
+ var readPromise = Promise.all([read(), promise]);
57
+ readPromise.then(function () {
58
+ expect(len).toEqual(pdfLength);
59
+ expect(isStreamingSupported).toEqual(true);
60
+ expect(isRangeSupported).toEqual(false);
61
+ done();
62
+ })["catch"](done.fail);
63
+ });
64
+ it('read ranges with streaming', function (done) {
65
+ var rangeSize = 32768;
66
+ var stream = new _fetch_stream.PDFFetchStream({
67
+ url: pdfUrl,
68
+ rangeChunkSize: rangeSize,
69
+ disableStream: false,
70
+ disableRange: false
71
+ });
72
+ var fullReader = stream.getFullReader();
73
+ var isStreamingSupported, isRangeSupported, fullReaderCancelled;
74
+ var promise = fullReader.headersReady.then(function () {
75
+ isStreamingSupported = fullReader.isStreamingSupported;
76
+ isRangeSupported = fullReader.isRangeSupported;
77
+ fullReader.cancel(new _util.AbortException('Don\'t need fullReader.'));
78
+ fullReaderCancelled = true;
79
+ });
80
+ var tailSize = pdfLength % rangeSize || rangeSize;
81
+ var rangeReader1 = stream.getRangeReader(pdfLength - tailSize - rangeSize, pdfLength - tailSize);
82
+ var rangeReader2 = stream.getRangeReader(pdfLength - tailSize, pdfLength);
83
+ var result1 = {
84
+ value: 0
85
+ },
86
+ result2 = {
87
+ value: 0
88
+ };
89
+
90
+ var read = function read(reader, lenResult) {
91
+ return reader.read().then(function (result) {
92
+ if (result.done) {
93
+ return undefined;
94
+ }
95
+
96
+ lenResult.value += result.value.byteLength;
97
+ return read(reader, lenResult);
98
+ });
99
+ };
100
+
101
+ var readPromise = Promise.all([read(rangeReader1, result1), read(rangeReader2, result2), promise]);
102
+ readPromise.then(function () {
103
+ expect(isStreamingSupported).toEqual(true);
104
+ expect(isRangeSupported).toEqual(true);
105
+ expect(fullReaderCancelled).toEqual(true);
106
+ expect(result1.value).toEqual(rangeSize);
107
+ expect(result2.value).toEqual(tailSize);
108
+ done();
109
+ })["catch"](done.fail);
110
+ });
111
+ });
@@ -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 2017 Mozilla Foundation
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,13 +19,13 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _function = require('../../core/function');
24
+ var _function = require("../../core/function");
25
25
 
26
- var _ps_parser = require('../../core/ps_parser');
26
+ var _ps_parser = require("../../core/ps_parser");
27
27
 
28
- var _stream = require('../../core/stream');
28
+ var _stream = require("../../core/stream");
29
29
 
30
30
  describe('function', function () {
31
31
  beforeEach(function () {
@@ -34,23 +34,29 @@ describe('function', function () {
34
34
  return {
35
35
  compare: function compare(actual, expected) {
36
36
  var result = {};
37
+
37
38
  if (actual.length !== expected.length) {
38
39
  result.pass = false;
39
40
  result.message = 'Array length: ' + actual.length + ', expected: ' + expected.length;
40
41
  return result;
41
42
  }
43
+
42
44
  result.pass = true;
45
+
43
46
  for (var i = 0; i < expected.length; i++) {
44
47
  var a = actual[i],
45
48
  b = expected[i];
49
+
46
50
  if (Array.isArray(b)) {
47
51
  if (a.length !== b.length) {
48
52
  result.pass = false;
49
53
  break;
50
54
  }
55
+
51
56
  for (var j = 0; j < a.length; j++) {
52
57
  var suba = a[j],
53
58
  subb = b[j];
59
+
54
60
  if (suba !== subb) {
55
61
  result.pass = false;
56
62
  break;
@@ -63,6 +69,7 @@ describe('function', function () {
63
69
  }
64
70
  }
65
71
  }
72
+
66
73
  return result;
67
74
  }
68
75
  };
@@ -75,6 +82,7 @@ describe('function', function () {
75
82
  var parser = new _ps_parser.PostScriptParser(new _ps_parser.PostScriptLexer(stream));
76
83
  return parser.parse();
77
84
  }
85
+
78
86
  it('parses empty programs', function () {
79
87
  var output = parse('{}');
80
88
  expect(output.length).toEqual(0);
@@ -133,6 +141,7 @@ describe('function', function () {
133
141
  var output = evaluator.execute();
134
142
  return output;
135
143
  }
144
+
136
145
  it('pushes stack', function () {
137
146
  var stack = evaluate('{ 99 }');
138
147
  var expectedStack = [99];
@@ -448,11 +457,13 @@ describe('function', function () {
448
457
  function check(code, domain, range, samples) {
449
458
  var compiler = new _function.PostScriptCompiler();
450
459
  var compiledCode = compiler.compile(code, domain, range);
460
+
451
461
  if (samples === null) {
452
462
  expect(compiledCode).toBeNull();
453
463
  } else {
454
464
  expect(compiledCode).not.toBeNull();
455
465
  var fn = new Function('src', 'srcOffset', 'dest', 'destOffset', compiledCode);
466
+
456
467
  for (var i = 0; i < samples.length; i++) {
457
468
  var out = new Float32Array(samples[i].output.length);
458
469
  fn(samples[i].input, 0, out, 0);
@@ -460,6 +471,7 @@ describe('function', function () {
460
471
  }
461
472
  }
462
473
  }
474
+
463
475
  it('check compiled add', function () {
464
476
  check([0.25, 0.5, 'add'], [], [0, 1], [{
465
477
  input: [],
@@ -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 2017 Mozilla Foundation
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.
@@ -22,17 +22,19 @@
22
22
  'use strict';
23
23
 
24
24
  function initializePDFJS(callback) {
25
- Promise.all(['pdfjs/display/api', 'pdfjs/display/worker_options', 'pdfjs/display/network', 'pdfjs/display/fetch_stream', 'pdfjs/shared/is_node', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/colorspace_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/custom_spec', 'pdfjs-test/unit/display_svg_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/encodings_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/message_handler_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/network_utils_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/pdf_history_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'].map(function (moduleName) {
26
- return SystemJS.import(moduleName);
25
+ Promise.all(['pdfjs/display/api', 'pdfjs/display/worker_options', 'pdfjs/display/network', 'pdfjs/display/fetch_stream', 'pdfjs/shared/is_node', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/colorspace_spec', 'pdfjs-test/unit/core_utils_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/custom_spec', 'pdfjs-test/unit/display_svg_spec', 'pdfjs-test/unit/display_utils_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/encodings_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/fetch_stream_spec', 'pdfjs-test/unit/message_handler_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/network_utils_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/pdf_find_controller_spec', 'pdfjs-test/unit/pdf_find_utils_spec', 'pdfjs-test/unit/pdf_history_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'].map(function (moduleName) {
26
+ return SystemJS["import"](moduleName);
27
27
  })).then(function (modules) {
28
28
  var displayApi = modules[0];
29
29
  var GlobalWorkerOptions = modules[1].GlobalWorkerOptions;
30
30
  var PDFNetworkStream = modules[2].PDFNetworkStream;
31
31
  var PDFFetchStream = modules[3].PDFFetchStream;
32
32
  var isNodeJS = modules[4];
33
+
33
34
  if (isNodeJS()) {
34
35
  throw new Error('The `gulp unittest` command cannot be used in ' + 'Node.js environments.');
35
36
  }
37
+
36
38
  if (typeof Response !== 'undefined' && 'body' in Response.prototype && typeof ReadableStream !== 'undefined') {
37
39
  displayApi.setPDFNetworkStreamFactory(function (params) {
38
40
  return new PDFFetchStream(params);
@@ -42,41 +44,44 @@ function initializePDFJS(callback) {
42
44
  return new PDFNetworkStream(params);
43
45
  });
44
46
  }
47
+
45
48
  GlobalWorkerOptions.workerSrc = '../../build/generic/build/pdf.worker.js';
46
49
  callback();
47
50
  });
48
51
  }
52
+
49
53
  (function () {
50
54
  window.jasmine = jasmineRequire.core(jasmineRequire);
51
55
  jasmineRequire.html(jasmine);
52
56
  var env = jasmine.getEnv();
53
- var jasmineInterface = jasmineRequire.interface(jasmine, env);
57
+ var jasmineInterface = jasmineRequire["interface"](jasmine, env);
54
58
  extend(window, jasmineInterface);
55
59
  var queryString = new jasmine.QueryString({
56
60
  getWindowLocation: function getWindowLocation() {
57
61
  return window.location;
58
62
  }
59
63
  });
60
- var stoppingOnSpecFailure = queryString.getParam('failFast');
61
- env.stopOnSpecFailure(typeof stoppingOnSpecFailure === 'undefined' ? false : stoppingOnSpecFailure);
62
- var throwingExpectationFailures = queryString.getParam('throwFailures');
63
- env.throwOnExpectationFailure(throwingExpectationFailures);
64
+ var config = {
65
+ failFast: queryString.getParam('failFast'),
66
+ oneFailurePerSpec: queryString.getParam('oneFailurePerSpec'),
67
+ hideDisabled: queryString.getParam('hideDisabled')
68
+ };
64
69
  var random = queryString.getParam('random');
65
- env.randomizeTests(random);
70
+
71
+ if (random !== undefined && random !== '') {
72
+ config.random = random;
73
+ }
74
+
66
75
  var seed = queryString.getParam('seed');
76
+
67
77
  if (seed) {
68
- env.seed(seed);
78
+ config.seed = seed;
69
79
  }
80
+
70
81
  var htmlReporter = new jasmine.HtmlReporter({
71
82
  env: env,
72
- onStopExecutionClick: function onStopExecutionClick() {
73
- queryString.navigateWithNewParam('failFast', env.stoppingOnSpecFailure());
74
- },
75
- onThrowExpectationsClick: function onThrowExpectationsClick() {
76
- queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
77
- },
78
- onRandomClick: function onRandomClick() {
79
- queryString.navigateWithNewParam('random', !env.randomTests());
83
+ navigateWithNewParam: function navigateWithNewParam(key, value) {
84
+ return queryString.navigateWithNewParam(key, value);
80
85
  },
81
86
  addToExistingQueryString: function addToExistingQueryString(key, value) {
82
87
  return queryString.fullStringWithNewParam(key, value);
@@ -90,37 +95,45 @@ function initializePDFJS(callback) {
90
95
  createTextNode: function createTextNode() {
91
96
  return document.createTextNode.apply(document, arguments);
92
97
  },
93
-
94
98
  timer: new jasmine.Timer()
95
99
  });
96
100
  env.addReporter(htmlReporter);
101
+
97
102
  if (queryString.getParam('browser')) {
98
103
  var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
99
104
  env.addReporter(testReporter);
100
105
  }
106
+
101
107
  var specFilter = new jasmine.HtmlSpecFilter({
102
108
  filterString: function filterString() {
103
109
  return queryString.getParam('spec');
104
110
  }
105
111
  });
106
- env.specFilter = function (spec) {
112
+
113
+ config.specFilter = function (spec) {
107
114
  return specFilter.matches(spec.getFullName());
108
115
  };
116
+
117
+ env.configure(config);
109
118
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
110
119
  var currentWindowOnload = window.onload;
120
+
111
121
  window.onload = function () {
112
122
  if (currentWindowOnload) {
113
123
  currentWindowOnload();
114
124
  }
125
+
115
126
  initializePDFJS(function () {
116
127
  htmlReporter.initialize();
117
128
  env.execute();
118
129
  });
119
130
  };
131
+
120
132
  function extend(destination, source) {
121
133
  for (var property in source) {
122
134
  destination[property] = source[property];
123
135
  }
136
+
124
137
  return destination;
125
138
  }
126
139
  })();