Skip to content

Commit

Permalink
Merge branch '8_1_X' into TIMOB-24415_81X
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshchdhry committed Jul 8, 2019
2 parents 6787759 + 4b91ab2 commit dd15493
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ public String getAllResponseHeaders()

public void clearCookies(String url)
{
if (url == null) {
return;
}

List<HttpCookie> cookies = new ArrayList<HttpCookie>(cookieManager.getCookieStore().getCookies());
cookieManager.getCookieStore().removeAll();
String lower_url = url.toLowerCase();
Expand Down
94 changes: 62 additions & 32 deletions common/Resources/ti.internal/extensions/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,92 @@ const redirects = new Map();
* @param {string} path original require path/id
* @returns {boolean}
*/
function isCoreModuleId(path) {
return !path.includes('.') && !path.includes('/');
function isHijackableModuleId(path) {
if (!path || path.length < 1) {
return false;
}
const firstChar = path.charAt(0);
return firstChar !== '.' && firstChar !== '/';
}

// Hack require to point to this as a core module "binding"
const originalRequire = global.require;
// This works for iOS as-is, and also intercepts the call on Android for ti.main.js (the first file executed)
global.require = function (moduleId) {
if (isCoreModuleId(moduleId)) {
if (bindings.has(moduleId)) {
return bindings.get(moduleId);
}
if (redirects.has(moduleId)) {
moduleId = redirects.get(moduleId);
}

if (bindings.has(moduleId)) {
return bindings.get(moduleId);
}
if (redirects.has(moduleId)) {
moduleId = redirects.get(moduleId);
}

return originalRequire(moduleId);
};

if (Ti.Platform.name === 'android') {
// ... but we still need to hack it when requiring from other files for Android
const originalModuleRequire = global.Module.prototype.require;
global.Module.prototype.require = function (path, context) {
if (isCoreModuleId(path)) {
if (bindings.has(path)) {
return bindings.get(path);
}
if (redirects.has(path)) {
path = redirects.get(path);
}

if (bindings.has(path)) {
return bindings.get(path);
}
if (redirects.has(path)) {
path = redirects.get(path);
}

return originalModuleRequire.call(this, path, context);
};
}

/**
* Registers a binding from a short module id to the full under the hood filepath.
* This allows for lazy instantiation of the module on-demand.
* Registers a binding from a short module id to an already loaded/constructed object/value to export for that core module id
*
* @param {string} coreModuleId the module id to "hijack"
* @param {string} internalPath the full filepath to require under the hood.
* This should be an already resolved absolute path,
* as otherwise the context of the call could change what gets loaded!
* @param {string} moduleId the module id to "hijack"
* @param {*} binding an already constructured value/object to return
*/
export function redirectCoreModuleIdToPath(coreModuleId, internalPath) {
redirects.set(coreModuleId, internalPath);
}
export function register(moduleId, binding) {
if (!isHijackableModuleId(moduleId)) {
throw new Error(`Cannot register for relative/absolute file paths; no leading '.' or '/' allowed (was given ${moduleId})`);
}

// TODO: Allow two types of bindings: a "redirect" from a "core" module id to the actual underlying file (as we have here)
// OR binding an object already loaded to a "core" module id
if (redirects.has(moduleId)) {
Ti.API.warn(`Another binding has already registered for module id: '${moduleId}', it will be overwritten...`);
redirects.delete(moduleId);
} else if (bindings.has(moduleId)) {
Ti.API.warn(`Another binding has already registered for module id: '${moduleId}', it will be overwritten...`);
}

bindings.set(moduleId, binding);
}

/**
* Registers a binding from a short module id to already loaded/constructed object to export for that core module id.
* @param {string} coreModuleId the core module id to register under
* @param {object} object the object to hook to respond to require requests for the module id
* Registers a binding from a short module id to the full under the hood filepath if given a string.
* This allows for lazy instantiation of the module on-demand
*
* @param {string} moduleId the module id to "hijack"
* @param {string} filepath the full filepath to require under the hood.
* This should be an already resolved absolute path,
* as otherwise the context of the call could change what gets loaded!
*/
export function bindObjectToCoreModuleId(coreModuleId, object) {
bindings.set(coreModuleId, object);
export function redirect(moduleId, filepath) {
if (!isHijackableModuleId(moduleId)) {
throw new Error(`Cannot register for relative/absolute file paths; no leading '.' or '/' allowed (was given ${moduleId})`);
}

if (bindings.has(moduleId)) {
Ti.API.warn(`Another binding has already registered for module id: '${moduleId}', it will be overwritten...`);
bindings.delete(moduleId);
} else if (redirects.has(moduleId)) {
Ti.API.warn(`Another binding has already registered for module id: '${moduleId}', it will be overwritten...`);
}

redirects.set(moduleId, filepath);
}

const binding = {
register,
redirect
};
global.binding = binding;
14 changes: 7 additions & 7 deletions common/Resources/ti.internal/extensions/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import assert from './assert';
import events from './events';

// hook our implementations to get loaded by require
import { bindObjectToCoreModuleId } from '../binding';
bindObjectToCoreModuleId('path', path);
bindObjectToCoreModuleId('os', os);
bindObjectToCoreModuleId('tty', tty);
bindObjectToCoreModuleId('util', util);
bindObjectToCoreModuleId('assert', assert);
bindObjectToCoreModuleId('events', events);
import { register } from '../binding';
register('path', path);
register('os', os);
register('tty', tty);
register('util', util);
register('assert', assert);
register('events', events);
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@
"ejs": "^2.6.1",
"fields": "0.1.24",
"fs-extra": "^8.0.1",
"ioslib": "^1.7.7",
"ioslib": "^1.7.9",
"klaw-sync": "^6.0.0",
"liveview": "^1.5.0",
"lodash.defaultsdeep": "^4.6.0",
"markdown": "0.5.0",
"moment": "^2.22.2",
"node-appc": "^0.3.2",
"node-appc": "^0.3.3",
"node-titanium-sdk": "^3.2.0",
"node-uuid": "1.4.8",
"p-limit": "^2.2.0",
Expand Down
4 changes: 2 additions & 2 deletions support/module/packaged/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
},
"hyperloop": {
"hyperloop": {
"url": "https://github.com/appcelerator-modules/hyperloop-builds/releases/download/v4.0.2/hyperloop-4.0.2.zip",
"integrity": "sha512-oKxHxWEyW1K+6/XgMoXB8Lt4+aZh4yl6L/+Q0F0lr1IlHkgfEUzzUVDsGfJOJ/KCDfP2WYXFKLz4VssJDJRHWg=="
"url": "https://github.com/appcelerator-modules/hyperloop-builds/releases/download/v4.0.3/hyperloop-4.0.3.zip",
"integrity": "sha512-IXraXPaHVfM4MvdGv5KJCfPJb6mXMNfaDiOL/rFWXt7sug6Ekaa8JJ96MtyNNxz6CGLZgGL46lqjJNRnJQj1mQ=="
}
}
}

0 comments on commit dd15493

Please sign in to comment.