82 { |
82 { |
83 public: |
83 public: |
84 QScriptValueIteratorPrivate() |
84 QScriptValueIteratorPrivate() |
85 : initialized(false) |
85 : initialized(false) |
86 {} |
86 {} |
|
87 |
|
88 ~QScriptValueIteratorPrivate() |
|
89 { |
|
90 if (!initialized) |
|
91 return; |
|
92 QScriptEnginePrivate *eng_p = engine(); |
|
93 if (!eng_p) |
|
94 return; |
|
95 QScript::APIShim shim(eng_p); |
|
96 propertyNames.clear(); //destroying the identifiers need to be done under the APIShim guard |
|
97 } |
|
98 |
|
99 QScriptValuePrivate *object() const |
|
100 { |
|
101 return QScriptValuePrivate::get(objectValue); |
|
102 } |
|
103 |
|
104 QScriptEnginePrivate *engine() const |
|
105 { |
|
106 return QScriptEnginePrivate::get(objectValue.engine()); |
|
107 } |
|
108 |
87 void ensureInitialized() |
109 void ensureInitialized() |
88 { |
110 { |
89 if (initialized) |
111 if (initialized) |
90 return; |
112 return; |
91 QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(object.engine()); |
113 QScriptEnginePrivate *eng_p = engine(); |
|
114 QScript::APIShim shim(eng_p); |
92 JSC::ExecState *exec = eng_p->globalExec(); |
115 JSC::ExecState *exec = eng_p->globalExec(); |
93 JSC::PropertyNameArray propertyNamesArray(exec); |
116 JSC::PropertyNameArray propertyNamesArray(exec); |
94 propertyNamesArray.setShouldCache(false); |
117 JSC::asObject(object()->jscValue)->getOwnPropertyNames(exec, propertyNamesArray, JSC::IncludeDontEnumProperties); |
95 JSC::asObject(QScriptValuePrivate::get(object)->jscValue)->getOwnPropertyNames(exec, propertyNamesArray, /*includeNonEnumerable=*/true); |
|
96 |
118 |
97 JSC::PropertyNameArray::const_iterator propertyNamesIt = propertyNamesArray.begin(); |
119 JSC::PropertyNameArray::const_iterator propertyNamesIt = propertyNamesArray.begin(); |
98 for(; propertyNamesIt != propertyNamesArray.end(); ++propertyNamesIt) { |
120 for(; propertyNamesIt != propertyNamesArray.end(); ++propertyNamesIt) { |
99 propertyNames.append(propertyNamesIt->ustring()); |
121 propertyNames.append(*propertyNamesIt); |
100 } |
122 } |
101 it = propertyNames.begin(); |
123 it = propertyNames.begin(); |
102 initialized = true; |
124 initialized = true; |
103 } |
125 } |
104 |
126 |
105 QScriptValue object; |
127 QScriptValue objectValue; |
106 QLinkedList<JSC::UString> propertyNames; |
128 QLinkedList<JSC::Identifier> propertyNames; |
107 QLinkedList<JSC::UString>::iterator it; |
129 QLinkedList<JSC::Identifier>::iterator it; |
108 QLinkedList<JSC::UString>::iterator current; |
130 QLinkedList<JSC::Identifier>::iterator current; |
109 bool initialized; |
131 bool initialized; |
110 }; |
132 }; |
111 |
133 |
112 /*! |
134 /*! |
113 Constructs an iterator for traversing \a object. The iterator is |
135 Constructs an iterator for traversing \a object. The iterator is |
117 QScriptValueIterator::QScriptValueIterator(const QScriptValue &object) |
139 QScriptValueIterator::QScriptValueIterator(const QScriptValue &object) |
118 : d_ptr(0) |
140 : d_ptr(0) |
119 { |
141 { |
120 if (object.isObject()) { |
142 if (object.isObject()) { |
121 d_ptr.reset(new QScriptValueIteratorPrivate()); |
143 d_ptr.reset(new QScriptValueIteratorPrivate()); |
122 d_ptr->object = object; |
144 d_ptr->objectValue = object; |
123 } |
145 } |
124 } |
146 } |
125 |
147 |
126 /*! |
148 /*! |
127 Destroys the iterator. |
149 Destroys the iterator. |
252 next() or previous(). |
274 next() or previous(). |
253 */ |
275 */ |
254 QScriptString QScriptValueIterator::scriptName() const |
276 QScriptString QScriptValueIterator::scriptName() const |
255 { |
277 { |
256 Q_D(const QScriptValueIterator); |
278 Q_D(const QScriptValueIterator); |
257 if (!d || !d->initialized) |
279 if (!d || !d->initialized || !d->engine()) |
258 return QScriptString(); |
280 return QScriptString(); |
259 return d->object.engine()->toStringHandle(name()); |
281 return d->engine()->toStringHandle(*d->current); |
260 } |
282 } |
261 |
283 |
262 /*! |
284 /*! |
263 Returns the value of the last property that was jumped over using |
285 Returns the value of the last property that was jumped over using |
264 next() or previous(). |
286 next() or previous(). |
266 \sa setValue(), name() |
288 \sa setValue(), name() |
267 */ |
289 */ |
268 QScriptValue QScriptValueIterator::value() const |
290 QScriptValue QScriptValueIterator::value() const |
269 { |
291 { |
270 Q_D(const QScriptValueIterator); |
292 Q_D(const QScriptValueIterator); |
271 if (!d || !d->initialized) |
293 if (!d || !d->initialized || !d->engine()) |
272 return QScriptValue(); |
294 return QScriptValue(); |
273 return d->object.property(name()); |
295 QScript::APIShim shim(d->engine()); |
|
296 JSC::JSValue jsValue = d->object()->property(*d->current); |
|
297 return d->engine()->scriptValueFromJSCValue(jsValue); |
274 } |
298 } |
275 |
299 |
276 /*! |
300 /*! |
277 Sets the \a value of the last property that was jumped over using |
301 Sets the \a value of the last property that was jumped over using |
278 next() or previous(). |
302 next() or previous(). |
280 \sa value(), name() |
304 \sa value(), name() |
281 */ |
305 */ |
282 void QScriptValueIterator::setValue(const QScriptValue &value) |
306 void QScriptValueIterator::setValue(const QScriptValue &value) |
283 { |
307 { |
284 Q_D(QScriptValueIterator); |
308 Q_D(QScriptValueIterator); |
285 if (!d || !d->initialized) |
309 if (!d || !d->initialized || !d->engine()) |
286 return; |
310 return; |
287 d->object.setProperty(name(), value); |
311 QScript::APIShim shim(d->engine()); |
|
312 JSC::JSValue jsValue = d->engine()->scriptValueToJSCValue(value); |
|
313 d->object()->setProperty(*d->current, jsValue); |
288 } |
314 } |
289 |
315 |
290 /*! |
316 /*! |
291 Returns the flags of the last property that was jumped over using |
317 Returns the flags of the last property that was jumped over using |
292 next() or previous(). |
318 next() or previous(). |
294 \sa value() |
320 \sa value() |
295 */ |
321 */ |
296 QScriptValue::PropertyFlags QScriptValueIterator::flags() const |
322 QScriptValue::PropertyFlags QScriptValueIterator::flags() const |
297 { |
323 { |
298 Q_D(const QScriptValueIterator); |
324 Q_D(const QScriptValueIterator); |
299 if (!d || !d->initialized) |
325 if (!d || !d->initialized || !d->engine()) |
300 return 0; |
326 return 0; |
301 return d->object.propertyFlags(name()); |
327 QScript::APIShim shim(d->engine()); |
|
328 return d->object()->propertyFlags(*d->current); |
302 } |
329 } |
303 |
330 |
304 /*! |
331 /*! |
305 Removes the last property that was jumped over using next() |
332 Removes the last property that was jumped over using next() |
306 or previous(). |
333 or previous(). |
308 \sa setValue() |
335 \sa setValue() |
309 */ |
336 */ |
310 void QScriptValueIterator::remove() |
337 void QScriptValueIterator::remove() |
311 { |
338 { |
312 Q_D(QScriptValueIterator); |
339 Q_D(QScriptValueIterator); |
313 if (!d || !d->initialized) |
340 if (!d || !d->initialized || !d->engine()) |
314 return; |
341 return; |
315 d->object.setProperty(name(), QScriptValue()); |
342 QScript::APIShim shim(d->engine()); |
|
343 d->object()->setProperty(*d->current, JSC::JSValue()); |
316 d->propertyNames.erase(d->current); |
344 d->propertyNames.erase(d->current); |
317 } |
345 } |
318 |
346 |
319 /*! |
347 /*! |
320 Makes the iterator operate on \a object. The iterator is set to be |
348 Makes the iterator operate on \a object. The iterator is set to be |