void JSCExecutor::receiveMessageFromOwner(const std::string& msgString) { CHECK(m_owner) << "Received message in a Executor that doesn't have an owner!"; JSValueRef args[] = { createMessageObject(msgString) }; Value onmessageValue = Object::getGlobalObject(m_context).getProperty("onmessage"); onmessageValue.asObject().callAsFunction(1, args); }
void JSCWebWorker::postMessage(JSValueRef msg) { std::string msgString = Value(owner_->getContext(), msg).toJSONString(); workerMessageQueueThread_->runOnQueue([this, msgString] () { if (isTerminated()) { return; } JSValueRef args[] = { createMessageObject(context_, msgString) }; Value onmessageValue = Object::getGlobalObject(context_).getProperty("onmessage"); onmessageValue.asObject().callAsFunction(1, args); }); }
void JSCExecutor::receiveMessageFromOwnedWebWorker(int workerId, const std::string& json) { Object* workerObj; try { workerObj = &m_ownedWorkers.at(workerId).jsObj; } catch (std::out_of_range& e) { // Worker was already terminated return; } Value onmessageValue = workerObj->getProperty("onmessage"); if (onmessageValue.isUndefined()) { return; } JSValueRef args[] = { createMessageObject(json) }; onmessageValue.asObject().callAsFunction(1, args); flush(); }