static void KprPromiseTargetComplete(KprMessage message, void* it) { KprPromiseTarget self = it; xsBeginHost(self->the); xsVars(3); xsVar(0) = xsAccess(self->resolve); xsVar(1) = xsAccess(self->reject); if (message->error) { xsVar(2) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID_KPR), xsID_message)); xsSetHostData(xsVar(2), message); FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageConstruct, message); message->usage++; // host (void)xsCallFunction1(xsVar(1), xsUndefined, xsVar(2)); } else { if (message->stream) KprMessageScriptTargetGet(message, the, &xsVar(2)); else { xsVar(2) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID_KPR), xsID_message)); xsSetHostData(xsVar(2), message); FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageConstruct, message); message->usage++; // host } (void)xsCallFunction1(xsVar(0), xsUndefined, xsVar(2)); } xsEndHost(self->the); }
void Zeroconf_browser_callback(KprZeroconfBrowser self, char* function, KprZeroconfServiceInfo service) { xsBeginHostSandboxCode(self->the, self->code); if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail; xsVars(3); { xsTry { xsVar(0) = xsAccess(self->behavior); xsVar(1) = xsNewInstanceOf(xsObjectPrototype); xsSet(xsVar(1), xsID("name"), xsString(service->name)); xsSet(xsVar(1), xsID("type"), xsString(service->type)); if (service->host) xsSet(xsVar(1), xsID("host"), xsString(service->host)); if (service->ip) { xsSet(xsVar(1), xsID("ip"), xsString(service->ip)); xsSet(xsVar(1), xsID("port"), xsInteger(service->port)); } if (service->txt) { char* txt = service->txt; UInt32 position = 0, size = FskStrLen(txt); UInt32 length = 0; xsVar(2) = xsNewInstanceOf(xsObjectPrototype); xsSet(xsVar(1), xsID("txt"), xsVar(2)); length = txt[position++] & 0xFF; while ((position + length) <= size) { char end; char* equal; if (!length) break; end = txt[position + length]; txt[position + length] = 0; equal = FskStrChr(txt + position, '='); if (equal) { *equal = 0; xsSet(xsVar(2), xsID(txt + position), xsString(equal + 1)); *equal = '='; } txt[position + length] = end; position += length; length = txt[position++] & 0xFF; } } if (xsFindResult(xsVar(0), xsID(function))) { (void)xsCallFunction1(xsResult, xsVar(0), xsVar(1)); } } xsCatch { } } bail: xsEndHostSandboxCode(); }
void KprMessageScriptTargetTransform(void* it, KprMessage message, xsMachine* machine) { KprMessageScriptTarget self = it; if (message->error) return; xsBeginHostSandboxCode(machine, NULL); { xsVars(2); { xsTry { void* data; UInt32 size; KprMessageGetResponseBody(message, &data, &size); if (data && size) { xsIndex id = xsID(self->name); if (xsHas(xsGlobal, id)) { xsVar(0) = xsGet(xsGlobal, id); xsVar(1) = xsNewInstanceOf(xsChunkPrototype); xsSetHostData(xsVar(1), data); xsSetHostDestructor(xsVar(1) , NULL); xsSet(xsVar(1), xsID("length"), xsInteger(size)); xsResult = xsCall1(xsVar(0), xsID("parse"), xsVar(1)); self->result = xsMarshall(xsResult); } } } xsCatch { } } } xsEndHostSandboxCode(); }
void kpr2jsSplitPath(xsMachine* the) { char *aPath; char *aSeparator = NULL; char *aDot = NULL; int aLength; char aDirectory[1024]; char aName[1024]; char anExtension[1024]; aPath = xsToString(xsArg(0)); aSeparator = strrchr(aPath, mxSeparator); if (aSeparator == NULL) aSeparator = aPath; else aSeparator++; aDot = strrchr(aSeparator, '.'); if (aDot == NULL) aDot = aSeparator + strlen(aSeparator); aLength = aSeparator - aPath; strncpy(aDirectory, aPath, aLength); aDirectory[aLength - 1] = 0; aLength = aDot - aSeparator; strncpy(aName, aSeparator, aLength); aName[aLength] = 0; strcpy(anExtension, aDot); xsResult = xsNewInstanceOf(xsArrayPrototype); xsSet(xsResult, 0, xsString(aDirectory)); xsSet(xsResult, 1, xsString(aName)); xsSet(xsResult, 2, xsString(anExtension)); }
void KprDebugMachineEchoItem(KprDebugMachine self, int theView, char* path, int line, char* name, char* value) { KprDebug debug = self->debug; xsMachine* the = debug->the; if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail; { xsTry { xsVar(0) = xsAccess(debug->behavior); xsVar(1) = xsGet(xsVar(0), xsID(self->address)); xsVar(2) = xsNewInstanceOf(xsObjectPrototype); if (path) xsNewHostProperty(xsVar(2), xsID("path"), xsString(path), xsDefault, xsDontScript); if (line >= 0) xsNewHostProperty(xsVar(2), xsID("line"), xsInteger(line), xsDefault, xsDontScript); if (name) xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript); if (value) xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript); if (xsFindResult(xsVar(1), xsID_push)) { (void)xsCallFunction1(xsResult, xsVar(1), xsVar(2)); } } xsCatch { } } bail: return; }
// image data void KPR_canvasRenderingContext2D_cloneImageData(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); FskCanvas2dImageData data = xsGetHostData(xsArg(0)); data = FskCanvas2dCloneImageData(ctx, data); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("imageData"))); xsSetHostData(xsResult, data); }
void KPR_imageData_get_data(xsMachine *the) { FskCanvas2dImageData data = xsGetHostData(xsThis); xsResult = xsNewInstanceOf(xsChunkPrototype); xsSetHostData(xsResult, (void*)data->data.bytes); xsSetHostDestructor(xsResult, NULL); xsSet(xsResult, xsID("length"), xsInteger(data->data.length)); }
void process_execArgv(xsMachine* the) { int i; xsResult = xsNewInstanceOf(xsArrayPrototype); for (i = gargi; i < gargc; i++) { xsSetAt(xsResult, xsInteger(i - gargi), xsString(gargv[i])); } }
void KPR_debug_get_machines(xsMachine *the) { KprDebug self = xsGetHostData(xsThis); KprDebugMachine machine = NULL; xsEnterSandbox(); xsVars(1); { xsResult = xsNewInstanceOf(xsArrayPrototype); for (machine = self->machine; machine; machine = machine->next) { xsVar(0) = xsNewInstanceOf(xsObjectPrototype); xsNewHostProperty(xsVar(0), xsID("address"), xsString(machine->address), xsDefault, xsDontScript); if (machine->title) xsNewHostProperty(xsVar(0), xsID("title"), xsString(machine->title), xsDefault, xsDontScript); xsCall1(xsResult, xsID_push, xsVar(0)); } } xsLeaveSandbox(); }
// pixel manipulation void KPR_canvasRenderingContext2D_createImageData(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); xsNumberValue sw = xsToNumber(xsArg(0)); xsNumberValue sh = xsToNumber(xsArg(1)); FskCanvas2dImageData data = FskCanvas2dCreateImageData(ctx, sw, sh); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("imageData"))); xsSetHostData(xsResult, data); }
FskErr FskSSLNew(void **fsslp, const char *host, int port, Boolean blocking, long flags, int priority) { FskSSL *fssl; FskErr err; if ((err = FskMemPtrNewClear(sizeof(FskSSL), (FskMemPtr*)(void*)&fssl)) != kFskErrNone) return err; if ((err = newSSLVM(&fssl->vm)) != kFskErrNone) { FskMemPtrDispose(fssl); return err; } xsBeginHost(fssl->vm->the); xsTry { const char *prStr; xsVars(2); /* construct the options */ xsVar(0) = xsNewInstanceOf(xsObjectPrototype); if (blocking) xsSet(xsVar(0), xsID("blocking"), xsTrue); if (flags & kConnectFlagsSynchronous) xsSet(xsVar(0), xsID("synchronous"), xsTrue); switch (priority) { default: case kFskNetSocketLowestPriority: prStr = "lowest"; break; case kFskNetSocketLowPriority: prStr = "low"; break; case kFskNetSocketMediumPriority: prStr = "medium"; break; case kFskNetSocketHighPriority: prStr = "high"; break; case kFskNetSocketHighestPriority: prStr = "highest"; break; } (void)xsSet(xsVar(0), xsID("priority"), xsString((xsStringValue)prStr)); (void)xsSet(xsVar(0), xsID("raw"), xsTrue); xsVar(1) = xsNew3(xsGet(xsGlobal, xsID("Stream")), xsID("Socket"), xsString((xsStringValue)host), xsInteger(port), xsVar(0)); fssl->socket = xsVar(1); xsRemember(fssl->socket); xsVar(1) = xsNew0(xsGet(xsGlobal, xsID("FskSSL")), xsID("Session")); fssl->ssl = xsVar(1); xsRemember(fssl->ssl); } xsCatch { if (xsHas(xsException, xsID("code"))) err = xsToInteger(xsGet(xsException, xsID("code"))); if (err == kFskErrNone) err = kFskErrOperationFailed; } xsEndHost(fssl->vm->the); if (err == kFskErrNone) { if (fsslp != NULL) *fsslp = fssl; } else { disposeSSLVM(fssl->vm); FskMemPtrDispose(fssl); } return err; }
void KPR_system_getWifiInfo(xsMachine* the) { DWORD dwResult = 0; HANDLE hClient = NULL; DWORD dwMaxClient = 2; DWORD dwCurVersion = 0; PWLAN_INTERFACE_INFO_LIST pIfList = NULL; int i; PWLAN_INTERFACE_INFO pIfInfo = NULL; DWORD connectInfoSize = sizeof(WLAN_CONNECTION_ATTRIBUTES); PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL; WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid; ULONG length; xsVars(1); dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient); if (dwResult != ERROR_SUCCESS) goto bail; dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList); if (dwResult != ERROR_SUCCESS) goto bail; for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) { pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i]; if (pIfInfo->isState == wlan_interface_state_connected) { dwResult = WlanQueryInterface(hClient, &pIfInfo->InterfaceGuid, wlan_intf_opcode_current_connection, NULL, &connectInfoSize, (PVOID *) &pConnectInfo, &opCode); if (dwResult != ERROR_SUCCESS) goto bail; length = pConnectInfo->wlanAssociationAttributes.dot11Ssid.uSSIDLength; if (length > 0) { xsResult = xsNewInstanceOf(xsObjectPrototype); xsVar(0) = xsStringBuffer(NULL, length + 1); FskMemCopy(xsToString(xsVar(0)), pConnectInfo->wlanAssociationAttributes.dot11Ssid.ucSSID, length); xsSet(xsResult, xsID("SSID"), xsVar(0)); } break; } } bail: if (pConnectInfo != NULL) { WlanFreeMemory(pConnectInfo); pConnectInfo = NULL; } if (pIfList != NULL) { WlanFreeMemory(pIfList); pIfList = NULL; } if (hClient != NULL) { WlanCloseHandle(hClient, NULL); hClient = NULL; } }
void xsMemPtrToChunk(xsMachine *the, xsSlot *ref, FskMemPtr data, UInt32 dataSize, Boolean alreadyAllocated) { xsDestructor destructor; if (!alreadyAllocated) *ref = xsNewInstanceOf(xsChunkPrototype); xsSetHostData(*ref, data); destructor = xsGetHostDestructor(*ref); xsSetHostDestructor(*ref, NULL); xsSet(*ref, xsID_length, xsInteger(dataSize)); xsSetHostDestructor(*ref, destructor); }
void KPR_canvas_getContext(xsMachine *the) { KprCanvas self = xsGetHostData(xsThis); if (self->cnv) { FskCanvas2dContext ctx = FskCanvasGet2dContext(self->cnv); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasRenderingContext2D"))); xsSetHostData(xsResult, ctx); xsSet(xsResult, xsID("canvas"), xsThis); KprContentInvalidate((KprContent)self); } }
void KPR_canvasRenderingContext2D_measureText(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); xsStringValue text = xsToString(xsArg(0)); UInt16* buffer; if (kFskErrNone == FskTextUTF8ToUnicode16NE((unsigned char*)text, FskStrLen(text), &buffer, NULL)) { xsNumberValue width = FskCanvas2dMeasureText(ctx, buffer); FskMemPtrDispose(buffer); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("textMetrics"))); xsSet(xsResult, xsID("width"), xsNumber(width)); } }
FskErr KprApplicationNew(KprApplication* it, char* url, char* id, Boolean breakOnStart, Boolean breakOnExceptions) { KprCoordinatesRecord coordinates = { kprLeftRight, kprTopBottom, 0, 0, 0, 0, 0, 0 }; xsAllocation allocation = { 2 * 1024 * 1024, 1024 * 1024, 64 * 1024, 8 * 1024, 2048, 16000, 1993 }; FskErr err = kFskErrNone; KprApplication self; bailIfError(FskMemPtrNewClear(sizeof(KprApplicationRecord), it)); self = *it; FskInstrumentedItemNew(self, NULL, &KprApplicationInstrumentation); self->dispatch = &KprApplicationDispatchRecord; self->flags = kprContainer | kprClip | kprVisible; KprContentInitialize((KprContent)self, &coordinates, NULL, NULL); bailIfError(KprURLMerge(gShell->url, url, &self->url)); if (id) { self->id = FskStrDoCopy(id); bailIfNULL(self->id); } self->the = xsAliasMachine(&allocation, gShell->root, self->url, self); if (!self->the) BAIL(kFskErrMemFull); FskInstrumentedItemSendMessageNormal(self, kprInstrumentedContentCreateMachine, self); xsBeginHost(self->the); xsResult = xsNewHostFunction(KPR_include, 1); xsSet(xsResult, xsID("uri"), xsString(self->url)); xsNewHostProperty(xsGlobal, xsID("include"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsResult = xsNewHostFunction(KPR_require, 1); xsSet(xsResult, xsID("uri"), xsString(self->url)); xsNewHostProperty(xsGlobal, xsID("require"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("application"))); self->slot = xsResult; xsSetHostData(xsResult, self); (void)xsCall1(xsGet(xsGlobal, xsID("Object")), xsID("seal"), xsResult); xsNewHostProperty(xsGlobal, xsID("application"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsNewHostProperty(xsGlobal, xsID("shell"), xsNull, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); if (breakOnStart) xsDebugger(); if (breakOnExceptions) (void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakOnException"), xsBoolean(breakOnExceptions)); (void)xsCall1(xsGlobal, xsID("include"), xsString(self->url)); xsEndHost(self->the); KprContentChainPrepend(&gShell->applicationChain, self, 0, NULL); bail: return err; }
void xs_z_div2(xsMachine *the) { z_t *z = xsGetHostData(xsThis); xsVars(2); z_call3(the, z, kcl_z_div, &xsVar(1)); xsVar(0) = xsResult; xsResult = xsNewInstanceOf(xsObjectPrototype); xsSet(xsResult, xsID("q"), xsVar(0)); xsSet(xsResult, xsID("r"), xsVar(1)); }
void xs_system_get_timezone(xsMachine *the) { struct timezone tz; xsVars(1); mc_gettimeofday(NULL, &tz); xsResult = xsNewInstanceOf(xsObjectPrototype); xsSetInteger(xsVar(0), tz.tz_minuteswest); xsSet(xsResult, xsID("timedifference"), xsVar(0)); xsSetInteger(xsVar(0), tz.tz_dsttime); xsSet(xsResult, xsID("dst"), xsVar(0)); }
void scanComment(void *data, const char *text) { Scanner* self = data; xsMachine* the = self->the; scanText(data); xsVar(VALUE) = xsString((xsStringValue)text); xsVar(LINE) = xsInteger(XML_GetCurrentLineNumber(self->expat)); xsVar(CHILD) = xsNewInstanceOf(xsVar(COMMENT_PROTOTYPE)); xsSet(xsVar(CHILD), xsID_path, xsVar(PATH)); xsSet(xsVar(CHILD), xsID_line, xsVar(LINE)); xsSet(xsVar(CHILD), xsID_parent, xsResult); xsSet(xsVar(CHILD), xsID_value, xsVar(VALUE)); xsArrayCacheItem(xsVar(CHILDREN), xsVar(CHILD)); }
int main(int argc, char* argv[]) { xsAllocation anAllocation = { 2048 * 1024, /* initialChunkSize */ 512 * 1024, /* incrementalChunkSize */ 1000 * 1000, /* initialHeapCount */ 50 * 1000, /* incrementalHeapCount */ 1024, /* stackCount */ 8192, /* symbolCount */ 1993 /* symbolModulo */ }; xsMachine* aMachine; int argi; int result = 1; for (argi = 0; argi < argc; argi++){ result = strncmp(argv[argi], "--help", strlen("--help")); if(!result) { printHelp(); exit(0); } } result = 1; gxProperties = calloc(mxPropertyModulo, sizeof(xsSlot)); if (gxProperties) { aMachine = xsNewMachine(&anAllocation, &kprconfigGrammar, NULL); if (aMachine) { xsBeginHost(aMachine); { xsTry { xsResult = xsNewInstanceOf(xsArrayPrototype); for (argi = 0; argi < argc; argi++) xsSet(xsResult, argi, xsString(argv[argi])); (void)xsCall1(xsGlobal, xsID("main"), xsResult); result = 0; } xsCatch { char* aMessage = xsToString(xsGet(xsException, xsID("message"))); fprintf(stderr, "### %s\n", aMessage); } } xsEndHost(aMachine); xsDeleteMachine(aMachine); } else fprintf(stderr, "### Cannot allocate machine!\n"); }
xsBooleanValue fxFindModuleLoadAsDirectory(xsMachine* the, xsStringValue base, xsStringValue name, xsIndex* id) { char node[1024]; UInt32 nodeSize; xsStringValue slash; FskErr err; FskFileMapping map = NULL; xsBooleanValue result = 0; xsStringValue path = NULL; unsigned char* data; FskInt64 size; xsSlot slot; nodeSize = sizeof(node); FskStrNCopy(node, base, nodeSize); slash = FskStrRChr(node, '/'); if (slash) *slash = 0; FskStrNCat(node, "/", nodeSize); FskStrNCat(node, name, nodeSize); if (FskStrTail(node, "/") != 0) FskStrNCat(node, "/", nodeSize); FskStrNCat(node, "package.json", nodeSize); err = KprURLToPath(node, &path); if (err == kFskErrNone) { err = FskFileMap(path, &data, &size, 0, &map); if (err == kFskErrNone) { xsTry { slot = xsNewInstanceOf(xsChunkPrototype); xsSetHostData(slot, data); xsSetHostDestructor(slot, NULL); xsSet(slot, xsID("length"), xsInteger(size)); slot = xsCall1(xsGet(xsGlobal, xsID("JSON")), xsID("parse"), slot); } xsCatch { slot = xsUndefined; } if (xsTest(slot)) { slot = xsGet(slot, xsID("main")); if (xsTest(slot)) { FskStrNCopy(node, name, nodeSize); if (FskStrTail(node, "/") != 0) FskStrNCat(node, "/", nodeSize); FskStrNCat(node, xsToString(slot), nodeSize); if (fxFindModuleLoadAsFile(the, base, node, id)) result = 1; } } }
void KPR_parseURI(xsMachine *the) { xsStringValue url = xsToString(xsArg(0)); KprURLPartsRecord parts; xsStringValue target; char c; xsThrowIfFskErr(FskMemPtrNew(FskStrLen(url) + 1, &target)); FskStrCopy(target, url); KprURLSplit(target, &parts); xsResult = xsNewInstanceOf(xsObjectPrototype); if (parts.scheme) { c = *(parts.scheme + parts.schemeLength); *(parts.scheme + parts.schemeLength) = 0; xsNewHostProperty(xsResult, xsID_scheme, xsString(parts.scheme), xsDefault, xsDontScript); *(parts.scheme + parts.schemeLength) = c; } if (parts.authority) { c = *(parts.authority + parts.authorityLength); *(parts.authority + parts.authorityLength) = 0; xsNewHostProperty(xsResult, xsID_authority, xsString(parts.authority), xsDefault, xsDontScript); *(parts.authority + parts.authorityLength) = c; } if (parts.path) { c = *(parts.path + parts.pathLength); *(parts.path + parts.pathLength) = 0; xsNewHostProperty(xsResult, xsID_path, xsString(parts.path), xsDefault, xsDontScript); *(parts.path + parts.pathLength) = c; } if (parts.name) { c = *(parts.name + parts.nameLength); *(parts.name + parts.nameLength) = 0; xsNewHostProperty(xsResult, xsID_name, xsString(parts.name), xsDefault, xsDontScript); *(parts.name + parts.nameLength) = c; } if (parts.query) { c = *(parts.query + parts.queryLength); *(parts.query + parts.queryLength) = 0; xsNewHostProperty(xsResult, xsID_query, xsString(parts.query), xsDefault, xsDontScript); *(parts.query + parts.queryLength) = c; } if (parts.fragment) { c = *(parts.fragment + parts.fragmentLength); *(parts.fragment + parts.fragmentLength) = 0; xsNewHostProperty(xsResult, xsID_fragment, xsString(parts.fragment), xsDefault, xsDontScript); *(parts.fragment + parts.fragmentLength) = c; } FskMemPtrDispose(target); }
void scanText(void *data) { Scanner* self = data; xsMachine* the = self->the; if (self->textOffset) { self->textBuffer[self->textOffset] = 0; xsVar(VALUE) = xsString(self->textBuffer); self->textOffset = 0; xsVar(CHILD) = xsNewInstanceOf(xsVar(CDATA_PROTOTYPE)); xsSet(xsVar(CHILD), xsID_path, xsVar(PATH)); xsSet(xsVar(CHILD), xsID_line, xsVar(LINE)); xsSet(xsVar(CHILD), xsID_parent, xsResult); xsSet(xsVar(CHILD), xsID_value, xsVar(VALUE)); xsArrayCacheItem(xsVar(CHILDREN), xsVar(CHILD)); } }
void KPR_canvas_get_size(xsMachine *the) { KprCanvas self = xsGetHostData(xsThis); xsResult = xsNewInstanceOf(xsObjectPrototype); if (self->cnv) { FskRectangleRecord bounds; FskBitmapGetBounds(FskGetCanvasBitmap(self->cnv), &bounds); xsNewHostProperty(xsResult, xsID_width, xsInteger(bounds.width), xsDefault, xsDontScript); xsNewHostProperty(xsResult, xsID_height, xsInteger(bounds.height), xsDefault, xsDontScript); } else if (self->shell) { KprShellAdjust(self->shell); xsNewHostProperty(xsResult, xsID_width, xsInteger(self->bounds.width), xsDefault, xsDontScript); xsNewHostProperty(xsResult, xsID_height, xsInteger(self->bounds.height), xsDefault, xsDontScript); } }
void KPR_canvasRenderingContext2D_pickHitRegion(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); xsNumberValue x = xsToNumber(xsArg(0)), y = xsToNumber(xsArg(1)); const char *id = NULL, *control = NULL; if (kFskErrNone == FskCanvas2dPickHitRegion(ctx, x, y, &id, &control)) { xsResult = xsNewInstanceOf(xsObjectPrototype); if (id) xsNewHostProperty(xsResult, xsID("id"), xsString((char*)id), xsDefault, xsDontScript); // TODO: Would we send a mouse event to the id? if (control) xsNewHostProperty(xsResult, xsID("control"), xsString((char*)control), xsDefault, xsDontScript); // TODO: We should call the control directly. } else { // How do we indicate failure? xsResult = NULL; } }
void scanProcessingInstruction(void *data, const char *target, const char *text) { Scanner* self = data; xsMachine* the = self->the; scanText(data); scanName(the, target, 1); xsVar(VALUE) = xsString((xsStringValue)text); xsVar(LINE) = xsInteger(XML_GetCurrentLineNumber(self->expat)); xsVar(CHILD) = xsNewInstanceOf(xsVar(PI_PROTOTYPE)); xsSet(xsVar(CHILD), xsID_path, xsVar(PATH)); xsSet(xsVar(CHILD), xsID_line, xsVar(LINE)); xsSet(xsVar(CHILD), xsID_parent, xsResult); xsSet(xsVar(CHILD), xsID_name, xsVar(NAME)); xsSet(xsVar(CHILD), xsID_namespace, xsVar(NAMESPACE)); xsSet(xsVar(CHILD), xsID_prefix, xsVar(PREFIX)); xsSet(xsVar(CHILD), xsID_value, xsVar(VALUE)); xsArrayCacheItem(xsVar(CHILDREN), xsVar(CHILD)); }
void KPR_application_get_size(xsMachine *the) { KprContainer container = xsGetHostData(xsThis); Boolean horizontal = true; SInt32 left = 0; SInt32 width = 0; SInt32 right = 0; Boolean vertical = true; SInt32 top = 0; SInt32 height = 0; SInt32 bottom = 0; while (container) { if (horizontal) { if ((container->coordinates.horizontal & kprWidth)) { width = container->coordinates.width - left - right; horizontal = false; if (!vertical) break; } else { left += container->coordinates.left; right += container->coordinates.right; } } if (vertical) { if ((container->coordinates.vertical & kprHeight)) { height = container->coordinates.height - top - bottom; vertical = false; if (!horizontal) break; } else { top += container->coordinates.top; bottom += container->coordinates.bottom; } } container = container->container; } xsResult = xsNewInstanceOf(xsObjectPrototype); xsNewHostProperty(xsResult, xsID_width, xsInteger(width), xsDefault, xsDontScript); xsNewHostProperty(xsResult, xsID_height, xsInteger(height), xsDefault, xsDontScript); }
FskErr FskSSLAttach(void **fsslp, FskSocket skt) { FskSSL *fssl; FskErr err; if ((err = FskMemPtrNewClear(sizeof(FskSSL), (FskMemPtr*)(void*)&fssl)) != kFskErrNone) return err; if ((err = newSSLVM(&fssl->vm)) != kFskErrNone) { FskMemPtrDispose(fssl); return err; } xsBeginHost(fssl->vm->the); xsTry { xsVars(2); xsVar(0) = xsNew1(xsGet(xsGlobal, xsID("Stream")), xsID("Socket"), xsHostData(skt)); xsVar(1) = xsNewInstanceOf(xsObjectPrototype); (void)xsSet(xsVar(1), xsID("raw"), xsTrue); xsCall1_noResult(xsVar(0), xsID("setProperties"), xsVar(1)); fssl->socket = xsVar(0); xsRemember(fssl->socket); xsVar(0) = xsNew0(xsGet(xsGlobal, xsID("FskSSL")), xsID("Session")); fssl->ssl = xsVar(0); xsRemember(fssl->ssl); } xsCatch { if (xsHas(xsException, xsID("code"))) err = xsToInteger(xsGet(xsException, xsID("code"))); if (err == kFskErrNone) err = kFskErrOperationFailed; } xsEndHost(fssl->vm->the); if (err == kFskErrNone) { if (fsslp != NULL) *fsslp = fssl; } else { disposeSSLVM(fssl->vm); FskMemPtrDispose(fssl); } return err; }
void KprDebugMachineLockView(KprDebugMachine self, int theView) { KprDebug debug = self->debug; xsMachine* the = debug->the; // FskDebugStr("%s: %d", __FUNCTION__, theView); if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail; { xsTry { xsVar(0) = xsAccess(debug->behavior); if (xsHasOwn(xsVar(0), xsID(self->address))) xsDelete(xsVar(0), xsID(self->address)); xsVar(1) = xsNewInstanceOf(xsArrayPrototype); xsNewHostProperty(xsVar(0), xsID(self->address), xsVar(1), xsDefault, xsDontScript); } xsCatch { } } bail: return; }
void xs_dbg_report(xsMachine *the) { if (xsToInteger(xsArgc) > 0 && xsTest(xsArg(0))) { /* silence - return the memory use */ xsMemoryUse slot, chunk; xsReportMemoryUse(the, &slot, &chunk); xsVars(1); xsResult = xsNewInstanceOf(xsObjectPrototype); xsSetInteger(xsVar(0), chunk.current); xsSet(xsResult, xsID("chunk"), xsVar(0)); xsSetInteger(xsVar(0), slot.current); xsSet(xsResult, xsID("slot"), xsVar(0)); } else { #if mxMC mc_mstats(true); #endif xsReportMemoryUse(the, NULL, NULL); } }