padolsey/jsapi-info

Resolving of extension classes causes bad source links

drewwells opened this issue · 2 comments

This one will be hard to reproduce. OpenLayers has definitions that look like this:

OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.XYZ, {
  name: "OpenStreetMap",
  attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
  sphericalMercator: true,
  url: 'http://tile.openstreetmap.org/${z}/${x}/${y}.png',
  ...
}

When you view OpenLayers.Layer.OSM, you get this:

function(){ P.apply(this, arguments); };

The definition of OpenLayers.Class looks like so:

OpenLayers.Class = function() {
    var len = arguments.length;
    var P = arguments[0];
    var F = arguments[len-1];

    var C = typeof F.initialize == "function" ?
        F.initialize :
        function(){ P.prototype.initialize.apply(this, arguments); };

    if (len > 1) {
        var newArgs = [C, P].concat(
            Array.prototype.slice.call(arguments).slice(1, len-1), F);
        OpenLayers.inherit.apply(null, newArgs);
    } else {
        C.prototype = F;
    }
    return C;
};

It seems OSM is being resolved to via OpenLayers.Class and pointing to the closure they used to extend the object. Any ideas on how to un-foobar this?

Right now, this entire project works on the presumption that the fully qualified name that you provide will reference a function and that function's source will lead to what you're looking for. In this case, the actual function that gets assigned to OpenLayers.Layer.OSM is no where near where you want to be.

I can't think of any easy way to fix this. The only thing to do would be to add an additional case to the SourceHandler where it has to try first to locate the item by traditional means, i.e. scan source for OpenLayers.Layer.OSM = ... -- and then somehow work out where the definition stops... This wouldn't solve all cases though. There's no way to get at everything, short of writing an entire JS parser and extracting the required info.

That was my black box assumption of the issue. It would be hard to analyze every situation where the meat of a function was not easily exposed. Thanks for looking into this.