@@ -9,50 +9,12 @@ const { decode } = require("@webassemblyjs/wasm-parser");
99
1010const { Tapable } = require ( "tapable" ) ;
1111const WebAssemblyImportDependency = require ( "./dependencies/WebAssemblyImportDependency" ) ;
12- const { readFileSync } = require ( "fs" ) ;
13- const { join } = require ( "path" ) ;
1412
1513const decoderOpts = {
1614 ignoreCodeSection : true ,
1715 ignoreDataSection : true
1816} ;
1917
20- // FIXME(sven): probably a better way of doing this?
21- function getSource ( context , request ) {
22- const path = require . resolve ( join ( context , request ) ) ;
23- return readFileSync ( path , "utf8" ) ;
24- }
25-
26- // FIXME(sven): probably a better way of doing this?
27- function ensureExported ( source , request ) {
28- const hasExport = source . indexOf ( "export " ) !== - 1 ;
29-
30- if ( hasExport === false ) {
31- const error = new Error (
32- request + " must export the Memory or Table object."
33- ) ;
34-
35- error . stack = "" ;
36-
37- throw error ;
38- }
39- }
40-
41- // FIXME(sven): probably a better way of doing this?
42- function ensureIdentNotAccessed ( source , request , ident ) {
43- const occurence = source . match ( new RegExp ( ident , "g" ) ) . length ;
44-
45- if ( occurence > 1 ) {
46- const error = new Error (
47- request + " is not allowed to access the Memory or Table object (yet)."
48- ) ;
49-
50- error . stack = "" ;
51-
52- throw error ;
53- }
54- }
55-
5618class WebAssemblyParser extends Tapable {
5719 constructor ( options ) {
5820 super ( ) ;
@@ -82,15 +44,6 @@ class WebAssemblyParser extends Tapable {
8244 ) ;
8345
8446 state . module . addDependency ( dep ) ;
85-
86- // To avoid unexpected behaviors we check that the Memory or Table
87- // has been exported and is not accessed by the user.
88- if ( node . descr . type === "Memory" || node . descr . type === "Table" ) {
89- const content = getSource ( state . module . context , node . module ) ;
90-
91- ensureExported ( content , node . module ) ;
92- ensureIdentNotAccessed ( content , node . module , node . name ) ;
93- }
9447 }
9548 } ) ;
9649
0 commit comments