@@ -452,6 +452,7 @@ exports.XMLHttpRequest = function() {
452
452
self . dispatchEvent ( "loadstart" ) ;
453
453
} else { // Synchronous
454
454
// Create a temporary file for communication with the other Node process
455
+ var contentFile = ".node-xmlhttprequest-content-" + process . pid ;
455
456
var syncFile = ".node-xmlhttprequest-sync-" + process . pid ;
456
457
fs . writeFileSync ( syncFile , "" , "utf8" ) ;
457
458
// The async request the other Node process executes
@@ -462,28 +463,33 @@ exports.XMLHttpRequest = function() {
462
463
+ "var req = doRequest(options, function(response) {"
463
464
+ "response.setEncoding('utf8');"
464
465
+ "response.on('data', function(chunk) {"
465
- + "responseText += chunk;"
466
+ + " responseText += chunk;"
466
467
+ "});"
467
468
+ "response.on('end', function() {"
468
- + "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
469
+ + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
470
+ + "fs.unlinkSync('" + syncFile + "');"
469
471
+ "});"
470
472
+ "response.on('error', function(error) {"
471
- + "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
473
+ + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
474
+ + "fs.unlinkSync('" + syncFile + "');"
472
475
+ "});"
473
476
+ "}).on('error', function(error) {"
474
- + "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
477
+ + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
478
+ + "fs.unlinkSync('" + syncFile + "');"
475
479
+ "});"
476
480
+ ( data ? "req.write('" + data . replace ( / ' / g, "\\'" ) + "');" :"" )
477
481
+ "req.end();" ;
478
482
// Start the other Node Process, executing this string
479
483
var syncProc = spawn ( process . argv [ 0 ] , [ "-e" , execString ] ) ;
480
- while ( ( self . responseText = fs . readFileSync ( syncFile , 'utf8' ) ) == "" ) {
481
- // Wait while the file is empty
484
+ var statusText ;
485
+ while ( fs . existsSync ( syncFile ) ) {
486
+ // Wait while the sync file is empty
482
487
}
488
+ self . responseText = fs . readFileSync ( contentFile , 'utf8' ) ;
483
489
// Kill the child process once the file has data
484
490
syncProc . stdin . end ( ) ;
485
491
// Remove the temporary file
486
- fs . unlinkSync ( syncFile ) ;
492
+ fs . unlinkSync ( contentFile ) ;
487
493
if ( self . responseText . match ( / ^ N O D E - X M L H T T P R E Q U E S T - E R R O R : / ) ) {
488
494
// If the file returned an error, handle it
489
495
var errorObj = self . responseText . replace ( / ^ N O D E - X M L H T T P R E Q U E S T - E R R O R : / , "" ) ;
0 commit comments