Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Vulture Culture posted:

3D is Cartesian for sanity, 2D generally isn't, for terrible reasons.

Hmm, https://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/ #12 matches my recollection, which is that dealing with 2D coordinates means lower-left origin. That's an old doc, though, and my memories are almost as old, so maybe they changed that in some modern revision?

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Subjunctive posted:

Hmm, https://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/ #12 matches my recollection, which is that dealing with 2D coordinates means lower-left origin. That's an old doc, though, and my memories are almost as old, so maybe they changed that in some modern revision?
You're correct, OpenGL is bottom-left. This section paraphrases my last post though:

quote:

Most 2D rendering APIs mimic writers and use a 2D coordinate system where the origin is in the upper left-hand corner of the screen or window (at least by default). On the other hand, 3D rendering APIs adopt the mathematically minded convention and assume a lower left-hand origin for their 3D coordinate systems.

I think what you'll find is that if a particular API or library is designed for both 2D and 3D, lower-left origin will probably be used, while most 2D-only frameworks use an upper-left origin.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Ah yes, that makes sense. Thanks.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Direct3D has (-1, -1) as top left. The only difference between the two is how the default view matrix is set up.

Also, I believe that sampling a texture at (0, 0) in OpenGL samples the top left texel.

Suspicious Dish fucked around with this message at 03:02 on Oct 23, 2015

Depressing Box
Jun 27, 2010

Half-price sideshow.
What's everyone using for unit tests, especially with React? I just started a new project with React/Redux and I want to at least keep the big pieces under control. I wrote some basic tests in Jest, and they work (after I disabled auto-mocking), but its sparse documentation and occasionally wonkiness make me nervous.

Second question, should I primarily use let or const? Assuming the variable doesn't need to be mutable.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Depressing Box posted:

What's everyone using for unit tests, especially with React? I just started a new project with React/Redux and I want to at least keep the big pieces under control. I wrote some basic tests in Jest, and they work (after I disabled auto-mocking), but its sparse documentation and occasionally wonkiness make me nervous.

Second question, should I primarily use let or const? Assuming the variable doesn't need to be mutable.

I prefer let, as that's how I'd rather my variables be scoped. However, if you have reason to want function scoping, use var.

Depressing Box
Jun 27, 2010

Half-price sideshow.

Skandranon posted:

I prefer let, as that's how I'd rather my variables be scoped. However, if you have reason to want function scoping, use var.

Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Jest is too slow.

I use mocha or karma depending on my mood.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Vulture Culture posted:

3D is Cartesian for sanity, 2D generally isn't, for terrible reasons.

Once again BMP is the best image format.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Depressing Box posted:

Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const?

I use const for immutable data for clarity. When using Babel to transpile to ES5 the const check is handled while compiling, the actual output is a var (same with let); so for now I'd say there's no performance hit at all! I think its unlikely there would be any performance implications once its hit browsers and we stop transpiling.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Depressing Box posted:

Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const?

Use const when you are trying to convey the concept that THIS doesn't change. It doesn't really do anything for the computer. Don't try using it to somehow optimize memory usage.

Depressing Box
Jun 27, 2010

Half-price sideshow.

necrotic posted:

I use const for immutable data for clarity. When using Babel to transpile to ES5 the const check is handled while compiling, the actual output is a var (same with let); so for now I'd say there's no performance hit at all! I think its unlikely there would be any performance implications once its hit browsers and we stop transpiling.

Ah, I didn't realize the checks were just during compilation, that's cool.

Skandranon posted:

Use const when you are trying to convey the concept that THIS doesn't change. It doesn't really do anything for the computer. Don't try using it to somehow optimize memory usage.

Yeah, I've just been using it to indicate (and lightly enforce) immutability. I was burned pretty hard by unexpected state mutation on a previous project, so this time I'm leaning heavily into stuff like Immutable.js/Redux/RxJs.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Depressing Box posted:

Ah, I didn't realize the checks were just during compilation, that's cool.

I wasn't 100% sure either. I find the online REPL useful for figuring out how Babel transpiles things.

Depressing Box
Jun 27, 2010

Half-price sideshow.
That's pretty handy. Interestingly enough, it looks like Babel has an optional transformer (part of "High compliancy" mode in the REPL) that will add TDZ checks to the compiled code.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Depressing Box posted:

That's pretty handy. Interestingly enough, it looks like Babel has an optional transformer (part of "High compliancy" mode in the REPL) that will add TDZ checks to the compiled code.

