Improve code generator scripts to support converting ScriptString.
authorjianli@chromium.org <jianli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 May 2010 00:01:11 +0000 (00:01 +0000)
committerjianli@chromium.org <jianli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 May 2010 00:01:11 +0000 (00:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=38699

Reviewed by Adam Barth.

Change both JSC and V8 generators to introduce "ConvertScriptString"
attribute to allow converting from ScriptString. Also updated the
bindings test result.

These changes are necessary in order to avoid adding custom binding codes
when we add the FileReader interface.

* bindings/scripts/CodeGeneratorJS.pm:
* bindings/scripts/CodeGeneratorV8.pm:
* bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
(webkit_dom_test_obj_get_script_string_attr):
(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::jsTestObjScriptStringAttr):
* bindings/scripts/test/JS/JSTestObj.h:
* bindings/scripts/test/ObjC/DOMTestObj.h:
* bindings/scripts/test/ObjC/DOMTestObj.mm:
(-[DOMTestObj scriptStringAttr]):
* bindings/scripts/test/TestObj.idl:
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::TestObjInternal::scriptStringAttrAttrGetter):
(WebCore::):

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

WebCore/ChangeLog
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/bindings/scripts/CodeGeneratorV8.pm
WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp
WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.h
WebCore/bindings/scripts/test/JS/JSTestObj.cpp
WebCore/bindings/scripts/test/JS/JSTestObj.h
WebCore/bindings/scripts/test/ObjC/DOMTestObj.h
WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm
WebCore/bindings/scripts/test/TestObj.idl
WebCore/bindings/scripts/test/V8/V8TestObj.cpp

index fedac52..028bcf0 100644 (file)
@@ -2,6 +2,39 @@
 
         Reviewed by Adam Barth.
 
+        Improve code generator scripts to support converting ScriptString.
+        https://bugs.webkit.org/show_bug.cgi?id=38699
+
+        Change both JSC and V8 generators to introduce "ConvertScriptString"
+        attribute to allow converting from ScriptString. Also updated the
+        bindings test result.
+
+        These changes are necessary in order to avoid adding custom binding codes
+        when we add the FileReader interface.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        * bindings/scripts/CodeGeneratorV8.pm:
+        * bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
+        (webkit_dom_test_obj_get_script_string_attr):
+        (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::jsTestObjScriptStringAttr):
+        * bindings/scripts/test/JS/JSTestObj.h:
+        * bindings/scripts/test/ObjC/DOMTestObj.h:
+        * bindings/scripts/test/ObjC/DOMTestObj.mm:
+        (-[DOMTestObj scriptStringAttr]):
+        * bindings/scripts/test/TestObj.idl:
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::TestObjInternal::scriptStringAttrAttrGetter):
+        (WebCore::):
+
+2010-05-06  Jian Li  <jianli@chromium.org>
+
+        Reviewed by Adam Barth.
+
         Improve code generator scripts to pass additional ScriptExecutionContext
         argument to the constructor.
         https://bugs.webkit.org/show_bug.cgi?id=38687
index 40208aa..dc21314 100644 (file)
@@ -2233,6 +2233,8 @@ sub NativeToJSValue
 
             die "Unknown value for ConvertNullStringTo extended attribute";
         }
+        $conv = $signature->extendedAttributes->{"ConvertScriptString"};
+        return "jsOwnedStringOrNull(exec, $value)" if $conv;
         $implIncludes{"<runtime/JSString.h>"} = 1;
         return "jsString(exec, $value)";
     }
index 6d950b0..9553b8b 100644 (file)
@@ -3066,6 +3066,8 @@ sub ReturnNativeToJSValue
 
             die "Unknown value for ConvertNullStringTo extended attribute";
         }
+        $conv = $signature->extendedAttributes->{"ConvertScriptString"};
+        return "v8StringOrNull(exec, $value)" if $conv;
         return "return v8String($value)";
     }
 
