Title: [123962] trunk/Source/WebCore
Revision
123962
Author
[email protected]
Date
2012-07-28 09:11:42 -0700 (Sat, 28 Jul 2012)

Log Message

[Clamp] support in binding generator.
https://bugs.webkit.org/show_bug.cgi?id=77605

Patch by Vineet Chaudhary <[email protected]> on 2012-07-28
Reviewed by Kentaro Hara.

Currently [Clamp] extended attribute in IDL files.
Spec: http://www.w3.org/TR/2012/CR-WebIDL-20120419/#Clamp

Tests: TestObj.idl

* bindings/scripts/CodeGeneratorCPP.pm:
(SkipFunction): Skips methods with [Clamp] parameters.
* bindings/scripts/CodeGeneratorGObject.pm:
(SkipFunction): Skips methods with [Clamp] parameters.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheck): Support [Clamp] for JSBindings.
* bindings/scripts/CodeGeneratorObjC.pm:
(SkipFunction): Skips methods with [Clamp] parameters.
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateParametersCheck): Support [Clamp] for V8Bindings.
* bindings/scripts/IDLAttributes.txt: Added [Clamp] to attributes list.
* bindings/scripts/test/JS/JSTestObj.cpp: Test.
(WebCore::jsTestObjPrototypeFunctionClassMethodWithClamp):
* bindings/scripts/test/JS/JSTestObj.h:
* bindings/scripts/test/TestObj.idl:
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::TestObjV8Internal::classMethodWithClampCallback):
(TestObjV8Internal):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (123961 => 123962)


