MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxBundleRun

Function fxBundleRun

xs/tools/xstBundle.c:142–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142void fxBundleRun(txMachine *the, char *buffer, size_t size)
143{
144 char *cursor = buffer;
145 char *end = buffer + size;
146 char *scripts[kBundleMapCap];
147 size_t scriptLens[kBundleMapCap];
148 int scriptCount = 0;
149 const char *entrySource = NULL;
150 size_t entrySourceLen = 0;
151
152 fxBundleMapReset();
153
154 while (cursor < end) {
155 if ((end - cursor) < kBundleMarkerPrefixLen ||
156 0 != memcmp(cursor, kBundleMarkerPrefix, kBundleMarkerPrefixLen)) {
157 // stray content; skip to next marker
158 cursor = fxBundleNextMarker(cursor, end, buffer);
159 continue;
160 }
161 char *markerBody = cursor + kBundleMarkerPrefixLen;
162 char *lineEnd = memchr(cursor, '\n', end - cursor);
163 if (!lineEnd)
164 lineEnd = end;
165 char *bodyStart = (lineEnd < end) ? lineEnd + 1 : end;
166 char *bodyEnd = fxBundleNextMarker(bodyStart, end, buffer);
167 size_t bodyLen = bodyEnd - bodyStart;
168
169 size_t markerLen = lineEnd - markerBody;
170 // strip trailing \r if present
171 if (markerLen && markerBody[markerLen - 1] == '\r')
172 markerLen--;
173
174 if (markerLen == 6 && 0 == memcmp(markerBody, "SCRIPT", 6)) {
175 if (scriptCount < kBundleMapCap) {
176 scripts[scriptCount] = bodyStart;
177 scriptLens[scriptCount] = bodyLen;
178 scriptCount++;
179 }
180 }
181 else if (markerLen == 17 && 0 == memcmp(markerBody, "MODULE_ENTRYPOINT", 17)) {
182 entrySource = bodyStart;
183 entrySourceLen = bodyLen;
184 }
185 else if (markerLen > 7 && 0 == memcmp(markerBody, "MODULE:", 7)) {
186 // null-terminate the module name in-place (overwrites the \n or \r)
187 markerBody[markerLen] = '\0';
188 fxBundleMapPut(markerBody + 7, bodyStart, bodyLen);
189 }
190 // else: unknown marker, skip its body
191
192 cursor = bodyEnd;
193 }
194
195 if (entrySource)
196 fxBundleMapPut(kBundleEntryName, entrySource, entrySourceLen);
197
198 txSlot *realm = mxProgram.value.reference->next->value.module.realm;
199

Callers 2

fuzzFunction · 0.85
fxRunBundleFunction · 0.85

Calls 6

fxBundleMapResetFunction · 0.85
fxBundleNextMarkerFunction · 0.85
fxBundleMapPutFunction · 0.85
fxRunScriptFunction · 0.85
fxRunImportFunction · 0.85
fxParseScriptFunction · 0.70

Tested by

no test coverage detected