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

Function fxFindModule

xs/sources/xsPlatforms.c:145–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143#if mxUseDefaultFindModule
144
145txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
146{
147 txPreparation* preparation = the->preparation;
148 char name[C_PATH_MAX];
149#if MODDEF_XS_TEST
150 char extension[5] = "";
151#endif
152 char buffer[C_PATH_MAX];
153 txInteger dot = 0;
154 txInteger i = 0;
155 txInteger hash = 0;
156 txString slash;
157 txString path;
158 fxToStringBuffer(the, slot, name, sizeof(name));
159 if (name[0] == '.') {
160 if (name[1] == '/') {
161 dot = 1;
162 i = 1;
163 }
164 else if ((name[1] == '.') && (name[2] == '/')) {
165 dot = 2;
166 i = 2;
167 while ((name[i + 1] == '.') && (name[i + 2] == '.') && (name[i + 3] == '/')) {
168 dot++;
169 i += 3;
170 }
171 }
172 }
173 else if (name[0] == '#') {
174 hash = 1;
175 }
176 else if (c_strncmp(name, "moddable:", 9) == 0)
177 c_memmove(name, name + 9, c_strlen(name) - 8);
178
179#if mxWindows
180 {
181 char c;
182 slash = name;
183 if (!c_strncmp(name, "xsbug://", 8))
184 slash += 8;
185 while ((c = *slash)) {
186 if (c == '/')
187 *slash = '\\';
188 slash++;
189 }
190 }
191#endif
192 slash = c_strrchr(name, mxSeparator);
193 if (!slash)
194 slash = name;
195 slash = c_strrchr(slash, '.');
196 if (slash && (!c_strcmp(slash, ".js") || !c_strcmp(slash, ".mjs"))) {
197#if MODDEF_XS_TEST
198 c_strcpy(extension, slash);
199#endif
200 *slash = 0;
201 }
202 if (dot > 0) {

Callers 2

fxResolveSpecifierFunction · 0.70
fxAwaitImportFunction · 0.70

Calls 4

fxToStringBufferFunction · 0.85
fxGetKeyNameFunction · 0.85
fxGetArchiveCodeFunction · 0.85
fxNewNameCFunction · 0.85

Tested by

no test coverage detected