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