[V8] CodeGeneratorV8.pm should support static attributes
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2012 04:55:58 +0000 (04:55 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2012 04:55:58 +0000 (04:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91764

Reviewed by Adam Barth.

CodeGeneratorJS.pm already supports static attributes.
CodeGeneratorV8.pm should also support them.

Tests: bindings/scripts/test/TestObj.idl
       bindings/scripts/test/TestSupplemental.idl

* bindings/scripts/CodeGeneratorV8.pm:
(GenerateNormalAttrGetter):
(GenerateNormalAttrSetter):

* bindings/scripts/test/TestObj.idl: Added defined(TESTING_V8).
* bindings/scripts/test/TestSupplemental.idl: Added test cases for static attributes in supplemental IDL files.

* bindings/scripts/test/JS/JSTestInterface.cpp: Updated run-bindings-tests results.
(WebCore):
(WebCore::jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr):
The generated code is wrong since CodeGeneratorJS.pm does not support static attributes for
supplemental IDL files. I will fix it in a follow-up patch.
(WebCore::jsTestInterfaceConstructorSupplementalStaticAttr):
(WebCore::setJSTestInterfaceConstructorSupplementalStaticAttr):
* bindings/scripts/test/JS/JSTestInterface.h:
(WebCore):
* bindings/scripts/test/V8/V8TestInterface.cpp: Updated run-bindings-tests results.
(WebCore::TestInterfaceV8Internal::supplementalStaticReadOnlyAttrAttrGetter):
(TestInterfaceV8Internal):
(WebCore::TestInterfaceV8Internal::supplementalStaticAttrAttrGetter):
(WebCore::TestInterfaceV8Internal::supplementalStaticAttrAttrSetter):
(WebCore):
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::TestObjV8Internal::staticReadOnlyIntAttrAttrGetter):
(TestObjV8Internal):
(WebCore::TestObjV8Internal::staticStringAttrAttrGetter):
(WebCore::TestObjV8Internal::staticStringAttrAttrSetter):
(WebCore):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.h
Source/WebCore/bindings/scripts/test/TestObj.idl
Source/WebCore/bindings/scripts/test/TestSupplemental.idl
Source/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

index 4b02f2a..b14f600 100644 (file)
@@ -1,3 +1,45 @@
+2012-07-22  Kentaro Hara  <haraken@chromium.org>
+
+        [V8] CodeGeneratorV8.pm should support static attributes
+        https://bugs.webkit.org/show_bug.cgi?id=91764
+
+        Reviewed by Adam Barth.
+
+        CodeGeneratorJS.pm already supports static attributes.
+        CodeGeneratorV8.pm should also support them.
+
+        Tests: bindings/scripts/test/TestObj.idl
+               bindings/scripts/test/TestSupplemental.idl
+
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateNormalAttrGetter):
+        (GenerateNormalAttrSetter):
+
+        * bindings/scripts/test/TestObj.idl: Added defined(TESTING_V8).
+        * bindings/scripts/test/TestSupplemental.idl: Added test cases for static attributes in supplemental IDL files.
+
+        * bindings/scripts/test/JS/JSTestInterface.cpp: Updated run-bindings-tests results.
+        (WebCore):
+        (WebCore::jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr):
+        The generated code is wrong since CodeGeneratorJS.pm does not support static attributes for
+        supplemental IDL files. I will fix it in a follow-up patch.
+        (WebCore::jsTestInterfaceConstructorSupplementalStaticAttr):
+        (WebCore::setJSTestInterfaceConstructorSupplementalStaticAttr):
+        * bindings/scripts/test/JS/JSTestInterface.h:
+        (WebCore):
+        * bindings/scripts/test/V8/V8TestInterface.cpp: Updated run-bindings-tests results.
+        (WebCore::TestInterfaceV8Internal::supplementalStaticReadOnlyAttrAttrGetter):
+        (TestInterfaceV8Internal):
+        (WebCore::TestInterfaceV8Internal::supplementalStaticAttrAttrGetter):
+        (WebCore::TestInterfaceV8Internal::supplementalStaticAttrAttrSetter):
+        (WebCore):
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::TestObjV8Internal::staticReadOnlyIntAttrAttrGetter):
+        (TestObjV8Internal):
+        (WebCore::TestObjV8Internal::staticStringAttrAttrGetter):
+        (WebCore::TestObjV8Internal::staticStringAttrAttrSetter):
+        (WebCore):
+
 2012-07-22  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Missing *explicit* keyword in storage and workers.
