Title: [205048] trunk/Source/WebCore
Revision
205048
Author
cdu...@apple.com
Date
2016-08-26 14:34:21 -0700 (Fri, 26 Aug 2016)

Log Message

REGRESSION(r204028): Fix unused-but-set-variable warning in generated JSNavigator.cpp
https://bugs.webkit.org/show_bug.cgi?id=161252

Reviewed by Ryosuke Niwa.

Improve support for [Conditional] with overloaded operations in the IDL.

No new tests, updated bindings tests.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateHeader):
(GeneratePropertiesHashTable):
(getConditionalForFunctionConsideringOverloads):
(GenerateOverloadedFunctionOrConstructor):
(GenerateImplementation):
* bindings/scripts/test/JS/JSTestGlobalObject.cpp:
(WebCore::jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation): Deleted.
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionConditionalOverload1):
(WebCore::jsTestObjPrototypeFunctionConditionalOverload2):
(WebCore::jsTestObjPrototypeFunctionConditionalOverload):
(WebCore::jsTestObjPrototypeFunctionEnabledAtRuntimeOperation): Deleted.
(WebCore::jsTestObjConstructorFunctionOverloadedMethod1): Deleted.
* bindings/scripts/test/TestObj.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205047 => 205048)


--- trunk/Source/WebCore/ChangeLog	2016-08-26 21:23:45 UTC (rev 205047)
+++ trunk/Source/WebCore/ChangeLog	2016-08-26 21:34:21 UTC (rev 205048)
@@ -1,3 +1,30 @@
+2016-08-26  Chris Dumez  <cdu...@apple.com>
+
+        REGRESSION(r204028): Fix unused-but-set-variable warning in generated JSNavigator.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=161252
+
+        Reviewed by Ryosuke Niwa.
+
+        Improve support for [Conditional] with overloaded operations in the IDL.
+
+        No new tests, updated bindings tests.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateHeader):
+        (GeneratePropertiesHashTable):
+        (getConditionalForFunctionConsideringOverloads):
+        (GenerateOverloadedFunctionOrConstructor):
+        (GenerateImplementation):
+        * bindings/scripts/test/JS/JSTestGlobalObject.cpp:
+        (WebCore::jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation): Deleted.
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionConditionalOverload1):
+        (WebCore::jsTestObjPrototypeFunctionConditionalOverload2):
+        (WebCore::jsTestObjPrototypeFunctionConditionalOverload):
+        (WebCore::jsTestObjPrototypeFunctionEnabledAtRuntimeOperation): Deleted.
+        (WebCore::jsTestObjConstructorFunctionOverloadedMethod1): Deleted.
+        * bindings/scripts/test/TestObj.idl:
+
 2016-08-26  Beth Dakin  <bda...@apple.com>
 
         charactersAroundPosition can be wrong because it crosses editing boundaries

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (205047 => 205048)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-08-26 21:23:45 UTC (rev 205047)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-08-26 21:34:21 UTC (rev 205048)
@@ -1537,7 +1537,8 @@
                 $inAppleCopyright = 0;
             }
 
-            my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
+            my $conditionalAttribute = getConditionalForFunctionConsideringOverloads($function);
+            my $conditionalString = $conditionalAttribute ? $codeGenerator->GenerateConditionalStringFromAttributeValue($conditionalAttribute) : undef;
             push(@headerContent, "#if ${conditionalString}\n") if $conditionalString;
             my $functionName = GetFunctionName($interface, $className, $function);
             push(@headerContent, "JSC::EncodedJSValue JSC_HOST_CALL ${functionName}(JSC::ExecState*);\n");
@@ -1674,7 +1675,7 @@
 
         push(@$hashSpecials, ComputeFunctionSpecial($interface, $function));
 
-        my $conditional = $function->signature->extendedAttributes->{"Conditional"};
+        my $conditional = getConditionalForFunctionConsideringOverloads($function);
         if ($conditional) {
             $conditionals->{$name} = $conditional;
         }
@@ -1828,6 +1829,22 @@
     }
 }
 
