Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Michael Schwartz
Because they are a different class of error. They're NOT an error using with. The less error prone for the end user, the better. On Jun 12, 2013, at 10:11 AM, Andreas Rossberg wrote: > On 12 June 2013 18:48, Michael Schwartz wrote: >> strict mode does not work in the real world where templat

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Andreas Rossberg
On 12 June 2013 18:48, Michael Schwartz wrote: > strict mode does not work in the real world where templates are concerned. > > Students don't want to see your compiled function. They may be designers, > not programmers. Likely are. > > Showing them a JavaScript error is simply the incorrect th

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Michael Schwartz
strict mode does not work in the real world where templates are concerned. Students don't want to see your compiled function. They may be designers, not programmers. Likely are. Showing them a JavaScript error is simply the incorrect thing to do. And it's perfectly valid to let them clobber a

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Andreas Rossberg
On 12 June 2013 18:27, Michael Schwartz wrote: > In the real world, your solution doesn't work. Are you saying that strict mode does not work in the real world? Then I beg to differ. > Like I said, you get a few hundred students of varying skills creating > templates. Many will just cut&paste

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Michael Schwartz
In the real world, your solution doesn't work. Like I said, you get a few hundred students of varying skills creating templates. Many will just cut&paste from existing templates, etc. "use strict" works on the compiled template. Throwing a run time error or showing the end user the compiled sc

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Andreas Rossberg
On 12 June 2013 17:35, Michael Schwartz wrote: > How is the template compiler to figure out i is a global reference? > > LOTS of code. > > That's the point. The template compiler could be 50 lines using with. IIUC, you don't want 'i' to pollute the global name space? Then don't use an undeclared

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Michael Schwartz
How is the template compiler to figure out i is a global reference? LOTS of code. That's the point. The template compiler could be 50 lines using with. On Jun 12, 2013, at 8:01 AM, Andreas Rossberg wrote: > On 12 June 2013 15:05, Michael Schwartz wrote: >> Inside the function, you have: >>

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Andreas Rossberg
On 12 June 2013 15:05, Michael Schwartz wrote: > Inside the function, you have: > > for (i=1; i<6; i++) { > > Which sets a new property, i, on the global/window object. > > Using with, it would set the new property on the o object So just generate 'o.i' instead of 'i' there. ;) /Andreas -- --

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Stephan Beal
On Wed, Jun 12, 2013 at 1:10 PM, Andreas Rossberg wrote: > And what's wrong with replacing this by the following? > > { > let out = '' > function write(s) { o.out += s; }, > function writeln(s) { o.out += s + '\n'; } > let obj = { title: 'whatever', otherMetaData: … } > eval(script); > } > i

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Michael Schwartz
Inside the function, you have: for (i=1; i<6; i++) { Which sets a new property, i, on the global/window object. Using with, it would set the new property on the o object as in: with (o) { eval ("i = 5"); /// <<< sets o.i = 5, not global.i = 5 } > function(o) { > o.writeln(''); > o.write('

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-12 Thread Andreas Rossberg
On 11 June 2013 19:56, Michael Schwartz wrote: > [...] > > Invocation might be something like: > > var o = { > out: '', > write: function(s) { o.out += s; }, > writeln: function(s) { o.out += s + '\n'; } > obj: { title: 'whatever', otherMetaData: … } > }; > with (o) { >eval(script); >

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Michael Schwartz
The best use case I can think of for "with" is in templates. Consider ejs style template: <%= obj.title %> <% for (i=1; i<6; i++) { %> Line #<%= i%> <% } %> This gets "compiled" into a script like: writeln(''); write(''); write(obj.title); writeln(''); writeln(''); for (i=1; i<6; i++) { wri

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Andreas Rossberg
On 11 June 2013 18:11, Michael Schwartz wrote: > I never understood why "with" is considered a bad thing. It's got a bad > reputation, though it has some real world use cases that make a lot of > sense. One thing to realise is that every pile of poo in any language can be motivated by use cases.

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Michael Schwartz
I never understood why "with" is considered a bad thing. It's got a bad reputation, though it has some real world use cases that make a lot of sense. Granted v8 doesn't optimize code using it. On Jun 11, 2013, at 9:06 AM, Stephan Beal wrote: > On Tue, Jun 11, 2013 at 5:53 PM, Michael Schwartz

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Stephan Beal
On Tue, Jun 11, 2013 at 5:53 PM, Michael Schwartz wrote: > with (o) { > Yeah, i was hoping to avoid the 'with'. i assume there is no clean/portable/sane way to do this in JS, and to be honest the idea never occurred to me until today while tinkering on my own pet scripting engine (which, by an a

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Michael Schwartz
Ugly but… In JavaScript you can do something like this: var o = { dbRow: whatever, rowNumber: whatever, colNames: whatever, colCount: whatever }; with (o) { function rowCallback() { // dbRow would be accessible without the o. prefix, etc. } } On Jun 11, 2013, at 8:30 AM, Andreas Rossbe

Re: [v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Andreas Rossberg
On 11 June 2013 17:11, Stephan Beal wrote: > Please consider this construct: > > function rowCallback(dbRow){ > // Notes below ref to this scope > } > > myDbDriver.query({ > sql:"SELECT * FROM T", > callback: rowCallback > }); > > That hypothetical code would run the given query and call the

[v8-users] How to achieve "scope property injection" in v8?

2013-06-11 Thread Stephan Beal
Hi, all, Please consider this construct: function rowCallback(dbRow){ // Notes below ref to this scope } myDbDriver.query({ sql:"SELECT * FROM T", callback: rowCallback }); That hypothetical code would run the given query and call the given callback for each row. What i would like to do h