index 052fcb1..7ac3e56 100644 (file)
@@ -892,9 +892,11 @@ END
         return value;
 END
         }
-        push(@implContentDecls, <<END);
+        if (!$attribute->isStatic) {
+            push(@implContentDecls, <<END);
     ${implClassName}* imp = V8${implClassName}::toNative(info.Holder());
 END
+        }
     }
 
     # Generate security checks if necessary
@@ -917,8 +919,10 @@ END
         if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
             my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
             AddToImplIncludes("${implementedBy}.h");
-            unshift(@arguments, "imp");
+            unshift(@arguments, "imp") if !$attribute->isStatic;
             $functionName = "${implementedBy}::${functionName}";
+        } elsif ($attribute->isStatic) {
+            $functionName = "${implClassName}::${functionName}";
         } else {
             $functionName = "imp->${functionName}";
         }
@@ -1169,9 +1173,11 @@ END
             # Skip the rest of the function!
         }
 
-        push(@implContentDecls, <<END);
+        if (!$attribute->isStatic) {
+            push(@implContentDecls, <<END);
     ${implClassName}* imp = V8${implClassName}::toNative(info.Holder());
 END
+        }
     }
 
     my $nativeType = GetNativeTypeFromSignature($attribute->signature, 0);
@@ -1235,8 +1241,10 @@ END
             if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {
                 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};
                 AddToImplIncludes("${implementedBy}.h");
-                unshift(@arguments, "imp");
+                unshift(@arguments, "imp") if !$attribute->isStatic;
                 $functionName = "${implementedBy}::${functionName}";
+            } elsif ($attribute->isStatic) {
+                $functionName = "${interfaceName}::${functionName}";
             } else {
                 $functionName = "imp->${functionName}";
             }
index afdb3b1..c3c829c 100644 (file)
@@ -81,12 +81,18 @@ static const HashTableValue JSTestInterfaceConstructorTableValues[] =
     { "SUPPLEMENTALCONSTANT2", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestInterfaceSUPPLEMENTALCONSTANT2), (intptr_t)0, NoIntrinsic },
 #endif
 #if ENABLE(Condition11) || ENABLE(Condition12)
+    { "supplementalStaticReadOnlyAttr", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr), (intptr_t)0, NoIntrinsic },
+#endif
+#if ENABLE(Condition11) || ENABLE(Condition12)
+    { "supplementalStaticAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestInterfaceConstructorSupplementalStaticAttr), (intptr_t)setJSTestInterfaceConstructorSupplementalStaticAttr, NoIntrinsic },
+#endif
+#if ENABLE(Condition11) || ENABLE(Condition12)
     { "supplementalMethod4", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestInterfaceConstructorFunctionSupplementalMethod4), (intptr_t)0, NoIntrinsic },
 #endif
     { 0, 0, 0, 0, NoIntrinsic }
 };
 
-static const HashTable JSTestInterfaceConstructorTable = { 4, 3, JSTestInterfaceConstructorTableValues, 0 };
+static const HashTable JSTestInterfaceConstructorTable = { 5, 3, JSTestInterfaceConstructorTableValues, 0 };
 
 #if ENABLE(Condition11) || ENABLE(Condition12)
 COMPILE_ASSERT(1 == TestSupplemental::SUPPLEMENTALCONSTANT1, TestInterfaceEnumSUPPLEMENTALCONSTANT1IsWrongUseDoNotCheckConstants);
@@ -236,6 +242,30 @@ bool JSTestInterface::getOwnPropertyDescriptor(JSObject* object, ExecState* exec
 }
 
 #if ENABLE(Condition11) || ENABLE(Condition12)
