Revision: 16092
Author: [email protected]
Date: Wed Aug 7 02:11:39 2013
Log: Make JSON::Parse return Local<Value>
It should be able to return Smi, etc. Not only JSObject.
BUG=v8:2821
TEST=cctest/test-api/JSONParseNumber
[email protected]
Review URL: https://codereview.chromium.org/22416003
Patch from Takeshi Yoshino <[email protected]>.
http://code.google.com/p/v8/source/detail?r=16092
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Wed Aug 7 01:26:23 2013
+++ /branches/bleeding_edge/include/v8.h Wed Aug 7 02:11:39 2013
@@ -1273,13 +1273,13 @@
class V8_EXPORT JSON {
public:
/**
- * Tries to parse the string |json_string| and returns it as object if
+ * Tries to parse the string |json_string| and returns it as value if
* successful.
*
* \param json_string The string to parse.
- * \return The corresponding object if successfully parsed.
+ * \return The corresponding value if successfully parsed.
*/
- static Local<Object> Parse(Local<String> json_string);
+ static Local<Value> Parse(Local<String> json_string);
};
=======================================
--- /branches/bleeding_edge/src/api.cc Wed Aug 7 01:26:23 2013
+++ /branches/bleeding_edge/src/api.cc Wed Aug 7 02:11:39 2013
@@ -2620,7 +2620,7 @@
// --- J S O N ---
-Local<Object> JSON::Parse(Local<String> json_string) {
+Local<Value> JSON::Parse(Local<String> json_string) {
i::Isolate* isolate = i::Isolate::Current();
EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
ENTER_V8(isolate);
@@ -2637,7 +2637,7 @@
has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
return Utils::ToLocal(
- i::Handle<i::JSObject>::cast(scope.CloseAndEscape(result)));
+ i::Handle<i::Object>::cast(scope.CloseAndEscape(result)));
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Tue Aug 6 06:58:21 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc Wed Aug 7 02:11:39 2013
@@ -19915,14 +19915,24 @@
}
-THREADED_TEST(JSONParse) {
+THREADED_TEST(JSONParseObject) {
LocalContext context;
HandleScope scope(context->GetIsolate());
- Local<Object> obj = v8::JSON::Parse(v8_str("{\"x\":42}"));
+ Local<Value> obj = v8::JSON::Parse(v8_str("{\"x\":42}"));
Handle<Object> global = context->Global();
global->Set(v8_str("obj"), obj);
ExpectString("JSON.stringify(obj)", "{\"x\":42}");
}
+
+
+THREADED_TEST(JSONParseNumber) {
+ LocalContext context;
+ HandleScope scope(context->GetIsolate());
+ Local<Value> obj = v8::JSON::Parse(v8_str("42"));
+ Handle<Object> global = context->Global();
+ global->Set(v8_str("obj"), obj);
+ ExpectString("JSON.stringify(obj)", "42");
+}
#ifndef WIN32
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.