index 92bc5bf..8c1bae2 100644 (file)
@@ -469,6 +469,16 @@ webkit_dom_test_obj_set_attr_with_getter_exception (WebKitDOMTestObj *self, glon
 
 }
 
+gchar* 
+webkit_dom_test_obj_get_script_string_attr (WebKitDOMTestObj *self)
+{
+    g_return_val_if_fail (self, 0);
+    WebCore::TestObj * item = WebKit::core(self);
+    gchar*  res = convertToUTF8String(item->scriptStringAttr());
+    return res;
+
+}
+
 
 G_DEFINE_TYPE(WebKitDOMTestObj, webkit_dom_test_obj, WEBKIT_TYPE_DOM_OBJECT)
 
@@ -517,6 +527,7 @@ enum {
     PROP_ATTR_WITH_SETTER_EXCEPTION,
     PROP_ATTR_WITH_GETTER_EXCEPTION,
     PROP_CUSTOM_ATTR,
+    PROP_SCRIPT_STRING_ATTR,
 };
 
 
@@ -640,6 +651,11 @@ static void webkit_dom_test_obj_get_property(GObject* object, guint prop_id, GVa
          g_value_set_long(value, coreSelf->attrWithGetterException());
          break;
     }
+    case PROP_SCRIPT_STRING_ATTR:
+    {
+         g_value_take_string(value, convertToUTF8String(coreSelf->scriptStringAttr()));
+         break;
+    }
      default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -745,6 +761,13 @@ G_MAXLONG, /* max */
 G_MAXLONG, /* max */
 0, /* default */
                                                            WEBKIT_PARAM_READWRITE));
+     g_object_class_install_property(gobjectClass,
+                                    PROP_SCRIPT_STRING_ATTR,
+                                    g_param_spec_string("script-string-attr", /* name */
+                                                           "test_obj_script-string-attr", /* short description */
+                                                           "read-only  gchar*  TestObj.script-string-attr", /* longer - could do with some extra doc stuff here */
+                                                           "", /* default */
+                                                           WEBKIT_PARAM_READABLE));
 
 
 
index ec7aa53..f8ad9c4 100644 (file)
@@ -169,6 +169,9 @@ webkit_dom_test_obj_get_attr_with_getter_exception (WebKitDOMTestObj *self);
 WEBKIT_API void
 webkit_dom_test_obj_set_attr_with_getter_exception (WebKitDOMTestObj *self, glong value);
 
+WEBKIT_API gchar* 
+webkit_dom_test_obj_get_script_string_attr (WebKitDOMTestObj *self);
+
 G_END_DECLS
 
 #endif /* WebKitDOMTestObj_h */
index d68041e..da99de2 100644 (file)
@@ -46,7 +46,7 @@ ASSERT_CLASS_FITS_IN_CELL(JSTestObj);
 #define THUNK_GENERATOR(generator)
 #endif
 
-static const HashTableValue JSTestObjTableValues[14] =
+static const HashTableValue JSTestObjTableValues[15] =
 {
     { "readOnlyIntAttr", DontDelete|ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReadOnlyIntAttr), (intptr_t)0 THUNK_GENERATOR(0) },
     { "readOnlyStringAttr", DontDelete|ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReadOnlyStringAttr), (intptr_t)0 THUNK_GENERATOR(0) },
@@ -60,6 +60,7 @@ static const HashTableValue JSTestObjTableValues[14] =
     { "attrWithSetterException", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjAttrWithSetterException), (intptr_t)setJSTestObjAttrWithSetterException THUNK_GENERATOR(0) },
     { "attrWithGetterException", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjAttrWithGetterException), (intptr_t)setJSTestObjAttrWithGetterException THUNK_GENERATOR(0) },
     { "customAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCustomAttr), (intptr_t)setJSTestObjCustomAttr THUNK_GENERATOR(0) },
+    { "scriptStringAttr", DontDelete|ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjScriptStringAttr), (intptr_t)0 THUNK_GENERATOR(0) },
     { "constructor", DontEnum|ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
 };
