Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: use of return outside of functions is deprecated #1670

Closed
Photodeus opened this issue Nov 22, 2012 · 1 comment
Closed

Warning: use of return outside of functions is deprecated #1670

Photodeus opened this issue Nov 22, 2012 · 1 comment
Milestone

Comments

@Photodeus
Copy link

Some userscripts have a return statement in top level code, which gives a warning in the Firefox error console.

Is it possible to add a line number where the offending piece of return is located?
I have a few huge scripts (developed by others) with ~20k lines of source and can't find what triggers this error message.

in greasemonkey.js:

function runScriptInSandbox(script, sandbox) {
  // Eval the code, with anonymous wrappers when/if appropriate.
  function evalWithWrapper(code, fileName) {
    try {
      Components.utils.evalInSandbox(code, sandbox, gMaxJSVersion, fileName, 1);
    } catch (e) {
      if ("return not in function" == e.message) {
        // See #1592; we never anon wrap anymore, unless forced to by a return
        // not in a function.
        GM_util.logError(
            gStringBundle.GetStringFromName('return-not-in-func-deprecated'),
            true // is a warning
--> maybe add fileName and e.lineNumber here?
            );
        Components.utils.evalInSandbox(
            GM_util.anonWrap(code), sandbox, gMaxJSVersion, fileName, 1);
      } else {
        // Otherwise raise.
        throw e;
      }
    }
  }

Not sure know how to patch this, but looking at evalWithCatch() seems to suggest it's easily done.

@Photodeus
Copy link
Author

Okay tested adding the two lines, seems to work as intended:

295c295,297
<             true // is a warning
---
>             true, // is a warning
>             fileName,
>             e.lineNumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants