JavaScriptCore:
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2007 22:07:43 +0000 (22:07 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2007 22:07:43 +0000 (22:07 +0000)
        Reviewed by Darin Adler.

        - fix an ASSERT when getIntIdentifier is called with 0 or -1

        * bindings/npruntime.cpp:
        (_NPN_GetIntIdentifier): We cannot use the hashmap for 0 and -1 since
        they are the empty value and the deleted value. Instead, keep the
        identifiers for those two integers in a static array.

WebKitTools:

        Reviewed by Darin Adler.

        - added a testGetIntIdentifier() method to TestNetscapePlugIn

        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
        (pluginInvoke):

LayoutTests:

        Reviewed by Darin Adler.

        - added a test of the behavior of getIntIdentifier with the integers
          0 and -1

        * plugins/getintidentifier-special-values-expected.txt: Added.
        * plugins/getintidentifier-special-values.html: Added.

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

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/npruntime.cpp
LayoutTests/ChangeLog
LayoutTests/plugins/getintidentifier-special-values-expected.txt [new file with mode: 0644]
LayoutTests/plugins/getintidentifier-special-values.html [new file with mode: 0644]
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c

index a4a708318aed10964bc10e9d2664a33c173cf2b7..dc38d8d5cc406758ee51eb176486dbc572fe1ee5 100644 (file)
@@ -1,3 +1,14 @@
+2007-12-03  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        - fix an ASSERT when getIntIdentifier is called with 0 or -1
+
+        * bindings/npruntime.cpp:
+        (_NPN_GetIntIdentifier): We cannot use the hashmap for 0 and -1 since
+        they are the empty value and the deleted value. Instead, keep the
+        identifiers for those two integers in a static array.
+
 2007-12-02  Darin Adler  <darin@apple.com>
 
         Reviewed by Mitz.
index 822b6aacaec5b99e409205ffeb50255414694da9..d762ff1092b2181f943f175c44e39476db603df0 100644 (file)
@@ -96,16 +96,29 @@ void _NPN_GetStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdenti
 
 NPIdentifier _NPN_GetIntIdentifier(int32_t intid)
 {
-    PrivateIdentifier* identifier = 0;
-    
-    identifier = getIntIdentifierMap()->get(intid);
-    if (identifier == 0) {
-        identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier));
-        // We never release identifier names, so this dictionary will grow.
-        identifier->isString = false;
-        identifier->value.number = intid;
-
-        getIntIdentifierMap()->set(intid, identifier);
+    PrivateIdentifier* identifier;
+
+    if (intid == 0 || intid == -1) {
+        static PrivateIdentifier* negativeOneAndZeroIdentifiers[2];
+
+        identifier = negativeOneAndZeroIdentifiers[intid + 1];
+        if (!identifier) {
+            identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier));
+            identifier->isString = false;
+            identifier->isString = intid;
+
+            negativeOneAndZeroIdentifiers[intid + 1] = identifier;
+        }
+    } else {
+        identifier = getIntIdentifierMap()->get(intid);
+        if (!identifier) {
+            identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier));
+            // We never release identifier names, so this dictionary will grow.
+            identifier->isString = false;
+            identifier->value.number = intid;
+
+            getIntIdentifierMap()->set(intid, identifier);
+        }
     }
     return (NPIdentifier)identifier;
 }
index cbf3ccf20b1a2f47ce5a24fc2e128af8a3676360..8241fb2dacdea6961bc830acc30cf0b7fa21a544 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-03  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        - added a test of the behavior of getIntIdentifier with the integers
+          0 and -1
+
+        * plugins/getintidentifier-special-values-expected.txt: Added.
+        * plugins/getintidentifier-special-values.html: Added.
+
 2007-12-03  Rob Buis  <buis@kde.org>
 
         Reviewed by Darin.
