debugging javascript in html5
Mark Waddingham
mark at livecode.com
Fri Mar 18 07:30:59 EDT 2022
On 2022-03-18 11:19, Bernard Devlin via use-livecode wrote:
> Here's a peculiarity I haven't seen mentioned before. I am trying to
> test
> the viability of the idea of a function to call back to LC and provide
> debugging info.
>
> Assume you create a LC function lclog(pmsg,pval) and you put a
> breakpoint
> in the IDE inside that function body. Set the htmltext of a browser
> widget
> to the code below, set the javascriptHandlers of the browser to contain
> the
> word: lclog . Your browser widget will have a button 'clickme'.
> 1) On clicking that button the JS alerts ALL trigger first.
> 2) After they have fired the first call to lclog() runs, and the second
> call to lclog() never runs.
>
> <html><head><script>
>
> function lcxhr(method, url) {
>
> alert('lcxhr called');
>
> var json = JSON.stringify({ name: "John", surname: "Smith"});
>
> liveCode.lclog('json created', json);
>
> alert('you see this alert before the above call to lclog()');
>
> liveCode.lclog('exit js function','');
>
> }</script>
So this is quite separate from what happens in the web engine which
works very differently.
Embeddable browsers are inherently asynchronous in their execution (not
necessarily in a multi-thready way, although that does play a part) -
but more in the sense that you can't get an embedded browser to do
anything and have it 'block' until it is done.
The converse is also true - the request to call an LC handler from the
browser widget is basically a post - not a send - which means that
(really) you can only call LC handlers as tail calls - i.e. as the last
thing on a handler.
Warmest Regards,
Mark.
P.S. The web engine is (essentially) the running the LC script 'as
JavaScript' so the same limitation does not apply - calling LC handlers
from JS in the web engine is synchronous.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list