That could be useful for development!

Depressing Box
Jun 27, 2010

Half-price sideshow.

necrotic posted:

That could be useful for development!

Definitely. I'll probably put it in the development env alongside the typecheck plugin.

Thermopyle posted:

Jest is too slow.

I use mocha or karma depending on my mood.

This helped a lot! I just finished rewriting my tests to work in Mocha (not that hard), and I'm already appreciating the lack of Jest's magical black box mocking system.

Also, you weren't kidding about the speed. Run time for the same tests (two React components and a couple utility functions):
  • Mocha – 60ms serial
  • Jest – 3s parallel (4s uncached)

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL

Depressing Box posted:

What's everyone using for unit tests, especially with React? I just started a new project with React/Redux and I want to at least keep the big pieces under control. I wrote some basic tests in Jest, and they work (after I disabled auto-mocking), but its sparse documentation and occasionally wonkiness make me nervous.

Second question, should I primarily use let or const? Assuming the variable doesn't need to be mutable.

1) mocha with js-dom is pretty nice. Jest has some really nice ideas but holy hell is it slow.
2) I use const unless I absolutely need let. Like others have said, even though it doesn't do much/anything, const is nice for indicating that a value doesn't change, and readable/understandable code is a great thing.

Sedro
Dec 31, 2008
I use 'let' generally, since it's easier to type and I find it easier to read. I'll use const in outer scopes where I define constants, only to be more expressive. Accidentally reassigning a variable is the least of my problems.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I use const everywhere until I have to switch to let. Even though const doesn't really do anything, my IDE (webstorm) (ok, really I use PyCharm, but same thing) warns me when I try to change a variable created as const. I then can evaluate whether I really want to change the variable to let or fix my design. This helps me avoid mistakes.

Revalis Enai
Apr 21, 2003
<img src="https://fi.somethingawful.com/customtitles/title-revalis_enai.gif"><br>Wait, what's my phone number again?
Fun Shoe
I'm attempting to write something for google sheet that will search for an item name on a sheet, then copy its price to another. Here's what I have:

code:

var tss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var mainvalue = tss.getDataRange().getValues();
  var readsheet = ss.getDataRange();
  var values  = readsheet.getValues();
  var rvalues = ss.getMaxRows();
  var cvalues = ss.getLastColumn();
  var rowp;
  var colp; 
  var codecol = 8;
  var namecol = 9;
  var endprice = 17;
  var itemcode;

// Below is the code for each item
itemcode = 0;
    for(i=0;i<values.length; i++)
      {
        rowvalue = values[i];        
        for (j=l=1;j<rowvalue.length; j++) {
             colvalue = rowvalue[j];             
             colvalue1 = colvalue.toString();             
             if(colvalue1.indexOf("Pork")>-1 &&
                colvalue1.indexOf("Fat")>-1 &&
                colvalue1.indexOf("5")==-1)
                {
                rowp = i+1, colp = j+2;               
                var itemcode = 3035;
                }
                else if(colvalue1.indexOf("Pork")>-1 &&
                        colvalue1.indexOf("Fat")>-1 &&
                        colvalue1.indexOf("5")>-1)
                 {
                rowp = i+1, colp = j+2;               
                var itemcode = 3035;
                
                }
                       else {itemcode = 0000; }
             
        }
      }         
  var iprice = ss.getRange(rowp, colp + 2).getValue();
  var isize = ss.getRange(rowp, colp +1).getValue();
  var iinfo = iprice;
  
  for(k=0;k<mainvalue.length; k++) {
    if(mainvalue[k][codecol] == itemcode) {
      var coderow = k + 1;
      
    }
  }
  tss.getRange(coderow,endprice).setValue(iinfo);
 }
Right now I have the repeating part x number of item on a sheet, meaning I have around 5k lines of code for each sheet. I was thinking if there's a way to make it less repetitive.
I'm also having trouble stopping the for loop once the first condition is met so it doesn't look for the second or third. Any tips on this would be great.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Revalis Enai posted:


I'm also having trouble stopping the for loop once the first condition is met so it doesn't look for the second or third. Any tips on this would be great.

You can use break to end execution of a loop early, or return from it and it will stop as well.

EDIT: examples!

JavaScript code:
function breakout() {
    console.log("I will log")
    for (var i = 0; i < 10000000; i += 1) {
        console.log("loop " + i); // will log 4 times
        if (i === 3) {
           break; // jumps to end of loop
        }
    }
    console.log("I will log as well");
}

