Java hosted module script provider for CommonJS



9 years ago
9 years ago


(Reporter: jpalka, Unassigned)




(1 attachment, 1 obsolete attachment)



9 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2) Gecko/20100115 Firefox/3.6
Build Identifier: 

This is initial implementation of Java hosted module script provider for CommonJS together with test cases.
It uses annotations and (more in test code).
At the moment it works, but I don't like the exceptions are handled.

Reproducible: Always

Comment 1

9 years ago
Created attachment 427652 [details] [diff] [review]

First version of Java hosted module script provider for CommonJS.

Comment 2

9 years ago
Looks interesting! I'm not sure it's a good idea to limit the exported objects to classes/constructors. A module may want to export other things such as functions, strings, number constants. I think we need to give modules more control on how to set up the exports object (in addition to your list of classes/constructors).

On a coding style level, I think it would be preferable to throw/propagate exceptions instead of just printing stack traces.

Comment 3

9 years ago
I agree it'd be preferred to propagate the exceptions. 

I just updated the declaration of the ModuleScriptProvider.getModuleScript() method - it can now throw any Exception, not just IOException, so you should be able to just propagate those with no friction.

Comment 4

9 years ago
Created attachment 428808 [details] [diff] [review]
Second implementation of Java hosted modules

This is second attempt to Java hosted modules.

First I changed exception handling and now I throw exceptions (thanks Attila for changes in ModuleScriptProvider interface). However I do hide ClassNotFoundException as it is handled by Require.getModule and I don't think it is good idea to handle module not found in other places.

I have also added support for exporting other things than classes. In @Exports annotation you can now declare classes that implement Script interface. During export these classes will be instantiated and method exec will be invoked. This way we can export anything we want. I thought about separate interface but I believe Script really fits in here.

Let me know what you think about it.
Attachment #427652 - Attachment is obsolete: true

Comment 5

9 years ago
Any comments, I still wonder if I should replace Script interface with more specific one.
You need to log in before you can comment on or make changes to this bug.