Asynchronous script execution

Hello,

I've just started embedding SpiderMonkey within my application, and so far,
it's great, but I'm wondering how I could do the following :

function example()
{
  Windows.MessageBox( 'hello world' );
}

Application.onStartup = example;

The part about calling the message box or calling the event is not a
problem. However, I use JS_ExecuteScript. So I cannot, like.. execute it,
THEN call onStartup from the host application. How could I do that? Not sure
I'm being clear..


0
Michael
11/19/2003 12:32:39 PM
netscape.mozilla.jseng 1530 articles. 0 followers. Follow

8 Replies
349 Views

Similar Articles

[PageSpeed] 52

Michael Putters wrote:

>Hello,
>
>I've just started embedding SpiderMonkey within my application, and so far,
>it's great, but I'm wondering how I could do the following :
>
>function example()
>{
>  Windows.MessageBox( 'hello world' );
>}
>
>Application.onStartup = example;
>
>The part about calling the message box or calling the event is not a
>problem. However, I use JS_ExecuteScript. So I cannot, like.. execute it,
>THEN call onStartup from the host application. How could I do that? Not sure
>I'm being clear..
>  
>

See JS_CallFunctionName and related APIs.

/be

0
Brendan
11/19/2003 9:56:21 PM
"Brendan Eich" <brendan@meer.net> wrote in message
news:3FBBE705.1080700@meer.net...
> Michael Putters wrote:
>
> >Hello,
> >
> >I've just started embedding SpiderMonkey within my application, and so
far,
> >it's great, but I'm wondering how I could do the following :
> >
> >function example()
> >{
> >  Windows.MessageBox( 'hello world' );
> >}
> >
> >Application.onStartup = example;
> >
> >The part about calling the message box or calling the event is not a
> >problem. However, I use JS_ExecuteScript. So I cannot, like.. execute it,
> >THEN call onStartup from the host application. How could I do that? Not
sure
> >I'm being clear..
> >
> >
>
> See JS_CallFunctionName and related APIs.
>
> /be
>

As I said, I have no problem calling the function, but right now it's like
this :

Application.onStartup = function()
{
  Windows.MessageBox( 'hello world' );
}

main(); // some global function I provide that will call onStartup

I'd like to get rid of main...
I can't call onStartup before JS_ExecuteScript, but I can't call it after
JS_ExecuteScript either..


0
Michael
11/19/2003 11:15:40 PM
Michael Putters wrote:

>"Brendan Eich" <brendan@meer.net> wrote in message
>  
>
>>See JS_CallFunctionName and related APIs.
>>
>>/be
>>
>As I said, I have no problem calling the function, but right now it's like
>this :
>
>Application.onStartup = function()
>{
>  Windows.MessageBox( 'hello world' );
>}
>
>main(); // some global function I provide that will call onStartup
>
>I'd like to get rid of main...
>I can't call onStartup before JS_ExecuteScript, but I can't call it after
>JS_ExecuteScript either..
>  
>

Why not?

You can't have it both ways.  Either you need a separate script 
containing the Application.onStartup = function(){...}, or you need an 
enclosing syntax (such as HTML affords with <body onload=...>) to define 
the onStartup function.

/be

0
Brendan
11/20/2003 7:03:40 PM
Well, that I understand, but isn't there a function JS_ExecuteScript that
keeps it in memory, then I can just call functions inside it from C? Even
using threads, I don't mind :)


"Brendan Eich" <brendan@meer.net> wrote in message
news:3FBD100C.1000705@meer.net...
> Michael Putters wrote:
>
> >"Brendan Eich" <brendan@meer.net> wrote in message
> >
> >
> >>See JS_CallFunctionName and related APIs.
> >>
> >>/be
> >>
> >As I said, I have no problem calling the function, but right now it's
like
> >this :
> >
> >Application.onStartup = function()
> >{
> >  Windows.MessageBox( 'hello world' );
> >}
> >
> >main(); // some global function I provide that will call onStartup
> >
> >I'd like to get rid of main...
> >I can't call onStartup before JS_ExecuteScript, but I can't call it after
> >JS_ExecuteScript either..
> >
> >
>
> Why not?
>
> You can't have it both ways.  Either you need a separate script
> containing the Application.onStartup = function(){...}, or you need an
> enclosing syntax (such as HTML affords with <body onload=...>) to define
> the onStartup function.
>
> /be
>


