kayahr / console-shim

Browser console compatibility shim for legacy JavaScript engines
MIT License
86 stars 16 forks source link

@cc_on is slow and breaks jquery-migrate #7

Open meelash opened 11 years ago

meelash commented 11 years ago

Please see the discussion here: http://bugs.jquery.com/ticket/13274

Paul Irish recommends using this: https://gist.github.com/padolsey/527683 instead of @cc_on because it is slow.

dmp42 commented 11 years ago

The reason for why "it" (or anything else using conditional compilation) breaks jquery is because they use @ in comments (which I don't quite get why it's not stripped out by minification, but that's a different topic). Anyhow, @cc_off should prevent any such side effect, and should definitely be done.

As for manipulating the DOM instead of using @cc:

meelash commented 11 years ago

It's not that @ is in the comments, it's a special keyword, added after minification for creating source maps for the browser debugger: http://net.tutsplus.com/tutorials/tools-and-tips/source-maps-101/

@cc_off does indeed solve the problem, but doesn't it make sense for you to do that at the end of your code, rather than forcing other people to add it to their code for defensive purposes? Also, @cc_off affects following code.

Regarding cc being slower, I don't have any numbers, just quoting from that link. I've asked for clarification there. But from my understanding, it's not a question of the actually cc call being slow, but rather the use of cc forces turning off js optimizations therefore causing all future evaluations to be slower. Perhaps paul will share some info about this with us.

meelash commented 11 years ago

Anyway, at least for me, the problem was solved by the jquery-migrate crew by removing source maps, which apparently were being generated by mistake, anyway.

dmp42 commented 11 years ago

"@cc_off does indeed solve the problem, but doesn't it make sense for you to do that at the end of your code, rather than forcing other people to add it to their code for defensive purposes?"

Absolutely. This should be fixed in console-shim code.

"Also, @cc_off affects following code."

It's quite hard to find proper documentation about conditional compilation. Do you by any chance have further links/infos about cc_off behavior in IE, or cc impact on IE perf? Even MSDN doesn't seem to have references about cc_off :( (http://msdn.microsoft.com/en-US/library/ahx1z4fs(v=vs.100).aspx)

Thanks a lot!

kayahr commented 11 years ago

Can you please give me an example how to use @cc_off? I can't find any documentation about this or any example and when I try to use it in IE myself I just get syntax errors or no effect (conditional compilation is still active)

dmp42 commented 11 years ago

Have you tried:

if (window["consoleShimTest"] != null || eval("/_@cc_on @_jscript_version <= 9 @ccoff @/")) {

That's supposed to be the syntax for console.

Put otherwise eval(/_@cc_on doSomething(); @ccoff @/)

kayahr commented 11 years ago

Doesn't work here. I still can get the @_jscript_version after @cc_off. That's what I mean, it has no effect. Maybe it depends on IE version? Tested on IE9 standard mode. I guess it's safest to use the other solution instead (Creating DOM elements with conditional comments). This solution doesn't work in IE10 but in this case it doesn't matter because I have to check for IE <=9 anyway.

kayahr commented 11 years ago

By the way: It looks like IE is caching expression results. So if you run @_jscript_version BEFORE @cc_on and then trying again with the same expression AFTER @cc_on then you get no result. Example:

/_@_jscriptversion@/ => No result because CC is off /_@ccon@/ /_@_jscriptversion@/ => Still no result (Most likely cached) /_@_jscriptversion @/ => Now outputs the JScript version, the whitespace helped.

So to test if @cc_off works I did this:

/_@_jscriptversion < 7 @/ => No result because CC is off /_@ccon@/ /_@_jscriptversion < 8 @/ => Return boolean result /_@ccoff@/ /_@_jscriptversion < 9 @/ => Still returns boolean result, so CC is still active

So it looks to me that this @ccoff is a myth. I can also run /@ccdeactivateThisStinkingMess@/ with the same result.

dmp42 commented 11 years ago

"So it looks to me that this @cc_off is a myth."

Or existed in previous versions of IE and has been removed.

What a mess :/

meelash commented 11 years ago

Agreed about the mess. ;) It seems like it only exists in the memory of people who've used this feature back in the day and I can't find any reference to it in the docs either.

evil-shrike commented 7 years ago

This conditional compilation code (eval("/*@cc_on @_jscript_version <= 9@*/"))) doesn't work correctly in a case of higher version IE emulates lower version. For example, if in IE11 we switch document mode to IE8 then that eval return false and console methods won't be wrapped.

It seems the cc check can be easily replaced with document.documentMode < 9.