[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:30:31 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit cb6911fa8c076f93cc8ccf0e203fc9489a63c500
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Mar 23 23:21:03 2004 +0000

    	Added implementation of KJS::Value <-> NP_Object conversion functions.
    	Augmented test program for 'C' bindings.
    	Added asserts and parameter checking to all public API.
    
            Reviewed by Ken.
    
            * JavaScriptCore.pbproj/project.pbxproj:
            * bindings/NP_jsobject.cpp:
            (NP_ToString):
            * bindings/NP_jsobject.h: Added.
            * bindings/NP_runtime.cpp:
            (NP_IdentifierFromUTF8):
            (NP_IsValidIdentifier):
            (NP_GetIdentifiers):
            (NP_CreateObject):
            (NP_RetainObject):
            (NP_ReleaseObject):
            (NP_IsKindOfClass):
            (NP_SetExceptionWithUTF8):
            (NP_SetException):
            (NP_IntFromNumber):
            (NP_FloatFromNumber):
            (NP_DoubleFromNumber):
            (NP_CreateStringWithUTF8):
            (NP_CreateStringWithUTF16):
            (NP_DeallocateUTF8):
            (NP_UTF8FromString):
            (NP_UTF16FromString):
            (NP_StringLength):
            (NP_BoolFromBoolean):
            * bindings/NP_runtime.h:
            * bindings/c/c_instance.cpp:
            (CInstance::invokeMethod):
            * bindings/c/c_utility.cpp:
            (coerceValueToNPString):
            (convertValueToNPValueType):
            (convertNPValueTypeToValue):
            * bindings/c/c_utility.h:
            * bindings/test.js:
            * bindings/testC.js: Added.
            * bindings/testbindings.cpp:
            (logMessage):
            (setDoubleValue):
            (setIntValue):
            (setStringValue):
            (setBooleanValue):
            (getDoubleValue):
            (getIntValue):
            (getStringValue):
            (getBooleanValue):
            (myInterfaceInvoke):
            (myInterfaceAllocate):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6249 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 8a17c06..d9b7bbd 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,58 @@
+2004-03-23  Richard Williamson   <rjw at apple.com>
+
+	Added implementation of KJS::Value <-> NP_Object conversion functions.
+	Augmented test program for 'C' bindings.
+	Added asserts and parameter checking to all public API.	
+
+        Reviewed by Ken.
+
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * bindings/NP_jsobject.cpp:
+        (NP_ToString):
+        * bindings/NP_jsobject.h: Added.
+        * bindings/NP_runtime.cpp:
+        (NP_IdentifierFromUTF8):
+        (NP_IsValidIdentifier):
+        (NP_GetIdentifiers):
+        (NP_CreateObject):
+        (NP_RetainObject):
+        (NP_ReleaseObject):
+        (NP_IsKindOfClass):
+        (NP_SetExceptionWithUTF8):
+        (NP_SetException):
+        (NP_IntFromNumber):
+        (NP_FloatFromNumber):
+        (NP_DoubleFromNumber):
+        (NP_CreateStringWithUTF8):
+        (NP_CreateStringWithUTF16):
+        (NP_DeallocateUTF8):
+        (NP_UTF8FromString):
+        (NP_UTF16FromString):
+        (NP_StringLength):
+        (NP_BoolFromBoolean):
+        * bindings/NP_runtime.h:
+        * bindings/c/c_instance.cpp:
+        (CInstance::invokeMethod):
+        * bindings/c/c_utility.cpp:
+        (coerceValueToNPString):
+        (convertValueToNPValueType):
+        (convertNPValueTypeToValue):
+        * bindings/c/c_utility.h:
+        * bindings/test.js:
+        * bindings/testC.js: Added.
+        * bindings/testbindings.cpp:
+        (logMessage):
+        (setDoubleValue):
+        (setIntValue):
+        (setStringValue):
+        (setBooleanValue):
+        (getDoubleValue):
+        (getIntValue):
+        (getStringValue):
+        (getBooleanValue):
+        (myInterfaceInvoke):
+        (myInterfaceAllocate):
+
 === Safari-133 ===
 
 2004-03-19  Darin Adler  <darin at apple.com>
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index 391cc74..ba23b57 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -254,6 +254,7 @@
 				5182A47105FFD45000CBD2F2,
 				5182A48E05FFFDC500CBD2F2,
 				5182A53D06012C3000CBD2F2,
+				517BE7F50610E39600221947,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -588,6 +589,21 @@
 			settings = {
 			};
 		};
