Skip to content

Commit a64d1b7

Browse files
Merge remote-tracking branch 'mark/bugfix-11277' into bugfix-11277_6.7
Conflicts: engine/src/cmdse.cpp engine/src/funcs.cpp
2 parents 2532874 + bb3c612 commit a64d1b7

8 files changed

Lines changed: 115 additions & 38 deletions

File tree

engine/src/cmds.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5454
#include "cmds.h"
5555
#include "mode.h"
5656
#include "osspec.h"
57+
#include "hndlrlst.h"
5758

5859
#include "core.h"
5960

@@ -309,7 +310,6 @@ MCDo::~MCDo()
309310
Parse_stat MCDo::parse(MCScriptPoint &sp)
310311
{
311312
initpoint(sp);
312-
h = sp.gethandler();
313313
if (sp.parseexp(False, True, &source) != PS_NORMAL)
314314
{
315315
MCperror->add(PE_DO_BADEXP, sp);
@@ -418,7 +418,13 @@ Exec_stat MCDo::exec(MCExecPoint &ep)
418418
MCeerror->add(EE_DO_BADEXP, line, pos);
419419
return ES_ERROR;
420420
}
421-
Exec_stat stat = h->doscript(*epptr, line, pos);
421+
// MW-2013-11-15: [[ Bug 11277 ]] If no handler, then evaluate in context of the
422+
// server script object.
423+
Exec_stat stat;
424+
if (ep . gethandler() != nil)
425+
stat = ep.gethandler()->doscript(*epptr, line, pos);
426+
else
427+
stat = ep.gethlist()->doscript(*epptr, line, pos);
422428
if (added)
423429
MCnexecutioncontexts--;
424430
return stat;

engine/src/cmds.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class MCConvert : public MCStatement
9696

9797
class MCDo : public MCStatement
9898
{
99-
MCHandler *h;
10099
MCExpression *source;
101100
MCExpression *alternatelang;
102101
protected:
@@ -1046,7 +1045,6 @@ class MCInsert : public MCStatement
10461045

10471046
class MCMessage : public MCStatement
10481047
{
1049-
MCHandler *h;
10501048
MCExpression *message;
10511049
MCExpression *eventtype;
10521050
MCChunk *target;

engine/src/cmdse.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4646
#include "osspec.h"
4747
#include "image.h"
4848
#include "font.h"
49+
#include "hndlrlst.h"
4950

5051
#include "globals.h"
5152

@@ -868,7 +869,6 @@ Parse_stat MCMessage::parse(MCScriptPoint &sp)
868869
{
869870
initpoint(sp);
870871

871-
h = sp.gethandler();
872872
if (sp.parseexp(False, True, &message) != PS_NORMAL)
873873
{
874874
MCperror->add(PE_SEND_BADEXP, sp);
@@ -1017,7 +1017,14 @@ Exec_stat MCMessage::exec(MCExecPoint &ep)
10171017

10181018
// MW-2011-08-11: [[ Bug 9668 ]] Make sure we copy 'pdata' if we use it, since
10191019
// mptr (into which it points) only lasts as long as this method call.
1020-
if (h->eval(ep) == ES_NORMAL)
1020+
// MW-2013-11-15: [[ Bug 11277 ]] If no handler, evaluate in the context of the
1021+
// server script object.
1022+
Exec_stat t_stat;
1023+
if (ep.gethandler() != nil)
1024+
t_stat = ep . gethandler() -> eval(ep);
1025+
else
1026+
t_stat = ep . gethlist() -> eval(ep);
1027+
if (t_stat == ES_NORMAL)
10211028
newparam->set_argument(ep);
10221029
else
10231030
newparam->copysvalue_argument(pdata);

engine/src/express.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class MCExpression
119119
class MCFuncref : public MCExpression
120120
{
121121
MCNameRef name;
122-
MCHandler *handler;
122+
MCHandler *handler;
123123
MCObject *parent;
124124
MCParameter *params;
125125
bool resolved : 1;

engine/src/funcs.cpp

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,14 +3349,21 @@ Exec_stat MCLocalLoc::eval(MCExecPoint &ep)
33493349

33503350
Parse_stat MCLocals::parse(MCScriptPoint &sp, Boolean the)
33513351
{
3352-
h = sp.gethandler();
33533352
return MCFunction::parse(sp, the);
33543353
}
33553354

33563355
Exec_stat MCLocals::eval(MCExecPoint &ep)
33573356
{
33583357
#ifdef /* MCLocals */ LEGACY_EXEC
3359-
return h->getvarnames(ep, False);
3358+
// MW-2013-11-15: [[ Bug 11277 ]] Server mode may call this outwith a handler.
3359+
3360+
if (ep . gethandler() != nil)
3361+
return ep . gethandler() -> getvarnames(ep, False);
3362+
3363+
ep.clear();
3364+
ep . gethlist() -> appendlocalnames(ep);
3365+
3366+
return ES_NORMAL;
33603367
#endif /* MCLocals */
33613368
}
33623369

@@ -3598,7 +3605,6 @@ MCMerge::~MCMerge()
35983605

35993606
Parse_stat MCMerge::parse(MCScriptPoint &sp, Boolean the)
36003607
{
3601-
h = sp.gethandler();
36023608
if (get1param(sp, &source, the) != PS_NORMAL)
36033609
{
36043610
MCperror->add
@@ -3682,17 +3688,29 @@ Exec_stat MCMerge::eval(MCExecPoint &ep)
36823688
uint4 ei = si + sptr + 1 - pstart;
36833689
MCString s(pstart + 2, pend - pstart - 4);
36843690
ep2.setsvalue(s);
3691+
// MW-2013-11-15: [[ Bug 11277 ]] If ep has no handler, then execute in
3692+
// server script object context.
36853693
if (isexpression)
36863694
{
3687-
if (h->eval(ep2) != ES_ERROR)
3695+
Exec_stat t_stat;
3696+
if (ep.gethandler() != nil)
3697+
t_stat = ep . gethandler()->eval(ep2);
3698+
else
3699+
t_stat = ep . gethlist()-> eval(ep2);
3700+
if (t_stat != ES_ERROR)
36883701
{
36893702
ep.insert(ep2.getsvalue(), si, ei);
36903703
rlength += ep2.getsvalue().getlength() - (pend - pstart);
36913704
}
36923705
}
36933706
else
36943707
{
3695-
if (h->doscript(ep2, line, pos) != ES_ERROR)
3708+
Exec_stat t_stat;
3709+
if (ep.gethandler() != nil)
3710+
t_stat = ep . gethandler() -> doscript(ep2, line, pos);
3711+
else
3712+
t_stat = ep . gethlist() -> doscript(ep2, line, pos);
3713+
if (t_stat != ES_ERROR)
36963714
{
36973715
MCresult->fetch(ep2);
36983716
ep.insert(ep2.getsvalue(), si, ei);
@@ -4148,7 +4166,6 @@ MCParam::~MCParam()
41484166

41494167
Parse_stat MCParam::parse(MCScriptPoint &sp, Boolean the)
41504168
{
4151-
h = sp.gethandler();
41524169
if (get1param(sp, &source, the) != PS_NORMAL)
41534170
{
41544171
MCperror->add
@@ -4166,46 +4183,68 @@ Exec_stat MCParam::eval(MCExecPoint &ep)
41664183
MCeerror->add(EE_PARAM_BADSOURCE, line, pos);
41674184
return ES_ERROR;
41684185
}
4169-
if (h->getparam(ep.getuint2(), ep) != ES_NORMAL)
4186+
// MW-2013-11-15: [[ Bug 11277 ]] If we don't have a handler then 'the param'
4187+
// makes no sense so just return empty.
4188+
if (ep.gethandler() != nil)
41704189
{
4171-
MCeerror->add(EE_PARAM_BADINDEX, line, pos, ep.getsvalue());
4172-
return ES_ERROR;
4190+
if (ep . gethandler()->getparam(ep.getuint2(), ep) != ES_NORMAL)
4191+
{
4192+
MCeerror->add(EE_PARAM_BADINDEX, line, pos, ep.getsvalue());
4193+
return ES_ERROR;
4194+
}
4195+
}
4196+
else
4197+
{
4198+
ep.clear();
41734199
}
41744200
return ES_NORMAL;
41754201
#endif /* MCParam */
41764202
}
41774203

41784204
Parse_stat MCParamCount::parse(MCScriptPoint &sp, Boolean the)
41794205
{
4180-
h = sp.gethandler();
41814206
return MCFunction::parse(sp, the);
41824207
}
41834208

41844209
Exec_stat MCParamCount::eval(MCExecPoint &ep)
41854210
{
41864211
#ifdef /* MCParamCount */ LEGACY_EXEC
4187-
uint2 count;
4188-
// PM-2014-04-14: [[Bug 12105]] Do this check to prevent crash in LC server
4189-
if (h == NULL)
4190-
{
4191-
MCeerror->add(EE_PARAMCOUNT_NOHANDLER, line, pos);
4192-
return ES_ERROR;
4193-
}
4194-
h->getnparams(count);
4195-
ep.setnvalue(count);
4212+
// MW-2013-11-15: [[ Bug 11277 ]] If we don't have a handler then 'the param'
4213+
// makes no sense so just return 0.
4214+
if (ep.gethandler() != nil)
4215+
{
4216+
uint2 count;
4217+
ep.gethandler()->getnparams(count);
4218+
ep.setnvalue(count);
4219+
}
4220+
else
4221+
{
4222+
ep.setnvalue(0);
4223+
}
4224+
41964225
return ES_NORMAL;
41974226
#endif /* MCParamCount */
41984227
}
41994228

42004229
Parse_stat MCParams::parse(MCScriptPoint &sp, Boolean the)
42014230
{
4202-
h = sp.gethandler();
42034231
return MCFunction::parse(sp, the);
42044232
}
42054233

42064234
Exec_stat MCParams::eval(MCExecPoint &ep)
42074235
{
42084236
#ifdef /* MCParams */ LEGACY_EXEC
4237+
// MW-2013-11-15: [[ Bug 11277 ]] If we don't have a handler then 'the param'
4238+
// makes no sense so just return empty.
4239+
if (ep.gethandler() == nil)
4240+
{
4241+
ep . clear();
4242+
return ES_NORMAL;
4243+
}
4244+
4245+
MCHandler *h;
4246+
h = ep.gethandler();
4247+
42094248
ep . setnameref_unsafe(h -> getname());
42104249
ep . appendchar(h -> gettype() == HT_FUNCTION ? '(' : ' ');
42114250

@@ -5431,7 +5470,6 @@ MCValue::~MCValue()
54315470

54325471
Parse_stat MCValue::parse(MCScriptPoint &sp, Boolean the)
54335472
{
5434-
h = sp.gethandler();
54355473
if (the)
54365474
{
54375475
if (get1param(sp, &source, the) != PS_NORMAL)
@@ -5543,26 +5581,44 @@ Exec_stat MCValue::eval(MCExecPoint &ep)
55435581
delete tptr;
55445582
}
55455583
else
5546-
if (h->eval(ep) != ES_NORMAL)
5584+
{
5585+
Exec_stat t_stat;
5586+
if (ep . gethandler() != nil)
5587+
t_stat = ep . gethandler() -> eval(ep);
5588+
else
5589+
t_stat = ep . gethlist() -> eval(ep);
5590+
5591+
if (t_stat != ES_NORMAL)
55475592
{
55485593
MCeerror->add
55495594
(EE_VALUE_ERROR, line, pos, ep.getsvalue());
55505595
return ES_ERROR;
55515596
}
5597+
}
55525598
return ES_NORMAL;
55535599
#endif /* MCValue */
55545600
}
55555601

55565602
Parse_stat MCVariables::parse(MCScriptPoint &sp, Boolean the)
55575603
{
5558-
h = sp.gethandler();
55595604
return MCFunction::parse(sp, the);
55605605
}
55615606

55625607
Exec_stat MCVariables::eval(MCExecPoint &ep)
55635608
{
55645609
#ifdef /* MCVariables */ LEGACY_EXEC
5565-
return h->getvarnames(ep, True);
5610+
// MW-2013-11-15: [[ Bug 11277 ]] If no handler, then process the handler list
5611+
// (server script scope).
5612+
if (ep . gethandler() != nil)
5613+
return ep.gethandler()->getvarnames(ep, True);
5614+
else
5615+
{
5616+
ep.clear();
5617+
ep.gethlist() -> appendlocalnames(ep);
5618+
ep.appendnewline();
5619+
ep.gethlist() -> appendglobalnames(ep, True);
5620+
}
5621+
return ES_NORMAL;
55665622
#endif /* MCVariables */
55675623
}
55685624

engine/src/funcs.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ class MCLocalLoc : public MCFunction
837837

838838
class MCLocals : public MCFunction
839839
{
840-
MCHandler *h;
841840
public:
842841
virtual Parse_stat parse(MCScriptPoint &, Boolean the);
843842
virtual Exec_stat eval(MCExecPoint &);
@@ -924,7 +923,6 @@ class MCMenus : public MCFunction
924923
class MCMerge : public MCFunction
925924
{
926925
public:
927-
MCHandler *h;
928926
MCExpression *source;
929927
public:
930928
MCMerge()
@@ -1111,7 +1109,6 @@ class MCOptionKey : public MCFunction
11111109

11121110
class MCParam : public MCFunction
11131111
{
1114-
MCHandler *h;
11151112
MCExpression *source;
11161113
public:
11171114
MCParam()
@@ -1125,15 +1122,13 @@ class MCParam : public MCFunction
11251122

11261123
class MCParamCount : public MCFunction
11271124
{
1128-
MCHandler *h;
11291125
public:
11301126
virtual Parse_stat parse(MCScriptPoint &, Boolean the);
11311127
virtual Exec_stat eval(MCExecPoint &);
11321128
};
11331129

11341130
class MCParams : public MCFunction
11351131
{
1136-
MCHandler *h;
11371132
public:
11381133
virtual Parse_stat parse(MCScriptPoint &, Boolean the);
11391134
virtual Exec_stat eval(MCExecPoint &);
@@ -1585,7 +1580,6 @@ class MCUrlStatus : public MCFunction
15851580

15861581
class MCValue : public MCFunction
15871582
{
1588-
MCHandler *h;
15891583
MCExpression *source;
15901584
MCChunk *object;
15911585
public:
@@ -1601,7 +1595,6 @@ class MCValue : public MCFunction
16011595

16021596
class MCVariables : public MCFunction
16031597
{
1604-
MCHandler *h;
16051598
public:
16061599
virtual Parse_stat parse(MCScriptPoint &, Boolean the);
16071600
virtual Exec_stat eval(MCExecPoint &);

engine/src/hndlrlst.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,16 @@ bool MCHandlerlist::enumerate(MCExecPoint& ep, bool p_first)
659659

660660
return p_first;
661661
}
662+
663+
Exec_stat MCHandlerlist::eval(MCExecPoint& ep)
664+
{
665+
// TODO: Implement execution outside of a handler.
666+
return ES_ERROR;
667+
}
668+
669+
Exec_stat MCHandlerlist::doscript(MCExecPoint& ep, uint2 line, uint2 pos)
670+
{
671+
// TODO: Implement execution outside of a handler.
672+
return ES_ERROR;
673+
}
674+

engine/src/hndlrlst.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ class MCHandlerlist
130130
MCVariable *getglobal(uint2 p_index);
131131
bool enumerate(MCExecPoint& ep, bool p_first = true);
132132

133+
// MW-2013-11-15: [[ Bug 11277 ]] Methods for eval/exec in handlerlist context.
134+
Exec_stat eval(MCExecPoint& ep);
135+
Exec_stat doscript(MCExecPoint& ep, uint2 line, uint2 pos);
136+
133137
uint2 getnvars(void)
134138
{
135139
return nvars;

0 commit comments

Comments
 (0)