Author Topic: [1.8] Cannot get OwnPropertyNames from process  (Read 3346 times)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
[1.8] Cannot get OwnPropertyNames from process
« on: 2013 January 03 11:25:09 »
I am not sure if this is a bug or an inconsistency, but this precludes VaryParams to work on 1.8 (but they way, executing the VaryParams test script discovers both the bug on parameters and the present issue).

The ProcessInstance does not return any propery when queried by Object.getOwnPropertyNames. This used to work on 1.7.  You can try:

Code: [Select]
js Object.getOwnPropertyNames(ProcessInstance.fromIcon("aNewImage"))
(use whatever process name you have in the workspace).  1.7 return the list of properties.

I did not find another way to access this information.  Is there one or is this a bug?

-- bitli

BTW VaryParams has also a minor bug (bad error message if the process do not generate image on the workspace), I found the issue by trying the corrected script on 1.8. 

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: [1.8] Cannot get OwnPropertyNames from process
« Reply #1 on: 2013 January 03 13:05:15 »
It seems Object.getOwnPropertyNames() is broken in the current version of the JavaScript engine for some reason. I'll investigate it.

However you have a much better way to implement introspection on JavaScript objects. For example:

Code: [Select]
var o = ProcessInstance.fromIcon( "aNewImage" );
for ( var i in o )
   console.writeln( i, ", ", typeof( o[i] ) );

For a PixelMath instance, the above code generates this output:

Code: [Select]
expression, string
expression0, string
expression1, string
expression2, string
expression3, string
useSingleExpression, boolean
symbols, string
variables, string
use64BitWorkingImage, boolean
rescale, boolean
rescaleLower, number
rescaleUpper, number
truncate, boolean
truncateLower, number
truncateUpper, number
createNewImage, boolean
newImageId, string
newImageWidth, number
newImageHeight, number
newImageAlpha, boolean
newImageColorSpace, number
newImageSampleFormat, number
SameAsTarget, number
RGB, number
Gray, number
i8, number
i16, number
i32, number
f32, number
f64, number

You should be able to apply the above routine to any process implemented in an installed module. Some core JavaScript objects, however, may have problems to access some properties requiring special preconditions. For example, we get the following for a File object:

Code: [Select]
isOpen, boolean
path, string
mode, number
canRead, boolean
canWrite, boolean
*** Error [000]: Error: File I/O Error: File::Position(): File must be open.

because the File.position property cannot be accessed if the file is not currently open. You can overcome this very easily as follows:

Code: [Select]
var o = new File; // for example
for ( var i in o )
{
   try
   {
      console.writeln( i, ", ", typeof( o[i] ) );
   }
   catch ( x )
   {
      console.writeln( i, ", (inaccessible)" );
   }
}

Let me know if this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: [1.8] Cannot get OwnPropertyNames from process
« Reply #2 on: 2013 January 03 13:27:14 »
Thanks,

I am not sure it is broken in Java script. For example it works well with javascript objects:
Code: [Select]
js a={a:1, b:2};Object.getOwnPropertyNames(a);

a,b

getOwnPropertyNames has a purpose, it returns the 'own' properties (and not the one added by prototype, even
if enumerable). Or something like that.  Maybe the object prototype inheritence is different for the built in objects in PI 1.8?  Just an idea.

Anyhow your solution solves the specific problem (I had no good reason to use only own properties on process icon, it just happened to work).

Unfortunately there is some other problems, likely because Javascript is (rightfully) more picky in handling undefined, at least with "use strict".  I should be able to correct this by tomorrow or saturday latest.  If you make a release before then, it is better not to include VaryParams as it would not work correctly.

Sorry for the inconvenience
--bitli