mirror of https://github.com/webpack/webpack.git
				
				
				
			fix: address some comments
This commit is contained in:
		
							parent
							
								
									24a95745f1
								
							
						
					
					
						commit
						b34ed237cf
					
				|  | @ -4,46 +4,47 @@ | ||||||
| 	*/ | 	*/ | ||||||
| "use strict"; | "use strict"; | ||||||
| 
 | 
 | ||||||
| const Queue = require("../util/Queue"); |  | ||||||
| const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); |  | ||||||
| const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError"); | const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError"); | ||||||
| 
 | 
 | ||||||
|  | const error = new UnsupportedWebAssemblyFeatureError( | ||||||
|  | 	"JavaScript modules can not use a WebAssembly export with an incompatible type signature" | ||||||
|  | ); | ||||||
|  | 
 | ||||||
| class WasmFinalizeExportsPlugin { | class WasmFinalizeExportsPlugin { | ||||||
| 	apply(compiler) { | 	apply(compiler) { | ||||||
| 		compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => { | 		compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => { | ||||||
| 			compilation.hooks.finishModules.tap( | 			compilation.hooks.finishModules.tap( | ||||||
| 				"WasmFinalizeExportsPlugin", | 				"WasmFinalizeExportsPlugin", | ||||||
| 				modules => { | 				modules => { | ||||||
| 					const queue = new Queue(); |  | ||||||
| 
 |  | ||||||
| 					let module; |  | ||||||
| 					let jsIncompatibleExports = []; |  | ||||||
| 
 |  | ||||||
| 					for (const module of modules) { | 					for (const module of modules) { | ||||||
| 						if (module.buildMeta.jsIncompatibleExports) { | 						const jsIncompatibleExports = | ||||||
| 							jsIncompatibleExports.push( | 							module.buildMeta.jsIncompatibleExports; | ||||||
| 								...module.buildMeta.jsIncompatibleExports | 
 | ||||||
| 							); | 						if ( | ||||||
|  | 							typeof jsIncompatibleExports === "undefined" || | ||||||
|  | 							jsIncompatibleExports.length === 0 | ||||||
|  | 						) { | ||||||
|  | 							continue; | ||||||
| 						} | 						} | ||||||
| 
 | 
 | ||||||
| 						queue.enqueue(module); | 						// 1. if a WebAssembly module
 | ||||||
| 					} | 						if (module.type.startsWith("webassembly") === true) { | ||||||
|  | 							for (const reason of module.reasons) { | ||||||
|  | 								// 2. is referenced by a non-WebAssembly module
 | ||||||
|  | 								if (reason.module.type.startsWith("webassembly") === false) { | ||||||
|  | 									// const ref = reason.dependency.getReference();
 | ||||||
| 
 | 
 | ||||||
| 					while (queue.length > 0) { | 									// ref.importedNames // returns true?
 | ||||||
| 						module = queue.dequeue(); |  | ||||||
| 
 | 
 | ||||||
| 						// 1. if a non WebAssembly module
 | 									const names = []; | ||||||
| 						if (module.type.startsWith("webassembly") === false) { | 
 | ||||||
| 							for (const dep of module.dependencies) { | 									names.forEach(name => { | ||||||
| 								// 2. imports a WebAssembly module
 | 										// 3. and uses a func with an incompatible JS signature
 | ||||||
| 								// FIXME(sven): pseudo code from here
 | 										if (jsIncompatibleExports.indexOf(name) !== -1) { | ||||||
| 								if (dep.type === "webassembly") { | 											// 4. error
 | ||||||
| 									// 3. if the used import is flaged as invalid
 | 											compilation.errors.push(error); | ||||||
| 									if (jsIncompatibleExports.indexOf(dep.usedName)) { |  | ||||||
| 										throw new UnsupportedWebAssemblyFeatureError( |  | ||||||
| 											"JavaScript modules can not use WebAssembly export with an incompatible type signature" |  | ||||||
| 										); |  | ||||||
| 										} | 										} | ||||||
|  | 									}); | ||||||
| 								} | 								} | ||||||
| 							} | 							} | ||||||
| 						} | 						} | ||||||
|  |  | ||||||
|  | @ -1,9 +1,13 @@ | ||||||
| it("should disallow exporting a func signature with result i64", function() { | it("should disallow exporting a func signature with result i64", function() { | ||||||
|     return expect(import("./export-i64-result.wat")).rejects.toThrow(/invalid type/); | 	return import("./export-i64-result.wat").then(({a}) => { | ||||||
|  | 		expect(a).toThrow(/invalid type/); | ||||||
|  | 	}); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| it("should disallow exporting a func signature with param i64", function() { | it("should disallow exporting a func signature with param i64", function() { | ||||||
|     return expect(import("./export-i64-param.wat")).rejects.toThrow(/invalid type/); | 	return import("./export-i64-param.wat").then(({a}) => { | ||||||
|  | 		expect(a).toThrow(/invalid type/); | ||||||
|  | 	}); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| it("should disallow importing a value type of i64", function() { | it("should disallow importing a value type of i64", function() { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue