[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:37:54 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 71b17a8c06536c7c0ed051e9cb1dc8bd4966abd1
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Apr 30 01:44:16 2004 +0000
Fixed several bad problems with the ObjC bindings. In particular, conversion
to/from JavaScriptObject (soon to be WebScriptObject) was completely broken.
Reviewed by Chris.
* bindings/objc/objc_jsobject.h:
* bindings/objc/objc_jsobject.mm:
(-[JavaScriptObject initWithObjectImp:KJS::root:Bindings::]):
(-[JavaScriptObject KJS::]):
(+[JavaScriptObject _convertValueToObjcValue:KJS::root:Bindings::]):
(-[JavaScriptObject call:arguments:]):
(-[JavaScriptObject evaluate:]):
(-[JavaScriptObject getMember:]):
(-[JavaScriptObject getSlot:]):
* bindings/objc/objc_runtime.mm:
(ObjcField::valueFromInstance):
(ObjcField::setValueToInstance):
* bindings/objc/objc_utility.mm:
(KJS::Bindings::convertValueToObjcValue):
(KJS::Bindings::convertObjcValueToValue):
* bindings/runtime.h:
* bindings/runtime_root.cpp:
(KJS::Bindings::rootForInterpreter):
(KJS::Bindings::addNativeReference):
(KJS::Bindings::removeNativeReference):
* bindings/runtime_root.h:
* bindings/testbindings.mm:
(-[MyFirstInterface logMessage:]):
(-[MyFirstInterface setJSObject:]):
(-[MyFirstInterface callJSObject::]):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6524 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 4e526f8..2e1d847 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,36 @@
+2004-04-29 Richard Williamson <rjw at apple.com>
+
+ Fixed several bad problems with the ObjC bindings. In particular, conversion
+ to/from JavaScriptObject (soon to be WebScriptObject) was completely broken.
+
+ Reviewed by Chris.
+
+ * bindings/objc/objc_jsobject.h:
+ * bindings/objc/objc_jsobject.mm:
+ (-[JavaScriptObject initWithObjectImp:KJS::root:Bindings::]):
+ (-[JavaScriptObject KJS::]):
+ (+[JavaScriptObject _convertValueToObjcValue:KJS::root:Bindings::]):
+ (-[JavaScriptObject call:arguments:]):
+ (-[JavaScriptObject evaluate:]):
+ (-[JavaScriptObject getMember:]):
+ (-[JavaScriptObject getSlot:]):
+ * bindings/objc/objc_runtime.mm:
+ (ObjcField::valueFromInstance):
+ (ObjcField::setValueToInstance):
+ * bindings/objc/objc_utility.mm:
+ (KJS::Bindings::convertValueToObjcValue):
+ (KJS::Bindings::convertObjcValueToValue):
+ * bindings/runtime.h:
+ * bindings/runtime_root.cpp:
+ (KJS::Bindings::rootForInterpreter):
+ (KJS::Bindings::addNativeReference):
+ (KJS::Bindings::removeNativeReference):
+ * bindings/runtime_root.h:
+ * bindings/testbindings.mm:
+ (-[MyFirstInterface logMessage:]):
+ (-[MyFirstInterface setJSObject:]):
+ (-[MyFirstInterface callJSObject::]):
+
2004-04-24 Darin Adler <darin at apple.com>
Reviewed by Dave.
diff --git a/JavaScriptCore/bindings/objc/objc_jsobject.h b/JavaScriptCore/bindings/objc/objc_jsobject.h
index 4a85b76..3e96161 100644
--- a/JavaScriptCore/bindings/objc/objc_jsobject.h
+++ b/JavaScriptCore/bindings/objc/objc_jsobject.h
@@ -29,6 +29,8 @@
#include <value.h>
+#include <runtime_root.h>
+
/*
ObjC to JavaScript
char Number
@@ -75,17 +77,12 @@
- (NSString *)toString;
- (id)getSlot:(unsigned int)index;
- (void)setSlot:(unsigned int)index value:(id)value;
- at end
-
-// This is intended to be an SPI, as it exposes KJS::Value.
- at interface JavaScriptValueConverter
-+ (void)registerConverter:(JavaScriptValueConverter *)aConverter;
-+ (void)unregisterConverter:(JavaScriptValueConverter *)aConverter;
-+ (NSArray *)converters;
-
-- (id)objectForValue:(KJS::Value)aValue;
+ at end
+ at interface JavaScriptObject (Private)
++ (id)_convertValueToObjcValue:(KJS::Value)value root:(const KJS::Bindings::RootObject *)root;
+- (KJS::ObjectImp *)imp;
@end
#endif
\ No newline at end of file
diff --git a/JavaScriptCore/bindings/objc/objc_jsobject.mm b/JavaScriptCore/bindings/objc/objc_jsobject.mm
index f3ecce8..2be0b4e 100644
--- a/JavaScriptCore/bindings/objc/objc_jsobject.mm
+++ b/JavaScriptCore/bindings/objc/objc_jsobject.mm
@@ -82,9 +82,8 @@ windowJavaScriptObject(root));
@implementation JavaScriptObjectPrivate
@end
- at interface JavaScriptObject (Private)
-- _initWithObjectImp:(KJS::ObjectImp *)imp root:(const Bindings::RootObject *)root;
-- (id)_convertValueToObjcValue:(KJS::Value)value;
+ at interface JavaScriptObject (ReallyPrivate)
+- initWithObjectImp:(KJS::ObjectImp *)imp root:(const Bindings::RootObject *)root;
@end
@implementation JavaScriptObject
@@ -96,7 +95,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
for (i = 0; i < numObjects; i++) {
id anObject = [array objectAtIndex:i];
- aList.append (convertObjcValueToValue(exec, anObject, ObjcObjectType));
+ aList.append (convertObjcValueToValue(exec, &anObject, ObjcObjectType));
}
return aList;
}
@@ -104,7 +103,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
- initWithObjectImp:(KJS::ObjectImp *)imp root:(const Bindings::RootObject *)root
{
assert (imp != 0);
- assert (root != 0);
+ //assert (root != 0);
self = [super init];
@@ -124,7 +123,12 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
[super dealloc];
}
-- (id)_convertValueToObjcValue:(KJS::Value)value
+- (KJS::ObjectImp *)imp
+{
+ return _private->imp;
+}
+
++ (id)_convertValueToObjcValue:(KJS::Value)value root:(const Bindings::RootObject *)root
{
id result = 0;
@@ -139,7 +143,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
}
// Convert to a JavaScriptObject
else {
- result = [[[JavaScriptObject alloc] _initWithObjectImp:objectImp root:_private->root] autorelease];
+ result = [[[JavaScriptObject alloc] initWithObjectImp:objectImp root:root] autorelease];
}
}
@@ -186,7 +190,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
Interpreter::unlock();
// Convert and return the result of the function call.
- return [self _convertValueToObjcValue:result];
+ return [JavaScriptObject _convertValueToObjcValue:result root:_private->root];
}
- (id)evaluate:(NSString *)script
@@ -197,7 +201,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
Value v = convertObjcValueToValue(exec, &script, ObjcObjectType);
KJS::Value result = _private->root->interpreter()->evaluate(v.toString(exec)).value();
Interpreter::unlock();
- return [self _convertValueToObjcValue:result];
+ return [JavaScriptObject _convertValueToObjcValue:result root:_private->root];
}
- (id)getMember:(NSString *)name
@@ -207,7 +211,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
Value v = convertObjcValueToValue(exec, &name, ObjcObjectType);
Value result = _private->imp->get (exec, Identifier (v.toString(exec)));
Interpreter::unlock();
- return [self _convertValueToObjcValue:result];
+ return [JavaScriptObject _convertValueToObjcValue:result root:_private->root];
}
- (void)setMember:(NSString *)name value:(id)value
@@ -248,7 +252,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
Value result = _private->imp->get (exec, (unsigned)index);
Interpreter::unlock();
- return [self _convertValueToObjcValue:result];
+ return [JavaScriptObject _convertValueToObjcValue:result root:_private->root];
}
- (void)setSlot:(unsigned int)index value:(id)value
diff --git a/JavaScriptCore/bindings/objc/objc_runtime.mm b/JavaScriptCore/bindings/objc/objc_runtime.mm
index 832f1cf..ea558ad 100644
--- a/JavaScriptCore/bindings/objc/objc_runtime.mm
+++ b/JavaScriptCore/bindings/objc/objc_runtime.mm
@@ -28,6 +28,7 @@
#include <JavaScriptCore/internal.h>
#include <objc_instance.h>
+#include <objc_jsobject.h>
#include <runtime_array.h>
#include <runtime_object.h>
@@ -92,8 +93,14 @@ Value ObjcField::valueFromInstance(KJS::ExecState *exec, const Instance *instanc
case ObjcObjectType: {
ObjectStructPtr obj = *(ObjectStructPtr *)(ivarValuePtr);
- Instance *anInstance = Instance::createBindingForLanguageInstance (Instance::ObjectiveCLanguage, (void *)obj);
- aValue = Object(new RuntimeObjectImp(anInstance,true));
+ if ([obj isKindOfClass:[JavaScriptObject class]]) {
+ JavaScriptObject *jsobject = (JavaScriptObject *)obj;
+ aValue = Object([jsobject imp]);
+ }
+ else {
+ Instance *anInstance = Instance::createBindingForLanguageInstance (Instance::ObjectiveCLanguage, (void *)obj);
+ aValue = Object(new RuntimeObjectImp(anInstance,true));
+ }
}
break;
@@ -158,7 +165,12 @@ void ObjcField::setValueToInstance(KJS::ExecState *exec, const Instance *instanc
// First see if we have an ObjC instance.
if (aValue.type() == KJS::ObjectType){
ObjcValue result = convertValueToObjcValue(exec, aValue, objcValueTypeForType(_ivar->ivar_type));
- *(ObjectStructPtr *)(ivarValuePtr) = result.objectValue;
+
+ // Release the previous value.
+ [*(ObjectStructPtr *)(ivarValuePtr) autorelease];
+
+ // Retain the new value.
+ *(ObjectStructPtr *)(ivarValuePtr) = [result.objectValue retain];
}
// FIXME. Deal with numbers.
diff --git a/JavaScriptCore/bindings/objc/objc_utility.mm b/JavaScriptCore/bindings/objc/objc_utility.mm
index d783e4d..2d89ced 100644
--- a/JavaScriptCore/bindings/objc/objc_utility.mm
+++ b/JavaScriptCore/bindings/objc/objc_utility.mm
@@ -29,6 +29,7 @@
#include <runtime_array.h>
#include <runtime_object.h>
#include <objc_instance.h>
+#include <objc_jsobject.h>
#include <objc_utility.h>
@@ -98,33 +99,13 @@ ObjcValue KJS::Bindings::convertValueToObjcValue (KJS::ExecState *exec, const KJ
d = value.toNumber(exec);
switch (type){
case ObjcObjectType: {
- result.objectValue = 0;
-
- // First see if we have a ObjC instance.
- if (value.type() == KJS::ObjectType){
- ObjectImp *objectImp = static_cast<ObjectImp*>(value.imp());
- if (strcmp(objectImp->classInfo()->className, "RuntimeObject") == 0) {
- RuntimeObjectImp *imp = static_cast<RuntimeObjectImp *>(value.imp());
- ObjcInstance *instance = static_cast<ObjcInstance*>(imp->getInternalInstance());
- if (instance)
- result.objectValue = instance->getObject();
- }
- }
-
- // Convert JavaScript String value to NSString?
- else if (value.type() == KJS::StringType) {
- StringImp *s = static_cast<KJS::StringImp*>(value.imp());
- UString u = s->value();
-
- NSString *string = [NSString stringWithCharacters:(const unichar*)u.data() length:u.size()];
- result.objectValue = string;
- }
-
- // Convert JavaScript Number value to NSNumber?
- else if (value.type() == KJS::NumberType) {
- Number n = Number::dynamicCast(value);
- result.objectValue = [NSNumber numberWithDouble:n.value()];
+ const Bindings::RootObject *root = rootForInterpreter(exec->interpreter());
+ if (!root) {
+ Bindings::RootObject *newRoot = new KJS::Bindings::RootObject(0);
+ newRoot->setInterpreter (exec->interpreter());
+ root = newRoot;
}
+ result.objectValue = [JavaScriptObject _convertValueToObjcValue:value root:root];
}
break;
@@ -223,6 +204,10 @@ Value KJS::Bindings::convertObjcValueToValue (KJS::ExecState *exec, void *buffer
else if ([*obj isKindOfClass:[NSArray class]]) {
aValue = Object(new RuntimeArrayImp(new ObjcArray (*obj)));
}
+ else if ([*obj isKindOfClass:[JavaScriptObject class]]) {
+ JavaScriptObject *jsobject = (JavaScriptObject *)*obj;
+ aValue = Object([jsobject imp]);
+ }
else {
aValue = Object(new RuntimeObjectImp(new ObjcInstance (*obj)));
}
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index 7a83924..06a6e5d 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -37,6 +37,7 @@ namespace Bindings
class Instance;
class Method;
+class RootObject;
// For now just use Java style type descriptors.
typedef const char * RuntimeType;
diff --git a/JavaScriptCore/bindings/runtime_root.cpp b/JavaScriptCore/bindings/runtime_root.cpp
index 1a8fe75..6287604 100644
--- a/JavaScriptCore/bindings/runtime_root.cpp
+++ b/JavaScriptCore/bindings/runtime_root.cpp
@@ -126,17 +126,44 @@ const Bindings::RootObject *KJS::Bindings::rootForImp (ObjectImp *imp)
return rootObject;
}
-void KJS::Bindings::addNativeReference (const Bindings::RootObject *root, ObjectImp *imp)
+const Bindings::RootObject *KJS::Bindings::rootForInterpreter (KJS::Interpreter *interpreter)
{
- CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (root);
+ CFMutableDictionaryRef refsByRoot = getReferencesByRootDictionary ();
- unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
- if (numReferences == 0) {
- imp->ref();
- CFDictionaryAddValue (referencesDictionary, imp, (const void *)1);
+ if (refsByRoot) {
+ const void **allValues = 0;
+ const void **allKeys = 0;
+ CFIndex count, i;
+
+ count = CFDictionaryGetCount(refsByRoot);
+ allKeys = (const void **)malloc (sizeof(void *) * count);
+ allValues = (const void **)malloc (sizeof(void *) * count);
+ CFDictionaryGetKeysAndValues (refsByRoot, allKeys, allValues);
+ for(i = 0; i < count; i++) {
+ const Bindings::RootObject *aRootObject = (const Bindings::RootObject *)allKeys[i];
+ if (aRootObject->interpreter() == interpreter)
+ return aRootObject;
+ }
+
+ free ((void *)allKeys);
+ free ((void *)allValues);
}
- else {
- CFDictionaryReplaceValue (referencesDictionary, imp, (const void *)(numReferences+1));
+ return 0;
+}
+
+void KJS::Bindings::addNativeReference (const Bindings::RootObject *root, ObjectImp *imp)
+{
+ if (root) {
+ CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (root);
+
+ unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
+ if (numReferences == 0) {
+ imp->ref();
+ CFDictionaryAddValue (referencesDictionary, imp, (const void *)1);
+ }
+ else {
+ CFDictionaryReplaceValue (referencesDictionary, imp, (const void *)(numReferences+1));
+ }
}
}
@@ -144,13 +171,15 @@ void KJS::Bindings::removeNativeReference (ObjectImp *imp)
{
CFMutableDictionaryRef referencesDictionary = findReferenceDictionary (imp);
- unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
- if (numReferences == 1) {
- imp->deref();
- CFDictionaryRemoveValue (referencesDictionary, imp);
- }
- else {
- CFDictionaryReplaceValue (referencesDictionary, imp, (const void *)(numReferences-1));
+ if (referencesDictionary) {
+ unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
+ if (numReferences == 1) {
+ imp->deref();
+ CFDictionaryRemoveValue (referencesDictionary, imp);
+ }
+ else {
+ CFDictionaryReplaceValue (referencesDictionary, imp, (const void *)(numReferences-1));
+ }
}
}
diff --git a/JavaScriptCore/bindings/runtime_root.h b/JavaScriptCore/bindings/runtime_root.h
index 112a5ec..3f74324 100644
--- a/JavaScriptCore/bindings/runtime_root.h
+++ b/JavaScriptCore/bindings/runtime_root.h
@@ -39,6 +39,7 @@ typedef RootObject *(*FindRootObjectForNativeHandleFunctionPtr)(void *);
extern CFMutableDictionaryRef findReferenceDictionary(ObjectImp *imp);
extern const Bindings::RootObject *rootForImp (ObjectImp *imp);
+extern const Bindings::RootObject *KJS::Bindings::rootForInterpreter (KJS::Interpreter *interpreter);
extern void addNativeReference (const Bindings::RootObject *root, ObjectImp *imp);
extern void removeNativeReference (ObjectImp *imp);
diff --git a/JavaScriptCore/bindings/testbindings.mm b/JavaScriptCore/bindings/testbindings.mm
index 7d13bea..7a0c145 100644
--- a/JavaScriptCore/bindings/testbindings.mm
+++ b/JavaScriptCore/bindings/testbindings.mm
@@ -32,6 +32,18 @@
#include "runtime.h"
#include "runtime_object.h"
+ at interface JavaScriptObject : NSObject
+
+- (id)call:(NSString *)methodName arguments:(NSArray *)args;
+- (id)evaluate:(NSString *)script;
+- (id)getMember:(NSString *)name;
+- (void)setMember:(NSString *)name value:(id)value;
+- (void)removeMember:(NSString *)name;
+- (NSString *)toString;
+- (id)getSlot:(unsigned int)index;
+- (void)setSlot:(unsigned int)index value:(id)value;
+
+ at end
#define LOG(formatAndArgs...) { \
fprintf (stderr, "%s: ", __PRETTY_FUNCTION__); \
@@ -62,13 +74,14 @@
{
int myInt;
MySecondInterface *mySecondInterface;
+ id jsobject;
}
- (int)getInt;
- (void)setInt: (int)anInt;
- (MySecondInterface *)getMySecondInterface;
- (void)logMessage:(NSString *)message;
-
+- (void)setJSObject:(id)jsobject;
@end
@implementation MyFirstInterface
@@ -122,6 +135,18 @@
printf ("%s\n", [message lossyCString]);
}
+- (void)setJSObject:(id)jso
+{
+ [jsobject autorelease];
+ jsobject = [jso retain];
+}
+
+- (void)callJSObject:(int)arg1 :(int)arg2
+{
+ id foo = [jsobject call:@"call" arguments:[NSArray arrayWithObjects:jsobject, [NSNumber numberWithInt:arg1], [NSNumber numberWithInt:arg2], nil]];
+ printf ("foo = %s\n", [[foo description] lossyCString] );
+}
+
@end
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list