metro-buck: check validity of segments

Reviewed By: davidaurelio

Differential Revision: D6496312

fbshipit-source-id: 586dc8d9f64d13cfddaf6bfe768e8f7b3442561a
This commit is contained in:
Jean Lauliac 2017-12-14 09:43:44 -08:00 committed by Facebook Github Bot
parent d2075f3743
commit 86914666e5
2 changed files with 23 additions and 6 deletions

View File

@ -160,6 +160,11 @@ function unpackModuleId(
}
require.unpackModuleId = unpackModuleId;
function packModuleId(value: {segmentId: number, localId: number}): ModuleID {
return value.segmentId << (ID_MASK_SHIFT + value.localId);
}
require.packModuleId = packModuleId;
function loadModuleImplementation(moduleId, module) {
const nativeRequire = global.nativeRequire;
if (!module && nativeRequire) {

View File

@ -66,15 +66,21 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
_require.unpackModuleId = unpackModuleId;
function packModuleId(value) {
return value.segmentId << ID_MASK_SHIFT + value.localId;
}
_require.packModuleId = packModuleId;
function loadModuleImplementation(moduleId, module) {
var nativeRequire = global.nativeRequire;
if (!module && nativeRequire) {
var _unpackModuleId = unpackModuleId(moduleId),
segmentId = _unpackModuleId.segmentId,
localId = _unpackModuleId.localId;
_segmentId = _unpackModuleId.segmentId,
_localId = _unpackModuleId.localId;
nativeRequire(localId, segmentId);
nativeRequire(_localId, _segmentId);
module = modules[moduleId];
}
@ -251,15 +257,21 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
_require.unpackModuleId = unpackModuleId;
function packModuleId(value) {
return value.segmentId << ID_MASK_SHIFT + value.localId;
}
_require.packModuleId = packModuleId;
function loadModuleImplementation(moduleId, module) {
var nativeRequire = global.nativeRequire;
if (!module && nativeRequire) {
var _unpackModuleId = unpackModuleId(moduleId),
segmentId = _unpackModuleId.segmentId,
localId = _unpackModuleId.localId;
_segmentId = _unpackModuleId.segmentId,
_localId = _unpackModuleId.localId;
nativeRequire(localId, segmentId);
nativeRequire(_localId, _segmentId);
module = modules[moduleId];
}