diff options
Diffstat (limited to 'JavaScriptCore/bindings')
-rw-r--r-- | JavaScriptCore/bindings/NP_jsobject.cpp | 10 | ||||
-rw-r--r-- | JavaScriptCore/bindings/c/c_instance.cpp | 4 | ||||
-rw-r--r-- | JavaScriptCore/bindings/c/c_runtime.cpp | 37 | ||||
-rw-r--r-- | JavaScriptCore/bindings/c/c_runtime.h | 3 | ||||
-rw-r--r-- | JavaScriptCore/bindings/jni/jni_android.cpp | 35 | ||||
-rw-r--r--[-rwxr-xr-x] | JavaScriptCore/bindings/make_testbindings | 0 | ||||
-rw-r--r-- | JavaScriptCore/bindings/npapi.h | 11 | ||||
-rw-r--r-- | JavaScriptCore/bindings/objc/objc_runtime.h | 3 | ||||
-rw-r--r-- | JavaScriptCore/bindings/objc/objc_runtime.mm | 8 | ||||
-rw-r--r-- | JavaScriptCore/bindings/runtime_array.cpp | 6 | ||||
-rw-r--r-- | JavaScriptCore/bindings/runtime_array.h | 4 | ||||
-rw-r--r-- | JavaScriptCore/bindings/runtime_object.cpp | 18 | ||||
-rw-r--r-- | JavaScriptCore/bindings/runtime_object.h | 3 | ||||
-rw-r--r-- | JavaScriptCore/bindings/runtime_root.cpp | 2 |
14 files changed, 126 insertions, 18 deletions
diff --git a/JavaScriptCore/bindings/NP_jsobject.cpp b/JavaScriptCore/bindings/NP_jsobject.cpp index 059b5df..b0a5a65 100644 --- a/JavaScriptCore/bindings/NP_jsobject.cpp +++ b/JavaScriptCore/bindings/NP_jsobject.cpp @@ -31,6 +31,7 @@ #include "JSGlobalObject.h" #include "PropertyNameArray.h" +#include "c_runtime.h" #include "c_utility.h" #include "interpreter.h" #include "npruntime_impl.h" @@ -359,14 +360,7 @@ bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) void _NPN_SetException(NPObject* o, const NPUTF8* message) { if (o->_class == NPScriptObjectClass) { - JavaScriptObject* obj = (JavaScriptObject*)o; - RootObject* rootObject = obj->rootObject; - if (!rootObject || !rootObject->isValid()) - return; - - ExecState* exec = rootObject->globalObject()->globalExec(); - JSLock lock; - throwError(exec, GeneralError, message); + KJS::Bindings::SetGlobalException(message); } } diff --git a/JavaScriptCore/bindings/c/c_instance.cpp b/JavaScriptCore/bindings/c/c_instance.cpp index 3d04054..b453bd0 100644 --- a/JavaScriptCore/bindings/c/c_instance.cpp +++ b/JavaScriptCore/bindings/c/c_instance.cpp @@ -97,6 +97,7 @@ JSValue* CInstance::invokeMethod(ExecState* exec, const MethodList& methodList, convertValueToNPVariant(exec, args.at(i), &cArgs[i]); // Invoke the 'C' method. + SetGlobalException(0); NPVariant resultVariant; VOID_TO_NPVARIANT(resultVariant); @@ -110,6 +111,7 @@ JSValue* CInstance::invokeMethod(ExecState* exec, const MethodList& methodList, JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get()); _NPN_ReleaseVariantValue(&resultVariant); + MoveGlobalExceptionToExecState(exec); return resultValue; } @@ -127,6 +129,7 @@ JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const List& args) convertValueToNPVariant(exec, args.at(i), &cArgs[i]); // Invoke the 'C' method. + SetGlobalException(0); NPVariant resultVariant; VOID_TO_NPVARIANT(resultVariant); { @@ -139,6 +142,7 @@ JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const List& args) JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get()); _NPN_ReleaseVariantValue(&resultVariant); + MoveGlobalExceptionToExecState(exec); return resultValue; } diff --git a/JavaScriptCore/bindings/c/c_runtime.cpp b/JavaScriptCore/bindings/c/c_runtime.cpp index c5636cd..2340d11 100644 --- a/JavaScriptCore/bindings/c/c_runtime.cpp +++ b/JavaScriptCore/bindings/c/c_runtime.cpp @@ -32,10 +32,42 @@ #include "c_instance.h" #include "c_utility.h" #include "npruntime_impl.h" +#include "object.h" namespace KJS { namespace Bindings { +/* + * When throwing an exception, we need to use the current ExecState. + * The following two methods implement a similar solution to the + * Objective-C implementation, where _NPN_SetException set a global + * exception (using SetGlobalException). + * We then test (using MoveGlobalExceptionToExecState) if the exception + * is set, after each javascript call that might result in an exception. + * If the exception is set we throw it with the passed ExecState. + */ + +static UString* globalLastException = 0; + +void SetGlobalException(const NPUTF8* exception) +{ + if (globalLastException != 0) { + delete globalLastException; + globalLastException = 0; + } + if (exception != 0) + globalLastException = new UString(exception); +} + +void MoveGlobalExceptionToExecState(ExecState* exec) +{ + if (!globalLastException) + return; + JSLock lock; + throwError(exec, GeneralError, *globalLastException); + SetGlobalException(0); +} + // ---------------------- CMethod ---------------------- const char* CMethod::name() const @@ -60,11 +92,13 @@ JSValue* CField::valueFromInstance(ExecState* exec, const Instance* inst) const NPVariant property; VOID_TO_NPVARIANT(property); + SetGlobalException(0); bool result; { JSLock::DropAllLocks dropAllLocks; result = obj->_class->getProperty(obj, _fieldIdentifier, &property); } + MoveGlobalExceptionToExecState(exec); if (result) { JSValue* result = convertNPVariantToValue(exec, &property, instance->rootObject()); _NPN_ReleaseVariantValue(&property); @@ -82,12 +116,15 @@ void CField::setValueToInstance(ExecState *exec, const Instance *inst, JSValue * NPVariant variant; convertValueToNPVariant(exec, aValue, &variant); + SetGlobalException(0); + { JSLock::DropAllLocks dropAllLocks; obj->_class->setProperty(obj, _fieldIdentifier, &variant); } _NPN_ReleaseVariantValue(&variant); + MoveGlobalExceptionToExecState(exec); } } diff --git a/JavaScriptCore/bindings/c/c_runtime.h b/JavaScriptCore/bindings/c/c_runtime.h index 469008a..0cac932 100644 --- a/JavaScriptCore/bindings/c/c_runtime.h +++ b/JavaScriptCore/bindings/c/c_runtime.h @@ -59,6 +59,9 @@ private: NPIdentifier _methodIdentifier; }; +void SetGlobalException(const NPUTF8* exception); +void MoveGlobalExceptionToExecState(ExecState* exec); + } // namespace Bindings } // namespace KJS diff --git a/JavaScriptCore/bindings/jni/jni_android.cpp b/JavaScriptCore/bindings/jni/jni_android.cpp new file mode 100644 index 0000000..b5f7d8f --- /dev/null +++ b/JavaScriptCore/bindings/jni/jni_android.cpp @@ -0,0 +1,35 @@ +/* + * + * Copyright (C) 2006 The Android Open Source Project + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include "jni/jni_utility.h" +#include "jni/jni_runtime.h" + +#if defined ANDROID +bool KJS::Bindings::dispatchJNICall (const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char*, JSValue *&exceptionDescription) +{ + bzero (&result, sizeof(jvalue)); + return false; + +} +#endif + diff --git a/JavaScriptCore/bindings/make_testbindings b/JavaScriptCore/bindings/make_testbindings index 1f528fe..1f528fe 100755..100644 --- a/JavaScriptCore/bindings/make_testbindings +++ b/JavaScriptCore/bindings/make_testbindings diff --git a/JavaScriptCore/bindings/npapi.h b/JavaScriptCore/bindings/npapi.h index ba8b6c7..d7ff9f3 100644 --- a/JavaScriptCore/bindings/npapi.h +++ b/JavaScriptCore/bindings/npapi.h @@ -105,7 +105,13 @@ /*----------------------------------------------------------------------*/ #define NP_VERSION_MAJOR 0 +#ifdef ANDROID_PLUGINS +// Implements NPN_PluginThreadAsyncCall. Sandbox WebKit is version 20 +// and should override this change when merged. +#define NP_VERSION_MINOR 19 +#else #define NP_VERSION_MINOR 18 +#endif @@ -706,6 +712,11 @@ void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion); void NPN_ForceRedraw(NPP instance); void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled); void NPN_PopPopupsEnabledState(NPP instance); +#ifdef ANDROID_PLUGINS +// Sandbox WebKit is version 20 NPAPI and implements +// NPN_PluginThreadAsyncCall. Remove this change when merged. +void NPN_PluginThreadAsyncCall(NPP instance, void (*func)(void *), void *userData); +#endif #ifdef __cplusplus } /* end extern "C" */ diff --git a/JavaScriptCore/bindings/objc/objc_runtime.h b/JavaScriptCore/bindings/objc/objc_runtime.h index 74bc49e..1151d53 100644 --- a/JavaScriptCore/bindings/objc/objc_runtime.h +++ b/JavaScriptCore/bindings/objc/objc_runtime.h @@ -103,7 +103,8 @@ public: const ClassInfo *classInfo() const { return &info; } virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); - virtual void put(ExecState*, const Identifier& propertyName, JSValue*); + virtual bool canPut(ExecState *exec, const Identifier &propertyName) const; + virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None); virtual bool implementsCall() const; virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); diff --git a/JavaScriptCore/bindings/objc/objc_runtime.mm b/JavaScriptCore/bindings/objc/objc_runtime.mm index 14877b4..ec0b41f 100644 --- a/JavaScriptCore/bindings/objc/objc_runtime.mm +++ b/JavaScriptCore/bindings/objc/objc_runtime.mm @@ -211,10 +211,16 @@ bool ObjcFallbackObjectImp::getOwnPropertySlot(ExecState*, const Identifier&, Pr return true; } -void ObjcFallbackObjectImp::put(ExecState*, const Identifier&, JSValue*) +void ObjcFallbackObjectImp::put(ExecState*, const Identifier&, JSValue*, int) { } +bool ObjcFallbackObjectImp::canPut(ExecState*, const Identifier&) const +{ + return false; +} + + JSType ObjcFallbackObjectImp::type() const { id targetObject = _instance->getObject(); diff --git a/JavaScriptCore/bindings/runtime_array.cpp b/JavaScriptCore/bindings/runtime_array.cpp index 005bae2..c8ff075 100644 --- a/JavaScriptCore/bindings/runtime_array.cpp +++ b/JavaScriptCore/bindings/runtime_array.cpp @@ -80,7 +80,7 @@ bool RuntimeArray::getOwnPropertySlot(ExecState *exec, unsigned index, PropertyS return JSObject::getOwnPropertySlot(exec, index, slot); } -void RuntimeArray::put(ExecState* exec, const Identifier& propertyName, JSValue* value) +void RuntimeArray::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) { if (propertyName == exec->propertyNames().length) { throwError(exec, RangeError); @@ -94,10 +94,10 @@ void RuntimeArray::put(ExecState* exec, const Identifier& propertyName, JSValue* return; } - JSObject::put(exec, propertyName, value); + JSObject::put(exec, propertyName, value, attr); } -void RuntimeArray::put(ExecState* exec, unsigned index, JSValue* value) +void RuntimeArray::put(ExecState* exec, unsigned index, JSValue* value, int) { if (index >= getLength()) { throwError(exec, RangeError); diff --git a/JavaScriptCore/bindings/runtime_array.h b/JavaScriptCore/bindings/runtime_array.h index 74b540f..2182b31 100644 --- a/JavaScriptCore/bindings/runtime_array.h +++ b/JavaScriptCore/bindings/runtime_array.h @@ -39,8 +39,8 @@ public: virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); virtual bool getOwnPropertySlot(ExecState *, unsigned, PropertySlot&); - virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value); - virtual void put(ExecState *exec, unsigned propertyName, JSValue *value); + virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None); + virtual void put(ExecState *exec, unsigned propertyName, JSValue *value, int attr = None); virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); virtual bool deleteProperty(ExecState *exec, unsigned propertyName); diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp index 30ab488..c2cb3e8 100644 --- a/JavaScriptCore/bindings/runtime_object.cpp +++ b/JavaScriptCore/bindings/runtime_object.cpp @@ -154,7 +154,7 @@ bool RuntimeObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& pro return false; } -void RuntimeObjectImp::put(ExecState* exec, const Identifier& propertyName, JSValue* value) +void RuntimeObjectImp::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int) { if (!instance) { throwInvalidAccessError(exec); @@ -174,6 +174,22 @@ void RuntimeObjectImp::put(ExecState* exec, const Identifier& propertyName, JSVa instance->end(); } +bool RuntimeObjectImp::canPut(ExecState* exec, const Identifier& propertyName) const +{ + if (!instance) { + throwInvalidAccessError(exec); + return false; + } + + instance->begin(); + + Field *aField = instance->getClass()->fieldNamed(propertyName, instance.get()); + + instance->end(); + + return !!aField; +} + bool RuntimeObjectImp::deleteProperty(ExecState*, const Identifier&) { // Can never remove a property of a RuntimeObject. diff --git a/JavaScriptCore/bindings/runtime_object.h b/JavaScriptCore/bindings/runtime_object.h index e2387e3..0ce7d74 100644 --- a/JavaScriptCore/bindings/runtime_object.h +++ b/JavaScriptCore/bindings/runtime_object.h @@ -40,7 +40,8 @@ public: const ClassInfo *classInfo() const { return &info; } virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); - virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value); + virtual bool canPut(ExecState *exec, const Identifier &propertyName) const; + virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None); virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); virtual JSValue *defaultValue(ExecState *exec, JSType hint) const; virtual bool implementsCall() const; diff --git a/JavaScriptCore/bindings/runtime_root.cpp b/JavaScriptCore/bindings/runtime_root.cpp index e7ae28f..738cfd6 100644 --- a/JavaScriptCore/bindings/runtime_root.cpp +++ b/JavaScriptCore/bindings/runtime_root.cpp @@ -197,7 +197,7 @@ void RootObject::setCreateRootObject(CreateRootObjectFunction createRootObject) PassRefPtr<RootObject> RootObject::create(const void* nativeHandle, JSGlobalObject* globalObject) { - return adoptRef(new RootObject(nativeHandle, globalObject)); + return new RootObject(nativeHandle, globalObject); } RootObject::RootObject(const void* nativeHandle, JSGlobalObject* globalObject) |