From fb13cf8973e39428aa7cf50cbbb6bbdc6b66a10b Mon Sep 17 00:00:00 2001 From: "nboyd%atg.com" Date: Fri, 9 Oct 2009 17:27:18 +0000 Subject: [PATCH] Fix bug Bug 519692 - Failed to decompile expressions like "new Date()" Patch from Marc Guillemot. git-svn-id: svn://10.0.0.236/trunk@258649 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/org/mozilla/javascript/IRFactory.java | 6 ++-- mozilla/js/rhino/testsrc/opt-1.tests | 3 -- mozilla/js/rhino/testsrc/opt0.tests | 3 -- mozilla/js/rhino/testsrc/opt9.tests | 3 -- .../javascript/tests/DecompileTest.java | 33 +++++++++++++++++++ 5 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/DecompileTest.java diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/IRFactory.java b/mozilla/js/rhino/src/org/mozilla/javascript/IRFactory.java index 5a716a403d0..5156d1a412c 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/IRFactory.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/IRFactory.java @@ -692,8 +692,7 @@ public final class IRFactory extends Parser Node nx = createCallOrNew(Token.NEW, transform(node.getTarget())); nx.setLineno(node.getLineno()); List args = node.getArguments(); - if (!args.isEmpty()) - decompiler.addToken(Token.LP); + decompiler.addToken(Token.LP); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); nx.addChildToBack(transform(arg)); @@ -701,8 +700,7 @@ public final class IRFactory extends Parser decompiler.addToken(Token.COMMA); } } - if (!args.isEmpty()) - decompiler.addToken(Token.RP); + decompiler.addToken(Token.RP); if (node.getInitializer() != null) { nx.addChildToBack(transformObjectLiteral(node.getInitializer())); } diff --git a/mozilla/js/rhino/testsrc/opt-1.tests b/mozilla/js/rhino/testsrc/opt-1.tests index d3d267ae10d..74701319a33 100644 --- a/mozilla/js/rhino/testsrc/opt-1.tests +++ b/mozilla/js/rhino/testsrc/opt-1.tests @@ -1353,10 +1353,8 @@ js1_5/decompilation/regress-349663.js js1_5/decompilation/regress-350670.js js1_5/decompilation/regress-351625.js js1_5/decompilation/regress-351626.js -js1_5/decompilation/regress-351705.js js1_5/decompilation/regress-352022.js js1_5/decompilation/regress-352073.js -js1_5/decompilation/regress-352312.js js1_5/decompilation/regress-352360.js js1_5/decompilation/regress-352873-01.js js1_5/decompilation/regress-352873-02.js @@ -1366,7 +1364,6 @@ js1_5/decompilation/regress-354910.js js1_5/decompilation/regress-371692.js js1_5/decompilation/regress-373678.js js1_5/decompilation/regress-375639.js -js1_5/decompilation/regress-376564.js js1_5/decompilation/regress-383721.js js1_5/decompilation/regress-406555.js js1_5/extensions/catchguard-001.js diff --git a/mozilla/js/rhino/testsrc/opt0.tests b/mozilla/js/rhino/testsrc/opt0.tests index 28ba3f44958..cb485f807a6 100644 --- a/mozilla/js/rhino/testsrc/opt0.tests +++ b/mozilla/js/rhino/testsrc/opt0.tests @@ -1349,10 +1349,8 @@ js1_5/decompilation/regress-349663.js js1_5/decompilation/regress-350670.js js1_5/decompilation/regress-351625.js js1_5/decompilation/regress-351626.js -js1_5/decompilation/regress-351705.js js1_5/decompilation/regress-352022.js js1_5/decompilation/regress-352073.js -js1_5/decompilation/regress-352312.js js1_5/decompilation/regress-352360.js js1_5/decompilation/regress-352873-01.js js1_5/decompilation/regress-352873-02.js @@ -1362,7 +1360,6 @@ js1_5/decompilation/regress-354910.js js1_5/decompilation/regress-371692.js js1_5/decompilation/regress-373678.js js1_5/decompilation/regress-375639.js -js1_5/decompilation/regress-376564.js js1_5/decompilation/regress-383721.js js1_5/decompilation/regress-406555.js js1_5/extensions/catchguard-001.js diff --git a/mozilla/js/rhino/testsrc/opt9.tests b/mozilla/js/rhino/testsrc/opt9.tests index 28ba3f44958..cb485f807a6 100644 --- a/mozilla/js/rhino/testsrc/opt9.tests +++ b/mozilla/js/rhino/testsrc/opt9.tests @@ -1349,10 +1349,8 @@ js1_5/decompilation/regress-349663.js js1_5/decompilation/regress-350670.js js1_5/decompilation/regress-351625.js js1_5/decompilation/regress-351626.js -js1_5/decompilation/regress-351705.js js1_5/decompilation/regress-352022.js js1_5/decompilation/regress-352073.js -js1_5/decompilation/regress-352312.js js1_5/decompilation/regress-352360.js js1_5/decompilation/regress-352873-01.js js1_5/decompilation/regress-352873-02.js @@ -1362,7 +1360,6 @@ js1_5/decompilation/regress-354910.js js1_5/decompilation/regress-371692.js js1_5/decompilation/regress-373678.js js1_5/decompilation/regress-375639.js -js1_5/decompilation/regress-376564.js js1_5/decompilation/regress-383721.js js1_5/decompilation/regress-406555.js js1_5/extensions/catchguard-001.js diff --git a/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/DecompileTest.java b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/DecompileTest.java new file mode 100644 index 00000000000..077fa4acdbf --- /dev/null +++ b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/DecompileTest.java @@ -0,0 +1,33 @@ +package org.mozilla.javascript.tests; + + +import org.junit.Assert; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.ContextAction; +import org.mozilla.javascript.Script; + +/** + * Test for {@link Context#decompileScript(Script, int)}. + * @author Marc Guillemot + */ +public class DecompileTest { + + /** + * As of head of trunk on 30.09.09, decompile of "new Date()" returns "new Date" without parentheses. + * @see Bug 519692 + */ + @Test + public void newObject0Arg() + { + final String source = "var x = new Date().getTime();"; + final ContextAction action = new ContextAction() { + public Object run(final Context cx) { + final Script script = cx.compileString(source, "my script", 0, null); + Assert.assertEquals(source, cx.decompileScript(script, 4).trim()); + return null; + } + }; + Utils.runWithAllOptimizationLevels(action); + } +}