strict mode

42 views
Skip to first unread message

Oleg Slobodskoi

unread,
Aug 22, 2010, 4:24:07 PM8/22/10
to nodejs
Hi all :)

Does anyone knows when the "use strict" will available?

I think its terrible important for SSJS especially because of
javascripts mess in defining global variables. It is quite inpossible
to guarantee that each variable was defined in special scope using
"var" or attached to any object.

Additionally node is one process for all requests, what means that one
request, in which a global variable is defined can impact on all
other requests.

The best solution for me is that variable which ist not explicitly
defined will brake the code.


Correct me please if am I totally wrong.

Just found an example of this issue in nodejs itself:
http://github.com/ry/node/blob/master/lib/sys.js

line 124.

Don't see any declaration for variable "output".

Michel Beloshitsky

unread,
Aug 22, 2010, 5:00:02 PM8/22/10
to nod...@googlegroups.com
2010/8/23 Oleg Slobodskoi <ole...@googlemail.com>

Hi all :)

Does anyone knows when the "use strict" will available?

You are free to do this yourself:

function strict (fun) {
   var sandbox = {}, err = null

   process.binding('evals').Script
.runInNewContext('('+fun.toString()+')()',sandbox);

   /* Check sandbox for new members. Each of them is an error */
   for (err in sandbox)
      console.error('Undeclarated variable: '+ err)
   if (err)
      throw 'Strict mode violation'
}

someVar = 1;

console.log('someVar:' + someVar)

strict(function () {
   var someVar = 2;
})

strict(function () {
   someVar = 2;
})

console.log('someVar:' + someVar)

Or you mean somethins different? 
 

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


Michel Beloshitsky

unread,
Aug 22, 2010, 5:04:47 PM8/22/10
to nod...@googlegroups.com
For clearance:

// This will run ok
strict(function () {
   var someVar = 2;
})

// This raises an error
strict(function () {
   someVar = 2;
})

2010/8/23 Michel Beloshitsky <mbelos...@gmail.com>

Oleg Slobodskoi

unread,
Aug 22, 2010, 5:17:09 PM8/22/10
to nodejs
1. doing this for my code only doesn't make my environment really
secure, because of using a lot of other libs etc.
2. strict mode should be able to detect also runtime violations

Your script will also throw an error if declared global variable was
axplicitly declared and is correct.

So I think the only way to do this right is doing it inside of js
parser.


On Aug 22, 11:00 pm, Michel Beloshitsky <mbeloshit...@gmail.com>
wrote:
> 2010/8/23 Oleg Slobodskoi <oleg...@googlemail.com>
> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> > .

mgen

unread,
Aug 22, 2010, 8:35:01 PM8/22/10
to nodejs
while i do see a use for strict mode. I will continually advise
against its use on several cases.

1. run time combinations of strict and normal mode will fail for
perfectly legitimate operations.
2. server side js has more of a reason to involve eval/Function as
they have more control over their environment.
3. strict mode implies a more 'pure' javascript, which is not the
case, but rather a subset of javascript complying to specific rules
which could be evaluated pre-interpretation with tools such as JSLINT.
4. run time checks will be costly time wise.

On the other hand, i highly recommend you do not run code you do not
trust or pre-process. ever.

Oleg Slobodskoi

unread,
Aug 23, 2010, 7:23:09 AM8/23/10
to nodejs
1. I think we should always use strict mode :)
2. I thought eval will consider strict mode and do the same checks?
4. it whould be nice to have a global setting for strict mode and be
able to turn it off for production environment, for the case it makes
the engine really slower.

Oleg Slobodskoi

unread,
Aug 23, 2010, 7:25:53 AM8/23/10
to nodejs
Strict mode or something else, there should be a secure way to avoid
such errors with global variables in the core of nodejs for all of us,
not only for me.

Michel Beloshitsky

unread,
Aug 23, 2010, 7:57:59 AM8/23/10
to nod...@googlegroups.com
Okay. If you consider strict mode javascript vm feature, better contact v8 developers.

Afaik Ryan keeps v8 untouched.

2010/8/23 Oleg Slobodskoi <ole...@googlemail.com>
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.

Oleg Slobodskoi

unread,
Aug 23, 2010, 8:06:38 AM8/23/10
to nodejs
Is I am the only one here, who is afraid of unexpected runtime global
variables, especially using node in larger projects ? :)

On Aug 23, 1:57 pm, Michel Beloshitsky <mbeloshit...@gmail.com> wrote:
> Okay. If you consider strict mode javascript vm feature, better contact v8
> developers.
>
> Afaik Ryan keeps v8 untouched.
>
> 2010/8/23 Oleg Slobodskoi <oleg...@googlemail.com>
> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> > .

Bradley Meck

unread,
Aug 23, 2010, 9:39:34 AM8/23/10
to nodejs
well, for large projects i think most of us are running javascript/
jslint and get errors/warnings of such things.

Oleg Slobodskoi

unread,
Aug 23, 2010, 9:46:19 AM8/23/10
to nodejs
and once again: sure, yes, of course !!!!!

But what about all libs? what about node js code itself?

Should we continuously check every software piece we want to use?

This all are workarounds, the issue should be fixed once in one
central place for all of us and forever !

I see this issue as a very dangerous, because it can cause errors,
which are REALLY difficult to find out!

:)

Oleg Slobodskoi

unread,
Aug 25, 2010, 9:41:01 AM8/25/10
to nodejs
Ryan, what do you think about this?

r...@tinyclouds.org

unread,
Aug 30, 2010, 2:28:23 PM8/30/10
to nod...@googlegroups.com
On Wed, Aug 25, 2010 at 6:41 AM, Oleg Slobodskoi <ole...@googlemail.com> wrote:
> Ryan, what do you think about this?

There is no strict mode in V8 yet.

Reply all
Reply to author
Forward
0 new messages