[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:28:29 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit f79aded1615e7c9c824c1be0438e24c86a1a2a1e
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Mar 3 20:04:03 2004 +0000
More 'C' binding implementation.
Reviewed by Chris.
* bindings/NP_runtime.cpp:
(identifierEqual):
(identifierHash):
(getIdentifierDictionary):
(NP_IdentifierFromUTF8):
(NP_UTF8FromIdentifier):
(NP_CreateObject):
(NP_ReleaseObject):
(NP_IsKindOfClass):
(numberCreate):
(NP_CreateNumberWithInt):
(NP_CreateNumberWithFloat):
(NP_CreateNumberWithDouble):
(NP_IntFromNumber):
(NP_FloatFromNumber):
(NP_DoubleFromNumber):
* bindings/NP_runtime.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6163 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 030c4f2..24316d2 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,27 @@
+2004-03-03 Richard Williamson <rjw at apple.com>
+
+ More 'C' binding implementation.
+
+ Reviewed by Chris.
+
+ * bindings/NP_runtime.cpp:
+ (identifierEqual):
+ (identifierHash):
+ (getIdentifierDictionary):
+ (NP_IdentifierFromUTF8):
+ (NP_UTF8FromIdentifier):
+ (NP_CreateObject):
+ (NP_ReleaseObject):
+ (NP_IsKindOfClass):
+ (numberCreate):
+ (NP_CreateNumberWithInt):
+ (NP_CreateNumberWithFloat):
+ (NP_CreateNumberWithDouble):
+ (NP_IntFromNumber):
+ (NP_FloatFromNumber):
+ (NP_DoubleFromNumber):
+ * bindings/NP_runtime.h:
+
2004-03-02 Richard Williamson <rjw at apple.com>
Removed retain/release from NP_Class. Classes will not be allowed to implement their
diff --git a/JavaScriptCore/bindings/npruntime.cpp b/JavaScriptCore/bindings/npruntime.cpp
index d49ef29..3f91e5b 100644
--- a/JavaScriptCore/bindings/npruntime.cpp
+++ b/JavaScriptCore/bindings/npruntime.cpp
@@ -27,10 +27,82 @@
#include <NP_runtime.h>
+static Boolean identifierEqual(const void *value1, const void *value2)
+{
+ return strcmp((const char *)value1, (const char *)value2) == 0;
+}
+
+static CFHashCode identifierHash (const void *value)
+{
+ const char *key = (const char *)value;
+ unsigned int len = strlen(key);
+ unsigned int result = len;
+
+ if (len <= 16) {
+ unsigned cnt = len;
+ while (cnt--) result = result * 257 + *(unsigned char *)key++;
+ } else {
+ unsigned cnt;
+ for (cnt = 8; cnt > 0; cnt--) result = result * 257 + *(unsigned char *)key++;
+ key += (len - 16);
+ for (cnt = 8; cnt > 0; cnt--) result = result * 257 + *(unsigned char *)key++;
+ }
+ result += (result << (len & 31));
+
+ return result;
+}
+
+CFDictionaryKeyCallBacks identifierCallbacks = {
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ identifierEqual,
+ identifierHash
+};
+
+static CFMutableDictionaryRef identifierDictionary = 0;
+
+static CFMutableDictionaryRef getIdentifierDictionary()
+{
+ if (!identifierDictionary)
+ identifierDictionary = CFDictionaryCreateMutable(NULL, 0, &identifierCallbacks, NULL);
+ return identifierDictionary;
+}
+
+#define INITIAL_IDENTIFIER_NAME_COUNT 128
+
+static const char **identifierNames = 0;
+static unsigned int maxIdentifierNames;
+static NP_Identifier identifierCount = 1;
NP_Identifier NP_IdentifierFromUTF8 (NP_UTF8 name)
{
- return 0;
+ NP_Identifier identifier = 0;
+
+ 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);
+ }
+
+ return identifier;
}
void NP_GetIdentifiers (NP_UTF8 *names, int nameCount, NP_Identifier *identifiers)
@@ -39,15 +111,21 @@ void NP_GetIdentifiers (NP_UTF8 *names, int nameCount, NP_Identifier *identifier
NP_UTF8 NP_UTF8FromIdentifier (NP_Identifier identifier)
{
- return NULL;
+ if (identifier == 0 || identifier >= identifierCount)
+ return NULL;
+
+ return (NP_UTF8)identifierNames[identifier];
}
NP_Object *NP_CreateObject (NP_Class *aClass)
{
- if (aClass->create != NULL)
- return aClass->create ();
-
- NP_Object *obj = (NP_Object *)malloc (sizeof(NP_Object));
+ NP_Object *obj;
+
+ if (aClass->allocate != NULL)
+ obj = aClass->allocate ();
+ else
+ obj = (NP_Object *)malloc (sizeof(NP_Object));
+
obj->_class = aClass;
obj->referenceCount = 1;
@@ -70,8 +148,8 @@ void NP_ReleaseObject (NP_Object *obj)
obj->referenceCount--;
if (obj->referenceCount == 0) {
- if (obj->_class->destroy)
- obj->_class->destroy (obj);
+ if (obj->_class->free)
+ obj->_class->free (obj);
else
free (obj);
}
@@ -79,6 +157,9 @@ void NP_ReleaseObject (NP_Object *obj)
bool NP_IsKindOfClass (NP_Object *obj, NP_Class *aClass)
{
+ if (obj->_class == aClass)
+ return true;
+
return false;
}
@@ -128,35 +209,73 @@ void NP_SetPropertyAtIndex (NP_JavaScriptObject *obj, unsigned index, NP_Object
// ---------------------------------- Types ----------------------------------
+// ---------------------------------- NP_Number ----------------------------------
+
+typedef struct
+{
+ NP_Object object;
+ double number;
+} NumberObject;
+
+NP_Object *numberCreate()
+{
+ return (NP_Object *)malloc(sizeof(NumberObject));
+}
+
+static NP_Class _numberClass = {
+ 1,
+ numberCreate,
+ (NP_FreeInterface)free,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+static NP_Class *numberClass = &_numberClass;
NP_Number *NP_CreateNumberWithInt (int i)
{
- return NULL;
+ NumberObject *number = (NumberObject *)NP_CreateObject (numberClass);
+ number->number = i;
+ return (NP_Number *)number;
}
NP_Number *NP_CreateNumberWithFloat (float f)
{
- return NULL;
+ NumberObject *number = (NumberObject *)NP_CreateObject (numberClass);
+ number->number = f;
+ return (NP_Number *)number;
}
NP_Number *NP_CreateNumberWithDouble (double d)
{
- return NULL;
+ NumberObject *number = (NumberObject *)NP_CreateObject (numberClass);
+ number->number = d;
+ return (NP_Number *)number;
}
int NP_IntFromNumber (NP_Number *obj)
{
- return 0;
+ assert (NP_IsKindOfClass (obj, numberClass));
+ NumberObject *number = (NumberObject *)obj;
+ return (int)number->number;
}
float NP_FloatFromNumber (NP_Number *obj)
{
- return 0.;
+ assert (NP_IsKindOfClass (obj, numberClass));
+ NumberObject *number = (NumberObject *)obj;
+ return (float)number->number;
}
double NP_DoubleFromNumber (NP_Number *obj)
{
- return 0.;
+ assert (NP_IsKindOfClass (obj, numberClass));
+ NumberObject *number = (NumberObject *)obj;
+ return number->number;
}
diff --git a/JavaScriptCore/bindings/npruntime.h b/JavaScriptCore/bindings/npruntime.h
index 216a346..71dfd8a 100644
--- a/JavaScriptCore/bindings/npruntime.h
+++ b/JavaScriptCore/bindings/npruntime.h
@@ -96,10 +96,8 @@ NP_UTF8 NP_UTF8FromIdentifier (NP_Identifier identifier);
/*
NP_Object behavior is implemented using the following set of callback interfaces.
*/
-typedef NP_Object *(*NP_CreateInterface)();
-typedef void *(*NP_DestroyInterface)(NP_Object *obj);
-typedef NP_Object *(*NP_RetainInterface)(NP_Object *obj);
-typedef void (*NP_ReleaseInterface)(NP_Object *obj);
+typedef NP_Object *(*NP_AllocateInterface)();
+typedef void (*NP_FreeInterface)(NP_Object *obj);
typedef void (*NP_InvalidateInterface)();
typedef bool (*NP_HasMethodInterface)(NP_Object *obj, NP_Identifier name);
typedef NP_Object *(*NP_InvokeInterface)(NP_Object *obj, NP_Identifier name, NP_Object **args, unsigned argCount);
@@ -125,8 +123,8 @@ typedef void (*NP_SetPropertyInterface)(NP_Object *obj, NP_Identifier name, NP_O
struct NP_Class
{
int32_t structVersion;
- NP_CreateInterface create;
- NP_DestroyInterface destroy;
+ NP_AllocateInterface allocate;
+ NP_FreeInterface free;
NP_InvalidateInterface invalidate;
NP_HasMethodInterface hasMethod;
NP_InvokeInterface invoke;
@@ -207,7 +205,7 @@ float NP_FloatFromNumber (NP_Number *obj);
double NP_DoubleFromNumber (NP_Number *obj);
NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String);
-NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String);
+NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String, unsigned int len);
/*
Memory returned from NP_UTF8FromString must be freed by the caller.
@@ -363,16 +361,12 @@ void NP_SetException (NP_Object *obj, NP_String *message);
return 0;
}
- NP_Object *myInterfaceCreate ()
+ NP_Object *myInterfaceAllocate ()
{
MyInterfaceObject *newInstance = (MyInterfaceObject *)malloc (sizeof(MyInterfaceObject));
if (stopIdentifier == 0)
initializeIdentifiers();
-
- newInstance->object->class = myInterface;
-
- return myInterfaceRetain (newInstance);
}
void myInterfaceInvalidate ()
@@ -381,34 +375,14 @@ void NP_SetException (NP_Object *obj, NP_String *message);
// objects.
}
- void myInterfaceDestroy (MyInterfaceObject *obj)
+ void myInterfaceFree (MyInterfaceObject *obj)
{
- assert (obj->referenceCount == 0);
-
free ((void *)obj);
}
- NP_Object *myInterfaceRetain (MyInterfaceObject *obj)
- {
- return referenceCount++;
- }
-
- void myInterfaceRelease (MyInterfaceObject *obj)
- {
- obj->referenceCount--;
-
- assert (obj->referenceCount >= 0)
-
- if (obj->referenceCount == 0) {
- myDestroyInterface (obj);
- }
- }
-
static NP_Class _myInterface = {
- (NP_CreateInterface) myInterfaceCreate,
- (NP_DestroyInterface) myInterfaceDestroy,
- (NP_RetainInterface) myInterfaceRetain,
- (NP_ReleaseInterface) myInterfaceRelease,
+ (NP_AllocateInterface) myInterfaceAllocate,
+ (NP_FreeInterface) myInterfaceFree,
(NP_InvalidateInterface) myInterfaceInvalidate,
(NP_HasMethodInterface) myInterfaceHasMethod,
(NP_InvokeInterface) myInterfaceInvoke,
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list