Support [ImplementedAs] for attributes
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 15:46:23 +0000 (15:46 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 15:46:23 +0000 (15:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81605

Reviewed by Adam Barth.

[ImplementedAs] just supports methods. [ImplementedAs] should support
attributes too.

Explained here: https://trac.webkit.org/wiki/WebKitIDL#ImplementedAs

Test: bindings/scripts/test/TestObj.idl

* bindings/scripts/CodeGenerator.pm: Modified to support [ImplementedAs] for attributes.
(AttributeNameForGetterAndSetter):

* bindings/scripts/test/TestObj.idl: Added a test case.

* bindings/scripts/test/CPP/WebDOMTestObj.cpp: Updated run-bindings-tests results.
(WebDOMTestObj::strawberry):
(WebDOMTestObj::setStrawberry):
* bindings/scripts/test/CPP/WebDOMTestObj.h:
* bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
(webkit_dom_test_obj_get_strawberry):
(webkit_dom_test_obj_set_strawberry):
(webkit_dom_test_obj_get_property):
(webkit_dom_test_obj_class_init):
* bindings/scripts/test/GObject/WebKitDOMTestObj.h:
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore):
(WebCore::jsTestObjStrawberry):
(WebCore::setJSTestObjStrawberry):
* bindings/scripts/test/JS/JSTestObj.h:
(WebCore):
* bindings/scripts/test/ObjC/DOMTestObj.h:
* bindings/scripts/test/ObjC/DOMTestObj.mm:
(-[DOMTestObj strawberry]):
(-[DOMTestObj setStrawberry:]):
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::TestObjInternal::strawberryAttrGetter):
(TestObjInternal):
(WebCore::TestObjInternal::strawberryAttrSetter):
(WebCore):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@111865 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGenerator.pm
Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp
Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h
Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp
Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.h
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.h
Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h
Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm
Source/WebCore/bindings/scripts/test/TestObj.idl
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

index ff9446cd3ea89dcf7258ca6d7dab5e40adbc5178..d7622052040ec4d663493901ba9c4a21da411d77 100644 (file)
@@ -1,3 +1,48 @@
+2012-03-23  Kentaro Hara  <haraken@chromium.org>
+
+        Support [ImplementedAs] for attributes
+        https://bugs.webkit.org/show_bug.cgi?id=81605
+
+        Reviewed by Adam Barth.
+
+        [ImplementedAs] just supports methods. [ImplementedAs] should support
+        attributes too.
+
+        Explained here: https://trac.webkit.org/wiki/WebKitIDL#ImplementedAs
+
+        Test: bindings/scripts/test/TestObj.idl
+
+        * bindings/scripts/CodeGenerator.pm: Modified to support [ImplementedAs] for attributes.
+        (AttributeNameForGetterAndSetter):
+
+        * bindings/scripts/test/TestObj.idl: Added a test case.
+
+        * bindings/scripts/test/CPP/WebDOMTestObj.cpp: Updated run-bindings-tests results.
+        (WebDOMTestObj::strawberry):
+        (WebDOMTestObj::setStrawberry):
+        * bindings/scripts/test/CPP/WebDOMTestObj.h:
+        * bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
+        (webkit_dom_test_obj_get_strawberry):
+        (webkit_dom_test_obj_set_strawberry):
+        (webkit_dom_test_obj_get_property):
+        (webkit_dom_test_obj_class_init):
+        * bindings/scripts/test/GObject/WebKitDOMTestObj.h:
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore):
+        (WebCore::jsTestObjStrawberry):
+        (WebCore::setJSTestObjStrawberry):
+        * bindings/scripts/test/JS/JSTestObj.h:
+        (WebCore):
+        * bindings/scripts/test/ObjC/DOMTestObj.h:
+        * bindings/scripts/test/ObjC/DOMTestObj.mm:
+        (-[DOMTestObj strawberry]):
+        (-[DOMTestObj setStrawberry:]):
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::TestObjInternal::strawberryAttrGetter):
+        (TestObjInternal):
+        (WebCore::TestObjInternal::strawberryAttrSetter):
+        (WebCore):
+
 2012-03-23  Tommy Widenflycht  <tommyw@google.com>
 
         The JSC code generator doesn't generate correct code for Constructors