function returnIt() {
    console.log("I will log")
    for (var i = 0; i < 10000000; i += 1) {
        console.log("loop " + i);  // will log 4 times
        if (i === 3) {
           return; // exits function right here.
        }
    }
    console.log("I will NOT log");
}

Lumpy fucked around with this message at 19:09 on Oct 27, 2015

Revalis Enai
Apr 21, 2003
<img src="https://fi.somethingawful.com/customtitles/title-revalis_enai.gif"><br>Wait, what's my phone number again?
Fun Shoe

Lumpy posted:

You can use break to end execution of a loop early, or return from it and it will stop as well.

EDIT: examples!

JavaScript code:
function breakout() {
    console.log("I will log")
    for (var i = 0; i < 10000000; i += 1) {
        console.log("loop " + i); // will log 4 times
        if (i === 3) {
           break; // jumps to end of loop
        }
    }
    console.log("I will log as well");
}

function returnIt() {
    console.log("I will log")
    for (var i = 0; i < 10000000; i += 1) {
        console.log("loop " + i);  // will log 4 times
        if (i === 3) {
           return; // exits function right here.
        }
    }
    console.log("I will NOT log");
}

I tried to add break; at the end of the first condition like this:
code:
for(i=0;i<values.length; i++)
      {
        rowvalue = values[i];        
        for (j=l=1;j<rowvalue.length; j++) {
             colvalue = rowvalue[j];             
             colvalue1 = colvalue.toString();             
             if(colvalue1.indexOf("Pork")>-1 &&
                colvalue1.indexOf("Fat")>-1 &&
                colvalue1.indexOf("5")==-1)
                {
                rowp = i+1, colp = j+2;               
                var itemcode = 3035;
                       break;
                }
                else if(colvalue1.indexOf("Pork")>-1 &&
                        colvalue1.indexOf("Fat")>-1 &&
                        colvalue1.indexOf("5")>-1)
                 {
                rowp = i+1, colp = j+2;               
                var itemcode = 3035;
                
                }
                       else {itemcode = 0000; }
But it still returns the value of the 2nd condition. Currently both conditions are true, but I wanted the code to go through the first and skip others if true.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Revalis Enai posted:

I tried to add break; at the end of the first condition like this:

...CODE...

But it still returns the value of the 2nd condition. Currently both conditions are true, but I wanted the code to go through the first and skip others if true.

There's a lot... not "wrong" but maybe "misunderstood" in this. Firstly, your loops will explode should they ever run to completion, as doing this: anArray[anArray.length] will always go past the end of the array. Secondly, without seeing the rest of it, you might be having global variable issues: there's lots of seemingly global things in your code (again, they might not be, but I can't tell from what you've posted) that could be the cause. Thirdly, both the first and second conditionals set the value of itemcode to the same thing, so even if you break there, you'll get the same value, since they are both setting to 3035. (Fourthly, I hope your code isn't really indented like that :v:)

Odette
Mar 19, 2011

Bluebird just blew up. I haven't changed a single thing in my code or dependencies, or anything. It was working perfectly before this.

code:
Unhandled rejection TypeError: expecting an array or an iterable object but got [object Null]
    at apiRejection (<directory>/node_modules/bluebird/js/release/promise.js:10:27)
    at PromiseArray.init [as _init] (<directory>/node_modules/bluebird/js/release/promise_array.js:62:19)
    at Promise._settlePromise (<directory>/node_modules/bluebird/js/release/promise.js:546:21)
    at Promise._settlePromise0 (<directory>/node_modules/bluebird/js/release/promise.js:594:10)
    at Promise._settlePromises (<directory>/node_modules/bluebird/js/release/promise.js:677:18)
    at Promise._fulfill (<directory>/node_modules/bluebird/js/release/promise.js:618:18)
    at Request._callback (<directory>/node_modules/bluebird/js/release/nodeback.js:42:21)
    at Request.self.callback (<directory>/node_modules/request/request.js:198:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (<directory>/node_modules/request/request.js:1082:10)
    at emitOne (events.js:82:20)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (<directory>/node_modules/request/request.js:1009:12)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
This is the code that's making it blow up.

JavaScript code:
app.get('/url', function(req, res){
	request.getAsync('https://www.facebook.com/').spread(function(response, body){
		return body;
	}).then(function(result){
		console.log(result);
		res.json({it:'works'});
	});
});
I've deleted node_modules & reinstalled. This only seems to happen with this particular project, so I'm really confused.

EDIT: Solved the issue by rolling back to the previous version of bluebird that I was currently using. I still don't know why it blew up because nothing changed. Eh.

EDIT2: The bluebird library changed the promisify/promisifyAll functions, this solved my problem:

JavaScript code:
var request = bluebird.promisifyAll(require('request'), {multiArgs: true});

Odette fucked around with this message at 05:56 on Oct 28, 2015

Revalis Enai
Apr 21, 2003
<img src="https://fi.somethingawful.com/customtitles/title-revalis_enai.gif"><br>Wait, what's my phone number again?
Fun Shoe

Lumpy posted:

There's a lot... not "wrong" but maybe "misunderstood" in this. Firstly, your loops will explode should they ever run to completion, as doing this: anArray[anArray.length] will always go past the end of the array. Secondly, without seeing the rest of it, you might be having global variable issues: there's lots of seemingly global things in your code (again, they might not be, but I can't tell from what you've posted) that could be the cause. Thirdly, both the first and second conditionals set the value of itemcode to the same thing, so even if you break there, you'll get the same value, since they are both setting to 3035. (Fourthly, I hope your code isn't really indented like that :v:)

Sorry, I'm a novice with programming in general, so if there's something fundamentally wrong with the code please let me know. The code I posted initially is the whole thing, with the for loop part repeated for each item. Other than the conditional part, the code executes fine on google sheet, which is what it's meant for. As far as I know the code is supposed to grab all cells with value into an array, then search through the array for item that contain certain strings. Once it finds the cell containing the strings, it picks up the price value, which is 1-5 columns away depending on which data source I'm working with, then assigns the proper item code, which is used to search for the proper row on our main spreadsheet to copy the price value to.

Also from what I learned so far, google action script is a dumbed down java script and does not like global anything, so all of the code I have needs to be in the same function.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Revalis Enai posted:

Sorry, I'm a novice with programming in general, so if there's something fundamentally wrong with the code please let me know. The code I posted initially is the whole thing, with the for loop part repeated for each item. Other than the conditional part, the code executes fine on google sheet, which is what it's meant for. As far as I know the code is supposed to grab all cells with value into an array, then search through the array for item that contain certain strings. Once it finds the cell containing the strings, it picks up the price value, which is 1-5 columns away depending on which data source I'm working with, then assigns the proper item code, which is used to search for the proper row on our main spreadsheet to copy the price value to.

Also from what I learned so far, google action script is a dumbed down java script and does not like global anything, so all of the code I have needs to be in the same function.

I've never done Google sheet coding, but I'd gladly take a crack at it. Do you have a shareable copy or just a few rows? You can PM me if you want.

fuf
Sep 12, 2004

haha
I wrote a little node script to read a file, do a search and replace, then write the file.

When I run it on my Mac and then open the newly written file in vim there's now an unnecessary carriage return ("^M" character) at the end of every line. I thought this was a DOS / Windows thing so I'm not sure why node is putting them there.

Is there any way to stop Node doing that?

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA

fuf posted:

I wrote a little node script to read a file, do a search and replace, then write the file.

When I run it on my Mac and then open the newly written file in vim there's now an unnecessary carriage return ("^M" character) at the end of every line. I thought this was a DOS / Windows thing so I'm not sure why node is putting them there.

Is there any way to stop Node doing that?

I've not had that problem, but I also don't use vim that much. You should be able clean it up with regex while you're doing the search and replace, just use this selection and replace it with nothing:

code:
  /^[\r\n]+|\.|[\r\n]+$/g  
\r matches for carriage return, \n matches for newline, mix to taste and serve.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
Java Script gurus I need a helping hand... I have ZERO JS knowledge and whilst making an ebay template I used some existing code. This is the code

http://pastebin.com/x9nvragZ

Now eBay are pretty restrictive and bounced it with this error.
"Your listing cannot contain javascript (".cookie", "cookie(", "replace(", IFRAME, META, or includes), cookies or base href."

I searched the script and it uses replace 3 times. Can anyone advise how to remove this from the script?

These are the areas with the replace....

code:

ISMQuery.prototype.removeClass = function(class_name) {
    for(var i = 0; i < this.nodes.length; i++)
    {
      var el = this.nodes[i];
      if(el.classList)
      {
        el.classList.remove(class_name.split(" "));
      }
      else
      {
        el.className = el.className.replace(new RegExp('(^|\\b)' + class_name.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
      }
    }
  };

code:

enable: function() {
    this.disabled = false;
    this.handle.className = this.handle.className.replace(/\s?disabled/g, '');
  },

code:
this.wrapper.className = this.wrapper.className.replace(' ' + this.options.activeClass, '');

thegasman2000 fucked around with this message at 15:32 on Nov 4, 2015

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



thegasman2000 posted:

Java Script gurus I need a helping hand... I have ZERO JS knowledge and whilst making an ebay template I used some existing code. This is the code

This might be too much to hope for but will a script with
JavaScript code:
String.prototype.repalce = String.prototype.replace;
in it pass their filter? If so, you just replace (heh) every instance of 'replace(' with 'repalce(' and you should be good.

qntm
Jun 17, 2009

thegasman2000 posted:

Java Script gurus I need a helping hand... I have ZERO JS knowledge and whilst making an ebay template I used some existing code. This is the code

http://pastebin.com/x9nvragZ

Now eBay are pretty restrictive and bounced it with this error.
"Your listing cannot contain javascript (".cookie", "cookie(", "replace(", IFRAME, META, or includes), cookies or base href."

I searched the script and it uses replace 3 times. Can anyone advise how to remove this from the script?

These are the areas with the replace....

code:

ISMQuery.prototype.removeClass = function(class_name) {
    for(var i = 0; i < this.nodes.length; i++)
    {
      var el = this.nodes[i];
      if(el.classList)
      {
        el.classList.remove(class_name.split(" "));
      }
      else
      {
        el.className = el.className.replace(new RegExp('(^|\\b)' + class_name.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
      }
    }
  };

code:

enable: function() {
    this.disabled = false;
    this.handle.className = this.handle.className.replace(/\s?disabled/g, '');
  },

code:
this.wrapper.className = this.wrapper.className.replace(' ' + this.options.activeClass, '');

I enjoy trying to circumvent poorly-implemented input sanitisation routines as much as the next person, but if eBay says you can't use JavaScript, have you considered not using JavaScript?

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

qntm posted:

I enjoy trying to circumvent poorly-implemented input sanitisation routines as much as the next person, but if eBay says you can't use JavaScript, have you considered not using JavaScript?

They don't say you cant use it they just restrict what you can and cant do... Which is where it gets fun!

I abandoned that script but thanks for the effort Munkeymon. It didn't work for me but I found one that works and was accepted.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Aww, now I want to sell something on eBay just to see if I can get around their filter :\

Was the error message something about '.replace' because you can do it with prototype['replace'], too.

Sedro
Dec 31, 2008
Or prototype['rep'+'lace']

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Or just className["replace"], not sure why the prototype is being referenced.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Because then it's not a member of every String and element.className.repalce is undefined.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Oh, I meant at the call site, sorry.

German Joey
Dec 18, 2004
Speaking of, and I'm kinda laughing at myself for even thinking about this, but is there any way to sandbox Javascript in the browser? Like, lets say I have some widget that has a bunch of methods attached to it, and I want to allow user-written scripts that can interact with this widget. As in, User A writes a script on the site, and User B loads the script and runs it.... WITHOUT needing to worry about his computer blowing up or known terrorists now knowing his credit card number and his mother's maiden name. Just from the top of my head, I'd want to ban DOM manipulations except via the widget's method calls, or modifying the widget itself, or the use the eval function, or access to cookies, or to load any external objects, or who knows what else. Is this possible natively?

kloa
Feb 14, 2007


Things like CoderPad exist, so it's definitely doable.

Adbot
ADBOT LOVES YOU

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

German Joey posted:

Speaking of, and I'm kinda laughing at myself for even thinking about this, but is there any way to sandbox Javascript in the browser? Like, lets say I have some widget that has a bunch of methods attached to it, and I want to allow user-written scripts that can interact with this widget. As in, User A writes a script on the site, and User B loads the script and runs it.... WITHOUT needing to worry about his computer blowing up or known terrorists now knowing his credit card number and his mother's maiden name. Just from the top of my head, I'd want to ban DOM manipulations except via the widget's method calls, or modifying the widget itself, or the use the eval function, or access to cookies, or to load any external objects, or who knows what else. Is this possible natively?

The requirement for making it so the script interacts with the widget means you should probably look into having the widget render on the server with the user script executing on the server as well (like using node / Rhino) - some of the codepad utilities will run the javascript in an iframe, but since the script needs to interact with the widget, it'll be nearly impossible to lock everything down client side.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply