1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
|
#include <tqmetaobject.h>
#include <private/qucom_p.h>
#include <tqpen.h>
#include <tqpixmap.h>
#include <tqimage.h>
#include <tqvariant.h>
#include <tqdatetime.h>
#include <tqsize.h>
#include <kjs/interpreter.h>
#include <kjs/ustring.h>
#include <kjs/types.h>
#include <kjs/value.h>
#include "global.h"
#include "jsbinding.h"
#include "jsobjectproxy.h"
#include "jsfactory.h"
#include "jsvalueproxy.h"
#include "jsopaqueproxy.h"
#include "jsbuiltinproxy.h"
#include "kjsembedpart.h"
#include "bindings/pen_imp.h"
#include "bindings/image_imp.h"
#include "bindings/pixmap_imp.h"
#include "bindings/painter_imp.h"
#include "bindings/brush_imp.h"
#include "bindings/size_imp.h"
#include "bindings/point_imp.h"
#include "bindings/rect_imp.h"
#include <stdlib.h>
namespace KJSEmbed {
//
//
// Supported
// =========
//
// Bool, Double, CString, String, StringList, Int, UInt, Date, Time, DateTime,
// Rect, Size, Point, Pixmap, Image, Brush, Pen, Size, Rect, Point, TTQValueList<TTQVariant>
//
// Opqaue
// ======
//
// Invalid, Map, List, Palette, ColorGroup,
// IconSet, PointArray, Region, Bitmap, Cursor, SizePolicy,
// ByteArray, BitArray
//
KJS::Value convertToValue( KJS::ExecState *exec, const TTQVariant &val ) {
if ( !val.isValid() )
return KJS::Undefined();
kdDebug( 80001 ) << "Convert a " << val.typeName() << " to a value" << endl;
KJS::List items;
uint type = val.type();
switch( type )
{
case TTQVariant::String:
case TTQVariant::CString:
return KJS::String( val.toString() );
break;
case TTQVariant::Int:
return KJS::Number( val.toInt() );
break;
case TTQVariant::UInt:
return KJS::Number( val.toUInt() );
break;
case TTQVariant::Double:
return KJS::Number( val.toDouble() );
break;
case TTQVariant::Bool:
return KJS::Boolean( val.toBool() );
break;
case TTQVariant::Rect:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::Rect::addBindings( exec, proxyObj );
return proxyObj;
break;
}
case TTQVariant::Date:
case TTQVariant::DateTime:
case TTQVariant::Time:
{
TTQDateTime dt = TTQDateTime::currentDateTime();
if ( type == TTQVariant::Date )
dt.setDate( val.toDate() );
else if ( type == TTQVariant::Time )
dt.setTime( val.toTime() );
else
dt = val.toDateTime();
items.append( KJS::Number( dt.date().year() ) );
items.append( KJS::Number( dt.date().month() - 1 ) );
items.append( KJS::Number( dt.date().day() ) );
items.append( KJS::Number( dt.time().hour() ) );
items.append( KJS::Number( dt.time().minute() ) );
items.append( KJS::Number( dt.time().second() ) );
items.append( KJS::Number( dt.time().msec() ) );
return KJS::Object( exec->interpreter() ->builtinDate().construct( exec, items ) );
break;
}
case TTQVariant::Point:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::Point::addBindings( exec, proxyObj );
return proxyObj;
break;
}
case TTQVariant::StringList:
{
TTQStringList lst = val.toStringList();
TTQStringList::Iterator idx = lst.begin();
for ( ; idx != lst.end(); ++idx )
items.append( KJS::String( ( *idx ) ) );
return KJS::Object( exec->interpreter() ->builtinArray().construct( exec, items ) );
break;
}
case TTQVariant::List:
// case TTQVariant::StringList:
// This will cause an extra conversion step for a TQStrinList so use the above case.
{
TTQValueList<TTQVariant> lst = val.toList();
TTQValueList<TTQVariant>::Iterator idx = lst.begin();
for ( ; idx != lst.end(); ++idx )
items.append( convertToValue( exec, ( *idx ) ) );
return KJS::Object( exec->interpreter() ->builtinArray().construct( exec, items ) );
break;
}
case TTQVariant::Map:
{
TTQMap<TTQString,TTQVariant> map = val.toMap();
TTQMap<TTQString,TTQVariant>::Iterator idx = map.begin();
KJS::Object array( exec->interpreter() ->builtinArray().construct( exec, 0 ) );
for ( ; idx != map.end(); ++idx )
array.put(exec, KJS::Identifier(idx.key().latin1()), convertToValue( exec, idx.data() ) );
return array;
break;
}
case TTQVariant::Pixmap:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::Pixmap::addBindings( exec, proxyObj );
return proxyObj;
break;
}
case TTQVariant::Brush:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::BrushImp::addBindings( exec, proxyObj );
return proxyObj;
}
case TTQVariant::Image:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::ImageImp::addBindings( exec, proxyObj );
return proxyObj;
break;
}
case TTQVariant::Pen:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::Pen::addBindings( exec, proxyObj );
return proxyObj;
break;
}
case TTQVariant::Size:
{
JSValueProxy * prx = new JSValueProxy( );
prx->setValue( val );
KJS::Object proxyObj( prx );
Bindings::Size::addBindings( exec, proxyObj );
return proxyObj;
break;
}
default:
{
if ( val.canCast( TTQVariant::String ) )
return KJS::String( val.toString() );
else
{
kdDebug( 80001 ) << "convertToValue() Creating value, type wrapper for " << val.typeName() << endl;
JSValueProxy *valproxy = new JSValueProxy();
KJS::Object obj = KJS::Object( valproxy );
valproxy->addBindings( exec, obj );
valproxy->setValue( val );
return obj;
}
}
}
}
TTQVariant convertToVariant( KJS::ExecState *exec, const KJS::Value &v ) {
TTQVariant val;
KJS::Type type = v.type();
kdDebug( 80001 ) << "Convert a value of type " << type << " to a variant" << endl;
switch( type )
{
case KJS::StringType:
val = v.toString( exec ).qstring();
break;
case KJS::NumberType:
val = v.toNumber( exec );
break;
case KJS::BooleanType:
val = v.toBoolean( exec );
break;
case KJS::ObjectType:
{
KJS::Object obj = v.toObject( exec );
kdDebug( 80001 ) << "convertToVariant() got an " << obj.className().qstring() << endl;
if ( obj.className().qstring() == "Array" ) {
if ( checkArray( exec, v ) == List )
val = convertArrayToList( exec, v );
else
val = convertArrayToMap(exec, v);
} else if ( obj.className().qstring() == "Date" ) {
val = convertDateToDateTime( exec, v );
} else if ( obj.className().qstring() == "Function" ) {
/* val = obj.className().qstring();*/
} else {
//JSObjectProxy *prx = JSProxy::toObjectProxy( obj.imp() );
JSValueProxy *vprx = JSProxy::toValueProxy(obj.imp() );
//JSOpaqueProxy *oprx = JSProxy::toOpaqueProxy( obj.imp() );
JSProxy *prxy = dynamic_cast<JSProxy*>(obj.imp());
/*
kdDebug(80001) << "Type " << obj.imp()->dispatchType() << endl;
kdDebug(80001) << "Object proxy: " << prx << " Value Proxy: " << vprx << " Opaque Proxy " << oprx << " Proxy " << prxy << endl;
kdDebug(80001) << "Object prototype valid " << obj.prototype().isValid() << endl;
kdDebug(80001) << "Prototype name: " << obj.prototype().toString(exec).ascii() << endl;
kdDebug(80001) << "Proxy imp " << dynamic_cast<JSProxyImp*>(obj.imp()) << endl;
kdDebug(80001) << "Builtin " << dynamic_cast<JSBuiltinProxy*>(obj.imp()) << endl;
*/
/*if ( prx ) {
TTQObject * o = prx->object();
TTQCString cs( o ? o->className() : "" );
if ( obj.implementsConstruct() )
val = TTQString( "new %1();" ).arg( obj.className().qstring() );
else if ( obj.implementsCall() )
val = TTQString( "%1(...);" ).arg( obj.className().qstring() );
kdDebug( 80001 ) << "convertToVariant() got a JSObjectProxy" << endl;
} else */if ( vprx ) {
kdDebug( 80001 ) << "convertToVariant() got a variant JSValueProxy" << endl;
val = vprx->toVariant();
} else if ( prxy ) {
/* kdDebug( 80001 ) << "convertToVariant() got a JSProxy" << endl;
val = prxy->typeName();
*/
} else { // Last resort map the object to a TTQMap<TTQString,TTQVariant>
kdDebug( 80001 ) << "convertToVariant() map to struct." << endl;
val = convertArrayToMap(exec, v);
}
}
break;
}
default:
{
TTQString msg = i18n( "Unsupported KJS::Value, type %1" ).arg( ( int ) v.type() );
throwError(exec, msg);
val = msg;
break;
}
}
kdDebug(80001) << "Returning a " << val.typeName() << endl;
return val;
}
TTQStringList dumpCompletion( KJS::ExecState *exec, KJS::Object &obj ) {
TTQStringList returnList;
if ( !obj.isValid() ) {
return returnList;
}
KJS::ReferenceList l = obj.propList( exec );
KJS::ReferenceListIterator propIt = l.begin();
while ( propIt != l.end() ) {
KJS::Identifier name = propIt->getPropertyName( exec );
if ( obj.hasProperty( exec, name ) ) {
KJS::Value v = obj.get( exec, name );
KJS::Object vobj = v.toObject( exec );
TTQString nm( name.ustring().qstring() );
TTQString vl;
if ( vobj.implementsConstruct() ) {
if ( vobj.prototype().toString( exec ).qstring() == "[function]" )
returnList << TTQString( "%1(...)" ).arg( nm );
} else if ( vobj.implementsCall() ) {
returnList << TTQString( "%1(...)" ).arg( nm );
} else {
TTQVariant val = convertToVariant( exec, v );
vl = val.toString();
returnList << nm;
}
}
propIt++;
}
JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() );
TTQObject *qo = proxy ? proxy->object() : 0;
TTQMetaObject *mo = qo ? qo->metaObject() : 0;
// TQObject
if ( proxy ) {
// TQProperties
TTQStrList propList( mo->propertyNames( true ) );
for ( TTQStrListIterator iter1( propList ); iter1.current(); ++iter1 ) {
TTQCString name = iter1.current();
int propid = mo->findProperty( name.data(), true );
if ( propid == -1 )
continue;
returnList << name;
}
// Slots
KJS::List items;
TTQStrList slotList( mo->slotNames( true ) );
for ( TTQStrListIterator iter2( slotList ); iter2.current(); ++iter2 ) {
TTQCString name = iter2.current();
TTQString nm( name );
int slotid = mo->findSlot( name.data(), true );
if ( slotid != -1 ) {
returnList << nm;
}
}
}
return returnList;
}
TTQString dumpObject( KJS::ExecState *exec, KJS::Object &obj ) {
if ( !obj.isValid() )
return TTQString( "Invalid object\n" );
TTQStringList properties;
TTQStringList methods;
KJS::ReferenceList l = obj.propList( exec, true );
KJS::ReferenceListIterator propIt = l.begin();
while ( propIt != l.end() ) {
KJS::Identifier name = propIt->getPropertyName( exec );
if ( obj.hasProperty( exec, name ) ) {
KJS::Value v = obj.get( exec, name );
KJS::Object vobj = v.toObject( exec );
TTQString nm( name.ustring().qstring() );
kdDebug( 80001 ) << "Getting: " << name.ustring().qstring() << " "
<< vobj.prototype().toString( exec ).qstring() << endl;
if ( vobj.implementsConstruct() ) {
// Do nothing
kdDebug( 80001 ) << "implementsConstruct: " << nm << endl;
if ( vobj.prototype().toString( exec ).qstring() == "[function]" )
methods += nm;
} else if ( vobj.implementsCall() ) {
kdDebug( 80001 ) << "implementsCall: " << nm << endl;
methods += nm;
} else {
properties += nm;
}
}
propIt++;
}
TTQString s;
// JS properties
s += TTQString( "<h2>Properties</h2>\n" );
if ( !properties.isEmpty() ) {
s += "<table width=\"90%\">\n";
s += "<tr><th>Type</th><th>Name</th><th>Value</th></tr>\n";
properties.sort();
for ( TTQStringList::Iterator iter = properties.begin(); iter != properties.end(); ++iter ) {
KJS::Value v = obj.get( exec, KJS::Identifier( KJS::UString( *iter ) ) );
TTQVariant val = convertToVariant( exec, v );
s += TTQString( "<tr><td align=\"center\">%1</td><td><b>%2</b></td><td align=\"center\">%3</td></tr>\n" )
.arg( val.typeName() ).arg( *iter ).arg( val.toString() );
}
s += "</table>\n";
} else
s += "<i>None</i>\n";
// Methods
s += TTQString( "<h2>Methods</h2>\n" );
if ( !methods.isEmpty() ) {
s += "<table width=\"90%\">";
methods.sort();
for ( TTQStringList::Iterator iter = methods.begin(); iter != methods.end(); ++iter ) {
s += "<tr><td><b>";
s += *iter;
s += "(...)</b></td></tr>";
}
s += "</table>";
} else
s += "<i>None</i>\n";
s += dumpTQObject( exec, obj );
return s;
}
TTQString dumpTQObject( KJS::ExecState * /*exec*/, KJS::Object &obj ) {
if ( !obj.isValid() )
return TTQString( "Invalid object\n" );
TTQString s( "" );
JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() );
TTQObject *qo = proxy ? proxy->object() : 0;
TTQMetaObject *mo = qo ? qo->metaObject() : 0;
// TQObject
if ( proxy ) {
// TQProperties
s += TTQString( "<h2>Qt Properties</h2>\n" );
TTQStrList propList( mo->propertyNames( true ) );
if ( !propList.isEmpty() ) {
s += "<table width=\"90%\">\n";
s += "<tr><th>Type</th><th>Name</th><th>Value</th></tr>\n";
propList.sort();
for ( TTQStrListIterator iter( propList ); iter.current(); ++iter ) {
TTQCString name = iter.current();
int propid = mo->findProperty( name.data(), true );
if ( propid == -1 )
continue;
TTQVariant vl = qo->property( name.data() );
s += TTQString( "<tr><td align=\"center\">%1</td><td><b>%2</b></td><td align=\"center\">%3</td></tr>\n" )
.arg( mo->property( propid, true ) ->type() ).arg( name ).arg( vl.toString() );
}
s += "</table>\n";
} else {
s += "<i>None</i>";
}
// Signals
s += TTQString( "<h2>Qt Signals</h2>\n" );
s += "<table width=\"90%\">";
TTQStrList signalList( mo->signalNames( true ) );
signalList.sort();
for ( TTQStrListIterator iter1( signalList ); iter1.current(); ++iter1 ) {
TTQCString name = iter1.current();
TTQString nm( name );
int signalid = mo->findSignal( name.data(), true );
if ( signalid != -1 )
s += TTQString( "<tr><td><b>%1</b></td></tr>\n" ).arg( nm );
}
s += "</table>";
if ( signalList.isEmpty() )
s += "<i>None</i>";
// Slots
s += TTQString( "<h2>Qt Slots</h2>\n" );
s += "<table width=\"90%\">";
KJS::List items;
TTQStrList slotList( mo->slotNames( true ) );
slotList.sort();
for ( TTQStrListIterator iter2( slotList ); iter2.current(); ++iter2 ) {
TTQCString name = iter2.current();
TTQString nm( name );
int slotid = mo->findSlot( name.data(), true );
if ( slotid != -1 ) {
const TQMetaData * md = mo->slot( slotid, true );
const TQUMethod *method = md->method;
if ( method->count && ( method->parameters->inOut == TQUParameter::Out ) ) {
TTQCString typenm( method->parameters->type->desc() );
if ( typenm == "ptr" ) {
s += TTQString( "<tr><td>%1</td><td><b>%2</b></td></tr>\n" )
.arg( ( const char * ) method->parameters->typeExtra ).arg( nm );
} else {
s += TTQString( "<tr><td>%1</td><td><b>%2</b></td></tr>\n" )
.arg( typenm.data() ).arg( nm );
}
} else
s += TTQString( "<tr><td>void</td><td><b>%1</b></td></tr>\n" ).arg( nm );
}
}
s += "</table>";
if ( slotList.isEmpty() )
s += "<i>None</i>";
}
return s;
}
TTQPen extractTQPen( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPen() : TTQPen();
}
TTQBrush extractTQBrush( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toBrush() : TTQBrush();
}
TTQFont extractTQFont( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toFont() : TTQFont();
}
TTQPixmap extractTQPixmap( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPixmap() : TTQPixmap();
}
TTQImage extractTQImage( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toImage() : TTQImage();
}
TTQPalette extractTQPalette( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPalette() : TTQPalette();
}
TTQString extractTQString( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? args[ idx ].toString( exec ).qstring() : TTQString::null;
}
int extractInt( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? args[ idx ].toInteger( exec ) : 0;
}
TTQColor extractTQColor( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toColor() : TTQColor();
}
TTQSize extractTQSize( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toSize() : TTQSize();
}
bool extractBool( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? args[ idx ].toBoolean( exec ) : false;
}
double extractDouble( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? args[ idx ].toNumber( exec ) : 0.0;
}
uint extractUInt( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? args[ idx ].toUInt32( exec ) : 0;
}
TTQStringList extractTQStringList( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertArrayToStringList( exec, args[ idx ] ) : TTQStringList();
}
/**
* This will return if the value is a list, associative array or neither
* @return
*/
JavaScriptArrayType checkArray( KJS::ExecState *exec, const KJS::Value &val ) {
KJS::Object obj = val.toObject( exec );
kdDebug( 80001 ) << "Object type: " << obj.className().qstring() << endl;
if ( obj.className().qstring() == "Array" ) {
//KJS::ReferenceList lst = obj.propList( exec, true );
KJS::Value len = obj.get(exec, KJS::Identifier("length"));
kdDebug(80001) << "Array length: " << len.toNumber(exec) << endl;
kdDebug(80001) << "Object type: " << len.type() << endl;
char buff[4];
if( !obj.hasProperty(exec, KJS::Identifier("length")) )
return Map;
else if( !obj.hasProperty(exec, KJS::Identifier( itoa((len.toNumber(exec) - 1), buff, 10 ) ) ) )
return Map;
/*
if( obj.get(exec, KJS::Identifier("length")).toInteger(exec) == 0 )
return List;
int offset = 0;
KJS::ReferenceListIterator idx = lst.begin();
for ( ; idx != lst.end(); idx++ ) {
if ( idx->getPropertyName( exec ).qstring().toInt() != offset )
return Map;
offset++;
kdDebug( 80001 ) << "Property Name: " << idx->getPropertyName( exec ).qstring() << endl;
kdDebug( 80001 ) << "Property Value: " << idx->getValue( exec ).toString( exec ).qstring() << endl;
}
*/
else
return List;
} else
return None;
}
TTQMap<TTQString, TTQVariant> convertArrayToMap( KJS::ExecState *exec, const KJS::Value &value ) {
TTQMap<TTQString, TTQVariant> returnMap;
KJS::Object obj = value.toObject(exec);
// if( obj.className().qstring() == "Array" ) {
KJS::ReferenceList lst = obj.propList(exec,false);
KJS::ReferenceListIterator idx = lst.begin();
for( ; idx != lst.end(); idx++ )
{
KJS::Identifier id = idx->getPropertyName(exec);
KJS::Value val = idx->getValue(exec);
returnMap.insert(id.qstring(),convertToVariant(exec,val));
}
// }
return returnMap;
}
TTQValueList<TTQVariant> convertArrayToList( KJS::ExecState *exec, const KJS::Value &value ) {
TTQValueList<TTQVariant> returnList;
KJS::Object obj = value.toObject( exec );
if ( obj.className().qstring() == "Array" ) {
int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec );
for ( int index = 0; index < length; ++index ) {
char buff[4];
KJS::Value val = obj.get(exec, KJS::Identifier( itoa( index, buff, 10 ) ) );
if( val.isValid() )
returnList += convertToVariant(exec, val );
else
returnList += "";
}
}
return returnList;
}
TTQStringList convertArrayToStringList( KJS::ExecState *exec, const KJS::Value &value ) {
TTQStringList returnList;
KJS::Object obj = value.toObject( exec );
if ( obj.className().qstring() == "Array" ) {
int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec );
for ( int index = 0; index < length; ++index ) {
char buff[4];
KJS::Value val = obj.get(exec, KJS::Identifier( itoa( index, buff, 10 ) ) );
if( val.isValid() )
returnList += val.toString(exec).qstring();
else
returnList += "";
}
}
return returnList;
}
/*
TTQStringList convertArrayToStringList( KJS::ExecState *exec, const KJS::Value &value ) {
TTQStringList returnList;
KJS::Object obj = value.toObject( exec );
if ( obj.className().qstring() == "Array" ) {
int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec );
for ( int index = 0; index < length; ++index ) {
returnList << obj.get( exec, KJS::Identifier( KJS::UString::from( index ) ) ).toString( exec ).qstring();
}
}
return returnList;
}
*/
TTQDateTime convertDateToDateTime( KJS::ExecState *exec, const KJS::Value &value ) {
KJS::List args;
TTQDateTime returnDateTime;
KJS::Object obj = value.toObject( exec );
if ( obj.className().qstring() == "Date" ) {
int seconds = obj.get( exec, KJS::Identifier( "getSeconds" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec );
int minutes = obj.get( exec, KJS::Identifier( "getMinutes" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec );
int hours = obj.get( exec, KJS::Identifier( "getHours" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec );
int month = obj.get( exec, KJS::Identifier( "getMonth" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec );
int day = obj.get( exec, KJS::Identifier( "getDate" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec );
int year = obj.get( exec, KJS::Identifier( "getFullYear" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec );
returnDateTime.setDate( TTQDate( year, month + 1, day ) );
returnDateTime.setTime( TTQTime( hours, minutes, seconds ) );
} else {
kdWarning() << "convertDateToDateTime() received a " << obj.className().qstring() << " instead of a Date" << endl;
}
return returnDateTime;
}
TTQDateTime extractTQDateTime( KJS::ExecState * exec, const KJS::List & args, int idx ) {
return ( args.size() > idx ) ? convertDateToDateTime( exec, args[ idx ] ) : TTQDateTime();
}
TTQDate extractTQDate( KJS::ExecState * exec, const KJS::List & args, int idx ) {
return ( args.size() > idx ) ? convertDateToDateTime( exec, args[ idx ] ).date() : TTQDate();
}
TTQTime extractTQTime( KJS::ExecState * exec, const KJS::List & args, int idx ) {
return ( args.size() > idx ) ? convertDateToDateTime( exec, args[ idx ] ).time() : TTQTime();
}
TTQRect extractTQRect( KJS::ExecState * exec, const KJS::List & args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toRect() : TTQRect();
}
TTQPoint extractTQPoint( KJS::ExecState * exec, const KJS::List & args, int idx ) {
return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPoint() : TTQPoint();
}
TTQStrList extractTQStrList( KJS::ExecState *exec, const KJS::List &args, int idx ) {
return ( args.size() > idx ) ? convertArrayToStrList( exec, args[ idx ] ) : TTQStrList();
}
TTQStrList convertArrayToStrList( KJS::ExecState *exec, const KJS::Value &value ) {
TTQStrList returnList;
KJS::Object obj = value.toObject( exec );
if ( obj.className().qstring() == "Array" ) {
int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec );
for ( int index = 0; index < length; ++index ) {
returnList.append( obj.get( exec, KJS::Identifier( KJS::UString::from( index ) ) ).toString( exec ).qstring().latin1() );
}
}
return returnList;
}
TTQObject *extractTQObject( KJS::ExecState *exec, const KJS::List &args, int idx ) {
KJS::Object obj = args[ idx ].toObject( exec );
JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() );
if ( !proxy )
return 0L;
return proxy->object();
}
TTQWidget *extractTQWidget( KJS::ExecState *exec, const KJS::List &args, int idx ) {
KJS::Object obj = args[ idx ].toObject( exec );
JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() );
if ( !proxy )
return 0L;
return proxy->widget();
}
JSOpaqueProxy *extractOpaqueProxy( KJS::ExecState *exec, const KJS::List &args, int idx ) {
KJS::Object obj = args[ idx ].toObject( exec );
return JSProxy::toOpaqueProxy( obj.imp() );
}
KJS::Object throwError( KJS::ExecState *exec, const TTQString &error, KJS::ErrorType type )
{
int sourceId = exec->context().sourceId();
int startLine = exec->context().curStmtFirstLine();
KJS::Object retValue = KJS::Error::create( exec, type, error.utf8(), startLine, sourceId );
kdWarning(80001) << error << endl;
exec->setException( retValue );
return retValue;
}
} // namespace KJSEmbed
|