webengine/device/src/DeviceLiwIterable.cpp
changeset 16 a359256acfc6
parent 0 dd21522fd290
child 68 92a765b5b3e7
equal deleted inserted replaced
13:10e98eab6f85 16:a359256acfc6
    26 const TInt KMaxKeySize = 128;
    26 const TInt KMaxKeySize = 128;
    27 
    27 
    28 using namespace KJS;
    28 using namespace KJS;
    29 
    29 
    30 const ClassInfo DeviceLiwIterable::info = { "DeviceLiwIterable", 0, 0, 0 };
    30 const ClassInfo DeviceLiwIterable::info = { "DeviceLiwIterable", 0, 0, 0 };
    31 const TInt INIT_JSOBJ_ARRAY_SIZE = 10;   // initial jsobject array
       
    32 // ============================= LOCAL FUNCTIONS ===============================
    31 // ============================= LOCAL FUNCTIONS ===============================
    33 /*
    32 /*
    34 @begin DeviceLiwIterableTable 1
    33 @begin DeviceLiwIterableTable 1
    35     getNext DeviceLiwIterable::getNext DontDelete|Function 0
    34     getNext DeviceLiwIterable::getNext DontDelete|Function 0
    36     reset   DeviceLiwIterable::reset   DontDelete|Function 0
    35     reset   DeviceLiwIterable::reset   DontDelete|Function 0
    58     ExecState* exec,
    57     ExecState* exec,
    59     CDeviceLiwBinding* binding,
    58     CDeviceLiwBinding* binding,
    60     CLiwIterable* variant)
    59     CLiwIterable* variant)
    61     : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype() )
    60     : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype() )
    62     {
    61     {
    63         m_privateData = new DeviceLiwIterablePrivate(variant, binding);
    62     m_valid = EFalse;
    64         if (!m_privateData || !m_privateData->m_jsobjArray )
    63     m_privateData = NULL;
    65             m_valid = false;
    64     if ( binding && variant )
    66         else 
    65         {
    67             {
    66         m_privateData = new DeviceLiwIterablePrivate(this, variant, binding);
    68             m_valid = true;
    67         if ( m_privateData )
    69             KJS::Collector::protect(this);            
    68             m_valid = ETrue;
    70             }            
    69         }            
    71     }
    70     }
    72 
    71 
    73 // ----------------------------------------------------------------------------
    72 // ----------------------------------------------------------------------------
    74 // DeviceLiwIterable::~DeviceLiwIterable
    73 // DeviceLiwIterable::~DeviceLiwIterable
    75 //
    74 //
    76 // ----------------------------------------------------------------------------
    75 // ----------------------------------------------------------------------------
    77 //
    76 //
    78 DeviceLiwIterable::~DeviceLiwIterable()
    77 DeviceLiwIterable::~DeviceLiwIterable()
    79     {
    78     {
    80         // only can be called by garbage collection after the 
    79     Close();
    81         // DeviceLiwIterable::Close() was called
       
    82     }
    80     }
    83 
    81 
    84 // ----------------------------------------------------------------------------
    82 // ----------------------------------------------------------------------------
    85 // DeviceLiwIterable::Close()
    83 // DeviceLiwIterable::Close()
    86 //
    84 //
    87 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
    88 //
    86 //
    89 void DeviceLiwIterable::Close(ExecState* exec, bool unmark)
    87 void DeviceLiwIterable::Close()
    90     {
    88     {
    91     // avoid double close    
    89     if ( !m_valid )
    92     if(!m_valid) 
       
    93         {   
       
    94         if(unmark) 
       
    95             {
       
    96             // unprotect this to allow the garbage collection to release this jsobject
       
    97             KJS::Collector::unprotect(this);
       
    98             }
       
    99         return;
    90         return;
   100         }
    91         
   101     
    92     m_valid = EFalse;
   102     // need exec to close other jsobject
       
   103     m_privateData->m_exec = exec;
       
   104     delete m_privateData;
    93     delete m_privateData;
   105     m_privateData = NULL;
    94     m_privateData = NULL;
   106     m_valid = false;
       
   107     
       
   108     if(unmark) 
       
   109         {
       
   110         // unprotect this to allow the garbage collection to release this jsobject
       
   111         KJS::Collector::unprotect(this);
       
   112         }
       
   113     }     
    95     }     
   114 
    96 
   115 // ----------------------------------------------------------------------------
    97 // ----------------------------------------------------------------------------
   116 // DeviceLiwIterable::toString
    98 // DeviceLiwIterable::toString
   117 // Returns string representation of the object
    99 // Returns string representation of the object
   214     
   196     
   215 // ---------------------------------------------------------------------------
   197 // ---------------------------------------------------------------------------
   216 // DeviceLiwIterablePrivate constructor
   198 // DeviceLiwIterablePrivate constructor
   217 //
   199 //
   218 // ---------------------------------------------------------------------------
   200 // ---------------------------------------------------------------------------
   219 DeviceLiwIterablePrivate::DeviceLiwIterablePrivate(const CLiwIterable* liwIterable, CDeviceLiwBinding* liwBinding)
   201 DeviceLiwIterablePrivate::DeviceLiwIterablePrivate(DeviceLiwIterable* jsobj, const CLiwIterable* liwIterable, CDeviceLiwBinding* liwBinding)
   220     {
   202     {
   221     TRAP_IGNORE(
   203     TRAP_IGNORE(
   222             m_liwBinding = liwBinding;
   204             m_liwBinding = liwBinding;
   223             m_jsobjArray = new RPointerArray<JSObject>( INIT_JSOBJ_ARRAY_SIZE );
       
   224             m_exec = NULL;    
   205             m_exec = NULL;    
   225             m_iterable = (CLiwIterable*) liwIterable;
   206             m_iterable = (CLiwIterable*) liwIterable;
       
   207             m_jsobj = jsobj;
   226             if ( m_iterable )
   208             if ( m_iterable )
   227                 m_iterable->IncRef();
   209                 m_iterable->IncRef();
   228             )
   210             )
   229     }
   211     }
   230     
   212     
   231 // ---------------------------------------------------------------------------
   213 // ---------------------------------------------------------------------------
   232 // DeviceLiwMapPrivate::Close
   214 // DeviceLiwMapPrivate::Close
   233 //
   215 //
   234 // ---------------------------------------------------------------------------
   216 // ---------------------------------------------------------------------------
   235 void DeviceLiwIterablePrivate::Close()
   217 DeviceLiwIterablePrivate::~DeviceLiwIterablePrivate()
   236     {
   218     {
   237     // close the jsobject
   219     // invalid the DeviceLiwIterable
   238     if ( m_jsobjArray && m_exec )
   220     if (m_jsobj)
   239         {
   221         m_jsobj->m_valid = EFalse;
   240         // close all the DeviceLiwMap objects and DeviceLiwIterable objects
       
   241         for (int i = 0; i < m_jsobjArray->Count(); i++)
       
   242             {
       
   243             JSObject * jsobj = (*m_jsobjArray)[i];
       
   244             if (jsobj->inherits( &DeviceLiwIterable::info ))
       
   245                 {
       
   246                 (static_cast<DeviceLiwIterable*>(jsobj))->Close(m_exec, true);
       
   247                 }
       
   248             else if (jsobj->inherits( &DeviceLiwMap::info ))
       
   249                 {
       
   250                 (static_cast<DeviceLiwMap*>(jsobj))->Close(m_exec, true);
       
   251                 }
       
   252             }
       
   253         m_jsobjArray->Close();
       
   254         delete m_jsobjArray;
       
   255         m_jsobjArray = NULL;
       
   256         m_exec = NULL;
       
   257         }
       
   258     
   222     
   259     // release the map    
   223     // release the map    
   260     if ( m_iterable ) 
   224     if ( m_iterable ) 
   261         {
   225         {
   262         m_iterable->DecRef();
   226         m_iterable->DecRef();
   321                 {
   285                 {
   322                 rval =  it->m_privateData->m_liwBinding->LiwVariant2JsVal( exec, vv );
   286                 rval =  it->m_privateData->m_liwBinding->LiwVariant2JsVal( exec, vv );
   323                 if(rval->isObject()) 
   287                 if(rval->isObject()) 
   324                     {
   288                     {
   325                     JSObject* obj =  static_cast<JSObject*> (rval);
   289                     JSObject* obj =  static_cast<JSObject*> (rval);
   326                     if(obj->inherits( &KJS::DeviceLiwIterable::info ) || obj->inherits( &KJS::DeviceLiwMap::info ))
   290                     DevicePrivateBase* thisData = it->getIterableData();
       
   291                     DevicePrivateBase* childData = NULL;
       
   292                     if ( obj->inherits( &KJS::DeviceLiwIterable::info ) )
       
   293                         childData = (static_cast<DeviceLiwIterable*> (obj))->getIterableData();
       
   294                     else if ( obj->inherits( &KJS::DeviceLiwMap::info ) )
       
   295                         childData = (static_cast<DeviceLiwMap*> (obj))->getMapData();   
       
   296 
       
   297                     if ( childData ) 
   327                         {
   298                         {
   328                         // insert into jsobject array
   299                         childData->SetParent( thisData ); 
   329                         it->m_privateData->m_jsobjArray->Append(obj);
   300                         thisData->AddChild( childData );
   330                         }
   301                         }
   331                     }                
   302                     }
   332                 
       
   333                 vv.Reset();
   303                 vv.Reset();
   334                 }
   304                 }
   335         }
   305         }
   336         else if ( m_func == DeviceLiwIterable::reset ){
   306         else if ( m_func == DeviceLiwIterable::reset ){
   337             it->m_privateData->m_iterable->Reset();
   307             it->m_privateData->m_iterable->Reset();
   338         }
   308         }
   339         else if ( m_func == DeviceLiwIterable::close ){
   309         else if ( m_func == DeviceLiwIterable::close ){
   340             it->Close(exec, false);
   310             it->Close();
   341         }
   311         }
   342         return rval;
   312         return rval;
   343     }
   313     }
   344 //END OF FILE
   314 //END OF FILE
   345 
   315