Ticket #5303 (new defect)

Opened 9 months ago

Last modified 6 months ago

shrinksafe runtime reference error

Reported by: guest Owned by: alex
Priority: normal Milestone: 1.3
Component: ShrinkSafe Version: 1.0
Severity: normal Keywords:
Cc: sjs@…

Description

Shrinksafe generates bad code when compressing a certain file.

Version info

custom_rhino.jar:: http://download.dojotoolkit.org/release-1.0.1/dojo-release-1.0.1-src.zip

js.jar:: ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_6R7.zip

yuicompressor-2.2.5.jar:: http://www.julienlecomte.net/yuicompressor/yuicompressor-2.2.5.zip

JS Code

sjs@cobra:/tmp/js$ cat bad.js 
(function() {
    CallMe = function(callback) {
        callback();
    };

    var say_hello_twice = function() {
        say_hello();

        CallMe(function(){
            say_hello();
        });
    };

    var say_hello = function() {
        print('hello world');
    };

    say_hello_twice();
})();

Details

The code works uncompressed and when compressed with yuicompressor, but not when compressed with Shrinksafe:

sjs@cobra:/tmp/js$ java -jar js.jar -f bad.js
hello world
hello world

sjs@cobra:/tmp/js$ java -jar custom_rhino.jar -c bad.js | java -jar js.jar -f -
Rhino 1.6 release 7 2007 08 19
js> js: "<stdin>", line 21: uncaught JavaScript runtime exception: ReferenceError: "say_hello" is not defined.
js> js> 

sjs@cobra:/tmp/js$ java -jar yuicompressor-2.2.5.jar bad.js | java -jar js.jar -f -

[INFO] Using charset UTF-8
Rhino 1.6 release 7 2007 08 19
js> hello world
hello world
js> 

The difference is that yuicompressor renamed both references to say_hello, while Shrinksafe only renamed one:

sjs@cobra:/tmp/js$ java -jar custom_rhino.jar -c bad.js
(function(){
CallMe=function(_1){
_1();
};
var _2=function(){
say_hello();
CallMe(function(){
_3();
});
};
var _3=function(){
print("hello world");
};
_2();
})();

sjs@cobra:/tmp/js$ java -jar yuicompressor-2.2.5.jar bad.js

[INFO] Using charset UTF-8
(function(){CallMe=function(C){C()};var B=function(){A();CallMe(function(){A()})};var A=function(){print("hello world")};B()})()

-Stephen

Change History

Changed 6 months ago by dylan

  • milestone set to 1.3
Note: See TracTickets for help on using tickets.