Bug 42182 - Change how numeric compare functions are detected
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Jul 2010 20:34:11 +0000 (20:34 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Jul 2010 20:34:11 +0000 (20:34 +0000)
commitb467c4c6a693b9e17709728106e2712e4b7d9633
treee96b0053dbf579017e552bf44751290d8c01faba
parent968aabd44a636a490d93cf590e77de56fbdd462c
Bug 42182 - Change how numeric compare functions are detected

Reviewed by Oliver Hunt.

JavaScriptCore:

There are three problems with the current mechanism:
  * It requires that a function executable be bytecode compiled without
    being JIT generated (in order to copy the bytecode from the numeric
    compare function).  This is a problem since we have an invariant when
    running with the JIT that functions are never bytecode compiled without
    also being JIT generated (after checking the codeblock we assume the
    function has JIT code).  To help maintain this invariant
  * This implementation will prevent us from experimenting with alternate
    compilation paths which do not compile via bytecode.
  * It doesn't work.  Functions passing more than two arguments will match
    if they are comparing their last two arguments, not the first two.
    Generally the mapping back from bytecode to semantics may be more
    complex then initially expected.

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::setIsNumericCompareFunction):
(JSC::BytecodeGenerator::argumentNumberFor):
* bytecompiler/BytecodeGenerator.h:
* bytecompiler/NodesCodegen.cpp:
(JSC::BlockNode::singleStatement):
(JSC::FunctionBodyNode::emitBytecode):
* parser/Nodes.h:
(JSC::ExpressionNode::isSubtract):
(JSC::BinaryOpNode::lhs):
(JSC::BinaryOpNode::rhs):
(JSC::SubNode::isSubtract):
(JSC::ReturnNode::value):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::JSGlobalData):
* runtime/JSGlobalData.h:

LayoutTests:

Test case.

* fast/js/array-sort-numericCompare-expected.txt: Added.
* fast/js/array-sort-numericCompare.html: Added.
* fast/js/script-tests/array-sort-numericCompare.js: Added.
(doSort):
(dontSort):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63244 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
JavaScriptCore/bytecompiler/BytecodeGenerator.h
JavaScriptCore/bytecompiler/NodesCodegen.cpp
JavaScriptCore/parser/Nodes.cpp
JavaScriptCore/parser/Nodes.h
JavaScriptCore/runtime/JSGlobalData.cpp
JavaScriptCore/runtime/JSGlobalData.h
LayoutTests/ChangeLog
LayoutTests/fast/js/array-sort-numericCompare-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/array-sort-numericCompare.html [new file with mode: 0644]
LayoutTests/fast/js/script-tests/array-sort-numericCompare.js [new file with mode: 0644]