I need to load an image synchronously, that is I need to pause execution of javascript until the image is loaded. Since image.onload is asynchronous, the main function will
Can't this be solved by refactoring?
Wrap whatever code you need to execute after the image load into a function invoked by the callback (or make that function the callbak).
I see that you say that if the main function returns, other code will execute. Can you wrap that, too? Can you delay it's execution or make it dependent on this onload event or someother event?
You could even dynamically load the source of the other javascript code in the image onload.