XMLHtttpRequest using narwhal

4 views
Skip to first unread message

ashish

unread,
Jun 16, 2010, 5:21:00 AM6/16/10
to Narwhal and Jack
Hi All,

I want to know if we can get XMLHttpRequest evaluated and executed
using Narwhal interpreter ?

Regards,
Ashish

Nathan Stott

unread,
Jun 16, 2010, 6:10:29 PM6/16/10
to narw...@googlegroups.com
yes, use the browserjs package


--
You received this message because you are subscribed to the Google Groups "Narwhal and Jack" group.
To post to this group, send email to narw...@googlegroups.com.
To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/narwhaljs?hl=en.


Ashish Agrawal

unread,
Jun 18, 2010, 12:21:15 AM6/18/10
to narw...@googlegroups.com
Hi Nathan,
Thanks for the reply.

As per my understanding, XMLHttpRequest is not part of the core javascript engine & hence when you way browserjs has httpRequest support, does it mean it is an integrated JS Engine + Web Engine(webcore).

Regards,
Ashish

James Cook

unread,
Jun 18, 2010, 8:31:45 AM6/18/10
to narw...@googlegroups.com
The ringojs project has a Javascript wrapper for Jetty's HttpClient library. Jetty's library implements a comprehensive set of http exchanges including sync and async.

-- jim

Nathan Stott

unread,
Jun 18, 2010, 8:40:32 AM6/18/10
to narw...@googlegroups.com
BrowserJS leverages rhino to provide XMLHttpRequest.

If you want to use a different JS engine, you'll have to do some work.  If you're using rhino though then just require("browserjs/xhrt").XMLHttpRequest and you've got it

Nathan Stott

unread,
Jun 18, 2010, 8:40:45 AM6/18/10
to narw...@googlegroups.com
oh, that was browserjs/xhr not xhrt
typo

Ashish Agrawal

unread,
Jun 25, 2010, 2:08:35 AM6/25/10
to narw...@googlegroups.com
Hi All,

thanks for the input.

So will I be right if I say, the XMLHttpReques support comes as part of the commonJS framework implementation.

Regards,
Ashish

Nathan Stott

unread,
Jun 25, 2010, 8:53:59 AM6/25/10
to narw...@googlegroups.com
I wouldn't say it's a part of the CommonJS framework.  It's just a package that you can use with narwhal and rhino.

Ashish Agrawal

unread,
Jun 29, 2010, 5:02:57 AM6/29/10
to narw...@googlegroups.com
Hi Nathan,

I wanted to know that how is the feature "require" is implemented in Narwhal.

As I understand, thru "require" we insert new javascript object in the JS engine.

Regards,
Ashish

On Fri, Jun 18, 2010 at 6:10 PM, Nathan Stott <nrs...@gmail.com> wrote:

Nathan Stott

unread,
Jun 29, 2010, 10:34:55 AM6/29/10
to narw...@googlegroups.com
I'm not an expert on narwhals implementation of require.  The simple answer is that require is an eval with some caching and a handful of free-variables defined.  The more complex answer I'll leave to someone else.

mcepl

unread,
Jun 29, 2010, 9:10:30 AM6/29/10
to Narwhal and Jack
On Jun 18, 2:40 pm, Nathan Stott <nrst...@gmail.com> wrote:
> If you want to use a different JS engine, you'll have to do some work. If
> you're using rhino though then just require("browserjs/xhrt").XMLHttpRequest
> and you've got it

Sorry for skewing the topic slightly, but what I am doing wrong in
http://gist.github.com/456337 that I can only do sync XMLHttpRequest.
Or does browserjs implementation of XMLHttpRequest doesn't really
support async? That would be very sad, given how async IO is promoted
as the main advantage of server-side JS.

Matěj

Nathan Stott

unread,
Jun 29, 2010, 3:25:56 PM6/29/10
to narw...@googlegroups.com
Try using my fork of browserjs on github, I believe I did async.


