45 // ---------------------------------------------------------------------------- |
45 // ---------------------------------------------------------------------------- |
46 // |
46 // |
47 DeviceLiwMap::DeviceLiwMap( JSValue* proto, const CLiwMap* liwMap, CDeviceLiwBinding* liwBinding) |
47 DeviceLiwMap::DeviceLiwMap( JSValue* proto, const CLiwMap* liwMap, CDeviceLiwBinding* liwBinding) |
48 : JSObject(proto) |
48 : JSObject(proto) |
49 { |
49 { |
50 m_privateData = new DeviceLiwMapPrivate(liwMap, liwBinding); |
50 m_valid = EFalse; |
51 if (!m_privateData ) |
51 m_privateData = NULL; |
52 m_valid = false; |
52 if (liwMap && liwBinding ) |
53 else |
53 { |
54 { |
54 m_privateData = new DeviceLiwMapPrivate(this, liwMap, liwBinding); |
55 m_valid = true; |
55 if ( m_privateData ) |
56 // protect this object |
56 m_valid = ETrue; |
57 KJS::Collector::protect(this); |
57 } |
58 } |
58 } |
59 } |
|
60 |
|
61 |
|
62 |
59 |
63 // ---------------------------------------------------------------------------- |
60 // ---------------------------------------------------------------------------- |
64 // DeviceLiwMap::~DeviceLiwMap |
61 // DeviceLiwMap::~DeviceLiwMap |
65 // |
62 // |
66 // ---------------------------------------------------------------------------- |
63 // ---------------------------------------------------------------------------- |
67 // |
64 // |
68 DeviceLiwMap::~DeviceLiwMap() |
65 DeviceLiwMap::~DeviceLiwMap() |
69 { |
66 { |
70 // only can be called by garbage collection after the |
67 Close(); |
71 // DeviceLiwMap::Close() was called |
|
72 } |
68 } |
73 |
69 |
74 // ---------------------------------------------------------------------------- |
70 // ---------------------------------------------------------------------------- |
75 // DeviceLiwMap::Close() |
71 // DeviceLiwMap::Close() |
76 // |
72 // |
77 // ---------------------------------------------------------------------------- |
73 // ---------------------------------------------------------------------------- |
78 // |
74 // |
79 void DeviceLiwMap::Close( ExecState* exec, bool unmark ) |
75 void DeviceLiwMap::Close() |
80 { |
76 { |
81 // avoid double close |
77 if ( !m_valid ) |
82 if(!m_valid) |
|
83 { |
|
84 if(unmark) |
|
85 { |
|
86 // unprotect this to allow the garbage collection to release this jsobject |
|
87 KJS::Collector::unprotect(this); |
|
88 } |
|
89 return; |
78 return; |
90 } |
79 |
91 |
80 m_valid = EFalse; |
92 if (exec) |
|
93 { |
|
94 PropertyNameArray propertyNames; |
|
95 this->getPropertyNames( exec, propertyNames ); |
|
96 unsigned size = static_cast<unsigned>(propertyNames.size()); |
|
97 |
|
98 for (unsigned i = 0; i < size; i++) |
|
99 { |
|
100 JSValue * jsvalue = this->get( exec, propertyNames[i] ); |
|
101 if(jsvalue->isObject()) |
|
102 { |
|
103 JSObject * prop = jsvalue->toObject( exec ); |
|
104 |
|
105 if (prop->inherits( &DeviceLiwIterable::info )) |
|
106 { |
|
107 (static_cast<DeviceLiwIterable*>(prop))->Close(exec, true); |
|
108 } |
|
109 else if (prop->inherits( &DeviceLiwMap::info )) |
|
110 { |
|
111 (static_cast<DeviceLiwMap*>(prop))->Close(exec, true); |
|
112 } |
|
113 } |
|
114 } |
|
115 } |
|
116 |
|
117 delete m_privateData; |
81 delete m_privateData; |
118 m_privateData = NULL; |
82 m_privateData = NULL; |
119 m_valid = false; |
|
120 |
|
121 if(unmark) |
|
122 { |
|
123 // unprotect this to allow the garbage collection to release this jsobject |
|
124 KJS::Collector::unprotect(this); |
|
125 } |
|
126 } |
83 } |
127 |
84 |
128 // ---------------------------------------------------------------------------- |
85 // ---------------------------------------------------------------------------- |
129 // Device::toString |
86 // Device::toString |
130 // |
87 // |
251 |
208 |
252 // --------------------------------------------------------------------------- |
209 // --------------------------------------------------------------------------- |
253 // DeviceLiwMapPrivate constructor |
210 // DeviceLiwMapPrivate constructor |
254 // |
211 // |
255 // --------------------------------------------------------------------------- |
212 // --------------------------------------------------------------------------- |
256 DeviceLiwMapPrivate::DeviceLiwMapPrivate(const CLiwMap* liwMap, CDeviceLiwBinding* liwBinding) |
213 DeviceLiwMapPrivate::DeviceLiwMapPrivate(DeviceLiwMap* jsobj, const CLiwMap* liwMap, CDeviceLiwBinding* liwBinding) |
257 { |
214 { |
258 TRAP_IGNORE( |
215 TRAP_IGNORE( |
259 m_liwBinding = liwBinding; |
216 m_liwBinding = liwBinding; |
260 m_liwMap = (CLiwMap*) liwMap; |
217 m_liwMap = (CLiwMap*) liwMap; |
|
218 m_jsobj = jsobj; |
261 if ( m_liwMap ) |
219 if ( m_liwMap ) |
262 m_liwMap->IncRef(); |
220 m_liwMap->IncRef(); |
263 ) |
221 ) |
264 } |
222 } |
265 |
223 |
266 // --------------------------------------------------------------------------- |
224 // --------------------------------------------------------------------------- |
267 // DeviceLiwMapPrivate::Close |
225 // DeviceLiwMapPrivate::Close |
268 // |
226 // |
269 // --------------------------------------------------------------------------- |
227 // --------------------------------------------------------------------------- |
270 void DeviceLiwMapPrivate::Close() |
228 DeviceLiwMapPrivate::~DeviceLiwMapPrivate() |
271 { |
229 { |
272 m_liwBinding = NULL; |
230 // invalid the DeviceLiwMap |
273 |
231 if (m_jsobj) |
|
232 m_jsobj->m_valid = EFalse; |
|
233 |
274 // release the map |
234 // release the map |
275 if ( m_liwMap ) |
235 if ( m_liwMap ) |
276 { |
236 { |
277 m_liwMap->DecRef(); |
237 m_liwMap->DecRef(); |
278 m_liwMap = NULL; |
238 m_liwMap = NULL; |
279 } |
239 } |
280 } |
240 } |
281 |
241 |
282 // ---------------------------------------------------------------------------- |
242 // ---------------------------------------------------------------------------- |
283 // DeviceLiwMapFunc::DeviceLiwMapFunc |
243 // DeviceLiwMapFunc::DeviceLiwMapFunc |
284 // |
244 // |
285 // ---------------------------------------------------------------------------- |
245 // ---------------------------------------------------------------------------- |
286 // |
246 // |
295 // |
255 // |
296 // ---------------------------------------------------------------------------- |
256 // ---------------------------------------------------------------------------- |
297 // |
257 // |
298 JSValue* DeviceLiwMapFunc::callAsFunction(ExecState* exec, JSObject *thisObj, const List& aArgs ) |
258 JSValue* DeviceLiwMapFunc::callAsFunction(ExecState* exec, JSObject *thisObj, const List& aArgs ) |
299 { |
259 { |
300 if (!thisObj->inherits(&DeviceLiwMap::info)) { |
260 if (!thisObj->inherits(&DeviceLiwMap::info)) |
301 return throwError(exec, GeneralError); |
261 { |
302 } |
262 return throwError(exec, GeneralError); |
303 |
263 } |
304 DeviceLiwMap *map = static_cast<DeviceLiwMap *>(thisObj); |
264 |
305 |
265 DeviceLiwMap *map = static_cast<DeviceLiwMap *>(thisObj); |
306 if ( m_func == DeviceLiwMap::close ) |
266 |
307 { |
267 if ( m_func == DeviceLiwMap::close ) |
308 map->Close(exec, false); |
268 { |
309 } |
269 map->Close(); |
310 return jsUndefined(); |
270 } |
|
271 return jsUndefined(); |
311 } |
272 } |
312 |
273 |
313 //END OF FILE |
274 //END OF FILE |
314 |
275 |
315 |
276 |