index 524b158f86c0d91452fbe38e89b1ef9317e32f6f..3f3379a1e90e4c3ebd4d9432a851a5e9de29eb82 100644 (file)
@@ -514,6 +514,9 @@ sub AttributeNameForGetterAndSetter
     my ($generator, $attribute) = @_;
 
     my $attributeName = $attribute->signature->name;
+    if ($attribute->signature->extendedAttributes->{"ImplementedAs"}) {
+        $attributeName = $attribute->signature->extendedAttributes->{"ImplementedAs"};
+    }
     my $attributeType = $generator->StripModule($attribute->signature->type);
 
     # Avoid clash with C++ keyword.
index 1ff5b967cc5f47d9c8ab74ceb84f25c54dcd43e7..8071df841b85ad645396d183842a485ae074bd2e 100644 (file)
@@ -583,6 +583,22 @@ void WebDOMTestObj::setImmutablePoint(const WebDOMSVGPoint& newImmutablePoint)
     impl()->setImmutablePoint(toWebCore(newImmutablePoint));
 }
 
+int WebDOMTestObj::strawberry() const
+{
+    if (!impl())
+        return 0;
+
+    return impl()->blueberry();
+}
+
+void WebDOMTestObj::setStrawberry(int newStrawberry)
+{
+    if (!impl())
+        return;
+
+    impl()->setBlueberry(newStrawberry);
+}
+
 float WebDOMTestObj::strictFloat() const
 {
     if (!impl())
index 7096d76fd11bca05034039cc2e8dc91b2e079585..e7ecc3f423d48bbdbcc0ba7dc17bec9ac8fdd3df 100644 (file)
@@ -135,6 +135,8 @@ public:
     void setMutablePoint(const WebDOMSVGPoint&);
     WebDOMSVGPoint immutablePoint() const;
     void setImmutablePoint(const WebDOMSVGPoint&);
+    int strawberry() const;
+    void setStrawberry(int);
     float strictFloat() const;
     void setStrictFloat(float);
     int description() const;
index 227ac9f062d88856e6e2af91c65053662476188c..c7ed165e9bf5177aacfdedee4474a9de8a46a22b 100644 (file)
@@ -1469,6 +1469,25 @@ webkit_dom_test_obj_set_immutable_point(WebKitDOMTestObj* self, WebKitDOMSVGPoin
     item->setImmutablePoint(converted_value);
 }
 
+gint
+webkit_dom_test_obj_get_strawberry(WebKitDOMTestObj* self)
+{
+    g_return_val_if_fail(self, 0);
+    WebCore::JSMainThreadNullState state;
+    WebCore::TestObj * item = WebKit::core(self);
+    gint res = item->blueberry();
+    return res;
+}
+
+void
+webkit_dom_test_obj_set_strawberry(WebKitDOMTestObj* self, gint value)
+{
+    g_return_if_fail(self);
+    WebCore::JSMainThreadNullState state;
+    WebCore::TestObj * item = WebKit::core(self);
+    item->setBlueberry(value);
+}
+
 gfloat
 webkit_dom_test_obj_get_strict_float(WebKitDOMTestObj* self)
 {
@@ -1590,6 +1609,7 @@ enum {
     PROP_CONTENT_DOCUMENT,
     PROP_MUTABLE_POINT,
     PROP_IMMUTABLE_POINT,
+    PROP_STRAWBERRY,
     PROP_STRICT_FLOAT,
     PROP_DESCRIPTION,
     PROP_ID,
@@ -1981,6 +2001,11 @@ static void webkit_dom_test_obj_get_property(GObject* object, guint prop_id, GVa
         g_value_set_object(value, WebKit::kit(ptr.get()));
         break;
     }
+    case PROP_STRAWBERRY:
+    {
+        g_value_set_int(value, coreSelf->blueberry());
+        break;
+    }
     case PROP_STRICT_FLOAT:
     {
         g_value_set_float(value, coreSelf->strictFloat());
@@ -2332,6 +2357,15 @@ G_MAXLONG, /* max */
                                                            "read-write  WebKitDOMSVGPoint* TestObj.immutable-point", /* longer - could do with some extra doc stuff here */
                                                            WEBKIT_TYPE_DOM_SVG_POINT, /* gobject type */
                                                            WEBKIT_PARAM_READWRITE));
+    g_object_class_install_property(gobjectClass,
+                                    PROP_STRAWBERRY,
+                                    g_param_spec_int("strawberry", /* name */
+                                                           "test_obj_strawberry", /* short description */
+                                                           "read-write  gint TestObj.strawberry", /* longer - could do with some extra doc stuff here */
+                                                           G_MININT, /* min */
+G_MAXINT, /* max */
+0, /* default */
+                                                           WEBKIT_PARAM_READWRITE));
     g_object_class_install_property(gobjectClass,
                                     PROP_STRICT_FLOAT,
                                     g_param_spec_float("strict-float", /* name */
index fc024acc8d4c6ba630d1ef0df1a190f3f0a713d2..cfa0248cb7e81088e81cb31597f1685e62565197 100644 (file)
@@ -1274,6 +1274,27 @@ webkit_dom_test_obj_get_immutable_point(WebKitDOMTestObj* self);
 WEBKIT_API void
 webkit_dom_test_obj_set_immutable_point(WebKitDOMTestObj* self, WebKitDOMSVGPoint* value);
 
+/**
+ * webkit_dom_test_obj_get_strawberry:
+ * @self: A #WebKitDOMTestObj
+ *
+ * Returns:
+ *
+**/
+WEBKIT_API gint
+webkit_dom_test_obj_get_strawberry(WebKitDOMTestObj* self);
+
+/**
+ * webkit_dom_test_obj_set_strawberry:
+ * @self: A #WebKitDOMTestObj
+ * @value: A #gint
+ *
+ * Returns:
+ *
+**/
+WEBKIT_API void
+webkit_dom_test_obj_set_strawberry(WebKitDOMTestObj* self, gint value);
+
 /**
  * webkit_dom_test_obj_get_strict_float:
  * @self: A #WebKitDOMTestObj
index a5d1fabf309b547693059320c0422dd529218f7d..33a4ea1f9e4c267e9306e7b2fe17e749e749f58a 100644 (file)
@@ -138,6 +138,7 @@ static const HashTableValue JSTestObjTableValues[] =
     { "contentDocument", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjContentDocument), (intptr_t)0, NoIntrinsic },
     { "mutablePoint", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjMutablePoint), (intptr_t)setJSTestObjMutablePoint, NoIntrinsic },
     { "immutablePoint", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjImmutablePoint), (intptr_t)setJSTestObjImmutablePoint, NoIntrinsic },
+    { "strawberry", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjStrawberry), (intptr_t)setJSTestObjStrawberry, NoIntrinsic },
     { "strictFloat", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjStrictFloat), (intptr_t)setJSTestObjStrictFloat, NoIntrinsic },
     { "description", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjDescription), (intptr_t)0, NoIntrinsic },
     { "id", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjId), (intptr_t)setJSTestObjId, NoIntrinsic },
@@ -146,7 +147,7 @@ static const HashTableValue JSTestObjTableValues[] =
     { 0, 0, 0, 0, NoIntrinsic }
 };
 
-static const HashTable JSTestObjTable = { 137, 127, JSTestObjTableValues, 0 };
+static const HashTable JSTestObjTable = { 138, 127, JSTestObjTableValues, 0 };
 /* Hash table for constructor */
 
 static const HashTableValue JSTestObjConstructorTableValues[] =
@@ -860,6 +861,16 @@ JSValue jsTestObjImmutablePoint(ExecState* exec, JSValue slotBase, const Identif
 }
 
 
+JSValue jsTestObjStrawberry(ExecState* exec, JSValue slotBase, const Identifier&)
+{
+    JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(slotBase));
+    UNUSED_PARAM(exec);
+    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
+    JSValue result = jsNumber(impl->blueberry());
+    return result;
+}
+
+
 JSValue jsTestObjStrictFloat(ExecState* exec, JSValue slotBase, const Identifier&)
 {
     JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(slotBase));
@@ -1270,6 +1281,14 @@ void setJSTestObjImmutablePoint(ExecState* exec, JSObject* thisObject, JSValue v
 }
 
 
+void setJSTestObjStrawberry(ExecState* exec, JSObject* thisObject, JSValue value)
+{
+    JSTestObj* castedThis = static_cast<JSTestObj*>(thisObject);
+    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
+    impl->setBlueberry(toint(value));
+}
+
+
 void setJSTestObjStrictFloat(ExecState* exec, JSObject* thisObject, JSValue value)
 {
     JSTestObj* castedThis = static_cast<JSTestObj*>(thisObject);
index 931a400d2166c71222d45812b77cda31a0811c26..12fa6986b3840a54f20948e602f29346142c1af8 100644 (file)
@@ -314,6 +314,8 @@ JSC::JSValue jsTestObjMutablePoint(JSC::ExecState*, JSC::JSValue, const JSC::Ide
 void setJSTestObjMutablePoint(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
 JSC::JSValue jsTestObjImmutablePoint(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
 void setJSTestObjImmutablePoint(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
+JSC::JSValue jsTestObjStrawberry(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
+void setJSTestObjStrawberry(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
 JSC::JSValue jsTestObjStrictFloat(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
 void setJSTestObjStrictFloat(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
 JSC::JSValue jsTestObjDescription(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
index 3f45e7e3ee8421ee57c4a5e62015d6004fd1a072..03267f1df0f7137f962f317afd4fe6380029d2a8 100644 (file)
@@ -163,6 +163,8 @@ enum {
 - (void)setMutablePoint:(DOMSVGPoint *)newMutablePoint;
 - (DOMSVGPoint *)immutablePoint;
 - (void)setImmutablePoint:(DOMSVGPoint *)newImmutablePoint;
+- (int)strawberry;
+- (void)setStrawberry:(int)newStrawberry;
 - (float)strictFloat;
 - (void)setStrictFloat:(float)newStrictFloat;
 - (int)descriptionName;
index cdd25e7449fd17eecba5b9bbc0a4e122dd8cd099..7daa0a1bec31ad20ea5988408967cebfe4f6100e 100644 (file)
     IMPL->setImmutablePoint(core(newImmutablePoint));
 }
 
+- (int)strawberry
+{
+    WebCore::JSMainThreadNullState state;
+    return IMPL->blueberry();
+}
+
+- (void)setStrawberry:(int)newStrawberry
+{
+    WebCore::JSMainThreadNullState state;
+    IMPL->setBlueberry(newStrawberry);
+}
+
 - (float)strictFloat
 {
     WebCore::JSMainThreadNullState state;
index 625fc1dbea77b75c15158a4c84fb89d8a1aad122..ed849ad891a3a113aa0758d02479c6f45eda39c3 100644 (file)
@@ -216,6 +216,7 @@ module test {
         [Immutable] SVGPoint immutablePointFunction();
 
         [ImplementedAs=banana] void orange();
+        attribute [ImplementedAs=blueberry] int strawberry;
 
         attribute [StrictTypeChecking] float strictFloat;
         [StrictTypeChecking] bool strictFunction(in DOMString str, in float a, in int b)
index 98c6eebfab72fc9887ccda68b7aaf01904108f35..7d08f56de7e6d9caa3827a5825fa74cfa5bdbe01 100644 (file)
@@ -941,6 +941,22 @@ static void immutablePointAttrSetter(v8::Local<v8::String> name, v8::Local<v8::V
     return;
 }
 
+static v8::Handle<v8::Value> strawberryAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestObj.strawberry._get");
+    TestObj* imp = V8TestObj::toNative(info.Holder());
+    return v8::Integer::New(imp->blueberry());
+}
+
+static void strawberryAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestObj.strawberry._set");
+    TestObj* imp = V8TestObj::toNative(info.Holder());
+    int v = V8int::HasInstance(value) ? V8int::toNative(v8::Handle<v8::Object>::Cast(value)) : 0;
+    imp->setBlueberry(v);
+    return;
+}
+
 static v8::Handle<v8::Value> strictFloatAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 {
     INC_STATS("DOM.TestObj.strictFloat._get");
@@ -1889,6 +1905,8 @@ static const BatchedAttribute TestObjAttrs[] = {
     {"mutablePoint", TestObjInternal::mutablePointAttrGetter, TestObjInternal::mutablePointAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'immutablePoint' (Type: 'attribute' ExtAttr: 'Immutable')
     {"immutablePoint", TestObjInternal::immutablePointAttrGetter, TestObjInternal::immutablePointAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+    // Attribute 'strawberry' (Type: 'attribute' ExtAttr: 'ImplementedAs')
+    {"strawberry", TestObjInternal::strawberryAttrGetter, TestObjInternal::strawberryAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'strictFloat' (Type: 'attribute' ExtAttr: 'StrictTypeChecking')
     {"strictFloat", TestObjInternal::strictFloatAttrGetter, TestObjInternal::strictFloatAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'description' (Type: 'readonly attribute' ExtAttr: '')