Skip to content

Commit

Permalink
do not add additional user arguments if it's not applicable (fixes WS…
Browse files Browse the repository at this point in the history
…ound loops regression)
  • Loading branch information
Koen Deforche committed Jul 11, 2014
1 parent 417baba commit d5834bf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Wt/WJavaScript
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ public:
virtual Wt::Signals::connection connect(WObject *target,
void (WObject::*method)());

protected:
virtual int argumentCount() const;

private:
JSignal(const JSignal<A1, A2, A3, A4, A5, A6>&);

Expand Down Expand Up @@ -653,6 +656,26 @@ bool JSignal<A1, A2, A3, A4, A5, A6>::isConnected() const
return impl_ ? impl_->num_slots() > 0 : EventSignalBase::isConnected();
}

template <typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6>
int JSignal<A1, A2, A3, A4, A5, A6>::argumentCount() const
{
if (typeid(A6) != typeid(NoClass))
return 6;
else if (typeid(A5) != typeid(NoClass))
return 5;
else if (typeid(A4) != typeid(NoClass))
return 4;
else if (typeid(A3) != typeid(NoClass))
return 3;
else if (typeid(A2) != typeid(NoClass))
return 2;
else if (typeid(A1) != typeid(NoClass))
return 1;
else
return 0;
}

template <typename T>
struct SignalArgTraits
{
Expand Down
34 changes: 34 additions & 0 deletions src/Wt/WSignal
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ protected:
static void pushSender(WObject *sender);
static void popSender();

virtual int argumentCount() const = 0;

private:
SignalBase(const SignalBase& other);

Expand Down Expand Up @@ -407,6 +409,9 @@ public:

virtual bool isConnected() const;

protected:
virtual int argumentCount() const;

private:
Signal(const Signal<A1, A2, A3, A4, A5, A6>&);

Expand Down Expand Up @@ -751,6 +756,9 @@ public:
virtual Wt::Signals::connection connect(WObject *target,
WObject::Method method);

protected:
virtual int argumentCount() const;

private:
#ifndef WT_CNOR
typedef Wt::Signals::signal<void(E)> BoostSignalType;
Expand Down Expand Up @@ -1004,6 +1012,26 @@ bool Signal<A1, A2, A3, A4, A5, A6>::isConnected() const
return impl_ ? impl_->num_slots() > 0 : false;
}

template <typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6>
int Signal<A1, A2, A3, A4, A5, A6>::argumentCount() const
{
if (typeid(A6) != typeid(NoClass))
return 6;
else if (typeid(A5) != typeid(NoClass))
return 5;
else if (typeid(A4) != typeid(NoClass))
return 4;
else if (typeid(A3) != typeid(NoClass))
return 3;
else if (typeid(A2) != typeid(NoClass))
return 2;
else if (typeid(A1) != typeid(NoClass))
return 1;
else
return 0;
}

#ifndef __clang__
template <typename E>
void *EventSignal<E>::operator new(std::size_t) {
Expand All @@ -1030,6 +1058,12 @@ bool EventSignal<E>::isConnected() const
return dynamic_.num_slots() > 0;
}

template <typename E>
int EventSignal<E>::argumentCount() const
{
return 0; // excluding the event 'e'
}

template <typename E>
template <class F>
Wt::Signals::connection EventSignal<E>::connect(const F& function)
Expand Down
11 changes: 10 additions & 1 deletion src/Wt/WSignal.C
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,18 @@ void EventSignalBase::connect(JSlot& slot)
void EventSignalBase::connect(const std::string& javaScript)
{
Wt::Signals::connection c;

int argc = argumentCount(); // user arguments, excluding 'e'

WStringStream ss;
ss << "(" << javaScript << ")(o,e";
for (int i = 0; i < argc; ++i)
ss << ",a" << (i+1);
ss << ");";

connections_.push_back
(StatelessConnection(c, 0,
new WStatelessSlot("(" + javaScript + ")(o,e,a1,a2,a3,a4,a5,a6);")));
new WStatelessSlot(ss.str())));

senderRepaint();
}
Expand Down

0 comments on commit d5834bf

Please sign in to comment.