🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #9512

Re: Script in InDesign CS2 - Can I convert VB to VBScript or JavaScript?

#9512
From: Dave_Saunders
Date: Wed, 16 Aug 2006 13:00
31 lines
3621 bytes
I've already run into this problem of namespaces big time, just this week with CS2. It's not something that comes up often, but it is an here-and-now issue.

In my case, my TextStylesReporter script unintentionally used a function name that was already part of the global space. The function name in question: resolve().

As long as my script was running in an environment where it was the only game in town, this didn't matter. The renaming wasn't important because my script didn't need to use the global function.

But suddenly, people started complaining about an error on line 265 of my script. I was completely baffled; I couldn't imagine what was happening and I couldn't reproduce the problem.

Then, on the BlueWorld list, I happened to ask one of the people using my script and getting the error if he had any third party plug-ins installed. And so the problem was discovered.

The user was running a Rorohiko plug-in.

Well, the plug-in was doing its thing by running some "Behind-the-scenes" JavaScripts. And they needed the resolve() built-in function.

Still, all would have been well if my script had not included a call to app.documents.add(). But it did because the script creates a new document to carry the report it generates. This triggered the plug-in which interrupted my script to do its thing.

But my script had polluted the environment by redefining that global function. So, when the plug-in tried to use resolve(), it was passed to the code in my script which proceeded to give a run-time error because it couldn't make head nor tail of the parameters it was passed.

So, this is not some future monster. The problem is here and now.

And there's not a lot you can do about it except proceed with caution. Certainly, Ole's approach of moving just about everything into a function is a good start, but what if a plug-in has a function named "main"?

And, clearly, you should avoid redefining global functions! Getting the list of names to avoid requires some hunting and pecking. I came up with this list:

alert, Application, Array, beep, Boolean, confirm, constructor, Date, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, Error, escape, eval, exit, File, Folder, Function, hasOwnProperty, Imports, isFinite, isNaN, isPrototypeOf, localize, Number, Object, parseFloat, parseInt, prompt, propertyIsEnumarable, reflect, Reflection, ReflectionInfo, RegExp, resolve, Socket, String, toLocaleString, toSource, toString, unescape, uneval, unwatch, valueOf, watch

Looking at that lot, about the only candidate for accidental use by me is indeed the one I did accidentally use: resolve. I've renamed it myResove() in my script.

By the way, I owe big-time thanks to Kris Coppieters of Rorohiko. By dint of his being in New Zealand and this issue coming up late at night here in the Eastern time zone, Kris got to work on the problem while I slept and he had identified the problem by the time I woke up next morning.

Dave
Technical Details
Message-ID: <3bc1426b.7@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.ecp.fr!news.stben.net!webcrossing
References: <3bc1426b.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,4856d139041796fa
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Dave_Saunders@adobeforums.com
Newsgroups: adobe.scripting.indesign
Subject: Re: Script in InDesign CS2 - Can I convert VB
 to VBScript or JavaScript?
Message-ID: <3bc1426b.7@webcrossing.la2eafNXanI>
Date: Wed, 16 Aug 2006 06:00:41 -0700
References: <3bc1426b.-1@webcrossing.la2eafNXanI>
Lines: 63
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.ecp.fr!news.stben.net!webcrossing