コード例 #1
0
ファイル: kprMessage.c プロジェクト: basuke/kinomajs
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);
}
コード例 #2
0
ファイル: kprPins.c プロジェクト: basuke/kinomajs
void KprPinsInvoke(KprService service, KprMessage message)
{
	FskErr err = kFskErrNone;
	KprPins self = gPins;
	if (KprMessageContinue(message)) {
		KprPinsListener listener = NULL;
		KprPinsListenerFind(&listener, self, message);
		if (listener) listener->useCount++;
		if (!FskStrCompareWithLength(message->parts.path, "close", message->parts.pathLength)) {
			if (listener) {
				xsBeginHostSandboxCode(listener->the, NULL);
				{
                    {
						xsTry {
							(void)xsCall0(xsAccess(listener->pins), xsID("close"));
						}
						xsCatch {
							err = exceptionToFskErr(the);
						}
					}

                    while (listener->pollers)
                        KprPinsPollerDispose(listener->pollers);
				}
				xsEndHostSandboxCode();
				KprPinsListenerDispose(listener, self);
				listener = NULL;
			}
			else {
				err = kFskErrNotFound;
			}
		}
		else if (!FskStrCompareWithLength(message->parts.path, "configure", message->parts.pathLength)) {
コード例 #3
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
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;
}
コード例 #4
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineLoadView(KprDebugMachine self, int theView, char* thePath, int theLine)
{
	FskErr err = kFskErrNone;
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;
//	FskFileInfo info;
//	FskFileMapping map = NULL;
//	FskDebugStr("%s: %d - %s:%d", __FUNCTION__, theView, thePath, theLine);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	xsVar(0) = xsAccess(debug->behavior);
	
	if (xsFindResult(xsVar(0), xsID("onMachineFileChanged"))) {
		(void)xsCallFunction5(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsNull, thePath ? xsString(thePath) : xsNull, xsInteger(theLine));
	}
//	if (kFskErrNone == FskFileGetFileInfo(thePath, &info) && (kFskDirectoryItemIsFile == info.filetype)) {
//		unsigned char *data;
//		FskInt64 size;
//		BAIL_IF_ERR(err = FskFileMap(thePath, &data, &size, 0, &map));
//		xsVar(0) = xsAccess(debug->behavior);
//		
//		if (xsFindResult(xsVar(0), xsID("onMachineFileChanged"))) {
//			(void)xsCallFunction5(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsNull, xsString(thePath), xsInteger(theLine));
//		}
//	}
bail:
//	FskFileDisposeMap(map);
	xsThrowIfFskErr(err);
}
コード例 #5
0
ファイル: kprZeroconf.c プロジェクト: kouis3940/kinomajs
void Zeroconf_advertisement_callback(KprZeroconfAdvertisement self, char* function)
{
	xsBeginHostSandboxCode(self->the, self->code);
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	xsVars(2);
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			xsVar(1) = xsAccess(self->slot);
			if (xsFindResult(xsVar(0), xsID(function))) {
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	xsEndHostSandboxCode();
}
コード例 #6
0
ファイル: kprZeroconf.c プロジェクト: kouis3940/kinomajs
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();
}
コード例 #7
0
ファイル: kprCodeWin.cpp プロジェクト: basuke/kinomajs
void KPR_shell_execute_stdout(KprShellExec exec, xsStringValue string)
{
	if (string) {
		xsBeginHost(exec->the);
		xsVars(3);
		xsVar(0) = xsAccess(exec->slot);
		xsVar(1) = xsGet(xsVar(0), xsID_stdout);
		if (xsTest(xsVar(1))) {
			xsVar(2) = xsString(string);
			xsResult = xsCallFunction1(xsVar(1), xsNull, xsVar(2));
		}
		xsEndHost(exec->the);
		FskMemPtrDispose(string);
	}
	KPR_shell_execute_callback(exec);
}
コード例 #8
0
ファイル: kprCodeWin.cpp プロジェクト: basuke/kinomajs
void KPR_shell_execute_callback(KprShellExec exec)
{
	exec->usage--;
	if (exec->usage == 0) {
		xsBeginHost(exec->the);
		xsVars(3);
		xsVar(0) = xsAccess(exec->slot);
		xsVar(1) = xsGet(xsVar(0), xsID_callback);
		if (xsTest(xsVar(1))) {
			xsVar(2) = xsInteger(exec->status);
			xsResult = xsCallFunction1(xsVar(1), xsNull, xsVar(2));
		}
		xsForget(exec->slot);
		xsSetHostData(xsVar(0), NULL);
		xsEndHost(exec->the);
		FskMemPtrDispose(exec);
	}
}
コード例 #9
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineUnlockView(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);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			KprDebugMachineCallbackView(self, "onMachineViewChanged", theView);
		}
		xsCatch {
		}
	}
