1

I am trying to get a Javascript speex library to run within a CSP protected environment. It runs great without CSP and I already fixed most "eval" problems. However - this one is giving me a headache:

this.interpolate = Function("buffer", toCompile);

See: https://github.com/grantgalitz/XAudioJS/blob/master/resampler.js

I tried something like

this.interpolate = function buffer () { return toCompile };

but that didn't work. Though I understand the .. well, basics of "Function" versus "function", I can't find working fix.

Any help is appreciated.

Michaela

Michaela.Merz
  • 143
  • 10
  • 1
    you need to rewrite `toCompile` but not as a `string` but as a `function`, for most parts its a peace of cake, but you might have some problem with loops. then in the last line: `this.interpolate = toCompile`. – neo Jan 09 '15 at 20:57
  • Yeah .. I figured that much. This is indeed a pain in .. well .. you know :) – Michaela.Merz Jan 09 '15 at 21:02
  • It is and unfortunately i'm afraid there's no way around it! – neo Jan 09 '15 at 21:08
  • Got it. Thanks. You helped me to stop fooling around and go for the only possible solution. Here's what I did (in the vent somebody stumbles over a situation like this): I dumped that content of the function string to the console and re-formatted it into a function. Renamed all "this" into "that" and made the old "this" into a function parameter. `// this.interpolate = Function("buffer", toCompile); this.interpolate = function buffer(buffer) { return(Bla(buffer,this)); } ` We shouldn't probably use Function :) – Michaela.Merz Jan 09 '15 at 21:28

0 Answers0