diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-24 02:54:39 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-24 02:54:39 +0000 |
commit | 74aef8947b7b72eca797a2f55d39997cc7af9c25 (patch) | |
tree | 60992d5a27fb7d10e2e6b280cad4dfde9256c043 /sca-cpp/trunk/modules/js | |
parent | e5f662ac57fa2c54882245e1c568e0982abab4fb (diff) |
Fix roundtripping of JSON arrays, booleans and numbers, ATOM / RSS feed detection, and support REST-style JSON and XML payloads in server handler and client proxy.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1052432 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/js/eval.hpp | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/json/json.hpp | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp index 3be0eea2d1..b7c69a1a0c 100644 --- a/sca-cpp/trunk/modules/js/eval.hpp +++ b/sca-cpp/trunk/modules/js/eval.hpp @@ -229,7 +229,9 @@ const jsval valueToJSVal(const value& val, const js::JSContext& cx) { JSObject* valuesToJSProperties(JSObject* o, const list<value>& l, const js::JSContext& cx); switch(type(val)) { - case value::String: + case value::String: { + return STRING_TO_JSVAL(JS_NewStringCopyZ(cx, c_str((string)val))); + } case value::Symbol: { return STRING_TO_JSVAL(JS_NewStringCopyZ(cx, c_str((string)val))); } diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp index a9dc57da15..df82fddbb5 100644 --- a/sca-cpp/trunk/modules/json/json.hpp +++ b/sca-cpp/trunk/modules/json/json.hpp @@ -37,6 +37,16 @@ namespace tuscany { namespace json { /** + * Return true if a list of strings contains a JSON document. + */ +const bool isJSON(const list<string>& ls) { + if (isNil(ls)) + return false; + const string s = substr(car(ls), 0, 1); + return s == "[" || s == "{"; +} + +/** * Consumes JSON strings and populates a JS object. */ failable<bool> consume(JSONParser* parser, const list<string>& ilist, const js::JSContext& cx) { @@ -93,7 +103,11 @@ template<typename R> JSBool writeCallback(const jschar *buf, uint32 len, void *d * Convert a list of values to a JSON document. */ template<typename R> const failable<R> writeJSON(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l, const js::JSContext& cx) { - jsval val = OBJECT_TO_JSVAL(valuesToJSProperties(JS_NewObject(cx, NULL, NULL, NULL), l, cx)); + jsval val; + if (js::isJSArray(l)) + val = OBJECT_TO_JSVAL(valuesToJSElements(JS_NewArrayObject(cx, 0, NULL), l, 0, cx)); + else + val = OBJECT_TO_JSVAL(valuesToJSProperties(JS_NewObject(cx, NULL, NULL, NULL), l, cx)); WriteContext<R> wcx(reduce, initial, cx); if (!JS_Stringify(cx, &val, NULL, JSVAL_NULL, writeCallback<R>, &wcx)) |