--- trunk/Source/WebCore/ChangeLog	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/ChangeLog	2012-07-28 16:11:42 UTC (rev 123962)
@@ -1,3 +1,34 @@
+2012-07-28  Vineet Chaudhary  <[email protected]>
+
+        [Clamp] support in binding generator.
+        https://bugs.webkit.org/show_bug.cgi?id=77605
+
+        Reviewed by Kentaro Hara.
+
+        Currently [Clamp] extended attribute in IDL files.
+        Spec: http://www.w3.org/TR/2012/CR-WebIDL-20120419/#Clamp
+
+        Tests: TestObj.idl
+
+        * bindings/scripts/CodeGeneratorCPP.pm:
+        (SkipFunction): Skips methods with [Clamp] parameters.
+        * bindings/scripts/CodeGeneratorGObject.pm:
+        (SkipFunction): Skips methods with [Clamp] parameters.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateParametersCheck): Support [Clamp] for JSBindings.
+        * bindings/scripts/CodeGeneratorObjC.pm:
+        (SkipFunction): Skips methods with [Clamp] parameters.
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateParametersCheck): Support [Clamp] for V8Bindings.
+        * bindings/scripts/IDLAttributes.txt: Added [Clamp] to attributes list.
+        * bindings/scripts/test/JS/JSTestObj.cpp: Test.
+        (WebCore::jsTestObjPrototypeFunctionClassMethodWithClamp):
+        * bindings/scripts/test/JS/JSTestObj.h:
+        * bindings/scripts/test/TestObj.idl:
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::TestObjV8Internal::classMethodWithClampCallback):
+        (TestObjV8Internal):
+
 2012-07-27  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r123908.

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorCPP.pm (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorCPP.pm	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorCPP.pm	2012-07-28 16:11:42 UTC (rev 123962)
@@ -206,6 +206,7 @@
 
     foreach my $param (@{$function->parameters}) {
         return 1 if $codeGenerator->GetSequenceType($param->type);
+        return 1 if $param->extendedAttributes->{"Clamp"};
     }
 
     # FIXME: This is typically used to add script execution state arguments to the method.

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2012-07-28 16:11:42 UTC (rev 123962)
@@ -247,6 +247,7 @@
     # code generator doesn't know how to auto-generate MediaQueryListListener or sequence<T>.
     foreach my $param (@{$function->parameters}) {
         if ($param->extendedAttributes->{"Callback"} ||
+            $param->extendedAttributes->{"Clamp"} ||
             $param->type eq "MediaQueryListListener" ||
             $codeGenerator->GetSequenceType($param->type)) {
             return 1;

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2012-07-28 16:11:42 UTC (rev 123962)
@@ -2607,6 +2607,14 @@
                 push(@$outputArray, "    }\n");
                 push(@$outputArray, "    RefPtr<$argType> $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n");
             }
+        } elsif ($parameter->extendedAttributes->{"Clamp"}) {
+                my $nativeValue = "${name}NativeValue";
+                push(@$outputArray, "    $argType $name = 0;\n");
+                push(@$outputArray, "    double $nativeValue = exec->argument($argsIndex).toNumber(exec);\n");
+                push(@$outputArray, "    if (exec->hadException())\n");
+                push(@$outputArray, "        return JSValue::encode(jsUndefined());\n\n");
+                push(@$outputArray, "    if (!isnan(objArgsShortNativeValue))\n");
+                push(@$outputArray, "        $name = clampTo<$argType>($nativeValue);\n\n");
         } else {
             # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an
             # interface type, then if the incoming value does not implement that interface, a TypeError

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm	2012-07-28 16:11:42 UTC (rev 123962)
@@ -457,6 +457,7 @@
     foreach my $param (@{$function->parameters}) {
         return 1 if $codeGenerator->GetSequenceType($param->type);
         return 1 if $codeGenerator->GetArrayType($param->type);
+        return 1 if $param->extendedAttributes->{"Clamp"};
     }
 
     return 0;

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2012-07-28 16:11:42 UTC (rev 123962)
@@ -1680,6 +1680,13 @@
                 $parameterCheckString .= "        return throwError(TYPE_MISMATCH_ERR, args.GetIsolate());\n";
                 $parameterCheckString .= "    RefPtr<" . $parameter->type . "> $parameterName = ${className}::create(args[$paramIndex], getScriptExecutionContext());\n";
             }
+        } elsif ($parameter->extendedAttributes->{"Clamp"}) {
+                my $nativeValue = "${parameterName}NativeValue";
+                my $paramType = $parameter->type;
+                $parameterCheckString .= "    $paramType $parameterName = 0\n";
+                $parameterCheckString .= "    EXCEPTION_BLOCK(double, $nativeValue, args[$paramIndex]->NumberValue());\n";
+                $parameterCheckString .= "    if (!isnan($nativeValue))\n";
+                $parameterCheckString .= "        $parameterName = clampTo<$paramType>($nativeValue);\n";
         } elsif ($parameter->type eq "SerializedScriptValue") {
             AddToImplIncludes("SerializedScriptValue.h");
             my $useTransferList = 0;

Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2012-07-28 16:11:42 UTC (rev 123962)
@@ -25,6 +25,7 @@
 Callback
 CheckSecurity
 CheckSecurityForNode
+Clamp
 Conditional=*
 Constructor
 ConstructorParameters=*

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


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2012-07-28 16:11:42 UTC (rev 123962)
@@ -305,6 +305,7 @@
     { "conditionalMethod3", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionConditionalMethod3), (intptr_t)0, NoIntrinsic },
 #endif
     { "overloadedMethod", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOverloadedMethod), (intptr_t)2, NoIntrinsic },
+    { "classMethodWithClamp", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionClassMethodWithClamp), (intptr_t)2, NoIntrinsic },
     { "methodWithUnsignedLongSequence", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithUnsignedLongSequence), (intptr_t)1, NoIntrinsic },
     { "stringArrayFunction", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionStringArrayFunction), (intptr_t)1, NoIntrinsic },
     { "getSVGDocument", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionGetSVGDocument), (intptr_t)0, NoIntrinsic },
@@ -2345,6 +2346,36 @@
 
 #endif
 
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionClassMethodWithClamp(ExecState* exec)
+{
+    JSValue thisValue = exec->hostThisValue();
+    if (!thisValue.inherits(&JSTestObj::s_info))
+        return throwVMTypeError(exec);
+    JSTestObj* castedThis = jsCast<JSTestObj*>(asObject(thisValue));
+    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestObj::s_info);
+    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
+    if (exec->argumentCount() < 2)
+        return throwVMError(exec, createNotEnoughArgumentsError(exec));
+    unsigned short objArgsShort = 0;
+    double objArgsShortNativeValue = exec->argument(0).toNumber(exec);
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    if (!isnan(objArgsShortNativeValue))
+        objArgsShort = clampTo<unsigned short>(objArgsShortNativeValue);
+
+    unsigned long objArgsLong = 0;
+    double objArgsLongNativeValue = exec->argument(1).toNumber(exec);
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    if (!isnan(objArgsShortNativeValue))
+        objArgsLong = clampTo<unsigned long>(objArgsLongNativeValue);
+
+    impl->classMethodWithClamp(objArgsShort, objArgsLong);
+    return JSValue::encode(jsUndefined());
+}
+
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithUnsignedLongSequence(ExecState* exec)
 {
     JSValue thisValue = exec->hostThisValue();

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h	2012-07-28 16:11:42 UTC (rev 123962)
@@ -203,6 +203,7 @@
 #if ENABLE(Condition1)
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionOverloadedMethod1(JSC::ExecState*);
 #endif
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionClassMethodWithClamp(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithUnsignedLongSequence(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionStringArrayFunction(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionGetSVGDocument(JSC::ExecState*);

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


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2012-07-28 16:11:42 UTC (rev 123962)
@@ -189,6 +189,8 @@
         [Conditional=Condition1] static void overloadedMethod1(in long arg);
         [Conditional=Condition1] static void overloadedMethod1(in DOMString type);
 
+        void classMethodWithClamp(in [Clamp] unsigned short objArgsShort, in [Clamp] unsigned long objArgsLong);
+
 #if defined(TESTING_V8)
         // 'V8EnabledAtRuntime' methods and attributes.
         [V8EnabledAtRuntime] void enabledAtRuntimeMethod1(in long longArg);

Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp (123961 => 123962)


--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp	2012-07-28 15:18:00 UTC (rev 123961)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp	2012-07-28 16:11:42 UTC (rev 123962)
@@ -1722,6 +1722,24 @@
 
 #endif // ENABLE(Condition1)
 
+static v8::Handle<v8::Value> classMethodWithClampCallback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.TestObj.classMethodWithClamp");
+    if (args.Length() < 2)
+        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
+    TestObj* imp = V8TestObj::toNative(args.Holder());
+    unsigned short objArgsShort = 0
+    EXCEPTION_BLOCK(double, objArgsShortNativeValue, args[0]->NumberValue());
+    if (!isnan(objArgsShortNativeValue))
+        objArgsShort = clampTo<unsigned short>(objArgsShortNativeValue);
+    unsigned long objArgsLong = 0
+    EXCEPTION_BLOCK(double, objArgsLongNativeValue, args[1]->NumberValue());
+    if (!isnan(objArgsLongNativeValue))
+        objArgsLong = clampTo<unsigned long>(objArgsLongNativeValue);
+    imp->classMethodWithClamp(objArgsShort, objArgsLong);
+    return v8::Handle<v8::Value>();
+}
+
 static v8::Handle<v8::Value> enabledAtRuntimeMethod1Callback(const v8::Arguments& args)
 {
     INC_STATS("DOM.TestObj.enabledAtRuntimeMethod1");
@@ -2068,6 +2086,7 @@
     {"conditionalMethod3", TestObjV8Internal::conditionalMethod3Callback},
 #endif
     {"overloadedMethod", TestObjV8Internal::overloadedMethodCallback},
+    {"classMethodWithClamp", TestObjV8Internal::classMethodWithClampCallback},
     {"stringArrayFunction", TestObjV8Internal::stringArrayFunctionCallback},
     {"getSVGDocument", TestObjV8Internal::getSVGDocumentCallback},
     {"mutablePointFunction", TestObjV8Internal::mutablePointFunctionCallback},
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to