3

I use the webkitAudioContext constructor, which is native to webkit browsers, in my application written using Google Closure javascript.

After I compiled my javascript using Plovr in ADVANCED mode, I found that the decodeAudioData method of my webkitAudioContext object was renamed to the obfuscated term c. To be concete,

Before compilation:

var myAudioContext = new webkitAudioContext();
myAudioContext.decodeAudioData(fileData, myCallBackFunction);

After compilation:

(new webkitAudioContext).c(a,b);

How do I tell the Closure javascript compiler to not obfuscate the names of methods of webkitAudioContext? I have tried to call

goog.exportSymbol('webkitAudioContext.prototype.decodeAudioData', webkitAudioContext.prototype.decodeAudioData);

to no avail.

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206

1 Answers1

4

As Felix Kling mentioned in his comment, externs files are used to prevent renaming externally defined symbols. The Closure Compiler source code has externs files under the following directories:

trunk
 |-- externs
 |-- contrib
      |-- externs

The externs file contrib/externs/w3c_audio.js includes webkitAudioContext.

See the plovr externs config option.

Community
  • 1
  • 1
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • 1
    Currently, experimental w3 apis are not included in the default externs. They are usually allowed time to stabilize before moving to the default externs. Most of them can be found in the contrib folder as Chris mentioned. However, it's not unusual to discover missing properties or methods that have been added/changed since the last refresh of the file. – Chad Killingsworth Sep 04 '12 at 13:18
  • Thanks! Specifying `"externs": "//chrome_extensions.js",` in my config.js file works. However, specifying `"externs": "//w3c_audio.js,"` in my config file does not work, even if I manually download and add "w3c_audio.js" into the `contrib/externs` folder. Do I need to edit settings somewhere else? – dangerChihuahua007 Sep 04 '12 at 23:43
  • Specifying `"externs": "//w3c_audio.js"` does not work because the February 2012 plovr release comes bundled with Closure Compiler revision 1559 from February 2, 2012, which did not include `w3c_audio.js`. You need to specify the path to your local copy of `w3c_audio.js` in your plovr config. – Christopher Peisert Sep 05 '12 at 04:28