@@ -386,13 +386,11 @@ class QtObjectNotifyCaller : public QObject
386
386
}
387
387
};
388
388
389
-
390
389
// A C++ signal-to-JS handler connection.
391
390
//
392
391
// Acts as a middle-man; intercepts a C++ signal,
393
392
// and invokes a JS callback function.
394
393
//
395
- class QScriptSignalData ;
396
394
class QScriptConnection : public QObject
397
395
{
398
396
public:
@@ -425,138 +423,12 @@ class QScriptConnection : public QObject
425
423
v8::Persistent<v8::Object> m_receiver;
426
424
};
427
425
428
- union QScriptMetaMethodInfo {
429
- QScriptMetaMethodInfo (): intData (0 )
430
- { }
431
-
432
- uint32_t intData;
433
- struct {
434
- uint index: 28 ;
435
- uint resolveMode: 1 ;
436
- uint overloaded: 1 ;
437
- uint voidvoid: 1 ;
438
- uint padding: 1 ; // Make sure the struct fits in an SMI
439
- };
440
- };
441
-
442
- template <typename T, v8::Persistent<v8::FunctionTemplate> QScriptEnginePrivate::*functionTemplate>
443
- class QScriptGenericMetaMethodData : public QScriptV8ObjectWrapper <T, functionTemplate> {
444
- public:
445
- enum ResolveMode {
446
- ResolvedByName = 0 ,
447
- ResolvedBySignature = 1
448
- };
449
-
450
- QScriptGenericMetaMethodData (QScriptEnginePrivate *eng, v8::Handle<v8::Object> object, QScriptMetaMethodInfo info)
451
- : m_object(v8::Persistent<v8::Object>::New(object)), m_info(info)
452
- {
453
- this ->engine = eng;
454
- // We cannot keep a persistant reference to the object, else it would never be garbage collected.
455
- // (the object also reference us, and persistent object are automatically marked.
456
- // A reference is kept in the second internal field of the v8 method object.
457
- m_object.MakeWeak (this , objectDestroyed);
458
- }
459
- ~QScriptGenericMetaMethodData ()
460
- {
461
- m_object.Dispose ();
462
- }
463
-
464
- // The QObject wrapper object that this signal is bound to.
465
- v8::Handle<v8::Object> object () const
466
- { return m_object; }
467
-
468
- int index () const
469
- { return m_info.index ; }
470
-
471
- ResolveMode resolveMode () const
472
- { return ResolveMode (m_info.resolveMode ); }
473
-
474
- v8::Handle<v8::Value> call ();
475
-
476
- v8::Persistent<v8::Object> m_object;
477
- QScriptMetaMethodInfo m_info;
478
- private:
479
- static void objectDestroyed (v8::Persistent<v8::Value> object, void *data) {
480
- QScriptGenericMetaMethodData *that = static_cast <QScriptGenericMetaMethodData *>(data);
481
- Q_ASSERT (that->m_object == object);
482
- that->m_object .Clear ();
483
- object.Dispose ();
484
- // Note that since the method keep a reference to the object in its internal field,
485
- // this is only called when the QScriptGenericMetaMethodData is about to be garbage collected as well.
486
- }
487
- };
488
-
489
- class QScriptMetaMethodData : public QScriptGenericMetaMethodData <QScriptMetaMethodData, &QScriptEnginePrivate::metaMethodTemplate>
426
+ QScriptSignalData::~QScriptSignalData ()
490
427
{
491
- typedef QScriptGenericMetaMethodData<QScriptMetaMethodData, &QScriptEnginePrivate::metaMethodTemplate> Base;
492
- public:
493
- QScriptMetaMethodData (QScriptEnginePrivate *engine, v8::Handle<v8::Object> object, QScriptMetaMethodInfo info)
494
- : Base(engine, object, info)
495
- { }
496
-
497
- static v8::Handle<v8::FunctionTemplate> createFunctionTemplate (QScriptEnginePrivate *engine);
498
- };
499
-
500
- // Data associated with a signal JS wrapper object.
501
- //
502
- // A signal wrapper is bound to the particular Qt wrapper object
503
- // where it was looked up as a member, i.e. signal wrappers are
504
- // _per instance_, not per class (prototype). This is in order
505
- // to support the connect() and disconnect() syntax:
506
- //
507
- // button1.clicked.connect(...);
508
- // button2.clicked.connect(...);
509
- //
510
- // When connect() is called, the this-object will be the signal
511
- // wrapper, not the QObject. Hence, in order to know which object's
512
- // clicked() signal to connect to, the signal must be bound to
513
- // that object.
514
- //
515
- // - object: The Qt wrapper object that this signal is bound to.
516
- //
517
- // - index: The index of the C++ signal.
518
- //
519
- // - resolve mode: How the signal was resolved; by name or signature.
520
- // If it was resolved by name, there's a chance the signal might have overloads.
521
- //
522
- class QScriptSignalData : public QScriptGenericMetaMethodData <QScriptSignalData, &QScriptEnginePrivate::signalTemplate>
523
- {
524
- typedef QScriptGenericMetaMethodData<QScriptSignalData, &QScriptEnginePrivate::signalTemplate> Base;
525
- public:
526
-
527
- QScriptSignalData (QScriptEnginePrivate *engine, v8::Handle<v8::Object> object, QScriptMetaMethodInfo info)
528
- : Base(engine, object, info)
529
- { }
530
-
531
- ~QScriptSignalData ()
532
- {
533
- foreach (QScriptConnection *connection, m_connections) {
534
- delete connection;
535
- }
428
+ foreach (QScriptConnection *connection, m_connections) {
429
+ delete connection;
536
430
}
537
-
538
- static v8::Handle<v8::FunctionTemplate> createFunctionTemplate (QScriptEnginePrivate *engine);
539
-
540
- v8::Handle<v8::Value> connect (v8::Handle<v8::Object> receiver,
541
- v8::Handle<v8::Object> slot,
542
- Qt::ConnectionType type = Qt::AutoConnection);
543
- v8::Handle<v8::Value> disconnect (v8::Handle<v8::Function> callback);
544
-
545
- static QScriptSignalData *get (v8::Handle<v8::Object> object)
546
- {
547
- void *ptr = object->GetPointerFromInternalField (0 );
548
- Q_ASSERT (ptr != 0 );
549
- return static_cast <QScriptSignalData*>(ptr);
550
- }
551
-
552
- void unregisterQScriptConnection (QScriptConnection *connection) { m_connections.removeAll (connection); }
553
- private:
554
- static v8::Handle<v8::Value> QtConnectCallback (const v8::Arguments& args);
555
- static v8::Handle<v8::Value> QtDisconnectCallback (const v8::Arguments& args);
556
- QList<QScriptConnection*> m_connections;
557
- };
558
-
559
-
431
+ }
560
432
561
433
v8::Handle<v8::FunctionTemplate> QScriptSignalData::createFunctionTemplate (QScriptEnginePrivate* engine)
562
434
{
0 commit comments