0
Michael
11/20/2003 9:59:11 PM
Michael Putters wrote:

>Well, that I understand, but isn't there a function JS_ExecuteScript that
>keeps it in memory, then I can just call functions inside it from C? Even
>using threads, I don't mind :)
>  
>

What do you mean by "call functions inside it from C"?  By "it", do you 
mean inside JS_ExecuteScript?  Exacly when is onStartup supposed to be 
called, in relation to other code in the script that you compile and 
execute?

I don't understand the problem, so you'll have to state it more clearly, 
or give more complete example code.

/be

0
Brendan
11/21/2003 2:17:47 AM
Basically, my (C) application starts. At some point, everything is loaded,
and I can execute the script (JS_ExecuteScript). If that happens, the script
does its stuff, then exits. What I'd like is that the script remains in
memory, and that I can just call events. For example, assuming such
functions would exist :

void startscript( void )
{
  handle = JS_ExecuteScriptAsync( context, somescript );
  JS_CallFunction( context, global, "onStart", .. );
}

void js_exit( void ) /* some function that can be called from the script
{
  JS_StopScript( handle );
}

Hope this explains a bit better. Basically, I'm wonder how a web browser can
call onLoad once the script is running.. (since the execution is blocked at
the JS_ExecuteScript call)


"Brendan Eich" <brendan@meer.net> wrote in message
news:3FBD75CB.20603@meer.net...
> Michael Putters wrote:
>
> >Well, that I understand, but isn't there a function JS_ExecuteScript that
> >keeps it in memory, then I can just call functions inside it from C? Even
> >using threads, I don't mind :)
> >
> >
>
> What do you mean by "call functions inside it from C"?  By "it", do you
> mean inside JS_ExecuteScript?  Exacly when is onStartup supposed to be
> called, in relation to other code in the script that you compile and
> execute?
>
> I don't understand the problem, so you'll have to state it more clearly,
> or give more complete example code.
>
> /be
>


0
Michael
11/21/2003 2:44:31 AM
Michael Putters wrote:

>Basically, my (C) application starts. At some point, everything is loaded,
>and I can execute the script (JS_ExecuteScript). If that happens, the script
>does its stuff, then exits.
>

How does it exit?

> What I'd like is that the script remains in
>memory,
>

Do you mean continue running, perhaps "in the background"?  The JSScript 
remains in memory already, although you need to protect it with 
JS_NewScriptObject and a GC root.  So that can't be the issue.

> and that I can just call events. For example, assuming such
>functions would exist :
>
>void startscript( void )
>{
>  handle = JS_ExecuteScriptAsync( context, somescript );
>  JS_CallFunction( context, global, "onStart", .. );
>}
>
>void js_exit( void ) /* some function that can be called from the script
>{
>  JS_StopScript( handle );
>}
>
>Hope this explains a bit better.
>

You have to use threads.  The API and engine support threads (define 
JS_THREADSAFE, read the docs, especially about JS_BeginRequest and 
friends).  It's up to you to figure out how to synchronize between the 
thread calling startscript and the event handlers, and the thread that 
actually executes the script.  Be careful that you don't impose 
multi-threaded programming on the people who write scripts for your 
embedding.

> Basically, I'm wonder how a web browser can
>call onLoad once the script is running.. (since the execution is blocked at
>the JS_ExecuteScript call)
>

Browser embedding execution is run-to-completion, apparently 
single-threaded, precisely so web JS authors don't have to be MT 
programmers.  There may be threads under the hood, but they're hidden 
from scripters.

/be

0
Brendan
11/21/2003 3:35:01 AM
"Brendan Eich" <brendan@meer.net> wrote in message
news:3FBD87E5.6010104@meer.net...

> >Basically, my (C) application starts. At some point, everything is
loaded,
> >and I can execute the script (JS_ExecuteScript). If that happens, the
script
> >does its stuff, then exits.
> >
>
> How does it exit?

It just doesn't call any function

> > What I'd like is that the script remains in
> >memory,
> >
>
> Do you mean continue running, perhaps "in the background"?  The JSScript
> remains in memory already, although you need to protect it with
> JS_NewScriptObject and a GC root.  So that can't be the issue.

Yup


> > and that I can just call events. For example, assuming such
> >functions would exist :
> >
> >void startscript( void )
> >{
> >  handle = JS_ExecuteScriptAsync( context, somescript );
> >  JS_CallFunction( context, global, "onStart", .. );
> >}
> >
> >void js_exit( void ) /* some function that can be called from the script
> >{
> >  JS_StopScript( handle );
> >}
> >
> >Hope this explains a bit better.
> >

> You have to use threads.  The API and engine support threads (define
> JS_THREADSAFE, read the docs, especially about JS_BeginRequest and
> friends).  It's up to you to figure out how to synchronize between the
> thread calling startscript and the event handlers, and the thread that
> actually executes the script.  Be careful that you don't impose
> multi-threaded programming on the people who write scripts for your
> embedding.

Guess I'll do that then ;p

> > Basically, I'm wonder how a web browser can
> >call onLoad once the script is running.. (since the execution is blocked
at
> >the JS_ExecuteScript call)
> >
>
> Browser embedding execution is run-to-completion, apparently
> single-threaded, precisely so web JS authors don't have to be MT
> programmers.  There may be threads under the hood, but they're hidden
> from scripters.
>
> /be
>

Thanks


0
Michael
11/21/2003 1:49:32 PM
Reply:

Similar Artilces:

Asynchronous event during script execution
Hi, I want to create a framework for executing script and maintaining an event queue for events during this script execution. Here is what I thought of: Obviously I will need 2 thread one executing the script and the other waiting for events. The 2 threads will have seperate contexts but share the same global object and thus both will access to the same global data. (I know this might cause race condition but this under the scope of my framework). The events will be generated by the C code and I want each event to cause a function invokation in the javascript shared by the two thre...

How execute a script at execution time ?
I'd like to know how can I execute a script inputed by user in an application at execution time ? Like this: Dim x as string x = "MsgBox(""Teste"")" Execute(x) OR something like a VBA script tool inside the application that can be used at execution time by the user application. I'm trying to create some places like events that will execute this scripts, so the user can config some tools inputing a script in a Setup Page and it will be executed at execution time. I'm sorry by my English, I'm from Brazil and I'l appreciate any h...

Mozilla Firefox PLUGINSPAGE Remote Script Code Execution Vulnerability
bugtraq id 13228 object class Access Validation Error cve CAN-2005-0752 remote Yes local No published Apr 16, 2005 updated Apr 19, 2005 vulnerable Mozilla Firefox 0.8 Mozilla Firefox 0.9 rc Mozilla Firefox 0.9 Mozilla Firefox 0.9.1 Mozilla Firefox 0.9.2 Mozilla Firefox 0.9.3 Mozilla Firefox 0.10 Mozilla Firefox 0.10.1 Mozilla Firefox 1.0 + Gentoo Linux + S.u.S.E. Linux 9.0 + S.u.S.E. Linux 9.0 x86_64 + S.u.S.E. Linux 9.1 + S.u.S.E. Linux 9.1 x86_64 + S.u.S.E. Linux 9.2 + S.u.S.E. Linux 9.2 x86_64 + Slackware Linux -current + Slackware Linux...

Mozilla Firefox PLUGINSPAGE Remote Script Code Execution Vulnerability #2
bugtraq id 13228 object class Access Validation Error cve CAN-2005-0752 remote Yes local No published Apr 16, 2005 updated Apr 27, 2005 vulnerable Mozilla Firefox 0.8 Mozilla Firefox 0.9 rc Mozilla Firefox 0.9 Mozilla Firefox 0.9.1 Mozilla Firefox 0.9.2 Mozilla Firefox 0.9.3 Mozilla Firefox 0.10 Mozilla Firefox 0.10.1 Mozilla Firefox 1.0 + Gentoo Linux + S.u.S.E. Linux 9.0 + S.u.S.E. Linux 9.0 x86_64 + S.u.S.E. Linux 9.1 + S.u.S.E. Linux 9.1 x86_64 + S.u.S.E. Linux 9.2 + S.u.S.E. Linux 9.2 x86_64 + Slackware Linux -current + Slackware Linux...

Mozilla Firefox Search Target Sidebar Panel Script Code Execution Vulnerability
bugtraq id 13231 object class Access Validation Error cve CVE-MAP-NOMATCH remote Yes local No published Apr 16, 2005 updated Apr 19, 2005 vulnerable Mozilla Firefox 0.8 Mozilla Firefox 0.9 rc Mozilla Firefox 0.9 Mozilla Firefox 0.9.1 Mozilla Firefox 0.9.2 Mozilla Firefox 0.9.3 Mozilla Firefox 0.10 Mozilla Firefox 0.10.1 Mozilla Firefox 1.0 + Gentoo Linux + S.u.S.E. Linux 9.0 + S.u.S.E. Linux 9.0 x86_64 + S.u.S.E. Linux 9.1 + S.u.S.E. Linux 9.1 x86_64 + S.u.S.E. Linux 9.2 + S.u.S.E. Linux 9.2 x86_64 + Slackware Linux -current + Slackware Lin...

Scripting Driver : Error executing script
Hello Everybody, Below is a trace from the scripting drivers log (lvl 10) Is is not quite working, the question is, what is wrong. I have it running in a number of ADs, but on this box it produces this error. I believe I have put exactly the same add script on this machine, as I have done on the other ones. The IDM driver is working on other machines as well. My "debug" version of the ADD script works. What I find especially intriguing is, that one of the log lines read StatusLog_getObjectDn: ending ObjectDn = ) Can anyone give me a clue of what to look for ? -Nicolai...

Executing perl scripts with a perl script
I have serveral perl scripts that I've written seperately. Now I want to run them sequentially. I don't want to cut and paste them into the same file to be run. Makes reusablity a pain. Is there a method to do this? I've tried searching but it appears I'm not using the correct search words. I'm using linux, and the standard command line. As you ask this question, I assume that you don't know much about how to modualize your scripts. Please refer to : perldoc -f use perldoc -f require perldoc -f do I 'd perfer using 'use', since errors ...

Mozilla Suite And Firefox Blocked Pop-Up Window Remote Script Code Execution Vulnerability
bugtraq id 13229 object class Access Validation Error cve CAN-2005-1153 remote Yes local No published Apr 16, 2005 updated Apr 19, 2005 vulnerable Mozilla Browser 1.7 rc3 Mozilla Browser 1.7 rc2 Mozilla Browser 1.7 rc1 Mozilla Browser 1.7 beta Mozilla Browser 1.7 alpha Mozilla Browser 1.7 Mozilla Browser 1.7.1 Mozilla Browser 1.7.2 Mozilla Browser 1.7.3 + HP Tru64 5.1 A PK6 + HP Tru64 5.1 A PK6 (BL24) + HP Tru64 5.1 B PK4 + HP Tru64 5.1 B-2 PK4 + HP Tru64 5.1 B-2 PK4 (BL25) Mozilla Browser 1.7.4 Mozilla Browser 1.7.5 + HP Tru64 5.1 A PK6 + HP Tru...

Mozilla Suite Multiple Code Execution, Cross-Site Scripting, And Policy Bypass Vulnerabilities
bugtraq id 13208 object class Unknown cve CAN-2005-0752 remote Yes local No published Apr 16, 2005 updated Apr 16, 2005 vulnerable Mozilla Browser 1.0 RC2 + Conectiva Linux 6.0 + Conectiva Linux 7.0 + Conectiva Linux 8.0 Mozilla Browser 1.0 RC1 - FreeBSD FreeBSD 4.1.1 - FreeBSD FreeBSD 4.2 - FreeBSD FreeBSD 4.3 - FreeBSD FreeBSD 4.4 - FreeBSD FreeBSD 4.5 Mozilla Browser 1.0 + MandrakeSoft Linux Mandrake 8.2 + MandrakeSoft Linux Mandrake 8.2 ppc + RedHat Linux 8.0 + RedHat Linux 8.0 i386 Mozilla Browser 1.0.1 Mozilla Browser 1.0.2 ...

Mozilla Suite And Firefox Blocked Pop-Up Window Remote Script Code Execution Vulnerability #2
bugtraq id 13229 object class Access Validation Error cve CAN-2005-1153 remote Yes local No published Apr 16, 2005 updated Apr 27, 2005 vulnerable Mozilla Browser 1.7 rc3 Mozilla Browser 1.7 rc2 Mozilla Browser 1.7 rc1 Mozilla Browser 1.7 beta Mozilla Browser 1.7 alpha Mozilla Browser 1.7 Mozilla Browser 1.7.1 Mozilla Browser 1.7.2 Mozilla Browser 1.7.3 + HP HP-UX B.11.00 + HP HP-UX B.11.11 + HP HP-UX B.11.11 + HP HP-UX B.11.22 + HP HP-UX B.11.23 + HP Tru64 5.1 A PK6 + HP Tru64 5.1 A PK6 (BL24) + HP Tru64 5.1 B PK4 + HP Tru64 5.1 B-2 PK4 ...

How to stop decendent script from executing in ancestor scripts?
Hi, all. I have an ancestor window. In the open event I have some code to test whether the window can be opened. If the conditions are not meet, the window should be closed immediately without executing decendent window's open event scripts. The ancestor code of open event is something like: If ib_allowopen = false Then close(this) return End If Now I don't know how to close the window immediately, without executing any decendent windows script in open event, and in PFC, pfc_postopen event. Thanks, Feng How about placing the IF NOT ib_allopwopen T...

Migration Issue:Ancestor script executes after decendant script.
Hello Everybody, My Application has been migrated from PB8 to PB11. After migration,I see the applications functions different than expected.When i digged thru denugger i found that in one place Decendant/child script executes first then Ancestor/Parent script executes next . Please find the Call stack details below for PB8 ----- pfc_w_master.active.24 pfc_w_sheet.active.1 wsheet_child.active.1 wsheet_child.active.1 PB11 ------- pfc_w_master.active.24 pfc_w_sheet.active.1 wsheet_child.active.1 wsheet_child.active.2 Here wsheet_child inhirited from w_sheet(in ...

How to let o button execute a script and then execute command
hello! i have a image button ,when i click the button ,i want to exectue a javascript(to open a window and check a value and get it),and then i want to get other datas with the select value(from the open window) from database. like this code   private void Page_Load(object sender, System.EventArgs e)  {   // 在此处放置用户代码以初始化页面   ImageButton1.Attributes["onclick"]="openallunit('TextBox2','TextBox1','allunit')";   //to open a window and get value into TextBox2  }  private void I...

How to let o button execute a script and then execute command
hello! i have a image button ,when i click the button ,i want to exectue a javascript(to open a window and check a value and get it),and then i want to get other datas with the select value(from the open window) from database. like this code private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 ImageButton1.Attributes["onclick"]="openallunit('TextBox2','TextBox1','allunit')"; //to open a window and get value into TextBox2 } private void ImageButton1_Click(object sender, System.Web.UI.I...

Web resources about - Asynchronous script execution - netscape.mozilla.jseng

Asynchronous Transfer Mode - Wikipedia, the free encyclopedia
and designed to unify telecommunication and computer networks . It was designed for a network that must handle both traditional high-throughput ...

Facebook adds asynchronous voice messages to Messenger app; begins testing VoIP in Canada
Facebook today released an update for its standalone Messenger app to allow users to record and send each other voice messages. The company also ...

Google Dart upgrade homes in on asynchronous programming
Google has released Dart 1.9, with a focus on asynchronous programming.

Decomposing Asynchronous Workers in Ruby
... pieces of our systems, we can potentially come away with new ways to compose the same functionality with multiple smaller pieces. Take asynchronous ...

AMD Dives Deep On Asynchronous Shading
... to reduce display chain latency, and finally features to reduce rendering latency. Key among the latter features set is support for asynchronous ...

Hero Academy brings smart, asynchronous strategy to Android
After a lengthy stay on iOS, Hero Academy is now available for Android. The turn-based strategy game uses a kind of card mechanic mixed with ...

Worms 2: Armageddon Finally Launches Asynchronous Multiplayer Mode
... crusades. The latest update to the sequel to the highly successful Worms finally adds what is understandably its most requested feature: asynchronous ...

Apple patents iPhone camera remote control with display, asynchronous notifications
The U.S. Patent and Trademark Office on Tuesday granted Apple a patent for a wireless accessory that can control an iPhone's camera functions, ...

Watch Dogs Asynchronous Multiplayer Trailer Turns This Into A Must-Buy Game
For the first time since I've laid eyes on Watch Dogs the game has finally portrayed itself as a must-buy title. All before now we've seen glimpses ...

Really Simple Asynchronous Web Services
Web services are better suited for the message-oriented communication paradigm, rather than remote procedure calls, the author says.

Resources last updated: 12/17/2015 5:22:07 AM