コード例 #1
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
void
FskSSLDispose(void *a)
{
	FskSSL *fssl = a;

	if (fssl->timer != NULL)
		FskTimeCallbackDispose(fssl->timer);

	/* when a VM is disposed, all objects associated to the vm will be discarded? */
	xsBeginHost(fssl->vm->the);
	xsTry {
		if (fssl->skt != NULL) {
			/* someone else owns the skt */
			xsCall0_noResult(fssl->socket, xsID("detachData"));
		}
		xsCall0_noResult(fssl->socket, xsID("close"));
	} xsCatch {
	}
	xsForget(fssl->socket);
	xsForget(fssl->ssl);
	xsEndHost(fssl->vm->the);

	disposeSSLVM(fssl->vm);
	FskMemPtrDispose(a);
}
コード例 #2
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLWrite(void *a, const void *buf, int *bufLen)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;
	int len = *bufLen;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	if (buf == NULL || len == 0)
		return kFskErrNone;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsVars(1);
		xsCall1_noResult(fssl->socket, xsID("attachData"), xsHostData(fssl->skt));
		xsVar(0) = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(len));
		FskMemCopy(xsGetHostData(xsVar(0)), buf, len);
		xsResult = xsCall2(fssl->ssl, xsID("write"), fssl->socket, xsVar(0));
		*bufLen = xsToInteger(xsResult);
		if (*bufLen == 0)
			err = kFskErrNoData;
		xsCall0_noResult(xsVar(0), xsID("free"));
	}  xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
コード例 #3
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLRead(void *a, void *buf, int *bufLen)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;
	int len = *bufLen, nread;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsCall1_noResult(fssl->socket, xsID("attachData"), xsHostData(fssl->skt));
		xsResult = xsCall2(fssl->ssl, xsID("read"), fssl->socket, xsInteger(len));
		if (xsTest(xsResult)) {
			nread = xsToInteger(xsGet(xsResult, xsID("length")));
			if (nread > len)
				nread = len;
			FskMemCopy(buf, xsGetHostData(xsResult), nread);
			xsCall0_noResult(xsResult, xsID("free"));
			*bufLen = nread;
			err = nread == 0 ? kFskErrNoData: kFskErrNone;
		}
		else
			err = kFskErrConnectionClosed;
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
コード例 #4
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);
}
コード例 #5
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLHandshake(void *a, FskNetSocketCreatedCallback callback, void *refCon, Boolean initiate)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	fssl->socketCallback = callback;
	fssl->callbackData = refCon;

	xsBeginHost(fssl->vm->the);

	xsTry {
		xsVars(1);

		/* set session._hostData = ssl, just for callback */
		xsVar(0) = xsNewHostObject(NULL);
		xsSetHostData(xsVar(0), fssl);
		xsSet(fssl->ssl, xsID("_hostData"), xsVar(0));
		xsVar(0) = xsNewHostFunction(xs_handshake_finished_callback, 2);
		xsSet(fssl->ssl, xsID("_hostCallback"), xsVar(0));
		xsCall3_noResult(fssl->ssl, xsID("handshake"), fssl->socket, xsVar(0), initiate ? xsTrue : xsFalse);
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}

	xsEndHost(fssl->vm->the);
	return err;
}
コード例 #6
0
ファイル: xm_timeinterval.c プロジェクト: basuke/kinomajs
static void
timeInterval_callback(xsMachine *the, struct mc_timeout *tc, void *closure)
{
	mc_timeinterval_t *ti = closure;

	xsBeginHost(the);
	xsCall_noResult(ti->obj, xsID("_callback"), NULL);
	xsEndHost(the);
}
コード例 #7
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
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;
}
コード例 #8
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_trace(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	xsStringValue text = xsToString(xsArg(0));
	xsBeginHost(application->the);
	{
		xsTrace(text);
	}
	xsEndHost(application->the);
}
コード例 #9
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_get_profiling(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean result = false;
	xsBeginHost(application->the);
	{
		result = xsTest(xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("isProfiling")));
	}
	xsEndHost(application->the);
	xsResult = xsBoolean(result);
}
コード例 #10
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
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;
}
コード例 #11
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_clearAllBreakpoints(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	xsBeginHost(application->the);
	{
		(void)xsCall0(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("clearAllBreakpoints"));
	}
	xsEndHost(application->the);
#endif
}
コード例 #12
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_set_debugging(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean flag = xsToBoolean(xsArg(0));
	xsBeginHost(application->the);
	{
		(void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setConnected"), xsBoolean(flag));
	}
	xsEndHost(application->the);
#endif
}
コード例 #13
0
ファイル: mc_usb.c プロジェクト: cugfeng/kinomajs
static void
usb_callback(xsMachine *the, void *closure)
{
	char *buf = closure;

	xsBeginHost(the);
	xsVars(2);
	xsGet(xsVar(0), xsGlobal, xsID("require"));
	xsSetString(xsVar(1), "CLI");
	xsCall(xsResult, xsVar(0), xsID("weak"), &xsVar(1), NULL);
	xsSetString(xsVar(1), buf);
	xsCall_noResult(xsResult, xsID("evaluate"), &xsVar(1), NULL);
	xsEndHost(the);
}
コード例 #14
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_setBreakpoint(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	xsStringValue file = xsToString(xsArg(0));
	xsStringValue line = xsToString(xsArg(1));
	xsBeginHost(application->the);
	{
		(void)xsCall2(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakpoint"), xsString(file), xsString(line));
	}
	xsEndHost(application->the);
#endif
}
コード例 #15
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_set_profiling(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean flag = xsToBoolean(xsArg(0));
	xsBeginHost(application->the);
	{
		if (flag)
			(void)xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("startProfiling"));
		else
			(void)xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("stopProfiling"));
	}
	xsEndHost(application->the);
}
コード例 #16
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_get_debugging(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean result = false;
	xsBeginHost(application->the);
	{
		result = xsTest(xsCall0(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("getConnected")));
	}
	xsEndHost(application->the);
	xsResult = xsBoolean(result);
#endif
}
コード例 #17
0
ファイル: xsTool.c プロジェクト: dadongdong/kinomajs
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");
	}
