Bug 43216

Summary: Script engine agnostic ScriptCallback class
Product: WebKit Reporter: Luiz Agostini <luiz>
Component: WebCore JavaScriptAssignee: Luiz Agostini <luiz>
Status: RESOLVED FIXED    
Severity: Normal CC: cmarcelo, commit-queue, darin, dglazkov, kenneth, oliver, sam, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 37205    
Attachments:
Description Flags
patch 1
none
patch 2
none
patch 3
none
patch 4
darin: review-
patch
oliver: review-
patch none

Luiz Agostini
Reported 2010-07-29 15:14:31 PDT
The objective is to this kind of code to be script engine agnostic: void doSomething(ScriptState* exec, ScriptValue function, bool p1, int p2, ...) { ScriptCallback callback(exec, function); callback.appendArgument(p1); callback.appendArgument(p2); callback.call(); }
Attachments
patch 1 (deleted)
2010-07-29 15:22 PDT, Luiz Agostini
no flags
patch 2 (16.66 KB, patch)
2010-07-29 15:35 PDT, Luiz Agostini
no flags
patch 3 (16.73 KB, patch)
2010-07-30 16:55 PDT, Luiz Agostini
no flags
patch 4 (16.69 KB, patch)
2010-08-06 14:31 PDT, Luiz Agostini
darin: review-
patch (15.95 KB, patch)
2010-09-17 12:40 PDT, Luiz Agostini
oliver: review-
patch (16.15 KB, patch)
2010-09-22 12:01 PDT, Luiz Agostini
no flags
Luiz Agostini
Comment 1 2010-07-29 15:22:28 PDT
Created attachment 62997 [details] patch 1
WebKit Review Bot
Comment 2 2010-07-29 15:29:15 PDT
Luiz Agostini
Comment 3 2010-07-29 15:35:26 PDT
Created attachment 63001 [details] patch 2
WebKit Review Bot
Comment 4 2010-07-29 16:31:10 PDT
Luiz Agostini
Comment 5 2010-07-30 16:55:51 PDT
Created attachment 63126 [details] patch 3
WebKit Review Bot
Comment 6 2010-07-30 18:35:29 PDT
Luiz Agostini
Comment 7 2010-08-06 14:31:10 PDT
Created attachment 63760 [details] patch 4
Luiz Agostini
Comment 8 2010-08-09 15:51:23 PDT
Bug 37205 needs a callback class. I could have an abstract class and two concrete classes for javascript, a JS and a V8 classes. Looking at file ScriptFunctionCall I have seen that it was almost what I needed to have a common class for JS and V8. This patch just does a small refactoring of class ScriptFunctionCall and implements the new callback class using NodeFilterCondition implementation as example (JS and V8). Any comments?
Kenneth Rohde Christiansen
Comment 9 2010-08-14 01:44:56 PDT
This looks OK with me. Sam, Oliver, can you have a quick look?
Luiz Agostini
Comment 10 2010-08-16 22:15:13 PDT
Comment on attachment 63760 [details] patch 4 It seems that this patch will not be usefull for bug 37205 as I thought it would at first. I will remove the review flag for now and will close the bug later, together with bug 37205.
Darin Adler
Comment 11 2010-09-16 10:43:37 PDT
Comment on attachment 63760 [details] patch 4 View in context: https://bugs.webkit.org/attachment.cgi?id=63760&action=prettypatch Seems like more of this code could be shared between the V8 and non-V8 versions. A lot of the changes are identical to both, which indicates we have the factoring wrong > WebCore/bindings/js/ScriptFunctionCall.cpp:201 > +ScriptCallback::ScriptCallback(ScriptState* exec, ScriptValue function) > + : ScriptCallArgumentHandler(exec) I would name this argument “state” rather than “exec”. > WebCore/bindings/js/ScriptFunctionCall.cpp:208 > + bool hadException = false; It does not seem necessary to initialize this boolean. > WebCore/bindings/js/ScriptFunctionCall.h:52 > + ScriptCallArgumentHandler(ScriptState* exec) : m_exec(exec) {} > + virtual ~ScriptCallArgumentHandler() {}; The argument should be named “state”, not “exec”. The braces should have a single space between them (WebKit codings style). Not something you introduced, but there is no reason for this class to have a virtual destructor. It has no other virtual functions, and adding a virtual destructor will make the object larger and not offer other benefits. I suggest not declaring the destructor at all. > WebCore/bindings/js/ScriptFunctionCall.h:76 > + virtual ~ScriptFunctionCall() {}; There’s no reason for this class to have a virtual destructor. > WebCore/bindings/js/ScriptFunctionCall.h:94 > + ScriptCallback(ScriptState* exec, ScriptValue function); There’s no need to name the ScriptState argument at all. Here. review- because I’d really like to see those needless virtual destructors removed, but the patch seems otherwise good
Luiz Agostini
Comment 12 2010-09-17 12:40:01 PDT
Luiz Agostini
Comment 13 2010-09-20 11:08:14 PDT
this latest patch is equal to previous one except by the virtual destructors that have been removed.
Luiz Agostini
Comment 14 2010-09-21 10:32:14 PDT
Darin, is there anything else you would like to see in this patch?
Darin Adler
Comment 15 2010-09-22 11:11:40 PDT
Comment on attachment 67939 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=67939&action=review > WebCore/bindings/js/ScriptFunctionCall.cpp:219 > + ASSERT(callType != CallTypeNone); What makes this assertion correct? Can we ever get CallTypeNone here? We must only assert something we know will be true for some reason. > WebCore/bindings/js/ScriptFunctionCall.h:69 > + protected: > + JSC::MarkedArgumentBuffer m_arguments; > + ScriptState* m_exec; Normally we would make data members private, and give derived classes access with protected accessor functions.
Oliver Hunt
Comment 16 2010-09-22 11:23:47 PDT
Comment on attachment 67939 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=67939&action=review > WebCore/bindings/js/ScriptFunctionCall.h:68 > + JSC::MarkedArgumentBuffer m_arguments; MarkedArgumentBuffer can't be heap allocated, so in addition to pulling MarkedArgumentBuffer up to this point you should also pull // MarkedArgumentBuffer must be stack allocated, so prevent heap void* operator new(size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); } void* operator new[](size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); } r-, because this could actually result in real bustage being introduced
Kenneth Rohde Christiansen
Comment 17 2010-09-22 11:37:37 PDT
Comment on attachment 67939 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=67939&action=review > WebCore/bindings/js/ScriptFunctionCall.h:-75 > - JSC::MarkedArgumentBuffer m_arguments; Oliver, it seems that that line was just refactored.
Oliver Hunt
Comment 18 2010-09-22 11:43:31 PDT
(In reply to comment #17) > (From update of attachment 67939 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=67939&action=review > > > WebCore/bindings/js/ScriptFunctionCall.h:-75 > > - JSC::MarkedArgumentBuffer m_arguments; > > Oliver, it seems that that line was just refactored. I know, however the guards to protect the class containing the argument buffer from heap allocation were not refactored with it.
Luiz Agostini
Comment 19 2010-09-22 12:01:47 PDT
Oliver Hunt
Comment 20 2010-09-22 12:04:21 PDT
Comment on attachment 68410 [details] patch r=me
Luiz Agostini
Comment 21 2010-09-22 12:15:57 PDT
(In reply to comment #15) > (From update of attachment 67939 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=67939&action=review > > > WebCore/bindings/js/ScriptFunctionCall.cpp:219 > > + ASSERT(callType != CallTypeNone); > > What makes this assertion correct? Can we ever get CallTypeNone here? We must only assert something we know will be true for some reason. It is possible since a ScriptValue is received in constructor and it may not be callable. Am I wrong? > > > WebCore/bindings/js/ScriptFunctionCall.h:69 > > + protected: > > + JSC::MarkedArgumentBuffer m_arguments; > > + ScriptState* m_exec; > > Normally we would make data members private, and give derived classes access with protected accessor functions. Sure. This time I just kept it as it was before.
WebKit Commit Bot
Comment 22 2010-09-22 12:46:46 PDT
Comment on attachment 68410 [details] patch Clearing flags on attachment: 68410 Committed r68074: <http://trac.webkit.org/changeset/68074>
WebKit Commit Bot
Comment 23 2010-09-22 12:46:54 PDT
All reviewed patches have been landed. Closing bug.
Darin Adler
Comment 24 2010-09-22 17:47:16 PDT
(In reply to comment #21) > (In reply to comment #15) > > > WebCore/bindings/js/ScriptFunctionCall.cpp:219 > > > + ASSERT(callType != CallTypeNone); > > > > What makes this assertion correct? Can we ever get CallTypeNone here? We must only assert something we know will be true for some reason. > > It is possible since a ScriptValue is received in constructor and it may not be callable. Am I wrong? Yes, the assertion is wrong, and thus the code is wrong! We need to handle that case. Please don’t use this class for anything until you fix that!
Note You need to log in before you can comment on or make changes to this bug.