@@ -320,6 +321,15 @@ JSValue jsTestObjCustomAttr(ExecState* exec, JSValue slotBase, const Identifier&
     return castedThis->customAttr(exec);
 }
 
+JSValue jsTestObjScriptStringAttr(ExecState* exec, JSValue slotBase, const Identifier&)
+{
+    JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(slotBase));
+    UNUSED_PARAM(exec);
+    TestObj* imp = static_cast<TestObj*>(castedThis->impl());
+    JSValue result = jsOwnedStringOrNull(exec, imp->scriptStringAttr());
+    return result;
+}
+
 JSValue jsTestObjConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
 {
     JSTestObj* domObject = static_cast<JSTestObj*>(asObject(slotBase));
index 704622f..f726efb 100644 (file)
@@ -133,6 +133,7 @@ JSC::JSValue jsTestObjAttrWithGetterException(JSC::ExecState*, JSC::JSValue, con
 void setJSTestObjAttrWithGetterException(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
 JSC::JSValue jsTestObjCustomAttr(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
 void setJSTestObjCustomAttr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);
+JSC::JSValue jsTestObjScriptStringAttr(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
 JSC::JSValue jsTestObjConstructor(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
 
 } // namespace WebCore
index d13ff52..dd9d2ee 100644 (file)
@@ -55,6 +55,7 @@
 - (void)setAttrWithGetterException:(int)newAttrWithGetterException;
 - (int)customAttr;
 - (void)setCustomAttr:(int)newCustomAttr;
+- (NSString *)scriptStringAttr;
 - (void)voidMethod;
 - (void)voidMethodWithArgs:(int)intArg strArg:(NSString *)strArg objArg:(DOMTestObj *)objArg;
 - (int)intMethod;
index 7257469..b964e36 100644 (file)
     IMPL->setCustomAttr(newCustomAttr);
 }
 
+- (NSString *)scriptStringAttr
+{
+    return IMPL->scriptStringAttr();
+}
+
 - (void)voidMethod
 {
     IMPL->voidMethod();
index 5f9ece3..b14328d 100644 (file)
@@ -89,6 +89,9 @@ module test {
         void    methodWithNonOptionalArgAndOptionalArg(in long nonOpt, in [Optional] long opt);
         void    methodWithNonOptionalArgAndTwoOptionalArgs(in long nonOpt, in [Optional] long opt1, in long opt2);
 
+        // 'ConvertScriptString' extended attribute
+        readonly attribute [ConvertScriptString] DOMString scriptStringAttr;
+
 #ifdef TESTING_V8
         // Overloads
         void    overloadedMethod(in TestObj objArg, in DOMString strArg);
index f5a1cc6..94dcd5e 100644 (file)
@@ -199,6 +199,13 @@ static void attrWithGetterExceptionAttrSetter(v8::Local<v8::String> name, v8::Lo
     return;
 }
 
+static v8::Handle<v8::Value> scriptStringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+    INC_STATS("DOM.TestObj.scriptStringAttr._get");
+    TestObj* imp = V8TestObj::toNative(info.Holder());
+    v8StringOrNull(exec, imp->scriptStringAttr());
+}
+
 static v8::Handle<v8::Value> voidMethodCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.TestObj.voidMethod");
@@ -583,6 +590,8 @@ static const BatchedAttribute TestObjAttrs[] = {
     {"attrWithGetterException", TestObjInternal::attrWithGetterExceptionAttrGetter, TestObjInternal::attrWithGetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     // Attribute 'customAttr' (Type: 'attribute' ExtAttr: 'Custom')
     {"customAttr", V8TestObj::customAttrAccessorGetter, V8TestObj::customAttrAccessorSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+    // Attribute 'scriptStringAttr' (Type: 'readonly attribute' ExtAttr: 'ConvertScriptString')
+    {"scriptStringAttr", TestObjInternal::scriptStringAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
 };
 static const BatchedCallback TestObjCallbacks[] = {
     {"voidMethod", TestObjInternal::voidMethodCallback},