Changeset 732

Show
Ignore:
Timestamp:
04/15/08 08:33:30 (8 months ago)
Author:
oyasu..@gmail.com
Message:

As a top-level "return" throws a compile-time error without executing any code, if a script depends on that feature, wrap it in the old-style empty function enclosure and retry. All other scripts get the benefit of their top level functions and variables living on the global object (this).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/global-object/components/greasemonkey.js

    r694 r732  
    303303      script.offsets = offsets; 
    304304 
    305       var scriptSrc = "(function(){\n" + 
     305      var scriptSrc = "\n" + // error line-number calculations depend on these 
    306306                         requires.join("\n") + 
    307307                         "\n" + 
    308308                         contents + 
    309                          "\n})()"; 
    310       this.evalInSandbox(scriptSrc, 
    311                          url, 
    312                          sandbox, 
    313                          script); 
     309                         "\n"; 
     310      if (!this.evalInSandbox(scriptSrc, url, sandbox, script)) 
     311        this.evalInSandbox("(function(){"+ scriptSrc +"})()", 
     312                           url, sandbox, script); 
    314313    } 
    315314  }, 
     
    347346        Components.utils.evalInSandbox(code, sandbox); 
    348347      } catch (e) { 
     348        if ("return not in function" == e.message) // pre-0.8 GM compat: 
     349          return false; // this script depends on the function enclosure 
     350 
    349351        // try to find the line of the actual error line 
    350352        var line = e.lineNumber; 
     
    379381      } 
    380382    } 
     383    return true; // did not need a (function() {...})() enclosure. 
    381384  }, 
    382385