예제 #1
0
VJSWebWorkerObject *VJSWebWorkerObject::_CreateWorker (XBOX::VJSContext &inParentContext, VJSWorker *inOutsideWorker,
        bool inReUseContext,
        const XBOX::VString &inUrl, bool inIsDedicated, const XBOX::VString &inName)
{
    xbox_assert(inOutsideWorker != NULL);

    bool		needToRun;
    VJSWorker	*insideWorker;

    if (inIsDedicated) {

        needToRun = true;
        insideWorker = new VJSWorker(inParentContext, inUrl, inReUseContext);

    } else

        insideWorker = VJSWorker::RetainSharedWorker(inParentContext, inUrl, inName, inReUseContext, &needToRun);

    xbox_assert(insideWorker != NULL);

    VJSMessagePort	*onMessagePort, *onErrorPort;

    onMessagePort = VJSMessagePort::Create(inOutsideWorker, insideWorker);
    onMessagePort->SetCallbackName(inOutsideWorker, "onmessage");
    onMessagePort->SetCallbackName(insideWorker, "onmessage");

    onErrorPort = VJSMessagePort::Create(inOutsideWorker, insideWorker);
    onErrorPort->SetCallbackName(inOutsideWorker, "onerror");
    onErrorPort->SetCallbackName(insideWorker, "onerror");

    inOutsideWorker->AddErrorPort(onErrorPort);
    insideWorker->AddErrorPort(onErrorPort);

    if (inIsDedicated)

        insideWorker->SetMessagePorts(onMessagePort, onErrorPort);

    else

        insideWorker->Connect(onMessagePort, onErrorPort);

    xbox_assert(!(inIsDedicated && !needToRun));
    if (needToRun)

        insideWorker->Run();

    XBOX::ReleaseRefCountable<VJSWorker>(&insideWorker);

    VJSWebWorkerObject	*webWorkerObject;

    webWorkerObject = new VJSWebWorkerObject(onMessagePort, onErrorPort);

    XBOX::ReleaseRefCountable<VJSMessagePort>(&onMessagePort);
    XBOX::ReleaseRefCountable<VJSMessagePort>(&onErrorPort);

    return webWorkerObject;
}
예제 #2
0
VJSWebWorkerObject *VJSWebWorkerObject::_CreateWorker (XBOX::VJSContext &inParentContext, VJSWorker *inOutsideWorker, 
														bool inReUseContext, VJSWebSocketObject *inWebSocket,
														const XBOX::VString &inUrl, bool inIsDedicated, const XBOX::VString &inName)
{
	xbox_assert(inOutsideWorker != NULL);
	
	bool		needToRun;
	VJSWorker	*insideWorker;
			
	if (inIsDedicated) {
	
		needToRun = true;
		insideWorker = new VJSWorker(inParentContext, inOutsideWorker, inUrl, inReUseContext, inWebSocket);
				
	} else 

		insideWorker = VJSWorker::RetainSharedWorker(inParentContext, inOutsideWorker, inUrl, inName, inReUseContext, &needToRun);

	xbox_assert(insideWorker != NULL);

	if (insideWorker == inOutsideWorker) {

		// Recursive SharedWorker constructor calls are forbidden.

		xbox_assert(!inIsDedicated);

		XBOX::ReleaseRefCountable<VJSWorker>(&insideWorker);
		XBOX::vThrowError(XBOX::VE_JVSC_RECURSIVE_SHARED_WORKER, inUrl);

		return NULL;

	}

	VJSMessagePort	*onMessagePort, *onErrorPort;
	
	onMessagePort = VJSMessagePort::Create(inOutsideWorker, insideWorker,inParentContext);
	onMessagePort->SetCallbackName(inOutsideWorker, "onmessage");	
	onMessagePort->SetCallbackName(insideWorker, "onmessage");
	
	onErrorPort = VJSMessagePort::Create(inOutsideWorker, insideWorker,inParentContext);
	onErrorPort->SetCallbackName(inOutsideWorker, "onerror");	
	onErrorPort->SetCallbackName(insideWorker, "onerror");

	inOutsideWorker->AddErrorPort(onErrorPort);
	insideWorker->AddErrorPort(onErrorPort);

	if (inIsDedicated)

		insideWorker->SetMessagePort(onMessagePort);

	VJSWebWorkerObject	*webWorkerObject;

	webWorkerObject = new VJSWebWorkerObject(onMessagePort, onErrorPort, insideWorker);

	xbox_assert(!(inIsDedicated && !needToRun));
	if (needToRun)

		insideWorker->Run();
	
	if (!inIsDedicated)

		insideWorker->Connect(onMessagePort, onErrorPort);

	XBOX::ReleaseRefCountable<VJSMessagePort>(&onMessagePort);
	XBOX::ReleaseRefCountable<VJSMessagePort>(&onErrorPort);
	XBOX::ReleaseRefCountable<VJSWorker>(&insideWorker);

	return webWorkerObject;
}