summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/js/ScriptValue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/bindings/js/ScriptValue.cpp')
-rw-r--r--WebCore/bindings/js/ScriptValue.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/WebCore/bindings/js/ScriptValue.cpp b/WebCore/bindings/js/ScriptValue.cpp
index a52024d..abc31e2 100644
--- a/WebCore/bindings/js/ScriptValue.cpp
+++ b/WebCore/bindings/js/ScriptValue.cpp
@@ -29,6 +29,7 @@
#include "config.h"
#include "ScriptValue.h"
+#include "InspectorValues.h"
#include "SerializedScriptValue.h"
#include <JavaScriptCore/APICast.h>
@@ -93,4 +94,62 @@ ScriptValue ScriptValue::deserialize(ScriptState* scriptState, SerializedScriptV
return ScriptValue(value->deserialize(scriptState, scriptState->lexicalGlobalObject()));
}
+#if ENABLE(INSPECTOR)
+static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value)
+{
+ if (!value) {
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+ if (value.isNull() || value.isUndefined())
+ return InspectorValue::null();
+ if (value.isBoolean())
+ return InspectorBasicValue::create(value.getBoolean());
+ if (value.isNumber())
+ return InspectorBasicValue::create(value.uncheckedGetNumber());
+ if (value.isString()) {
+ UString s = value.getString(scriptState);
+ return InspectorString::create(String(s.data(), s.size()));
+ }
+ if (value.isObject()) {
+ if (isJSArray(&scriptState->globalData(), value)) {
+ RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
+ JSArray* array = asArray(value);
+ unsigned length = array->length();
+ for (unsigned i = 0; i < length; i++) {
+ JSValue element = array->getIndex(i);
+ RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element);
+ if (!elementValue) {
+ ASSERT_NOT_REACHED();
+ elementValue = InspectorValue::null();
+ }
+ inspectorArray->push(elementValue);
+ }
+ return inspectorArray;
+ }
+ RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
+ JSObject* object = value.getObject();
+ PropertyNameArray propertyNames(scriptState);
+ object->getOwnPropertyNames(scriptState, propertyNames);
+ for (size_t i = 0; i < propertyNames.size(); i++) {
+ const Identifier& name = propertyNames[i];
+ JSValue propertyValue = object->get(scriptState, name);
+ RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue);
+ if (!inspectorValue) {
+ ASSERT_NOT_REACHED();
+ inspectorValue = InspectorValue::null();
+ }
+ inspectorObject->set(String(name.data(), name.size()), inspectorValue);
+ }
+ return inspectorObject;
+ }
+ return 0;
+}
+
+PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const
+{
+ return jsToInspectorValue(scriptState, m_value.get());
+}
+#endif // ENABLE(INSPECTOR)
+
} // namespace WebCore