Hi guys
I'd been getting an error when running a simple Royale application:
Uncaught TypeError: Cannot read property 'BIG_ENDIAN' of undefined
at new org.apache.royale.utils.BinaryData (BinaryData.js:28)
the line in question is from the constructor:
org.apache.royale.utils.BinaryData = function(bytes) {
bytes = typeof bytes !== 'undefined' ? bytes : null;
this._endian = org.apache.royale.utils.Endian.BIG_ENDIAN;
and "Endian" is undefined.
After a little digging I found this is because the BinaryData object is being
constructed without the JS engine having knowledge of the "Endian" class:
something went wrong with the google dependency thing. In my generated html
page I have a line:
goog.addDependency('../../../org/apache/royale/utils/BinaryData.js',
['org.apache.royale.utils.BinaryData'],
['org.apache.royale.utils.IBinaryDataInput',
'org.apache.royale.utils.IBinaryDataOutput']);
and if I change this to:
goog.addDependency('../../../org/apache/royale/utils/BinaryData.js',
['org.apache.royale.utils.BinaryData'],
['org.apache.royale.utils.IBinaryDataInput',
'org.apache.royale.utils.IBinaryDataOutput', 'org.apache.royale.utils.Endian']);
then it works.
Looking at where this comes from in the compiler:
compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogleDepsWriter.java
function "generateDeps" is creating these lists, and if the "removeCirculars"
value is true (which it is by default unless changed on the command-line) then
we add dependencies for the interfaces that we implement (gd.fileInfo.impls)
and any static dependencies (gd.fileInfo.staticDeps) but we don't add the
actual dependencies that were calculated (gd.deps or gd.fileInfo.deps - both of
these contain the Endian definition).
So I can fix my project by updating the compiler to do:
if (gd.fileInfo.deps != null)
deps.addAll(gd.fileInfo.deps);
and then it works: the generated line though is:
goog.addDependency('../../../org/apache/royale/utils/BinaryData.js',
['org.apache.royale.utils.BinaryData'], ['goog.DEBUG',
'org.apache.royale.utils.Endian', 'org.apache.royale.utils.IBinaryDataInput',
'org.apache.royale.utils.IBinaryDataOutput']);
So my questions:
1. where is the fault here? Am I right in thinking that there's a missing
set of dependencies that need to also be added per the above snippet, or should
the Endian definition be listed as a dependency in the gd.fileInfo.staticDeps
list (which is null for me)
2. presumably we don't want "goog.DEBUG" to end up in the dependency list:
is there a sensible way of getting rid of this (or should we just manually
filter out anything starting "goog.")?
3. if we should be adding these dependencies separately, is there a
preference for "gd.deps" vs "gd.fileInfo.deps"?
thanks
Andrew