New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-24404] Expose global object on iOS #9552
Conversation
5ddac52
to
b05fc70
Compare
Generated by 🚫 dangerJS |
@sgtcoolguy I'd like to add the unit-tests for Jan - should I create a new test-suite, e.g. "globals.test.js" or integrate into an existing one? Eventually, we could also test other globals like setTimeout, setInterval, __filename and __dirname. |
@janvennemann I am not sure about the performance-impact of this change, because (for now) we hang every Ti.* element on the global namespace now, which can be referenced from everywhere now. This example: var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var btn = Ti.UI.createButton({
title: 'Trigger'
});
btn.addEventListener('click', function(e) {
console.log(global);
});
win.add(btn);
win.open(); returns: {
L = "<KrollCallback: 0x60c000266900>";
alert = "<KrollCallback: 0x60c0002669c0>";
btn = "[object TiUIButton]";
clearInterval = "<KrollCallback: 0x60c0002667c0>";
clearTimeout = "<KrollCallback: 0x60c000266880>";
console = "[object TiConsole]";
require = "<KrollCallback: 0x60c000266a00>";
setInterval = "<KrollCallback: 0x60c000266b00>";
setTimeout = "<KrollCallback: 0x60c000266bc0>";
win = "[object TiUIWindow]";
} I mean, we just reference them, but I feel like this may have some ugly side-effect that should be well-tested against. |
@hansemannn We have some tests of globals int he suite, but they're poorly organized. Right now they live in:
I'd copy and update one of those, or combine them into a global.test.js. |
Ok, I'll remove the ones from |
@hansemannn, this should not change the scope of any variables, it only makes the global object available under the @sgtcoolguy Support for this on Android seems to only work under Alloy. Any idea why? |
@janvennemann uhhh, I don't know. Maybe an artifact of the difference in the way we treat app.js versus all other required JS files? In non-app.js we wrap in a self-invoking function ala Node: https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/js/kroll.js#L120 app.js is treated specially: https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/js/module.js#L580 |
So to follow up on this: As part of that and this PR I looked at what Node does, and it is exactly what Jan does here. For Android, To unify the platforms, I think we should hang "global" off the global object as Jan does here, then global should be available everywhere in any JS file for both platforms. We could then remove the global argument to the self-invoking wrapper function on Android. On another related note, I'm seeing some undocumented/unofficial global weirdness with require too. You can do |
JIRA: https://jira.appcelerator.org/browse/TIMOB-24404
Optional Description:
Exposes the global object as a node like
global
variable. Allows the following code to be run:This already works in Alloy apps in Android, but not in classic apps.