summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/bindings/c
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/bindings/c')
-rw-r--r--JavaScriptCore/bindings/c/c_instance.cpp4
-rw-r--r--JavaScriptCore/bindings/c/c_runtime.cpp37
-rw-r--r--JavaScriptCore/bindings/c/c_runtime.h3
3 files changed, 44 insertions, 0 deletions
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