Commit bebf3779 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Fix JSON.stringify for objects with interceptor handlers.

BUG=161028

Review URL: https://chromiumcodereview.appspot.com/11348209

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13041 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent bbb6d450
......@@ -76,9 +76,6 @@ class BasicJsonStringifier BASE_EMBEDDED {
}
}
Handle<Object> GetProperty(Handle<JSObject> object,
Handle<String> key);
Handle<Object> ApplyToJsonFunction(Handle<Object> object,
Handle<Object> key);
......@@ -262,34 +259,6 @@ void BasicJsonStringifier::Append_(const Char* chars) {
}
Handle<Object> BasicJsonStringifier::GetProperty(Handle<JSObject> object,
Handle<String> key) {
LookupResult lookup(isolate_);
object->LocalLookupRealNamedProperty(*key, &lookup);
if (!lookup.IsProperty()) return factory_->undefined_value();
switch (lookup.type()) {
case NORMAL: {
Object* value = lookup.holder()->GetNormalizedProperty(&lookup);
ASSERT(!value->IsTheHole());
return Handle<Object>(value, isolate_);
}
case FIELD: {
Object* value = lookup.holder()->FastPropertyAt(
lookup.GetFieldIndex().field_index());
ASSERT(!value->IsTheHole());
return Handle<Object>(value, isolate_);
}
case CONSTANT_FUNCTION:
return Handle<Object>(lookup.GetConstantFunction(), isolate_);
default: {
PropertyAttributes attr;
return Object::GetProperty(object, object, &lookup, key, &attr);
}
}
return Handle<Object>::null();
}
Handle<Object> BasicJsonStringifier::ApplyToJsonFunction(
Handle<Object> object, Handle<Object> key) {
LookupResult lookup(isolate_);
......@@ -400,8 +369,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric(
bool deferred_comma,
bool deferred_key) {
Handle<JSObject> builtins(isolate_->native_context()->builtins());
Handle<JSFunction> builtin = Handle<JSFunction>::cast(
v8::internal::GetProperty(builtins, "JSONSerializeAdapter"));
Handle<JSFunction> builtin =
Handle<JSFunction>::cast(GetProperty(builtins, "JSONSerializeAdapter"));
Handle<Object> argv[] = { key, object };
bool has_exception = false;
......
......@@ -453,3 +453,29 @@ THREADED_TEST(HandleScopeSegment) {
"result;"))->Run();
CHECK_EQ(100, result->Int32Value());
}
v8::Handle<v8::Array> JSONStringifyEnumerator(const AccessorInfo& info) {
v8::Handle<v8::Array> array = v8::Array::New(1);
array->Set(0, v8_str("regress"));
return array;
}
v8::Handle<v8::Value> JSONStringifyGetter(Local<String> name,
const AccessorInfo& info) {
return v8_str("crbug-161028");
}
THREADED_TEST(JSONStringifyNamedInterceptorObject) {
v8::HandleScope scope;
LocalContext env;
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
obj->SetNamedPropertyHandler(
JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator);
env->Global()->Set(v8_str("obj"), obj->NewInstance());
v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected));
}
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