+sub getConditionalForFunctionConsideringOverloads
+{
+    my $function = shift;
+
+    return $function->signature->extendedAttributes->{"Conditional"} unless $function->{overloads};
+
+    my %conditions;
+    foreach my $overload (@{$function->{overloads}}) {
+        if ($overload->signature->extendedAttributes->{"Conditional"}) {
+            $conditions{$overload->signature->extendedAttributes->{"Conditional"}} = 1;
+        }
+    }
+    return undef unless keys %conditions;
+    return join("|", keys %conditions);
+}
+
 # Implements the overload resolution algorithm, as defined in the Web IDL specification:
 # http://heycam.github.io/webidl/#es-overloads
 sub GenerateOverloadedFunctionOrConstructor
@@ -1913,6 +1930,9 @@
 
     my $maxArgCount = LengthOfLongestFunctionParameterList($function->{overloads});
 
+    my $conditionalAttribute = getConditionalForFunctionConsideringOverloads($function);
+    my $conditionalString = $conditionalAttribute ? $codeGenerator->GenerateConditionalStringFromAttributeValue($conditionalAttribute) : undef;
+    push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
     if ($isConstructor) {
         push(@implContent, "template<> EncodedJSValue JSC_HOST_CALL ${className}Constructor::construct(ExecState* state)\n");
     } else {
@@ -1998,7 +2018,9 @@
     } else {
         push(@implContent, "    return throwVMTypeError(state);\n")
     }
-    push(@implContent, "}\n\n");
+    push(@implContent, "}\n");
+    push(@implContent, "#endif\n") if $conditionalString;
+    push(@implContent, "\n");
 }
 
 # As per Web IDL specification, the length of a function Object is its number of mandatory parameters.
@@ -2291,7 +2313,8 @@
                 $inAppleCopyright = 0;
             }
 
-            my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
+            my $conditionalAttribute = getConditionalForFunctionConsideringOverloads($function);
+            my $conditionalString = $conditionalAttribute ? $codeGenerator->GenerateConditionalStringFromAttributeValue($conditionalAttribute) : undef;
             push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
             my $functionName = GetFunctionName($interface, $className, $function);
             push(@implContent, "JSC::EncodedJSValue JSC_HOST_CALL ${functionName}(JSC::ExecState*);\n");

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp (205047 => 205048)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp	2016-08-26 21:23:45 UTC (rev 205047)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp	2016-08-26 21:34:21 UTC (rev 205048)
@@ -395,6 +395,7 @@
 
 #endif
 
+#if ENABLE(TEST_FEATURE)
 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation(ExecState* state)
 {
     size_t argsCount = std::min<size_t>(1, state->argumentCount());
@@ -410,6 +411,7 @@
     }
     return argsCount < 1 ? throwVMError(state, createNotEnoughArgumentsError(state)) : throwVMTypeError(state);
 }
+#endif
 
 #if ENABLE(TEST_FEATURE)
 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(ExecState* state)

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (205047 => 205048)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-08-26 21:23:45 UTC (rev 205047)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-08-26 21:34:21 UTC (rev 205048)
@@ -784,6 +784,9 @@
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunction(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNeedsCustomElementReactionStack(JSC::ExecState*);
+#if ENABLE(CONDITION1) || ENABLE(CONDITION2)
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionConditionalOverload(JSC::ExecState*);
+#endif
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAttachShadowRoot(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionToString(JSC::ExecState*);
 
@@ -1379,6 +1382,11 @@
     { "testPromiseFunctionWithOptionalIntArgument", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument), (intptr_t) (0) } },
     { "testPromiseOverloadedFunction", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionTestPromiseOverloadedFunction), (intptr_t) (1) } },
     { "methodWithNeedsCustomElementReactionStack", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithNeedsCustomElementReactionStack), (intptr_t) (0) } },
+#if ENABLE(CONDITION1) || ENABLE(CONDITION2)
+    { "conditionalOverload", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionConditionalOverload), (intptr_t) (1) } },
+#else
+    { 0, 0, NoIntrinsic, { 0, 0 } },
+#endif
     { "attachShadowRoot", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionAttachShadowRoot), (intptr_t) (1) } },
     { "toString", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionToString), (intptr_t) (0) } },
 #if ENABLE(Condition1)
@@ -4204,6 +4212,7 @@
 
 #endif
 
