Follow-up fix for:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 21:18:23 +0000 (21:18 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 21:18:23 +0000 (21:18 +0000)
JavaScript bindings are unnecessarily checking for impossible empty JSValue arguments
https://bugs.webkit.org/show_bug.cgi?id=145811

Reviewed by Antti Koivisto.

There was one unusual case in the bindings generator that was depending on this.

* bindings/js/JSDOMBinding.h:
(WebCore::argumentOrNull): Deleted.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheck): Stop using argumentOrNull.
* bindings/scripts/test/JS/JSTestNamedConstructor.cpp: Updated.
* bindings/scripts/test/JS/JSTestObj.cpp: Updated.

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

index 6db4be2c0ce9be72245891e453ab7ceafad36a48..e327ebdf39d37c1310065cd0bb3d32132ea789c5 100644 (file)
@@ -1,3 +1,20 @@
+2015-06-09  Darin Adler  <darin@apple.com>
+
+        Follow-up fix for:
+        JavaScript bindings are unnecessarily checking for impossible empty JSValue arguments
+        https://bugs.webkit.org/show_bug.cgi?id=145811
+
+        Reviewed by Antti Koivisto.
+
+        There was one unusual case in the bindings generator that was depending on this.
+
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::argumentOrNull): Deleted.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateParametersCheck): Stop using argumentOrNull.
+        * bindings/scripts/test/JS/JSTestNamedConstructor.cpp: Updated.
+        * bindings/scripts/test/JS/JSTestObj.cpp: Updated.
+
 2015-06-09  Darin Adler  <darin@apple.com>
 
         JavaScript bindings are unnecessarily checking for impossible empty JSValue arguments
index 9b12d297d2bff8fef03f6fdc5e658d806b1fd55e..5f23238da9e652bfae8b3e7510f0aefa4b591bc5 100644 (file)
@@ -238,11 +238,6 @@ template<typename WrapperClass, typename DOMClass> inline JSC::JSValue createNew
     return createWrapper<WrapperClass>(globalObject, domObject);
 }
 
-inline JSC::JSValue argumentOrNull(JSC::ExecState* exec, unsigned index)
-{
-    return index >= exec->argumentCount() ? JSC::JSValue() : exec->argument(index);
-}
-
 void addImpureProperty(const AtomicString&);
 
 const JSC::HashTable& getHashTableForGlobalData(JSC::VM&, const JSC::HashTable& staticTable);
index c14deda9bfef130d6dc79e5a4cd72c2c1c926b97..8bcd5e7afc05ad6c9857a2791730eded000b43e5 100644 (file)
@@ -3335,7 +3335,16 @@ sub GenerateParametersCheck
                 push(@$outputArray, "    if ($name.isNull())\n");
                 push(@$outputArray, "        return JSValue::encode(jsNull());\n");
             } else {
-                push(@$outputArray, "    " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, $optional && $defaultAttribute && $defaultAttribute eq "NullString" ? "argumentOrNull(exec, $argsIndex)" : "exec->argument($argsIndex)", $function->signature->extendedAttributes->{"Conditional"}) . ";\n");
+                my $outer;
+                my $inner;
+                if ($optional && $defaultAttribute && $defaultAttribute eq "NullString") {
+                    $outer = "exec->argumentCount() <= $argsIndex ? String() : ";
+                    $inner = "exec->uncheckedArgument($argsIndex)";
+                } else {
+                    $outer = "";
+                    $inner = "exec->argument($argsIndex)";
+                }
+                push(@$outputArray, "    " . GetNativeTypeFromSignature($parameter) . " $name = $outer" . JSValueToNative($parameter, $inner, $function->signature->extendedAttributes->{"Conditional"}) . ";\n");
             }
 
             # If a parameter is "an index" and it's negative it should throw an INDEX_SIZE_ERR exception.
index ff7ae417865aa4d8a69f2e2df79144d176f86d69..ac16246c9e5170e5b600668e4467523ade742af5 100644 (file)
@@ -134,7 +134,7 @@ EncodedJSValue JSC_HOST_CALL JSTestNamedConstructorNamedConstructor::constructJS
     String str2 = exec->argument(1).toString(exec)->value(exec);
     if (UNLIKELY(exec->hadException()))
         return JSValue::encode(jsUndefined());
-    String str3 = argumentOrNull(exec, 2).toString(exec)->value(exec);
+    String str3 = exec->argumentCount() <= 2 ? String() : exec->uncheckedArgument(2).toString(exec)->value(exec);
     if (UNLIKELY(exec->hadException()))
         return JSValue::encode(jsUndefined());
     RefPtr<TestNamedConstructor> object = TestNamedConstructor::createForJSConstructor(*castedThis->document(), str1, str2, str3, ec);
index 0e8a3dea2ec90f3355a9dec2fbbb45f753a71f4b..04f3e34d8e807b467888bb30dbac0063650c0a5b 100644 (file)
@@ -3578,7 +3578,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalStringI
         return throwThisTypeError(*exec, "TestObj", "methodWithOptionalStringIsNullString");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     auto& impl = castedThis->impl();
-    String str = argumentOrNull(exec, 0).toString(exec)->value(exec);
+    String str = exec->argumentCount() <= 0 ? String() : exec->uncheckedArgument(0).toString(exec)->value(exec);
     if (UNLIKELY(exec->hadException()))
         return JSValue::encode(jsUndefined());
     impl.methodWithOptionalStringIsNullString(str);