SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-92

Rule: Prohibit use of obsolete arguments.caller and arguments.callee

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      • Title
        Prohibit use of obsolete arguments.caller and arguments.callee
      • Description
        Both arguments.caller and arguments.callee make quite a few optimizations impossible so they were deprecated in latest versions of JavaScript. In fact, EcmaScript 5 forbids the use of arguments.callee in strict mode.

      Example with the caller property :

      function whoCalled() {
         if (arguments.caller == null)   //Non-Compliant
            console.log('I was called from the global scope.');
         else
            console.log(arguments.caller + ' called me!');
      }
      
      • Violation message
        Remove use of arguments.xxxx
      • Default severity
        Critical

      Part of Sonar Way quality profile

      Origin : JSHint

        Issue Links

          Activity

          Hide
          Evgeny Mandrikov added a comment - - edited

          Should be noted that according to https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode?redirectlocale=en-US&redirectslug=JavaScript%2FStrict_mode "arguments.callee" and "arguments.caller" not supported in strict mode (SONARPLUGINS-2508):

          function fun() {
            "use strict";
            arguments.callee; // throws a TypeError
            arguments.caller; // throws a TypeError
          }
          
          Show
          Evgeny Mandrikov added a comment - - edited Should be noted that according to https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode?redirectlocale=en-US&redirectslug=JavaScript%2FStrict_mode "arguments.callee" and "arguments.caller" not supported in strict mode ( SONARPLUGINS-2508 ): function fun() { "use strict" ; arguments.callee; // throws a TypeError arguments.caller; // throws a TypeError }
          Hide
          Linda Martin added a comment -

          Assigned to you @Ann for specification. Thank you!

          Show
          Linda Martin added a comment - Assigned to you @Ann for specification. Thank you!
          Hide
          G. Ann Campbell added a comment -

          missing functionName.caller and functionName.arguments

          Show
          G. Ann Campbell added a comment - missing functionName.caller and functionName.arguments
          Hide
          Linda Martin added a comment -

          Added.

          Show
          Linda Martin added a comment - Added.
          Hide
          G. Ann Campbell added a comment -

          looks good

          Show
          G. Ann Campbell added a comment - looks good

            People

            • Assignee:
              Linda Martin
              Reporter:
              Freddy Mallet
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: