Bug 35401 - Fix handling of errors in handling calls over bridge, where base object bridge-type does not match method bridge-type.
Summary: Fix handling of errors in handling calls over bridge, where base object bridg...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Gavin Barraclough
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-25 13:18 PST by Gavin Barraclough
Modified: 2010-02-26 14:21 PST (History)
2 users (show)

See Also:


Attachments
The patch (18.71 KB, patch)
2010-02-25 13:44 PST, Gavin Barraclough
ap: review-
Details | Formatted Diff | Diff
New awesomier patch. (27.12 KB, patch)
2010-02-26 11:23 PST, Gavin Barraclough
ap: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gavin Barraclough 2010-02-25 13:18:27 PST
The code assumes users will only attempt to invoke a Java method on a Java base object, etc.  This leads to unsafe casting, and crashiosity.  Should type check that the method & this object match before embarking on the method invocation, throw an exception on type mismatch.
Comment 1 Gavin Barraclough 2010-02-25 13:44:51 PST
Created attachment 49530 [details]
The patch
Comment 2 Alexey Proskuryakov 2010-02-25 14:01:08 PST
Comment on attachment 49530 [details]
The patch

> +    if (!asObject(runtimeMethod)->inherits(&CRuntimeMethod::info))
> +        return throwError(exec, TypeError, "Attempt to invoke non-C method on C object.");

The "C" hierarchy of classes is a huge misnomer, it's bindings for NPAPI plug-ins. Please don't call it "C" in text visible to Web developers.

+    const MethodList &methodList = *runtimeMethod->methods();

Misplaced &. Repeated several times in the patch.

+class ObjcRuntimeMethod : public RuntimeMethod {

The modern spelling is "ObjC". I used that for RuntimeObject, even though old code used "Objc".

+        (WebKit::):

This is just a result of a bug in the script, please delete it. Per-function comments would be even better.

+class PluginRuntimeMethod : public RuntimeMethod {

Maybe "ProxyRuntimeMethod", to match ProxyInstance and ProxyRuntimeObject?

+public:
+    PluginRuntimeMethod(ExecState* exec, const Identifier& name, Bindings::MethodList& list)
+        : RuntimeMethod(exec, name, list)
+    {
+    }
+
+    static const ClassInfo s_info;
+};

Don't you need to override classInfo() in all those classes?

Looks good, r- for lack of tests.
Comment 3 Alexey Proskuryakov 2010-02-25 14:02:10 PST
> The "C" hierarchy of classes is a huge misnomer, it's bindings for NPAPI
> plug-ins. Please don't call it "C" in text visible to Web developers.

The text should be the same as the one in WebKit, as it's the same plug-ins we are dealing with, just in-process vs. out of process.
Comment 4 Gavin Barraclough 2010-02-26 11:23:20 PST
Created attachment 49603 [details]
New awesomier patch.
Comment 5 WebKit Review Bot 2010-02-26 12:11:17 PST
Attachment 49603 [details] did not build on qt:
Build output: http://webkit-commit-queue.appspot.com/results/314585
Comment 6 Alexey Proskuryakov 2010-02-26 12:16:15 PST
Comment on attachment 49603 [details]
New awesomier patch.

 __ZN7WebCore6String8fromUTF8EPKcm
+__ZTVN3JSC13RuntimeMethodE
 __ZNK3JSC8Bindings13RuntimeObject12defaultValueEPNS_9ExecStateENS_22PreferredPrimitiveTypeE

This doesn't look sorted properly.

+    virtual const ClassInfo* classInfo() const { return &info; }

In RuntimeMethod, it's s_info. Why does this work (or what is broken)?

+class CRuntimeMethod : public RuntimeMethod {

I didn't notice it last time, but we really prefer to have classes in their own files in new code.

+#import "JavaScriptCore/Error.h"
 #import "NetscapePluginHostProxy.h"
 #import "ProxyRuntimeObject.h"
 #import <WebCore/IdentifierRep.h>
 #import <WebCore/JSDOMWindow.h>
 #import <WebCore/npruntime_impl.h>
 #import <runtime/PropertyNameArray.h>
+#import "WebCore/runtime_method.h"
 
This looks like a mess. I think it should be "runtime/Error.h" and <WebCore/runtime_method.h>.

+        * java/java-and-plugins.html: Add tests for passing mismatched this objects to methdods.

The patch and ChangeLog don't include changes for expected results.

With the exception of "one class per file", the comments above clearly must be addressed before landing, r=me assuming you make the appropriate changes, and also fix Qt build.
Comment 7 Gavin Barraclough 2010-02-26 14:21:56 PST
Fixed all review issues other than the one-class-per-file one.

I strongly disagree with this change.  I believe the purpose of this rule is to make the code easier to maintain by making it simple for developers to find the definitions of classes.  However in the case of a scaffolding class only used within one .cpp I don't believe that moving this out into a header benefits anyone.  It inflates the size of the codebase, and unnecessarily hides from developers the fact that the scope of the class is constrained (the header is only included in one place, but there is no way for a future engineer coming along to know that).  I think this is a bad application of the rule, which only serves to obfuscate.

Landed in r55312