+JSValue jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr(ExecState* exec, JSValue, PropertyName)
+{
+    ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
+    if (!scriptContext)
+        return jsUndefined();
+    JSC::JSValue result = jsNumber(TestInterface::supplementalStaticReadOnlyAttr(scriptContext));
+    return result;
+}
+
+#endif
+
+#if ENABLE(Condition11) || ENABLE(Condition12)
+JSValue jsTestInterfaceConstructorSupplementalStaticAttr(ExecState* exec, JSValue, PropertyName)
+{
+    ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
+    if (!scriptContext)
+        return jsUndefined();
+    JSC::JSValue result = jsString(exec, TestInterface::supplementalStaticAttr(scriptContext));
+    return result;
+}
+
+#endif
+
+#if ENABLE(Condition11) || ENABLE(Condition12)
 JSValue jsTestInterfaceSupplementalStr1(ExecState* exec, JSValue slotBase, PropertyName)
 {
     JSTestInterface* castedThis = jsCast<JSTestInterface*>(asObject(slotBase));
@@ -296,6 +326,17 @@ void JSTestInterface::put(JSCell* cell, ExecState* exec, PropertyName propertyNa
 }
 
 #if ENABLE(Condition11) || ENABLE(Condition12)
+void setJSTestInterfaceConstructorSupplementalStaticAttr(ExecState* exec, JSObject*, JSValue value)
+{
+    ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
+    if (!scriptContext)
+        return;
+    TestInterface::setSupplementalStaticAttr(scriptContext, ustringToString(value.isEmpty() ? UString() : value.toString(exec)->value(exec)));
+}
+
+#endif
+
+#if ENABLE(Condition11) || ENABLE(Condition12)
 void setJSTestInterfaceSupplementalStr2(ExecState* exec, JSObject* thisObject, JSValue value)
 {
     UNUSED_PARAM(exec);
index d7963a2..8baaa73 100644 (file)
@@ -170,6 +170,13 @@ JSC::EncodedJSValue JSC_HOST_CALL jsTestInterfaceConstructorFunctionSupplemental
 // Attributes
 
 #if ENABLE(Condition11) || ENABLE(Condition12)
+JSC::JSValue jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);
+#endif
+#if ENABLE(Condition11) || ENABLE(Condition12)
+JSC::JSValue jsTestInterfaceConstructorSupplementalStaticAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);
+void setJSTestInterfaceConstructorSupplementalStaticAttr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
+#endif
+#if ENABLE(Condition11) || ENABLE(Condition12)
 JSC::JSValue jsTestInterfaceSupplementalStr1(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);
 #endif
 #if ENABLE(Condition11) || ENABLE(Condition12)
