2

So it seems that debugging is getting a new meaning, at least in Closure Compiler.

I have a rather big code base, and isolating the problem is a difficult task. In my entry point class I instantiate the dependencies. One of these, is not created correctly, the object is there, but its constructor is not being called.

This only happens in ADVANCED mode, so I tried to pass --debug flag, and voila, the bug is gone, the constructor gets called. It's mind blowing. I can't copy paste any particular code, what would you suggest?

/**
 * @param {Element} parent
 * @param {Object}  opts
 * @constructor
 */
ns.App = function(parent, opts) {
    this.options = new ns.Options(opts || {});

    var w = this.options.width || parent.offsetWidth;
    var h = this.options.height || parent.offsetHeight;
    this.view = new ns.AppView(w, h);
    this.history = new ns.CommandManager();

    // ....

    // this one doesn't get called
    this.amx_ = new ns.ActivityManager(this, this.options);
    // this one does
    this.output_ = new ns.Writer();
    this.bind_();
};
5
  • 3
    when debugging solves a problem, its generally an indication that you have a race condition.
    – jbabey
    Commented Aug 31, 2012 at 12:42
  • 1
    @jbabey While I agree with you in general that this has the symptoms of a race condition, in JS (being single-threaded) I don't think this is possible. Commented Aug 31, 2012 at 12:52
  • @OliverWeiler most javascript bugs are race conditions, it is possible and probable.
    – jbabey
    Commented Aug 31, 2012 at 12:53
  • @jbabey that's not true, and it doesn't really matter as it is not really helping solve the problem. If you don't have a good knowledge of closure compiler, don't bother.
    – skrat
    Commented Aug 31, 2012 at 12:55
  • @skrat can you post the code you use to "instantiate the dependencies" (the pre-compiled version)?
    – jbabey
    Commented Aug 31, 2012 at 13:02

1 Answer 1

2

With Closure-compiler, when the debug flag makes the error go away it usually indicates that you have a renaming collision. This can be caused by setting properties on an externally defined object who's properties are not completely defined to the compiler. The compiler renames your property to the same name as an existing property.

This can also be caused by referencing a property using dotted syntax (obj.prop) where it was declared using quoted syntax (obj['prop']). By definition, the compiler sees these as different properties.

Make sure you turn on --warning_level VERBOSE to help identify accessing undefined properties. Although it is still possible that your particular case won't be recognized.

3
  • Well, I'm not sure whether renaming was the issue, but with --warning_level VERBOSE, I resolved some tiny issues, and now it seems to work ok. It still doesn't explain why this.amx_ = new ns.ActivityManager() wasn't called, and stuff above and below was.
    – skrat
    Commented Aug 31, 2012 at 14:57
  • Agree with Chad totally. --debug is used primarily to resolve naming issues. It doesn't do anything except rename things to a predictable name. If --debug solves it, then it is a naming issue. The bug may be more subtle than you realize. For example, understand that Closure renames variables first to single-characters, then to double-characters. Are you sure you don't have things in your webapp that can potentially conflict with these names? Bear in mind that attributes on DOM nodes are case NON-SENSITIVE, so if something is renamed "iD", it will overwrite the DOM node's "id". Commented Sep 3, 2012 at 2:59
  • I'd suggest you look into what ns.ActivityManager is being renamed to and check whether it conflicts with or gets overwritten by something with a similar name... Commented Sep 3, 2012 at 3:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.