Skip to content

$j.isError_ incorrectly assumes function with WebSocket event #1623

@peter-backlund-sg

Description

@peter-backlund-sg

Expected Behavior

Should conclude that incoming value is not an Error.

Current Behavior

Tries to invoke a string as a function, which fails with "Function expected".

Possible Solution

This if-statement in j$.isError

    if (value && value.constructor && value.constructor.constructor &&
      (value instanceof (value.constructor.constructor('return this')()).Error)) {
      return true;
    }

assumes that value.constructor.constructor('return this') evaluates to a function (and calls it). This is not always the case. I have a combination of Jasmine, Karma, Typesript, RxJs and WebSocket (puh!) where the incoming value parameter is a WebSocket open event.

In IE the expression value.constructor.constructor evaluates to Object where in Chrome it evaluates to Function. Calling that with the argument 'return this' creates a string object in IE but a function that returns a string in Chrome.

We are using this override now, that has a more defensive approach:

jasmine.isError_ = function (value) {
    if (value instanceof Error) {
        return true;
    }
    if (value && value.constructor && value.constructor.constructor) {
        var vccTarget = value.constructor.constructor('return this');
        if (typeof vccTarget === 'function') {
            vccTarget = vccTarget();
        }
        if (vccTarget.Error && (value instanceof vccTarget.Error)) {
            return true;
        }
    }
    return false;
};

Your Environment

  • Version used: 3.1.0
  • Environment name and version: IE11
  • Operating System and version: Windows 7 x64
  • Link to your project: Commercial

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions