summaryrefslogtreecommitdiffstats
path: root/WebCore/bridge/objc
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-04-27 16:31:00 +0100
committerSteve Block <steveblock@google.com>2010-05-11 14:42:12 +0100
commitdcc8cf2e65d1aa555cce12431a16547e66b469ee (patch)
tree92a8d65cd5383bca9749f5327fb5e440563926e6 /WebCore/bridge/objc
parentccac38a6b48843126402088a309597e682f40fe6 (diff)
downloadexternal_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.zip
external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.gz
external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.bz2
Merge webkit.org at r58033 : Initial merge by git
Change-Id: If006c38561af287c50cd578d251629b51e4d8cd1
Diffstat (limited to 'WebCore/bridge/objc')
-rw-r--r--WebCore/bridge/objc/ObjCRuntimeObject.h52
-rw-r--r--WebCore/bridge/objc/ObjCRuntimeObject.mm52
-rw-r--r--WebCore/bridge/objc/objc_instance.h10
-rw-r--r--WebCore/bridge/objc/objc_instance.mm53
-rw-r--r--WebCore/bridge/objc/objc_runtime.mm22
5 files changed, 165 insertions, 24 deletions
diff --git a/WebCore/bridge/objc/ObjCRuntimeObject.h b/WebCore/bridge/objc/ObjCRuntimeObject.h
new file mode 100644
index 0000000..5c44157
--- /dev/null
+++ b/WebCore/bridge/objc/ObjCRuntimeObject.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ObjCRuntimeObject_h
+#define ObjCRuntimeObject_h
+
+#include "runtime_object.h"
+
+namespace JSC {
+namespace Bindings {
+
+class ObjcInstance;
+
+class ObjCRuntimeObject : public RuntimeObject {
+public:
+ ObjCRuntimeObject(ExecState*, PassRefPtr<ObjcInstance>);
+ virtual ~ObjCRuntimeObject();
+
+ ObjcInstance* getInternalObjCInstance() const;
+
+ static const ClassInfo s_info;
+
+private:
+ virtual const ClassInfo* classInfo() const { return &s_info; }
+};
+
+}
+}
+
+#endif
diff --git a/WebCore/bridge/objc/ObjCRuntimeObject.mm b/WebCore/bridge/objc/ObjCRuntimeObject.mm
new file mode 100644
index 0000000..c7c4e98
--- /dev/null
+++ b/WebCore/bridge/objc/ObjCRuntimeObject.mm
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "ObjCRuntimeObject.h"
+#import "objc_instance.h"
+
+namespace JSC {
+namespace Bindings {
+
+const ClassInfo ObjCRuntimeObject::s_info = { "ObjCRuntimeObject", &RuntimeObject::s_info, 0, 0 };
+
+ObjCRuntimeObject::ObjCRuntimeObject(ExecState* exec, PassRefPtr<ObjcInstance> instance)
+ : RuntimeObject(exec, instance)
+{
+}
+
+ObjCRuntimeObject::~ObjCRuntimeObject()
+{
+}
+
+ObjcInstance* ObjCRuntimeObject::getInternalObjCInstance() const
+{
+ return static_cast<ObjcInstance*>(getInternalInstance());
+}
+
+
+}
+}
diff --git a/WebCore/bridge/objc/objc_instance.h b/WebCore/bridge/objc/objc_instance.h
index 64cd491..7e87188 100644
--- a/WebCore/bridge/objc/objc_instance.h
+++ b/WebCore/bridge/objc/objc_instance.h
@@ -46,8 +46,10 @@ public:
virtual JSValue valueOf(ExecState*) const;
virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
-
- virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList&);
+
+ virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName);
+ JSValue invokeObjcMethod(ExecState*, ObjcMethod* method, const ArgList&);
+ virtual JSValue invokeMethod(ExecState*, RuntimeMethod* method, const ArgList&);
virtual bool supportsInvokeDefaultMethod() const;
virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&);
@@ -68,7 +70,9 @@ private:
static void moveGlobalExceptionToExecState(ExecState*);
ObjcInstance(ObjectStructPtr, PassRefPtr<RootObject>);
-
+
+ virtual RuntimeObject* newRuntimeObject(ExecState*);
+
RetainPtr<ObjectStructPtr> _instance;
mutable ObjcClass *_class;
ObjectStructPtr _pool;
diff --git a/WebCore/bridge/objc/objc_instance.mm b/WebCore/bridge/objc/objc_instance.mm
index 86b701b..de330ae 100644
--- a/WebCore/bridge/objc/objc_instance.mm
+++ b/WebCore/bridge/objc/objc_instance.mm
@@ -26,7 +26,9 @@
#import "config.h"
#import "objc_instance.h"
+#import "runtime_method.h"
#import "FoundationExtras.h"
+#import "ObjCRuntimeObject.h"
#import "WebScriptObject.h"
#import <objc/objc-auto.h>
#import <runtime/Error.h>
@@ -52,15 +54,20 @@ static NSMapTable *s_instanceWrapperCache;
static NSMapTable *createInstanceWrapperCache()
{
#ifdef BUILDING_ON_TIGER
- return NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
+ return NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
#else
// NSMapTable with zeroing weak pointers is the recommended way to build caches like this under garbage collection.
- NSPointerFunctionsOptions keyOptions = NSPointerFunctionsZeroingWeakMemory | NSPointerFunctionsObjectPersonality;
+ NSPointerFunctionsOptions keyOptions = NSPointerFunctionsZeroingWeakMemory | NSPointerFunctionsOpaquePersonality;
NSPointerFunctionsOptions valueOptions = NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality;
return [[NSMapTable alloc] initWithKeyOptions:keyOptions valueOptions:valueOptions capacity:0];
#endif
}
+RuntimeObject* ObjcInstance::newRuntimeObject(ExecState* exec)
+{
+ return new (exec) ObjCRuntimeObject(exec, this);
+}
+
void ObjcInstance::setGlobalException(NSString* exception, JSGlobalObject* exceptionEnvironment)
{
HardRelease(s_exception);
@@ -167,7 +174,41 @@ bool ObjcInstance::supportsInvokeDefaultMethod() const
return [_instance.get() respondsToSelector:@selector(invokeDefaultMethodWithArguments:)];
}
-JSValue ObjcInstance::invokeMethod(ExecState* exec, const MethodList &methodList, const ArgList &args)
+class ObjCRuntimeMethod : public RuntimeMethod {
+public:
+ ObjCRuntimeMethod(ExecState* exec, const Identifier& name, Bindings::MethodList& list)
+ : RuntimeMethod(exec, name, list)
+ {
+ }
+
+ virtual const ClassInfo* classInfo() const { return &s_info; }
+
+ static const ClassInfo s_info;
+};
+
+const ClassInfo ObjCRuntimeMethod::s_info = { "ObjCRuntimeMethod", &RuntimeMethod::s_info, 0, 0 };
+
+JSValue ObjcInstance::getMethod(ExecState* exec, const Identifier& propertyName)
+{
+ MethodList methodList = getClass()->methodsNamed(propertyName, this);
+ return new (exec) ObjCRuntimeMethod(exec, propertyName, methodList);
+}
+
+JSValue ObjcInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod, const ArgList &args)
+{
+ if (!asObject(runtimeMethod)->inherits(&ObjCRuntimeMethod::s_info))
+ return throwError(exec, TypeError, "Attempt to invoke non-plug-in method on plug-in object.");
+
+ const MethodList& methodList = *runtimeMethod->methods();
+
+ // Overloading methods is not allowed in ObjectiveC. Should only be one
+ // name match for a particular method.
+ ASSERT(methodList.size() == 1);
+
+ return invokeObjcMethod(exec, static_cast<ObjcMethod*>(methodList[0]), args);
+}
+
+JSValue ObjcInstance::invokeObjcMethod(ExecState* exec, ObjcMethod* method, const ArgList &args)
{
JSValue result = jsUndefined();
@@ -175,13 +216,7 @@ JSValue ObjcInstance::invokeMethod(ExecState* exec, const MethodList &methodList
setGlobalException(nil);
- // Overloading methods is not allowed in ObjectiveC. Should only be one
- // name match for a particular method.
- ASSERT(methodList.size() == 1);
-
@try {
- ObjcMethod* method = 0;
- method = static_cast<ObjcMethod*>(methodList[0]);
NSMethodSignature* signature = method->getMethodSignature();
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:method->selector()];
diff --git a/WebCore/bridge/objc/objc_runtime.mm b/WebCore/bridge/objc/objc_runtime.mm
index 772695c..f845a00 100644
--- a/WebCore/bridge/objc/objc_runtime.mm
+++ b/WebCore/bridge/objc/objc_runtime.mm
@@ -27,6 +27,7 @@
#include "objc_runtime.h"
#include "JSDOMBinding.h"
+#include "ObjCRuntimeObject.h"
#include "WebScriptObject.h"
#include "objc_instance.h"
#include "runtime_array.h"
@@ -216,34 +217,31 @@ void ObjcFallbackObjectImp::put(ExecState*, const Identifier&, JSValue, PutPrope
static JSValue JSC_HOST_CALL callObjCFallbackObject(ExecState* exec, JSObject* function, JSValue thisValue, const ArgList& args)
{
- if (!thisValue.inherits(&RuntimeObjectImp::s_info))
+ if (!thisValue.inherits(&ObjCRuntimeObject::s_info))
return throwError(exec, TypeError);
JSValue result = jsUndefined();
- RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(asObject(thisValue));
- Instance* instance = imp->getInternalInstance();
+ ObjCRuntimeObject* runtimeObject = static_cast<ObjCRuntimeObject*>(asObject(thisValue));
+ ObjcInstance* objcInstance = runtimeObject->getInternalObjCInstance();
- if (!instance)
- return RuntimeObjectImp::throwInvalidAccessError(exec);
+ if (!objcInstance)
+ return RuntimeObject::throwInvalidAccessError(exec);
- instance->begin();
+ objcInstance->begin();
- ObjcInstance* objcInstance = static_cast<ObjcInstance*>(instance);
id targetObject = objcInstance->getObject();
if ([targetObject respondsToSelector:@selector(invokeUndefinedMethodFromWebScript:withArguments:)]){
- ObjcClass* objcClass = static_cast<ObjcClass*>(instance->getClass());
+ ObjcClass* objcClass = static_cast<ObjcClass*>(objcInstance->getClass());
OwnPtr<ObjcMethod> fallbackMethod(new ObjcMethod(objcClass->isa(), @selector(invokeUndefinedMethodFromWebScript:withArguments:)));
const Identifier& nameIdentifier = static_cast<ObjcFallbackObjectImp*>(function)->propertyName();
RetainPtr<CFStringRef> name(AdoptCF, CFStringCreateWithCharacters(0, nameIdentifier.data(), nameIdentifier.size()));
fallbackMethod->setJavaScriptName(name.get());
- MethodList methodList;
- methodList.append(fallbackMethod.get());
- result = instance->invokeMethod(exec, methodList, args);
+ result = objcInstance->invokeObjcMethod(exec, fallbackMethod.get(), args);
}
- instance->end();
+ objcInstance->end();
return result;
}