Add the support for Symbol attributes on IDL
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 Oct 2015 15:37:03 +0000 (15:37 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 Oct 2015 15:37:03 +0000 (15:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150586

Reviewed by Ryosuke Niwa.

This patch addes readonly attribute support for Symbols.
It involves the IDL generator functionality converting Native type (PrivateName) to Symbol.

* bindings/scripts/CodeGeneratorGObject.pm:
(SkipAttribute):
(SkipFunction):
* bindings/scripts/CodeGeneratorJS.pm:
(NativeToJSValue):
* bindings/scripts/CodeGeneratorObjC.pm:
(SkipFunction):
(SkipAttribute):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjReadOnlySymbolAttr):
(WebCore::jsTestObjConstructorStaticReadOnlySymbolAttr):
* bindings/scripts/test/TestObj.idl:

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/TestObj.idl

index a89c59cb0c6e80a3c8b1f4e76af4986676adfaa6..79cd5e7c3138232c33234f1936097356a4c556d5 100644 (file)
@@ -1,3 +1,26 @@
+2015-10-31  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Add the support for Symbol attributes on IDL
+        https://bugs.webkit.org/show_bug.cgi?id=150586
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch addes readonly attribute support for Symbols.
+        It involves the IDL generator functionality converting Native type (PrivateName) to Symbol.
+
+        * bindings/scripts/CodeGeneratorGObject.pm:
+        (SkipAttribute):
+        (SkipFunction):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (NativeToJSValue):
+        * bindings/scripts/CodeGeneratorObjC.pm:
+        (SkipFunction):
+        (SkipAttribute):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjReadOnlySymbolAttr):
+        (WebCore::jsTestObjConstructorStaticReadOnlySymbolAttr):
+        * bindings/scripts/test/TestObj.idl:
+
 2015-10-30  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: Support IDBObjectStore.get() for IDBKeyRanges.
index a3a1373e78f07bcebce8d48bcaa0cd6a602ecfad..45e18b7f5ea02adc10665591e3997bbb0a891daf 100644 (file)
@@ -262,6 +262,8 @@ sub SkipAttribute {
 
     return 1 if $attribute->signature->type eq "EventHandler";
 
+    return 1 if $attribute->signature->type eq "Symbol";
+
     if ($attribute->signature->type eq "MediaQueryListListener") {
         return 1;
     }
@@ -371,6 +373,8 @@ sub SkipFunction {
 
     return 1 if $function->signature->type eq "Promise";
 
+    return 1 if $function->signature->type eq "Symbol";
+
     return 1 if $function->signature->type eq "Date";
 
     return 1 if $function->signature->extendedAttributes->{"JSBuiltin"};
index 56837a29409da911ea1d250dd92e2c501fdc822e..756b59d53100912bb0dc321300e1d4cd851befe8 100644 (file)
@@ -3938,6 +3938,7 @@ my %nativeType = (
     "byte" => "int8_t",
     "octet" => "uint8_t",
     "DOMTimeStamp" => "DOMTimeStamp",
+    "Symbol" => "PrivateName"
 );
 
 sub GetNativeType
@@ -4152,6 +4153,11 @@ sub NativeToJSValue
         return "jsDateOrNull(state, $value)";
     }
 
+    if ($type eq "Symbol") {
+        AddToImplIncludes("<runtime/Symbol.h>", $conditional);
+        return "Symbol::create(state->vm(), *($value).uid())";
+    }
+
     if ($signature->extendedAttributes->{"Reflect"} and ($type eq "unsigned long" or $type eq "unsigned short")) {
         $value =~ s/getUnsignedIntegralAttribute/getIntegralAttribute/g;
         return "jsNumber(std::max(0, " . $value . "))";
index 8d8bb10f7c57ae7dae4cc14e8f81ddbdfa9824cd..41719874c7d6101e2c8602f3466068456dd18420 100644 (file)
@@ -539,6 +539,7 @@ sub SkipFunction
     return 1 if $codeGenerator->GetArrayType($function->signature->type);
 
     return 1 if $function->signature->type eq "Promise";
+    return 1 if $function->signature->type eq "Symbol";
     return 1 if $function->signature->extendedAttributes->{"CustomBinding"};
 
     foreach my $param (@{$function->parameters}) {
@@ -562,6 +563,7 @@ sub SkipAttribute
     return 1 if $codeGenerator->IsTypedArrayType($type);
     return 1 if $codeGenerator->IsEnumType($type);
     return 1 if $type eq "EventHandler";
+    return 1 if $type eq "Symbol";
     return 1 if $attribute->isStatic;
 
     # This is for DynamicsCompressorNode.idl.
index fc7aad3a246d11718b824d548ba3517f2de800a8..6935c73c9b1674e2d446107298891f5cbfc52123 100644 (file)
@@ -61,6 +61,7 @@
 #include <runtime/Error.h>
 #include <runtime/JSArray.h>
 #include <runtime/JSString.h>
+#include <runtime/Symbol.h>
 #include <wtf/GetPtr.h>
 
 #if ENABLE(Condition1)
@@ -211,6 +212,8 @@ JSC::EncodedJSValue jsTestObjXMLObjAttr(JSC::ExecState*, JSC::JSObject*, JSC::En
 void setJSTestObjXMLObjAttr(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::EncodedJSValue);
 JSC::EncodedJSValue jsTestObjCreate(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
 void setJSTestObjCreate(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::EncodedJSValue);
+JSC::EncodedJSValue jsTestObjReadOnlySymbolAttr(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
+JSC::EncodedJSValue jsTestObjConstructorStaticReadOnlySymbolAttr(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
 JSC::EncodedJSValue jsTestObjReflectedStringAttr(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
 void setJSTestObjReflectedStringAttr(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::EncodedJSValue);
 JSC::EncodedJSValue jsTestObjReflectedIntegralAttr(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
@@ -420,6 +423,7 @@ static const HashTableValue JSTestObjConstructorTableValues[] =
     { "staticReadOnlyLongAttr", DontDelete | ReadOnly, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructorStaticReadOnlyLongAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
     { "staticStringAttr", DontDelete, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructorStaticStringAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjConstructorStaticStringAttr) } },
     { "TestSubObj", DontDelete | ReadOnly, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructorTestSubObj), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+    { "staticReadOnlySymbolAttr", DontDelete | ReadOnly, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructorStaticReadOnlySymbolAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
     { "staticMethodWithCallbackAndOptionalArg", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionStaticMethodWithCallbackAndOptionalArg), (intptr_t) (0) } },
     { "staticMethodWithCallbackArg", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionStaticMethodWithCallbackArg), (intptr_t) (1) } },
     { "classMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionClassMethod), (intptr_t) (0) } },
@@ -494,6 +498,7 @@ static const HashTableValue JSTestObjPrototypeTableValues[] =
     { "testObjAttr", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjTestObjAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjTestObjAttr) } },
     { "XMLObjAttr", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjXMLObjAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjXMLObjAttr) } },
     { "create", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCreate), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjCreate) } },
+    { "readOnlySymbolAttr", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReadOnlySymbolAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
     { "reflectedStringAttr", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReflectedStringAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjReflectedStringAttr) } },
     { "reflectedIntegralAttr", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReflectedIntegralAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjReflectedIntegralAttr) } },
     { "reflectedUnsignedIntegralAttr", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReflectedUnsignedIntegralAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjReflectedUnsignedIntegralAttr) } },
@@ -1025,6 +1030,33 @@ EncodedJSValue jsTestObjCreate(ExecState* state, JSObject* slotBase, EncodedJSVa
 }
 
 
+EncodedJSValue jsTestObjReadOnlySymbolAttr(ExecState* state, JSObject* slotBase, EncodedJSValue thisValue, PropertyName)
+{
+    UNUSED_PARAM(state);
+    UNUSED_PARAM(slotBase);
+    UNUSED_PARAM(thisValue);
+    JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(JSValue::decode(thisValue));
+    if (UNLIKELY(!castedThis)) {
+        if (jsDynamicCast<JSTestObjPrototype*>(slotBase))
+            return reportDeprecatedGetterError(*state, "TestObj", "readOnlySymbolAttr");
+        return throwGetterTypeError(*state, "TestObj", "readOnlySymbolAttr");
+    }
+    auto& impl = castedThis->impl();
+    JSValue result = Symbol::create(state->vm(), *(impl.readOnlySymbolAttr()).uid());
+    return JSValue::encode(result);
+}
+
+
+EncodedJSValue jsTestObjConstructorStaticReadOnlySymbolAttr(ExecState* state, JSObject* slotBase, EncodedJSValue thisValue, PropertyName)
+{
+    UNUSED_PARAM(state);
+    UNUSED_PARAM(slotBase);
+    UNUSED_PARAM(thisValue);
+    JSValue result = Symbol::create(state->vm(), *(TestObj::staticReadOnlySymbolAttr()).uid());
+    return JSValue::encode(result);
+}
+
+
 EncodedJSValue jsTestObjReflectedStringAttr(ExecState* state, JSObject* slotBase, EncodedJSValue thisValue, PropertyName)
 {
     UNUSED_PARAM(state);
index 342d68585d20ffe873407fc451454ebb95199e1a..9eb563330b3b0f2643283935abc322559207727e 100644 (file)
@@ -62,6 +62,10 @@ enum _optional { "", "OptionalValue1", "OptionalValue2", "OptionalValue3" };
     attribute TestObj                  XMLObjAttr;
     attribute boolean                  create;
 
+    // Readonly Symbol typed attributes.
+    readonly attribute Symbol readOnlySymbolAttr;
+    static readonly attribute Symbol staticReadOnlySymbolAttr;
+
     // Reflected DOM attributes
     [Reflect] attribute DOMString reflectedStringAttr;
     [Reflect] attribute long reflectedIntegralAttr;