Siorki / RegPack

Self-contained packer for size-constrained JS code
Other
299 stars 14 forks source link

Context hashing loop inserted at incorrect offset #43

Open Siorki opened 8 years ago

Siorki commented 8 years ago

Observed : g=a.cloneNode();ac=g.getContext("2d")for(i in ;ac[c.at](innerWidth/)c[i[2]+[i[7]]]=i2,0);ac[c.a](innerHeight/128,innerHeight/128);

Reason : there are several 2D contexts in the code, and some of them are used before the last one is declared. RegPack always insert the hashing loop at the declaration of the last context, yet replaces methods earlier in the code (which in turns changes the offset).

A strategy is needed for cases where a context's methods are called before all contexts are used, such as :

c = a.getContext("2d");
c.fillStyle = "#fff";
c.fillRect(0,0,innerWidth,innerHeight);
na = a.cloneNode();
nc = na.getContext("2d");

One cannot iterate on nc before it is defined. But at this point methods from c have already been used.

Siorki commented 8 years ago

Possible solutions :