Yes. It is a bug. Thank you for reporting it.
The last ray should be a total reflection ray. However, the ray was treated emmitted from air to glass, so the code did something wrong.
It is fixed now.

The above simulation was designed such that you can use javascript to change the shape of the polygon (px,py) and the position of laser point(xs,ys).

You do not need to re-compile the EJS. For you case :

Suppose the name for the EJS applet is "polygonsn". The following two javascript call will set up the above configuration.
document.polygonsn._setVariables("n=4;px=10,-50,100,100;py=-30,30,30,-30;xs=-90;ys=-25");//set up the above parameters
document.polygonsn._model.setit();// Some parameters need to re-calculate according to the above change,this is the method defined as Custom code
EJS variables are decleared as global variables, so you can change it with _setVariables (";" separated variable assignment , use "," to separate indicidual array (variable) values.

I just added another option so that user can edit coordinate for polygon in the popup window (when table is checked).
There is a second tabbed panel which display coordinate for the polygon points (it is editable).
However, only the fist N rows are useful (You can adjust N with slider).