本文整理汇总了C++中MessagePort类的典型用法代码示例。如果您正苦于以下问题:C++ MessagePort类的具体用法?C++ MessagePort怎么用?C++ MessagePort使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MessagePort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MessagePortChannelArray
PassOwnPtr<MessagePortChannelArray> MessagePort::disentanglePorts(const MessagePortArray* ports, ExceptionCode& ec)
{
if (!ports || !ports->size())
return 0;
// HashSet used to efficiently check for duplicates in the passed-in array.
HashSet<MessagePort*> portSet;
// Walk the incoming array - if there are any duplicate ports, or null ports or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
for (unsigned int i = 0; i < ports->size(); ++i) {
MessagePort* port = (*ports)[i].get();
if (!port || port->isCloned() || portSet.contains(port)) {
ec = INVALID_STATE_ERR;
return 0;
}
portSet.add(port);
}
// Passed-in ports passed validity checks, so we can disentangle them.
MessagePortChannelArray* portArray = new MessagePortChannelArray(ports->size());
for (unsigned int i = 0 ; i < ports->size() ; ++i) {
OwnPtr<MessagePortChannel> channel = (*ports)[i]->disentangle(ec);
ASSERT(!ec); // Can't generate exception here if passed above checks.
(*portArray)[i] = channel.release();
}
return portArray;
}
示例2: closeCallback
static v8::Handle<v8::Value> closeCallback(const v8::Arguments& args)
{
INC_STATS("DOM.MessagePort.close");
MessagePort* imp = V8MessagePort::toNative(args.Holder());
imp->close();
return v8::Handle<v8::Value>();
}
示例3: setJSMessagePortOnmessage
void setJSMessagePortOnmessage(ExecState* exec, JSObject* thisObject, JSValue value)
{
UNUSED_PARAM(exec);
JSMessagePort* castedThis = static_cast<JSMessagePort*>(thisObject);
MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
imp->setOnmessage(createJSAttributeEventListener(exec, value, thisObject));
}
示例4: onmessageAttrSetter
static void onmessageAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
MessagePort* imp = V8MessagePort::toNative(info.Holder());
transferHiddenDependency(info.Holder(), imp->onmessage(), value, V8MessagePort::eventListenerCacheIndex);
imp->setOnmessage(V8DOMWrapper::getEventListener(value, true, ListenerFindOrCreate));
return;
}
示例5:
std::unique_ptr<MessagePortChannelArray> MessagePort::disentanglePorts(const MessagePortArray* ports, ExceptionCode& ec)
{
if (!ports || !ports->size())
return nullptr;
// HashSet used to efficiently check for duplicates in the passed-in array.
HashSet<MessagePort*> portSet;
// Walk the incoming array - if there are any duplicate ports, or null ports or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
for (unsigned int i = 0; i < ports->size(); ++i) {
MessagePort* port = (*ports)[i].get();
if (!port || port->isNeutered() || portSet.contains(port)) {
ec = DATA_CLONE_ERR;
return nullptr;
}
portSet.add(port);
}
// Passed-in ports passed validity checks, so we can disentangle them.
auto portArray = std::make_unique<MessagePortChannelArray>(ports->size());
for (unsigned int i = 0 ; i < ports->size() ; ++i) {
std::unique_ptr<MessagePortChannel> channel = (*ports)[i]->disentangle();
(*portArray)[i] = std::move(channel);
}
return portArray;
}
示例6: connectTask
void WebSharedWorkerImpl::connectTask(PassOwnPtr<WebMessagePortChannel> channel, ExecutionContext* context)
{
// Wrap the passed-in channel in a MessagePort, and send it off via a connect event.
MessagePort* port = MessagePort::create(*context);
port->entangle(channel);
WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScope());
workerGlobalScope->dispatchEvent(createConnectEvent(port));
}
示例7: connectTask
void WebSharedWorkerImpl::connectTask(WebMessagePortChannelUniquePtr channel,
ExecutionContext* context) {
// Wrap the passed-in channel in a MessagePort, and send it off via a connect
// event.
MessagePort* port = MessagePort::create(*context);
port->entangle(std::move(channel));
WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
SECURITY_DCHECK(workerGlobalScope->isSharedWorkerGlobalScope());
workerGlobalScope->dispatchEvent(createConnectEvent(port));
}
示例8: jsMessagePortPrototypeFunctionClose
JSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionClose(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
UNUSED_PARAM(args);
if (!thisValue.inherits(&JSMessagePort::s_info))
return throwError(exec, TypeError);
JSMessagePort* castedThisObj = static_cast<JSMessagePort*>(asObject(thisValue));
MessagePort* imp = static_cast<MessagePort*>(castedThisObj->impl());
imp->close();
return jsUndefined();
}
示例9: jsMessagePortPrototypeFunctionClose
EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionClose(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&JSMessagePort::s_info))
return throwVMTypeError(exec);
JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
ASSERT_GC_OBJECT_INHERITS(castedThis, &JSMessagePort::s_info);
MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
imp->close();
return JSValue::encode(jsUndefined());
}
示例10: jsMessagePortOnmessage
JSValue jsMessagePortOnmessage(ExecState* exec, JSValue slotBase, const Identifier&)
{
JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(slotBase));
UNUSED_PARAM(exec);
MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
if (EventListener* listener = imp->onmessage()) {
if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
return jsFunction;
}
}
return jsNull();
}
示例11: INC_STATS
v8::Handle<v8::Value> V8MessagePort::addEventListenerCallback(const v8::Arguments& args)
{
INC_STATS("DOM.MessagePort.addEventListener()");
MessagePort* messagePort = V8DOMWrapper::convertToNativeObject<MessagePort>(V8ClassIndex::MESSAGEPORT, args.Holder());
RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(messagePort, args[1], false, ListenerFindOrCreate);
if (listener) {
String type = toWebCoreString(args[0]);
bool useCapture = args[2]->BooleanValue();
messagePort->addEventListener(type, listener, useCapture);
createHiddenDependency(args.Holder(), args[1], V8Custom::kMessagePortRequestCacheIndex);
}
return v8::Undefined();
}
示例12: jsMessagePortPrototypeFunctionDispatchEvent
JSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionDispatchEvent(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
UNUSED_PARAM(args);
if (!thisValue.inherits(&JSMessagePort::s_info))
return throwError(exec, TypeError);
JSMessagePort* castedThisObj = static_cast<JSMessagePort*>(asObject(thisValue));
MessagePort* imp = static_cast<MessagePort*>(castedThisObj->impl());
ExceptionCode ec = 0;
Event* evt = toEvent(args.at(0));
JSC::JSValue result = jsBoolean(imp->dispatchEvent(evt, ec));
setDOMException(exec, ec);
return result;
}
示例13: dispatchEventCallback
static v8::Handle<v8::Value> dispatchEventCallback(const v8::Arguments& args)
{
if (args.Length() < 1)
return throwNotEnoughArgumentsError(args.GetIsolate());
MessagePort* imp = V8MessagePort::toNative(args.Holder());
ExceptionCode ec = 0;
{
V8TRYCATCH(Event*, evt, V8Event::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Event::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
bool result = imp->dispatchEvent(evt, ec);
if (UNLIKELY(ec))
goto fail;
return v8Boolean(result, args.GetIsolate());
}
fail:
return setDOMException(ec, args.GetIsolate());
}
示例14: dispatchEventCallback
static v8::Handle<v8::Value> dispatchEventCallback(const v8::Arguments& args)
{
INC_STATS("DOM.MessagePort.dispatchEvent");
MessagePort* imp = V8MessagePort::toNative(args.Holder());
ExceptionCode ec = 0;
{
EXCEPTION_BLOCK(Event*, evt, V8Event::HasInstance(args[0]) ? V8Event::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0);
bool result = imp->dispatchEvent(evt, ec);
if (UNLIKELY(ec))
goto fail;
return v8Boolean(result);
}
fail:
V8Proxy::setDOMException(ec);
return v8::Handle<v8::Value>();
}
示例15: jsMessagePortPrototypeFunctionRemoveEventListener
EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionRemoveEventListener(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&JSMessagePort::s_info))
return throwVMTypeError(exec);
JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
ASSERT_GC_OBJECT_INHERITS(castedThis, &JSMessagePort::s_info);
MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
if (exec->argumentCount() < 2)
return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
JSValue listener = exec->argument(1);
if (!listener.isObject())
return JSValue::encode(jsUndefined());
imp->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
return JSValue::encode(jsUndefined());
}