void fxLoadModuleXML(txMachine* the, txString path, txID moduleID) { FskFileMapping map = NULL; txFileMapStream fileMapStream; txStringStream stringStream; txScript* script = NULL; mxTry(the) { fxBeginHost(the); xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map)); fileMapStream.offset = 0; mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(3); fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag); fxCallID(the, fxID(the, "generate")); fxToString(the, the->stack); stringStream.slot = the->stack; stringStream.size = c_strlen(stringStream.slot->value.string); stringStream.offset = 0; script = fxParseScript(the, &stringStream, fxStringGetter, mxDebugFlag); fxEndHost(the); } mxCatch(the) { break; } FskFileDisposeMap(map); fxResolveModule(the, moduleID, script, NULL, NULL); }
void fxPerformPromiseJobs(void* it) { txMachine* the = it; fxBeginHost(the); { fxRunPromiseJobs(the); } fxEndHost(the); }
void fxPerformJob(void* it) { txJob* job = it; txMachine* the = job->the; fxBeginHost(the); { fxRunPromiseJobs(the); } fxEndHost(the); #if mxMacOSX CFRunLoopRemoveSource(CFRunLoopGetCurrent(), job->source, gxRunLoopMode); #endif c_free(job); }
void fx_setTimeoutCallback(CFRunLoopTimerRef timer, void *info) { txTimeoutData* data = info; txMachine* the = data->the; fxBeginHost(the); { mxPush(data->argument); /* ARGC */ mxPushInteger(1); /* THIS */ mxPushUndefined(); /* FUNCTION */ mxPush(data->function); fxCall(the); the->stack++; } fxEndHost(the); }
void fxToPrimitive(txMachine* the, txSlot* theSlot, txInteger theHint) { if (theSlot->kind == XS_REFERENCE_KIND) { fxBeginHost(the); if (theHint == XS_NO_HINT) mxPushString(mxDefaultString.value.string); else if (theHint == XS_NUMBER_HINT) mxPushString(mxNumberString.value.string); else mxPushString(mxStringString.value.string); mxPushInteger(1); mxPushSlot(theSlot); fxCallID(the, mxID(_Symbol_toPrimitive)); theSlot->kind = the->stack->kind; theSlot->value = the->stack->value; the->stack++; fxEndHost(the); } }
txSlot* fxCreateInstance(txMachine* the, txSlot* slot) { txSlot* prototype; mxPushUndefined(); prototype = the->stack; fxBeginHost(the); mxPushReference(slot); fxGetID(the, mxID(_prototype)); *prototype = *the->stack; fxEndHost(the); /* txSlot* prototype = mxFunctionInstancePrototype(slot); if (prototype->kind == XS_NULL_KIND) { if (prototype->flag & XS_DONT_SET_FLAG) mxTypeError("new.target: no constructor"); if (slot->flag & XS_SHARED_FLAG) mxTypeError("new.target: shared"); fxDefaultFunctionPrototype(the, slot, prototype); } mxPushSlot(prototype); */ fxNewInstanceOf(the); return the->stack->value.reference; }
void fxIncludeScript(txParser* parser, txString string) { txBoolean done = 0; char* base = NULL; char name[PATH_MAX]; char* slash = NULL; char* dot = NULL; char* extension = NULL; char* url = NULL; char* path = NULL; FskFileInfo fileInfo; FskFileMapping map= NULL; txFileMapStream fileMapStream; txStringStream stringStream; txMachine* the = parser->console; fxBeginHost(the); { mxTry(the) { xsThrowIfFskErr(KprPathToURL(parser->path->string, &base)); FskStrCopy(name, string); slash = FskStrRChr(name, '/'); if (!slash) slash = name; dot = FskStrRChr(slash, '.'); if (dot) extension = dot; else extension = name + FskStrLen(name); if (!dot) FskStrCopy(extension, ".js"); if (!FskStrCompare(extension, ".js")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, (unsigned char**)&(fileMapStream.buffer), &(fileMapStream.size), 0, &map)); fileMapStream.offset = 0; fxIncludeTree(parser, &fileMapStream, fxFileMapGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } if (!dot) FskStrCopy(extension, ".xml"); if (!FskStrCompare(extension, ".xml")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map)); fileMapStream.offset = 0; mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(3); fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag); fxCallID(the, fxID(the, "generate")); fxToString(the, the->stack); stringStream.slot = the->stack; stringStream.size = c_strlen(stringStream.slot->value.string); stringStream.offset = 0; fxIncludeTree(parser, &stringStream, fxStringGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } FskMemPtrDispose(base); } mxCatch(the) { FskFileDisposeMap(map); FskMemPtrDispose(path); FskMemPtrDispose(url); FskMemPtrDispose(base); break; } } fxEndHost(the); if (!done) fxReportParserError(parser, "include file not found: %s", string); }