RESOLVED FIXED 94695
[Qt] Port convertValueToQVariant to use the JSC C API
https://bugs.webkit.org/show_bug.cgi?id=94695
Summary [Qt] Port convertValueToQVariant to use the JSC C API
Simon Hausmann
Reported 2012-08-22 05:38:00 PDT
[Qt] Port convertValueToQVariant to use the JSC C API
Attachments
Patch (45.03 KB, patch)
2012-08-22 05:42 PDT, Simon Hausmann
no flags
Patch (45.00 KB, patch)
2012-08-29 04:01 PDT, Simon Hausmann
kenneth: review+
Simon Hausmann
Comment 1 2012-08-22 05:42:44 PDT
Caio Marcelo de Oliveira Filho
Comment 2 2012-08-22 11:37:34 PDT
Comment on attachment 159912 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=159912&action=review > Source/WebCore/bridge/qt/qt_runtime.cpp:224 > + int objdist = 0; Since you are touching this code, could you improve this name? > Source/WebCore/bridge/qt/qt_runtime.cpp:244 > + JSStringRef lengthStr = JSStringCreateWithUTF8CString("length"); "static JSStringRef". And get rid of the release below. > Source/WebCore/bridge/qt/qt_runtime.cpp:452 > + JSStringRef str = JSValueToStringCopy(context, value, exception); > + QChar ch; > + if (str && JSStringGetLength(str) > 0) > + ch = *reinterpret_cast<const QChar*>(JSStringGetCharactersPtr(str)); > + ret = QVariant(ch); > + if (str) > + JSStringRelease(str); Use JSRetainPtr and get rid of the "if (str) JSStringRelease(str);". > Source/WebCore/bridge/qt/qt_runtime.cpp:466 > + JSStringRef str = JSValueToStringCopy(context, value, exception); JSRetainPtr here too, since we are creating a block in the case should be OK. > Source/WebKit/qt/Api/qwebelement.cpp:763 > + return JSC::Bindings::convertValueToQVariant(toRef(state), toRef(state, evaluationResult), QMetaType::Void, &distance, /*exception*/0); Use "JSValueRef* ignoredException = 0;" then pass it on the function. We use else-where to avoid the inline comment.
Simon Hausmann
Comment 3 2012-08-23 00:23:57 PDT
Comment on attachment 159912 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=159912&action=review >> Source/WebKit/qt/Api/qwebelement.cpp:763 >> + return JSC::Bindings::convertValueToQVariant(toRef(state), toRef(state, evaluationResult), QMetaType::Void, &distance, /*exception*/0); > > Use "JSValueRef* ignoredException = 0;" then pass it on the function. We use else-where to avoid the inline comment. What's the advantage of an extra variable on the stack and passing a non-null pointer over the inline comment "ignored exception" ?
Caio Marcelo de Oliveira Filho
Comment 4 2012-08-23 06:39:59 PDT
Comment on attachment 159912 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=159912&action=review >>> Source/WebKit/qt/Api/qwebelement.cpp:763 >>> + return JSC::Bindings::convertValueToQVariant(toRef(state), toRef(state, evaluationResult), QMetaType::Void, &distance, /*exception*/0); >> >> Use "JSValueRef* ignoredException = 0;" then pass it on the function. We use else-where to avoid the inline comment. > > What's the advantage of an extra variable on the stack and passing a non-null pointer over the inline comment "ignored exception" ? It is a null pointer. Effectively it will be the same than passing 0. It's a tradeoff between one more pointer in the stack and a variable name versus having the inline comment. I tend to choose the first option in those cases, but YMMV.
Simon Hausmann
Comment 5 2012-08-29 03:49:21 PDT
Comment on attachment 159912 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=159912&action=review >> Source/WebCore/bridge/qt/qt_runtime.cpp:224 >> + int objdist = 0; > > Since you are touching this code, could you improve this name? Going for propertyConversionDistance :) >> Source/WebCore/bridge/qt/qt_runtime.cpp:244 >> + JSStringRef lengthStr = JSStringCreateWithUTF8CString("length"); > > "static JSStringRef". And get rid of the release below. Done. >> Source/WebCore/bridge/qt/qt_runtime.cpp:452 >> + JSStringRelease(str); > > Use JSRetainPtr and get rid of the "if (str) JSStringRelease(str);". Done. >> Source/WebCore/bridge/qt/qt_runtime.cpp:466 >> + JSStringRef str = JSValueToStringCopy(context, value, exception); > > JSRetainPtr here too, since we are creating a block in the case should be OK. Done. >>>> Source/WebKit/qt/Api/qwebelement.cpp:763 >>>> + return JSC::Bindings::convertValueToQVariant(toRef(state), toRef(state, evaluationResult), QMetaType::Void, &distance, /*exception*/0); >>> >>> Use "JSValueRef* ignoredException = 0;" then pass it on the function. We use else-where to avoid the inline comment. >> >> What's the advantage of an extra variable on the stack and passing a non-null pointer over the inline comment "ignored exception" ? > > It is a null pointer. Effectively it will be the same than passing 0. > > It's a tradeoff between one more pointer in the stack and a variable name versus having the inline comment. I tend to choose the first option in those cases, but YMMV. Ah right, it's actually a null pointer. Okay, I don't care too much about it and am fine with using your pattern.
Simon Hausmann
Comment 6 2012-08-29 04:01:30 PDT
Created attachment 161175 [details] Patch Updated patch to address comments
Caio Marcelo de Oliveira Filho
Comment 7 2012-08-30 06:02:21 PDT
LGTM.
Kenneth Rohde Christiansen
Comment 8 2012-08-30 06:06:39 PDT
Comment on attachment 161175 [details] Patch r=me given caio's comments
Simon Hausmann
Comment 9 2012-08-31 02:03:01 PDT
Note You need to log in before you can comment on or make changes to this bug.