+		517BE7F40610E39600221947 = {
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			lastKnownFileType = sourcecode.c.h;
+			name = NP_jsobject.h;
+			path = bindings/NP_jsobject.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		517BE7F50610E39600221947 = {
+			fileRef = 517BE7F40610E39600221947;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		517D52DC056BF2F5003851BD = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
@@ -811,6 +827,7 @@
 				5182A4FB06010F8200CBD2F2,
 				5182A47005FFD45000CBD2F2,
 				51532CC705F7FD2C00EC779C,
+				517BE7F40610E39600221947,
 				515B876A05F532B900EABBF9,
 				515B879205F535B300EABBF9,
 				517D52DC056BF2F5003851BD,
diff --git a/JavaScriptCore/bindings/NP_jsobject.cpp b/JavaScriptCore/bindings/NP_jsobject.cpp
index ca684a1..c2192a7 100644
--- a/JavaScriptCore/bindings/NP_jsobject.cpp
+++ b/JavaScriptCore/bindings/NP_jsobject.cpp
@@ -22,13 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
-#include <NP_runtime.h>
-
-#include <c_utility.h>
-
-#include <runtime.h>
-#include <runtime_object.h>
-#include <runtime_root.h>
+#include <NP_jsobject.h>
 
 using namespace KJS;
 using namespace KJS::Bindings;
@@ -39,13 +33,6 @@ static KJS::List listFromNPArray(KJS::ExecState *exec, NP_Object **args, unsigne
     return aList;
 }
 
-typedef struct
-{
-    NP_Object object;
-    KJS::ObjectImp *imp;
-    KJS::Bindings::RootObject *root;
-} JavaScriptObject;
-
 static NP_Object *jsAllocate()
 {
     return (NP_Object *)malloc(sizeof(JavaScriptObject));
@@ -175,7 +162,7 @@ void NP_ToString (NP_JavaScriptObject *o, NP_JavaScriptResultInterface resultCal
     Object thisObj = Object(const_cast<ObjectImp*>(obj->imp));
     ExecState *exec = obj->root->interpreter()->globalExec();
     
-    NP_String *value = (NP_String *)coerceValueToNPValueType(exec, thisObj, NP_StringValueType);
+    NP_String *value = (NP_String *)coerceValueToNPString(exec, thisObj);
 
     Interpreter::unlock();
     
diff --git a/WebCore/kwq/KWQEditCommand.h b/JavaScriptCore/bindings/NP_jsobject.h
similarity index 84%
copy from WebCore/kwq/KWQEditCommand.h
copy to JavaScriptCore/bindings/NP_jsobject.h
index 676eb03..054191e 100644
--- a/WebCore/kwq/KWQEditCommand.h
+++ b/JavaScriptCore/bindings/NP_jsobject.h
@@ -22,15 +22,18 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
+#include <NP_runtime.h>
 
-#include "htmlediting.h"
+#include <c_utility.h>
 
- at interface KWQEditCommand : NSObject
+#include <runtime.h>
+#include <runtime_object.h>
+#include <runtime_root.h>
+ 
+typedef struct
 {
-    khtml::EditCommandImpl *m_impl;   
-}
+    NP_Object object;
+    KJS::ObjectImp *imp;
+    KJS::Bindings::RootObject *root;
+} JavaScriptObject;
 
-+ (KWQEditCommand *)commandWithEditCommandImpl:(khtml::EditCommandImpl *)impl;
-- (khtml::EditCommandImpl *)impl;
-
- at end
\ No newline at end of file
diff --git a/JavaScriptCore/bindings/c/c_instance.cpp b/JavaScriptCore/bindings/c/c_instance.cpp
index 5e49c0d..1576b89 100644
--- a/JavaScriptCore/bindings/c/c_instance.cpp
+++ b/JavaScriptCore/bindings/c/c_instance.cpp
@@ -115,15 +115,18 @@ Value CInstance::invokeMethod (KJS::ExecState *exec, const MethodList &methodLis
 
     // Invoke the 'C' method.
     NP_Object *result = _object->_class->invoke (_object, ident, cArgs, count);
-    
-    resultValue = convertNPValueTypeToValue (exec, result);
-    
-    if (cArgs != localBuffer)
-        free ((void *)cArgs);
+    if (result) {
+        resultValue = convertNPValueTypeToValue (exec, result);
         
-    NP_ReleaseObject (result);
+        if (cArgs != localBuffer)
+            free ((void *)cArgs);
+            
+        NP_ReleaseObject (result);
+        
+        return resultValue;
+    }
     
-    return resultValue;
+    return Undefined();
 }
 
 
diff --git a/JavaScriptCore/bindings/c/c_utility.cpp b/JavaScriptCore/bindings/c/c_utility.cpp
index 062afb0..8c9166d 100644
--- a/JavaScriptCore/bindings/c/c_utility.cpp
+++ b/JavaScriptCore/bindings/c/c_utility.cpp
@@ -22,22 +22,104 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
+#include <c_instance.h> 
 #include <c_utility.h> 
+#include <internal.h>
+#include <runtime.h>
+#include <runtime_object.h>
+#include <runtime_root.h>
+#include <value.h>
+#include <NP_jsobject.h>
 
 using namespace KJS;
+using namespace KJS::Bindings;
 
-NP_Object *coerceValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value, NP_ValueType type)
+NP_Object *coerceValueToNPString (KJS::ExecState *exec, const KJS::Value &value)
 {
-    return 0;
+    UString ustring = value.toString(exec);
+    return NP_CreateStringWithUTF8 (ustring.UTF8String().c_str());
 }
 
 NP_Object *convertValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value)
 {
+    Type type = value.type();
+    
+    if (type == StringType) {
+        UString ustring = value.toString(exec);
+        return NP_CreateStringWithUTF8 (ustring.UTF8String().c_str());
+    }
+    else if (type == NumberType) {
+        return NP_CreateNumberWithDouble (value.toNumber(exec));
+    }
+    else if (type == BooleanType) {
+        return NP_CreateBoolean (value.toBoolean(exec));
+    }
+    else if (type == UnspecifiedType) {
+        return NP_GetUndefined();
+    }
+    else if (type == NullType) {
+        return NP_GetNull();
+    }
+    else if (type == ObjectType) {
+        KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());
+        if (strcmp(objectImp->classInfo()->className, "RuntimeObject") == 0) {
+            KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());
+            CInstance *instance = static_cast<CInstance*>(imp->getInternalInstance());
+            return instance->getObject();
+        }
+    }
+    
     return 0;
 }
 
 Value convertNPValueTypeToValue (KJS::ExecState *exec, const NP_Object *obj)
 {
+    if (NP_IsKindOfClass (obj, NP_BooleanClass)) {
+        if (NP_BoolFromBoolean ((NP_Boolean *)obj))
+            return KJS::Boolean (true);
+        return KJS::Boolean (false);
+    }
+    else if (NP_IsKindOfClass (obj, NP_NullClass)) {
+        return Null();
+    }
+    else if (NP_IsKindOfClass (obj, NP_UndefinedClass)) {
+        return Undefined();
+    }
+    else if (NP_IsKindOfClass (obj, NP_ArrayClass)) {
+        // FIXME:  Need to implement
+    }
+    else if (NP_IsKindOfClass (obj, NP_NumberClass)) {
+        return Number (NP_DoubleFromNumber((NP_Number *)obj));
+    }
+    else if (NP_IsKindOfClass (obj, NP_StringClass)) {
+
+        NP_UTF8 *utf8String = NP_UTF8FromString((NP_String *)obj);
+        CFStringRef stringRef = CFStringCreateWithCString (NULL, utf8String, kCFStringEncodingUTF8);
+        NP_DeallocateUTF8 (utf8String);
+
+        int length = CFStringGetLength (stringRef);
+        NP_UTF16 *buffer = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*length);
+
+        // Convert the string to UTF16.
+        CFRange range = { 0, length };
+        CFStringGetCharacters (stringRef, range, (UniChar *)buffer);
+        CFRelease (stringRef);
+
+        String resultString(UString((const UChar *)buffer,length));
+        free (buffer);
+        
+        return resultString;
+    }
+    else if (NP_IsKindOfClass (obj, NP_JavaScriptObjectClass)) {
+        // Get ObjectImp from NP_JavaScriptObject.
+        JavaScriptObject *o = (JavaScriptObject *)obj;
+        return Object(const_cast<ObjectImp*>(o->imp));
+    }
+    else {
+        //  Wrap NP_Object in a CInstance.
+        return Instance::createRuntimeObject(Instance::CLanguage, (void *)obj);
+    }
+    
     return Undefined();
 }
 
