We are downloading code off the Internet and executing it on the user's device, so run it sandboxed to avoid potential bad actors. Since it's impossible to eval() safely in JS and React Native doesn't offer something akin to Node's vm module, here we are rolling our own. On Android it uses the Duktape JavaScript engine and on iOS the builtin JavaScriptCore engine. The extra JS engine is *only* used for evaluating the downloaded code and returning a JSON string which is then passed back to RN.
17 lines
503 B
JavaScript
17 lines
503 B
JavaScript
// @flow
|
|
|
|
export * from './functions.any';
|
|
|
|
/**
|
|
* Loads config.js from a specific remote server.
|
|
*
|
|
* @param {string} url - The URL to load.
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
export async function loadConfig(url: string): Promise<Object> { // eslint-disable-line no-unused-vars
|
|
// Return "the config.js file" from the global scope - that is how the
|
|
// Web app on both the client and the server was implemented before the
|
|
// React Native app was even conceived.
|
|
return window.config;
|
|
}
|