Problem
With V8, any constant that isn't a String or primitive doesn't seem to be accessible from JavaScript -- they come across as undefined.
Is Rhino Broken [in this way] Too?
Nope.
Reproduction
Create a module (where "titanium" is an alias to the titanium.py in your 1.8.0.1 folder):
{quote}titanium create --type=module --name=booltest --id=ti.booltest --platform=android{quote}
My original test requires the following two file changes in the module. It tests for access to Boolean constants. See my comments down below for a more comprehensive, albiet less humorous, test.
Update the module's source file to the following:
package ti.booltest;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
@Kroll.module(name="Booltest", id="ti.booltest")
public class BooltestModule extends KrollModule
{
@Kroll.constant public static final Boolean THE_SKY_IS_BLUE = true;
public BooltestModule()
{
super();
}
}
Update the app.js to the following:
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
win.add(Ti.UI.createLabel({
text: 'Papa! Papa! Is the sky blue?\n\n'
+ (require('ti.booltest').THE_SKY_IS_BLUE ? 'Yes! Just like your eyes, son.' : 'No! And while we\'re at it, Santa...')
}));
win.open();
Run the code on your device. You should see confirmation that the sky is, indeed, blue (in the form of a gripping father-son narrative). If you see slander against Santa, than we still have a problem that needs to be fixed.
While we're at it, let's test all the available constants.
Expanded Results
All the following work on Rhino. But ONLY STRINGS work on V8.package ti.booltest; import org.appcelerator.kroll.KrollModule; import org.appcelerator.kroll.annotations.Kroll; import org.appcelerator.titanium.TiApplication; @Kroll.module(name="Booltest", id="ti.booltest") public class BooltestModule extends KrollModule { /* * This test marches through the various available types in Java * to see if they can be used as constants in a Titanium Mobile app. * * They follow the naming convention "d" + either "w" for the wrapped * form or "p" for the primitive form + the variable type. */ @Kroll.constant public static final Boolean dbool = true; @Kroll.constant public static final Integer dint = 2; @Kroll.constant public static final Short dshort = 3; @Kroll.constant public static final Byte dbyte = 0x4; @Kroll.constant public static final Float dfloat = 5.5f; @Kroll.constant public static final Double ddouble = 6.6d; @Kroll.constant public static final Long dlong = 7l; @Kroll.constant public static final String dstr = "So how 'bout them Bears?"; public BooltestModule() { super(); } }var win = Ti.UI.createWindow({ backgroundColor: '#fff', layout: 'vertical' }); var constants = [ 'dbool', 'dint', 'dshort', 'dbyte', 'dfloat', 'ddouble', 'dlong', 'dstr' ]; var BoolTest = require('ti.booltest'); for (var c in constants) { win.add(Ti.UI.createLabel({ text: BoolTest[constants[c]] || (constants[c] + ' FAILED!'), height: '12dp', top: '1dp' })); } win.open();Sorry for the misleading title. After further investigation, Rhino supports any sort of constants I throw at it. But V8 does not support any wrapped type variable (like Boolean, Integer, Float) EXCEPT for String. The primitive forms work great (int, bool, short, etc).