Skip to content

Commit a356015

Browse files
committed
Merge pull request livecode#3500 from peter-b/js/unwaitify
[Bug 16619][emscripten] Disable "wait" in HTML5 engine
2 parents 6590eac + ef1acd6 commit a356015

File tree

10 files changed

+62
-59
lines changed

10 files changed

+62
-59
lines changed

docs/guides/HTML5 Deployment.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ Several important features are not yet supported:
3030

3131
* some `ask` and `answer` message boxes
3232
* networking
33+
* JavaScript in LiveCode Builder extensions
3334

34-
The HTML5 engine is unlikely ever to support externals (including revdb).
35+
Two important unsupported features are unlikely to be added in the near future:
36+
37+
* operations that need to pause the script while something happens
38+
(e.g. `wait 10`)
39+
* externals (including revdb)
3540

3641
# How to deploy an app to HTML5
3742

docs/notes/bugfix-16076.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/notes/bugfix-16619.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# No "wait" syntax in HTML5 standalones
2+
3+
In LiveCode 8.0.0-dp-11, changes were made to the HTML5 standalone
4+
engine to enable the use of `wait` (and related syntax; see
5+
[bug 16076](http://quality.livecode.com/show_bug.cgi?id/16076). These
6+
changes made the HTML5 engine run unacceptably slowly, and have now
7+
been removed.
8+
9+
Instead of using `wait` in stacks for HTML5 deployment, the use of the
10+
`send <message> in <time>` syntax is recommended.

engine/src/em-dc-mainloop.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ X_init(int argc,
118118
/* ---------- Set up global variables */
119119
X_clear_globals();
120120

121+
/* No blocking during initialization */
122+
++MCwaitdepth;
123+
121124
MCswapbytes = MCEmscriptenIsLittleEndian();
122125
MCtruemcstring = MCtruestring;
123126
MCfalsemcstring = MCfalsestring;
@@ -132,33 +135,33 @@ X_init(int argc,
132135

133136
if (!MCFontInitialize())
134137
{
135-
return false;
138+
goto error_cleanup;
136139
}
137140

138141
if (!MCLogicalFontTableInitialize())
139142
{
140-
return false;
143+
goto error_cleanup;
141144
}
142145

143146
/* ---------- More globals */
144147

145148
/* executable file name */
146149
if (!MCsystem->PathFromNative(argv[0], MCcmd))
147150
{
148-
return false;
151+
goto error_cleanup;
149152
}
150153

151154
/* Locales */
152155
if (!MCLocaleCreateWithName(MCSTR("en_US"), kMCBasicLocale))
153156
{
154-
return false;
157+
goto error_cleanup;
155158
}
156159

157160
kMCSystemLocale = MCS_getsystemlocale();
158161

159162
if (nil == kMCSystemLocale)
160163
{
161-
return false;
164+
goto error_cleanup;
162165
}
163166

164167
/* ---------- argv[] global variables */
@@ -178,11 +181,21 @@ X_init(int argc,
178181
* available in the VFS before calling X_open(). */
179182
if (!MCEmscriptenStandaloneUnpack())
180183
{
181-
return false;
184+
goto error_cleanup;
182185
}
183186

184187
/* ---------- Continue booting... */
185-
return X_open(argc, argv, envp);
188+
if (!X_open(argc, argv, envp))
189+
{
190+
goto error_cleanup;
191+
}
192+
193+
--MCwaitdepth;
194+
return true;
195+
196+
error_cleanup:
197+
--MCwaitdepth;
198+
return false;
186199
}
187200

188201
/* ================================================================

engine/src/em-dc.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,19 @@ MCScreenDC::GetCurrentStack()
170170
* Event loop
171171
* ================================================================ */
172172

173-
/* Returns true if quit is requested. */
173+
/* Returns true if quit is requested, or from any inner main loop. */
174174
Boolean
175175
MCScreenDC::wait(real64_t p_duration,
176176
Boolean p_allow_dispatch,
177177
Boolean p_accept_any_event)
178178
{
179+
/* Don't permit inner main loops. They cause amusing "-12" assertion
180+
* failures from Emterpreter. */
181+
if (0 < int(MCwaitdepth))
182+
{
183+
return true;
184+
}
185+
179186
p_duration = MCMax(p_duration, 0.0);
180187

181188
/* We allow p_duration to be infinite, but only if

engine/src/em-whitelist.json

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,9 @@
66
"^__Z20send_startup_messageb",
77
"^__Z13platform_mainiPPcS0_$",
88
"^__Z21X_main_loop_iterationv$",
9+
"^__ZN10MCScreenDC4waitEdhh$",
910

1011
"^_MCEventQueueDispatch$",
1112
"^__ZL25MCEventQueueDispatchEventP7MCEvent$",
12-
"^_MCEmscriptenAsyncYield$",
13-
14-
"MCWidgetExec",
15-
"MCWidgetOn",
16-
17-
"AddRunloopAction",
18-
"DoRunloopActions",
19-
20-
"(exec|eval)_ctxt",
21-
"4wait",
22-
"26message_with_valueref_args",
23-
"addmessage",
24-
"7message",
25-
"6handle",
26-
"13handlepending",
27-
"10handleself",
28-
"11exechandler",
29-
"[0-9]+close",
30-
"3del",
31-
"help",
32-
"[0-9]+(k|m)(focus|down|up)",
33-
"mdrag",
34-
"paste",
35-
"doubledown",
36-
"layerchanged",
37-
"resizeparent",
38-
"sync_mfocus",
39-
"toolchanged",
40-
"wdoubledown",
41-
"wmdragenter",
42-
"wmdragleave",
43-
"wmfocus_stack",
44-
45-
"MCExecContext[0-9]+(TryTo)?[Ee]val",
46-
"MCEngineEvalValue",
47-
"MCEngine\\w*Wait",
48-
"MCEngineExecDispatch",
49-
"MCEngineExecDo",
50-
"MCEngineExecSend",
51-
52-
"MC[SU]_\\w*url(?!(en|de)code)",
53-
54-
"__ZN9MCHandler4exec",
55-
"MCKeywordsExec"
13+
"^_MCEmscriptenAsyncYield$"
5614
]

engine/src/globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ uint2 MCnsockets;
241241
MCStack **MCusing;
242242
uint2 MCnusing;
243243
uint2 MCiconicstacks;
244-
uint2 MCwaitdepth;
244+
MCSemaphore MCwaitdepth;
245245
uint4 MCrecursionlimit = 400000; // actual max is about 480K on OSX
246246

247247
MCClipboard* MCclipboard;
@@ -634,7 +634,7 @@ void X_clear_globals(void)
634634
MCusing = nil;
635635
MCnusing = 0;
636636
MCiconicstacks = 0;
637-
MCwaitdepth = 0;
637+
MCwaitdepth = MCSemaphore("wait-depth");
638638
MCrecursionlimit = 400000;
639639
MCclipboard = NULL;
640640
MCselection = NULL;

engine/src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ extern uint2 MCnsockets;
163163
extern MCStack **MCusing;
164164
extern uint2 MCnusing;
165165
extern uint2 MCiconicstacks;
166-
extern uint2 MCwaitdepth;
166+
extern MCSemaphore MCwaitdepth;
167167
extern uint4 MCrecursionlimit;
168168

169169

engine/src/mcsemaphore.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class MCSemaphore
6464
return IsLocked();
6565
}
6666

67+
/* Automatic extraction of the wait depth */
68+
operator int() const
69+
{
70+
return m_counter;
71+
}
72+
6773
/* ---------- Locking ops */
6874
void Lock()
6975
{

tests/_emscripten/__boot.livecodescript

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on startup
1616
TestLoadLibrary "_inputlib"
1717

1818
-- Run tests
19-
local tTestFiles, tTestFile, tStackName, tCommand, tSetupResult
19+
local tTestFiles, tTestFile, tStackName, tCommand, tSetupResult, tError
2020

2121
put TesterGetTestFileNames("/boot/standalone") into tTestFiles
2222

@@ -45,7 +45,12 @@ on startup
4545
end if
4646

4747
-- Run tests
48-
dispatch tCommand to tStackName
48+
try
49+
dispatch tCommand to tStackName
50+
catch tError
51+
TestDiagnostic tError
52+
TestAssert empty, false
53+
end try
4954

5055
-- Send teardown command
5156
dispatch "TestTearDown" to tStackName

0 commit comments

Comments
 (0)