RESOLVED DUPLICATE of bug 163247 160926
Merge toNativeArray and toRefPtrNativeArray
https://bugs.webkit.org/show_bug.cgi?id=160926
Summary Merge toNativeArray and toRefPtrNativeArray
Ryosuke Niwa
Reported 2016-08-16 17:32:09 PDT
Merge these two functions to reduce the code duplication.
Attachments
Merges the functions (10.81 KB, patch)
2016-08-16 23:46 PDT, Ryosuke Niwa
no flags
Rebaselined binding tests (38.44 KB, patch)
2016-08-17 14:36 PDT, Ryosuke Niwa
no flags
Updated for ToT (37.04 KB, patch)
2016-08-17 15:48 PDT, Ryosuke Niwa
no flags
Ryosuke Niwa
Comment 1 2016-08-16 23:46:07 PDT
Created attachment 286282 [details] Merges the functions
Ryosuke Niwa
Comment 2 2016-08-17 14:36:45 PDT
Created attachment 286330 [details] Rebaselined binding tests
Ryosuke Niwa
Comment 3 2016-08-17 15:48:06 PDT
Created attachment 286334 [details] Updated for ToT
Sam Weinig
Comment 4 2016-08-17 20:45:37 PDT
I wonder if we can do this without adding separate toWrapped overload for each wrapper type. Instead, maybe do something like: template<> struct JSDOMWrapperConverterTraits<Element> { typedef JSElement WrapperType; }; And then, you could have a single toWrapped in JSDOMBindings.h that looks something like: template<typename NativeType> NativeType* toWrapped(JSC::ExecState& state, JSC::JSValue jsValue) { typedef typename JSDOMWrapperConverterTraits<NativeType>::WrapperType WrapperType; return WrapperType::toWrapped(value) } (As usual, C++ typed into a comment is not guaranteed to work).
Ryosuke Niwa
Comment 5 2016-08-18 13:03:20 PDT
(In reply to comment #4) > I wonder if we can do this without adding separate toWrapped overload for > each wrapper type. Instead, maybe do something like: > > template<> struct JSDOMWrapperConverterTraits<Element> { > typedef JSElement WrapperType; > }; > > And then, you could have a single toWrapped in JSDOMBindings.h that looks > something like: > > template<typename NativeType> > NativeType* toWrapped(JSC::ExecState& state, JSC::JSValue jsValue) > { > typedef typename JSDOMWrapperConverterTraits<NativeType>::WrapperType > WrapperType; > return WrapperType::toWrapped(value) > } > > (As usual, C++ typed into a comment is not guaranteed to work). We’d have to define both WrapperType and NativeType (because some wrappers use RefPtr instead of raw pointer) but sure.
Ryosuke Niwa
Comment 6 2016-08-18 13:07:44 PDT
Actually, no quite because toWrapped takes ExecState in addition to JSValue when JSCustomToNativeObject is set :( We could change it so that it always takes two arguments, or add yet another trait which tells us whether the function takes one or two arguments.
Sam Weinig
Comment 7 2016-08-18 15:26:28 PDT
(In reply to comment #5) > We’d have to define both WrapperType and NativeType (because some wrappers > use RefPtr instead of raw pointer) but sure. Really? Which ones?
Sam Weinig
Comment 8 2016-08-18 15:28:59 PDT
(In reply to comment #6) > Actually, no quite because toWrapped takes ExecState in addition to JSValue > when JSCustomToNativeObject is set :( > > We could change it so that it always takes two arguments, or add yet another > trait which tells us whether the function takes one or two arguments. I think changing toWrapped to always take both makes sense. Having different signatures is really weird here.
Ryosuke Niwa
Comment 9 2016-08-18 22:44:08 PDT
Ugh... a bunch of inspector code relies on the fact JSNode::toWrapped doesn’t require ExecState.
Ryosuke Niwa
Comment 10 2016-08-18 22:52:26 PDT
(In reply to comment #9) > Ugh... a bunch of inspector code relies on the fact JSNode::toWrapped > doesn’t require ExecState. Oh, I can just call jsNodeCast for that.
Ryosuke Niwa
Comment 11 2016-08-18 23:36:06 PDT
Nope :(. SerializedScriptValue also assumes you can call toWrapped without ExecState.
Ryosuke Niwa
Comment 12 2016-08-19 00:01:16 PDT
Actually, getting rid of ExecState is easier. Only two toWrapped functions use ExecState, and they’re probably just written by someone who didn’t understand how toWrapped function is used: RefPtr<DOMStringList> JSDOMStringList::toWrapped(ExecState& state, JSValue value) { if (value.inherits(JSDOMStringList::info())) return &jsCast<JSDOMStringList*>(asObject(value))->wrapped(); if (!isJSArray(value)) return nullptr; JSArray* array = asArray(value); RefPtr<DOMStringList> stringList = DOMStringList::create(); for (unsigned i = 0; i < array->length(); ++i) stringList->append(array->getIndex(&state, i).toString(&state)->value(&state)); return stringList; } RefPtr<XPathNSResolver> JSXPathNSResolver::toWrapped(ExecState& state, JSValue value) { if (value.inherits(JSXPathNSResolver::info())) return &jsCast<JSXPathNSResolver*>(asObject(value))->wrapped(); return JSCustomXPathNSResolver::create(&state, value); }
Ryosuke Niwa
Comment 13 2016-08-19 00:08:35 PDT
Hm... actually, the one for XPathNSResolver was added recently in https://trac.webkit.org/changeset/200550. Chris, why does toWrapped need to call XPathNSResolver::create when the wrapped JSValue isn’t XPathNSResolver?
Ryosuke Niwa
Comment 14 2016-08-31 10:39:36 PDT
Comment on attachment 286334 [details] Updated for ToT I'm gonna also give up on this patch after bug 161030.
Sam Weinig
Comment 15 2016-09-02 13:48:09 PDT
(In reply to comment #14) > Comment on attachment 286334 [details] > Updated for ToT > > I'm gonna also give up on this patch after bug 161030. :(. Re-opening as we really should do this.
Alexey Shvayka
Comment 16 2020-08-07 12:39:33 PDT
to[RefPtr]NativeArray() were merged to Converter<IDLSequence<T>> in r207150. *** This bug has been marked as a duplicate of bug 163247 ***
Note You need to log in before you can comment on or make changes to this bug.