diff --git a/JavaScriptCore/bindings/c/c_utility.h b/JavaScriptCore/bindings/c/c_utility.h
index 7f2230c..3d73006 100644
--- a/JavaScriptCore/bindings/c/c_utility.h
+++ b/JavaScriptCore/bindings/c/c_utility.h
@@ -43,7 +43,7 @@ typedef enum
 } NP_ValueType;
 
 
-extern NP_Object *coerceValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value, NP_ValueType type);
+extern NP_Object *coerceValueToNPString (KJS::ExecState *exec, const KJS::Value &value);
 extern NP_Object *convertValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value);
 extern KJS::Value convertNPValueTypeToValue (KJS::ExecState *exec, const NP_Object *obj);
 
diff --git a/JavaScriptCore/bindings/npruntime.cpp b/JavaScriptCore/bindings/npruntime.cpp
index 6dffade..0a3d82d 100644
--- a/JavaScriptCore/bindings/npruntime.cpp
+++ b/JavaScriptCore/bindings/npruntime.cpp
@@ -78,44 +78,59 @@ static NP_Identifier identifierCount = 1;
 
 NP_Identifier NP_IdentifierFromUTF8 (const NP_UTF8 *name)
 {
-    NP_Identifier identifier = 0;
+    assert (name);
     
-    identifier = (NP_Identifier)CFDictionaryGetValue (getIdentifierDictionary(), (const void *)name);
-    if (identifier == 0) {
-        identifier = identifierCount++;
-        // We never release identifier names, so this dictionary will grow, as will
-        // the memory for the identifier name strings.
-        const char *identifierName = strdup (name);
+    if (name) {
+        NP_Identifier identifier = 0;
         
-        if (!identifierNames) {
-            identifierNames = (const char **)malloc (sizeof(const char *)*INITIAL_IDENTIFIER_NAME_COUNT);
-            maxIdentifierNames = INITIAL_IDENTIFIER_NAME_COUNT;
-        }
-        
-        if (identifierCount >= maxIdentifierNames) {
-            maxIdentifierNames *= 2;
-            identifierNames = (const char **)realloc ((void *)identifierNames, sizeof(const char *)*maxIdentifierNames);
-        }
-        
-        identifierNames[identifier] = identifierName;
+        identifier = (NP_Identifier)CFDictionaryGetValue (getIdentifierDictionary(), (const void *)name);
+        if (identifier == 0) {
+            identifier = identifierCount++;
+            // We never release identifier names, so this dictionary will grow, as will
+            // the memory for the identifier name strings.
+            const char *identifierName = strdup (name);
+            
+            if (!identifierNames) {
+                identifierNames = (const char **)malloc (sizeof(const char *)*INITIAL_IDENTIFIER_NAME_COUNT);
+                maxIdentifierNames = INITIAL_IDENTIFIER_NAME_COUNT;
+            }
+            
+            if (identifierCount >= maxIdentifierNames) {
+                maxIdentifierNames *= 2;
+                identifierNames = (const char **)realloc ((void *)identifierNames, sizeof(const char *)*maxIdentifierNames);
+            }
+            
+            identifierNames[identifier] = identifierName;
 
-        CFDictionaryAddValue (getIdentifierDictionary(), identifierName, (const void *)identifier);
+            CFDictionaryAddValue (getIdentifierDictionary(), identifierName, (const void *)identifier);
+        }
+        return identifier;
     }
-
-    return identifier;
+    
+    return 0;
 }
 
 bool NP_IsValidIdentifier (const NP_UTF8 *name)
 {
-    return CFDictionaryGetValue (getIdentifierDictionary(), (const void *)name) == 0 ? false : true;
+    assert (name);
+    
+    if (name)
+        return CFDictionaryGetValue (getIdentifierDictionary(), (const void *)name) == 0 ? false : true;
+
+    return false;
 }
 
 void NP_GetIdentifiers (const NP_UTF8 **names, int nameCount, NP_Identifier *identifiers)
 {
-    int i;
+    assert (names);
+    assert (identifiers);
     
-    for (i = 0; i < nameCount; i++) {
-        identifiers[i] = NP_IdentifierFromUTF8 (names[i]);
+    if (names && identifiers) {
+        int i;
+        
+        for (i = 0; i < nameCount; i++) {
+            identifiers[i] = NP_IdentifierFromUTF8 (names[i]);
+        }
     }
 }
 
@@ -129,23 +144,32 @@ const NP_UTF8 *NP_UTF8FromIdentifier (NP_Identifier identifier)
 
 NP_Object *NP_CreateObject (NP_Class *aClass)
 {
-    NP_Object *obj;
-    
-    if (aClass->allocate != NULL)
-        obj = aClass->allocate ();
-    else
-        obj = (NP_Object *)malloc (sizeof(NP_Object));
+    assert (aClass);
+
+    if (aClass) {
+        NP_Object *obj;
         
-    obj->_class = aClass;
-    obj->referenceCount = 1;
+        if (aClass->allocate != NULL)
+            obj = aClass->allocate ();
+        else
+            obj = (NP_Object *)malloc (sizeof(NP_Object));
+            
+        obj->_class = aClass;
+        obj->referenceCount = 1;
 
-    return obj;
+        return obj;
+    }
+    
+    return 0;
 }
 
 
 NP_Object *NP_RetainObject (NP_Object *obj)
 {
-    obj->referenceCount++;
+    assert (obj);
+
+    if (obj)
+        obj->referenceCount++;
 
     return obj;
 }
@@ -153,36 +177,51 @@ NP_Object *NP_RetainObject (NP_Object *obj)
 
 void NP_ReleaseObject (NP_Object *obj)
 {
+    assert (obj);
     assert (obj->referenceCount >= 1);
 
-    obj->referenceCount--;
-            
-    if (obj->referenceCount == 0) {
-        if (obj->_class->deallocate)
-            obj->_class->deallocate (obj);
-        else
-            free (obj);
+    if (obj && obj->referenceCount >= 1) {
+        obj->referenceCount--;
+                
+        if (obj->referenceCount == 0) {
+            if (obj->_class->deallocate)
+                obj->_class->deallocate (obj);
+            else
+                free (obj);
+        }
     }
 }
 
-bool NP_IsKindOfClass (NP_Object *obj, NP_Class *aClass)
+bool NP_IsKindOfClass (const NP_Object *obj, const NP_Class *aClass)
 {
-    if (obj->_class == aClass)
-        return true;
-
+    assert (obj);
+    assert (aClass);
+    
+    if (obj && aClass) {
+        if (obj->_class == aClass)
+            return true;
+    }
+    
     return false;
 }
 
+
 void NP_SetExceptionWithUTF8 (NP_Object *obj, const NP_UTF8 *message)
 {
-    NP_String *m = NP_CreateStringWithUTF8(message);
-    NP_SetException (obj, m);
-    NP_ReleaseObject (m);
+    assert (obj);
+    assert (message);
+ 
+    if (obj && message) {
+        NP_String *m = NP_CreateStringWithUTF8(message);
+        NP_SetException (obj, m);
+        NP_ReleaseObject (m);
+    }
 }
 
 
 void NP_SetException (NP_Object *obj, NP_String *message)
 {
+    // FIX ME.  Need to implement.
 }
 
 // ---------------------------------- Types ----------------------------------
@@ -238,23 +277,38 @@ NP_Number *NP_CreateNumberWithDouble (double d)
 
 int NP_IntFromNumber (NP_Number *obj)
 {
-    assert (NP_IsKindOfClass (obj, numberClass));
-    NumberObject *number = (NumberObject *)obj;
-    return (int)number->number;
+    assert (obj && NP_IsKindOfClass (obj, numberClass));
+
+    if (obj && NP_IsKindOfClass (obj, numberClass)) {
+        NumberObject *number = (NumberObject *)obj;
+        return (int)number->number;
+    }
+    
+    return 0;
 }
 
 float NP_FloatFromNumber (NP_Number *obj)
 {
-    assert (NP_IsKindOfClass (obj, numberClass));
-    NumberObject *number = (NumberObject *)obj;
-    return (float)number->number;
+    assert (obj && NP_IsKindOfClass (obj, numberClass));
+
+    if (obj && NP_IsKindOfClass (obj, numberClass)) {
+        NumberObject *number = (NumberObject *)obj;
+        return (float)number->number;
+    }
+    
+    return 0.;
 }
 
 double NP_DoubleFromNumber (NP_Number *obj)
 {
-    assert (NP_IsKindOfClass (obj, numberClass));
-    NumberObject *number = (NumberObject *)obj;
-    return number->number;
+    assert (obj && NP_IsKindOfClass (obj, numberClass));
+    
+    if (obj && NP_IsKindOfClass (obj, numberClass)) {
+        NumberObject *number = (NumberObject *)obj;
+        return number->number;
+    }
+    
+    return 0.;
 }
 
 
@@ -297,89 +351,118 @@ NP_Class *NP_StringClass = stringClass;
 
 NP_String *NP_CreateStringWithUTF8 (const NP_UTF8 *utf8String)
 {
-    StringObject *string = (StringObject *)NP_CreateObject (stringClass);
+    assert (utf8String);
+    
+    if (utf8String) {
+        StringObject *string = (StringObject *)NP_CreateObject (stringClass);
 
-    CFStringRef stringRef = CFStringCreateWithCString (NULL, utf8String, kCFStringEncodingUTF8);
+        CFStringRef stringRef = CFStringCreateWithCString (NULL, utf8String, kCFStringEncodingUTF8);
 
-    string->length = CFStringGetLength (stringRef);
-    string->string = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*string->length);
+        string->length = CFStringGetLength (stringRef);
+        string->string = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*string->length);
 
-    // Convert the string to UTF16.
-    CFRange range = { 0, string->length };
-    CFStringGetCharacters (stringRef, range, (UniChar *)string->string);
-    CFRelease (stringRef);
+        // Convert the string to UTF16.
+        CFRange range = { 0, string->length };
+        CFStringGetCharacters (stringRef, range, (UniChar *)string->string);
+        CFRelease (stringRef);
 
-    return (NP_String *)string;
+        return (NP_String *)string;
+    }
+    
+    return 0;
 }
 
 
 NP_String *NP_CreateStringWithUTF16 (const NP_UTF16 *utf16String, int32_t len)
 {
-    StringObject *string = (StringObject *)NP_CreateObject (stringClass);
-
-    string->length = len;
-    string->string = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*string->length);
-    memcpy ((void *)string->string, utf16String, sizeof(NP_UTF16)*string->length);
+    assert (utf16String);
     
-    return (NP_String *)string;
+    if (utf16String) {
+        StringObject *string = (StringObject *)NP_CreateObject (stringClass);
+
+        string->length = len;
+        string->string = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*string->length);
+        memcpy ((void *)string->string, utf16String, sizeof(NP_UTF16)*string->length);
+        
+        return (NP_String *)string;
+    }
+
+    return 0;
+}
+
+void NP_DeallocateUTF8 (NP_UTF8 *UTF8Buffer)
+{
+    free (UTF8Buffer);
 }
 
 NP_UTF8 *NP_UTF8FromString (NP_String *obj)
 {
-    assert (NP_IsKindOfClass (obj, stringClass));
+    assert (obj && NP_IsKindOfClass (obj, stringClass));
 
-    StringObject *string = (StringObject *)obj;
+    if (obj && NP_IsKindOfClass (obj, stringClass)) {
+        StringObject *string = (StringObject *)obj;
 
-    // Allow for max conversion factor.
-    UInt8 *buffer;
-    UInt8 _localBuffer[LOCAL_CONVERSION_BUFFER_SIZE];
-    CFIndex maxBufferLength;
-    
-    if (string->length*sizeof(UInt8)*8 > LOCAL_CONVERSION_BUFFER_SIZE) {
-        maxBufferLength = string->length*sizeof(UInt8)*8;
-        buffer = (UInt8 *)malloc(maxBufferLength);
-    }
-    else {
-        maxBufferLength = LOCAL_CONVERSION_BUFFER_SIZE;
-        buffer = _localBuffer;
+        // Allow for max conversion factor.
+        UInt8 *buffer;
+        UInt8 _localBuffer[LOCAL_CONVERSION_BUFFER_SIZE];
+        CFIndex maxBufferLength;
+        
+        if (string->length*sizeof(UInt8)*8 > LOCAL_CONVERSION_BUFFER_SIZE) {
+            maxBufferLength = string->length*sizeof(UInt8)*8;
+            buffer = (UInt8 *)malloc(maxBufferLength);
+        }
+        else {
+            maxBufferLength = LOCAL_CONVERSION_BUFFER_SIZE;
+            buffer = _localBuffer;
+        }
+        
+        // Convert the string to UTF8.
+        CFIndex usedBufferLength;
+        CFStringRef stringRef = CFStringCreateWithCharacters (NULL, (UniChar *)string->string, string->length);
+        CFRange range = { 0, string->length };
+        CFStringGetBytes (stringRef, range, kCFStringEncodingUTF8, 0, false, buffer, maxBufferLength, &usedBufferLength);
+        
+        NP_UTF8 *resultString = (NP_UTF8 *)malloc (usedBufferLength+1);
+        strncpy ((char *)resultString, (const char *)buffer, usedBufferLength);
+        char *cp = (char *)resultString;
+        cp[usedBufferLength] = 0;
+        
+        CFRelease (stringRef);
+        if (buffer != _localBuffer)
+            free ((void *)buffer);
+            
+        return resultString;
     }
     
-    // Convert the string to UTF8.
-    CFIndex usedBufferLength;
-    CFStringRef stringRef = CFStringCreateWithCharacters (NULL, (UniChar *)string->string, string->length);
-    CFRange range = { 0, string->length };
-    CFStringGetBytes (stringRef, range, kCFStringEncodingUTF8, 0, false, buffer, maxBufferLength, &usedBufferLength);
-    
-    NP_UTF8 *resultString = (NP_UTF8 *)malloc (usedBufferLength+1);
-    strncpy ((char *)resultString, (const char *)buffer, usedBufferLength);
-    char *cp = (char *)resultString;
-    cp[usedBufferLength] = 0;
-    
-    CFRelease (stringRef);
-    if (buffer != _localBuffer)
-        free ((void *)buffer);
-        
-    return resultString;
+    return 0;
 }
 
 NP_UTF16 *NP_UTF16FromString (NP_String *obj)
 {
-    assert (NP_IsKindOfClass (obj, stringClass));
+    assert (obj && NP_IsKindOfClass (obj, stringClass));
 
-    StringObject *string = (StringObject *)obj;
-    
-    NP_UTF16 *resultString = (NP_UTF16*)malloc(sizeof(int16_t)*string->length);
-    memcpy ((void *)resultString, string->string, sizeof(int16_t)*string->length);
+    if (obj && NP_IsKindOfClass (obj, stringClass)) {
+        StringObject *string = (StringObject *)obj;
+        
+        NP_UTF16 *resultString = (NP_UTF16*)malloc(sizeof(int16_t)*string->length);
+        memcpy ((void *)resultString, string->string, sizeof(int16_t)*string->length);
 
-    return resultString;
+        return resultString;
+    }
+    
+    return 0;
 }
 
 int32_t NP_StringLength (NP_String *obj)
 {
-    assert (NP_IsKindOfClass (obj, stringClass));
+    assert (obj && NP_IsKindOfClass (obj, stringClass));
 
-    StringObject *string = (StringObject *)obj;
-    return string->length;
+    if (obj && NP_IsKindOfClass (obj, stringClass)) {
+        StringObject *string = (StringObject *)obj;
+        return string->length;
+    }
+    
+    return 0;
 }
 
 // ---------------------------------- NP_Boolean ----------------------------------
@@ -435,12 +518,16 @@ NP_Boolean *NP_CreateBoolean (bool f)
 
 bool NP_BoolFromBoolean (NP_Boolean *obj)
 {
-    assert (NP_IsKindOfClass (obj, booleanClass) 
+    assert (obj && NP_IsKindOfClass (obj, booleanClass) 
             && ((BooleanObject *)obj == theTrueObject || (BooleanObject *)obj == theFalseObject));
 
-    BooleanObject *booleanObj = (BooleanObject *)obj;
-    if (booleanObj == theTrueObject)
-        return true;
+    if (obj && NP_IsKindOfClass (obj, booleanClass) 
+            && ((BooleanObject *)obj == theTrueObject || (BooleanObject *)obj == theFalseObject)) {
+        BooleanObject *booleanObj = (BooleanObject *)obj;
+        if (booleanObj == theTrueObject)
+            return true;
+    }
+    
     return false;
 }
 
diff --git a/JavaScriptCore/bindings/npruntime.h b/JavaScriptCore/bindings/npruntime.h
index b98b2c1..abf0103 100644
--- a/JavaScriptCore/bindings/npruntime.h
+++ b/JavaScriptCore/bindings/npruntime.h
@@ -35,7 +35,7 @@
  * Revision 4 (March 11, 2004):
  * Added additional convenience NP_SetExceptionWithUTF8().
  * Changed NP_HasPropertyInterface and NP_HasMethodInterface to take NP_Class
- * pointers instead of objects.
+ * pointers instead of NP_Object pointers.
  * Added NP_IsValidIdentifier().
  *
  * Revision 5 (March 17, 2004):
@@ -251,9 +251,11 @@ NP_String *NP_CreateStringWithUTF8 (const NP_UTF8 *utf8String);
 NP_String *NP_CreateStringWithUTF16 (const NP_UTF16 *utf16String, unsigned int len);
 
 /*
-    Memory returned from NP_UTF8FromString and NP_UTF16FromString must be freed by the caller.
+    Memory returned from NP_UTF8FromString must be deallocated
+    by calling NP_DeallocateUTF8.
 */
 NP_UTF8 *NP_UTF8FromString (NP_String *obj);
+void NP_DeallocateUTF8 (NP_UTF8 *UTF8Buffer);
 NP_UTF16 *NP_UTF16FromString (NP_String *obj);
 int32_t NP_StringLength (NP_String *obj);
 
@@ -292,7 +294,7 @@ NP_Object *NP_ObjectAtIndex (NP_Array *array, int32_t index);
     Returns true if the object is a kind of class as specified by
     aClass.
 */
-bool NP_IsKindOfClass (NP_Object *obj, NP_Class *aClass);
+bool NP_IsKindOfClass (const NP_Object *obj, const NP_Class *aClass);
 
 /*
     NP_SetException may be called to trigger a JavaScript exception upon return
diff --git a/JavaScriptCore/bindings/test.js b/JavaScriptCore/bindings/test.js
index e1075e0..5d4f79f 100644
--- a/JavaScriptCore/bindings/test.js
+++ b/JavaScriptCore/bindings/test.js
@@ -1,6 +1,12 @@
-myInterface.logMessage ("starting test");
+myInterface.logMessage ("Starting test");
 
-myInterface.logMessage ("myInterface.getInt() = " + myInterface.getInt());
+myInterface.logMessage ("Testing properties:");
+myInterface.logMessage ("myInterface.doubleValue = " + myInterface.doubleValue);
+myInterface.logMessage ("myInterface.intValue = " + myInterface.intValue);
+myInterface.logMessage ("myInterface.stringValue = " + myInterface.stringValue);
+myInterface.logMessage ("myInterface.booleanValue = " + myInterface.booleanValue);
+myInterface.logMessage ("myInterface.nullValue = " + myInterface.nullValue);
+myInterface.logMessage ("myInterface.undefinedValue = " + myInterface.undefinedValue);
 
 myInterface.logMessage ("myInterface.setInt_(666) = " + myInterface.setInt_(666));
 myInterface.logMessage ("myInterface.getInt() = " + myInterface.getInt());
diff --git a/JavaScriptCore/bindings/testC.js b/JavaScriptCore/bindings/testC.js
new file mode 100644
index 0000000..44677c7
--- /dev/null
+++ b/JavaScriptCore/bindings/testC.js
@@ -0,0 +1,21 @@
+myInterface.logMessage ("Starting test");
+
+myInterface.logMessage ("Testing properties:");
+myInterface.logMessage ("  myInterface.doubleValue = " + myInterface.doubleValue);
+myInterface.logMessage ("  myInterface.intValue = " + myInterface.intValue);
+myInterface.logMessage ("  myInterface.stringValue = " + myInterface.stringValue);
+myInterface.logMessage ("  myInterface.booleanValue = " + myInterface.booleanValue);
+myInterface.logMessage ("  myInterface.nullValue = " + myInterface.nullValue);
+myInterface.logMessage ("  myInterface.undefinedValue = " + myInterface.undefinedValue);
+
+myInterface.logMessage ("Testing methods:");
+myInterface.logMessage ("  myInterface.setDoubleValue(1234.1234) = " + myInterface.setDoubleValue(1234.1234));
+myInterface.logMessage ("  myInterface.setIntValue(5678) = " + myInterface.setIntValue(5678));
+myInterface.logMessage ("  myInterface.setStringValue(Goodbye) = " + myInterface.setStringValue('Goodbye'));
+myInterface.logMessage ("  myInterface.setBooleanValue(false) = " + myInterface.setBooleanValue(false));
+
+myInterface.logMessage ("Value of properties after calling setters:");
+myInterface.logMessage ("  myInterface.getDoubleValue() = " + myInterface.getDoubleValue());
+myInterface.logMessage ("  myInterface.getIntValue() = " + myInterface.getIntValue());
+myInterface.logMessage ("  myInterface.getStringValue() = " + myInterface.getStringValue());
+myInterface.logMessage ("  myInterface.getBooleanValue() = " + myInterface.getBooleanValue());
diff --git a/JavaScriptCore/bindings/testbindings.cpp b/JavaScriptCore/bindings/testbindings.cpp
index 8eb6572..14a01ad 100644
--- a/JavaScriptCore/bindings/testbindings.cpp
+++ b/JavaScriptCore/bindings/testbindings.cpp
@@ -19,6 +19,7 @@
  *  Boston, MA 02111-1307, USA.
  *
  */
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -70,10 +71,28 @@ static const NP_UTF8 *myPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
 	"undefinedValue"
 };
 
-#define NUM_METHOD_IDENTIFIERS		0
+#define ID_LOG_MESSAGE				0
+#define ID_SET_DOUBLE_VALUE			1
+#define ID_SET_INT_VALUE			2
+#define ID_SET_STRING_VALUE			3
+#define ID_SET_BOOLEAN_VALUE		4
+#define ID_GET_DOUBLE_VALUE			5
+#define ID_GET_INT_VALUE			6
+#define ID_GET_STRING_VALUE			7
+#define ID_GET_BOOLEAN_VALUE		8
+#define NUM_METHOD_IDENTIFIERS		9
 
 static NP_Identifier myMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
 static const NP_UTF8 *myMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
+	"logMessage",
+	"setDoubleValue",
+	"setIntValue",
+	"setStringValue",
+	"setBooleanValue",
+	"getDoubleValue",
+	"getIntValue",
+	"getStringValue",
+	"getBooleanValue"
 };
 
 static void initializeIdentifiers()
