Skip to content

Module define environment

Siorki edited this page Aug 13, 2016 · 2 revisions

Define environment

Principle

This module removes all references to Math inside the code and encapsulates it inside a with(Math) block :

...
x=Math.cos(a*Math.PI*t);
y=Math.sin(a*Math.PI*t);
...

becomes

with(Math){
...
x=cos(a*PI*t);
y=sin(a*PI*t);
...
}

Warning : this module may shave a few bytes of the code, but usually causes a large performance hit, since upon execution Javascript will look for every global name (mostly your variables and functions) inside the Math object first.

Inner clockwork

All references to Math.foo() and Math.bar are replaced respectively by foo() and bar. The encapsulation with(Math) is prepended to the function evaluating the unpacked code (either eval() or setInterval()).

Options

Parameter name Type Default Effect
withMath boolean false enable or disable the module

In RegPack v1 to v3, the option is activated by choosing the button "Pack with(Math)".
In RegPack v4+, the option is activated by the checkbox "Encapsulate with(Math)".

Implementation

Extraction of the environment is performed in Shapeshifter.preprocess() which stores it as PackerData.environment. It is then featured in the unpacking routines created by the different stages in the class RegPack.

Clone this wiki locally