NOTICE! This is a static HTML version of a legacy Fiji BugZilla bug.

The Fiji project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Bug 239 - JavaScript that works in IJ text windows produces errors when run from the Script_Editor
JavaScript that works in IJ text windows produces errors when run from the Sc...
Status: RESOLVED WONTFIX
Product: Fiji
Classification: Unclassified
Component: Other
unspecified
Macintosh Mac OS
: P2 normal
Assigned To: ImageJ Bugs Mailing List
Depends on:
Blocks:
 
Reported: 2010-10-08 11:49 CDT by Jan Eglinger
Modified: 2010-10-12 11:27 CDT
0 users

See Also:

Description Jan Eglinger 2010-10-08 11:49:40 CDT
I wanted to try some example JavaScript code at:
http://rsbweb.nih.gov/ij/macros/js/RoisToOverlay.js

When you open the URL via Drag&Drop, the .js opens in an IJ text window, and it runs as intended.

When you download the file and drag it onto the Fiji window, it opens in the nice Script Editor, but when you run it, it throws the error cited below.

Are there two versions of JavaScript running in Fiji?
Cheers,
Jan
(MacOS 10.5.8 with up-to-date Fiji/ImageJA 1.44h)


---------------------
Started RoisToOverlay.js at Fri Oct 08 11:34:47 CEST 2010
org.mozilla.javascript.EcmaError: ReferenceError: "Random" is not defined. (<cmd>#10)
	 at org.mozilla.javascript.ScriptRuntime.constructError(null:-1)
	 at org.mozilla.javascript.ScriptRuntime.constructError(null:-1)
	 at org.mozilla.javascript.ScriptRuntime.notFoundError(null:-1)
	 at org.mozilla.javascript.ScriptRuntime.name(null:-1)
	 at org.mozilla.javascript.gen.c4._c0(<cmd>:10)
	 at org.mozilla.javascript.gen.c4.call(<cmd>:-1)
	 at org.mozilla.javascript.ContextFactory.doTopCall(null:-1)
	 at org.mozilla.javascript.ScriptRuntime.doTopCall(null:-1)
	 at org.mozilla.javascript.gen.c4.call(<cmd>:-1)
	 at org.mozilla.javascript.gen.c4.exec(<cmd>:-1)
	 at org.mozilla.javascript.Context.evaluateReader(null:-1)
	 at Javascript.Refresh_Javascript_Scripts.runScript(Refresh_Javascript_Scripts.java:49)
	 at common.RefreshScripts.runScript(RefreshScripts.java:392)
	 at fiji.scripting.TextEditor$13.execute(TextEditor.java:1494)
	 at fiji.scripting.TextEditor$Executer$1.run(TextEditor.java:1345)
Comment 1 Albert Cardona 2010-10-12 11:27:29 CDT
What happens is that the class Random cannot be found.
ImageJ's built-in javascript is automatically importing a lot of classes. See below:

http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/plugin/frame/Editor.java;hb=HEAD#l20

Among them, the package "java.util" which includes class Random.

How to solve it: add this line to the top of your js script:

importPackage(Packages.ij.util);

We won't fix this issue -- default imports for java.lang and ImageJ's classes are ok, but for the rest it's not a great idea (name collisions).