Bug 161397 - Executing a KstScript file does not return the expected result
Summary: Executing a KstScript file does not return the expected result
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-29 02:43 UTC by Yiwen Mao
Modified: 2008-05-13 22:41 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
the source file to create the data vector (29.86 KB, text/plain)
2008-04-29 02:49 UTC, Yiwen Mao
Details
the js file used to excute the kstscript in the problem description (473 bytes, text/plain)
2008-04-29 02:51 UTC, Yiwen Mao
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yiwen Mao 2008-04-29 02:43:06 UTC
Version:           1.7.0 (using KDE 3.5.8KDE 1.2)
Installed from:    0Compiled From Sources
OS:                Linux

Problem: Executing a KstScript file to construct a new DataVector and check its propety skip and skipLength, and the js file returns an unexpected result.

Procedures to reproduce the proplem:
create a js file: datavec.js

var s=new DataSource("/home/vyiwen/graphics/kst/tests/asciimatrix.txt");
function skipTest()
{
var result = new Boolean();
var v=new DataVector(s,"test1",0,10,0,false)//construct a new vector from data
                                            //source, and read 10 frames from                    
                                            //frame 0 and skip 0 frame   
if(v.skip==false&&v.skipLength==0)
result=true
else
result=false
return result;//expect result=true
}

Load datavec.js
Open the kst javaScript Console
Type "skipTest()"
return false

To compare with the result from executing the above script directly from JavaScript Console
Type the following codes in JavaScript Console:
kst> var s=new DataSource("/home/vyiwen/graphics/kst/tests/asciimatrix.txt");
kst> var v=new DataVector(s,"test1",0,10,0,false)
kst> if(v.skip==false&&v.skipLength==0){result=true}
true
kst> result
true

The result is true
Comment 1 Yiwen Mao 2008-04-29 02:49:57 UTC
Created attachment 24548 [details]
the source file to create the data vector
Comment 2 Yiwen Mao 2008-04-29 02:51:50 UTC
Created attachment 24549 [details]
the js file used to excute the kstscript in the problem description
Comment 3 Andrew Walker 2008-04-29 19:26:43 UTC
This is a "feature"

Because updates on most objects in Kst occur asynchronously you can never be sure when an object has actually been updated.

The code "works" when entered by hand as there is a sufficiently long gap between creation of the Data Vector and querying for its values, that the necessary updates have been completed. 

The code "fails" when run via the script as sufficient time is not available.

This can be seen by putting in an alert() statement immediately after creating the Data Vector and before querying for vector values. The expected values will now be returned.
Comment 4 Andrew Walker 2008-05-12 19:10:58 UTC
This is actually a problem as it places a severe onus on a client of the javaScript extension of Kst to ensure that an update has occured before querying for the results.
Comment 5 Andrew Walker 2008-05-12 19:24:42 UTC
SVN commit 806977 by arwalker:

CCBUG:161397 first draft of allowing the client to make 'synchronous' calls to the Kst javaScript extension.

 M  +5 -0      kst.cpp  
 M  +1 -0      kst.h  
 M  +70 -7     updatethread.cpp  
 M  +6 -2      updatethread.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=806977
Comment 6 Andrew Walker 2008-05-12 19:25:24 UTC
SVN commit 806978 by arwalker:

CCBUG:161397 first draft of allowing the client to make 'synchronous' calls to the Kst javaScript extension.

 M  +17 -3     bind_kst.cpp  
 M  +5 -0      bind_kst.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=806978
Comment 7 Andrew Walker 2008-05-13 22:41:38 UTC
If a client wants to make a "synchronous" call they should make the call as usual and then make a call to Kst.waitForUpdate(). The latter call will return only after the next update loop has completed, thereby ensuring that the actions of the original call have been fully propagated.