<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Initial implementation of JavaScriptCore glib bindings"
   href="https://bugs.webkit.org/show_bug.cgi?id=164061">bug 164061</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
               &nbsp;
           </td>
           <td>cgarcia&#64;igalia.com
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Initial implementation of JavaScriptCore glib bindings"
   href="https://bugs.webkit.org/show_bug.cgi?id=164061#c12">Comment # 12</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Initial implementation of JavaScriptCore glib bindings"
   href="https://bugs.webkit.org/show_bug.cgi?id=164061">bug 164061</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=164061#c11">comment #11</a>)
<span class="quote">&gt; Comment on <span class=""><a href="attachment.cgi?id=294417&amp;action=diff" name="attach_294417" title="Patch">attachment 294417</a> <a href="attachment.cgi?id=294417&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=294417&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=294417&amp;action=review</a>
&gt; 
&gt; &gt;&gt; Source/JavaScriptCore/API/glib/JSCContext.cpp:125
&gt; &gt;&gt; +        return nullptr;
&gt; &gt; 
&gt; &gt; I'm not sure if we will need a null value implementation too. In any case, you are handling here the null value, but null is not allowed in jsc_context_set_value
&gt; 
&gt; Yes.. I thought about that too... Would it be too ugly if we accept nullptr
&gt; as a valid input for jsc_context_set_value and create the null JSValue
&gt; internally? :P
&gt; Nah... I think a JSCNull will be better...</span >

I'm not sure, TBH. Maybe at some point we need to distinguish between a function returning nullptr to express an error and returning nullptr as a the JavaScript null value. So, I don't know, maybe we can start using nullptr and add the object later of needed to make things easier.

<span class="quote">&gt; &gt;&gt; Source/JavaScriptCore/API/glib/JSCContext.cpp:165
&gt; &gt;&gt; +    }
&gt; &gt; 
&gt; &gt; This is not how we want to cache the values, I think. We should cache all wrapped values, not only the ones added to the global object. As I said in a previous review, let's forget about objects lifecycle for now, do not cache anything, to make this simpler, and then we can discuss, design and implement the way we want to handle objects lifecycle.
&gt; 
&gt; Agreed. Will postpone that and change all the tests to unref every value
&gt; (*ouch*) ;)</span >

Don't worry too much about leaking in the tests for now, we will fix everything eventually once we have the liefcycle management implemented.

<span class="quote">&gt; I see 2 ways of caching every value: 
&gt; 1) we can make JSCContext a factory of values or 
&gt; 2) we can make add a privte jscContextCacheValue and call it on constructed
&gt; of JSCValue...</span >

Not easy for me to give an opinion about this, because I don't fully understand how to the wrapped api objects and internal objects work in JavaScriptCore. We need to understand how things work in JSC to make a decision.

<span class="quote">&gt; Just don't know what will be the best structure to hold those values... is
&gt; that a good practice to use JSValueRef as the key of the hashmap?</span >

I think so.

<span class="quote">&gt; I did some tests and found out the following:
&gt; when you create a JSValueRef, set it in the global object and retrieve it
&gt; back, it points to the same structure.
&gt; If you evaluate a script to change the value, the retrieved JSValueRef is
&gt; differrent from the set one. A new value is created. This logic allows us
&gt; use JSValueRef as the hashmap key, but I'm not sure if it's a good
&gt; practice...
&gt; 
&gt; &gt;&gt; Source/JavaScriptCore/API/glib/JSCContext.cpp:189
&gt; &gt;&gt; +    JSObjectSetProperty(priv-&gt;context.get(), object, strName.get(), jsValue, kJSPropertyAttributeReadOnly, nullptr);
&gt; &gt; 
&gt; &gt; Why kJSPropertyAttributeReadOnly? That means we can call this twice for the same name to update the value.
&gt; 
&gt; No valid reason for this. Already changed to kJSPropertyAttributeNone. :P
&gt; 
&gt; I think that we'll need a way to change that parameter though... Some use
&gt; cases may not want JavaScript to change a value or delete it... I think we
&gt; can add another parameter to jsc_context_set_value or maybe to JSCValue.
&gt; 
&gt; I think that adding this info to JSCValue will be better, because we can
&gt; still use the same jsc_context_set_value to expose callbacks and full
&gt; objects. Depending on the type, we retrieve different properties and use
&gt; them internally.</span >

