Changed RuntimeArrayImp to inherit from ArrayInstanceImp and
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 May 2004 22:19:02 +0000 (22:19 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 May 2004 22:19:02 +0000 (22:19 +0000)
fixed ClassInfo to correctly reflect inheritance.  This is required
because of the runtime checks in JSC for arrays, i.e. in
the Function objects apply method.

        Reviewed by Ken.

        * bindings/jni/jni_runtime.cpp:
        (JavaArray::convertJObjectToArray):
        * bindings/objc/objc_utility.mm:
        (KJS::Bindings::convertObjcValueToValue):
        * bindings/runtime_array.cpp:
        (RuntimeArrayImp::RuntimeArrayImp):
        * bindings/runtime_array.h:
        * bindings/testM.js: Added.
        * bindings/testbindings.mm:
        (+[MyFirstInterface webScriptNameForSelector:]):
        (-[MyFirstInterface logMessages:]):
        (-[MyFirstInterface logMessage:prefix:]):
        (-[MyFirstInterface callJSObject::]):

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

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/jni/jni_runtime.cpp
JavaScriptCore/bindings/objc/objc_utility.mm
JavaScriptCore/bindings/runtime_array.cpp
JavaScriptCore/bindings/runtime_array.h
JavaScriptCore/bindings/testM.js [new file with mode: 0644]
JavaScriptCore/bindings/testbindings.mm

index 0c99f6a29de2d50f2c450e46072f349891673c31..4646bcd4a9749e9343908f6369866b73bcb5f9de 100644 (file)
@@ -1,3 +1,26 @@
+2004-05-24  Richard Williamson   <rjw@apple.com>
+
+       Changed RuntimeArrayImp to inherit from ArrayInstanceImp and
+       fixed ClassInfo to correctly reflect inheritance.  This is required
+       because of the runtime checks in JSC for arrays, i.e. in
+       the Function objects apply method.
+
+        Reviewed by Ken.
+
+        * bindings/jni/jni_runtime.cpp:
+        (JavaArray::convertJObjectToArray):
+        * bindings/objc/objc_utility.mm:
+        (KJS::Bindings::convertObjcValueToValue):
+        * bindings/runtime_array.cpp:
+        (RuntimeArrayImp::RuntimeArrayImp):
+        * bindings/runtime_array.h:
+        * bindings/testM.js: Added.
+        * bindings/testbindings.mm:
+        (+[MyFirstInterface webScriptNameForSelector:]):
+        (-[MyFirstInterface logMessages:]):
+        (-[MyFirstInterface logMessage:prefix:]):
+        (-[MyFirstInterface callJSObject::]):
+
 2004-05-22  Darin Adler  <darin@apple.com>
 
         Reviewed by Maciej.
index 99574b575aa4c53e346d0953a6096504a36bd7b0..bb4dd2527a68a60bbd4e475b6b0c0c261a4ee5bb 100644 (file)
@@ -62,7 +62,7 @@ KJS::Value JavaArray::convertJObjectToArray (KJS::ExecState *exec, jobject anObj
     if (type[0] != '[')
         return Undefined();
 
-    return KJS::Object(new RuntimeArrayImp(new JavaArray ((jobject)anObject, type)));
+    return KJS::Object(new RuntimeArrayImp(exec, new JavaArray ((jobject)anObject, type)));
 }
 
 KJS::Value JavaField::valueFromInstance(KJS::ExecState *exec, const Instance *i) const 
index f18acb3a0290335baad7f1ad867fd836db30aa05..9ca994bb9a59d0b5e22f5dd15be7ea749b957bb4 100644 (file)
@@ -198,7 +198,7 @@ Value KJS::Bindings::convertObjcValueToValue (KJS::ExecState *exec, void *buffer
                     aValue = Number([*obj doubleValue]);
                 }
                 else if ([*obj isKindOfClass:[NSArray class]]) {
-                    aValue = Object(new RuntimeArrayImp(new ObjcArray (*obj)));
+                    aValue = Object(new RuntimeArrayImp(exec, new ObjcArray (*obj)));
                 }
                 else if ([*obj isKindOfClass:[WebScriptObject class]]) {
                     WebScriptObject *jsobject = (WebScriptObject *)*obj;
index fa4e5096d965b6dbb4139f3472b63a9ad8b7288d..1ff4ec18eab8bd383b45b03c57c35bf8e5670ddd 100644 (file)
@@ -29,9 +29,9 @@
 
 using namespace KJS;
 
-const ClassInfo RuntimeArrayImp::info = {"RuntimeArray", 0, 0, 0};
+const ClassInfo RuntimeArrayImp::info = {"RuntimeArray", &ArrayInstanceImp::info, 0, 0};
 
-RuntimeArrayImp::RuntimeArrayImp(Bindings::Array *a)
+RuntimeArrayImp::RuntimeArrayImp(ExecState *exec, Bindings::Array *a) : ArrayInstanceImp (exec->lexicalInterpreter()->builtinArrayPrototype().imp(), a->getLength())
 {
     // Always takes ownership of concrete array.
     _array = a;
index 2792a6472c6392622ef708ece39e910db60f8b56..e05ee217c5b6705197c79acfbe28b1294dd4fde3 100644 (file)
 #ifndef _RUNTIME_ARRAY_H_
 #define _RUNTIME_ARRAY_H_
 
+#include <array_instance.h>
 #include <object.h>
 #include <runtime.h>
 
 
 namespace KJS {
     
-class RuntimeArrayImp : public ObjectImp {
+class RuntimeArrayImp : public ArrayInstanceImp {
 public:
-    RuntimeArrayImp(Bindings::Array *i);
+    RuntimeArrayImp(ExecState *exec, Bindings::Array *i);
     ~RuntimeArrayImp();
     
     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
diff --git a/JavaScriptCore/bindings/testM.js b/JavaScriptCore/bindings/testM.js
new file mode 100644 (file)
index 0000000..6d17563
--- /dev/null
@@ -0,0 +1,29 @@
+myInterface.logMessage ("Starting test");
+
+myInterface.logMessage ("Testing properties:");
+
+myInterface.jsobject = new Function ("arg1","arg2","return arg1 + arg2;");
+myInterface.logMessage ("myInterface.jsobject =" + myInterface.jsobject);
+
+var functionBody = 'return arg1*arg2;'
+
+myInterface.setJSObject_(new Function ("arg1","arg2",functionBody));
+myInterface.logMessage ("myInterface.jsobject =" + myInterface.jsobject);
+myInterface.callJSObject__(5,6);
+myInterface.callJSObject__(8,9);
+
+myInterface.logMessage ("myInterface.setInt_(666) = " + myInterface.setInt_(666));
+myInterface.logMessage ("myInterface.getInt() = " + myInterface.getInt());
+myInterface.logMessage ("myInterface.getString() = " + myInterface.getString());
+myInterface.logMessage ("myInterface.myInt = " + myInterface.myInt);
+myInterface.logMessage ("setting myInterface.myInt = 777");
+myInterface.myInt = 777;
+myInterface.logMessage ("myInterface.myInt = " + myInterface.myInt);
+myInterface.logMessage ("myInterface.getMySecondInterface().doubleValue = " + myInterface.getMySecondInterface().doubleValue);
+myInterface.logMessage ("myInterface.getMySecondInterface() = " + myInterface.getMySecondInterface());
+
+myInterface.logMessageWithPrefix ("msg", "prefix");
+
+var strings = [ "one", "two", "three" ];
+
+myInterface.logMessages (strings);
\ No newline at end of file
index d3b090cf285bc655da43925767d3a45929c05a25..b6d8ed1965b7cf98da773d75bbaa34443cc6543c 100644 (file)
 
 @implementation MyFirstInterface
 
++ (NSString *)webScriptNameForSelector:(SEL)aSelector
+{
+    if (aSelector == @selector(logMessage:))
+        return @"logMessage";
+    if (aSelector == @selector(logMessages:))
+        return @"logMessages";
+    if (aSelector == @selector(logMessage:prefix:))
+        return @"logMessageWithPrefix";
+    return nil;
+}
+
 - init
 {
     LOG ("\n");
     [super dealloc];
 }
 
-+ (NSString *)webScriptNameForSelector:(SEL)aSelector
-{
-    if (aSelector == @selector(logMessage:))
-        return @"logMessage";
-    return nil;
-}
-
 - (int)getInt 
 {
     LOG ("myInt = %d\n", myInt);
     printf ("%s\n", [message lossyCString]);
 }
 
+- (void)logMessages:(id)messages
+{
+    int i, count = [[messages valueForKey:@"length"] intValue];
+    for (i = 0; i < count; i++)
+        printf ("%s\n", [[messages webScriptValueAtIndex:i] lossyCString]);
+}
+
+- (void)logMessage:(NSString *)message prefix:(NSString *)prefix
+{
+    printf ("%s:%s\n", [prefix lossyCString], [message lossyCString]);
+}
+
 - (void)setJSObject:(id)jso
 {
     [jsobject autorelease];
 
 - (void)callJSObject:(int)arg1 :(int)arg2
 {
-    id foo = [jsobject callWebScriptMethod:@"call" withArguments:[NSArray arrayWithObjects:jsobject, [NSNumber numberWithInt:arg1], [NSNumber numberWithInt:arg2], nil]];
-    printf ("foo = %s\n", [[foo description] lossyCString] );
+    id foo1 = [jsobject callWebScriptMethod:@"call" withArguments:[NSArray arrayWithObjects:jsobject, [NSNumber numberWithInt:arg1], [NSNumber numberWithInt:arg2], nil]];
+    printf ("foo (via call) = %s\n", [[foo1 description] lossyCString] );
+    id foo2 = [jsobject callWebScriptMethod:@"apply" withArguments:[NSArray arrayWithObjects:jsobject, [NSArray arrayWithObjects:[NSNumber numberWithInt:arg1], [NSNumber numberWithInt:arg2], nil], nil]];
+    printf ("foo (via apply) = %s\n", [[foo2 description] lossyCString] );
 }
 
 @end