diff options
Diffstat (limited to 'WebCore/bridge')
46 files changed, 869 insertions, 353 deletions
diff --git a/WebCore/bridge/IdentifierRep.cpp b/WebCore/bridge/IdentifierRep.cpp index 11560e3..bc599de 100644 --- a/WebCore/bridge/IdentifierRep.cpp +++ b/WebCore/bridge/IdentifierRep.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "IdentifierRep.h" +#include "JSDOMBinding.h" #include "PlatformString.h" #include <runtime/UString.h> @@ -91,7 +92,7 @@ IdentifierRep* IdentifierRep::get(const char* name) if (!name) return 0; - UString string = String::fromUTF8WithLatin1Fallback(name, strlen(name)); + UString string = stringToUString(String::fromUTF8WithLatin1Fallback(name, strlen(name))); pair<StringIdentifierMap::iterator, bool> result = stringIdentifierMap().add(string.rep(), 0); if (result.second) { ASSERT(!result.first->second); diff --git a/WebCore/bridge/NP_jsobject.cpp b/WebCore/bridge/NP_jsobject.cpp index 2b1d17f..d983f6a 100644 --- a/WebCore/bridge/NP_jsobject.cpp +++ b/WebCore/bridge/NP_jsobject.cpp @@ -230,7 +230,7 @@ bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); - JSValue function = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); + JSValue function = obj->imp->get(exec, identifierFromNPIdentifier(exec, i->string())); CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) @@ -311,7 +311,7 @@ bool _NPN_GetProperty(NPP, NPObject* o, NPIdentifier propertyName, NPVariant* va JSLock lock(SilenceAssertionsOnly); JSValue result; if (i->isString()) - result = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); + result = obj->imp->get(exec, identifierFromNPIdentifier(exec, i->string())); else result = obj->imp->get(exec, i->number()); @@ -345,7 +345,7 @@ bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVaria if (i->isString()) { PutPropertySlot slot; - obj->imp->put(exec, identifierFromNPIdentifier(i->string()), convertNPVariantToValue(exec, variant, rootObject), slot); + obj->imp->put(exec, identifierFromNPIdentifier(exec, i->string()), convertNPVariantToValue(exec, variant, rootObject), slot); } else obj->imp->put(exec, i->number(), convertNPVariantToValue(exec, variant, rootObject)); exec->clearException(); @@ -370,7 +370,7 @@ bool _NPN_RemoveProperty(NPP, NPObject* o, NPIdentifier propertyName) ExecState* exec = rootObject->globalObject()->globalExec(); IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); if (i->isString()) { - if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string()))) { + if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(exec, i->string()))) { exec->clearException(); return false; } @@ -383,7 +383,7 @@ bool _NPN_RemoveProperty(NPP, NPObject* o, NPIdentifier propertyName) JSLock lock(SilenceAssertionsOnly); if (i->isString()) - obj->imp->deleteProperty(exec, identifierFromNPIdentifier(i->string())); + obj->imp->deleteProperty(exec, identifierFromNPIdentifier(exec, i->string())); else obj->imp->deleteProperty(exec, i->number()); @@ -406,7 +406,7 @@ bool _NPN_HasProperty(NPP, NPObject* o, NPIdentifier propertyName) IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); JSLock lock(SilenceAssertionsOnly); if (i->isString()) { - bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string())); + bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(exec, i->string())); exec->clearException(); return result; } @@ -437,7 +437,7 @@ bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); - JSValue func = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); + JSValue func = obj->imp->get(exec, identifierFromNPIdentifier(exec, i->string())); exec->clearException(); return !func.isUndefined(); } @@ -474,7 +474,7 @@ bool _NPN_Enumerate(NPP, NPObject* o, NPIdentifier** identifier, uint32_t* count NPIdentifier* identifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * size)); for (unsigned i = 0; i < size; ++i) - identifiers[i] = _NPN_GetStringIdentifier(propertyNames[i].ustring().UTF8String().c_str()); + identifiers[i] = _NPN_GetStringIdentifier(propertyNames[i].ustring().UTF8String().data()); *identifier = identifiers; *count = size; diff --git a/WebCore/bridge/c/CRuntimeObject.cpp b/WebCore/bridge/c/CRuntimeObject.cpp new file mode 100644 index 0000000..47425a2 --- /dev/null +++ b/WebCore/bridge/c/CRuntimeObject.cpp @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include "config.h" + +#if ENABLE(NETSCAPE_PLUGIN_API) + +#include "CRuntimeObject.h" +#include "c_instance.h" + +namespace JSC { +namespace Bindings { + +const ClassInfo CRuntimeObject::s_info = { "CRuntimeObject", &RuntimeObject::s_info, 0, 0 }; + +CRuntimeObject::CRuntimeObject(ExecState* exec, PassRefPtr<CInstance> instance) + : RuntimeObject(exec, instance) +{ +} + +CRuntimeObject::~CRuntimeObject() +{ +} + +CInstance* CRuntimeObject::getInternalCInstance() const +{ + return static_cast<CInstance*>(getInternalInstance()); +} + + +} +} + +#endif diff --git a/WebCore/bridge/c/CRuntimeObject.h b/WebCore/bridge/c/CRuntimeObject.h new file mode 100644 index 0000000..b53387a --- /dev/null +++ b/WebCore/bridge/c/CRuntimeObject.h @@ -0,0 +1,55 @@ +/* + * 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 CRuntimeObject_h +#define CRuntimeObject_h + +#if ENABLE(NETSCAPE_PLUGIN_API) + +#include "runtime_object.h" + +namespace JSC { +namespace Bindings { + +class CInstance; + +class CRuntimeObject : public RuntimeObject { +public: + CRuntimeObject(ExecState*, PassRefPtr<CInstance>); + virtual ~CRuntimeObject(); + + CInstance* getInternalCInstance() const; + + static const ClassInfo s_info; + +private: + virtual const ClassInfo* classInfo() const { return &s_info; } +}; + +} +} + +#endif +#endif diff --git a/WebCore/bridge/c/c_class.cpp b/WebCore/bridge/c/c_class.cpp index e8499cb..ea71638 100644 --- a/WebCore/bridge/c/c_class.cpp +++ b/WebCore/bridge/c/c_class.cpp @@ -34,6 +34,7 @@ #include "npruntime_impl.h" #include <runtime/Identifier.h> #include <runtime/JSLock.h> +#include <wtf/text/StringHash.h> namespace JSC { namespace Bindings { diff --git a/WebCore/bridge/c/c_instance.cpp b/WebCore/bridge/c/c_instance.cpp index 1b05259..7dbc1d9 100644 --- a/WebCore/bridge/c/c_instance.cpp +++ b/WebCore/bridge/c/c_instance.cpp @@ -29,15 +29,17 @@ #include "c_instance.h" +#include "CRuntimeObject.h" +#include "IdentifierRep.h" #include "c_class.h" #include "c_runtime.h" #include "c_utility.h" -#include "IdentifierRep.h" #include "npruntime_impl.h" +#include "runtime_method.h" #include "runtime_root.h" +#include <interpreter/CallFrame.h> #include <runtime/ArgList.h> #include <runtime/Error.h> -#include <interpreter/CallFrame.h> #include <runtime/JSLock.h> #include <runtime/JSNumberCell.h> #include <runtime/PropertyNameArray.h> @@ -89,6 +91,11 @@ CInstance::~CInstance() _NPN_ReleaseObject(_object); } +RuntimeObject* CInstance::newRuntimeObject(ExecState* exec) +{ + return new (exec) CRuntimeObject(exec, this); +} + Class *CInstance::getClass() const { if (!_class) @@ -101,8 +108,33 @@ bool CInstance::supportsInvokeDefaultMethod() const return _object->_class->invokeDefault; } -JSValue CInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList& args) +class CRuntimeMethod : public RuntimeMethod { +public: + CRuntimeMethod(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 CRuntimeMethod::s_info = { "CRuntimeMethod", &RuntimeMethod::s_info, 0, 0 }; + +JSValue CInstance::getMethod(ExecState* exec, const Identifier& propertyName) +{ + MethodList methodList = getClass()->methodsNamed(propertyName, this); + return new (exec) CRuntimeMethod(exec, propertyName, methodList); +} + +JSValue CInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod, const ArgList& args) { + if (!asObject(runtimeMethod)->inherits(&CRuntimeMethod::s_info)) + return throwError(exec, TypeError, "Attempt to invoke non-plug-in method on plug-in object."); + + const MethodList& methodList = *runtimeMethod->methods(); + // Overloading methods are not allowed by NPObjects. Should only be one // name match for a particular method. ASSERT(methodList.size() == 1); @@ -271,7 +303,7 @@ void CInstance::getPropertyNames(ExecState* exec, PropertyNameArray& nameArray) IdentifierRep* identifier = static_cast<IdentifierRep*>(identifiers[i]); if (identifier->isString()) - nameArray.add(identifierFromNPIdentifier(identifier->string())); + nameArray.add(identifierFromNPIdentifier(exec, identifier->string())); else nameArray.add(Identifier::from(exec, identifier->number())); } diff --git a/WebCore/bridge/c/c_instance.h b/WebCore/bridge/c/c_instance.h index abbabad..be4a4cb 100644 --- a/WebCore/bridge/c/c_instance.h +++ b/WebCore/bridge/c/c_instance.h @@ -59,7 +59,8 @@ 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); + virtual JSValue invokeMethod(ExecState*, RuntimeMethod* method, const ArgList&); virtual bool supportsInvokeDefaultMethod() const; virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&); @@ -77,6 +78,8 @@ public: private: CInstance(NPObject*, PassRefPtr<RootObject>); + virtual RuntimeObject* newRuntimeObject(ExecState*); + mutable CClass *_class; NPObject *_object; }; diff --git a/WebCore/bridge/c/c_utility.cpp b/WebCore/bridge/c/c_utility.cpp index 7ff77e7..3e65eb9 100644 --- a/WebCore/bridge/c/c_utility.cpp +++ b/WebCore/bridge/c/c_utility.cpp @@ -30,6 +30,7 @@ #include "c_utility.h" +#include "CRuntimeObject.h" #include "JSDOMWindow.h" #include "NP_jsobject.h" #include "c_instance.h" @@ -75,7 +76,7 @@ void convertValueToNPVariant(ExecState* exec, JSValue value, NPVariant* result) if (value.isString()) { UString ustring = value.toString(exec); CString cstring = ustring.UTF8String(); - NPString string = { (const NPUTF8*)cstring.c_str(), static_cast<uint32_t>(cstring.size()) }; + NPString string = { (const NPUTF8*)cstring.data(), static_cast<uint32_t>(cstring.length()) }; NPN_InitializeVariantWithStringCopy(result, &string); } else if (value.isNumber()) { DOUBLE_TO_NPVARIANT(value.toNumber(exec), *result); @@ -85,9 +86,9 @@ void convertValueToNPVariant(ExecState* exec, JSValue value, NPVariant* result) NULL_TO_NPVARIANT(*result); } else if (value.isObject()) { JSObject* object = asObject(value); - if (object->classInfo() == &RuntimeObjectImp::s_info) { - RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(object); - CInstance* instance = static_cast<CInstance*>(imp->getInternalInstance()); + if (object->classInfo() == &CRuntimeObject::s_info) { + CRuntimeObject* runtimeObject = static_cast<CRuntimeObject*>(object); + CInstance* instance = runtimeObject->getInternalCInstance(); if (instance) { NPObject* obj = instance->getObject(); _NPN_RetainObject(obj); @@ -142,9 +143,9 @@ String convertNPStringToUTF16(const NPString* string) return String::fromUTF8WithLatin1Fallback(string->UTF8Characters, string->UTF8Length); } -Identifier identifierFromNPIdentifier(const NPUTF8* name) +Identifier identifierFromNPIdentifier(ExecState* exec, const NPUTF8* name) { - return Identifier(WebCore::JSDOMWindow::commonJSGlobalData(), convertUTF8ToUTF16WithLatin1Fallback(name, -1)); + return Identifier(exec, stringToUString(convertUTF8ToUTF16WithLatin1Fallback(name, -1))); } } } diff --git a/WebCore/bridge/c/c_utility.h b/WebCore/bridge/c/c_utility.h index f69bba6..6af8fb6 100644 --- a/WebCore/bridge/c/c_utility.h +++ b/WebCore/bridge/c/c_utility.h @@ -49,7 +49,7 @@ typedef uint16_t NPUTF16; WebCore::String convertNPStringToUTF16(const NPString *string); void convertValueToNPVariant(ExecState*, JSValue, NPVariant* result); JSValue convertNPVariantToValue(ExecState*, const NPVariant*, RootObject*); -Identifier identifierFromNPIdentifier(const NPUTF8* name); +Identifier identifierFromNPIdentifier(ExecState*, const NPUTF8* name); } } diff --git a/WebCore/bridge/jni/JNIBridge.cpp b/WebCore/bridge/jni/JNIBridge.cpp index f8a3979..28e8698 100644 --- a/WebCore/bridge/jni/JNIBridge.cpp +++ b/WebCore/bridge/jni/JNIBridge.cpp @@ -29,19 +29,10 @@ #if ENABLE(MAC_JAVA_BRIDGE) -#include "CString.h" #include "StringBuilder.h" +#include <wtf/text/CString.h> -#ifdef NDEBUG -#define JS_LOG(formatAndArgs...) ((void)0) -#else -#define JS_LOG(formatAndArgs...) { \ - fprintf(stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ - fprintf(stderr, formatAndArgs); \ -} -#endif - using namespace JSC; using namespace JSC::Bindings; using namespace WebCore; diff --git a/WebCore/bridge/jni/JNIUtility.cpp b/WebCore/bridge/jni/JNIUtility.cpp index e558955..ece39ed 100644 --- a/WebCore/bridge/jni/JNIUtility.cpp +++ b/WebCore/bridge/jni/JNIUtility.cpp @@ -77,7 +77,7 @@ JavaVM* getJavaVM() if (jniError == JNI_OK && nJVMs > 0) jvm = jvmArray[0]; else - fprintf(stderr, "%s: JNI_GetCreatedJavaVMs failed, returned %ld\n", __PRETTY_FUNCTION__, static_cast<long>(jniError)); + LOG_ERROR("JNI_GetCreatedJavaVMs failed, returned %ld", static_cast<long>(jniError)); return jvm; } @@ -93,7 +93,7 @@ JNIEnv* getJNIEnv() jniError = getJavaVM()->AttachCurrentThread(&u.dummy, 0); if (jniError == JNI_OK) return u.env; - fprintf(stderr, "%s: AttachCurrentThread failed, returned %ld\n", __PRETTY_FUNCTION__, static_cast<long>(jniError)); + LOG_ERROR("AttachCurrentThread failed, returned %ld", static_cast<long>(jniError)); return 0; } @@ -319,10 +319,10 @@ jvalue getJNIField(jobject obj, JNIType type, const char* name, const char* sign result.d = env->functions->GetDoubleField(env, obj, field); break; default: - fprintf(stderr, "%s: invalid field type (%d)\n", __PRETTY_FUNCTION__, static_cast<int>(type)); + LOG_ERROR("Invalid field type (%d)", static_cast<int>(type)); } } else { - fprintf(stderr, "%s: Could not find field: %s\n", __PRETTY_FUNCTION__, name); + LOG_ERROR("Could not find field: %s", name); env->ExceptionDescribe(); env->ExceptionClear(); fprintf(stderr, "\n"); @@ -330,7 +330,7 @@ jvalue getJNIField(jobject obj, JNIType type, const char* name, const char* sign env->DeleteLocalRef(cls); } else - fprintf(stderr, "%s: Could not find class for object\n", __PRETTY_FUNCTION__); + LOG_ERROR("Could not find class for object"); } return result; diff --git a/WebCore/bridge/jni/JNIUtility.h b/WebCore/bridge/jni/JNIUtility.h index c832ef3..0eb889c 100644 --- a/WebCore/bridge/jni/JNIUtility.h +++ b/WebCore/bridge/jni/JNIUtility.h @@ -212,14 +212,14 @@ static T callJNIMethodV(jobject obj, const char* name, const char* sig, va_list env->DeleteLocalRef(cls); return JNICaller<T>::callV(obj, mid, args); } - fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, name, obj); + LOG_ERROR("Could not find method: %s for %p", name, obj); env->ExceptionDescribe(); env->ExceptionClear(); fprintf(stderr, "\n"); env->DeleteLocalRef(cls); } else - fprintf(stderr, "%s: Could not find class for %p\n", __PRETTY_FUNCTION__, obj); + LOG_ERROR("Could not find class for %p", obj); } return 0; @@ -254,7 +254,7 @@ T callJNIStaticMethod(jclass cls, const char* methodName, const char* methodSign if (mid) result = JNICaller<T>::callStaticV(cls, mid, args); else { - fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, methodName, cls); + LOG_ERROR("Could not find method: %s for %p", methodName, cls); env->ExceptionDescribe(); env->ExceptionClear(); fprintf(stderr, "\n"); diff --git a/WebCore/bridge/jni/jni_jsobject.mm b/WebCore/bridge/jni/jni_jsobject.mm index 603624f..5e036ab 100644 --- a/WebCore/bridge/jni/jni_jsobject.mm +++ b/WebCore/bridge/jni/jni_jsobject.mm @@ -29,10 +29,12 @@ #if ENABLE(MAC_JAVA_BRIDGE) #include "Frame.h" +#include "JavaRuntimeObject.h" #include "JNIBridge.h" #include "JNIUtility.h" #include "JNIUtilityPrivate.h" #include "JSDOMBinding.h" +#include "Logging.h" #include "ScriptController.h" #include "StringSourceProvider.h" #include "WebCoreFrameView.h" @@ -42,21 +44,12 @@ #include <runtime/Completion.h> #include <runtime/JSGlobalObject.h> #include <runtime/JSLock.h> -#include <wtf/Assertions.h> using WebCore::Frame; using namespace JSC::Bindings; using namespace JSC; - -#ifdef NDEBUG -#define JS_LOG(formatAndArgs...) ((void)0) -#else -#define JS_LOG(formatAndArgs...) { \ - fprintf (stderr, "%s(%p,%p): ", __PRETTY_FUNCTION__, _performJavaScriptRunLoop, CFRunLoopGetCurrent()); \ - fprintf(stderr, formatAndArgs); \ -} -#endif +using namespace WebCore; #define UndefinedHandle 1 @@ -68,12 +61,12 @@ static CFRunLoopSourceRef completionSource; static void completedJavaScriptAccess (void *i) { - assert (CFRunLoopGetCurrent() != _performJavaScriptRunLoop); + ASSERT(CFRunLoopGetCurrent() != _performJavaScriptRunLoop); JSObjectCallContext *callContext = (JSObjectCallContext *)i; CFRunLoopRef runLoop = (CFRunLoopRef)callContext->originatingLoop; - assert (CFRunLoopGetCurrent() == runLoop); + ASSERT(CFRunLoopGetCurrent() == runLoop); CFRunLoopStop(runLoop); } @@ -115,7 +108,7 @@ static void dispatchToJavaScriptThread(JSObjectCallContext *context) CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent(); - assert (currentRunLoop != _performJavaScriptRunLoop); + ASSERT(currentRunLoop != _performJavaScriptRunLoop); // Setup a source to signal once the invocation of the JavaScript // call completes. @@ -144,7 +137,7 @@ static void dispatchToJavaScriptThread(JSObjectCallContext *context) static void performJavaScriptAccess(void*) { - assert (CFRunLoopGetCurrent() == _performJavaScriptRunLoop); + ASSERT(CFRunLoopGetCurrent() == _performJavaScriptRunLoop); // Dispatch JavaScript calls here. CFRunLoopSourceContext sourceContext; @@ -205,7 +198,7 @@ jvalue JavaJSObject::invoke(JSObjectCallContext *context) else { JSObject *imp = jlong_to_impptr(nativeHandle); if (!findProtectingRootObject(imp)) { - fprintf (stderr, "%s:%d: Attempt to access JavaScript from destroyed applet, type %d.\n", __FILE__, __LINE__, context->type); + LOG_ERROR("Attempt to access JavaScript from destroyed applet, type %d.", context->type); return result; } @@ -256,7 +249,7 @@ jvalue JavaJSObject::invoke(JSObjectCallContext *context) } default: { - fprintf (stderr, "%s: invalid JavaScript call\n", __PRETTY_FUNCTION__); + LOG_ERROR("invalid JavaScript call"); } } } @@ -283,7 +276,7 @@ RootObject* JavaJSObject::rootObject() const jobject JavaJSObject::call(jstring methodName, jobjectArray args) const { - JS_LOG ("methodName = %s\n", JavaString(methodName).UTF8String()); + LOG(LiveConnect, "JavaJSObject::call methodName = %s", JavaString(methodName).UTF8String()); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -312,7 +305,7 @@ jobject JavaJSObject::call(jstring methodName, jobjectArray args) const jobject JavaJSObject::eval(jstring script) const { - JS_LOG ("script = %s\n", JavaString(script).UTF8String()); + LOG(LiveConnect, "JavaJSObject::eval script = %s", JavaString(script).UTF8String()); JSValue result; @@ -339,7 +332,7 @@ jobject JavaJSObject::eval(jstring script) const jobject JavaJSObject::getMember(jstring memberName) const { - JS_LOG ("(%p) memberName = %s\n", _imp, JavaString(memberName).UTF8String()); + LOG(LiveConnect, "JavaJSObject::getMember (%p) memberName = %s", _imp, JavaString(memberName).UTF8String()); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -355,7 +348,7 @@ jobject JavaJSObject::getMember(jstring memberName) const void JavaJSObject::setMember(jstring memberName, jobject value) const { - JS_LOG ("memberName = %s, value = %p\n", JavaString(memberName).UTF8String(), value); + LOG(LiveConnect, "JavaJSObject::setMember memberName = %s, value = %p", JavaString(memberName).UTF8String(), value); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -371,7 +364,7 @@ void JavaJSObject::setMember(jstring memberName, jobject value) const void JavaJSObject::removeMember(jstring memberName) const { - JS_LOG ("memberName = %s\n", JavaString(memberName).UTF8String()); + LOG(LiveConnect, "JavaJSObject::removeMember memberName = %s", JavaString(memberName).UTF8String()); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -385,11 +378,7 @@ void JavaJSObject::removeMember(jstring memberName) const jobject JavaJSObject::getSlot(jint index) const { -#ifdef __LP64__ - JS_LOG ("index = %d\n", index); -#else - JS_LOG ("index = %ld\n", index); -#endif + LOG(LiveConnect, "JavaJSObject::getSlot index = %ld", static_cast<long>(index)); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -406,11 +395,7 @@ jobject JavaJSObject::getSlot(jint index) const void JavaJSObject::setSlot(jint index, jobject value) const { -#ifdef __LP64__ - JS_LOG ("index = %d, value = %p\n", index, value); -#else - JS_LOG ("index = %ld, value = %p\n", index, value); -#endif + LOG(LiveConnect, "JavaJSObject::setSlot index = %ld, value = %p", static_cast<long>(index), value); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -424,7 +409,7 @@ void JavaJSObject::setSlot(jint index, jobject value) const jstring JavaJSObject::toString() const { - JS_LOG ("\n"); + LOG(LiveConnect, "JavaJSObject::toString"); RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -434,7 +419,7 @@ jstring JavaJSObject::toString() const JSObject *thisObj = const_cast<JSObject*>(_imp); ExecState* exec = rootObject->globalObject()->globalExec(); - return (jstring)convertValueToJValue (exec, thisObj, object_type, "java.lang.String").l; + return static_cast<jstring>(convertValueToJValue(exec, rootObject, thisObj, object_type, "java.lang.String").l); } void JavaJSObject::finalize() const @@ -462,7 +447,7 @@ static PassRefPtr<RootObject> createRootObject(void* nativeHandle) // another JavaJSObject. jlong JavaJSObject::createNative(jlong nativeHandle) { - JS_LOG ("nativeHandle = %d\n", (int)nativeHandle); + LOG(LiveConnect, "JavaJSObject::createNative nativeHandle = %d", static_cast<int>(nativeHandle)); if (nativeHandle == UndefinedHandle) return nativeHandle; @@ -528,27 +513,25 @@ jobject JavaJSObject::convertValueToJObject(JSValue value) const jlong nativeHandle; if (value.isObject()) { - JSObject* imp = asObject(value); + JSObject* object = asObject(value); // We either have a wrapper around a Java instance or a JavaScript // object. If we have a wrapper around a Java instance, return that // instance, otherwise create a new Java JavaJSObject with the JSObject* // as its nativeHandle. - if (imp->classInfo() && strcmp(imp->classInfo()->className, "RuntimeObject") == 0) { - RuntimeObjectImp* runtimeImp = static_cast<RuntimeObjectImp*>(imp); - JavaInstance *runtimeInstance = static_cast<JavaInstance *>(runtimeImp->getInternalInstance()); + if (object->inherits(&JavaRuntimeObject::s_info)) { + JavaRuntimeObject* runtimeObject = static_cast<JavaRuntimeObject*>(object); + JavaInstance* runtimeInstance = runtimeObject->getInternalJavaInstance(); if (!runtimeInstance) return 0; return runtimeInstance->javaInstance(); + } else { + nativeHandle = ptr_to_jlong(object); + rootObject->gcProtect(object); } - else { - nativeHandle = ptr_to_jlong(imp); - rootObject->gcProtect(imp); - } - } + } else { // All other types will result in an undefined object. - else { nativeHandle = UndefinedHandle; } diff --git a/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp b/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp index 8776cd2..6de1011 100644 --- a/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp +++ b/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp @@ -30,22 +30,14 @@ #if ENABLE(MAC_JAVA_BRIDGE) #include "JNIUtilityPrivate.h" +#include "Logging.h" #include "runtime_array.h" #include "runtime_object.h" #include <runtime/Error.h> -#ifdef NDEBUG -#define JS_LOG(formatAndArgs...) ((void)0) -#else -#define JS_LOG(formatAndArgs...) { \ - fprintf(stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ - fprintf(stderr, formatAndArgs); \ -} -#endif - using namespace JSC; using namespace JSC::Bindings; - +using namespace WebCore; JavaField::JavaField(JNIEnv* env, jobject aField) { @@ -116,6 +108,9 @@ JSValue JavaField::valueFromInstance(ExecState* exec, const Instance* i) const jvalue result = dispatchValueFromInstance(exec, instance, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", object_type); jobject anObject = result.l; + if (!anObject) + return jsNull(); + const char* arrayType = type(); if (arrayType[0] == '[') jsresult = JavaArray::convertJObjectToArray(exec, anObject, arrayType, instance->rootObject()); @@ -155,7 +150,7 @@ JSValue JavaField::valueFromInstance(ExecState* exec, const Instance* i) const break; } - JS_LOG("getting %s = %s\n", UString(name()).UTF8String().c_str(), jsresult.toString(exec).ascii()); + LOG(LiveConnect, "JavaField::valueFromInstance getting %s = %s", UString(name()).UTF8String().data(), jsresult.toString(exec).ascii()); return jsresult; } @@ -189,9 +184,9 @@ void JavaField::dispatchSetValueToInstance(ExecState* exec, const JavaInstance* void JavaField::setValueToInstance(ExecState* exec, const Instance* i, JSValue aValue) const { const JavaInstance* instance = static_cast<const JavaInstance*>(i); - jvalue javaValue = convertValueToJValue(exec, aValue, m_JNIType, type()); + jvalue javaValue = convertValueToJValue(exec, i->rootObject(), aValue, m_JNIType, type()); - JS_LOG("setting value %s to %s\n", UString(name()).UTF8String().c_str(), aValue.toString(exec).ascii()); + LOG(LiveConnect, "JavaField::setValueToInstance setting value %s to %s", UString(name()).UTF8String().data(), aValue.toString(exec).ascii()); switch (m_JNIType) { case array_type: @@ -261,7 +256,6 @@ JavaArray::JavaArray(jobject array, const char* type, PassRefPtr<RootObject> roo JNIEnv* env = getJNIEnv(); m_length = env->GetArrayLength(static_cast<jarray>(m_array->m_instance)); m_type = strdup(type); - m_rootObject = rootObject; } JavaArray::~JavaArray() @@ -287,7 +281,7 @@ void JavaArray::setValueAt(ExecState* exec, unsigned index, JSValue aValue) cons javaClassName = strdup(&m_type[2]); javaClassName[strchr(javaClassName, ';')-javaClassName] = 0; } - jvalue aJValue = convertValueToJValue(exec, aValue, arrayType, javaClassName); + jvalue aJValue = convertValueToJValue(exec, m_rootObject.get(), aValue, arrayType, javaClassName); switch (arrayType) { case object_type: diff --git a/WebCore/bridge/jni/jsc/JNIUtilityPrivate.cpp b/WebCore/bridge/jni/jsc/JNIUtilityPrivate.cpp index 8ce150f..69782f3 100644 --- a/WebCore/bridge/jni/jsc/JNIUtilityPrivate.cpp +++ b/WebCore/bridge/jni/jsc/JNIUtilityPrivate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2003, 2010 Apple, Inc. All rights reserved. * Copyright 2009, The Android Open Source Project * * Redistribution and use in source and binary forms, with or without @@ -29,6 +29,7 @@ #if ENABLE(MAC_JAVA_BRIDGE) +#include "JavaRuntimeObject.h" #include "JNIBridgeJSC.h" #include "runtime_array.h" #include "runtime_object.h" @@ -168,59 +169,94 @@ static jobject convertArrayInstanceToJavaArray(ExecState* exec, JSArray* jsArray return jarray; } -jvalue convertValueToJValue(ExecState* exec, JSValue value, JNIType jniType, const char* javaClassName) +jvalue convertValueToJValue(ExecState* exec, RootObject* rootObject, JSValue value, JNIType jniType, const char* javaClassName) { JSLock lock(SilenceAssertionsOnly); jvalue result; + memset(&result, 0, sizeof(jvalue)); switch (jniType) { case array_type: case object_type: { - result.l = (jobject)0; + // FIXME: JavaJSObject::convertValueToJObject functionality is almost exactly the same, + // these functions should use common code. - // First see if we have a Java instance. if (value.isObject()) { - JSObject* objectImp = asObject(value); - if (objectImp->classInfo() == &RuntimeObjectImp::s_info) { - RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(objectImp); - JavaInstance* instance = static_cast<JavaInstance*>(imp->getInternalInstance()); + JSObject* object = asObject(value); + if (object->inherits(&JavaRuntimeObject::s_info)) { + // Unwrap a Java instance. + JavaRuntimeObject* runtimeObject = static_cast<JavaRuntimeObject*>(object); + JavaInstance* instance = runtimeObject->getInternalJavaInstance(); if (instance) result.l = instance->javaInstance(); - } else if (objectImp->classInfo() == &RuntimeArray::s_info) { + } else if (object->classInfo() == &RuntimeArray::s_info) { // Input is a JavaScript Array that was originally created from a Java Array - RuntimeArray* imp = static_cast<RuntimeArray*>(objectImp); + RuntimeArray* imp = static_cast<RuntimeArray*>(object); JavaArray* array = static_cast<JavaArray*>(imp->getConcreteArray()); result.l = array->javaArray(); - } else if (objectImp->classInfo() == &JSArray::info) { + } else if (object->classInfo() == &JSArray::info) { // Input is a Javascript Array. We need to create it to a Java Array. result.l = convertArrayInstanceToJavaArray(exec, asArray(value), javaClassName); + } else if (!result.l && (!strcmp(javaClassName, "java.lang.Object")) || (!strcmp(javaClassName, "netscape.javascript.JSObject"))) { + // Wrap objects in JSObject instances. + JNIEnv* env = getJNIEnv(); + jclass jsObjectClass = env->FindClass("sun/plugin/javascript/webkit/JSObject"); + jmethodID constructorID = env->GetMethodID(jsObjectClass, "<init>", "(J)V"); + if (constructorID) { + jlong nativeHandle = ptr_to_jlong(object); + rootObject->gcProtect(object); + result.l = env->NewObject(jsObjectClass, constructorID, nativeHandle); + } } } - // Now convert value to a string if the target type is a java.lang.string, and we're not - // converting from a Null. - if (!result.l && !strcmp(javaClassName, "java.lang.String")) { -#ifdef CONVERT_NULL_TO_EMPTY_STRING - if (value->isNull()) { + // Create an appropriate Java object if target type is java.lang.Object. + if (!result.l && !strcmp(javaClassName, "java.lang.Object")) { + if (value.isString()) { + UString stringValue = asString(value)->value(exec); JNIEnv* env = getJNIEnv(); - jchar buf[2]; - jobject javaString = env->functions->NewString(env, buf, 0); + jobject javaString = env->functions->NewString(env, (const jchar*)stringValue.data(), stringValue.size()); result.l = javaString; - } else -#else - if (!value.isNull()) -#endif - { + } else if (value.isNumber()) { + double doubleValue = value.uncheckedGetNumber(); + JNIEnv* env = getJNIEnv(); + jclass clazz = env->FindClass("java/lang/Double"); + jmethodID constructor = env->GetMethodID(clazz, "<init>", "(D)V"); + jobject javaDouble = env->functions->NewObject(env, clazz, constructor, doubleValue); + result.l = javaDouble; + } else if (value.isBoolean()) { + bool boolValue = value.getBoolean(); + JNIEnv* env = getJNIEnv(); + jclass clazz = env->FindClass("java/lang/Boolean"); + jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Z)V"); + jobject javaBoolean = env->functions->NewObject(env, clazz, constructor, boolValue); + result.l = javaBoolean; + } else if (value.isUndefined()) { + UString stringValue = "undefined"; + JNIEnv* env = getJNIEnv(); + jobject javaString = env->functions->NewString(env, (const jchar*)stringValue.data(), stringValue.size()); + result.l = javaString; + } + } + + // Convert value to a string if the target type is a java.lang.String, and we're not + // converting from a null. + if (!result.l && !strcmp(javaClassName, "java.lang.String")) { + if (!value.isNull()) { UString stringValue = value.toString(exec); JNIEnv* env = getJNIEnv(); - jobject javaString = env->functions->NewString(env, (const jchar *)stringValue.data(), stringValue.size()); + jobject javaString = env->functions->NewString(env, (const jchar*)stringValue.data(), stringValue.size()); result.l = javaString; } +<<<<<<< HEAD } else if (!result.l) // ANDROID memset(&result, 0, sizeof(jvalue)); // Handle it the same as a void case +======= + } +>>>>>>> webkit.org at r58033 } break; @@ -272,15 +308,15 @@ jvalue convertValueToJValue(ExecState* exec, JSValue value, JNIType jniType, con } break; - break; - case invalid_type: - default: case void_type: +<<<<<<< HEAD { // ANDROID memset(&result, 0, sizeof(jvalue)); } +======= +>>>>>>> webkit.org at r58033 break; } return result; diff --git a/WebCore/bridge/jni/jsc/JNIUtilityPrivate.h b/WebCore/bridge/jni/jsc/JNIUtilityPrivate.h index 0297f97..8d4652d 100644 --- a/WebCore/bridge/jni/jsc/JNIUtilityPrivate.h +++ b/WebCore/bridge/jni/jsc/JNIUtilityPrivate.h @@ -39,7 +39,9 @@ class JSObject; namespace Bindings { -jvalue convertValueToJValue(ExecState*, JSValue, JNIType, const char* javaClassName); +class RootObject; + +jvalue convertValueToJValue(ExecState*, RootObject*, JSValue, JNIType, const char* javaClassName); bool dispatchJNICall(ExecState*, const void* targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue* args, jvalue& result, const char* callingURL, JSValue& exceptionDescription); } // namespace Bindings diff --git a/WebCore/bridge/jni/jsc/JavaClassJSC.cpp b/WebCore/bridge/jni/jsc/JavaClassJSC.cpp index ec5c172..e1b8b4c 100644 --- a/WebCore/bridge/jni/jsc/JavaClassJSC.cpp +++ b/WebCore/bridge/jni/jsc/JavaClassJSC.cpp @@ -40,7 +40,7 @@ JavaClass::JavaClass(jobject anInstance) jobject aClass = callJNIMethod<jobject>(anInstance, "getClass", "()Ljava/lang/Class;"); if (!aClass) { - fprintf(stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, anInstance); + LOG_ERROR("Unable to call getClass on instance %p", anInstance); m_name = fastStrDup("<Unknown>"); return; } diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp index f2a2cf4..666df54 100644 --- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp @@ -28,16 +28,20 @@ #if ENABLE(MAC_JAVA_BRIDGE) +#include "JavaRuntimeObject.h" #include "JNIBridgeJSC.h" #include "JNIUtility.h" #include "JNIUtilityPrivate.h" #include "JavaClassJSC.h" +#include "Logging.h" +#include "runtime_method.h" #include "runtime_object.h" #include "runtime_root.h" #include <runtime/ArgList.h> #include <runtime/Error.h> #include <runtime/JSLock.h> +<<<<<<< HEAD #if PLATFORM(ANDROID) #include <assert.h> #endif @@ -56,8 +60,11 @@ #define LOG_TAG JavaInstanceJSC.cpp #endif +======= +>>>>>>> webkit.org at r58033 using namespace JSC::Bindings; using namespace JSC; +using namespace WebCore; JavaInstance::JavaInstance(jobject instance, PassRefPtr<RootObject> rootObject) : Instance(rootObject) @@ -71,6 +78,11 @@ JavaInstance::~JavaInstance() delete m_class; } +RuntimeObject* JavaInstance::newRuntimeObject(ExecState* exec) +{ + return new (exec) JavaRuntimeObject(exec, this); +} + #define NUM_LOCAL_REFS 64 void JavaInstance::virtualBegin() @@ -119,10 +131,35 @@ JSValue JavaInstance::booleanValue() const return jsBoolean(booleanValue); } -JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList &args) +class JavaRuntimeMethod : public RuntimeMethod { +public: + JavaRuntimeMethod(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 JavaRuntimeMethod::s_info = { "JavaRuntimeMethod", &RuntimeMethod::s_info, 0, 0 }; + +JSValue JavaInstance::getMethod(ExecState* exec, const Identifier& propertyName) +{ + MethodList methodList = getClass()->methodsNamed(propertyName, this); + return new (exec) JavaRuntimeMethod(exec, propertyName, methodList); +} + +JSValue JavaInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod, const ArgList &args) { - int i, count = args.size(); - jvalue* jArgs; + if (!asObject(runtimeMethod)->inherits(&JavaRuntimeMethod::s_info)) + return throwError(exec, TypeError, "Attempt to invoke non-Java method on Java object."); + + const MethodList& methodList = *runtimeMethod->methods(); + + int i; + int count = args.size(); JSValue resultValue; Method* method = 0; size_t numMethods = methodList.size(); @@ -132,31 +169,27 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList // notion of method overloading and Java does. We could // get a bit more sophisticated and attempt to does some // type checking as we as checking the number of parameters. - Method* aMethod; for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { - aMethod = methodList[methodIndex]; + Method* aMethod = methodList[methodIndex]; if (aMethod->numParameters() == count) { method = aMethod; break; } } if (!method) { - JS_LOG("unable to find an appropiate method\n"); + LOG(LiveConnect, "JavaInstance::invokeMethod unable to find an appropiate method"); return jsUndefined(); } const JavaMethod* jMethod = static_cast<const JavaMethod*>(method); - JS_LOG("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), m_instance->m_instance); + LOG(LiveConnect, "JavaInstance::invokeMethod call %s %s on %p", UString(jMethod->name()).UTF8String().data(), jMethod->signature(), m_instance->m_instance); - if (count > 0) - jArgs = (jvalue*)malloc(count * sizeof(jvalue)); - else - jArgs = 0; + Vector<jvalue> jArgs(count); for (i = 0; i < count; i++) { JavaParameter* aParameter = jMethod->parameterAt(i); - jArgs[i] = convertValueToJValue(exec, args.at(i), aParameter->getJNIType(), aParameter->type()); - JS_LOG("arg[%d] = %s\n", i, args.at(i).toString(exec).ascii()); + jArgs[i] = convertValueToJValue(exec, m_rootObject.get(), args.at(i), aParameter->getJNIType(), aParameter->type()); + LOG(LiveConnect, "JavaInstance::invokeMethod arg[%d] = %s", i, args.at(i).toString(exec).ascii()); } jvalue result; @@ -173,55 +206,53 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList jobject obj = m_instance->m_instance; JSValue exceptionDescription; const char *callingURL = 0; // FIXME, need to propagate calling URL to Java - handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); + handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs.data(), result, callingURL, exceptionDescription); if (exceptionDescription) { throwError(exec, GeneralError, exceptionDescription.toString(exec)); - free(jArgs); return jsUndefined(); } } - // The following code can be conditionally removed once we have a Tiger update that - // contains the new Java plugin. It is needed for builds prior to Tiger. +#ifdef BUILDING_ON_TIGER if (!handled) { jobject obj = m_instance->m_instance; switch (jMethod->JNIReturnType()) { case void_type: - callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs); + callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs.data()); break; case object_type: - result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs); + result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs.data()); break; case boolean_type: - result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs); + result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs.data()); break; case byte_type: - result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs); + result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs.data()); break; case char_type: - result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs); + result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs.data()); break; case short_type: - result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs); + result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs.data()); break; case int_type: - result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs); + result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs.data()); break; - case long_type: - result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs); + result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs.data()); break; case float_type: - result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs); + result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs.data()); break; case double_type: - result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs); + result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs.data()); break; + case array_type: case invalid_type: - default: break; } } +#endif switch (jMethod->JNIReturnType()) { case void_type: @@ -233,13 +264,28 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList case object_type: { if (result.l) { + // FIXME: array_type return type is handled below, can we actually get an array here? const char* arrayType = jMethod->returnType(); if (arrayType[0] == '[') resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); - else - resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); + else { + jobject classOfInstance = callJNIMethod<jobject>(result.l, "getClass", "()Ljava/lang/Class;"); + jstring className = static_cast<jstring>(callJNIMethod<jobject>(classOfInstance, "getName", "()Ljava/lang/String;")); + if (!strcmp(JavaString(className).UTF8String(), "sun.plugin.javascript.webkit.JSObject")) { + // Pull the nativeJSObject value from the Java instance. This is a pointer to the JSObject. + JNIEnv* env = getJNIEnv(); + jfieldID fieldID = env->GetFieldID(static_cast<jclass>(classOfInstance), "nativeJSObject", "J"); + jlong nativeHandle = env->GetLongField(result.l, fieldID); + // FIXME: Handling of undefined values differs between functions in JNIUtilityPrivate.cpp and those in those in jni_jsobject.mm, + // and so it does between different versions of LiveConnect spec. There should not be multiple code paths to do the same work. + if (nativeHandle == 1 /* UndefinedHandle */) + return jsUndefined(); + return static_cast<JSObject*>(jlong_to_ptr(nativeHandle)); + } else + return JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); + } } else - resultValue = jsUndefined(); + return jsUndefined(); } break; @@ -291,16 +337,21 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList } break; + case array_type: + { + const char* arrayType = jMethod->returnType(); + ASSERT(arrayType[0] == '['); + resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); + } + break; + case invalid_type: - default: { resultValue = jsUndefined(); } break; } - free(jArgs); - return resultValue; } @@ -328,11 +379,15 @@ JSValue JavaInstance::valueOf(ExecState* exec) const JObjectWrapper::JObjectWrapper(jobject instance) : m_refCount(0) { +<<<<<<< HEAD assert(instance); #if PLATFORM(ANDROID) if (!instance) LOGE("Attempted to create JObjectWrapper for null object"); #endif +======= + ASSERT(instance); +>>>>>>> webkit.org at r58033 // Cache the JNIEnv used to get the global ref for this java instance. // It'll be used to delete the reference. @@ -340,19 +395,24 @@ JObjectWrapper::JObjectWrapper(jobject instance) m_instance = m_env->NewGlobalRef(instance); - JS_LOG("new global ref %p for %p\n", m_instance, instance); + LOG(LiveConnect, "JObjectWrapper ctor new global ref %p for %p", m_instance, instance); +<<<<<<< HEAD if (!m_instance) #if PLATFORM(ANDROID) LOGE("%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); #else fprintf(stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); #endif +======= + if (!m_instance) + LOG_ERROR("Could not get GlobalRef for %p", instance); +>>>>>>> webkit.org at r58033 } JObjectWrapper::~JObjectWrapper() { - JS_LOG("deleting global ref %p\n", m_instance); + LOG(LiveConnect, "JObjectWrapper dtor deleting global ref %p", m_instance); m_env->DeleteGlobalRef(m_instance); } diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.h b/WebCore/bridge/jni/jsc/JavaInstanceJSC.h index a46c6d3..d395cc8 100644 --- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.h +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.h @@ -82,7 +82,8 @@ public: virtual JSValue valueOf(ExecState*) const; virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; - virtual JSValue invokeMethod(ExecState* exec, const MethodList& method, const ArgList& args); + virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName); + virtual JSValue invokeMethod(ExecState* exec, RuntimeMethod* method, const ArgList& args); jobject javaInstance() const { return m_instance->m_instance; } @@ -92,6 +93,9 @@ public: protected: JavaInstance(jobject instance, PassRefPtr<RootObject>); + + virtual RuntimeObject* newRuntimeObject(ExecState*); + virtual void virtualBegin(); virtual void virtualEnd(); diff --git a/WebCore/bridge/jni/jsc/JavaRuntimeObject.cpp b/WebCore/bridge/jni/jsc/JavaRuntimeObject.cpp new file mode 100644 index 0000000..dc58b71 --- /dev/null +++ b/WebCore/bridge/jni/jsc/JavaRuntimeObject.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "config.h" + +#include "JavaInstanceJSC.h" +#include "JavaRuntimeObject.h" + +namespace JSC { +namespace Bindings { + +const ClassInfo JavaRuntimeObject::s_info = { "JavaRuntimeObject", &RuntimeObject::s_info, 0, 0 }; + +JavaRuntimeObject::JavaRuntimeObject(ExecState* exec, PassRefPtr<JavaInstance> instance) + : RuntimeObject(exec, instance) +{ +} + +JavaRuntimeObject::~JavaRuntimeObject() +{ +} + +JavaInstance* JavaRuntimeObject::getInternalJavaInstance() const +{ + return static_cast<JavaInstance*>(getInternalInstance()); +} + + + +} +} diff --git a/WebCore/bridge/jni/jsc/JavaRuntimeObject.h b/WebCore/bridge/jni/jsc/JavaRuntimeObject.h new file mode 100644 index 0000000..d9bf693 --- /dev/null +++ b/WebCore/bridge/jni/jsc/JavaRuntimeObject.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 JavaRuntimeObject_h +#define JavaRuntimeObject_h + +#include "runtime_object.h" + +namespace JSC { +namespace Bindings { + +class JavaInstance; + +class JavaRuntimeObject : public RuntimeObject { +public: + JavaRuntimeObject(ExecState*, PassRefPtr<JavaInstance>); + virtual ~JavaRuntimeObject(); + + JavaInstance* getInternalJavaInstance() const; + + static const ClassInfo s_info; + +private: + virtual const ClassInfo* classInfo() const { return &s_info; } +}; + +} +} + +#endif diff --git a/WebCore/bridge/jni/jsc/JavaStringJSC.h b/WebCore/bridge/jni/jsc/JavaStringJSC.h index 7c37f70..0a7dad5 100644 --- a/WebCore/bridge/jni/jsc/JavaStringJSC.h +++ b/WebCore/bridge/jni/jsc/JavaStringJSC.h @@ -62,13 +62,13 @@ public: const char* UTF8String() const { - if (!m_utf8String.c_str()) { + if (!m_utf8String.data()) { JSLock lock(SilenceAssertionsOnly); m_utf8String = UString(m_rep).UTF8String(); } - return m_utf8String.c_str(); + return m_utf8String.data(); } - const jchar* uchars() const { return (const jchar*)m_rep->data(); } + const jchar* uchars() const { return (const jchar*)m_rep->characters(); } int length() const { return m_rep->length(); } UString uString() const { return UString(m_rep); } diff --git a/WebCore/bridge/jni/v8/JavaStringV8.h b/WebCore/bridge/jni/v8/JavaStringV8.h index 08d4b95..21420b7 100644 --- a/WebCore/bridge/jni/v8/JavaStringV8.h +++ b/WebCore/bridge/jni/v8/JavaStringV8.h @@ -26,8 +26,8 @@ #ifndef JavaStringV8_h #define JavaStringV8_h -#include "CString.h" #include "JNIUtility.h" +#include <wtf/text/CString.h> namespace JSC { @@ -42,7 +42,7 @@ public: { int size = e->GetStringLength(s); const char* cs = getCharactersFromJStringInEnv(e, s); - m_utf8String = WebCore::CString(cs, size); + m_utf8String = WTF::CString(cs, size); releaseCharactersForJStringInEnv(e, s, cs); } @@ -51,7 +51,7 @@ public: int length() const { return m_utf8String.length(); } private: - WebCore::CString m_utf8String; + WTF::CString m_utf8String; }; } // namespace Bindings diff --git a/WebCore/bridge/jsc/BridgeJSC.cpp b/WebCore/bridge/jsc/BridgeJSC.cpp index ed582d3..3d8f62d 100644 --- a/WebCore/bridge/jsc/BridgeJSC.cpp +++ b/WebCore/bridge/jsc/BridgeJSC.cpp @@ -83,7 +83,7 @@ void Instance::end() virtualEnd(); } -RuntimeObjectImp* Instance::createRuntimeObject(ExecState* exec) +RuntimeObject* Instance::createRuntimeObject(ExecState* exec) { ASSERT(m_rootObject); ASSERT(m_rootObject->isValid()); @@ -95,10 +95,10 @@ RuntimeObjectImp* Instance::createRuntimeObject(ExecState* exec) return m_runtimeObject; } -RuntimeObjectImp* Instance::newRuntimeObject(ExecState* exec) +RuntimeObject* Instance::newRuntimeObject(ExecState* exec) { JSLock lock(SilenceAssertionsOnly); - return new (exec)RuntimeObjectImp(exec, this); + return new (exec)RuntimeObject(exec, this); } void Instance::willDestroyRuntimeObject() diff --git a/WebCore/bridge/jsc/BridgeJSC.h b/WebCore/bridge/jsc/BridgeJSC.h index 8e2cb2b..8379170 100644 --- a/WebCore/bridge/jsc/BridgeJSC.h +++ b/WebCore/bridge/jsc/BridgeJSC.h @@ -40,13 +40,14 @@ class ArgList; class Identifier; class JSGlobalObject; class PropertyNameArray; -class RuntimeObjectImp; +class RuntimeMethod; namespace Bindings { class Instance; class Method; class RootObject; +class RuntimeObject; typedef Vector<Method*> MethodList; @@ -83,14 +84,15 @@ public: void end(); virtual Class* getClass() const = 0; - RuntimeObjectImp* createRuntimeObject(ExecState*); + RuntimeObject* createRuntimeObject(ExecState*); void willInvalidateRuntimeObject(); void willDestroyRuntimeObject(); // Returns false if the value was not set successfully. virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; } - virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args) = 0; + virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName) = 0; + virtual JSValue invokeMethod(ExecState*, RuntimeMethod* method, const ArgList& args) = 0; virtual bool supportsInvokeDefaultMethod() const { return false; } virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); } @@ -115,12 +117,12 @@ public: protected: virtual void virtualBegin() { } virtual void virtualEnd() { } - virtual RuntimeObjectImp* newRuntimeObject(ExecState*); + virtual RuntimeObject* newRuntimeObject(ExecState*); RefPtr<RootObject> m_rootObject; private: - RuntimeObjectImp* m_runtimeObject; + RuntimeObject* m_runtimeObject; }; class Array : public Noncopyable { diff --git a/WebCore/bridge/npapi.h b/WebCore/bridge/npapi.h index 351b414..f82d25e 100644 --- a/WebCore/bridge/npapi.h +++ b/WebCore/bridge/npapi.h @@ -50,7 +50,7 @@ #define JRIEnv void #endif -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__SYMBIAN32__) # ifndef XP_WIN # define XP_WIN 1 # endif /* XP_WIN */ 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; } diff --git a/WebCore/bridge/qt/qt_class.cpp b/WebCore/bridge/qt/qt_class.cpp index 09a1544..cfd74d9 100644 --- a/WebCore/bridge/qt/qt_class.cpp +++ b/WebCore/bridge/qt/qt_class.cpp @@ -127,7 +127,7 @@ Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) con QObject* obj = qtinst->getObject(); UString ustring = identifier.ustring(); - QString objName((const QChar*)ustring.rep()->data(), ustring.size()); + QString objName((const QChar*)ustring.rep()->characters(), ustring.size()); QByteArray ba = objName.toAscii(); // First check for a cached field @@ -139,6 +139,7 @@ Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) con // other types so we can delete them later if (f->fieldType() == QtField::MetaProperty) return f; +#ifndef QT_NO_PROPERTIES else if (f->fieldType() == QtField::DynamicProperty) { if (obj->dynamicPropertyNames().indexOf(ba) >= 0) return f; @@ -147,7 +148,9 @@ Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) con qtinst->m_fields.remove(objName); delete f; } - } else { + } +#endif + else { QList<QObject*> children = obj->children(); for (int index = 0; index < children.count(); ++index) { QObject *child = children.at(index); @@ -172,6 +175,7 @@ Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) con } } +#ifndef QT_NO_PROPERTIES // Dynamic properties index = obj->dynamicPropertyNames().indexOf(ba); if (index >= 0) { @@ -179,6 +183,7 @@ Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) con qtinst->m_fields.insert(objName, f); return f; } +#endif // Child objects @@ -202,12 +207,14 @@ Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) con if (qtinst->m_methods.contains(ba)) return 0; +#ifndef QT_NO_PROPERTIES // deleted qobject, but can't throw an error from here (no exec) // create a fake QtField that will throw upon access if (!f) { f = new QtField(ba); qtinst->m_fields.insert(objName, f); } +#endif return f; } } diff --git a/WebCore/bridge/qt/qt_instance.cpp b/WebCore/bridge/qt/qt_instance.cpp index fcfe1cd..4e39371 100644 --- a/WebCore/bridge/qt/qt_instance.cpp +++ b/WebCore/bridge/qt/qt_instance.cpp @@ -44,15 +44,15 @@ typedef QMultiHash<void*, QtInstance*> QObjectInstanceMap; static QObjectInstanceMap cachedInstances; // Derived RuntimeObject -class QtRuntimeObjectImp : public RuntimeObjectImp { +class QtRuntimeObject : public RuntimeObject { public: - QtRuntimeObjectImp(ExecState*, PassRefPtr<Instance>); + QtRuntimeObject(ExecState*, PassRefPtr<Instance>); static const ClassInfo s_info; virtual void markChildren(MarkStack& markStack) { - RuntimeObjectImp::markChildren(markStack); + RuntimeObject::markChildren(markStack); QtInstance* instance = static_cast<QtInstance*>(getInternalInstance()); if (instance) instance->markAggregate(markStack); @@ -64,16 +64,16 @@ public: } protected: - static const unsigned StructureFlags = RuntimeObjectImp::StructureFlags | OverridesMarkChildren; + static const unsigned StructureFlags = RuntimeObject::StructureFlags | OverridesMarkChildren; private: virtual const ClassInfo* classInfo() const { return &s_info; } }; -const ClassInfo QtRuntimeObjectImp::s_info = { "QtRuntimeObject", &RuntimeObjectImp::s_info, 0, 0 }; +const ClassInfo QtRuntimeObject::s_info = { "QtRuntimeObject", &RuntimeObject::s_info, 0, 0 }; -QtRuntimeObjectImp::QtRuntimeObjectImp(ExecState* exec, PassRefPtr<Instance> instance) - : RuntimeObjectImp(exec, WebCore::deprecatedGetDOMStructure<QtRuntimeObjectImp>(exec), instance) +QtRuntimeObject::QtRuntimeObject(ExecState* exec, PassRefPtr<Instance> instance) + : RuntimeObject(exec, WebCore::deprecatedGetDOMStructure<QtRuntimeObject>(exec), instance) { } @@ -164,22 +164,24 @@ QtInstance* QtInstance::getInstance(JSObject* object) { if (!object) return 0; - if (!object->inherits(&QtRuntimeObjectImp::s_info)) + if (!object->inherits(&QtRuntimeObject::s_info)) return 0; - return static_cast<QtInstance*>(static_cast<RuntimeObjectImp*>(object)->getInternalInstance()); + return static_cast<QtInstance*>(static_cast<RuntimeObject*>(object)->getInternalInstance()); } Class* QtInstance::getClass() const { + if (!m_object) + return 0; if (!m_class) m_class = QtClass::classForObject(m_object); return m_class; } -RuntimeObjectImp* QtInstance::newRuntimeObject(ExecState* exec) +RuntimeObject* QtInstance::newRuntimeObject(ExecState* exec) { JSLock lock(SilenceAssertionsOnly); - return new (exec) QtRuntimeObjectImp(exec, this); + return new (exec) QtRuntimeObject(exec, this); } void QtInstance::markAggregate(MarkStack& markStack) @@ -220,10 +222,12 @@ void QtInstance::getPropertyNames(ExecState* exec, PropertyNameArray& array) } } +#ifndef QT_NO_PROPERTIES QList<QByteArray> dynProps = obj->dynamicPropertyNames(); foreach(QByteArray ba, dynProps) { array.add(Identifier(exec, ba.constData())); } +#endif for (i=0; i < meta->methodCount(); i++) { QMetaMethod method = meta->method(i); @@ -234,13 +238,20 @@ void QtInstance::getPropertyNames(ExecState* exec, PropertyNameArray& array) } } -JSValue QtInstance::invokeMethod(ExecState*, const MethodList&, const ArgList&) +JSValue QtInstance::getMethod(ExecState* exec, const Identifier& propertyName) +{ + if (!getClass()) + return jsNull(); + MethodList methodList = m_class->methodsNamed(propertyName, this); + return new (exec) RuntimeMethod(exec, propertyName, methodList); +} + +JSValue QtInstance::invokeMethod(ExecState*, RuntimeMethod*, const ArgList&) { // Implemented via fallbackMethod & QtRuntimeMetaMethod::callAsFunction return jsUndefined(); } - JSValue QtInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const { if (hint == PreferString) @@ -252,12 +263,15 @@ JSValue QtInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) c JSValue QtInstance::stringValue(ExecState* exec) const { + QObject* obj = getObject(); + if (!obj) + return jsNull(); + // Hmm.. see if there is a toString defined QByteArray buf; bool useDefault = true; getClass(); - QObject* obj = getObject(); - if (m_class && obj) { + if (m_class) { // Cheat and don't use the full name resolution int index = obj->metaObject()->indexOfMethod("toString()"); if (index >= 0) { @@ -302,7 +316,7 @@ JSValue QtInstance::numberValue(ExecState* exec) const JSValue QtInstance::booleanValue() const { // ECMA 9.2 - return jsBoolean(true); + return jsBoolean(getObject()); } JSValue QtInstance::valueOf(ExecState* exec) const @@ -320,8 +334,10 @@ const char* QtField::name() const return m_property.name(); else if (m_type == ChildObject && m_childObject) return m_childObject->objectName().toLatin1(); +#ifndef QT_NO_PROPERTIES else if (m_type == DynamicProperty) return m_dynamicProperty.constData(); +#endif return ""; // deleted child object } @@ -339,9 +355,10 @@ JSValue QtField::valueFromInstance(ExecState* exec, const Instance* inst) const return jsUndefined(); } else if (m_type == ChildObject) val = QVariant::fromValue((QObject*) m_childObject); +#ifndef QT_NO_PROPERTIES else if (m_type == DynamicProperty) val = obj->property(m_dynamicProperty); - +#endif return convertQVariantToValue(exec, inst->rootObject(), val); } else { QString msg = QString(QLatin1String("cannot access member `%1' of deleted QObject")).arg(QLatin1String(name())); @@ -366,8 +383,11 @@ void QtField::setValueToInstance(ExecState* exec, const Instance* inst, JSValue if (m_type == MetaProperty) { if (m_property.isWritable()) m_property.write(obj, val); - } else if (m_type == DynamicProperty) + } +#ifndef QT_NO_PROPERTIES + else if (m_type == DynamicProperty) obj->setProperty(m_dynamicProperty.constData(), val); +#endif } else { QString msg = QString(QLatin1String("cannot access member `%1' of deleted QObject")).arg(QLatin1String(name())); throwError(exec, GeneralError, msg.toLatin1().constData()); diff --git a/WebCore/bridge/qt/qt_instance.h b/WebCore/bridge/qt/qt_instance.h index 1fc253a..607f133 100644 --- a/WebCore/bridge/qt/qt_instance.h +++ b/WebCore/bridge/qt/qt_instance.h @@ -40,7 +40,7 @@ public: ~QtInstance(); virtual Class* getClass() const; - virtual RuntimeObjectImp* newRuntimeObject(ExecState*); + virtual RuntimeObject* newRuntimeObject(ExecState*); virtual void begin(); virtual void end(); @@ -50,7 +50,8 @@ public: void markAggregate(MarkStack&); - virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList&); + virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName); + virtual JSValue invokeMethod(ExecState*, RuntimeMethod*, const ArgList&); virtual void getPropertyNames(ExecState*, PropertyNameArray&); diff --git a/WebCore/bridge/qt/qt_pixmapruntime.cpp b/WebCore/bridge/qt/qt_pixmapruntime.cpp index 5978804..803316d 100644 --- a/WebCore/bridge/qt/qt_pixmapruntime.cpp +++ b/WebCore/bridge/qt/qt_pixmapruntime.cpp @@ -33,6 +33,7 @@ #include <QVariant> #include <runtime_object.h> #include <runtime_root.h> +#include <runtime_method.h> using namespace WebCore; namespace JSC { @@ -142,9 +143,9 @@ struct QtPixmapMetaData { } qt_pixmap_metaData; // Derived RuntimeObject -class QtPixmapRuntimeObjectImp : public RuntimeObjectImp { +class QtPixmapRuntimeObject : public RuntimeObject { public: - QtPixmapRuntimeObjectImp(ExecState*, PassRefPtr<Instance>); + QtPixmapRuntimeObject(ExecState*, PassRefPtr<Instance>); static const ClassInfo s_info; @@ -154,18 +155,18 @@ public: } protected: - static const unsigned StructureFlags = RuntimeObjectImp::StructureFlags | OverridesMarkChildren; + static const unsigned StructureFlags = RuntimeObject::StructureFlags | OverridesMarkChildren; private: virtual const ClassInfo* classInfo() const { return &s_info; } }; -QtPixmapRuntimeObjectImp::QtPixmapRuntimeObjectImp(ExecState* exec, PassRefPtr<Instance> instance) - : RuntimeObjectImp(exec, WebCore::deprecatedGetDOMStructure<QtPixmapRuntimeObjectImp>(exec), instance) +QtPixmapRuntimeObject::QtPixmapRuntimeObject(ExecState* exec, PassRefPtr<Instance> instance) + : RuntimeObject(exec, WebCore::deprecatedGetDOMStructure<QtPixmapRuntimeObject>(exec), instance) { } -const ClassInfo QtPixmapRuntimeObjectImp::s_info = { "QtPixmapRuntimeObject", &RuntimeObjectImp::s_info, 0, 0 }; +const ClassInfo QtPixmapRuntimeObject::s_info = { "QtPixmapRuntimeObject", &RuntimeObject::s_info, 0, 0 }; QtPixmapClass::QtPixmapClass() { @@ -177,8 +178,16 @@ Class* QtPixmapInstance::getClass() const return &qt_pixmap_metaData.cls; } -JSValue QtPixmapInstance::invokeMethod(ExecState* exec, const MethodList& methods, const ArgList& args) +JSValue QtPixmapInstance::getMethod(ExecState* exec, const Identifier& propertyName) { + MethodList methodList = getClass()->methodsNamed(propertyName, this); + return new (exec) RuntimeMethod(exec, propertyName, methodList); +} + +JSValue QtPixmapInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod, const ArgList& args) +{ + const MethodList& methods = *runtimeMethod->methods(); + if (methods.size() == 1) { QtPixmapRuntimeMethod* method = static_cast<QtPixmapRuntimeMethod*>(methods[0]); return method->invoke(exec, this, args); @@ -317,9 +326,9 @@ QVariant QtPixmapInstance::variantFromObject(JSObject* object, QMetaType::Type h : QVariant::fromValue<QImage>(pixmap->toImage()); } - if (object->inherits(&QtPixmapRuntimeObjectImp::s_info)) { - QtPixmapRuntimeObjectImp* imp = static_cast<QtPixmapRuntimeObjectImp*>(object); - QtPixmapInstance* instance = static_cast<QtPixmapInstance*>(imp->getInternalInstance()); + if (object->inherits(&QtPixmapRuntimeObject::s_info)) { + QtPixmapRuntimeObject* runtimeObject = static_cast<QtPixmapRuntimeObject*>(object); + QtPixmapInstance* instance = static_cast<QtPixmapInstance*>(runtimeObject->getInternalInstance()); if (!instance) goto returnEmptyVariant; @@ -340,7 +349,7 @@ returnEmptyVariant: JSObject* QtPixmapInstance::createRuntimeObject(ExecState* exec, PassRefPtr<RootObject> root, const QVariant& data) { JSLock lock(SilenceAssertionsOnly); - return new(exec) QtPixmapRuntimeObjectImp(exec, new QtPixmapInstance(root, data)); + return new(exec) QtPixmapRuntimeObject(exec, new QtPixmapInstance(root, data)); } bool QtPixmapInstance::canHandle(QMetaType::Type hint) diff --git a/WebCore/bridge/qt/qt_pixmapruntime.h b/WebCore/bridge/qt/qt_pixmapruntime.h index 5455298..a0e0e26 100644 --- a/WebCore/bridge/qt/qt_pixmapruntime.h +++ b/WebCore/bridge/qt/qt_pixmapruntime.h @@ -32,7 +32,8 @@ class QtPixmapInstance : public Instance { public: QtPixmapInstance(PassRefPtr<RootObject> rootObj, const QVariant& newData); virtual Class* getClass() const; - virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args); + virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName); + virtual JSValue invokeMethod(ExecState*, RuntimeMethod*, const ArgList& args); virtual void getPropertyNames(ExecState*, PropertyNameArray&); virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; diff --git a/WebCore/bridge/qt/qt_runtime.cpp b/WebCore/bridge/qt/qt_runtime.cpp index ada9f01..40ff6a1 100644 --- a/WebCore/bridge/qt/qt_runtime.cpp +++ b/WebCore/bridge/qt/qt_runtime.cpp @@ -154,7 +154,7 @@ static JSRealType valueRealType(ExecState* exec, JSValue val) return Date; else if (object->inherits(&RegExpObject::info)) return RegExp; - else if (object->inherits(&RuntimeObjectImp::s_info)) + else if (object->inherits(&RuntimeObject::s_info)) return QObj; return Object; } @@ -308,7 +308,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type dist = 6; } else { UString str = value.toString(exec); - ret = QVariant(QChar(str.size() ? *(const ushort*)str.rep()->data() : 0)); + ret = QVariant(QChar(str.size() ? *(const ushort*)str.rep()->characters() : 0)); if (type == String) dist = 3; else @@ -323,7 +323,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type return QString(); } else { UString ustring = value.toString(exec); - ret = QVariant(QString((const QChar*)ustring.rep()->data(), ustring.size())); + ret = QVariant(QString((const QChar*)ustring.rep()->characters(), ustring.size())); if (type == String) dist = 0; else @@ -332,7 +332,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type break; } - case QMetaType::QVariantMap: + case QMetaType::QVariantMap: if (type == Object || type == Array || type == RTArray) { // Enumerate the contents of the object PropertyNameArray properties(exec); @@ -347,7 +347,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type QVariant v = convertValueToQVariant(exec, val, QMetaType::Void, &objdist, visitedObjects); if (objdist >= 0) { UString ustring = (*it).ustring(); - QString id = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString id = QString((const QChar*)ustring.rep()->characters(), ustring.size()); result.insert(id, v); } } @@ -422,7 +422,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type for (int i = 0; i < len; ++i) { JSValue val = rtarray->getConcreteArray()->valueAt(exec, i); UString ustring = val.toString(exec); - QString qstring = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString qstring = QString((const QChar*)ustring.rep()->characters(), ustring.size()); result.append(qstring); } @@ -436,7 +436,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type for (int i = 0; i < len; ++i) { JSValue val = array->get(exec, i); UString ustring = val.toString(exec); - QString qstring = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString qstring = QString((const QChar*)ustring.rep()->characters(), ustring.size()); result.append(qstring); } @@ -445,7 +445,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type } else { // Make a single length array UString ustring = value.toString(exec); - QString qstring = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString qstring = QString((const QChar*)ustring.rep()->characters(), ustring.size()); QStringList result; result.append(qstring); ret = QVariant(result); @@ -461,7 +461,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type dist = 0; } else { UString ustring = value.toString(exec); - ret = QVariant(QString((const QChar*)ustring.rep()->data(), ustring.size()).toLatin1()); + ret = QVariant(QString((const QChar*)ustring.rep()->characters(), ustring.size()).toLatin1()); if (type == String) dist = 5; else @@ -503,7 +503,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type } } else if (type == String) { UString ustring = value.toString(exec); - QString qstring = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString qstring = QString((const QChar*)ustring.rep()->characters(), ustring.size()); if (hint == QMetaType::QDateTime) { QDateTime dt = QDateTime::fromString(qstring, Qt::ISODate); @@ -552,7 +552,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type */ // Attempt to convert.. a bit risky UString ustring = value.toString(exec); - QString qstring = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString qstring = QString((const QChar*)ustring.rep()->characters(), ustring.size()); // this is of the form '/xxxxxx/i' int firstSlash = qstring.indexOf(QLatin1Char('/')); @@ -572,7 +572,7 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type } } else if (type == String) { UString ustring = value.toString(exec); - QString qstring = QString((const QChar*)ustring.rep()->data(), ustring.size()); + QString qstring = QString((const QChar*)ustring.rep()->characters(), ustring.size()); QRegExp re(qstring); if (re.isValid()) { @@ -871,6 +871,8 @@ JSValue convertQVariantToValue(ExecState* exec, PassRefPtr<RootObject> root, con if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) { QObject* obj = variant.value<QObject*>(); + if (!obj) + return jsNull(); return QtInstance::getQtInstance(obj, root, QScriptEngine::QtOwnership)->createRuntimeObject(exec); } @@ -1471,15 +1473,15 @@ void QtRuntimeMetaMethod::getOwnPropertyNames(ExecState* exec, PropertyNameArray QtRuntimeMethod::getOwnPropertyNames(exec, propertyNames, mode); } -JSValue QtRuntimeMetaMethod::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot&) +JSValue QtRuntimeMetaMethod::lengthGetter(ExecState* exec, JSValue, const Identifier&) { // QtScript always returns 0 return jsNumber(exec, 0); } -JSValue QtRuntimeMetaMethod::connectGetter(ExecState* exec, const Identifier& ident, const PropertySlot& slot) +JSValue QtRuntimeMetaMethod::connectGetter(ExecState* exec, JSValue slotBase, const Identifier& ident) { - QtRuntimeMetaMethod* thisObj = static_cast<QtRuntimeMetaMethod*>(asObject(slot.slotBase())); + QtRuntimeMetaMethod* thisObj = static_cast<QtRuntimeMetaMethod*>(asObject(slotBase)); QW_DS(QtRuntimeMetaMethod, thisObj); if (!d->m_connect) @@ -1487,9 +1489,9 @@ JSValue QtRuntimeMetaMethod::connectGetter(ExecState* exec, const Identifier& id return d->m_connect; } -JSValue QtRuntimeMetaMethod::disconnectGetter(ExecState* exec, const Identifier& ident, const PropertySlot& slot) +JSValue QtRuntimeMetaMethod::disconnectGetter(ExecState* exec, JSValue slotBase, const Identifier& ident) { - QtRuntimeMetaMethod* thisObj = static_cast<QtRuntimeMetaMethod*>(asObject(slot.slotBase())); + QtRuntimeMetaMethod* thisObj = static_cast<QtRuntimeMetaMethod*>(asObject(slotBase)); QW_DS(QtRuntimeMetaMethod, thisObj); if (!d->m_disconnect) @@ -1677,7 +1679,7 @@ void QtRuntimeConnectionMethod::getOwnPropertyNames(ExecState* exec, PropertyNam QtRuntimeMethod::getOwnPropertyNames(exec, propertyNames, mode); } -JSValue QtRuntimeConnectionMethod::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot&) +JSValue QtRuntimeConnectionMethod::lengthGetter(ExecState* exec, JSValue, const Identifier&) { // we have one formal argument, and one optional return jsNumber(exec, 1); diff --git a/WebCore/bridge/qt/qt_runtime.h b/WebCore/bridge/qt/qt_runtime.h index c3fa8b4..0951e5b 100644 --- a/WebCore/bridge/qt/qt_runtime.h +++ b/WebCore/bridge/qt/qt_runtime.h @@ -40,7 +40,9 @@ public: typedef enum { MetaProperty, +#ifndef QT_NO_PROPERTIES DynamicProperty, +#endif ChildObject } QtFieldType; @@ -48,9 +50,11 @@ public: : m_type(MetaProperty), m_property(p) {} +#ifndef QT_NO_PROPERTIES QtField(const QByteArray &b) : m_type(DynamicProperty), m_dynamicProperty(b) {} +#endif QtField(QObject *child) : m_type(ChildObject), m_childObject(child) @@ -179,9 +183,9 @@ protected: private: virtual CallType getCallData(CallData&); static JSValue JSC_HOST_CALL call(ExecState* exec, JSObject* functionObject, JSValue thisValue, const ArgList& args); - static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&); - static JSValue connectGetter(ExecState*, const Identifier&, const PropertySlot&); - static JSValue disconnectGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue lengthGetter(ExecState*, JSValue, const Identifier&); + static JSValue connectGetter(ExecState*, JSValue, const Identifier&); + static JSValue disconnectGetter(ExecState*, JSValue, const Identifier&); }; class QtConnectionObject; @@ -200,7 +204,7 @@ protected: private: virtual CallType getCallData(CallData&); static JSValue JSC_HOST_CALL call(ExecState* exec, JSObject* functionObject, JSValue thisValue, const ArgList& args); - static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue lengthGetter(ExecState*, JSValue, const Identifier&); static QMultiMap<QObject *, QtConnectionObject *> connections; friend class QtConnectionObject; }; diff --git a/WebCore/bridge/runtime_array.cpp b/WebCore/bridge/runtime_array.cpp index 9e8da85..1f2bfe7 100644 --- a/WebCore/bridge/runtime_array.cpp +++ b/WebCore/bridge/runtime_array.cpp @@ -40,21 +40,26 @@ const ClassInfo RuntimeArray::s_info = { "RuntimeArray", &JSArray::info, 0, 0 }; RuntimeArray::RuntimeArray(ExecState* exec, Bindings::Array* array) // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object // We need to pass in the right global object for "array". - : JSObject(deprecatedGetDOMStructure<RuntimeArray>(exec)) - , _array(array) + : JSArray(deprecatedGetDOMStructure<RuntimeArray>(exec)) { + setSubclassData(array); } -JSValue RuntimeArray::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +RuntimeArray::~RuntimeArray() { - RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slot.slotBase())); + delete getConcreteArray(); +} + +JSValue RuntimeArray::lengthGetter(ExecState* exec, JSValue slotBase, const Identifier&) +{ + RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slotBase)); return jsNumber(exec, thisObj->getLength()); } -JSValue RuntimeArray::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +JSValue RuntimeArray::indexGetter(ExecState* exec, JSValue slotBase, unsigned index) { - RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slot.slotBase())); - return thisObj->getConcreteArray()->valueAt(exec, slot.index()); + RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slotBase)); + return thisObj->getConcreteArray()->valueAt(exec, index); } void RuntimeArray::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) @@ -72,7 +77,7 @@ void RuntimeArray::getOwnPropertyNames(ExecState* exec, PropertyNameArray& prope bool RuntimeArray::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) { if (propertyName == exec->propertyNames().length) { - slot.setCustom(this, lengthGetter); + slot.setCacheableCustom(this, lengthGetter); return true; } diff --git a/WebCore/bridge/runtime_array.h b/WebCore/bridge/runtime_array.h index 6c6cacd..e301268 100644 --- a/WebCore/bridge/runtime_array.h +++ b/WebCore/bridge/runtime_array.h @@ -27,29 +27,30 @@ #define RUNTIME_ARRAY_H_ #include "Bridge.h" -#include <runtime/JSGlobalObject.h> +#include <runtime/ArrayPrototype.h> namespace JSC { -class RuntimeArray : public JSObject { +class RuntimeArray : public JSArray { public: RuntimeArray(ExecState*, Bindings::Array*); + virtual ~RuntimeArray(); virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties); - virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); - virtual bool getOwnPropertySlot(ExecState *, unsigned, PropertySlot&); - virtual bool getOwnPropertyDescriptor(ExecState *, const Identifier&, PropertyDescriptor&); + virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); + virtual bool getOwnPropertySlot(ExecState*, unsigned, PropertySlot&); + virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&); virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&); virtual void put(ExecState*, unsigned propertyName, JSValue); - virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); - virtual bool deleteProperty(ExecState *exec, unsigned propertyName); + virtual bool deleteProperty(ExecState* exec, const Identifier &propertyName); + virtual bool deleteProperty(ExecState* exec, unsigned propertyName); - virtual const ClassInfo *classInfo() const { return &s_info; } + virtual const ClassInfo* classInfo() const { return &s_info; } unsigned getLength() const { return getConcreteArray()->getLength(); } - Bindings::Array *getConcreteArray() const { return _array.get(); } + Bindings::Array* getConcreteArray() const { return static_cast<Bindings::Array*>(subclassData()); } static const ClassInfo s_info; @@ -58,17 +59,10 @@ public: return globalObject->arrayPrototype(); } - static PassRefPtr<Structure> createStructure(JSValue prototype) - { - return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount); - } - private: static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags; - static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&); - static JSValue indexGetter(ExecState*, const Identifier&, const PropertySlot&); - - OwnPtr<Bindings::Array> _array; + static JSValue lengthGetter(ExecState*, JSValue, const Identifier&); + static JSValue indexGetter(ExecState*, JSValue, unsigned); }; } // namespace JSC diff --git a/WebCore/bridge/runtime_method.cpp b/WebCore/bridge/runtime_method.cpp index ffe4c0a..29145b6 100644 --- a/WebCore/bridge/runtime_method.cpp +++ b/WebCore/bridge/runtime_method.cpp @@ -27,6 +27,8 @@ #include "runtime_method.h" #include "JSDOMBinding.h" +#include "JSHTMLElement.h" +#include "JSPluginElementFunctions.h" #include "runtime_object.h" #include <runtime/Error.h> #include <runtime/FunctionPrototype.h> @@ -39,7 +41,7 @@ using namespace Bindings; ASSERT_CLASS_FITS_IN_CELL(RuntimeMethod); -const ClassInfo RuntimeMethod::s_info = { "RuntimeMethod", 0, 0, 0 }; +const ClassInfo RuntimeMethod::s_info = { "RuntimeMethod", &InternalFunction::info, 0, 0 }; RuntimeMethod::RuntimeMethod(ExecState* exec, const Identifier& ident, Bindings::MethodList& m) // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object @@ -50,9 +52,9 @@ RuntimeMethod::RuntimeMethod(ExecState* exec, const Identifier& ident, Bindings: { } -JSValue RuntimeMethod::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +JSValue RuntimeMethod::lengthGetter(ExecState* exec, JSValue slotBase, const Identifier&) { - RuntimeMethod* thisObj = static_cast<RuntimeMethod*>(asObject(slot.slotBase())); + RuntimeMethod* thisObj = static_cast<RuntimeMethod*>(asObject(slotBase)); // Ick! There may be more than one method with this name. Arbitrarily // just pick the first method. The fundamental problem here is that @@ -66,7 +68,7 @@ JSValue RuntimeMethod::lengthGetter(ExecState* exec, const Identifier&, const Pr bool RuntimeMethod::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot) { if (propertyName == exec->propertyNames().length) { - slot.setCustom(this, lengthGetter); + slot.setCacheableCustom(this, lengthGetter); return true; } @@ -91,27 +93,27 @@ static JSValue JSC_HOST_CALL callRuntimeMethod(ExecState* exec, JSObject* functi if (method->methods()->isEmpty()) return jsUndefined(); - - RuntimeObjectImp* imp; - if (thisValue.inherits(&RuntimeObjectImp::s_info)) { - imp = static_cast<RuntimeObjectImp*>(asObject(thisValue)); + RefPtr<Instance> instance; + + if (thisValue.inherits(&RuntimeObject::s_info)) { + RuntimeObject* runtimeObject = static_cast<RuntimeObject*>(asObject(thisValue)); + instance = runtimeObject->getInternalInstance(); + if (!instance) + return RuntimeObject::throwInvalidAccessError(exec); } else { - // If thisObj is the DOM object for a plugin, get the corresponding - // runtime object from the DOM object. - JSValue value = thisValue.get(exec, Identifier(exec, "__apple_runtime_object")); - if (value.inherits(&RuntimeObjectImp::s_info)) - imp = static_cast<RuntimeObjectImp*>(asObject(value)); - else + // Calling a runtime object of a plugin element? + if (thisValue.inherits(&JSHTMLElement::s_info)) { + HTMLElement* element = static_cast<JSHTMLElement*>(asObject(thisValue))->impl(); + instance = pluginInstance(element); + } + if (!instance) return throwError(exec, TypeError); } + ASSERT(instance); - RefPtr<Instance> instance = imp->getInternalInstance(); - if (!instance) - return RuntimeObjectImp::throwInvalidAccessError(exec); - instance->begin(); - JSValue result = instance->invokeMethod(exec, *method->methods(), args); + JSValue result = instance->invokeMethod(exec, method, args); instance->end(); return result; } diff --git a/WebCore/bridge/runtime_method.h b/WebCore/bridge/runtime_method.h index 914ab00..9c80ba1 100644 --- a/WebCore/bridge/runtime_method.h +++ b/WebCore/bridge/runtime_method.h @@ -50,9 +50,11 @@ public: return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount); } + virtual const ClassInfo* classInfo() const { return &s_info; } + private: static const unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesMarkChildren | InternalFunction::StructureFlags; - static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue lengthGetter(ExecState*, JSValue, const Identifier&); virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&); virtual CallType getCallData(CallData&); diff --git a/WebCore/bridge/runtime_object.cpp b/WebCore/bridge/runtime_object.cpp index 26b85f9..83aae74 100644 --- a/WebCore/bridge/runtime_object.cpp +++ b/WebCore/bridge/runtime_object.cpp @@ -34,32 +34,31 @@ using namespace WebCore; namespace JSC { +namespace Bindings { -using namespace Bindings; +const ClassInfo RuntimeObject::s_info = { "RuntimeObject", 0, 0, 0 }; -const ClassInfo RuntimeObjectImp::s_info = { "RuntimeObject", 0, 0, 0 }; - -RuntimeObjectImp::RuntimeObjectImp(ExecState* exec, PassRefPtr<Instance> instance) +RuntimeObject::RuntimeObject(ExecState* exec, PassRefPtr<Instance> instance) // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object // We need to pass in the right global object for "i". - : JSObject(deprecatedGetDOMStructure<RuntimeObjectImp>(exec)) + : JSObject(deprecatedGetDOMStructure<RuntimeObject>(exec)) , m_instance(instance) { } -RuntimeObjectImp::RuntimeObjectImp(ExecState*, NonNullPassRefPtr<Structure> structure, PassRefPtr<Instance> instance) +RuntimeObject::RuntimeObject(ExecState*, NonNullPassRefPtr<Structure> structure, PassRefPtr<Instance> instance) : JSObject(structure) , m_instance(instance) { } -RuntimeObjectImp::~RuntimeObjectImp() +RuntimeObject::~RuntimeObject() { if (m_instance) m_instance->willDestroyRuntimeObject(); } -void RuntimeObjectImp::invalidate() +void RuntimeObject::invalidate() { ASSERT(m_instance); if (m_instance) @@ -67,9 +66,9 @@ void RuntimeObjectImp::invalidate() m_instance = 0; } -JSValue RuntimeObjectImp::fallbackObjectGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +JSValue RuntimeObject::fallbackObjectGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) { - RuntimeObjectImp* thisObj = static_cast<RuntimeObjectImp*>(asObject(slot.slotBase())); + RuntimeObject* thisObj = static_cast<RuntimeObject*>(asObject(slotBase)); RefPtr<Instance> instance = thisObj->m_instance; if (!instance) @@ -85,9 +84,9 @@ JSValue RuntimeObjectImp::fallbackObjectGetter(ExecState* exec, const Identifier return result; } -JSValue RuntimeObjectImp::fieldGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +JSValue RuntimeObject::fieldGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) { - RuntimeObjectImp* thisObj = static_cast<RuntimeObjectImp*>(asObject(slot.slotBase())); + RuntimeObject* thisObj = static_cast<RuntimeObject*>(asObject(slotBase)); RefPtr<Instance> instance = thisObj->m_instance; if (!instance) @@ -104,9 +103,9 @@ JSValue RuntimeObjectImp::fieldGetter(ExecState* exec, const Identifier& propert return result; } -JSValue RuntimeObjectImp::methodGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +JSValue RuntimeObject::methodGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) { - RuntimeObjectImp* thisObj = static_cast<RuntimeObjectImp*>(asObject(slot.slotBase())); + RuntimeObject* thisObj = static_cast<RuntimeObject*>(asObject(slotBase)); RefPtr<Instance> instance = thisObj->m_instance; if (!instance) @@ -114,16 +113,14 @@ JSValue RuntimeObjectImp::methodGetter(ExecState* exec, const Identifier& proper instance->begin(); - Class *aClass = instance->getClass(); - MethodList methodList = aClass->methodsNamed(propertyName, instance.get()); - JSValue result = new (exec) RuntimeMethod(exec, propertyName, methodList); + JSValue method = instance->getMethod(exec, propertyName); instance->end(); - return result; + return method; } -bool RuntimeObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) +bool RuntimeObject::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) { if (!m_instance) { throwInvalidAccessError(exec); @@ -168,7 +165,7 @@ bool RuntimeObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& pro return instance->getOwnPropertySlot(this, exec, propertyName, slot); } -bool RuntimeObjectImp::getOwnPropertyDescriptor(ExecState *exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +bool RuntimeObject::getOwnPropertyDescriptor(ExecState *exec, const Identifier& propertyName, PropertyDescriptor& descriptor) { if (!m_instance) { throwInvalidAccessError(exec); @@ -217,7 +214,7 @@ bool RuntimeObjectImp::getOwnPropertyDescriptor(ExecState *exec, const Identifie return instance->getOwnPropertyDescriptor(this, exec, propertyName, descriptor); } -void RuntimeObjectImp::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +void RuntimeObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) { if (!m_instance) { throwInvalidAccessError(exec); @@ -237,13 +234,13 @@ void RuntimeObjectImp::put(ExecState* exec, const Identifier& propertyName, JSVa instance->end(); } -bool RuntimeObjectImp::deleteProperty(ExecState*, const Identifier&) +bool RuntimeObject::deleteProperty(ExecState*, const Identifier&) { // Can never remove a property of a RuntimeObject. return false; } -JSValue RuntimeObjectImp::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const +JSValue RuntimeObject::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const { if (!m_instance) return throwInvalidAccessError(exec); @@ -258,14 +255,15 @@ JSValue RuntimeObjectImp::defaultValue(ExecState* exec, PreferredPrimitiveType h static JSValue JSC_HOST_CALL callRuntimeObject(ExecState* exec, JSObject* function, JSValue, const ArgList& args) { - RefPtr<Instance> instance(static_cast<RuntimeObjectImp*>(function)->getInternalInstance()); + ASSERT(function->inherits(&RuntimeObject::s_info)); + RefPtr<Instance> instance(static_cast<RuntimeObject*>(function)->getInternalInstance()); instance->begin(); JSValue result = instance->invokeDefaultMethod(exec, args); instance->end(); return result; } -CallType RuntimeObjectImp::getCallData(CallData& callData) +CallType RuntimeObject::getCallData(CallData& callData) { if (!m_instance) return CallTypeNone; @@ -280,7 +278,8 @@ CallType RuntimeObjectImp::getCallData(CallData& callData) static JSObject* callRuntimeConstructor(ExecState* exec, JSObject* constructor, const ArgList& args) { - RefPtr<Instance> instance(static_cast<RuntimeObjectImp*>(constructor)->getInternalInstance()); + ASSERT(constructor->inherits(&RuntimeObject::s_info)); + RefPtr<Instance> instance(static_cast<RuntimeObject*>(constructor)->getInternalInstance()); instance->begin(); JSValue result = instance->invokeConstruct(exec, args); instance->end(); @@ -289,7 +288,7 @@ static JSObject* callRuntimeConstructor(ExecState* exec, JSObject* constructor, return result.isObject() ? static_cast<JSObject*>(result.asCell()) : constructor; } -ConstructType RuntimeObjectImp::getConstructData(ConstructData& constructData) +ConstructType RuntimeObject::getConstructData(ConstructData& constructData) { if (!m_instance) return ConstructTypeNone; @@ -302,7 +301,7 @@ ConstructType RuntimeObjectImp::getConstructData(ConstructData& constructData) return ConstructTypeHost; } -void RuntimeObjectImp::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode) +void RuntimeObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode) { if (!m_instance) { throwInvalidAccessError(exec); @@ -316,9 +315,10 @@ void RuntimeObjectImp::getOwnPropertyNames(ExecState* exec, PropertyNameArray& p instance->end(); } -JSObject* RuntimeObjectImp::throwInvalidAccessError(ExecState* exec) +JSObject* RuntimeObject::throwInvalidAccessError(ExecState* exec) { return throwError(exec, ReferenceError, "Trying to access object from destroyed plug-in."); } } +} diff --git a/WebCore/bridge/runtime_object.h b/WebCore/bridge/runtime_object.h index ef5a2f7..b735e36 100644 --- a/WebCore/bridge/runtime_object.h +++ b/WebCore/bridge/runtime_object.h @@ -30,11 +30,12 @@ #include <runtime/JSGlobalObject.h> namespace JSC { +namespace Bindings { -class RuntimeObjectImp : public JSObject { +class RuntimeObject : public JSObject { public: - RuntimeObjectImp(ExecState*, PassRefPtr<Bindings::Instance>); - virtual ~RuntimeObjectImp(); + RuntimeObject(ExecState*, PassRefPtr<Instance>); + virtual ~RuntimeObject(); virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier& propertyName, PropertyDescriptor&); @@ -48,7 +49,7 @@ public: void invalidate(); - Bindings::Instance* getInternalInstance() const { return m_instance.get(); } + Instance* getInternalInstance() const { return m_instance.get(); } static JSObject* throwInvalidAccessError(ExecState*); @@ -66,18 +67,19 @@ public: protected: static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags; - RuntimeObjectImp(ExecState*, NonNullPassRefPtr<Structure>, PassRefPtr<Bindings::Instance>); + RuntimeObject(ExecState*, NonNullPassRefPtr<Structure>, PassRefPtr<Instance>); private: virtual const ClassInfo* classInfo() const { return &s_info; } - static JSValue fallbackObjectGetter(ExecState*, const Identifier&, const PropertySlot&); - static JSValue fieldGetter(ExecState*, const Identifier&, const PropertySlot&); - static JSValue methodGetter(ExecState*, const Identifier&, const PropertySlot&); + static JSValue fallbackObjectGetter(ExecState*, JSValue, const Identifier&); + static JSValue fieldGetter(ExecState*, JSValue, const Identifier&); + static JSValue methodGetter(ExecState*, JSValue, const Identifier&); - RefPtr<Bindings::Instance> m_instance; + RefPtr<Instance> m_instance; }; -} // namespace +} +} #endif diff --git a/WebCore/bridge/runtime_root.cpp b/WebCore/bridge/runtime_root.cpp index b179d56..09fd43b 100644 --- a/WebCore/bridge/runtime_root.cpp +++ b/WebCore/bridge/runtime_root.cpp @@ -101,8 +101,8 @@ void RootObject::invalidate() return; { - HashSet<RuntimeObjectImp*>::iterator end = m_runtimeObjects.end(); - for (HashSet<RuntimeObjectImp*>::iterator it = m_runtimeObjects.begin(); it != end; ++it) + HashSet<RuntimeObject*>::iterator end = m_runtimeObjects.end(); + for (HashSet<RuntimeObject*>::iterator it = m_runtimeObjects.begin(); it != end; ++it) (*it)->invalidate(); m_runtimeObjects.clear(); @@ -168,7 +168,7 @@ JSGlobalObject* RootObject::globalObject() const return m_globalObject; } -void RootObject::addRuntimeObject(RuntimeObjectImp* object) +void RootObject::addRuntimeObject(RuntimeObject* object) { ASSERT(m_isValid); ASSERT(!m_runtimeObjects.contains(object)); @@ -176,7 +176,7 @@ void RootObject::addRuntimeObject(RuntimeObjectImp* object) m_runtimeObjects.add(object); } -void RootObject::removeRuntimeObject(RuntimeObjectImp* object) +void RootObject::removeRuntimeObject(RuntimeObject* object) { ASSERT(m_isValid); ASSERT(m_runtimeObjects.contains(object)); diff --git a/WebCore/bridge/runtime_root.h b/WebCore/bridge/runtime_root.h index a81afb8..04f382a 100644 --- a/WebCore/bridge/runtime_root.h +++ b/WebCore/bridge/runtime_root.h @@ -41,11 +41,11 @@ namespace JSC { class Interpreter; class JSGlobalObject; -class RuntimeObjectImp; namespace Bindings { class RootObject; +class RuntimeObject; typedef HashCountedSet<JSObject*> ProtectCountSet; @@ -70,8 +70,8 @@ public: const void* nativeHandle() const; JSGlobalObject* globalObject() const; - void addRuntimeObject(RuntimeObjectImp*); - void removeRuntimeObject(RuntimeObjectImp*); + void addRuntimeObject(RuntimeObject*); + void removeRuntimeObject(RuntimeObject*); struct InvalidationCallback { virtual void operator()(RootObject*) = 0; @@ -88,7 +88,7 @@ private: ProtectedPtr<JSGlobalObject> m_globalObject; ProtectCountSet m_protectCountSet; - HashSet<RuntimeObjectImp*> m_runtimeObjects; + HashSet<RuntimeObject*> m_runtimeObjects; HashSet<InvalidationCallback*> m_invalidationCallbacks; }; |