+#if ENABLE(TEST_FEATURE)
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionEnabledAtRuntimeOperation(ExecState* state)
 {
     size_t argsCount = std::min<size_t>(1, state->argumentCount());
@@ -4219,6 +4228,7 @@
     }
     return argsCount < 1 ? throwVMError(state, createNotEnoughArgumentsError(state)) : throwVMTypeError(state);
 }
+#endif
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVoidMethod(ExecState* state)
 {
@@ -5978,6 +5988,7 @@
 
 #endif
 
+#if ENABLE(Condition1)
 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionOverloadedMethod1(ExecState* state)
 {
     size_t argsCount = std::min<size_t>(1, state->argumentCount());
@@ -5993,6 +6004,7 @@
     }
     return argsCount < 1 ? throwVMError(state, createNotEnoughArgumentsError(state)) : throwVMTypeError(state);
 }
+#endif
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionClassMethodWithClamp(ExecState* state)
 {
@@ -6521,6 +6533,64 @@
     return JSValue::encode(jsUndefined());
 }
 
+#if ENABLE(CONDITION1)
+static inline EncodedJSValue jsTestObjPrototypeFunctionConditionalOverload1(ExecState* state)
+{
+    JSValue thisValue = state->thisValue();
+    auto castedThis = jsDynamicCast<JSTestObj*>(thisValue);
+    if (UNLIKELY(!castedThis))
+        return throwThisTypeError(*state, "TestObject", "conditionalOverload");
+    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
+    auto& impl = castedThis->wrapped();
+    if (UNLIKELY(state->argumentCount() < 1))
+        return throwVMError(state, createNotEnoughArgumentsError(state));
+    auto str = state->argument(0).toWTFString(state);
+    if (UNLIKELY(state->hadException()))
+        return JSValue::encode(jsUndefined());
+    impl.conditionalOverload(WTFMove(str));
+    return JSValue::encode(jsUndefined());
+}
+
+#endif
+
+#if ENABLE(CONDITION2)
+static inline EncodedJSValue jsTestObjPrototypeFunctionConditionalOverload2(ExecState* state)
+{
+    JSValue thisValue = state->thisValue();
+    auto castedThis = jsDynamicCast<JSTestObj*>(thisValue);
+    if (UNLIKELY(!castedThis))
+        return throwThisTypeError(*state, "TestObject", "conditionalOverload");
+    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
+    auto& impl = castedThis->wrapped();
+    if (UNLIKELY(state->argumentCount() < 1))
+        return throwVMError(state, createNotEnoughArgumentsError(state));
+    auto a = convert<int32_t>(*state, state->argument(0), NormalConversion);
+    if (UNLIKELY(state->hadException()))
+        return JSValue::encode(jsUndefined());
+    impl.conditionalOverload(WTFMove(a));
+    return JSValue::encode(jsUndefined());
+}
+
+#endif
+
+#if ENABLE(CONDITION1) || ENABLE(CONDITION2)
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionConditionalOverload(ExecState* state)
+{
+    size_t argsCount = std::min<size_t>(1, state->argumentCount());
+    if (argsCount == 1) {
+        JSValue distinguishingArg = state->uncheckedArgument(0);
+#if ENABLE(CONDITION2)
+        if (distinguishingArg.isNumber())
+            return jsTestObjPrototypeFunctionConditionalOverload2(state);
+#endif
+#if ENABLE(CONDITION1)
+        return jsTestObjPrototypeFunctionConditionalOverload1(state);
+#endif
+    }
+    return argsCount < 1 ? throwVMError(state, createNotEnoughArgumentsError(state)) : throwVMTypeError(state);
+}
+#endif
+
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAttachShadowRoot(ExecState* state)
 {
     JSValue thisValue = state->thisValue();

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (205047 => 205048)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-08-26 21:23:45 UTC (rev 205047)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-08-26 21:34:21 UTC (rev 205048)
@@ -397,6 +397,12 @@
     [CEReactions] void methodWithNeedsCustomElementReactionStack();
 #endif
 
+#if defined(TESTING_JS)
+    // Overloading with conditionals.
+    [Conditional=CONDITION1] void conditionalOverload(DOMString str);
+    [Conditional=CONDITION2] void conditionalOverload(long a);
+#endif
+
     void attachShadowRoot(TestDictionary init);
 
     stringifier attribute USVString stringifierAttribute;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to