コード例 #18
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);
}
コード例 #19
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);
	}
}
コード例 #20
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_set_profilingDirectory(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	char* directory = NULL;
	if (xsTest(xsArg(0))) {
		xsThrowIfFskErr(KprURLToPath(xsToString(xsArg(0)), &directory));
	}
	xsBeginHost(application->the);
	{
		if (directory) {
			xsResult = xsString(directory);
			FskMemPtrDispose(directory);
		}
		(void)xsCall1(xsGet(xsGlobal, xsID("xs")), xsID("setProfilingDirectory"), xsResult);
	}
	xsEndHost(application->the);
}
コード例 #21
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
int
FskSSLGetBytesAvailable(void *a)
{
	FskSSL *fssl = a;
	int ret = 0;

	if (fssl->skt == NULL)
		return -1;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsResult = xsGet(fssl->ssl, xsID("bytesAvailable"));
		ret = xsToInteger(xsResult);
	} xsCatch {
		ret = -1;
	}
	xsEndHost(fssl->vm->the);
	return ret;
}
コード例 #22
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLLoadCerts(void *a, FskSocketCertificateRecord *cert)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	xsBeginHost(fssl->vm->the);

	xsTry {
		xsVars(2);

		xsVar(0) = xsUndefined;
		xsVar(1) = xsUndefined;
		if (cert != NULL) {
			if (cert->certificates != NULL && cert->certificatesSize > 0) {
				xsVar(0) = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(cert->certificatesSize));
				FskMemCopy(xsGetHostData(xsVar(0)), cert->certificates, cert->certificatesSize);
			}
			if (cert->policies != NULL) {
				if (cert->certificates == NULL)
					xsVar(0) = xsNew0(xsGlobal, xsID("Chunk"));	// create a null chunk just for setting the polices
				xsSet(xsVar(0), xsID("policies"), xsString(cert->policies));
			}
			if (cert->hostname != NULL) {
				xsSet(fssl->socket, xsID("hostname"), xsString(cert->hostname));	// too easy but should work...
			}
			if (cert->key != NULL && cert->keySize > 0) {
				xsVar(1) = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(cert->keySize));
				FskMemCopy(xsGetHostData(xsVar(1)), cert->key, cert->keySize);
			}
		}
		xsCall2_noResult(fssl->ssl, xsID("loadCerts"), xsVar(0), xsVar(1));
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}

	xsEndHost(fssl->vm->the);
	return err;
}
コード例 #23
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
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;
}
コード例 #24
0
ファイル: kprApplication.c プロジェクト: giapdangle/kinomajs
void KPR_host_get_profilingDirectory(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	FskErr err = kFskErrNone;
	char* directory = NULL;
	xsBeginHost(application->the);
	{
		xsResult = xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("getProfilingDirectory"));
		if (xsTest(xsResult))
			err = KprPathToURL(xsToString(xsResult), &directory);
	}
	xsEndHost(application->the);
	if (directory) {
		xsResult = xsString(directory);
		FskMemPtrDispose(directory);
	}
	else {
		xsThrowIfFskErr(err);
	}
}
コード例 #25
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLClose(void *a)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsResult = xsCall1(fssl->ssl, xsID("close"), fssl->socket);
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
コード例 #26
0
ファイル: kpr2js.c プロジェクト: dadongdong/kinomajs
int main(int argc, char* argv[])
{
    xsAllocation anAllocation = {
        2048 * 1024, /* initialChunkSize */
        512 * 1024, /* incrementalChunkSize */
        1000 * 1000, /* initialHeapCount */
        50 * 1000, /* incrementalHeapCount */
        64 * 1024, /* stackCount */
        4096, /* symbolCount */
        1993 /* symbolModulo */
    };
    xsMachine* aMachine;
    int argi;
    int result = 1;

    aMachine = xsNewMachine(&anAllocation, &kpr2jsGrammar, 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")));
                if (*aMessage)
                    fprintf(stderr, "### %s\n", aMessage);
                else
                    fprintf(stderr, "### XML error(s)\n");
            }
        }
        xsEndHost(aMachine);
        xsDeleteMachine(aMachine);
    }
    else
