OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
| 7 #include <iomanip> |
7 #include <memory> | 8 #include <memory> |
8 | 9 |
9 #include "src/disasm.h" | 10 #include "src/disasm.h" |
10 #include "src/disassembler.h" | 11 #include "src/disassembler.h" |
11 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
12 #include "src/objects-inl.h" | 13 #include "src/objects-inl.h" |
13 #include "src/ostreams.h" | 14 #include "src/ostreams.h" |
14 #include "src/regexp/jsregexp.h" | 15 #include "src/regexp/jsregexp.h" |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 break; | 311 break; |
311 } | 312 } |
312 } | 313 } |
313 } else if (IsJSGlobalObject()) { | 314 } else if (IsJSGlobalObject()) { |
314 global_dictionary()->Print(os); | 315 global_dictionary()->Print(os); |
315 } else { | 316 } else { |
316 property_dictionary()->Print(os); | 317 property_dictionary()->Print(os); |
317 } | 318 } |
318 } | 319 } |
319 | 320 |
320 | 321 template <class T, bool print_the_hole> |
321 template <class T> | |
322 static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT | 322 static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT |
323 T* p = T::cast(object); | 323 T* array = T::cast(object); |
324 for (int i = 0; i < p->length(); i++) { | 324 if (array->length() == 0) return; |
325 os << "\n " << i << ": " << p->get_scalar(i); | 325 int previous_index = 0; |
| 326 double previous_value = array->get_scalar(0); |
| 327 double value; |
| 328 int i; |
| 329 for (i = 1; i <= array->length(); i++) { |
| 330 if (i < array->length()) value = array->get_scalar(i); |
| 331 bool values_are_nan = std::isnan(previous_value) && std::isnan(value); |
| 332 if ((previous_value == value || values_are_nan) && i != array->length()) { |
| 333 continue; |
| 334 } |
| 335 os << "\n"; |
| 336 std::stringstream ss; |
| 337 ss << previous_index; |
| 338 if (previous_index != i - 1) { |
| 339 ss << '-' << (i - 1); |
| 340 } |
| 341 os << std::setw(12) << ss.str() << ": "; |
| 342 if (print_the_hole && |
| 343 FixedDoubleArray::cast(object)->is_the_hole(previous_index)) { |
| 344 os << "<the_hole>"; |
| 345 } else { |
| 346 os << previous_value; |
| 347 } |
| 348 previous_index = i; |
| 349 previous_value = value; |
326 } | 350 } |
327 } | 351 } |
328 | 352 |
329 | 353 |
330 void JSObject::PrintElements(std::ostream& os) { // NOLINT | 354 void JSObject::PrintElements(std::ostream& os) { // NOLINT |
331 // Don't call GetElementsKind, its validation code can cause the printer to | 355 // Don't call GetElementsKind, its validation code can cause the printer to |
332 // fail when debugging. | 356 // fail when debugging. |
| 357 if (elements()->length() == 0) return; |
333 switch (map()->elements_kind()) { | 358 switch (map()->elements_kind()) { |
334 case FAST_HOLEY_SMI_ELEMENTS: | 359 case FAST_HOLEY_SMI_ELEMENTS: |
335 case FAST_SMI_ELEMENTS: | 360 case FAST_SMI_ELEMENTS: |
336 case FAST_HOLEY_ELEMENTS: | 361 case FAST_HOLEY_ELEMENTS: |
337 case FAST_ELEMENTS: | 362 case FAST_ELEMENTS: |
338 case FAST_STRING_WRAPPER_ELEMENTS: { | 363 case FAST_STRING_WRAPPER_ELEMENTS: { |
339 // Print in array notation for non-sparse arrays. | 364 // Print in array notation for non-sparse arrays. |
340 FixedArray* p = FixedArray::cast(elements()); | 365 FixedArray* array = FixedArray::cast(elements()); |
341 for (int i = 0; i < p->length(); i++) { | 366 Object* previous_value = array->get(0); |
342 os << "\n " << i << ": " << Brief(p->get(i)); | 367 Object* value; |
| 368 int previous_index = 0; |
| 369 int i; |
| 370 for (i = 1; i <= array->length(); i++) { |
| 371 if (i < array->length()) value = array->get(i); |
| 372 if (previous_value == value && i != array->length()) { |
| 373 continue; |
| 374 } |
| 375 os << "\n"; |
| 376 std::stringstream ss; |
| 377 ss << previous_index; |
| 378 if (previous_index != i - 1) { |
| 379 ss << '-' << (i - 1); |
| 380 } |
| 381 os << std::setw(12) << ss.str() << ": " << Brief(previous_value); |
| 382 previous_index = i; |
| 383 previous_value = value; |
343 } | 384 } |
344 break; | 385 break; |
345 } | 386 } |
346 case FAST_HOLEY_DOUBLE_ELEMENTS: | 387 case FAST_HOLEY_DOUBLE_ELEMENTS: |
347 case FAST_DOUBLE_ELEMENTS: { | 388 case FAST_DOUBLE_ELEMENTS: { |
348 // Print in array notation for non-sparse arrays. | 389 DoPrintElements<FixedDoubleArray, true>(os, elements()); |
349 if (elements()->length() > 0) { | |
350 FixedDoubleArray* p = FixedDoubleArray::cast(elements()); | |
351 for (int i = 0; i < p->length(); i++) { | |
352 os << "\n " << i << ": "; | |
353 if (p->is_the_hole(i)) { | |
354 os << "<the hole>"; | |
355 } else { | |
356 os << p->get_scalar(i); | |
357 } | |
358 } | |
359 } | |
360 break; | 390 break; |
361 } | 391 } |
362 | 392 |
363 | 393 #define PRINT_ELEMENTS(Kind, Type) \ |
364 #define PRINT_ELEMENTS(Kind, Type) \ | 394 case Kind: { \ |
365 case Kind: { \ | 395 DoPrintElements<Type, false>(os, elements()); \ |
366 DoPrintElements<Type>(os, elements()); \ | 396 break; \ |
367 break; \ | |
368 } | 397 } |
369 | 398 |
370 PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array) | 399 PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array) |
371 PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray) | 400 PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray) |
372 PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array) | 401 PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array) |
373 PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array) | 402 PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array) |
374 PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array) | 403 PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array) |
375 PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array) | 404 PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array) |
376 PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array) | 405 PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array) |
377 PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array) | 406 PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array) |
378 PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array) | 407 PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array) |
379 | 408 |
380 #undef PRINT_ELEMENTS | 409 #undef PRINT_ELEMENTS |
381 | 410 |
382 case DICTIONARY_ELEMENTS: | 411 case DICTIONARY_ELEMENTS: |
383 case SLOW_STRING_WRAPPER_ELEMENTS: | 412 case SLOW_STRING_WRAPPER_ELEMENTS: |
384 SeededNumberDictionary::cast(elements())->Print(os); | 413 SeededNumberDictionary::cast(elements())->Print(os); |
385 break; | 414 break; |
386 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: | 415 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: |
387 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { | 416 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { |
388 FixedArray* p = FixedArray::cast(elements()); | 417 FixedArray* p = FixedArray::cast(elements()); |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT | 1451 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT |
1423 Object* transitions = map()->raw_transitions(); | 1452 Object* transitions = map()->raw_transitions(); |
1424 int num_transitions = TransitionArray::NumberOfTransitions(transitions); | 1453 int num_transitions = TransitionArray::NumberOfTransitions(transitions); |
1425 if (num_transitions == 0) return; | 1454 if (num_transitions == 0) return; |
1426 os << "\n - transitions"; | 1455 os << "\n - transitions"; |
1427 TransitionArray::PrintTransitions(os, transitions, false); | 1456 TransitionArray::PrintTransitions(os, transitions, false); |
1428 } | 1457 } |
1429 #endif // defined(DEBUG) || defined(OBJECT_PRINT) | 1458 #endif // defined(DEBUG) || defined(OBJECT_PRINT) |
1430 } // namespace internal | 1459 } // namespace internal |
1431 } // namespace v8 | 1460 } // namespace v8 |
OLD | NEW |