mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 11:27:49 +00:00

Currently omj/TokenStream and omj/optimizer/Optimizer.java both contain code to convert number value to a wrapper object of smallest size. The attached patch moves this wrapping to Node constructor to avoid code duplication and eliminate special treatment of exact integers in Optimizer.java. The constant folding code in omj/optimizer/Optimizer.java currently always replaces x * 1, x - 0 by simply x which does not force the toNumber convertion, which is visible, for example, via typeof. For example, when running at optimization level 2, the following function f() { return "0" * 1; } print(typeof(f())); prints "string" instead of expected "number". The const_fold.patch fixes this via replacing x*1 by (+x) to force number convertion. It assumes that the patch with number wrapping changes is in place.