"Oh no, sir, no ... Dobby will have to punish himself most grievously for coming to see you, sir. Dobby will have to shut his ears in the oven door for this. If they ever knew, sir --"
I am not quite sure if I understand the phrase "shut his ears in the oven door". Is it he cut his ears off and put it into the oven or he cut his ears off by shutting the oven door?
How should we understand the phrase?
-- Excerpted from Harry Potter.