Commit 5818d831 authored by yangguo@chromium.org's avatar yangguo@chromium.org

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
R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/22416003

Patch from Takeshi Yoshino <tyoshino@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16092 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5ad4a845
...@@ -1273,13 +1273,13 @@ class V8_EXPORT StackFrame { ...@@ -1273,13 +1273,13 @@ class V8_EXPORT StackFrame {
class V8_EXPORT JSON { class V8_EXPORT JSON {
public: 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. * successful.
* *
* \param json_string The string to parse. * \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);
}; };
......
...@@ -2620,7 +2620,7 @@ bool StackFrame::IsConstructor() const { ...@@ -2620,7 +2620,7 @@ bool StackFrame::IsConstructor() const {
// --- J S O N --- // --- 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(); i::Isolate* isolate = i::Isolate::Current();
EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
ENTER_V8(isolate); ENTER_V8(isolate);
...@@ -2637,7 +2637,7 @@ Local<Object> JSON::Parse(Local<String> json_string) { ...@@ -2637,7 +2637,7 @@ Local<Object> JSON::Parse(Local<String> json_string) {
has_pending_exception = result.is_null(); has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
return Utils::ToLocal( return Utils::ToLocal(
i::Handle<i::JSObject>::cast(scope.CloseAndEscape(result))); i::Handle<i::Object>::cast(scope.CloseAndEscape(result)));
} }
......
...@@ -19915,16 +19915,26 @@ THREADED_TEST(Regress260106) { ...@@ -19915,16 +19915,26 @@ THREADED_TEST(Regress260106) {
} }
THREADED_TEST(JSONParse) { THREADED_TEST(JSONParseObject) {
LocalContext context; LocalContext context;
HandleScope scope(context->GetIsolate()); 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(); Handle<Object> global = context->Global();
global->Set(v8_str("obj"), obj); global->Set(v8_str("obj"), obj);
ExpectString("JSON.stringify(obj)", "{\"x\":42}"); 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 #ifndef WIN32
class ThreadInterruptTest { class ThreadInterruptTest {
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment