OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 INLINE(void Append(const char* chars)) { | 71 INLINE(void Append(const char* chars)) { |
72 if (is_ascii_) { | 72 if (is_ascii_) { |
73 Append_<true>(chars); | 73 Append_<true>(chars); |
74 } else { | 74 } else { |
75 Append_<false>(chars); | 75 Append_<false>(chars); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 Handle<Object> GetProperty(Handle<JSObject> object, | |
80 Handle<String> key); | |
81 | |
82 Handle<Object> ApplyToJsonFunction(Handle<Object> object, | 79 Handle<Object> ApplyToJsonFunction(Handle<Object> object, |
83 Handle<Object> key); | 80 Handle<Object> key); |
84 | 81 |
85 Result SerializeGeneric(Handle<Object> object, | 82 Result SerializeGeneric(Handle<Object> object, |
86 Handle<Object> key, | 83 Handle<Object> key, |
87 bool deferred_comma, | 84 bool deferred_comma, |
88 bool deferred_key); | 85 bool deferred_key); |
89 | 86 |
90 // Entry point to serialize the object. | 87 // Entry point to serialize the object. |
91 INLINE(Result SerializeObject(Handle<Object> obj)) { | 88 INLINE(Result SerializeObject(Handle<Object> obj)) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (current_index_ == part_length_) Extend(); | 252 if (current_index_ == part_length_) Extend(); |
256 } | 253 } |
257 | 254 |
258 | 255 |
259 template <bool is_ascii, typename Char> | 256 template <bool is_ascii, typename Char> |
260 void BasicJsonStringifier::Append_(const Char* chars) { | 257 void BasicJsonStringifier::Append_(const Char* chars) { |
261 for ( ; *chars != '\0'; chars++) Append_<is_ascii, Char>(*chars); | 258 for ( ; *chars != '\0'; chars++) Append_<is_ascii, Char>(*chars); |
262 } | 259 } |
263 | 260 |
264 | 261 |
265 Handle<Object> BasicJsonStringifier::GetProperty(Handle<JSObject> object, | |
266 Handle<String> key) { | |
267 LookupResult lookup(isolate_); | |
268 object->LocalLookupRealNamedProperty(*key, &lookup); | |
269 if (!lookup.IsProperty()) return factory_->undefined_value(); | |
270 switch (lookup.type()) { | |
271 case NORMAL: { | |
272 Object* value = lookup.holder()->GetNormalizedProperty(&lookup); | |
273 ASSERT(!value->IsTheHole()); | |
274 return Handle<Object>(value, isolate_); | |
275 } | |
276 case FIELD: { | |
277 Object* value = lookup.holder()->FastPropertyAt( | |
278 lookup.GetFieldIndex().field_index()); | |
279 ASSERT(!value->IsTheHole()); | |
280 return Handle<Object>(value, isolate_); | |
281 } | |
282 case CONSTANT_FUNCTION: | |
283 return Handle<Object>(lookup.GetConstantFunction(), isolate_); | |
284 default: { | |
285 PropertyAttributes attr; | |
286 return Object::GetProperty(object, object, &lookup, key, &attr); | |
287 } | |
288 } | |
289 return Handle<Object>::null(); | |
290 } | |
291 | |
292 | |
293 Handle<Object> BasicJsonStringifier::ApplyToJsonFunction( | 262 Handle<Object> BasicJsonStringifier::ApplyToJsonFunction( |
294 Handle<Object> object, Handle<Object> key) { | 263 Handle<Object> object, Handle<Object> key) { |
295 LookupResult lookup(isolate_); | 264 LookupResult lookup(isolate_); |
296 JSObject::cast(*object)->LookupRealNamedProperty(*tojson_symbol_, &lookup); | 265 JSObject::cast(*object)->LookupRealNamedProperty(*tojson_symbol_, &lookup); |
297 if (!lookup.IsProperty()) return object; | 266 if (!lookup.IsProperty()) return object; |
298 PropertyAttributes attr; | 267 PropertyAttributes attr; |
299 Handle<Object> fun = | 268 Handle<Object> fun = |
300 Object::GetProperty(object, object, &lookup, tojson_symbol_, &attr); | 269 Object::GetProperty(object, object, &lookup, tojson_symbol_, &attr); |
301 if (!fun->IsJSFunction()) return object; | 270 if (!fun->IsJSFunction()) return object; |
302 | 271 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 362 } |
394 } | 363 } |
395 | 364 |
396 | 365 |
397 BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric( | 366 BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric( |
398 Handle<Object> object, | 367 Handle<Object> object, |
399 Handle<Object> key, | 368 Handle<Object> key, |
400 bool deferred_comma, | 369 bool deferred_comma, |
401 bool deferred_key) { | 370 bool deferred_key) { |
402 Handle<JSObject> builtins(isolate_->native_context()->builtins()); | 371 Handle<JSObject> builtins(isolate_->native_context()->builtins()); |
403 Handle<JSFunction> builtin = Handle<JSFunction>::cast( | 372 Handle<JSFunction> builtin = |
404 v8::internal::GetProperty(builtins, "JSONSerializeAdapter")); | 373 Handle<JSFunction>::cast(GetProperty(builtins, "JSONSerializeAdapter")); |
405 | 374 |
406 Handle<Object> argv[] = { key, object }; | 375 Handle<Object> argv[] = { key, object }; |
407 bool has_exception = false; | 376 bool has_exception = false; |
408 Handle<Object> result = | 377 Handle<Object> result = |
409 Execution::Call(builtin, object, 2, argv, &has_exception); | 378 Execution::Call(builtin, object, 2, argv, &has_exception); |
410 if (has_exception) return EXCEPTION; | 379 if (has_exception) return EXCEPTION; |
411 if (result->IsUndefined()) return UNCHANGED; | 380 if (result->IsUndefined()) return UNCHANGED; |
412 if (deferred_key) { | 381 if (deferred_key) { |
413 if (key->IsSmi()) key = factory_->NumberToString(key); | 382 if (key->IsSmi()) key = factory_->NumberToString(key); |
414 SerializeDeferredKey(deferred_comma, key); | 383 SerializeDeferredKey(deferred_comma, key); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 SerializeString_<false, char>(flat.ToAsciiVector(), object); | 761 SerializeString_<false, char>(flat.ToAsciiVector(), object); |
793 } else { | 762 } else { |
794 SerializeString_<false, uc16>(flat.ToUC16Vector(), object); | 763 SerializeString_<false, uc16>(flat.ToUC16Vector(), object); |
795 } | 764 } |
796 } | 765 } |
797 } | 766 } |
798 | 767 |
799 } } // namespace v8::internal | 768 } } // namespace v8::internal |
800 | 769 |
801 #endif // V8_JSON_STRINGIFIER_H_ | 770 #endif // V8_JSON_STRINGIFIER_H_ |
OLD | NEW |