Opened 12 years ago

Closed 11 years ago

Last modified 10 years ago

#5303 closed defect (duplicate)

shrinksafe runtime reference error

Reported by: guest Owned by: alex
Priority: high Milestone: future
Component: ShrinkSafe Version: 1.0
Keywords: Cc: sjs@…
Blocked By: Blocking:

Description (last modified by bill)

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 (6)

comment:1 Changed 12 years ago by dylan

Milestone: 1.3

comment:2 Changed 11 years ago by bill

Description: modified (diff)
Milestone: 1.3future

move unowned / abandoned tickets to "future" milestone

comment:3 Changed 11 years ago by Adam Peller

Resolution: duplicate
Status: newclosed

this example works as of trunk 2009-01-26, probably as a result of upgrading to Rhino 1.7 (see #7127)

I believe this is a dup of #3241

comment:4 Changed 11 years ago by Adam Peller

(In [16542]) Create Shrinksafe unit tests. Refs #5303

comment:5 Changed 11 years ago by Adam Peller

(In [16543]) Refactor shrinksafe unit test. Refs #5303

comment:6 Changed 10 years ago by Adam Peller

(In [16909]) restructure and improve existing shrinksafe test. Refs #5303

Note: See TracTickets for help on using tickets.