77
88// LLVM => JavaScript compiler, main entry point
99
10- var nodeFS = require ( 'fs' ) ;
11- nodePath = require ( 'path' ) ;
10+ global . nodeFS = require ( 'fs' ) ;
11+ global . nodePath = require ( 'path' ) ;
1212
13- print = ( x ) => {
13+ global . print = ( x ) => {
1414 process [ 'stdout' ] . write ( x + '\n' ) ;
1515} ;
1616
17- printErr = ( x ) => {
17+ global . printErr = ( x ) => {
1818 process [ 'stderr' ] . write ( x + '\n' ) ;
1919} ;
2020
2121function find ( filename ) {
22- var prefixes = [ __dirname , process . cwd ( ) ] ;
23- for ( var i = 0 ; i < prefixes . length ; ++ i ) {
24- var combined = nodePath . join ( prefixes [ i ] , filename ) ;
22+ const prefixes = [ __dirname , process . cwd ( ) ] ;
23+ for ( let i = 0 ; i < prefixes . length ; ++ i ) {
24+ const combined = nodePath . join ( prefixes [ i ] , filename ) ;
2525 if ( nodeFS . existsSync ( combined ) ) {
2626 return combined ;
2727 }
2828 }
2929 return filename ;
3030}
3131
32- read = ( filename ) => {
33- var absolute = find ( filename ) ;
32+ global . read = ( filename ) => {
33+ const absolute = find ( filename ) ;
3434 return nodeFS . readFileSync ( absolute ) . toString ( ) ;
3535} ;
3636
@@ -45,22 +45,23 @@ load('utility.js');
4545load ( './settings.js' ) ;
4646load ( './settings_internal.js' ) ;
4747
48- var arguments_ = process [ 'argv' ] . slice ( 2 ) ;
49- var settingsFile = arguments_ [ 0 ] ;
48+ const settingsFile = process [ 'argv' ] [ 2 ] ;
5049
5150if ( settingsFile ) {
52- var settings = JSON . parse ( read ( settingsFile ) ) ;
53- for ( var key in settings ) {
54- var value = settings [ key ] ;
55- if ( value [ 0 ] == '@' ) {
56- // response file type thing, workaround for large inputs: value is @path-to-file
57- try {
58- value = JSON . parse ( read ( value . substr ( 1 ) ) ) ;
59- } catch ( e ) {
60- // continue normally; assume it is not a response file
51+ const settings = JSON . parse ( read ( settingsFile ) ) ;
52+ for ( const key in settings ) {
53+ if ( Object . prototype . hasOwnProperty . call ( settings , key ) ) {
54+ let value = settings [ key ] ;
55+ if ( value [ 0 ] == '@' ) {
56+ // response file type thing, workaround for large inputs: value is @path-to-file
57+ try {
58+ value = JSON . parse ( read ( value . substr ( 1 ) ) ) ;
59+ } catch ( e ) {
60+ // continue normally; assume it is not a response file
61+ }
6162 }
63+ global [ key ] = eval ( JSON . stringify ( value ) ) ;
6264 }
63- global [ key ] = eval ( JSON . stringify ( value ) ) ;
6465 }
6566}
6667
@@ -72,7 +73,7 @@ INCOMING_MODULE_JS_API = new Set(INCOMING_MODULE_JS_API);
7273RUNTIME_DEBUG = LIBRARY_DEBUG || GL_DEBUG || DYLINK_DEBUG || PTHREADS_DEBUG ;
7374
7475// Side modules are pure wasm and have no JS
75- assert ( ! SIDE_MODULE , " JS compiler should not run on side modules" ) ;
76+ assert ( ! SIDE_MODULE , ' JS compiler should not run on side modules' ) ;
7677
7778// Output some info and warnings based on settings
7879
@@ -87,17 +88,17 @@ load('parseTools.js');
8788load ( 'jsifier.js' ) ;
8889load ( 'runtime.js' ) ;
8990
90- //===============================
91+ // ===============================
9192// Main
92- //===============================
93+ // ===============================
9394
9495B = new Benchmarker ( ) ;
9596
9697try {
97- JSify ( ) ;
98+ runJSify ( ) ;
9899
99100 B . print ( 'glue' ) ;
100- } catch ( err ) {
101+ } catch ( err ) {
101102 if ( err . toString ( ) . includes ( 'Aborting compilation due to previous errors' ) ) {
102103 // Compiler failed on user error, don't print the stacktrace in this case.
103104 printErr ( err ) ;
0 commit comments