Ignore:
Timestamp:
Nov 18, 2002, 5:01:16 PM (23 years ago)
Author:
mjs
Message:

JavaScriptCore:

Partway to removing Value from List. Created a marking List
variant, used it in place of ListImp.

  • kjs/internal.h: Removed List stuff.
  • kjs/internal.cpp: (InterpreterImp::mark): Call appropriate List method to do marking of empty ListImp.
  • kjs/object.h:
  • kjs/object.cpp: Use marking List instead of ListImp *.
  • kjs/types.h:
  • kjs/types.cpp: (List::List): New boolean needsMarking parameter. (List::operator=): Perform trickery related to needsMarking. (List::~List): Likewise. (List::mark): Mark the ListImp. (List::markEmptyList): (ListImp::*): Moved here fron internal.cpp, they will be integrated into the relevant List methods soon.

WebCore:

  • force-js-clean-timestamp: Rebuild for JSC changes.
File:
1 edited

Legend:

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

    r2483 r2741  
    332332}
    333333
    334 // ------------------------------ ListImp --------------------------------------
    335 
    336 #ifdef KJS_DEBUG_MEM
    337 int ListImp::count = 0;
    338 #endif
    339 
    340 Value ListImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
    341 {
    342   // invalid for List
    343   assert(false);
    344   return Value();
    345 }
    346 
    347 bool ListImp::toBoolean(ExecState */*exec*/) const
    348 {
    349   // invalid for List
    350   assert(false);
    351   return false;
    352 }
    353 
    354 double ListImp::toNumber(ExecState */*exec*/) const
    355 {
    356   // invalid for List
    357   assert(false);
    358   return 0;
    359 }
    360 
    361 UString ListImp::toString(ExecState */*exec*/) const
    362 {
    363   // invalid for List
    364   assert(false);
    365   return UString::null;
    366 }
    367 
    368 Object ListImp::toObject(ExecState */*exec*/) const
    369 {
    370   // invalid for List
    371   assert(false);
    372   return Object();
    373 }
    374 
    375 ListImp::ListImp()
    376 {
    377 #ifdef KJS_DEBUG_MEM
    378   count++;
    379 #endif
    380 
    381   hook = new ListNode(Null(), 0L, 0L);
    382   hook->next = hook;
    383   hook->prev = hook;
    384   //fprintf(stderr,"ListImp::ListImp %p hook=%p\n",this,hook);
    385 }
    386 
    387 ListImp::~ListImp()
    388 {
    389   //fprintf(stderr,"ListImp::~ListImp %p\n",this);
    390 #ifdef KJS_DEBUG_MEM
    391   count--;
    392 #endif
    393 
    394   clear();
    395   delete hook;
    396 
    397   if ( emptyList == this )
    398     emptyList = 0L;
    399 }
    400 
    401 void ListImp::mark()
    402 {
    403   ListNode *n = hook->next;
    404   while (n != hook) {
    405     if (!n->member->marked())
    406       n->member->mark();
    407     n = n->next;
    408   }
    409   ValueImp::mark();
    410 }
    411 
    412 void ListImp::append(const Value& obj)
    413 {
    414   ListNode *n = new ListNode(obj, hook->prev, hook);
    415   hook->prev->next = n;
    416   hook->prev = n;
    417 }
    418 
    419 void ListImp::prepend(const Value& obj)
    420 {
    421   ListNode *n = new ListNode(obj, hook, hook->next);
    422   hook->next->prev = n;
    423   hook->next = n;
    424 }
    425 
    426 void ListImp::appendList(const List& lst)
    427 {
    428   ListIterator it = lst.begin();
    429   ListIterator e = lst.end();
    430   while(it != e) {
    431     append(*it);
    432     ++it;
    433   }
    434 }
    435 
    436 void ListImp::prependList(const List& lst)
    437 {
    438   ListIterator it = lst.end();
    439   ListIterator e = lst.begin();
    440   while(it != e) {
    441     --it;
    442     prepend(*it);
    443   }
    444 }
    445 
    446 void ListImp::removeFirst()
    447 {
    448   erase(hook->next);
    449 }
    450 
    451 void ListImp::removeLast()
    452 {
    453   erase(hook->prev);
    454 }
    455 
    456 void ListImp::remove(const Value &obj)
    457 {
    458   if (obj.isNull())
    459     return;
    460   ListNode *n = hook->next;
    461   while (n != hook) {
    462     if (n->member == obj.imp()) {
    463       erase(n);
    464       return;
    465     }
    466     n = n->next;
    467   }
    468 }
    469 
    470 void ListImp::clear()
    471 {
    472   ListNode *n = hook->next;
    473   while (n != hook) {
    474     n = n->next;
    475     delete n->prev;
    476   }
    477 
    478   hook->next = hook;
    479   hook->prev = hook;
    480 }
    481 
    482 ListImp *ListImp::copy() const
    483 {
    484   ListImp* newList = new ListImp;
    485 
    486   ListIterator e = end();
    487   ListIterator it = begin();
    488 
    489   while(it != e) {
    490     newList->append(*it);
    491     ++it;
    492   }
    493 
    494   //fprintf( stderr, "ListImp::copy returning newList=%p\n", newList );
    495   return newList;
    496 }
    497 
    498 void ListImp::erase(ListNode *n)
    499 {
    500   if (n != hook) {
    501     n->next->prev = n->prev;
    502     n->prev->next = n->next;
    503     delete n;
    504   }
    505 }
    506 
    507 bool ListImp::isEmpty() const
    508 {
    509   return (hook->prev == hook);
    510 }
    511 
    512 int ListImp::size() const
    513 {
    514   int s = 0;
    515   ListNode *node = hook;
    516   while ((node = node->next) != hook)
    517     s++;
    518 
    519   return s;
    520 }
    521 
    522 Value ListImp::at(int i) const
    523 {
    524   if (i < 0 || i >= size())
    525     return Undefined();
    526 
    527   ListIterator it = begin();
    528   int j = 0;
    529   while ((j++ < i))
    530     it++;
    531 
    532   return *it;
    533 }
    534 
    535 ListImp *ListImp::emptyList = 0L;
    536 
    537 ListImp *ListImp::empty()
    538 {
    539   if (!emptyList)
    540     emptyList = new ListImp();
    541   return emptyList;
    542 }
    543 
    544334// ------------------------------ ContextImp -----------------------------------
    545335
     
    878668  if (BooleanImp::staticFalse && !BooleanImp::staticFalse->marked())
    879669    BooleanImp::staticFalse->mark();
    880   if (ListImp::emptyList && !ListImp::emptyList->marked())
    881     ListImp::emptyList->mark();
     670  List::markEmptyList();
    882671  //fprintf( stderr, "InterpreterImp::mark this=%p global.imp()=%p\n", this, global.imp() );
    883672  if (global.imp())
Note: See TracChangeset for help on using the changeset viewer.