CodeQL documentation

Illegal invocation

ID: js/illegal-invocation
Kind: problem
Security severity: 
Severity: error
Precision: high
Tags:
   - quality
   - reliability
   - correctness
   - language-features
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

Class methods and arrow functions must not be invoked using new, and attempting to do so will result in a runtime error.

Conversely, constructors can only be invoked using new or super(...), and attempting to invoke them as a normal function will result in a runtime error.

Recommendation

Correct the invocation in question by adding or removing new as appropriate.

Example

In the following example, Point is a class, but on line 8 it is invoked without new. This will lead to a runtime error.

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

let p = Point(23, 42);

Instead, new should be used:

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

let p = new Point(23, 42);

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy