# Ecmascript module

**URL:** <https://www.ruby-forum.com/t/ecmascript-module/158118>\
**Category:** NGINX\
**Created:** [January 19, 2009, 3:14pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118 "2009-01-19T15:14:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 3:14pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/1 "2009-01-19T15:14:46Z")

</div>

Hi,

I’ve started to build an nginx module to process server-side  
ecmascript (javascript) by embedding the spidermonkey engine. I’ve got  
a (very) rough proof of concept hacked together just now, but after  
about 30-50 requests the I can’t allocate enough memory to build the  
spidermonkey runtime.

I’m new to C and just skim-read the white book to get this far so I  
expect I am just making naive C mistakes.

What I couldn’t understand is that the same jsapi code outside of the  
nginx module never seemed to have the allocation issues.  
And if it was a memory allocation issue… wouldn’t my worker  
processes rise above 2MB?

Sorry for the vague message, but if someone could give me a nudge in  
the right direction of what might be happening so I can get back to  
learning it would be much appreciated!

here’s my example so far:

> <https://github.com/chrisfarms/nginx_ecmascript_module/blob/0d970a33771c4cdbec2293c5c5db9f34191e7ffa/ngx_http_ecmascript_module.c>

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/2 "2009-01-19T15:17:07Z")

</div>

PS: thanks “Evan M.” for the module tutorial 😉

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 3:21pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/3 "2009-01-19T15:21:19Z")

</div>

On Mon, Jan 19, 2009 at 02:00:26PM +0000, Chris Farmiloe wrote:

> nginx module never seemed to have the allocation issues.  
> And if it was a memory allocation issue… wouldn’t my worker  
> processes rise above 2MB?
> 
> Sorry for the vague message, but if someone could give me a nudge in  
> the right direction of what might be happening so I can get back to  
> learning it would be much appreciated!
> 
> here’s my example so far:
> 
> [nginx\_ecmascript\_module/ngx\_http\_ecmascript\_module.c at 0d970a33771c4cdbec2293c5c5db9f34191e7ffa · chrisfarms/nginx\_ecmascript\_module · GitHub](http://github.com/chrisfarms/nginx_ecmascript_module/blob/0d970a33771c4cdbec2293c5c5db9f34191e7ffa/ngx_http_ecmascript_module.c)

There is already an attempt to embedd SpiderMonkey:  
[http://www.cmsbuilder.ru/files/nginx.js/ngx\_http\_js\_module-0.1.tgz](http://www.cmsbuilder.ru/files/nginx.js/ngx_http_js_module-0.1.tgz)

(and some comments in Russian):  
[http://www.cmsbuilder.ru/blog/2008/12/07/ngx\_http\_js\_module-01/](http://www.cmsbuilder.ru/blog/2008/12/07/ngx_http_js_module-01/)  
[http://www.cmsbuilder.ru/blog/2008/11/30/nginx-js/](http://www.cmsbuilder.ru/blog/2008/11/30/nginx-js/)

You may look this implementation.

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/4 "2009-01-19T15:51:28Z")

</div>

Thanks! I’ll take a look

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/5 "2009-01-19T15:51:28Z")

</div>

Chris Farmiloe wrote:

> Hi,
> 
> I’ve started to build an nginx module to process server-side  
> ecmascript (javascript) by embedding the spidermonkey engine.  
> This is something I’ve been hoping would be developed for a while now.  
> However, wouldn’t it be better to have the spidermonkey engine running  
> as an SGI/FCGI module rather than embedded, to open it up to more  
> services?

–

_Phillip B Oldham_  
The Activity People  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

_Policies_

This e-mail and its attachments are intended for the above named  
recipient(s) only and may be confidential. If they have come to you in  
error, please reply to this e-mail and highlight the error. No action  
should be taken regarding content, nor must you copy or show them to  
anyone.

This e-mail has been created in the knowledge that Internet e-mail is  
not a 100% secure communications medium, and we have taken steps to  
ensure that this e-mail and attachments are free from any virus. We must  
advise that in keeping with good computing practice the recipient should  
ensure they are completely virus free, and that you understand and  
observe the lack of security when e-mailing us.

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/6 "2009-01-19T16:35:17Z")

</div>

On Jan 19, 2009, at 15:41 , Phillip B Oldham wrote:

> Chris Farmiloe wrote:
> 
> > Hi,
> > 
> > I’ve started to build an nginx module to process server-side  
> > ecmascript (javascript) by embedding the spidermonkey engine.  
> > This is something I’ve been hoping would be developed for a while  
> > now. However, wouldn’t it be better to have the spidermonkey engine  
> > running as an SGI/FCGI module rather than embedded, to open it up to  
> > more services?

I have to agree with this. There are a couple of attempts out there  
such as [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/jslibs/)

> –  
> Phillip B Oldham  
> The Activity People  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

/J

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [January 19, 2009, 5:58pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/7 "2009-01-19T17:58:31Z")

</div>

That would certainly make it more portable among other servers, but I  
do like the simplicity of letting the nginx worker host the request.

That said, making an HTTP server for the jslibs collection might also  
be fun, then nginx could just play proxy again.

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [February 25, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/8 "2009-02-25T18:12:17Z")

</div>

Chris Farmiloe wrote:

> Sorry for the vague message, but if someone could give me a nudge in  
> the right direction of what might be happening so I can get back to  
> learning it would be much appreciated!

Hi, Chris. That attempt of embedding spidermonkey  
([http://www.cmsbuilder.ru/files/nginx.js/ngx\_http\_js\_module-0.1.tgz](http://www.cmsbuilder.ru/files/nginx.js/ngx_http_js_module-0.1.tgz)) in  
nginx was mine 🙂 I didn’t know that it can be interesting for someone  
elsewhere than Russia. So I’v posted that review only in my native  
language, russian.

If you kept the interest till now, please contact me via email  
([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)). It will be grate to talk about js in nginx 🙂

---

<div class="post-metadata">

**Author:** ![Chris\_Farmiloe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Chris\_Farmiloe](https://www.ruby-forum.com/u/Chris_Farmiloe)\
**Post date:** [February 26, 2009, 12:39am UTC](https://www.ruby-forum.com/t/ecmascript-module/158118/9 "2009-02-26T00:39:08Z")

</div>

Took my legs in arms and followed your example, Chris:

> **[GitHub - peter-leonov/ngx\_http\_js\_module: nginx javascript module](https://github.com/peter-leonov/ngx_http_js_module/tree/master)**
>
> master
