Merge pull request #11771 from Snuffleupagus/issue-11762
Fail early, in modern `GENERIC` builds, if certain required browser functionality is missing (issue 11762)
This commit is contained in:
		
						commit
						7ed71a0d7c
					
				
							
								
								
									
										4
									
								
								external/dist/lib/README.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								external/dist/lib/README.md
									
									
									
									
										vendored
									
									
								
							| @ -3,5 +3,5 @@ pre-built library as found in e.g. the `/build`, `/web`, and `/image_decoders` | |||||||
| folders in the root of this repository. | folders in the root of this repository. | ||||||
| 
 | 
 | ||||||
| Please note that the "lib" build target exists mostly to enable unit-testing in | Please note that the "lib" build target exists mostly to enable unit-testing in | ||||||
| Node.js/Travis, and that you'll need to handle e.g. any Node.js dependencies | Node.js/Travis, and that you'll need to handle e.g. any necessary polyfills | ||||||
| yourself if using the files in this folder. | and/or Node.js dependencies yourself if using the files in this folder. | ||||||
|  | |||||||
							
								
								
									
										43
									
								
								gulpfile.js
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								gulpfile.js
									
									
									
									
									
								
							| @ -1150,9 +1150,7 @@ gulp.task("jsdoc", function(done) { | |||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| gulp.task( | function buildLib(defines, dir) { | ||||||
|   "lib", |  | ||||||
|   gulp.series("buildnumber", "default_preferences", function() { |  | ||||||
|   // When we create a bundle, webpack is run on the source and it will replace
 |   // When we create a bundle, webpack is run on the source and it will replace
 | ||||||
|   // require with __webpack_require__. When we want to use the real require,
 |   // require with __webpack_require__. When we want to use the real require,
 | ||||||
|   // __non_webpack_require__ has to be used.
 |   // __non_webpack_require__ has to be used.
 | ||||||
| @ -1171,8 +1169,7 @@ gulp.task( | |||||||
|   } |   } | ||||||
|   function preprocess(content) { |   function preprocess(content) { | ||||||
|     var skipBabel = |     var skipBabel = | ||||||
|         bundleDefines.SKIP_BABEL || |       bundleDefines.SKIP_BABEL || /\/\*\s*no-babel-preset\s*\*\//.test(content); | ||||||
|         /\/\*\s*no-babel-preset\s*\*\//.test(content); |  | ||||||
|     content = preprocessor2.preprocessPDFJSCode(ctx, content); |     content = preprocessor2.preprocessPDFJSCode(ctx, content); | ||||||
|     content = babel.transform(content, { |     content = babel.transform(content, { | ||||||
|       sourceType: "module", |       sourceType: "module", | ||||||
| @ -1190,19 +1187,14 @@ gulp.task( | |||||||
|       ], |       ], | ||||||
|     }).code; |     }).code; | ||||||
|     var removeCjsSrc = /^(var\s+\w+\s*=\s*(_interopRequireDefault\()?require\(".*?)(?:\/src)(\/[^"]*"\)\)?;)$/gm; |     var removeCjsSrc = /^(var\s+\w+\s*=\s*(_interopRequireDefault\()?require\(".*?)(?:\/src)(\/[^"]*"\)\)?;)$/gm; | ||||||
|       content = content.replace( |     content = content.replace(removeCjsSrc, (all, prefix, interop, suffix) => { | ||||||
|         removeCjsSrc, |  | ||||||
|         (all, prefix, interop, suffix) => { |  | ||||||
|       return prefix + suffix; |       return prefix + suffix; | ||||||
|         } |     }); | ||||||
|       ); |  | ||||||
|     return licenseHeaderLibre + content; |     return licenseHeaderLibre + content; | ||||||
|   } |   } | ||||||
|   var babel = require("@babel/core"); |   var babel = require("@babel/core"); | ||||||
|   var versionInfo = getVersionJSON(); |   var versionInfo = getVersionJSON(); | ||||||
|     var bundleDefines = builder.merge(DEFINES, { |   var bundleDefines = builder.merge(defines, { | ||||||
|       GENERIC: true, |  | ||||||
|       LIB: true, |  | ||||||
|     BUNDLE_VERSION: versionInfo.version, |     BUNDLE_VERSION: versionInfo.version, | ||||||
|     BUNDLE_BUILD: versionInfo.commit, |     BUNDLE_BUILD: versionInfo.commit, | ||||||
|     TESTING: process.env["TESTING"] === "true", |     TESTING: process.env["TESTING"] === "true", | ||||||
| @ -1235,7 +1227,28 @@ gulp.task( | |||||||
|     gulp.src("test/unit/*.js", { base: "." }), |     gulp.src("test/unit/*.js", { base: "." }), | ||||||
|   ]) |   ]) | ||||||
|     .pipe(transform("utf8", preprocess)) |     .pipe(transform("utf8", preprocess)) | ||||||
|       .pipe(gulp.dest("build/lib/")); |     .pipe(gulp.dest(dir)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | gulp.task( | ||||||
|  |   "lib", | ||||||
|  |   gulp.series("buildnumber", "default_preferences", function() { | ||||||
|  |     var defines = builder.merge(DEFINES, { GENERIC: true, LIB: true }); | ||||||
|  | 
 | ||||||
|  |     return buildLib(defines, "build/lib/"); | ||||||
|  |   }) | ||||||
|  | ); | ||||||
|  | 
 | ||||||
|  | gulp.task( | ||||||
|  |   "lib-es5", | ||||||
|  |   gulp.series("buildnumber", "default_preferences", function() { | ||||||
|  |     var defines = builder.merge(DEFINES, { | ||||||
|  |       GENERIC: true, | ||||||
|  |       LIB: true, | ||||||
|  |       SKIP_BABEL: false, | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     return buildLib(defines, "build/lib-es5/"); | ||||||
|   }) |   }) | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
| @ -1371,7 +1384,7 @@ gulp.task("baseline", function(done) { | |||||||
| 
 | 
 | ||||||
| gulp.task( | gulp.task( | ||||||
|   "unittestcli", |   "unittestcli", | ||||||
|   gulp.series("testing-pre", "lib", function(done) { |   gulp.series("testing-pre", "lib-es5", function(done) { | ||||||
|     var options = [ |     var options = [ | ||||||
|       "node_modules/jasmine/bin/jasmine", |       "node_modules/jasmine/bin/jasmine", | ||||||
|       "JASMINE_CONFIG_PATH=test/unit/clitests.json", |       "JASMINE_CONFIG_PATH=test/unit/clitests.json", | ||||||
|  | |||||||
| @ -136,6 +136,21 @@ var WorkerMessageHandler = { | |||||||
|             "; thus breaking e.g. `for...in` iteration of `Array`s." |             "; thus breaking e.g. `for...in` iteration of `Array`s." | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|  | 
 | ||||||
|  |       // Ensure that (primarily) Node.js users won't accidentally attempt to use
 | ||||||
|  |       // a non-translated/non-polyfilled build of the library, since that would
 | ||||||
|  |       // quickly fail anyway because of missing functionality (such as e.g.
 | ||||||
|  |       // `ReadableStream).
 | ||||||
|  |       if ( | ||||||
|  |         (typeof PDFJSDev === "undefined" || PDFJSDev.test("SKIP_BABEL")) && | ||||||
|  |         typeof ReadableStream === "undefined" | ||||||
|  |       ) { | ||||||
|  |         throw new Error( | ||||||
|  |           "The browser/environment lacks native support for critical " + | ||||||
|  |             "functionality used by the PDF.js library (e.g. `ReadableStream`); " + | ||||||
|  |             "please use an ES5-compatible build instead." | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     var docId = docParams.docId; |     var docId = docParams.docId; | ||||||
|  | |||||||
| @ -14,11 +14,9 @@ | |||||||
|  */ |  */ | ||||||
| /* eslint no-var: error */ | /* eslint no-var: error */ | ||||||
| 
 | 
 | ||||||
| // Skip compatibility checks for modern builds (unless we're running the
 | // Skip compatibility checks for modern builds and if we already ran the module.
 | ||||||
| // unit-tests in Node.js/Travis) and if we already ran the module.
 |  | ||||||
| if ( | if ( | ||||||
|   (typeof PDFJSDev === "undefined" || |   (typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) && | ||||||
|     PDFJSDev.test("!SKIP_BABEL || (LIB && TESTING)")) && |  | ||||||
|   (typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked) |   (typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked) | ||||||
| ) { | ) { | ||||||
|   // Provides support for globalThis in legacy browsers.
 |   // Provides support for globalThis in legacy browsers.
 | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| { | { | ||||||
|   "spec_dir": "build/lib/test/unit", |   "spec_dir": "build/lib-es5/test/unit", | ||||||
| 
 | 
 | ||||||
|   "helpers": [ |   "helpers": [ | ||||||
|     "clitests_helper.js" |     "clitests_helper.js" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user