aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Preprocess JavaScript source code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Preprocess JavaScript source code" Watch "Preprocess JavaScript source code" New topic
Author

Preprocess JavaScript source code

bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Hi Guys,

I need to proprocess JavaScript file and figure out the key function calls, based on the context and make a decision how to expend the function. We have to expend the function call for thread synchronization purpose and the expension is context sensitive.

I am thinking to parse the .js file and figure out the context and the function call. Anyone got good any idea about how to implement this?

thanks,
Bujin Wang
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I am not sure what you are talking about exactly. Can you try to explain what you are trying to do in another way.

Thanks
bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Here is other description of my question:

In my .js file, there is a function call: aFunction(). This function call could happen anywhere, e.g. inside a for(; , inside a equality statement, etc. The problem is with this function call.

We have to expend this function to take care of the synchronization issue. The function call will send a request to server and it takes some time to return. The probem is that the subsequent code depends on the result. Hence someone in our company figured out a way to handle this: expend the function so the subsequent code can wait until the function returns. I am not sure how he handle this yet. His original solution is to write an engine to parse the .js sourcecode, figure out this function calls and expend the function into another .js file. The problem with this solution is the parsing was based on regualar expression. It's hard to maintain.

My intention is to use some parser generator, e.g. ANTLR, to generat lexical parser and hope that is the right direction. Anyone got better idea how to implement this?

Thanks,
Bujin Wang
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

That's not the way things work. You can't just make a request from inside a Javascript function and pause waiting for the result. And any attempts to hack such functionality is doomed to failure, or at best, be so completely obsure as to be madness.

What I think you should do is breathe deeply, step away from the keyboard, and figure out what it is you are really trying to accomplish. Then figure out, using the traditional request-response HTTP cycle, what the best way to accomplish it might be.

The Servlets forum might be a good place to start once you figure out what it is you really need to accomplish.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
If I understand you correctly:
1. You have some kind of frame or popup
2. You have a function, that submits request into this frame or popup.
3. You want this function to wait, until that request is returned, and than do some proccesing.
4. You know the name of the function to be "extended"

if you could break submiting request and proccesing the result onto 2 separate functions, than everything is easy.


Now, let say you have function, and you want to "extend it" to make it not return until some flag is set. The only way to do that, is to do some loop, which will really kill you page perfomance, and may cause a popup alert on some browser version. If you are up to that than:
bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
I think Yuriy got my idea right. However my problem is how to parse the "aFunction" out in the original source code, given that it can be used in many different forms, e.g., var e = aFunction(), for(aFunction(); , etc.?

Burt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Preprocess JavaScript source code