Commit 6b7f7edc authored by ggaren's avatar ggaren

JavaScriptCore:

        Reviewed by Maciej Stachowiak.
        
        Fixed http://bugs.webkit.org/show_bug.cgi?id=15490
        Iteration statements sometimes incorrectly evaluate to the empty value 
        (KDE r670547). 
        
        [ Broken off from http://bugs.webkit.org/show_bug.cgi?id=14868 ]
        
        This patch is a merge of KDE r670547, with substantial modification 
        for performance.
        
        It fixes do-while statements to evaluate to a value. (They used
        to evaluate to the empty value in all cases.) 

        It also fixes SourceElementsNode to maintain the value of abnormal 
        completions like "break" and "continue."
        
        It also re-works the main execution loop in SourceElementsNode so that
        it (1) makes a little more sense and (2) avoids unnecessary work. This 
        is a .28% speedup on command-line JS iBench.

        * kjs/nodes.cpp:
        (DoWhileNode::execute):
        (SourceElementsNode::execute):

LayoutTests:

        Reviewed by Maciej Stachowiak.
        
        Layout tests for http://bugs.webkit.org/show_bug.cgi?id=15490
        Iteration statements sometimes incorrectly evaluate to the empty value 
        (KDE r670547)        

        * fast/js/do-while-expression-value-expected.txt: Added.
        * fast/js/do-while-expression-value.html: Added.
        * fast/js/while-expression-value-expected.txt: Added.
        * fast/js/while-expression-value.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@26617 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f9941240
2007-10-12 Geoffrey Garen <ggaren@apple.com>
Reviewed by Maciej Stachowiak.
Fixed http://bugs.webkit.org/show_bug.cgi?id=15490
Iteration statements sometimes incorrectly evaluate to the empty value
(KDE r670547).
[ Broken off from http://bugs.webkit.org/show_bug.cgi?id=14868 ]
This patch is a merge of KDE r670547, with substantial modification
for performance.
It fixes do-while statements to evaluate to a value. (They used
to evaluate to the empty value in all cases.)
It also fixes SourceElementsNode to maintain the value of abnormal
completions like "break" and "continue."
It also re-works the main execution loop in SourceElementsNode so that
it (1) makes a little more sense and (2) avoids unnecessary work. This
is a .28% speedup on command-line JS iBench.
* kjs/nodes.cpp:
(DoWhileNode::execute):
(SourceElementsNode::execute):
2007-10-15 Simon Hausmann <hausmann@kde.org>
Reviewed by Lars.
......
......@@ -52,6 +52,7 @@ namespace KJS {
ComplType complType() const { return comp; }
JSValue *value() const { return val; }
void setValue(JSValue* v) { val = v; }
Identifier target() const { return tar; }
bool isValueCompletion() const { return !!val; }
private:
......
......@@ -1807,6 +1807,7 @@ Completion DoWhileNode::execute(ExecState *exec)
JSValue *bv;
Completion c;
JSValue* value = 0;
do {
// bail out on error
......@@ -1819,9 +1820,12 @@ Completion DoWhileNode::execute(ExecState *exec)
if (exec->dynamicInterpreter()->timedOut())
return Completion(Interrupted);
if (c.isValueCompletion())
value = c.value();
if (!((c.complType() == Continue) && ls.contains(c.target()))) {
if ((c.complType() == Break) && ls.contains(c.target()))
return Completion(Normal, 0);
return Completion(Normal, value);
if (c.complType() != Normal)
return c;
}
......@@ -1829,7 +1833,7 @@ Completion DoWhileNode::execute(ExecState *exec)
KJS_CHECKEXCEPTION
} while (bv->toBoolean(exec));
return Completion(Normal, 0);
return Completion(Normal, value);
}
void DoWhileNode::processVarDecls(ExecState *exec)
......@@ -2559,23 +2563,22 @@ SourceElementsNode::SourceElementsNode(SourceElementsNode *s1, StatementNode *s2
Completion SourceElementsNode::execute(ExecState *exec)
{
KJS_CHECKEXCEPTION
JSValue* v = 0;
SourceElementsNode* n = this;
while (1) {
Completion c = n->node->execute(exec);
Completion c1 = node->execute(exec);
KJS_CHECKEXCEPTION;
if (c1.complType() != Normal)
return c1;
for (SourceElementsNode *n = next.get(); n; n = n->next.get()) {
Completion c2 = n->node->execute(exec);
if (c2.complType() != Normal)
return c2;
// The spec says to return c2 here, but it seems that mozilla returns c1 if
// c2 doesn't have a value
if (c2.value())
c1 = c2;
if (JSValue* v2 = c.value())
v = v2;
c.setValue(v);
if (c.complType() != Normal)
return c;
n = n->next.get();
if (!n)
return c;
}
return c1;
}
// ECMA 14
......
2007-10-13 Geoffrey Garen <ggaren@apple.com>
Reviewed by Maciej Stachowiak.
Layout tests for http://bugs.webkit.org/show_bug.cgi?id=15490
Iteration statements sometimes incorrectly evaluate to the empty value
(KDE r670547)
* fast/js/do-while-expression-value-expected.txt: Added.
* fast/js/do-while-expression-value.html: Added.
* fast/js/while-expression-value-expected.txt: Added.
* fast/js/while-expression-value.html: Added.
2007-10-15 Darin Adler <darin@apple.com>
Reviewed by Sam.
......
This page tests the evaluated value of a do-while expression.
PASS: x should be 1 and is.
PASS: x should be 1 and is.
PASS: x should be 1 and is.
PASS: x should be 1 and is.
<p>This page tests the evaluated value of a do-while expression.</p>
<pre id="console"></pre>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(s)
{
document.getElementById("console").appendChild(document.createTextNode(s + "\r\n"));
}
function shouldBe(a, b)
{
var evalA;
try {
evalA = eval(a);
} catch(e) {
evalA = e;
}
if (evalA === b) {
log("PASS: " + a + " should be " + b + " and is.");
} else {
log("FAIL: " + a + " should be " + b + " but instead is " + evalA + ".");
}
}
var x;
x = eval("do { 1; } while(0);");
shouldBe("x", 1);
var x = eval("do { 1; break; } while(0);");
shouldBe("x", 1);
var x = eval("do { 1; continue; } while(0);");
shouldBe("x", 1);
var x = eval("do { 1; ; } while(0);");
shouldBe("x", 1);
</script>
This page tests the evaluated value of a while expression.
PASS: x should be 1 and is.
PASS: x should be 1 and is.
PASS: x should be 1 and is.
PASS: x should be 1 and is.
<p>This page tests the evaluated value of a while expression.</p>
<pre id="console"></pre>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function log(s)
{
document.getElementById("console").appendChild(document.createTextNode(s + "\r\n"));
}
function shouldBe(a, b)
{
var evalA;
try {
evalA = eval(a);
} catch(e) {
evalA = e;
}
if (evalA === b) {
log("PASS: " + a + " should be " + b + " and is.");
} else {
log("FAIL: " + a + " should be " + b + " but instead is " + evalA + ".");
}
}
var x, condition;
condition = true;
x = eval("while (condition) { condition = false; 1; }");
shouldBe("x", 1);
condition = true;
var x = eval("while (condition) { condition = false; 1; break; }");
shouldBe("x", 1);
condition = true;
var x = eval("while (condition) { condition = false; 1; continue; }");
shouldBe("x", 1);
condition = true;
var x = eval("while (condition) { condition = false; 1; ; }");
shouldBe("x", 1);
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment