As requested, try this for polygons other than rectangles. This should work for the text frame whose centre lies within the path (without depending on the bounding boxes).
var doc = app.activeDocument;
var items = doc.pathItems;
var text = doc.textFrames;
for (var i = items.length - 1; i > -1; i--) {
for (var j = text.length - 1; j > -1; j--) {
var textBounds = text[j].geometricBounds;
var centre = [
textBounds[0] + ((textBounds[2] - textBounds[0]) / 2),
textBounds[1] + ((textBounds[3] - textBounds[1]) / 2)
];
if (pointIsInPoly(items[i].pathPoints, centre)) {
items[i].name = text[j].contents;
text[j].remove();
continue;
}
}
}
// Jonas Raoni Soares Silva
// http://jsfromhell.com/math/is-point-in-poly
function pointIsInPoly(poly, pt){
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i].anchor[1] <= pt[1] && pt[1] < poly[j].anchor[1]) ||
(poly[j].anchor[1] <= pt[1] && pt[1] < poly[i].anchor[1]))
&&
(pt[0] <
(poly[j].anchor[0] - poly[i].anchor[0]) * (pt[1] - poly[i].anchor[1]) /
(poly[j].anchor[1] - poly[i].anchor[1]) + poly[i].anchor[0])
&&
(c = !c);
return c;
}