diff --git a/LayoutTests/plugins/getintidentifier-special-values-expected.txt b/LayoutTests/plugins/getintidentifier-special-values-expected.txt
new file mode 100644 (file)
index 0000000..570f381
--- /dev/null
@@ -0,0 +1,2 @@
+PASS: getIntIdentifier(n) returned consistent identifiers for n = 1, 0 and -1.
+
diff --git a/LayoutTests/plugins/getintidentifier-special-values.html b/LayoutTests/plugins/getintidentifier-special-values.html
new file mode 100644 (file)
index 0000000..b75f93d
--- /dev/null
@@ -0,0 +1,61 @@
+<html>
+<body>
+    <pre id="console"></pre>
+    <embed id="plg" type="application/x-webkit-test-netscape"></embed>
+    <script>
+        function log(message)
+        {
+            document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+        }
+
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+
+        var plugin = document.getElementById("plg");
+
+        var pass = true;
+
+        var firstOneID = plugin.testGetIntIdentifier(1);
+        var firstZeroID = plugin.testGetIntIdentifier(0);
+        var firstMinusOneID = plugin.testGetIntIdentifier(-1);
+
+        if (firstOneID == firstZeroID) {
+            log ("FAIL: getIntIdentifier(1) and getIntIdentifier(0) returned the same identifier: " + firstOneID);
+            pass = false;
+        }
+
+        if (firstOneID == firstMinusOneID) {
+            log ("FAIL: getIntIdentifier(1) and getIntIdentifier(-1) returned the same identifier: " + firstOneID);
+            pass = false;
+        }
+
+        if (firstMinusOneID == firstZeroID) {
+            log ("FAIL: getIntIdentifier(0) and getIntIdentifier(-1) returned the same identifier: " + firstZeroID);
+            pass = false;
+        }
+
+        var secondOneID = plugin.testGetIntIdentifier(1);
+        var secondZeroID = plugin.testGetIntIdentifier(0);
+        var secondMinusOneID = plugin.testGetIntIdentifier(-1);
+
+        if (firstOneID != secondOneID) {
+            log("FAIL: getIntIdentifier(1) returned " + firstOneID + " the first time and " + secondOneID + " the second time.");
+            pass = false;
+        }
+
+        if (firstZeroID != secondZeroID) {
+            log("FAIL: getIntIdentifier(0) returned " + firstZeroID + " the first time and " + secondZeroID + " the second time.");
+            pass = false;
+        }
+
+        if (firstMinusOneID != secondMinusOneID) {
+            log("FAIL: getIntIdentifier(-1) returned " + firstMinusOneID + " the first time and " + secondMinusOneID + " the second time.");
+            pass = false;
+        }
+
+        if (pass)
+            log("PASS: getIntIdentifier(n) returned consistent identifiers for n = 1, 0 and -1.");
+
+    </script>
+</body>
+</html>
index a733ea732cf00e9d76f95a227778458b7c7060de..cc8b24f39812e452b83f13d86c61ae3cdcd3c974 100644 (file)
@@ -1,3 +1,12 @@
+2007-12-03  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        - added a testGetIntIdentifier() method to TestNetscapePlugIn
+
+        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
+        (pluginInvoke):
+
 2007-12-03  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Oliver.
index f9c808f02ef033a1cee42147a998698a13a94d36..41e00a34a6d62bed27f26cbb3ed8675c50840eda 100644 (file)
@@ -93,7 +93,8 @@ static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
 #define ID_TEST_INVOKE_DEFAULT      5
 #define ID_DESTROY_STREAM           6
 #define ID_TEST_ENUMERATE           7
-#define NUM_METHOD_IDENTIFIERS      8
+#define ID_TEST_GETINTIDENTIFIER    8
+#define NUM_METHOD_IDENTIFIERS      9
 
 static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
 static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
@@ -104,7 +105,8 @@ static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
     "getURLNotify",
     "testInvokeDefault",
     "destroyStream",
-    "testEnumerate"
+    "testEnumerate",
+    "testGetIntIdentifier"
 };
 
 static NPUTF8* createCStringFromNPVariant(const NPVariant *variant)
@@ -282,7 +284,7 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
             if (browser->enumerate(obj->npp, NPVARIANT_TO_OBJECT(args[0]), &identifiers, &count)) {
                 NPObject* outArray = NPVARIANT_TO_OBJECT(args[1]);
                 NPIdentifier pushIdentifier = browser->getstringidentifier("push");
-                
+
                 for (uint32_t i = 0; i < count; i++) {
                     NPUTF8* string = browser->utf8fromidentifier(identifiers[i]);
                     
@@ -296,7 +298,7 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
                     browser->releasevariantvalue(&browserResult);
                     browser->memfree(string);
                 }
-                
+
                 browser->memfree(identifiers);
             }
             
@@ -307,7 +309,13 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
         NPError npError = browser->destroystream(obj->npp, obj->stream, NPRES_USER_BREAK);
         INT32_TO_NPVARIANT(npError, *result);
         return true;        
-    } 
+    } else if (name == pluginMethodIdentifiers[ID_TEST_GETINTIDENTIFIER]) {
+        if (argCount == 1 && NPVARIANT_IS_DOUBLE(args[0])) {
+            NPIdentifier identifier = browser->getintidentifier((int)NPVARIANT_TO_DOUBLE(args[0]));
+            INT32_TO_NPVARIANT((int32)identifier, *result);
+            return true;
+        }
+    }
     return false;
 }