From 47fe52380a232a1c364e21f71e2644a5a3348366 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Thu, 8 Feb 2018 06:30:53 -0800 Subject: [PATCH] Migrate SourceCode from Native Module to a Native Extension. Reviewed By: danzimm Differential Revision: D6848275 fbshipit-source-id: c50305018aa2bdf014f5f665f370f65866197c3b --- Libraries/Image/resolveAssetSource.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Libraries/Image/resolveAssetSource.js b/Libraries/Image/resolveAssetSource.js index 0aaa7978f1d934..7b861633ee80d0 100644 --- a/Libraries/Image/resolveAssetSource.js +++ b/Libraries/Image/resolveAssetSource.js @@ -15,16 +15,15 @@ const AssetRegistry = require('AssetRegistry'); const AssetSourceResolver = require('AssetSourceResolver'); -const NativeModules = require('NativeModules'); import type { ResolvedAssetSource } from 'AssetSourceResolver'; let _customSourceTransformer, _serverURL, _scriptURL; +let _sourceCodeScriptURL: ?string; function getDevServerURL(): ?string { if (_serverURL === undefined) { - var scriptURL = NativeModules.SourceCode.scriptURL; - var match = scriptURL && scriptURL.match(/^https?:\/\/.*?\//); + const match = _sourceCodeScriptURL && _sourceCodeScriptURL.match(/^https?:\/\/.*?\//); if (match) { // jsBundle was loaded from network _serverURL = match[0]; @@ -54,8 +53,7 @@ function _coerceLocalScriptURL(scriptURL: ?string): ?string { function getScriptURL(): ?string { if (_scriptURL === undefined) { - const scriptURL = NativeModules.SourceCode.scriptURL; - _scriptURL = _coerceLocalScriptURL(scriptURL); + _scriptURL = _coerceLocalScriptURL(_sourceCodeScriptURL); } return _scriptURL; } @@ -91,6 +89,13 @@ function resolveAssetSource(source: any): ?ResolvedAssetSource { return resolver.defaultAsset(); } +let sourceCodeScriptURL: ?string = global.nativeExtensions && global.nativeExtensions.SourceCode && global.nativeExtensions.SourceCode.scriptURL; +if (!sourceCodeScriptURL) { + const NativeModules = require('NativeModules'); + sourceCodeScriptURL = NativeModules && NativeModules.SourceCode && NativeModules.SourceCode.scriptURL; +} +_sourceCodeScriptURL = sourceCodeScriptURL; + module.exports = resolveAssetSource; module.exports.pickScale = AssetSourceResolver.pickScale; module.exports.setCustomSourceTransformer = setCustomSourceTransformer;