Permalink
Browse files

Stop using named function expressions

IE<9 does some truly messed-up things when it sees these.

Another great JS feature banished for the foreseeable future by
the bunglers in Redmont, sigh.
  • Loading branch information...
1 parent 0118d35 commit e89fa823b9ae0f258c7b7bd44c12e71486bfd534 @marijnh marijnh committed Jan 26, 2013
Showing with 21 additions and 15 deletions.
  1. +12 −9 lib/codemirror.js
  2. +1 −1 mode/coffeescript/coffeescript.js
  3. +2 −2 mode/haxe/haxe.js
  4. +2 −2 mode/javascript/javascript.js
  5. +1 −1 mode/vb/vb.js
  6. +3 −0 test/lint/lint.js
View
@@ -1406,11 +1406,12 @@ window.CodeMirror = (function() {
// Above handler holds on to the editor and its data structures.
// Here we poll to unregister it when the editor is no longer in
// the document, so that it can be garbage-collected.
- setTimeout(function unregister() {
+ function unregister() {
for (var p = d.wrapper.parentNode; p && p != document.body; p = p.parentNode) {}
if (p) setTimeout(unregister, 5000);
else off(window, "resize", onResize);
- }, 5000);
+ }
+ setTimeout(unregister, 5000);
on(d.input, "keyup", operation(cm, function(e) {
if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
@@ -1980,21 +1981,23 @@ window.CodeMirror = (function() {
var extval = display.input.value = " " + (posEq(sel.from, sel.to) ? "" : display.input.value), i = 0;
display.prevInput = " ";
display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
- detectingSelectAll = setTimeout(function poll(){
+ var poll = function(){
if (display.prevInput == " " && display.input.selectionStart == 0)
operation(cm, commands.selectAll)(cm);
else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
else resetInput(cm);
- }, 200);
+ };
+ detectingSelectAll = setTimeout(poll, 200);
}
}
if (gecko) {
e_stop(e);
- on(window, "mouseup", function mouseup() {
+ var mouseup = function() {
off(window, "mouseup", mouseup);
setTimeout(rehide, 20);
- });
+ };
+ on(window, "mouseup", mouseup);
} else {
setTimeout(rehide, 50);
}
@@ -3123,7 +3126,7 @@ window.CodeMirror = (function() {
on(textarea.form, "submit", save);
var form = textarea.form, realSubmit = form.submit;
try {
- form.submit = function wrappedSubmit() {
+ var wrappedSubmit = form.submit = function() {
save();
form.submit = realSubmit;
form.submit();
@@ -4119,7 +4122,7 @@ window.CodeMirror = (function() {
};
var nextDocId = 0;
- var Doc = CodeMirror.Doc = function Doc(text, mode, firstLine) {
+ var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
if (firstLine == null) firstLine = 0;
@@ -5064,7 +5067,7 @@ window.CodeMirror = (function() {
// Browsers seem to always treat the boundaries of block elements as being L.
var outerType = "L";
- return function charOrdering(str) {
+ return function(str) {
if (!bidiRE.test(str)) return false;
var len = str.length, types = [];
for (var i = 0, type; i < len; ++i)
@@ -170,7 +170,7 @@ CodeMirror.defineMode('coffeescript', function(conf) {
function tokenFactory(delimiter, outclass) {
var singleline = delimiter.length == 1;
- return function tokenString(stream, state) {
+ return function(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"\/\\]/);
if (stream.eat('\\')) {
View
@@ -235,7 +235,7 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
poplex.lex = true;
function expect(wanted) {
- return function expecting(type) {
+ return function(type) {
if (type == wanted) return cont();
else if (wanted == ";") return pass();
else return cont(arguments.callee);
@@ -330,7 +330,7 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
if (type == end) return cont();
return cont(expect(end));
}
- return function commaSeparated(type) {
+ return function(type) {
if (type == end) return cont();
else return pass(what, proceed);
};
@@ -242,7 +242,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
poplex.lex = true;
function expect(wanted) {
- return function expecting(type) {
+ return function(type) {
if (type == wanted) return cont();
else if (wanted == ";") return pass();
else return cont(arguments.callee);
@@ -307,7 +307,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == end) return cont();
return cont(expect(end));
}
- return function commaSeparated(type) {
+ return function(type) {
if (type == end) return cont();
else return pass(what, proceed);
};
View
@@ -159,7 +159,7 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
var singleline = delimiter.length == 1;
var OUTCLASS = 'string';
- return function tokenString(stream, state) {
+ return function(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"]/);
if (stream.match(delimiter)) {
View
@@ -72,6 +72,9 @@ function checkFile(fileName) {
cur.vars[node.name].used = true;
return;
}
+ },
+ FunctionExpression: function(node) {
+ if (node.id) fail("Named function expression", node.loc);
}
}, scopePasser);

0 comments on commit e89fa82

Please sign in to comment.