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

Function fx_RegExp

xs/sources/xsRegExp.c:217–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void fx_RegExp(txMachine* the)
218{
219#if mxRegExp
220 txSlot* pattern = ((mxArgc > 0) && (mxArgv(0)->kind != XS_UNDEFINED_KIND)) ? mxArgv(0) : C_NULL;
221 txSlot* flags = ((mxArgc > 1) && (mxArgv(1)->kind != XS_UNDEFINED_KIND)) ? mxArgv(1) : C_NULL;
222 txBoolean patternIsRegExp = (pattern && fxIsRegExp(the, pattern)) ? 1 : 0;
223
224 if (!mxHasTarget) {
225 if (patternIsRegExp && !flags) {
226 mxPushSlot(pattern);
227 mxGetID(mxID(_constructor));
228 if ((the->stack->kind == mxFunction->kind) && (the->stack->value.reference == mxFunction->value.reference)) {
229 mxPop();
230 *mxResult = *pattern;
231 return;
232 }
233 mxPop();
234 }
235 mxPushSlot(mxFunction);
236 }
237 else {
238 mxPushSlot(mxTarget);
239 }
240 fxGetPrototypeFromConstructor(the, &mxRegExpPrototype);
241 fxNewRegExpInstance(the);
242 mxPush(mxInitializeRegExpFunction);
243 mxCall();
244 if (patternIsRegExp) {
245 mxPushSlot(pattern);
246 mxGetID(mxID(_source));
247 if (flags)
248 mxPushSlot(flags);
249 else {
250 mxPushSlot(pattern);
251 mxGetID(mxID(_flags));
252 }
253 }
254 else {
255 if (pattern)
256 mxPushSlot(pattern);
257 else
258 mxPushUndefined();
259 if (flags)
260 mxPushSlot(flags);
261 else
262 mxPushUndefined();
263 }
264 mxRunCount(2);
265 mxPullSlot(mxResult);
266#else
267 mxUnknownError("not built-in");
268#endif
269}
270
271void fx_RegExp_prototype_get_flag(txMachine* the, txU4 flag)
272{

Callers

nothing calls this directly

Calls 3

fxIsRegExpFunction · 0.85
fxNewRegExpInstanceFunction · 0.85

Tested by

no test coverage detected