bail:
	return;
}
コード例 #10
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineCallbackView(KprDebugMachine machine, char* function, int view)
{
	KprDebug self = machine->debug;
	xsMachine* the = self->the;
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			if (xsFindResult(xsVar(0), xsID(function))) {
				xsVar(1) = xsGet(xsVar(0), xsID(machine->address));
				xsDelete(xsVar(0), xsID(machine->address));
				(void)xsCallFunction3(xsResult, xsVar(0), xsString(machine->address), xsInteger(view), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
コード例 #11
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineSetViewTitle(KprDebugMachine self, int theView, char* theTitle)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

//	FskDebugStr("%s: %d - %s", __FUNCTION__, theView, theTitle);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			if (xsFindResult(xsVar(0), xsID("onMachineViewTitle")))
				(void)xsCallFunction3(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsString(theTitle));
		}
		xsCatch {
		}
	}
bail:
	return;
}
コード例 #12
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
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;
}
コード例 #13
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_quitting(xsMachine* the)
{
	KprContainer container = xsGetHostData(xsThis);
	KprContent content = container->first;
	KprScriptBehavior self = (KprScriptBehavior)content->behavior;
#if SUPPORT_INSTRUMENTATION
	void* params[2] = { self, "xsID_onQuitting" };
	FskInstrumentedItemSendMessageDebug(content, kprInstrumentedContentCallBehavior, params);
#endif
    if (self) {
        xsBeginHostSandboxCode(self->the, self->code);
        {
 			xsVars(2);
			xsVar(0) = xsAccess(self->slot);
			if (xsFindResult(xsVar(0), xsID_onQuitting)) {
				xsVar(1) = kprContentGetter(content);
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
        }
        xsEndHostSandboxCode();
    }
}
コード例 #14
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineCallbackText(KprDebugMachine machine, char* function, int view, char* text)
{
	KprDebug self = machine->debug;
	xsMachine* the = self->the;
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			if (xsFindResult(xsVar(0), xsID(function))) {
				if (view >= 0)
					(void)xsCallFunction3(xsResult, xsVar(0), xsString(machine->address), xsInteger(view), xsString(text));
				else if (text)
					(void)xsCallFunction2(xsResult, xsVar(0), xsString(machine->address), xsString(text));
				else
					(void)xsCallFunction1(xsResult, xsVar(0), xsString(machine->address));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
コード例 #15
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineEchoProperty(KprDebugMachine self, int theView, int column, char* flags, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	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);
			xsNewHostProperty(xsVar(2), xsID("column"), xsInteger(column), xsDefault, xsDontScript);
			flags[4] = 0;
			xsNewHostProperty(xsVar(2), xsID("flags"), xsString(flags + 1), xsDefault, xsDontScript);
			if (flags[0] == ' ')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			else if (flags[0] == '+')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(1), xsDefault, xsDontScript);
			else if (flags[0] == '-')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(2), xsDefault, xsDontScript);
			else
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), 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;
}
コード例 #16
0
ファイル: kprDebug.c プロジェクト: dadongdong/kinomajs
void KprDebugMachineEchoView(KprDebugMachine self, int theView, char* theName, char* theValue)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	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);
			xsNewHostProperty(xsVar(2), xsID("name"), xsString(theName), xsDefault, xsDontScript);
			xsNewHostProperty(xsVar(2), xsID("value"), xsString(theValue), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}