--

James Cook

unread,
Jun 29, 2010, 4:44:08 PM6/29/10
to narw...@googlegroups.com
I'n not sure if browserjs/xhrt supports async or not, but the RingoJS's ringo/httpclient I mentioned earlier in this thread does. You can even fire off several async requests and wait for all of them to respond before continuing. (It would be cool to extend this to use a promise api.)

-- jim

Matěj Cepl

unread,
Jun 29, 2010, 5:16:59 PM6/29/10
to narw...@googlegroups.com
Dne 29.6.2010 21:25, Nathan Stott napsal(a):

> Try using my fork of browserjs on github, I believe I did async.

I tried all branches of http://github.com/nrstott/browserjs.git and none
of them worked. Most of the complained on my
rhino-1.7-0.7.r2.2.el6.noarch that there is no forEach and that
require("uri").URI.parse is obsoleted by require("uri").parse, but even
I fixed that, all of them were non-working in the same manner as the
standard browserjs (I get only req.readyState == 1).

Matěj

--
My point was simply that such tax proposals [for Pigovian taxes
compensating for the transaction costs] are the stuff that dreams
are made of. In my youth it was said, that what was too silly to
be said may be sung. In modern economics it may be put into
mathematics.
-- Ronald Coase
Notes on the Problem of Social Cost

Matěj Cepl

unread,
Jun 29, 2010, 5:18:18 PM6/29/10
to narw...@googlegroups.com, James Cook
Dne 29.6.2010 22:44, James Cook napsal(a):

> I'n not sure if browserjs/xhrt supports async or not, but the RingoJS's
> ringo/httpclient I mentioned earlier in this thread does. You can even
> fire off several async requests and wait for all of them to respond
> before continuing. (It would be cool to extend this to use a promise api.)

I am trying to do just light script for posting blog to blogger via
AtomPub. Bringing jetty with this 8k script seems quite excessive.

But thanks for the idea,

Matěj
--
They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.
-- Benjamin Franklin, Historical Review
of Pennsylvania, 1759.

James Cook

unread,
Jun 29, 2010, 5:28:09 PM6/29/10
to narw...@googlegroups.com
I understand.

Just to be fair though, you are using almost 2MB of java code alongside your 8K script. :)

The dependencies to use Jetty's HttpClient code would add 447K. It wouldn't be bundled in your script/app, but rather installed as a package in narwhal.

-- jim

Matěj Cepl

unread,
Jun 29, 2010, 5:43:07 PM6/29/10
to narw...@googlegroups.com, James Cook
Dne 29.6.2010 23:28, James Cook napsal(a):

> Just to be fair though, you are using almost 2MB of java code alongside
> your 8K script. :)

Wov! That's the curse of ADSL ... one doesn't even see how much junk he
downloads on his disk.

1.9M of that is however in libraries which possibly could be replaced by
the system libraries and not taken with my script:

johanka:narwhal$ ls -lh /usr/share/java/{jna,js,jline}.jar
lrwxrwxrwx. 1 root root 16 4. bře 17.40 /usr/share/java/jline.jar ->
jline-0.9.94.jar
lrwxrwxrwx. 1 root root 13 29. dub 17.04 /usr/share/java/jna.jar ->
jna-3.2.4.jar
lrwxrwxrwx. 1 root root 10 29. led 09.41 /usr/share/java/js.jar ->
js-1.7.jar
johanka:narwhal$

> The dependencies to use Jetty's HttpClient code would add 447K. It
> wouldn't be bundled in your script/app, but rather installed as a
> package in narwhal.

Yes, that's correct.

I will try to work with sync XMLHttpRequest for now and maybe later I
will try to look at fixing browserjs.

Matěj
--
Microwave oven? Whaddya mean, it's a microwave oven? I've been
watching Channel 4 on the thing for two weeks.

Reply all
Reply to author
Forward
0 new messages