Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery exceptions using Internet Explorer 11 & ASP .NET

When I'm navigating through my ASP .NET site I'm getting the following JQuery exceptions while using Internet Explorer. Also, I'm using Telerik Controls suite for ASP .NET & Visual Studio 2012.

enter image description here

If I check for the line numbers in ScriptResource.axd?d=... (Telerik's file):

/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */

a.querySelectorAll("*,:x"), //Line 10673

s.call(a,"[s!='']:x"), //Line 10898

And in my jquery-2.1.0.min.js:

/*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */

a.querySelectorAll("*,:x") //Line 10357

q.call(a,"[s!='']:x") //Line 10571

In both files I'm getting an exception in the same two sentences. Those exceptions are not causing extrange behaviour but I don't like to see them in Visual Studio as there might be a signal that something is wrong.

NOTE: If i remove Telerik's JQuery or Standard JQuery the error still there. Even if i set the Telerik's JQuery to use the standar one the error still there. Also, NO errors in console.

What's happening?

like image 964
DiegoS Avatar asked Jan 31 '17 14:01

DiegoS


2 Answers

Short answer:

There is nothing wrong with jquery - sometimes it do its own 'dirty' business to make your hands clean since sometimes there is no 'clean' way to do what needs to be done

TLDR;

Long answer:

It seems like in both cases you saw caught errors from jQuery, since, according to Telerik documentation, some Telerik controls depends on jQuery - so you would have jQuery out of box

About exceptions - after jQuery loads, its do a feature detection - as you know, browser behavior vary for each browser/version and often there is no way to do detection without trying using features and catching exceptions if the feature is not supported

For example the first exception (at a.querySelectorAll("*,:x")) happens when jquery do a feature detection for selectors supported by document.querySelectorAll - you can simply find it in by searching at github or in any non minified jquery file:

// Opera 10-11 does not throw on post-comma invalid pseudos
el.querySelectorAll("*,:x");
rbuggyQSA.push(",.*:");

As you can see its intended behavior and there is no way to avoid it as long as you have jquery on your page

like image 78
Igor B Avatar answered Oct 05 '22 23:10

Igor B


The jQuery team uses exceptions in certain situations for logic flow. They uses the assert function to do feature detection for each browser. If you look into the jQuery code, you could find the assert function like the following

function assert( fn ) {
    var el = document.createElement("fieldset");

    try {
        return !!fn( el );
    } catch (e) {
        return false;
    } finally {
        // Remove from its parent by default
        if ( el.parentNode ) {
            el.parentNode.removeChild( el );
        }
        // release memory in IE
        el = null;
    }
}

To desmontrate, I've created a sample asp.net webpage that using jQuery 3.1.1. When I run the webpage locally, selecting Internet Explorer and run it within Visual Studio, it will raise the exceptions like this

...
'iexplore.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'. 
Exception was thrown at line 1361, column 4 in http://localhost:63177/Scripts/jquery-3.1.1.js
0x800a139e - JavaScript 実行時エラー: SyntaxError
Exception was thrown at line 1379, column 4 in http://localhost:63177/Scripts/jquery-3.1.1.js
0x800a139e - JavaScript 実行時エラー: SyntaxError
Exception was thrown at line 37, column 60610 in http://localhost:63409/15db952270ca47e19969bb659e432c6d/browserLink
0x800a139e - JavaScript 実行時エラー: SyntaxError
The thread 0x5250 has exited with code 0 (0x0).
...

Looking at lines 1361 and 1379 in jQuery 3.1.1 code, you will find these error was raised on purpose.

Line 1360-1361

// Opera 10-11 does not throw on post-comma invalid pseudos
el.querySelectorAll("*,:x");

Line 1377-1379

// This should fail with an exception
// Gecko does not error, returns false instead
matches.call( el, "[s!='']:x" );

Since the exception was handled, the jQuery team don't consider it a problem. You could refer the similar problem as the following link https://bugs.jquery.com/ticket/14123

It's intended codes of jQuery, so I think you could leave it as it is.

like image 33
Trung Duong Avatar answered Oct 05 '22 23:10

Trung Duong