[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:30 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 22da2a0617efd53f40f9a0c7e97f947ee1dc8269
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Mar 3 22:50:07 2004 +0000
More 'C' binding implementation. Fleshed out all the
'primitive' data types.
Reviewed by Chris.
* bindings/NP_runtime.cpp:
(NP_ReleaseObject):
(numberAllocate):
(stringAllocate):
(stringDeallocate):
(NP_CreateStringWithUTF8):
(NP_CreateStringWithUTF16):
(NP_UTF8FromString):
(NP_UTF16FromString):
(NP_StringLength):
(booleanAllocate):
(booleanDeallocate):
(NP_CreateBoolean):
(NP_BoolFromBoolean):
(nullAllocate):
(nullDeallocate):
(NP_GetNull):
(undefinedAllocate):
(undefinedDeallocate):
(NP_GetUndefined):
* bindings/NP_runtime.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6164 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 24316d2..48e66fe 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,5 +1,34 @@
2004-03-03 Richard Williamson <rjw at apple.com>
+ More 'C' binding implementation. Fleshed out all the
+ 'primitive' data types.
+
+ Reviewed by Chris.
+
+ * bindings/NP_runtime.cpp:
+ (NP_ReleaseObject):
+ (numberAllocate):
+ (stringAllocate):
+ (stringDeallocate):
+ (NP_CreateStringWithUTF8):
+ (NP_CreateStringWithUTF16):
+ (NP_UTF8FromString):
+ (NP_UTF16FromString):
+ (NP_StringLength):
+ (booleanAllocate):
+ (booleanDeallocate):
+ (NP_CreateBoolean):
+ (NP_BoolFromBoolean):
+ (nullAllocate):
+ (nullDeallocate):
+ (NP_GetNull):
+ (undefinedAllocate):
+ (undefinedDeallocate):
+ (NP_GetUndefined):
+ * bindings/NP_runtime.h:
+
+2004-03-03 Richard Williamson <rjw at apple.com>
+
More 'C' binding implementation.
Reviewed by Chris.
diff --git a/JavaScriptCore/bindings/npruntime.cpp b/JavaScriptCore/bindings/npruntime.cpp
index 3f91e5b..937df4a 100644
--- a/JavaScriptCore/bindings/npruntime.cpp
+++ b/JavaScriptCore/bindings/npruntime.cpp
@@ -148,8 +148,8 @@ void NP_ReleaseObject (NP_Object *obj)
obj->referenceCount--;
if (obj->referenceCount == 0) {
- if (obj->_class->free)
- obj->_class->free (obj);
+ if (obj->_class->deallocate)
+ obj->_class->deallocate (obj);
else
free (obj);
}
@@ -217,15 +217,15 @@ typedef struct
double number;
} NumberObject;
-NP_Object *numberCreate()
+static NP_Object *numberAllocate()
{
return (NP_Object *)malloc(sizeof(NumberObject));
}
static NP_Class _numberClass = {
1,
- numberCreate,
- (NP_FreeInterface)free,
+ numberAllocate,
+ (NP_DeallocateInterface)free,
0,
0,
0,
@@ -279,47 +279,274 @@ double NP_DoubleFromNumber (NP_Number *obj)
}
-NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String)
+// ---------------------------------- NP_String ----------------------------------
+
+typedef struct
{
- return NULL;
+ NP_Object object;
+ NP_UTF16 string;
+ int32_t length;
+} StringObject;
+
+static NP_Object *stringAllocate()
+{
+ return (NP_Object *)malloc(sizeof(StringObject));
}
-NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String)
+void stringDeallocate (StringObject *string)
{
- return NULL;
+ free (string->string);
+ free (string);
+}
+
+static NP_Class _stringClass = {
+ 1,
+ stringAllocate,
+ (NP_DeallocateInterface)stringDeallocate,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+static NP_Class *stringClass = &_stringClass;
+
+#define LOCAL_CONVERSION_BUFFER_SIZE 4096
+
+NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String)
+{
+ StringObject *string = (StringObject *)NP_CreateObject (stringClass);
+
+ CFStringRef stringRef = CFStringCreateWithCString (NULL, utf8String, kCFStringEncodingUTF8);
+
+ string->length = CFStringGetLength (stringRef);
+ string->string = (NP_UTF16)malloc(sizeof(int16_t)*string->length);
+
+ // Convert the string to UTF16.
+ CFRange range = { 0, string->length };
+ CFStringGetCharacters (stringRef, range, (UniChar *)string->string);
+ CFRelease (stringRef);
+
+ return (NP_String *)string;
}
+NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String, int32_t len)
+{
+ StringObject *string = (StringObject *)NP_CreateObject (stringClass);
+
+ string->length = len;
+ string->string = (NP_UTF16)malloc(sizeof(int16_t)*string->length);
+ memcpy (string->string, utf16String, sizeof(int16_t)*string->length);
+
+ return (NP_String *)string;
+}
+
NP_UTF8 NP_UTF8FromString (NP_String *obj)
{
- return NULL;
+ assert (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;
+ }
+
+ // 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 (resultString, (const char *)buffer, usedBufferLength);
+ resultString[usedBufferLength] = 0;
+
+ CFRelease (stringRef);
+ if (buffer != _localBuffer)
+ free ((void *)buffer);
+
+ return resultString;
}
NP_UTF16 NP_UTF16FromString (NP_String *obj)
{
- return NULL;
+ assert (NP_IsKindOfClass (obj, stringClass));
+
+ StringObject *string = (StringObject *)obj;
+
+ NP_UTF16 resultString = (NP_UTF16)malloc(sizeof(int16_t)*string->length);
+ memcpy (resultString, string->string, sizeof(int16_t)*string->length);
+
+ return resultString;
+}
+
+int32_t NP_StringLength (NP_String *obj)
+{
+ assert (NP_IsKindOfClass (obj, stringClass));
+
+ StringObject *string = (StringObject *)obj;
+ return string->length;
+}
+
+// ---------------------------------- NP_Boolean ----------------------------------
+
+typedef struct
+{
+ NP_Object object;
+ bool value;
+} BooleanObject;
+
+static NP_Object *booleanAllocate()
+{
+ return (NP_Object *)malloc(sizeof(BooleanObject));
+}
+
+static void booleanDeallocate (BooleanObject *string)
+{
+ // Do nothing, single true and false instances.
}
+static NP_Class _booleanClass = {
+ 1,
+ booleanAllocate,
+ (NP_DeallocateInterface)booleanDeallocate,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+static BooleanObject *theTrueObject = 0;
+static BooleanObject *theFalseObject = 0;
+
+static NP_Class *booleanClass = &_booleanClass;
+
NP_Boolean *NP_CreateBoolean (bool f)
{
- return NULL;
+ if (f) {
+ if (!theTrueObject) {
+ theTrueObject = (BooleanObject *)NP_CreateObject (booleanClass);
+ theTrueObject->value = f;
+ }
+ return (NP_Boolean *)theTrueObject;
+ }
+
+ // False
+ if (!theFalseObject) {
+ theFalseObject = (BooleanObject *)NP_CreateObject (booleanClass);
+ theFalseObject->value = f;
+ }
+ return (NP_Boolean *)theFalseObject;
+}
+
+bool NP_BoolFromBoolean (NP_Boolean *obj)
+{
+ assert (NP_IsKindOfClass (obj, booleanClass));
+
+ BooleanObject *booleanObj = (BooleanObject *)obj;
+ return booleanObj->value;
+}
+
+// ---------------------------------- NP_Null ----------------------------------
+
+typedef struct
+{
+ NP_Object object;
+} NullObject;
+
+static NP_Object *nullAllocate()
+{
+ return (NP_Object *)malloc(sizeof(NullObject));
}
-bool NP_BoolFromBoolean (NP_Boolean *aBool)
+static void nullDeallocate (StringObject *string)
{
- return true;
+ // Do nothing, the null object is a singleton.
}
+
+static NullObject *theNullObject = 0;
+
+static NP_Class _nullClass = {
+ 1,
+ nullAllocate,
+ (NP_DeallocateInterface)nullDeallocate,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+static NP_Class *nullClass = &_nullClass;
+
NP_Null *NP_GetNull()
{
- return NULL;
+ if (!theNullObject)
+ theNullObject = (NullObject *)NP_CreateObject(nullClass);
+ return (NP_Null *)theNullObject;
+}
+
+
+// ---------------------------------- NP_Undefined ----------------------------------
+
+typedef struct
+{
+ NP_Object object;
+} UndefinedObject;
+
+static NP_Object *undefinedAllocate()
+{
+ return (NP_Object *)malloc(sizeof(UndefinedObject));
+}
+
+static void undefinedDeallocate (StringObject *string)
+{
+ // Do nothing, the null object is a singleton.
}
+
+static NullObject *theUndefinedObject = 0;
+
+static NP_Class _undefinedClass = {
+ 1,
+ undefinedAllocate,
+ (NP_DeallocateInterface)undefinedDeallocate,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+static NP_Class *undefinedClass = &_undefinedClass;
+
NP_Undefined *NP_GetUndefined()
{
- return NULL;
+ if (!theUndefinedObject)
+ theUndefinedObject = (NullObject *)NP_CreateObject(undefinedClass);
+ return (NP_Undefined *)theUndefinedObject;
}
+// ---------------------------------- NP_Array ----------------------------------
+
NP_Array *NP_CreateArray (const NP_Object **, unsigned count)
{
return NULL;
diff --git a/JavaScriptCore/bindings/npruntime.h b/JavaScriptCore/bindings/npruntime.h
index 71dfd8a..5f43ab1 100644
--- a/JavaScriptCore/bindings/npruntime.h
+++ b/JavaScriptCore/bindings/npruntime.h
@@ -97,7 +97,7 @@ NP_UTF8 NP_UTF8FromIdentifier (NP_Identifier identifier);
NP_Object behavior is implemented using the following set of callback interfaces.
*/
typedef NP_Object *(*NP_AllocateInterface)();
-typedef void (*NP_FreeInterface)(NP_Object *obj);
+typedef void (*NP_DeallocateInterface)(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);
@@ -124,7 +124,7 @@ struct NP_Class
{
int32_t structVersion;
NP_AllocateInterface allocate;
- NP_FreeInterface free;
+ NP_DeallocateInterface deallocate;
NP_InvalidateInterface invalidate;
NP_HasMethodInterface hasMethod;
NP_InvokeInterface invoke;
@@ -191,7 +191,7 @@ NP_Object *NP_GetProperty (NP_JavaScriptObject *obj, NP_Identifier propertyName
void NP_SetProperty (NP_JavaScriptObject *obj, NP_Identifier propertyName, NP_Object value);
void NP_RemoveProperty (NP_JavaScriptObject *obj, NP_Identifier propertyName);
NP_UTF8 NP_ToString (NP_JavaScriptObject *obj);
-NP_Object *NP_GetPropertyAtIndex (NP_JavaScriptObject *obj, unsigned int index);
+NP_Object *NP_GetPropertyAtIndex (NP_JavaScriptObject *obj, int32_t index);
void NP_SetPropertyAtIndex (NP_JavaScriptObject *obj, unsigned index, NP_Object value);
/*
@@ -208,13 +208,11 @@ NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String);
NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String, unsigned int len);
/*
- Memory returned from NP_UTF8FromString must be freed by the caller.
+ Memory returned from NP_UTF8FromString and NP_UTF16FromString must be freed by the caller.
*/
NP_UTF8 NP_UTF8FromString (NP_String *obj);
-/*
- Memory returned from NP_UTF16FromString must be freed by the caller.
-*/
NP_UTF16 NP_UTF16FromString (NP_String *obj);
+int32_t NP_StringLength (NP_String *obj);
NP_Boolean *NP_CreateBoolean (bool f);
bool NP_BoolFromBoolean (NP_Boolean *aBool);
@@ -375,14 +373,14 @@ void NP_SetException (NP_Object *obj, NP_String *message);
// objects.
}
- void myInterfaceFree (MyInterfaceObject *obj)
+ void myInterfaceDeallocate (MyInterfaceObject *obj)
{
free ((void *)obj);
}
static NP_Class _myInterface = {
(NP_AllocateInterface) myInterfaceAllocate,
- (NP_FreeInterface) myInterfaceFree,
+ (NP_DeallocateInterface) myInterfaceDeallocate,
(NP_InvalidateInterface) myInterfaceInvalidate,
(NP_HasMethodInterface) myInterfaceHasMethod,
(NP_InvokeInterface) myInterfaceInvoke,
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list