summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/js/SerializedScriptValue.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-12-17 09:55:06 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2009-12-17 09:55:06 -0800
commitb880d713c04257ca40abfef97c300afdead423b8 (patch)
tree6982576c228bcd1a7efe98afed544d840751094c /WebCore/bindings/js/SerializedScriptValue.cpp
parente2e7a5c57b53f01e63a0245b4420d54b454cb373 (diff)
parent643ca7872b450ea4efacab6188849e5aac2ba161 (diff)
downloadexternal_webkit-b880d713c04257ca40abfef97c300afdead423b8.zip
external_webkit-b880d713c04257ca40abfef97c300afdead423b8.tar.gz
external_webkit-b880d713c04257ca40abfef97c300afdead423b8.tar.bz2
am 643ca787: Merge webkit.org at r51976 : Initial merge by git.
Merge commit '643ca7872b450ea4efacab6188849e5aac2ba161' into eclair-mr2-plus-aosp * commit '643ca7872b450ea4efacab6188849e5aac2ba161': Merge webkit.org at r51976 : Initial merge by git.
Diffstat (limited to 'WebCore/bindings/js/SerializedScriptValue.cpp')
-rw-r--r--WebCore/bindings/js/SerializedScriptValue.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/WebCore/bindings/js/SerializedScriptValue.cpp b/WebCore/bindings/js/SerializedScriptValue.cpp
index 48cd92d..7c4ad62 100644
--- a/WebCore/bindings/js/SerializedScriptValue.cpp
+++ b/WebCore/bindings/js/SerializedScriptValue.cpp
@@ -27,6 +27,11 @@
#include "config.h"
#include "SerializedScriptValue.h"
+#include "File.h"
+#include "JSDOMGlobalObject.h"
+#include "JSFile.h"
+#include "JSFileList.h"
+#include <JavaScriptCore/APICast.h>
#include <runtime/DateInstance.h>
#include <runtime/ExceptionHelpers.h>
#include <runtime/PropertyNameArray.h>
@@ -148,6 +153,12 @@ SerializedScriptValueData::SerializedScriptValueData(RefPtr<SerializedArray> dat
{
}
+SerializedScriptValueData::SerializedScriptValueData(const File* file)
+ : m_type(FileType)
+ , m_string(file->path().crossThreadString())
+{
+}
+
SerializedArray* SharedSerializedData::asArray()
{
return static_cast<SerializedArray*>(this);
@@ -470,7 +481,7 @@ struct SerializingTreeWalker : public BaseWalker {
return SerializedScriptValueData(value);
if (value.isString())
- return SerializedScriptValueData(asString(value)->value());
+ return SerializedScriptValueData(asString(value)->value(m_exec));
if (value.isNumber())
return SerializedScriptValueData(SerializedScriptValueData::NumberType, value.uncheckedGetNumber());
@@ -481,10 +492,15 @@ struct SerializingTreeWalker : public BaseWalker {
if (isArray(value))
return SerializedScriptValueData();
- CallData unusedData;
- if (value.isObject() && value.getCallData(unusedData) == CallTypeNone)
- return SerializedScriptValueData();
-
+ if (value.isObject()) {
+ JSObject* obj = asObject(value);
+ if (obj->inherits(&JSFile::s_info))
+ return SerializedScriptValueData(toFile(obj));
+
+ CallData unusedData;
+ if (value.getCallData(unusedData) == CallTypeNone)
+ return SerializedScriptValueData();
+ }
// Any other types are expected to serialize as null.
return SerializedScriptValueData(jsNull());
}
@@ -640,6 +656,8 @@ struct DeserializingTreeWalker : public BaseWalker {
return jsNumber(m_exec, value.asDouble());
case SerializedScriptValueData::DateType:
return new (m_exec) DateInstance(m_exec, value.asDouble());
+ case SerializedScriptValueData::FileType:
+ return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject()), File::create(value.asString().crossThreadString()));
default:
ASSERT_NOT_REACHED();
return JSValue();
@@ -836,4 +854,36 @@ void SerializedScriptValueData::tearDownSerializedData()
walk<TeardownTreeWalker>(context, *this);
}
+SerializedScriptValue::~SerializedScriptValue()
+{
+}
+
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(JSContextRef originContext, JSValueRef apiValue, JSValueRef* exception)
+{
+ ExecState* exec = toJS(originContext);
+ JSValue value = toJS(exec, apiValue);
+ PassRefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::create(exec, value);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ return 0;
+ }
+
+ return serializedValue;
+}
+
+JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception)
+{
+ ExecState* exec = toJS(destinationContext);
+ JSValue value = deserialize(exec);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ return 0;
+ }
+ return toRef(exec, value);
+}
+
}