index 7775875..c1ea6f5 100644 (file)
@@ -38,7 +38,7 @@ module test {
         readonly attribute long            readOnlyIntAttr;
         readonly attribute DOMString       readOnlyStringAttr;
         readonly attribute TestObj         readOnlyTestObjAttr;
-#if defined(TESTING_JS)
+#if defined(TESTING_JS) || defined(TESTING_V8)
         static readonly attribute long     staticReadOnlyIntAttr;
         static attribute DOMString         staticStringAttr;
 #endif
index 6051412..524515b 100644 (file)
@@ -33,6 +33,10 @@ module test {
         Conditional=Condition11|Condition12,
         Supplemental=TestInterface
     ] TestSupplemental {
+#if defined(TESTING_JS) || defined(TESTING_V8)
+        static readonly attribute long supplementalStaticReadOnlyAttr;
+        static attribute DOMString supplementalStaticAttr;
+#endif
         readonly attribute DOMString supplementalStr1;
         attribute DOMString supplementalStr2;
         attribute [CustomGetter, CustomSetter] DOMString supplementalStr3;
index b828d54..1d7dcb5 100644 (file)
@@ -50,6 +50,38 @@ template <typename T> void V8_USE(T) { }
 
 #if ENABLE(Condition11) || ENABLE(Condition12)
 
+static v8::Handle<v8::Value> supplementalStaticReadOnlyAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestInterface.supplementalStaticReadOnlyAttr._get");
+    return v8Integer(TestSupplemental::supplementalStaticReadOnlyAttr(), info.GetIsolate());
+}
+
+#endif // ENABLE(Condition11) || ENABLE(Condition12)
+
+#if ENABLE(Condition11) || ENABLE(Condition12)
+
+static v8::Handle<v8::Value> supplementalStaticAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestInterface.supplementalStaticAttr._get");
+    return v8String(TestSupplemental::supplementalStaticAttr(), info.GetIsolate());
+}
+
+#endif // ENABLE(Condition11) || ENABLE(Condition12)
+
+#if ENABLE(Condition11) || ENABLE(Condition12)
+
+static void supplementalStaticAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestInterface.supplementalStaticAttr._set");
+    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK_VOID(V8Parameter<>, v, value);
+    TestSupplemental::setSupplementalStaticAttr(v);
+    return;
+}
+
+#endif // ENABLE(Condition11) || ENABLE(Condition12)
+
+#if ENABLE(Condition11) || ENABLE(Condition12)
+
 static v8::Handle<v8::Value> supplementalStr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 {
     INC_STATS("DOM.TestInterface.supplementalStr1._get");
@@ -160,6 +192,14 @@ static v8::Handle<v8::Value> supplementalMethod4Callback(const v8::Arguments& ar
 
 static const BatchedAttribute TestInterfaceAttrs[] = {
 #if ENABLE(Condition11) || ENABLE(Condition12)
+    // Attribute 'supplementalStaticReadOnlyAttr' (Type: 'readonly attribute' ExtAttr: 'Conditional ImplementedBy')
+    {"supplementalStaticReadOnlyAttr", TestInterfaceV8Internal::supplementalStaticReadOnlyAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+#endif // ENABLE(Condition11) || ENABLE(Condition12)
+#if ENABLE(Condition11) || ENABLE(Condition12)
+    // Attribute 'supplementalStaticAttr' (Type: 'attribute' ExtAttr: 'Conditional ImplementedBy')
+    {"supplementalStaticAttr", TestInterfaceV8Internal::supplementalStaticAttrAttrGetter, TestInterfaceV8Internal::supplementalStaticAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+#endif // ENABLE(Condition11) || ENABLE(Condition12)
+#if ENABLE(Condition11) || ENABLE(Condition12)
     // Attribute 'supplementalStr1' (Type: 'readonly attribute' ExtAttr: 'Conditional ImplementedBy')
     {"supplementalStr1", TestInterfaceV8Internal::supplementalStr1AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
 #endif // ENABLE(Condition11) || ENABLE(Condition12)
index e397070..c47e6ae 100644 (file)
@@ -109,6 +109,26 @@ static v8::Handle<v8::Value> readOnlyTestObjAttrAttrGetter(v8::Local<v8::String>
     return wrapper;
 }
 
+static v8::Handle<v8::Value> staticReadOnlyIntAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestObj.staticReadOnlyIntAttr._get");
+    return v8Integer(TestObj::staticReadOnlyIntAttr(), info.GetIsolate());
+}
+
+static v8::Handle<v8::Value> staticStringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestObj.staticStringAttr._get");
+    return v8String(TestObj::staticStringAttr(), info.GetIsolate());
+}
+
+static void staticStringAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestObj.staticStringAttr._set");
+    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK_VOID(V8Parameter<>, v, value);
+    TestObj::setStaticStringAttr(v);
+    return;
+}
+
 static v8::Handle<v8::Value> shortAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 {
     INC_STATS("DOM.TestObj.shortAttr._get");
@@ -1852,6 +1872,10 @@ static const BatchedAttribute TestObjAttrs[] = {
     {"readOnlyStringAttr", TestObjV8Internal::readOnlyStringAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'readOnlyTestObjAttr' (Type: 'readonly attribute' ExtAttr: '')
     {"readOnlyTestObjAttr", TestObjV8Internal::readOnlyTestObjAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+    // Attribute 'staticReadOnlyIntAttr' (Type: 'readonly attribute' ExtAttr: '')
+    {"staticReadOnlyIntAttr", TestObjV8Internal::staticReadOnlyIntAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+    // Attribute 'staticStringAttr' (Type: 'attribute' ExtAttr: '')
+    {"staticStringAttr", TestObjV8Internal::staticStringAttrAttrGetter, TestObjV8Internal::staticStringAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'shortAttr' (Type: 'attribute' ExtAttr: '')
     {"shortAttr", TestObjV8Internal::shortAttrAttrGetter, TestObjV8Internal::shortAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'unsignedShortAttr' (Type: 'attribute' ExtAttr: '')