If you invest in the stock market, that's not an emergency fund. It's an investment you plan to sell during emergencies, which will be a good or bad decision based on stock market performance between now and your next emergency. It's as risky as it sounds.
A more traditional emergency fund is in cash (CDs, checking account, money market, etc). The money won't lose value, and will be there when you need it.