From 4844225eedd6c9638cf529be14c8c924eabed13a Mon Sep 17 00:00:00 2001 From: rh389 Date: Wed, 11 Jan 2017 22:28:07 -0800 Subject: [PATCH] JavaScriptLoader BCBundle version check Summary: Currently a build warning is thrown by `if (header.BCVersion != runtimeBCVersion) ...` because `runtimeBCVersion` is signed, apparently because `-1` is used to mean that the runtime has no support for bytecode bundles. This PR splits out the error case of the runtime not supporting BC bundles from the case of a version mismatch. Tested as much as I could by building and running `UIExplorer` - I haven't attempted to use real bytecode bundles. Closes https://github.com/facebook/react-native/pull/11806 Differential Revision: D4408608 fbshipit-source-id: a1d868bb2064588e6a20827692629a46b6ba1e74 --- React/Base/RCTJavaScriptLoader.h | 1 + React/Base/RCTJavaScriptLoader.mm | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/React/Base/RCTJavaScriptLoader.h b/React/Base/RCTJavaScriptLoader.h index 1d32372cd56..c1d30ce2016 100755 --- a/React/Base/RCTJavaScriptLoader.h +++ b/React/Base/RCTJavaScriptLoader.h @@ -20,6 +20,7 @@ NS_ENUM(NSInteger) { RCTJavaScriptLoaderErrorFailedStatingFile = 3, RCTJavaScriptLoaderErrorURLLoadFailed = 3, RCTJavaScriptLoaderErrorBCVersion = 4, + RCTJavaScriptLoaderErrorBCNotSupported = 4, RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously = 1000, }; diff --git a/React/Base/RCTJavaScriptLoader.mm b/React/Base/RCTJavaScriptLoader.mm index 1d0f3cdec88..eacdf024f22 100755 --- a/React/Base/RCTJavaScriptLoader.mm +++ b/React/Base/RCTJavaScriptLoader.mm @@ -142,10 +142,19 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) return nil; case facebook::react::ScriptTag::BCBundle: - if (header.BCVersion != runtimeBCVersion) { + if (runtimeBCVersion == JSNoBytecodeFileFormatVersion || runtimeBCVersion < 0) { + if (error) { + *error = [NSError errorWithDomain:RCTJavaScriptLoaderErrorDomain + code:RCTJavaScriptLoaderErrorBCNotSupported + userInfo:@{NSLocalizedDescriptionKey: + @"Bytecode bundles are not supported by this runtime."}]; + } + return nil; + } + else if ((uint32_t)runtimeBCVersion != header.BCVersion) { if (error) { NSString *errDesc = - [NSString stringWithFormat:@"BC Version Mismatch. Expect: %d, Actual: %d", + [NSString stringWithFormat:@"BC Version Mismatch. Expect: %d, Actual: %u", runtimeBCVersion, header.BCVersion]; *error = [NSError errorWithDomain:RCTJavaScriptLoaderErrorDomain