Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ce54c34

Browse files
committed
[[ Bug ]] Ensure result mode is not clobbered by debugger messages
This patch ensures that `return for value` and `return for error` function correctly under the debugger. Previously the call to `MCB_trace` on the last line of a handler would clobber the result mode set in the return statement. (cherry picked from commit fa4ccaa)
1 parent b796879 commit ce54c34

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

engine/src/debug.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ void MCB_message(MCExecContext &ctxt, MCNameRef mess, MCParameter *p)
208208
/* UNCHECKED */ MCVariable::createwithname(MCNAME("MCdebugresult"), MCresult);
209209
MCtracereturn = False;
210210
MCtraceabort = False;
211+
212+
MCExecResultMode t_oldresultmode = MCresultmode;
211213

212214
Boolean oldcheck;
213215
oldcheck = MCcheckstack;
@@ -246,6 +248,8 @@ void MCB_message(MCExecContext &ctxt, MCNameRef mess, MCParameter *p)
246248
MCresult = oldresult;
247249
MCU_restoreprops(sp);
248250
MCexitall = exitall;
251+
MCresultmode = t_oldresultmode;
252+
249253
}
250254

251255
void MCB_prepmessage(MCExecContext &ctxt, MCNameRef mess, uint2 line, uint2 pos, uint2 id, MCStringRef p_info)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
script "CoreEngineTrace"
2+
/*
3+
Copyright (C) 2018 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on trace pHandlerName, pLine
20+
set the traceReturn to true
21+
end trace

tests/lcs/core/engine/return.livecodescript

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,21 @@ on TestReturnNested
229229
the result is "ReturnValue" and \
230230
it is "TheIt"
231231
end TestReturnNested
232+
233+
on TestMessageMessagesResultMode
234+
local tPath
235+
put format("%s/../_trace.livecodescript", the filename of me) into tPath
236+
start using stack tPath
237+
set the traceReturn to true
238+
set the traceStack to the long id of me
239+
DoReturnValueInCommand "foobar"
240+
local tIt, tResult
241+
put it into tIt
242+
put the result into tResult
243+
TestDiagnostic "it" && tIt
244+
TestDiagnostic "result" && tResult
245+
TestAssert "result mode is not clobbered in messageHandled", tIt is "foobar"
246+
set the traceStack to empty
247+
stop using stack tPath
248+
end TestMessageMessagesResultMode
249+

0 commit comments

Comments
 (0)