Both chambers of the state legislature voted Wednesday night in favor of Gov. Dannel P. Malloy’s controversial plan to recruit the nonprofit Jackson Laboratory to Farmington with a $291 million offer to construct a new building and create 300 direct jobs over the next 10 years. On a strict party line vote, the Senate voted 21 to 14 in favor of the measure. Sen. Edwin Gomes, a Bridgeport Democrat, missed the vote because he is recovering at his home following a recent heart attack.