зеркало из https://github.com/mozilla/gecko-dev.git
Bug 776317 - Separate the body of a constructed function from its braces with newlines. r=luke
This commit is contained in:
Родитель
f6aa463f03
Коммит
4cd03908be
|
@ -40,7 +40,7 @@ function runTests() {
|
|||
root.setAttribute("onclick", listenerSource);
|
||||
infos = els.getListenerInfoFor(root, {});
|
||||
is(infos.length, 1, "Element should have listeners (1)");
|
||||
is(infos[0].toSource(), 'function onclick(event) { ' + listenerSource + ' }',
|
||||
is(infos[0].toSource(), 'function onclick(event) {\n' + listenerSource + '\n}',
|
||||
"Unexpected serialization (1)");
|
||||
is(infos[0].type, "click", "Wrong type (1)");
|
||||
is(infos[0].capturing, false, "Wrong phase (1)");
|
||||
|
|
|
@ -45,10 +45,10 @@ div.onload = f;
|
|||
is(div.onload, f, "Should have 'f' as div's onload");
|
||||
div.setAttribute("onload", "");
|
||||
isnot(div.onload, f, "Should not longer have 'f' as div's onload");
|
||||
is(div.onload.toString(), "function onload(event) { }",
|
||||
is(div.onload.toString(), "function onload(event) {\n\n}",
|
||||
"Should have wrapped empty string in a function");
|
||||
div.setAttribute("onload", "foopy();");
|
||||
is(div.onload.toString(), "function onload(event) { foopy(); }",
|
||||
is(div.onload.toString(), "function onload(event) {\nfoopy();\n}",
|
||||
"Should have wrapped call in a function");
|
||||
div.removeAttribute("onload");
|
||||
is(div.onload, null, "Should have null onload now");
|
||||
|
@ -69,11 +69,11 @@ function testPropagationToWindow(eventName) {
|
|||
|
||||
document.body.setAttribute("on"+eventName, eventName);
|
||||
is(window["on"+eventName].toString(),
|
||||
"function on"+eventName+"(event) { "+eventName+" }",
|
||||
"function on"+eventName+"(event) {\n"+eventName+"\n}",
|
||||
"Setting on"+eventName+"attribute on body should propagate to window");
|
||||
document.createElement("body").setAttribute("on"+eventName, eventName+"2");
|
||||
is(window["on"+eventName].toString(),
|
||||
"function on"+eventName+"(event) { "+eventName+"2 }",
|
||||
"function on"+eventName+"(event) {\n"+eventName+"2\n}",
|
||||
"Setting on"+eventName+"attribute on body outside the document should propagate to window");
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=689564
|
|||
var div = document.createElement("div");
|
||||
div.setAttribute("onclick", "div");
|
||||
is(window.onclick, null, "div should not forward onclick");
|
||||
is(div.onclick.toString(), "function onclick(event) { div }",
|
||||
is(div.onclick.toString(), "function onclick(event) {\ndiv\n}",
|
||||
"div should have an onclick handler");
|
||||
|
||||
div.setAttribute("onscroll", "div");
|
||||
is(window.onscroll, null, "div should not forward onscroll");
|
||||
is(div.onscroll.toString(), "function onscroll(event) { div }",
|
||||
is(div.onscroll.toString(), "function onscroll(event) {\ndiv\n}",
|
||||
"div should have an onscroll handler");
|
||||
|
||||
div.setAttribute("onpopstate", "div");
|
||||
|
@ -36,25 +36,25 @@ is(div.onpopstate, null, "div should not have onpopstate handler");
|
|||
var body = document.createElement("body");
|
||||
body.setAttribute("onclick", "body");
|
||||
is(window.onclick, null, "body should not forward onclick");
|
||||
is(body.onclick.toString(), "function onclick(event) { body }",
|
||||
is(body.onclick.toString(), "function onclick(event) {\nbody\n}",
|
||||
"body should have an onclick handler");
|
||||
body.setAttribute("onscroll", "body");
|
||||
is(window.onscroll.toString(), "function onscroll(event) { body }",
|
||||
is(window.onscroll.toString(), "function onscroll(event) {\nbody\n}",
|
||||
"body should forward onscroll");
|
||||
body.setAttribute("onpopstate", "body");
|
||||
is(window.onpopstate.toString(), "function onpopstate(event) { body }",
|
||||
is(window.onpopstate.toString(), "function onpopstate(event) {\nbody\n}",
|
||||
"body should forward onpopstate");
|
||||
|
||||
var frameset = document.createElement("frameset");
|
||||
frameset.setAttribute("onclick", "frameset");
|
||||
is(window.onclick, null, "frameset should not forward onclick");
|
||||
is(frameset.onclick.toString(), "function onclick(event) { frameset }",
|
||||
is(frameset.onclick.toString(), "function onclick(event) {\nframeset\n}",
|
||||
"frameset should have an onclick handler");
|
||||
frameset.setAttribute("onscroll", "frameset");
|
||||
is(window.onscroll.toString(), "function onscroll(event) { frameset }",
|
||||
is(window.onscroll.toString(), "function onscroll(event) {\nframeset\n}",
|
||||
"frameset should forward onscroll");
|
||||
frameset.setAttribute("onpopstate", "frameset");
|
||||
is(window.onpopstate.toString(), "function onpopstate(event) { frameset }",
|
||||
is(window.onpopstate.toString(), "function onpopstate(event) {\nframeset\n}",
|
||||
"frameset should forward onpopstate");
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
var f = Function("a", "b", "return a + b;");
|
||||
assertEq(f.toString(), "function anonymous(a, b) { return a + b; }");
|
||||
assertEq(f.toSource(), "(function anonymous(a, b) { return a + b; })");
|
||||
assertEq(f.toString(), "function anonymous(a, b) {\nreturn a + b;\n}");
|
||||
assertEq(f.toSource(), "(function anonymous(a, b) {\nreturn a + b;\n})");
|
||||
assertEq(decompileFunction(f), f.toString());
|
||||
assertEq(decompileBody(f), "return a + b;");
|
||||
f = Function("a", "...rest", "return rest[42] + b;");
|
||||
assertEq(f.toString(), "function anonymous(a, ...rest) { return rest[42] + b; }");
|
||||
assertEq(f.toSource(), "(function anonymous(a, ...rest) { return rest[42] + b; })")
|
||||
assertEq(f.toString(), "function anonymous(a, ...rest) {\nreturn rest[42] + b;\n}");
|
||||
assertEq(f.toSource(), "(function anonymous(a, ...rest) {\nreturn rest[42] + b;\n})")
|
||||
assertEq(decompileFunction(f), f.toString());
|
||||
assertEq(decompileBody(f), "return rest[42] + b;");
|
||||
f = Function("x", "return let (y) x;");
|
||||
assertEq(f.toSource(), "(function anonymous(x) { return let (y) x; })");
|
||||
assertEq(f.toSource(), "(function anonymous(x) {\nreturn let (y) x;\n})");
|
||||
f = Function("");
|
||||
assertEq(f.toString(), "function anonymous() { }");
|
||||
assertEq(f.toString(), "function anonymous() {\n\n}");
|
||||
f = Function("", "(abc)");
|
||||
assertEq(f.toString(), "function anonymous() { (abc) }");
|
||||
assertEq(f.toString(), "function anonymous() {\n(abc)\n}");
|
||||
f = Function("", "return function (a, b) a + b;")();
|
||||
assertEq(f.toString(), "function (a, b) a + b");
|
||||
|
|
|
@ -7,8 +7,8 @@ function test(str, arg, result)
|
|||
|
||||
var fun = new Function('x', str);
|
||||
|
||||
var got = fun.toSource().replace(/\n/g,'');
|
||||
var expect = '(function anonymous(x) { ' + str + ' })';
|
||||
var got = fun.toSource();
|
||||
var expect = '(function anonymous(x) {\n' + str + '\n})';
|
||||
if (got !== expect) {
|
||||
print("GOT: " + got);
|
||||
print("EXPECT: " + expect);
|
||||
|
|
|
@ -641,7 +641,7 @@ JSFunction::toString(JSContext *cx, bool bodyOnly, bool lambdaParen)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
if (!out.append(") { "))
|
||||
if (!out.append(") {\n"))
|
||||
return NULL;
|
||||
}
|
||||
if ((bodyOnly && !funCon) || addUseStrict) {
|
||||
|
@ -678,7 +678,7 @@ JSFunction::toString(JSContext *cx, bool bodyOnly, bool lambdaParen)
|
|||
return NULL;
|
||||
}
|
||||
if (buildBody) {
|
||||
if (!out.append(" }"))
|
||||
if (!out.append("\n}"))
|
||||
return NULL;
|
||||
}
|
||||
if (bodyOnly) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче