JavaScriptCore:
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Mar 2007 23:38:23 +0000 (23:38 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Mar 2007 23:38:23 +0000 (23:38 +0000)
        Reviewed by Geoff.

        * bindings/NP_jsobject.cpp:
        (_NPN_InvokeDefault):
        Call JSObject:call for native JavaScript objects.

LayoutTests:

        Reviewed by Geoff.

        Add NPN_InvokeDefault test.

        * plugins/netscape-invoke-default-expected.txt: Added.
        * plugins/netscape-invoke-default.html: Added.

WebKitTools:

        Reviewed by Geoff.

        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
        (pluginInvoke):
        Add new function which takes a function and calls it using NPN_InvokeDefault.

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

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/NP_jsobject.cpp
LayoutTests/ChangeLog
LayoutTests/plugins/netscape-invoke-default-expected.txt [new file with mode: 0644]
LayoutTests/plugins/netscape-invoke-default.html [new file with mode: 0644]
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c

index bceb03294ec417dbce844f30bbc40afc684fb177..6e62cbd016bbab9c8598884bed74c96fbf418784 100644 (file)
@@ -1,3 +1,11 @@
+2007-03-27  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        * bindings/NP_jsobject.cpp:
+        (_NPN_InvokeDefault):
+        Call JSObject:call for native JavaScript objects.
+
 2007-03-26  David Carson  <dacarson@gmail.com>
 
         Reviewed by Darin, landed by Anders.
index 1bb8a6a167e0ae72b3d52a360888835173c92ae7..c63529bf58f160cd2298178fec8b486b79b6466d 100644 (file)
@@ -102,9 +102,29 @@ NPObject *_NPN_CreateNoScriptObject(void)
 
 bool _NPN_InvokeDefault(NPP, NPObject* o, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
-    if (o->_class == NPScriptObjectClass)
-        // No notion of a default function on JS objects. Just return false, can't handle.
-        return false;
+    if (o->_class == NPScriptObjectClass) {
+        JavaScriptObject* obj = (JavaScriptObject*)o; 
+        if (!_isSafeScript(obj))
+            return false;        
+        
+        // Lookup the function object.
+        RootObject* rootObject = obj->rootObject;
+        if (!rootObject || !rootObject->isValid())
+            return false;
+        
+        ExecState* exec = rootObject->interpreter()->globalExec();
+        JSLock lock;
+        
+        // Call the function object.
+        JSObject *funcImp = static_cast<JSObject*>(obj->imp);
+        List argList = listFromVariantArgs(exec, args, argCount);
+        JSValue *resultV = funcImp->call (exec, funcImp, argList);
+        
+        // Convert and return the result of the function call.
+        convertValueToNPVariant(exec, resultV, result);
+        return true;        
+    }
+
     if (o->_class->invokeDefault)
         return o->_class->invokeDefault(o, args, argCount, result);    
     VOID_TO_NPVARIANT(*result);
index da721cfa3fcf9de5f81ebc449e058b62624a14d7..91fbda28f60cc7812a3beb8e69d7108e6027f6c7 100644 (file)
@@ -1,3 +1,12 @@
+2007-03-27  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        Add NPN_InvokeDefault test.
+        
+        * plugins/netscape-invoke-default-expected.txt: Added.
+        * plugins/netscape-invoke-default.html: Added.
+
 2007-03-27  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by darin
diff --git a/LayoutTests/plugins/netscape-invoke-default-expected.txt b/LayoutTests/plugins/netscape-invoke-default-expected.txt
new file mode 100644 (file)
index 0000000..f3c2408
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that it's possible to call NPN_InvokeDefault on a JavaScript object. If this test succeeded, the text "SUCCESS" should be shown below.
+SUCCESS
+
diff --git a/LayoutTests/plugins/netscape-invoke-default.html b/LayoutTests/plugins/netscape-invoke-default.html
new file mode 100644 (file)
index 0000000..8d8d263
--- /dev/null
@@ -0,0 +1,29 @@
+<html>
+<script>
+function runTest()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+        
+    var successCount = 0;
+    var plugin = document.getElementById("testPlugin");
+    var retval = plugin.testInvokeDefault(
+        function f(str) { 
+            if (f == this && str == 'test')
+                successCount++;
+        });
+    
+    if (retval)
+        successCount++;
+        
+    if (successCount == 2)
+        document.getElementById('result').innerHTML = 'SUCCESS'
+}
+</script>
+
+<body onload="runTest();">
+This tests that it's possible to call NPN_InvokeDefault on a JavaScript object. If this test succeeded, the text "SUCCESS" should be shown below.
+<div id="result">FAILURE</div>
+<embed id="testPlugin" type="application/x-webkit-test-netscape" width="200" height="200"></embed>
+</body>
+</html>
index 7fc5904c63bc70703fdcfc982f6d0f926b7e540e..b1a6fc6d435d3241ddc8dfdedf2fe1f30e49db38 100644 (file)
@@ -1,3 +1,11 @@
+2007-03-27  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
+        (pluginInvoke):
+        Add new function which takes a function and calls it using NPN_InvokeDefault.
+
 2007-03-27  Adele Peterson  <adele@apple.com>
 
         Adding comment.
index 78bce0e1e1da8cd24c69e8f01512dbd8e3613488..38843004a8006872b1d925880685c7bd5b3b89b8 100644 (file)
@@ -80,8 +80,8 @@ static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
 #define ID_REMOVE_DEFAULT_METHOD    2
 #define ID_TEST_DOM_ACCESS          3
 #define ID_TEST_GET_URL_NOTIFY      4
-
-#define NUM_METHOD_IDENTIFIERS      5
+#define ID_TEST_INVOKE_DEFAULT      5
+#define NUM_METHOD_IDENTIFIERS      6
 
 static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
 static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
@@ -90,6 +90,7 @@ static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
     "removeDefaultMethod",
     "testDOMAccess",
     "getURLNotify",
+    "testInvokeDefault"
 };
 
 static NPUTF8* createCStringFromNPVariant(const NPVariant *variant)
@@ -227,6 +228,20 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
             VOID_TO_NPVARIANT(*result);
             return true;
         }
+    } else if (name == pluginMethodIdentifiers[ID_TEST_INVOKE_DEFAULT] && NPVARIANT_IS_OBJECT(args[0])) {
+        NPObject *callback = NPVARIANT_TO_OBJECT(args[0]);
+        
+        NPVariant args[1];
+        NPVariant browserResult;
+        
+        STRINGZ_TO_NPVARIANT("test", args[0]);
+        bool retval = browser->invokeDefault(obj->npp, callback, args, 1, &browserResult);
+        
+        if (retval)
+            browser->releasevariantvalue(&browserResult);
+        
+        BOOLEAN_TO_NPVARIANT(retval, *result);
+        return true;        
     }
 
     return false;