diff --git a/React/Modules/RCTSourceCode.m b/React/Modules/RCTSourceCode.m index f8d96fac6..1608aca70 100644 --- a/React/Modules/RCTSourceCode.m +++ b/React/Modules/RCTSourceCode.m @@ -31,8 +31,7 @@ RCT_EXPORT_METHOD(getScriptText:(RCTPromiseResolveBlock)resolve { if (RCT_DEV && self.scriptData && self.scriptURL) { NSString *scriptText = [[NSString alloc] initWithData:self.scriptData encoding:NSUTF8StringEncoding]; - - resolve(@{@"text": scriptText, @"url": self.scriptURL.absoluteString}); + resolve(@{@"text": RCTNullIfNil(scriptText), @"url": self.scriptURL.absoluteString}); } else { reject(RCTErrorUnavailable, nil, RCTErrorWithMessage(@"Source code is not available")); } diff --git a/packager/react-packager/src/Resolver/polyfills/require-unbundle.js b/packager/react-packager/src/Resolver/polyfills/require-unbundle.js index 70cd11391..fa774787e 100644 --- a/packager/react-packager/src/Resolver/polyfills/require-unbundle.js +++ b/packager/react-packager/src/Resolver/polyfills/require-unbundle.js @@ -9,15 +9,11 @@ 'use strict'; -const {ErrorUtils, nativeRequire} = global; global.require = require; global.__d = define; const modules = Object.create(null); -const loadModule = ErrorUtils ? - guardedLoadModule : loadModuleImplementation; - function define(moduleId, factory) { if (moduleId in modules) { // prevent repeated calls to `global.nativeRequire` to overwrite modules @@ -36,20 +32,29 @@ function require(moduleId) { const module = modules[moduleId]; return module && module.isInitialized ? module.exports - : loadModule(moduleId, module); + : guardedLoadModule(moduleId, module); } +var inGuard = false; function guardedLoadModule(moduleId, module) { - try { + if (global.ErrorUtils && !inGuard) { + inGuard = true; + var returnValue; + try { + returnValue = loadModuleImplementation(moduleId, module); + } catch (e) { + global.ErrorUtils.reportFatalError(e); + } + inGuard = false; + return returnValue; + } else { return loadModuleImplementation(moduleId, module); - } catch (e) { - ErrorUtils.reportFatalError(e); } } function loadModuleImplementation(moduleId, module) { if (!module) { - nativeRequire(moduleId); + global.nativeRequire(moduleId); module = modules[moduleId]; } @@ -90,6 +95,7 @@ function loadModuleImplementation(moduleId, module) { module.isInitialized = false; module.hasError = true; module.exports = undefined; + throw e; } }