Ignore:
Timestamp:
Dec 28, 2002, 3:07:37 PM (22 years ago)
Author:
kocienda
Message:

Reviewed by Gramps and Ken.
Checked in by Ken.

  • fixed 3134693 -- carsdirect.com crash on used car search, due to large JavaScript array

The parser was using recursion to handle many types of lists.
This meant that we crashed out of stack space when any of the lists were extra big.
I applied the same sort of fix we had already applied a while back for argument lists for
all the other types of lists, including the list of ElementNode that was the reason for
the crash reported here.

  • kjs/grammar.y: Removed ElisionNode altogether and just use a count. Use specific node types for PropertyNameAndValueList and PropertyName.
  • kjs/grammar.cpp: Regenerated.
  • kjs/grammar.cpp.h: Regenerated.
  • kjs/grammar.h: Regenerated.
  • kjs/nodes.h: Elide "ElisionNode", changing objects to keep elision counts instead. Make the ObjectLiteralNode list field be PropertyValueNode, not just Node. Make PropertyValueNode fields have specific types. Add new reverse list functions, calls to those functions in the constructors, and friend declarations as needed so the class that holds the head of a list can reverse the list during parsing.
  • kjs/nodes.cpp: (ElementNode::ref): Use iteration instead of recursion. Also elide "elision". (ElementNode::deref): Ditto. (ElementNode::evaluate): Use iteration instead of recursion, taking advantage of the fact that the linked list is reversed. Also use the elision count rather than an elision list. (ArrayNode::reverseElementList): Reverse the list so we can iterate normally. (ArrayNode::ref): Elide "elision". (ArrayNode::deref): Ditto. (ArrayNode::evaluate): Use elision count instead of elision list. (ObjectLiteralNode::reverseList): Reverse the list so we can iterate normally. (PropertyValueNode::ref): Use iteration instead of recursion. (PropertyValueNode::deref): Use iteration instead of recursion. (PropertyValueNode::evaluate): Use iteration instead of recursion, taking advantage of the fact that the linked list is reversed. (ArgumentListNode::ref): Change code to match the other similar cases we had to revise. (ArgumentListNode::deref): Ditto. (ArgumentListNode::evaluateList): Ditto. (ArgumentsNode::reverseList): Ditto. (VarDeclListNode::ref): Use iteration instead of recursion. (VarDeclListNode::deref): Ditto. (VarDeclListNode::evaluate): Use iteration instead of recursion, taking advantage of the fact that the linked list is reversed. (VarDeclListNode::processVarDecls): Ditto. (VarStatementNode::reverseList): Reverse the list so we can iterate normally. (FunctionBodyNode::FunctionBodyNode): Use BlockNode as the base class, removing most of the FunctionBodyNode class.
  • kjs/nodes2string.cpp: (ElementNode::streamTo): Update for using a count for elision, and reverse linking. (ArrayNode::streamTo): Update for using a count for elision. (PropertyValueNode::streamTo): Update for reverse linking. (ArgumentListNode::streamTo): Update for reverse linking. This has been wrong for a while, since we added the reverse a long time ago. (VarDeclListNode::streamTo): Update for reverse linking. (ParameterNode::streamTo): Update for reverse linking.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes2string.cpp

    r3098 r3192  
    120120void ResolveNode::streamTo(SourceStream &s) const { s << ident; }
    121121
    122 void ElisionNode::streamTo(SourceStream &s) const
    123 {
    124   if (elision)
    125     s << elision << ",";
    126   else
     122void ElementNode::streamTo(SourceStream &s) const
     123{
     124  for (int i = 0; i < elision; i++)
    127125    s << ",";
    128 }
    129 
    130 void ElementNode::streamTo(SourceStream &s) const
    131 {
     126  s << node;
    132127  if (list)
    133     s << list << ",";
    134   s << elision << node;
     128    s << "," << list;
    135129}
    136130
    137131void ArrayNode::streamTo(SourceStream &s) const
    138132{
    139   s << "[" << element << elision << "]";
     133  s << "[" << element;
     134  for (int i = 0; i < elision; i++)
     135    s << ",";
     136  s << "]";
    140137}
    141138
     
    150147void PropertyValueNode::streamTo(SourceStream &s) const
    151148{
     149  s << name << ": " << assign;
    152150  if (list)
    153     s << list << ", ";
    154   s << name << ": " << assign;
     151    s << ", " << list;
    155152}
    156153
     
    175172void ArgumentListNode::streamTo(SourceStream &s) const
    176173{
     174  s << expr;
    177175  if (list)
    178     s << list << ", ";
    179   s << expr;
     176    s << ", " << list;
    180177}
    181178
     
    407404void VarDeclListNode::streamTo(SourceStream &s) const
    408405{
     406  s << var;
    409407  if (list)
    410     s << list << ", ";
    411   s << var;
     408    s << ", " << list;
    412409}
    413410
     
    585582}
    586583
    587 void FunctionBodyNode::streamTo(SourceStream &s) const {
    588   s << SourceStream::Endl << "{" << SourceStream::Indent
    589     << source << SourceStream::Unindent << SourceStream::Endl << "}";
    590 }
    591 
    592584void FuncDeclNode::streamTo(SourceStream &s) const {
    593585  s << "function " << ident << "(";
Note: See TracChangeset for help on using the changeset viewer.