@@ -172,8 +191,91 @@ void myInterfaceSetProperty (MyInterfaceObject *obj, NP_Identifier name, NP_Obje
 	}
 }
 
+void logMessage (NP_String *message)
+{
+	printf ("%s\n", NP_UTF8FromString (message));
+}
+
+void setDoubleValue (MyInterfaceObject *obj, NP_Number *number)
+{
+	obj->doubleValue = NP_DoubleFromNumber (number);
+}
+
+void setIntValue (MyInterfaceObject *obj, NP_Number *number)
+{
+	obj->intValue = NP_IntFromNumber (number);
+}
+
+void setStringValue (MyInterfaceObject *obj, NP_String *string)
+{
+	NP_DeallocateUTF8 ((NP_UTF8 *)obj->stringValue);
+	obj->stringValue = NP_UTF8FromString (string);
+}
+
+void setBooleanValue (MyInterfaceObject *obj, NP_Boolean *boolean)
+{
+	obj->boolValue = NP_BoolFromBoolean (boolean);
+}
+
+NP_Number *getDoubleValue (MyInterfaceObject *obj)
+{
+	return NP_CreateNumberWithDouble (obj->doubleValue);
+}
+
+NP_Number *getIntValue (MyInterfaceObject *obj)
+{
+	return NP_CreateNumberWithInt (obj->intValue);
+}
+
+NP_String *getStringValue (MyInterfaceObject *obj)
+{
+	return NP_CreateStringWithUTF8 (obj->stringValue);
+}
+
+NP_Boolean *getBooleanValue (MyInterfaceObject *obj)
+{
+	return NP_CreateBoolean (obj->boolValue);
+}
+
 NP_Object *myInterfaceInvoke (MyInterfaceObject *obj, NP_Identifier name, NP_Object **args, unsigned argCount)
 {
+	if (name == myMethodIdentifiers[ID_LOG_MESSAGE]) {
+		if (argCount == 1 && NP_IsKindOfClass (args[0], NP_StringClass))
+			logMessage ((NP_String *)args[0]);
+		return 0;
+	}
+	else if (name == myMethodIdentifiers[ID_SET_DOUBLE_VALUE]) {
+		if (argCount == 1 && NP_IsKindOfClass (args[0], NP_NumberClass))
+			setDoubleValue (obj, (NP_Number *)args[0]);
+		return 0;
+	}
+	else if (name == myMethodIdentifiers[ID_SET_INT_VALUE]) {
+		if (argCount == 1 && NP_IsKindOfClass (args[0], NP_NumberClass))
+			setIntValue (obj, (NP_Number *)args[0]);
+		return 0;
+	}
+	else if (name == myMethodIdentifiers[ID_SET_STRING_VALUE]) {
+		if (argCount == 1 && NP_IsKindOfClass (args[0], NP_StringClass))
+			setStringValue (obj, (NP_String *)args[0]);
+		return 0;
+	}
+	else if (name == myMethodIdentifiers[ID_SET_BOOLEAN_VALUE]) {
+		if (argCount == 1 && NP_IsKindOfClass (args[0], NP_BooleanClass))
+			setBooleanValue (obj, (NP_Boolean *)args[0]);
+		return 0;
+	}
+	else if (name == myMethodIdentifiers[ID_GET_DOUBLE_VALUE]) {
+		return getDoubleValue (obj);
+	}
+	else if (name == myMethodIdentifiers[ID_GET_INT_VALUE]) {
+		return getIntValue (obj);
+	}
+	else if (name == myMethodIdentifiers[ID_GET_STRING_VALUE]) {
+		return getStringValue (obj);
+	}
+	else if (name == myMethodIdentifiers[ID_GET_BOOLEAN_VALUE]) {
+		return getBooleanValue (obj);
+	}
 	return NP_GetUndefined();
 }
 
@@ -186,6 +288,12 @@ NP_Object *myInterfaceAllocate ()
 		initializeIdentifiers();
 	}
 	
+	
+	newInstance->doubleValue = 666.666;
+	newInstance->intValue = 1234;
+	newInstance->boolValue = true;
+	newInstance->stringValue = strdup("Hello world");
+	
 	return (NP_Object *)newInstance;
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list