コード例 #1
0
ファイル: FskECMAScript.c プロジェクト: giapdangle/kinomajs
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);
}
コード例 #2
0
ファイル: kprMessage.c プロジェクト: basuke/kinomajs
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();
}
コード例 #3
0
ファイル: kprCanvas.c プロジェクト: afrog33k/kinomajs
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));
}
コード例 #4
0
ファイル: kpr.c プロジェクト: basuke/kinomajs
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;
				}
			}
		}
コード例 #5
0
ファイル: kprMessage.c プロジェクト: basuke/kinomajs
void KprMessageScriptTargetGet(KprMessage self, xsMachine* the, xsSlot* slot)
{
	if (self->stream->dispatch->dispose == KprMessageScriptTargetDispose) {
		KprMessageScriptTarget target = (KprMessageScriptTarget)self->stream;
		if (target->result)
			*slot = xsDemarshall(target->result);
		else {
			void* data;
			UInt32 size; 
			KprMessageGetResponseBody(self, &data, &size);
			if (data && size) {
				if (!FskStrCompare(target->name, "TEXT"))
					*slot = xsStringBuffer(data, size);
				else {
					*slot = xsNewInstanceOf(xsChunkPrototype);
					xsSetHostData(*slot, data);
					xsSetHostDestructor(*slot , NULL);
					xsSet(*slot, xsID("length"), xsInteger(size));		//@@jph
				}
			}
		}
	}
}