OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 | 1861 |
1862 void JSObject::JSObjectShortPrint(StringStream* accumulator) { | 1862 void JSObject::JSObjectShortPrint(StringStream* accumulator) { |
1863 switch (map()->instance_type()) { | 1863 switch (map()->instance_type()) { |
1864 case JS_ARRAY_TYPE: { | 1864 case JS_ARRAY_TYPE: { |
1865 double length = JSArray::cast(this)->length()->IsUndefined() | 1865 double length = JSArray::cast(this)->length()->IsUndefined() |
1866 ? 0 | 1866 ? 0 |
1867 : JSArray::cast(this)->length()->Number(); | 1867 : JSArray::cast(this)->length()->Number(); |
1868 accumulator->Add("<JS Array[%u]>", static_cast<uint32_t>(length)); | 1868 accumulator->Add("<JS Array[%u]>", static_cast<uint32_t>(length)); |
1869 break; | 1869 break; |
1870 } | 1870 } |
| 1871 case JS_BOUND_FUNCTION_TYPE: { |
| 1872 JSBoundFunction* bound_function = JSBoundFunction::cast(this); |
| 1873 Object* name = bound_function->name(); |
| 1874 accumulator->Add("<JS BoundFunction"); |
| 1875 if (name->IsString()) { |
| 1876 String* str = String::cast(name); |
| 1877 if (str->length() > 0) { |
| 1878 accumulator->Add(" "); |
| 1879 accumulator->Put(str); |
| 1880 } |
| 1881 } |
| 1882 accumulator->Add( |
| 1883 " (BoundTargetFunction %p)>", |
| 1884 reinterpret_cast<void*>(bound_function->bound_target_function())); |
| 1885 break; |
| 1886 } |
1871 case JS_WEAK_MAP_TYPE: { | 1887 case JS_WEAK_MAP_TYPE: { |
1872 accumulator->Add("<JS WeakMap>"); | 1888 accumulator->Add("<JS WeakMap>"); |
1873 break; | 1889 break; |
1874 } | 1890 } |
1875 case JS_WEAK_SET_TYPE: { | 1891 case JS_WEAK_SET_TYPE: { |
1876 accumulator->Add("<JS WeakSet>"); | 1892 accumulator->Add("<JS WeakSet>"); |
1877 break; | 1893 break; |
1878 } | 1894 } |
1879 case JS_REGEXP_TYPE: { | 1895 case JS_REGEXP_TYPE: { |
1880 accumulator->Add("<JS RegExp>"); | 1896 accumulator->Add("<JS RegExp>"); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2400 return String::cast(constructor->shared()->instance_class_name()); | 2416 return String::cast(constructor->shared()->instance_class_name()); |
2401 } | 2417 } |
2402 // If the constructor is not present, return "Object". | 2418 // If the constructor is not present, return "Object". |
2403 return GetHeap()->Object_string(); | 2419 return GetHeap()->Object_string(); |
2404 } | 2420 } |
2405 | 2421 |
2406 | 2422 |
2407 MaybeHandle<String> JSReceiver::BuiltinStringTag(Handle<JSReceiver> object) { | 2423 MaybeHandle<String> JSReceiver::BuiltinStringTag(Handle<JSReceiver> object) { |
2408 Maybe<bool> is_array = Object::IsArray(object); | 2424 Maybe<bool> is_array = Object::IsArray(object); |
2409 MAYBE_RETURN(is_array, MaybeHandle<String>()); | 2425 MAYBE_RETURN(is_array, MaybeHandle<String>()); |
| 2426 Isolate* const isolate = object->GetIsolate(); |
2410 if (is_array.FromJust()) { | 2427 if (is_array.FromJust()) { |
2411 return object->GetIsolate()->factory()->Array_string(); | 2428 return isolate->factory()->Array_string(); |
| 2429 } |
| 2430 if (object->IsCallable()) { |
| 2431 return isolate->factory()->Function_string(); |
2412 } | 2432 } |
2413 // TODO(adamk): class_name() is expensive, replace with instance type | 2433 // TODO(adamk): class_name() is expensive, replace with instance type |
2414 // checks where possible. | 2434 // checks where possible. |
2415 return handle(object->class_name()); | 2435 return handle(object->class_name(), isolate); |
2416 } | 2436 } |
2417 | 2437 |
2418 | 2438 |
2419 // static | 2439 // static |
2420 Handle<String> JSReceiver::GetConstructorName(Handle<JSReceiver> receiver) { | 2440 Handle<String> JSReceiver::GetConstructorName(Handle<JSReceiver> receiver) { |
2421 Isolate* isolate = receiver->GetIsolate(); | 2441 Isolate* isolate = receiver->GetIsolate(); |
2422 | 2442 |
2423 // If the object was instantiated simply with base == new.target, the | 2443 // If the object was instantiated simply with base == new.target, the |
2424 // constructor on the map provides the most accurate name. | 2444 // constructor on the map provides the most accurate name. |
2425 // Don't provide the info for prototypes, since their constructors are | 2445 // Don't provide the info for prototypes, since their constructors are |
(...skipping 8313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10739 int number_of_literals, | 10759 int number_of_literals, |
10740 PretenureFlag pretenure) { | 10760 PretenureFlag pretenure) { |
10741 Handle<FixedArray> literals = isolate->factory()->NewFixedArray( | 10761 Handle<FixedArray> literals = isolate->factory()->NewFixedArray( |
10742 number_of_literals + kFirstLiteralIndex, pretenure); | 10762 number_of_literals + kFirstLiteralIndex, pretenure); |
10743 Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals); | 10763 Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals); |
10744 casted_literals->set_feedback_vector(*vector); | 10764 casted_literals->set_feedback_vector(*vector); |
10745 return casted_literals; | 10765 return casted_literals; |
10746 } | 10766 } |
10747 | 10767 |
10748 | 10768 |
10749 // static | |
10750 Handle<BindingsArray> BindingsArray::New(Isolate* isolate, | |
10751 Handle<TypeFeedbackVector> vector, | |
10752 Handle<JSReceiver> bound_function, | |
10753 Handle<Object> bound_this, | |
10754 int number_of_bindings) { | |
10755 Handle<FixedArray> bindings = isolate->factory()->NewFixedArray( | |
10756 number_of_bindings + kFirstBindingIndex); | |
10757 Handle<BindingsArray> casted_bindings = Handle<BindingsArray>::cast(bindings); | |
10758 casted_bindings->set_feedback_vector(*vector); | |
10759 casted_bindings->set_bound_function(*bound_function); | |
10760 casted_bindings->set_bound_this(*bound_this); | |
10761 return casted_bindings; | |
10762 } | |
10763 | |
10764 | |
10765 // static | |
10766 Handle<JSArray> BindingsArray::CreateBoundArguments( | |
10767 Handle<BindingsArray> bindings) { | |
10768 int bound_argument_count = bindings->bindings_count(); | |
10769 Factory* factory = bindings->GetIsolate()->factory(); | |
10770 Handle<FixedArray> arguments = factory->NewFixedArray(bound_argument_count); | |
10771 bindings->CopyTo(kFirstBindingIndex, *arguments, 0, bound_argument_count); | |
10772 return factory->NewJSArrayWithElements(arguments); | |
10773 } | |
10774 | |
10775 | |
10776 // static | |
10777 Handle<JSArray> BindingsArray::CreateRuntimeBindings( | |
10778 Handle<BindingsArray> bindings) { | |
10779 Factory* factory = bindings->GetIsolate()->factory(); | |
10780 // A runtime bindings array consists of | |
10781 // [bound function, bound this, [arg0, arg1, ...]]. | |
10782 Handle<FixedArray> runtime_bindings = | |
10783 factory->NewFixedArray(2 + bindings->bindings_count()); | |
10784 bindings->CopyTo(kBoundFunctionIndex, *runtime_bindings, 0, | |
10785 2 + bindings->bindings_count()); | |
10786 return factory->NewJSArrayWithElements(runtime_bindings); | |
10787 } | |
10788 | |
10789 | |
10790 int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out, | 10769 int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out, |
10791 CatchPrediction* prediction_out) { | 10770 CatchPrediction* prediction_out) { |
10792 int innermost_handler = -1, innermost_start = -1; | 10771 int innermost_handler = -1, innermost_start = -1; |
10793 for (int i = 0; i < length(); i += kRangeEntrySize) { | 10772 for (int i = 0; i < length(); i += kRangeEntrySize) { |
10794 int start_offset = Smi::cast(get(i + kRangeStartIndex))->value(); | 10773 int start_offset = Smi::cast(get(i + kRangeStartIndex))->value(); |
10795 int end_offset = Smi::cast(get(i + kRangeEndIndex))->value(); | 10774 int end_offset = Smi::cast(get(i + kRangeEndIndex))->value(); |
10796 int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value(); | 10775 int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value(); |
10797 int handler_offset = HandlerOffsetField::decode(handler_field); | 10776 int handler_offset = HandlerOffsetField::decode(handler_field); |
10798 CatchPrediction prediction = HandlerPredictionField::decode(handler_field); | 10777 CatchPrediction prediction = HandlerPredictionField::decode(handler_field); |
10799 int stack_depth = Smi::cast(get(i + kRangeDepthIndex))->value(); | 10778 int stack_depth = Smi::cast(get(i + kRangeDepthIndex))->value(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10839 #endif | 10818 #endif |
10840 | 10819 |
10841 | 10820 |
10842 bool String::LooksValid() { | 10821 bool String::LooksValid() { |
10843 if (!GetIsolate()->heap()->Contains(this)) return false; | 10822 if (!GetIsolate()->heap()->Contains(this)) return false; |
10844 return true; | 10823 return true; |
10845 } | 10824 } |
10846 | 10825 |
10847 | 10826 |
10848 // static | 10827 // static |
10849 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) { | 10828 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name, |
10850 if (name->IsString()) return Handle<String>::cast(name); | 10829 Handle<String> prefix) { |
10851 // ES6 section 9.2.11 SetFunctionName, step 4. | 10830 // ES6 section 9.2.11 SetFunctionName, step 4. |
10852 Isolate* const isolate = name->GetIsolate(); | 10831 Isolate* const isolate = name->GetIsolate(); |
10853 Handle<Object> description(Handle<Symbol>::cast(name)->name(), isolate); | |
10854 if (description->IsUndefined()) return isolate->factory()->empty_string(); | |
10855 IncrementalStringBuilder builder(isolate); | 10832 IncrementalStringBuilder builder(isolate); |
10856 builder.AppendCharacter('['); | 10833 if (prefix->length() != 0) { |
10857 builder.AppendString(Handle<String>::cast(description)); | 10834 builder.AppendString(prefix); |
10858 builder.AppendCharacter(']'); | 10835 builder.AppendCharacter(' '); |
| 10836 } |
| 10837 if (name->IsString()) { |
| 10838 builder.AppendString(Handle<String>::cast(name)); |
| 10839 } else { |
| 10840 Handle<Object> description(Handle<Symbol>::cast(name)->name(), isolate); |
| 10841 if (!description->IsUndefined()) { |
| 10842 builder.AppendCharacter('['); |
| 10843 builder.AppendString(Handle<String>::cast(description)); |
| 10844 builder.AppendCharacter(']'); |
| 10845 } |
| 10846 } |
10859 return builder.Finish(); | 10847 return builder.Finish(); |
10860 } | 10848 } |
10861 | 10849 |
10862 | 10850 |
10863 namespace { | 10851 namespace { |
10864 | 10852 |
10865 bool AreDigits(const uint8_t* s, int from, int to) { | 10853 bool AreDigits(const uint8_t* s, int from, int to) { |
10866 for (int i = from; i < to; i++) { | 10854 for (int i = from; i < to; i++) { |
10867 if (s[i] < '0' || s[i] > '9') return false; | 10855 if (s[i] < '0' || s[i] > '9') return false; |
10868 } | 10856 } |
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12842 case JS_SET_ITERATOR_TYPE: | 12830 case JS_SET_ITERATOR_TYPE: |
12843 case JS_MAP_ITERATOR_TYPE: | 12831 case JS_MAP_ITERATOR_TYPE: |
12844 case JS_ITERATOR_RESULT_TYPE: | 12832 case JS_ITERATOR_RESULT_TYPE: |
12845 case JS_WEAK_MAP_TYPE: | 12833 case JS_WEAK_MAP_TYPE: |
12846 case JS_WEAK_SET_TYPE: | 12834 case JS_WEAK_SET_TYPE: |
12847 case JS_PROMISE_TYPE: | 12835 case JS_PROMISE_TYPE: |
12848 case JS_REGEXP_TYPE: | 12836 case JS_REGEXP_TYPE: |
12849 case JS_FUNCTION_TYPE: | 12837 case JS_FUNCTION_TYPE: |
12850 return true; | 12838 return true; |
12851 | 12839 |
| 12840 case JS_BOUND_FUNCTION_TYPE: |
12852 case JS_PROXY_TYPE: | 12841 case JS_PROXY_TYPE: |
12853 case JS_GLOBAL_PROXY_TYPE: | 12842 case JS_GLOBAL_PROXY_TYPE: |
12854 case JS_GLOBAL_OBJECT_TYPE: | 12843 case JS_GLOBAL_OBJECT_TYPE: |
12855 case FIXED_ARRAY_TYPE: | 12844 case FIXED_ARRAY_TYPE: |
12856 case FIXED_DOUBLE_ARRAY_TYPE: | 12845 case FIXED_DOUBLE_ARRAY_TYPE: |
12857 case ODDBALL_TYPE: | 12846 case ODDBALL_TYPE: |
12858 case FOREIGN_TYPE: | 12847 case FOREIGN_TYPE: |
12859 case MAP_TYPE: | 12848 case MAP_TYPE: |
12860 case CODE_TYPE: | 12849 case CODE_TYPE: |
12861 case CELL_TYPE: | 12850 case CELL_TYPE: |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13110 builder.AppendCString("() { [native code] }"); | 13099 builder.AppendCString("() { [native code] }"); |
13111 return builder.Finish().ToHandleChecked(); | 13100 return builder.Finish().ToHandleChecked(); |
13112 } | 13101 } |
13113 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource); | 13102 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource); |
13114 } | 13103 } |
13115 | 13104 |
13116 } // namespace | 13105 } // namespace |
13117 | 13106 |
13118 | 13107 |
13119 // static | 13108 // static |
| 13109 Handle<String> JSBoundFunction::ToString(Handle<JSBoundFunction> function) { |
| 13110 Isolate* const isolate = function->GetIsolate(); |
| 13111 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource); |
| 13112 } |
| 13113 |
| 13114 |
| 13115 // static |
13120 Handle<String> JSFunction::ToString(Handle<JSFunction> function) { | 13116 Handle<String> JSFunction::ToString(Handle<JSFunction> function) { |
13121 Isolate* const isolate = function->GetIsolate(); | 13117 Isolate* const isolate = function->GetIsolate(); |
13122 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate); | 13118 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate); |
13123 | 13119 |
13124 // Check if {function} should hide its source code. | 13120 // Check if {function} should hide its source code. |
13125 if (!shared_info->script()->IsScript() || | 13121 if (!shared_info->script()->IsScript() || |
13126 Script::cast(shared_info->script())->hide_source()) { | 13122 Script::cast(shared_info->script())->hide_source()) { |
13127 return NativeCodeFunctionSourceString(shared_info); | 13123 return NativeCodeFunctionSourceString(shared_info); |
13128 } | 13124 } |
13129 | 13125 |
(...skipping 6351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19481 if (cell->value() != *new_value) { | 19477 if (cell->value() != *new_value) { |
19482 cell->set_value(*new_value); | 19478 cell->set_value(*new_value); |
19483 Isolate* isolate = cell->GetIsolate(); | 19479 Isolate* isolate = cell->GetIsolate(); |
19484 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19480 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19485 isolate, DependentCode::kPropertyCellChangedGroup); | 19481 isolate, DependentCode::kPropertyCellChangedGroup); |
19486 } | 19482 } |
19487 } | 19483 } |
19488 | 19484 |
19489 } // namespace internal | 19485 } // namespace internal |
19490 } // namespace v8 | 19486 } // namespace v8 |
OLD | NEW |