コード例 #27
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLFlush(void *a)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsVars(1);
		xsCall1_noResult(fssl->socket, xsID("attachData"), xsHostData(fssl->skt));
		xsResult = xsCall1(fssl->ssl, xsID("flush"), fssl->socket);
		err = xsToBoolean(xsResult) ? kFskErrNone: kFskErrNoData;
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
コード例 #28
0
ファイル: xsr6.c プロジェクト: basuke/kinomajs
int main(int argc, char* argv[]) 
{
	xsCreation creation_mc = {
		25*1024,	/* initial chunk size */
		2048,		/* incremental chunk size */
		50*1024/16,	/* initial heap count	-- will be calculated later */
		128,		/* incremental heap count	-- wasting 16 bytes / allocation */
		650,		/* stack count */
		2048+1024,	/* key count */
		97,		/* name modulo */
		127,		/* symbol modulo */
	};
	xsCreation creation_tool = {
		128 * 1024 * 1024, 	/* initialChunkSize */
		16 * 1024 * 1024, 	/* incrementalChunkSize */
		8 * 1024 * 1024, 		/* initialHeapCount */
		1 * 1024 * 1024, 		/* incrementalHeapCount */
		4096, 		/* stackCount */
		4096*3, 		/* keyCount */
		1993, 		/* nameModulo */
		127 		/* symbolModulo */
	};
	xsCreation* creation = &creation_tool;
	int error = 0;
	int argi = 1;
	void* archive = NULL;
	xsBooleanValue program = 0;
	xsBooleanValue xsbug = 0;
	xsMachine* machine;
	char path[PATH_MAX];
	char modulePath[PATH_MAX];
	xsStringValue extension;
	xsStringValue slash;
	xsStringValue name;
	int size;
	if (argi < argc) {
		if (!strcmp(argv[argi], "-a")) {
			argi++;
			if (argi < argc) {
                if (realpath(argv[argi], path)) {
                	archive = fxMapArchive(path, NULL);
                    if (!archive) {
                        fprintf(stderr, "# invalid archive: %s\n", path);
                        return 1;
                    }
                    if (strstr(path, "mc.xsa")) {
                  		creation = &creation_mc;
                    }
                }
				else {
					fprintf(stderr, "# archive not found: %s\n", argv[argi]);
					return 1;
				}
				argi++;
			}
		}
	}
	while (argi < argc) {
		if (!strcmp(argv[argi], "-p")) {
			program = 1;
			argi++;
		}
		else if (!strcmp(argv[argi], "-x")) {
			xsbug = 1;
			argi++;
		}
		else
			break;
	}
	gargc = argc;
	gargi = argi;
	gargv = argv;
	machine = xsCreateMachine(creation, archive, "xsr6", NULL);
	xsBeginHost(machine);
	{
		xsVars(2);
		{
			xsTry {
				xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
				if (xsbug)
					xsVar(1) = xsNewHostFunction(console_log_xsbug, 0);
				else
					xsVar(1) = xsNewHostFunction(console_log, 0);
				xsSet(xsVar(0), xsID("log"), xsVar(1));
				xsSet(xsGlobal, xsID("console"), xsVar(0));

				xsVar(0) = xsNewHostObject(weakTest);
				xsVar(1) = xsNewHostConstructor(WeakTest, 1, xsVar(0));
				xsSet(xsGlobal, xsID("WeakTest"), xsVar(1));
				xsVar(1) = xsNewHostFunction(gc, 0);
				xsSet(xsGlobal, xsID("gc"), xsVar(1));

				xsResult = xsModulePaths();
				if (archive) {
					slash = strrchr(path, mxSeparator);
					if (slash) {
						*(slash + 1) = 0;
						xsCall1(xsResult, xsID("add"), xsString(path));
					}
				}
				realpath(argv[0], modulePath);
				slash = strrchr(modulePath, mxSeparator);
				if (slash) {
					strcpy(slash + 1, "modules");
					size = c_strlen(modulePath);
					modulePath[size++] = mxSeparator;
					modulePath[size] = 0;
					xsCall1(xsResult, xsID("add"), xsString(modulePath));
				}

				if (argi == argc) {
					fprintf(stderr, "# no module, no program\n");
					error = 1;
				}	
				else if (program) {
					xsVar(0) = xsNewHostFunction(print, 0);
					xsSet(xsGlobal, xsID("print"), xsVar(0));
					//xsStartProfiling();
					while (argi < argc) {
						if (argv[argi][0] != '-') {
							xsElseError(realpath(argv[argi], path));
							strcpy(modulePath, path);
							slash = strrchr(modulePath, mxSeparator);
							*(slash + 1) = 0;
							xsCall1(xsResult, xsID("add"), xsString(modulePath));
							strcat(modulePath, "modules/");
							xsCall1(xsResult, xsID("add"), xsString(modulePath));
							fxRunProgram(the, path);
						}
						argi++;
					}
					fxRunLoop(the);
					//xsStopProfiling();
				}
				else {
					xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
					xsVar(1) = xsNewHostFunction(process_cwd, 0);
					xsSet(xsVar(0), xsID("cwd"), xsVar(1));
				#ifdef mxDebug
					xsSet(xsVar(0), xsID("debug"), xsTrue);
				#else
					xsSet(xsVar(0), xsID("debug"), xsFalse);
				#endif
					xsVar(1) = xsNewHostFunction(process_execArgv, 0);
					xsSet(xsVar(0), xsID("execArgv"), xsVar(1));
					xsVar(1) = xsNewHostFunction(process_getenv, 0);
					xsSet(xsVar(0), xsID("getenv"), xsVar(1));
					xsVar(1) = xsNewHostFunction(process_then, 1);
					xsSet(xsVar(0), xsID("then"), xsVar(1));
					xsSet(xsVar(0), xsID("platform"), xsString("darwin"));
					xsSet(xsGlobal, xsID("process"), xsVar(0));
		
					strcpy(path, argv[argi]);
					slash = strrchr(path, mxSeparator);
					if (slash) {
						*slash = 0;
						realpath(path, modulePath);
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						strcat(modulePath, "modules");
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						name = slash + 1;
					
					}
					else {
						realpath(".", modulePath);
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						strcat(modulePath, "modules");
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						name = path;
					}
					extension = strrchr(name, '.');
					if (extension)
						*extension = 0;
					//xsStartProfiling();
					fxRunModule(the, name);
					//xsStopProfiling();
				}
			}
			xsCatch {
				xsStringValue message = xsToString(xsException);
				fprintf(stderr, "### %s\n", message);
				error = 1;
			}
		}
	}
	xsEndHost(the);
	xsDeleteMachine(machine);
	fxUnmapArchive(archive);
	if (!error && process_then_parameters) {
	#if mxWindows
		error =_spawnvp(_P_WAIT, process_then_parameters[0], process_then_parameters);
		if (error < 0)
			fprintf(stderr, "### Cannot execute %s!\n", process_then_parameters[0]);
	#else
		execvp(process_then_parameters[0], process_then_parameters);
	#endif
	}
	return error;
}
コード例 #29
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
static FskErr
makeSSLRootVM(const char *calistpath)
{
#ifdef KPR_CONFIG
	FskErr err = kFskErrNone;

	xsBeginHost(gShell->root);
	xsTry {
		xsCall1_noResult(xsGet(xsGlobal, xsID("FskSSL")), xsID("loadRootCerts"), xsString((xsStringValue)calistpath));
	} xsCatch {
		err = kFskErrOperationFailed;
	}
	xsEndHost(gShell->root);
	return err;
#else
	char *rootPath, *xsbPath, *xsbName;
	xsGrammar *grammar;
	FskErr err;

	if ((err = FskMemPtrNewClear(sizeof(FskECMAScriptRecord), &gSSLVM)) != kFskErrNone)
		return err;

#if FSK_EMBED
	FskExtensionsEmbedLoad(SSL_VMNAME);
	FskExtensionsEmbedGrammar(SSL_VMNAME, &xsbName, &grammar);
#else
	xsbName = "FskCore.xsb";
	grammar = &FskCoreGrammar;
#endif
	rootPath = FskEnvironmentDoApply(FskStrDoCopy("[applicationPath]"));
	xsbPath = FskStrDoCat(rootPath, xsbName);
	FskMemPtrDispose(rootPath);

	grammar->name = (xsStringValue)SSL_VMNAME;
	if ((err = loadGrammar(xsbPath, grammar)) == kFskErrNone) {
		if ((gSSLVM->the = xsNewMachine(&anAllocation, grammar, gSSLVM)) == NULL)
			err = kFskErrMemFull;
		FskMemPtrDispose(grammar->symbols);
		FskMemPtrDispose(grammar->code);
	}
	FskMemPtrDispose(xsbPath);
	BAIL_IF_ERR(err);

	xsBeginHost(gSSLVM->the);
	xsTry {
#if !FSK_EMBED
		/* load Crypt and FskSSL extensions which are only needed for Fsk SSL */
		xsCall3_noResult(xsGet(xsGlobal, xsID("System")), xsID("loadExtension"), xsString("Crypt"), xsString("[applicationPath]"), xsInteger(0));
		xsCall3_noResult(xsGet(xsGlobal, xsID("System")), xsID("loadExtension"), xsString("FskSSL"), xsString("[applicationPath]"), xsInteger(1));
#endif
		xsCall1_noResult(xsGet(xsGlobal, xsID("FskSSL")), xsID("loadRootCerts"), xsString((xsStringValue)calistpath));
	} xsCatch {
		err = kFskErrOperationFailed;
	}
	xsEndHost(gSSLVM->the);

	if (err == kFskErrNone)
		xsShareMachine(gSSLVM->the);

bail:
	if (err != kFskErrNone)
		disposeSSLRootVM();
	return err;
#endif
}