I'm not sure, this is just a convenient way to expose a value to the global object, if you need to do anything special, I guess you will be able to evaluate (const foo = 'bar') to make it const, no?

<span class="quote">&gt; &gt;&gt; Source/JavaScriptCore/API/glib/JSCPrivate.h:22
&gt; &gt;&gt; +#define WEBKIT_DEFINE_SIMPLE_TYPE(TypeName, type_name, TYPE_PARENT) \
&gt; &gt; 
&gt; &gt; Why is this needed? What's different compared to G_DEFINE_TYPE?
&gt; 
&gt; It's just to explicitly remove type_name_init and type_name_class_init from
&gt; cpp files in subtypes and avoid style-checker issues. if that's not a
&gt; problem, I'll switch back to G_DEFINE_TYPE.</span >

It's not a problem.

<span class="quote">&gt; &gt;&gt; Source/JavaScriptCore/API/glib/JSCString.cpp:97
&gt; &gt;&gt; +    return g_strdup(&quot;the string value&quot;);
&gt; &gt; 
&gt; &gt; What? I guess this should be return buff
&gt; 
&gt; Of course it is! I was testing something and forgot about that. Sorry! :P</span >

:-)

<span class="quote">&gt; &gt;&gt; Source/JavaScriptCore/API/glib/JSCValue.cpp:79
&gt; &gt;&gt; +        g_object_add_weak_pointer(G_OBJECT(context), (gpointer*)&amp;priv-&gt;context);
&gt; &gt; 
&gt; &gt; Use C++ style cast. I'm not sure I understand this weak pointer, since we only null check the context in dispose method. I think the context should never be released if it still contains values, so values should take a reference to the context.
&gt; 
&gt; Hrm... if we do this, we won't be able to simply g_object_unref the context.
&gt; We'll need to add an API to clear the values before unreffing the context,
&gt; so that it will be correctly destroyed. That's why I used a weak ref...</span >

The thing is that the C API works that way in any case, I think. Protected JSValues prevent the context from being destroyed by the garbage collector. So, the values have a strong reference to the context anyway internally.

<span class="quote">&gt; And I got an error when using static_cast here...
&gt; 
&gt; &gt;&gt; Source/JavaScriptCore/PlatformGTK.cmake:52
&gt; &gt;&gt; +if (ENABLE_JSC_GLIB)
&gt; &gt; 
&gt; &gt; As I said in my previous review: I don't think we should make this conditional. It doesn't add any new dependency and the api should always be available.
&gt; 
&gt; I'm just afraid of breaking things up :P</span >

For now, it's enough with not installing the headers, the symbols won't be exposed in production builds anyway, until we use JSC_API like macro in the headers.

<span class="quote">&gt; &gt;&gt; Tools/TestWebKitAPI/JavaScriptCoreGlib/main.cpp:26
&gt; &gt;&gt; +#include &quot;Tests/JavaScriptCoreGlib/TestJSCUndefined.h&quot;
&gt; &gt; 
&gt; &gt; The main should be in Tests/JavaScriptCoreGlib/ too. Do not add a file for every test case, move them all here to the same file and rename this as TestJSCValue for example
&gt; 
&gt; I can do that. But I followed gtk:
&gt; 
&gt; Tools/TestWebKitAPI/gtk/main.cpp
&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/</span >

Not really. In GTK+ we have a &quot;library&quot; with support classes shared by the tests. Those are in Tools/TestWebKitAPI/gtk/WebKit2Gtk/ because they are not tests themselves. Tools/TestWebKitAPI/gtk/main.cpp is the common main used by the google tests based tests. In our case we are not adding tests helper classes, but for now only tests, so they should go to Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/

<span class="quote">&gt; And I splited the files for readability... but I'll merge them.</span >

We split &quot;test suites&quot; in files, with all the tests cases of the suite in the same file.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>