Opened 11 years ago

Closed 11 years ago

#6885 closed defect (wontfix)

Build fails when "dojo.requireLocalization" arguments aren't a string constant because i18nUtil.js executes eval instruction to get string value

Reported by: harobed Owned by: alex
Priority: high Milestone:
Component: BuildSystem Version: 1.1.0
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by harobed)

I've this code :

try {
    Node.innerHTML = code.replace(reg,function(o,a,b) {
        if (!window[a]) { //unknown localization module?
            dojo.requireLocalization("i18n",a.substring(2,64).toLowerCase());
            window[a] = dojo.i18n.getLocalization("i18n", a.substring(2,64).toLowerCase());
        }
        var sRes = (window[a])[b] || "";
        return sRes.replace(/\\n/g,"<br>");
   });
} catch(e) {
    console.error("Error in translateApp:",e.message);
}

ShrinkSafe? raise this error :

release:  Interning strings for file: ../../release/dojo/dojo/dojo.js
release:  Optimizing (shrinksafe) file: ../../release/dojo/dojo/dojo.js
js: "jslib/i18nUtil.js#64(eval)", line 1: uncaught JavaScript runtime exception: ReferenceError: "a" is not defined.

I've look in dojo/util/buildscripts/jslib/i18nUtil.js

62  var requireStatements = fileContents.match(/dojo\.requireLocalization\(.*\)\;/g);
63  if(requireStatements){	
64      eval(requireStatements.join(";"));
65
66      //print("loaded bundles: "+djLoadedBundles.length);
67      
68      var djBundlesByLocale = {};
69      var jsLocale, entry, bundle;
70      
71      ...

ShrinkSafe? extract and eval all "requireLocalization" to get the ressource file name. In my instance, requireLocalization bundleName parameter isn't a constant but one variable then the string extracted can't be process by "eval" instruction.

I've write a patch to fix issue.

Attachments (1)

i18nUtil.js.patch (1.4 KB) - added by harobed 11 years ago.
i18nUtil.js patch

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by harobed

Attachment: i18nUtil.js.patch added

i18nUtil.js patch

comment:1 Changed 11 years ago by harobed

Description: modified (diff)

comment:2 Changed 11 years ago by James Burke

Component: ShrinkSafeBuildSystem
Resolution: wontfix
Status: newclosed
Summary: ShrinkSafe fail when "dojo.requireLocalization" arguments aren't a string constant because ShrinkSafe execute eval instruction to get string valueBuild fails when "dojo.requireLocalization" arguments aren't a string constant because i18nUtil.js executes eval instruction to get string value

That function in i18nUtil.js is trying to do an optimization, to collapse the i18n bundles so that you only incur the cost of one i18n bundle call, instead of one for each language, country, variant.

However, if you are using a variable, then that code cannot participate in this feature of the build. I am concerned that there will be other side-effects with this kind of patch.

I suggest instead of modifying the build that you change your requireLocalization call use the ![""!] syntax instead of the dot syntax:

dojo["requireLocalization"]("i18n",a.substring(2,64).toLowerCase());

That syntax is not recognized by the build system.

Also note that your example code will only work with normal dojo builds, not with an xdomain build -- in xdomain builds, dojo.requireLocalization() calls are not synchronous.

Note: See TracTickets for help on using tickets.