⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277199 in webkit


Ignore:
Timestamp:
May 7, 2021, 2:32:50 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

IPC testing API should have the ability to create and receive IPC::Semaphore
​https://bugs.webkit.org/show_bug.cgi?id=225537

Reviewed by Wenson Hsieh.

Source/WebKit:

This patch adds the capability to create IPC::Semaphore for IPC testing purposes.
It adds IPC.createSemaphore which creates a JavaScript object representing a semaphore
with signal and waitFor methods like IPC::Semaphore but waitFor taking milliseconds
to be consistent with other JavaScript APIs.

This patch also adds the support for encoding RemoteRenderingBackendCreationParameters
to facilitate creating a remote rendering backend during IPC testing.

Tests: TestWebKitAPI.IPCTestingAPI.CanReceiveIPCSemaphore

TestWebKitAPI.IPCTestingAPI.CanCreateIPCSemaphore

  • Platform/IPC/JSIPCBinding.cpp:

(IPC::jsValueForDecodedArgumentValue): Takes r-value reference since IPC::Semaphore
doesn't have a copy constructor.

  • Platform/IPC/JSIPCBinding.h:

(IPC::jsValueForDecodedArgumentValue): Ditto. Added a specialization for IPC::Semaphore.
(IPC::putJSValueForDecodeArgumentInArray):

  • WebProcess/WebPage/IPCTestingAPI.cpp:

(WebKit::IPCTestingAPI::JSIPCSemaphore): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::create): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::exchange): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::JSIPCSemaphore): Added.
(WebKit::IPCTestingAPI::createTypeError): Moved up.
(WebKit::IPCTestingAPI::JSIPCSemaphore::createJSWrapper): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::wrapperClass): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::unwrap): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::toWrapped): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::initialize): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::finalize): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::staticFunctions): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::signal): Added.
(WebKit::IPCTestingAPI::JSIPCSemaphore::waitFor): Added.
(WebKit::IPCTestingAPI::JSIPC::wrapperClass):
(WebKit::IPCTestingAPI::JSIPC::staticFunctions): Added IPC.createSemaphore.
(WebKit::IPCTestingAPI::getObjectIdentifierFromProperty): Added.
(WebKit::IPCTestingAPI::encodeRemoteRenderingBackendCreationParameters): Added.
(WebKit::IPCTestingAPI::encodeArgument): Added the support for encoding
RemoteRenderingBackendCreationParameters as an IPC argument.
(WebKit::IPCTestingAPI::JSIPC::createSemaphore): Added.
(IPC::jsValueForDecodedArgumentValue): Defined the aforementioned specialization for
IPC::Semaphore with IPCTestingAPI .

Tools:

Added tests to make sure IPC testing API allows creation of a semaphore,
and receiving one as a reply to an IPC message.

  • TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:

