Skip to content

Commit

Permalink
fix(ios): export original native module object
Browse files Browse the repository at this point in the history
  • Loading branch information
janvennemann authored and ewanharris committed Jun 22, 2021
1 parent b96e9ff commit cf4073a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions common/Resources/ti.internal/kernel/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,27 @@ function bootstrap (global, kroll) {
* @return {object} wrapper around the externalModule
*/
createModuleWrapper (externalModule, sourceUrl) {
if (OS_IOS) {
// iOS does not need a module wrapper, return original external module
return externalModule;
}

// The module wrapper forwards on using the original as a prototype
function ModuleWrapper() {}
ModuleWrapper.prototype = externalModule;

const wrapper = new ModuleWrapper();
if (OS_ANDROID) {
// Android-specific portion!
// Here we take the APIs defined in the bootstrap.js
// and effectively lazily hook them
// We explicitly guard the code so iOS doesn't even use/include the referenced invoker.js import
const invocationAPIs = externalModule.invocationAPIs || [];
for (const api of invocationAPIs) {
const delegate = externalModule[api];
if (!delegate) {
continue;
}

wrapper[api] = invoker.createInvoker(externalModule, delegate, new kroll.ScopeVars({ sourceUrl }));
// Here we take the APIs defined in the bootstrap.js
// and effectively lazily hook them
// We explicitly guard the code so iOS doesn't even use/include the referenced invoker.js import
const invocationAPIs = externalModule.invocationAPIs || [];
for (const api of invocationAPIs) {
const delegate = externalModule[api];
if (!delegate) {
continue;
}

wrapper[api] = invoker.createInvoker(externalModule, delegate, new kroll.ScopeVars({ sourceUrl }));
}

wrapper.addEventListener = function (...args) {
Expand Down

0 comments on commit cf4073a

Please sign in to comment.