(IPCTestingAPI.CanReceiveIPCSemaphore): Added.
(IPCTestingAPI.CanCreateIPCSemaphore): Added.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r277196 r277199  
     12021-05-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        IPC testing API should have the ability to create and receive IPC::Semaphore
     4        https://bugs.webkit.org/show_bug.cgi?id=225537
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        This patch adds the capability to create IPC::Semaphore for IPC testing purposes.
     9        It adds IPC.createSemaphore which creates a JavaScript object representing a semaphore
     10        with signal and waitFor methods like IPC::Semaphore but waitFor taking milliseconds
     11        to be consistent with other JavaScript APIs.
     12
     13        This patch also adds the support for encoding RemoteRenderingBackendCreationParameters
     14        to facilitate creating a remote rendering backend during IPC testing.
     15
     16        Tests: TestWebKitAPI.IPCTestingAPI.CanReceiveIPCSemaphore
     17               TestWebKitAPI.IPCTestingAPI.CanCreateIPCSemaphore
     18
     19        * Platform/IPC/JSIPCBinding.cpp:
     20        (IPC::jsValueForDecodedArgumentValue): Takes r-value reference since IPC::Semaphore
     21        doesn't have a copy constructor.
     22        * Platform/IPC/JSIPCBinding.h:
     23        (IPC::jsValueForDecodedArgumentValue): Ditto. Added a specialization for IPC::Semaphore.
     24        (IPC::putJSValueForDecodeArgumentInArray):
     25        * WebProcess/WebPage/IPCTestingAPI.cpp:
     26        (WebKit::IPCTestingAPI::JSIPCSemaphore): Added.
     27        (WebKit::IPCTestingAPI::JSIPCSemaphore::create): Added.
     28        (WebKit::IPCTestingAPI::JSIPCSemaphore::exchange): Added.
     29        (WebKit::IPCTestingAPI::JSIPCSemaphore::JSIPCSemaphore): Added.
     30        (WebKit::IPCTestingAPI::createTypeError): Moved up.
     31        (WebKit::IPCTestingAPI::JSIPCSemaphore::createJSWrapper): Added.
     32        (WebKit::IPCTestingAPI::JSIPCSemaphore::wrapperClass): Added.
     33        (WebKit::IPCTestingAPI::JSIPCSemaphore::unwrap): Added.
     34        (WebKit::IPCTestingAPI::JSIPCSemaphore::toWrapped): Added.
     35        (WebKit::IPCTestingAPI::JSIPCSemaphore::initialize): Added.
     36        (WebKit::IPCTestingAPI::JSIPCSemaphore::finalize): Added.
     37        (WebKit::IPCTestingAPI::JSIPCSemaphore::staticFunctions): Added.
     38        (WebKit::IPCTestingAPI::JSIPCSemaphore::signal): Added.
     39        (WebKit::IPCTestingAPI::JSIPCSemaphore::waitFor): Added.
     40        (WebKit::IPCTestingAPI::JSIPC::wrapperClass):
     41        (WebKit::IPCTestingAPI::JSIPC::staticFunctions): Added IPC.createSemaphore.
     42        (WebKit::IPCTestingAPI::getObjectIdentifierFromProperty): Added.
     43        (WebKit::IPCTestingAPI::encodeRemoteRenderingBackendCreationParameters): Added.
     44        (WebKit::IPCTestingAPI::encodeArgument): Added the support for encoding
     45        RemoteRenderingBackendCreationParameters as an IPC argument.
     46        (WebKit::IPCTestingAPI::JSIPC::createSemaphore): Added.
     47        (IPC::jsValueForDecodedArgumentValue): Defined the aforementioned specialization for
     48        IPC::Semaphore with IPCTestingAPI .
     49
    1502021-05-07  Wenson Hsieh  <wenson_hsieh@apple.com>
    251
  • trunk/Source/WebKit/Platform/IPC/JSIPCBinding.cpp

    r273058 r277199  
    5252
    5353template<>
    54 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const String& value)
     54JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, String&& value)
    5555{
    5656    return jsValueForDecodedStringArgumentValue(globalObject, value, "String"_s);
    … …  
    5858
    5959template<>
    60 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const URL& value)
     60JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, URL&& value)
    6161{
    6262    return jsValueForDecodedStringArgumentValue(globalObject, value.string(), "URL"_s);
    … …  
    6464
    6565template<>
    66 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const WebCore::RegistrableDomain& value)
     66JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, WebCore::RegistrableDomain&& value)
    6767{
    6868    return jsValueForDecodedStringArgumentValue(globalObject, value.string(), "RegistrableDomain"_s);
    … …  
    184184
    185185template<>
    186 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const WebCore::IntRect& value)
     186JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, WebCore::IntRect&& value)
    187187{
    188188    return jsValueForDecodedArgumentRect(globalObject, value, "IntRect");
    … …  
    190190
    191191template<>
    192 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const WebCore::FloatRect& value)
     192JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, WebCore::FloatRect&& value)
    193193{
    194194    return jsValueForDecodedArgumentRect(globalObject, value, "FloatRect");
  • trunk/Source/WebKit/Platform/IPC/JSIPCBinding.h

    r272592 r277199  
    5454namespace IPC {
    5555
     56class Semaphore;
     57
    5658template<typename T, std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_enum<T>::value>* = nullptr>
    57 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, const T&)
     59JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, T&&)
    5860{
    5961    return JSC::jsUndefined();
    6062}
    6163
    62 template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, const String&);
    63 template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, const URL&);
    64 template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, const WebCore::RegistrableDomain&);
     64template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, String&&);
     65template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, URL&&);
     66template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, WebCore::RegistrableDomain&&);
     67
     68template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, IPC::Semaphore&&);
    6569
    6670template<typename T, std::enable_if_t<std::is_arithmetic<T>::value>* = nullptr>
    … …  
    9094
    9195template<typename U>
    92 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const ObjectIdentifier<U>& value)
     96JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, ObjectIdentifier<U>&& value)
    9397{
    9498    return jsValueForDecodedArgumentValue(globalObject, value.toUInt64());
    9599}
    96100
    97 template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, const WebCore::IntRect&);
    98 template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, const WebCore::FloatRect&);
     101template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, WebCore::IntRect&&);
     102template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, WebCore::FloatRect&&);
    99103
    100104template<typename U>
    101 JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, const OptionSet<U>& value)
     105JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, OptionSet<U>&& value)
    102106{   
    103107    auto& vm = globalObject->vm();
    … …  
    130134        return WTF::nullopt;
    131135
    132     auto jsValue = jsValueForDecodedArgumentValue(globalObject, *value);
     136    auto jsValue = jsValueForDecodedArgumentValue(globalObject, WTFMove(*value));
    133137    if (jsValue.isEmpty())
    134138        return jsValue;
  • trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp

    r276678 r277199  
    3232#include "FrameInfoData.h"
    3333#include "GPUProcessConnection.h"
     34#include "IPCSemaphore.h"
     35#include "JSIPCBinding.h"
    3436#include "MessageArgumentDescriptions.h"
    3537#include "NetworkProcessConnection.h"
     38#include "RemoteRenderingBackendCreationParameters.h"
    3639#include "WebCoreArgumentCoders.h"
    3740#include "WebFrame.h"
    … …  
    5154#include <WebCore/RegistrableDomain.h>
    5255#include <WebCore/ScriptController.h>
     56#include <wtf/PageBlock.h>
    5357
    5458namespace WebKit {
    5559
    5660namespace IPCTestingAPI {
     61
     62class JSIPCSemaphore : public RefCounted<JSIPCSemaphore> {
     63public:
     64    static Ref<JSIPCSemaphore> create(IPC::Semaphore&& semaphore = { })
     65    {
     66        return adoptRef(*new JSIPCSemaphore(WTFMove(semaphore)));
     67    }
     68
     69    JSObjectRef createJSWrapper(JSContextRef);
     70
     71    static JSIPCSemaphore* toWrapped(JSContextRef, JSValueRef);
     72
     73    IPC::Semaphore exchange(IPC::Semaphore&& semaphore = { })
     74    {
     75        return std::exchange(m_semaphore, WTFMove(semaphore));
     76    }
     77
     78private:
     79    JSIPCSemaphore(IPC::Semaphore&& semaphore)
     80        : m_semaphore(WTFMove(semaphore))
     81    { }
     82
     83    static JSClassRef wrapperClass();
     84    static JSIPCSemaphore* unwrap(JSObjectRef);
     85    static void initialize(JSContextRef, JSObjectRef);
     86    static void finalize(JSObjectRef);
     87
     88    static const JSStaticFunction* staticFunctions();
     89
     90    static JSValueRef signal(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
     91    static JSValueRef waitFor(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
     92
     93    IPC::Semaphore m_semaphore;
     94};
    5795
    5896class JSIPC;
    … …  
    107145    static JSValueRef sendSyncMessage(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    108146
     147    static JSValueRef createSemaphore(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
     148
    109149    static JSValueRef visitedLinkStoreID(JSContextRef, JSObjectRef, JSStringRef, JSValueRef* exception);
    110150    static JSValueRef webPageProxyID(JSContextRef, JSObjectRef, JSStringRef, JSValueRef* exception);
    … …  
    121161};
    122162
     163static JSValueRef createTypeError(JSContextRef context, const String& message)
     164{
     165    JSC::JSLockHolder lock(toJS(context)->vm());
     166    return toRef(JSC::createTypeError(toJS(context), message));
     167}
     168
     169JSObjectRef JSIPCSemaphore::createJSWrapper(JSContextRef context)
     170{
     171    auto* globalObject = toJS(context);
     172    auto& vm = globalObject->vm();
     173    JSC::JSLockHolder lock(vm);
     174    auto scope = DECLARE_CATCH_SCOPE(vm);
     175    JSObjectRef wrapperObject = JSObjectMake(toGlobalRef(globalObject), wrapperClass(), this);
     176    scope.clearException();
     177    return wrapperObject;
     178}
     179
     180JSClassRef JSIPCSemaphore::wrapperClass()
     181{
     182    static JSClassRef jsClass;
     183    if (!jsClass) {
     184        JSClassDefinition definition = kJSClassDefinitionEmpty;
     185        definition.className = "Semaphore";
     186        definition.parentClass = nullptr;
     187        definition.staticValues = nullptr;
     188        definition.staticFunctions = staticFunctions();
     189        definition.initialize = initialize;
     190        definition.finalize = finalize;
     191        jsClass = JSClassCreate(&definition);
     192    }
     193    return jsClass;
     194}
     195
     196inline JSIPCSemaphore* JSIPCSemaphore::unwrap(JSObjectRef object)
     197{
     198    return static_cast<JSIPCSemaphore*>(JSObjectGetPrivate(object));
     199}
     200
     201JSIPCSemaphore* JSIPCSemaphore::toWrapped(JSContextRef context, JSValueRef value)
     202{
     203    if (!context || !value || !JSValueIsObjectOfClass(context, value, wrapperClass()))
     204        return nullptr;
     205    return unwrap(JSValueToObject(context, value, 0));
     206}
     207
     208void JSIPCSemaphore::initialize(JSContextRef, JSObjectRef object)
     209{
     210    unwrap(object)->ref();
     211}
     212
     213void JSIPCSemaphore::finalize(JSObjectRef object)
     214{
     215    unwrap(object)->deref();
     216}
     217
     218const JSStaticFunction* JSIPCSemaphore::staticFunctions()
     219{
     220    static const JSStaticFunction functions[] = {
     221        { "signal", signal, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
     222        { "waitFor", waitFor, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
     223        { 0, 0, 0 }
     224    };
     225    return functions;
     226}
     227
     228JSValueRef JSIPCSemaphore::signal(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     229{
     230    auto* globalObject = toJS(context);
     231    JSC::JSLockHolder lock(globalObject->vm());
     232    auto isIPCSemaphore = makeRefPtr(toWrapped(context, thisObject));
     233    if (!isIPCSemaphore) {
     234        *exception = createTypeError(context, "Wrong type"_s);
     235        return JSValueMakeUndefined(context);
     236    }
     237
     238    isIPCSemaphore->m_semaphore.signal();
     239
     240    return JSValueMakeUndefined(context);
     241}
     242
     243JSValueRef JSIPCSemaphore::waitFor(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     244{
     245    auto* globalObject = toJS(context);
     246    JSC::JSLockHolder lock(globalObject->vm());
     247    auto isIPCSemaphore = makeRefPtr(toWrapped(context, thisObject));
     248    if (!isIPCSemaphore) {
     249        *exception = createTypeError(context, "Wrong type"_s);
     250        return JSValueMakeUndefined(context);
     251    }
     252
     253    if (argumentCount < 1) {
     254        *exception = createTypeError(context, "Must specify the timeout in milliseconds as the first argument"_s);
     255        return JSValueMakeUndefined(context);
     256    }
     257
     258    auto jsValue = toJS(globalObject, arguments[0]);
     259    Seconds timeout;
     260    if (jsValue.isNumber()) {
     261        double milliseconds = jsValue.asNumber();
     262        if (std::isfinite(milliseconds) && milliseconds > 0)
     263            timeout = Seconds::fromMilliseconds(milliseconds);
     264    }
     265    if (!timeout) {
     266        *exception = createTypeError(context, "Timeout must be a positive number"_s);
     267        return JSValueMakeUndefined(context);
     268    }
     269
     270    auto result = isIPCSemaphore->m_semaphore.waitFor(timeout);
     271
     272    return JSValueMakeBoolean(context, result);
     273}
     274
    123275JSClassRef JSIPC::wrapperClass()
    124276{
    … …  
    127279        JSClassDefinition definition = kJSClassDefinitionEmpty;
    128280        definition.className = "IPC";
    129         definition.parentClass = 0;
     281        definition.parentClass = nullptr;
    130282        definition.staticValues = staticValues();
    131283        definition.staticFunctions = staticFunctions();
    … …  
    166318        { "sendMessage", sendMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
    167319        { "sendSyncMessage", sendSyncMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
     320        { "createSemaphore", createSemaphore, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
    168321        { 0, 0, 0 }
    169322    };
    … …  
    198351}
    199352
    200 static JSValueRef createTypeError(JSContextRef context, const String& message)
    201 {
    202     JSC::JSLockHolder lock(toJS(context)->vm());
    203     return toRef(JSC::createTypeError(toJS(context), message));
    204 }
    205 
    206353static RefPtr<IPC::Connection> processTargetFromArgument(JSC::JSGlobalObject* globalObject, JSValueRef valueRef, JSValueRef* exception)
    207354{
    … …  
    364511}
    365512
     513#if ENABLE(GPU_PROCESS)
     514template <typename ObjectIdentifierType>
     515Optional<ObjectIdentifier<ObjectIdentifierType>> getObjectIdentifierFromProperty(JSC::JSGlobalObject* globalObject, JSC::JSObject* jsObject, ASCIILiteral propertyName, JSC::CatchScope& scope)
     516{
     517    auto jsPropertyValue = jsObject->get(globalObject, JSC::Identifier::fromString(globalObject->vm(), propertyName));
     518    if (scope.exception())
     519        return WTF::nullopt;
     520    if (jsPropertyValue.isBigInt())
     521        return makeObjectIdentifier<ObjectIdentifierType>(JSC::JSBigInt::toBigUInt64(jsPropertyValue));
     522    if (jsPropertyValue.isNumber())
     523        return makeObjectIdentifier<ObjectIdentifierType>(jsPropertyValue.asNumber());
     524    return WTF::nullopt;
     525}
     526
     527static bool encodeRemoteRenderingBackendCreationParameters(IPC::Encoder& encoder, JSC::JSGlobalObject* globalObject, JSC::JSObject* jsObject, JSC::CatchScope& scope)
     528{
     529    auto identifier = getObjectIdentifierFromProperty<RenderingBackendIdentifierType>(globalObject, jsObject, "identifier"_s, scope);
     530    if (!identifier)
     531        return false;
     532
     533    auto jsSemaphore = jsObject->get(globalObject, JSC::Identifier::fromString(globalObject->vm(), "semaphore"_s));
     534    if (scope.exception())
     535        return false;
     536    auto semaphoreObject = makeRefPtr(JSIPCSemaphore::toWrapped(toRef(globalObject), toRef(jsSemaphore)));
     537    if (!semaphoreObject)
     538        return false;
     539
     540    auto pageProxyID = getObjectIdentifierFromProperty<WebPageProxyIdentifierType>(globalObject, jsObject, "pageProxyID"_s, scope);
     541    if (!pageProxyID)
     542        return false;
     543
     544    auto pageID = getObjectIdentifierFromProperty<WebCore::PageIdentifierType>(globalObject, jsObject, "pageID"_s, scope);
     545    if (!pageID)
     546        return false;
     547
     548    auto semaphore = semaphoreObject->exchange();
     549    RemoteRenderingBackendCreationParameters parameters { *identifier, WTFMove(semaphore), *pageProxyID, *pageID };
     550    encoder << parameters;
     551    semaphoreObject->exchange(WTFMove(parameters.resumeDisplayListSemaphore));
     552    return true;
     553}
     554#endif
     555
    366556static bool encodeArgument(IPC::Encoder&, JSIPC&, JSContextRef, JSValueRef, JSValueRef* exception);
    367557
    … …  
    475665        return true;
    476666    }
     667
     668#if ENABLE(GPU_PROCESS)
     669    if (type == "RemoteRenderingBackendCreationParameters") {
     670        if (!encodeRemoteRenderingBackendCreationParameters(encoder, globalObject, jsObject, scope)) {
     671            *exception = createTypeError(context, "Failed to convert RemoteRenderingBackendCreationParameters"_s);
     672            return false;
     673        }
     674        return true;
     675    }
     676#endif
    477677
    478678    if (type == "FrameInfoData") {
    … …  
    761961}
    762962
     963JSValueRef JSIPC::createSemaphore(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     964{
     965    return JSIPCSemaphore::create()->createJSWrapper(context);
     966}
     967
    763968JSValueRef JSIPC::visitedLinkStoreID(JSContextRef context, JSObjectRef thisObject, JSStringRef, JSValueRef* exception)
    764969{
    … …  
    10181223} // namespace WebKit
    10191224
     1225namespace IPC {
     1226
     1227template<>
     1228JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, IPC::Semaphore&& value)
     1229{
     1230    auto& vm = globalObject->vm();
     1231    auto scope = DECLARE_THROW_SCOPE(vm);
     1232    auto* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype());
     1233    RETURN_IF_EXCEPTION(scope, JSC::JSValue());
     1234    object->putDirect(vm, JSC::Identifier::fromString(vm, "type"_s), JSC::jsNontrivialString(vm, "Semaphore"));
     1235    RETURN_IF_EXCEPTION(scope, JSC::JSValue());
     1236    auto jsValue = toJS(globalObject, WebKit::IPCTestingAPI::JSIPCSemaphore::create(WTFMove(value))->createJSWrapper(toRef(globalObject)));
     1237    object->putDirect(vm, JSC::Identifier::fromString(vm, "value"_s), jsValue);
     1238    RETURN_IF_EXCEPTION(scope, JSC::JSValue());
     1239    return object;
     1240}
     1241
     1242} // namespace IPC
     1243
    10201244#endif
  • trunk/Tools/ChangeLog

    r277180 r277199  
     12021-05-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        IPC testing API should have the ability to create and receive IPC::Semaphore
     4        https://bugs.webkit.org/show_bug.cgi?id=225537
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Added tests to make sure IPC testing API allows creation of a semaphore,
     9        and receiving one as a reply to an IPC message.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
     12        (IPCTestingAPI.CanReceiveIPCSemaphore): Added.
     13        (IPCTestingAPI.CanCreateIPCSemaphore): Added.
     14
    1152021-05-07  Aakash Jain  <aakash_jain@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm

    r276733 r277199  
    210210    EXPECT_FALSE([webView stringByEvaluatingJavaScript:@"result.arguments[0].value"].boolValue);
    211211}
     212
     213TEST(IPCTestingAPI, CanReceiveIPCSemaphore)
     214{
     215    auto webView = createWebViewWithIPCTestingAPI();
     216
     217    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     218    [webView setUIDelegate:delegate.get()];
     219
     220    done = false;
     221    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>"
     222        "const semaphore = IPC.createSemaphore();"
     223        "IPC.sendMessage('GPU', 0, IPC.messages.GPUConnectionToWebProcess_CreateRenderingBackend.name,"
     224        "    [{type: 'RemoteRenderingBackendCreationParameters', 'identifier': 123, semaphore, 'pageProxyID': IPC.webPageProxyID, 'pageID': IPC.pageID}]);"
     225        "const result = IPC.sendSyncMessage('GPU', 123, IPC.messages.RemoteRenderingBackend_SemaphoreForGetImageData.name, 100, []);"
     226        "semaphore.signal();"
     227        "alert(result.arguments.length + ':' + result.arguments[0].type + ':' + result.arguments[0].value.waitFor(100));"
     228        "</script>"];
     229    TestWebKitAPI::Util::run(&done);
     230
     231    EXPECT_STREQ([alertMessage UTF8String], "1:Semaphore:false");
     232}
    212233#endif
     234
     235TEST(IPCTestingAPI, CanCreateIPCSemaphore)
     236{
     237    auto webView = createWebViewWithIPCTestingAPI();
     238
     239    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     240    [webView setUIDelegate:delegate.get()];
     241
     242    done = false;
     243    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>alert(IPC.createSemaphore().waitFor(100));</script>"];
     244    TestWebKitAPI::Util::run(&done);
     245
     246    EXPECT_FALSE([alertMessage boolValue]);
     247}
    213248
    214249TEST(IPCTestingAPI, DecodesReplyArgumentsForPrompt)
Note: See TracChangeset for help on using the changeset viewer.