Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: src/objects.cc

Issue 1542963002: [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@FunctionConstructor
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 8287 matching lines...) Expand 10 before | Expand all | Expand 10 after
10713 int number_of_literals, 10733 int number_of_literals,
10714 PretenureFlag pretenure) { 10734 PretenureFlag pretenure) {
10715 Handle<FixedArray> literals = isolate->factory()->NewFixedArray( 10735 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(
10716 number_of_literals + kFirstLiteralIndex, pretenure); 10736 number_of_literals + kFirstLiteralIndex, pretenure);
10717 Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals); 10737 Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals);
10718 casted_literals->set_feedback_vector(*vector); 10738 casted_literals->set_feedback_vector(*vector);
10719 return casted_literals; 10739 return casted_literals;
10720 } 10740 }
10721 10741
10722 10742
10723 // static
10724 Handle<BindingsArray> BindingsArray::New(Isolate* isolate,
10725 Handle<TypeFeedbackVector> vector,
10726 Handle<JSReceiver> bound_function,
10727 Handle<Object> bound_this,
10728 int number_of_bindings) {
10729 Handle<FixedArray> bindings = isolate->factory()->NewFixedArray(
10730 number_of_bindings + kFirstBindingIndex);
10731 Handle<BindingsArray> casted_bindings = Handle<BindingsArray>::cast(bindings);
10732 casted_bindings->set_feedback_vector(*vector);
10733 casted_bindings->set_bound_function(*bound_function);
10734 casted_bindings->set_bound_this(*bound_this);
10735 return casted_bindings;
10736 }
10737
10738
10739 // static
10740 Handle<JSArray> BindingsArray::CreateBoundArguments(
10741 Handle<BindingsArray> bindings) {
10742 int bound_argument_count = bindings->bindings_count();
10743 Factory* factory = bindings->GetIsolate()->factory();
10744 Handle<FixedArray> arguments = factory->NewFixedArray(bound_argument_count);
10745 bindings->CopyTo(kFirstBindingIndex, *arguments, 0, bound_argument_count);
10746 return factory->NewJSArrayWithElements(arguments);
10747 }
10748
10749
10750 // static
10751 Handle<JSArray> BindingsArray::CreateRuntimeBindings(
10752 Handle<BindingsArray> bindings) {
10753 Factory* factory = bindings->GetIsolate()->factory();
10754 // A runtime bindings array consists of
10755 // [bound function, bound this, [arg0, arg1, ...]].
10756 Handle<FixedArray> runtime_bindings =
10757 factory->NewFixedArray(2 + bindings->bindings_count());
10758 bindings->CopyTo(kBoundFunctionIndex, *runtime_bindings, 0,
10759 2 + bindings->bindings_count());
10760 return factory->NewJSArrayWithElements(runtime_bindings);
10761 }
10762
10763
10764 int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out, 10743 int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out,
10765 CatchPrediction* prediction_out) { 10744 CatchPrediction* prediction_out) {
10766 int innermost_handler = -1, innermost_start = -1; 10745 int innermost_handler = -1, innermost_start = -1;
10767 for (int i = 0; i < length(); i += kRangeEntrySize) { 10746 for (int i = 0; i < length(); i += kRangeEntrySize) {
10768 int start_offset = Smi::cast(get(i + kRangeStartIndex))->value(); 10747 int start_offset = Smi::cast(get(i + kRangeStartIndex))->value();
10769 int end_offset = Smi::cast(get(i + kRangeEndIndex))->value(); 10748 int end_offset = Smi::cast(get(i + kRangeEndIndex))->value();
10770 int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value(); 10749 int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value();
10771 int handler_offset = HandlerOffsetField::decode(handler_field); 10750 int handler_offset = HandlerOffsetField::decode(handler_field);
10772 CatchPrediction prediction = HandlerPredictionField::decode(handler_field); 10751 CatchPrediction prediction = HandlerPredictionField::decode(handler_field);
10773 int stack_depth = Smi::cast(get(i + kRangeDepthIndex))->value(); 10752 int stack_depth = Smi::cast(get(i + kRangeDepthIndex))->value();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
10813 #endif 10792 #endif
10814 10793
10815 10794
10816 bool String::LooksValid() { 10795 bool String::LooksValid() {
10817 if (!GetIsolate()->heap()->Contains(this)) return false; 10796 if (!GetIsolate()->heap()->Contains(this)) return false;
10818 return true; 10797 return true;
10819 } 10798 }
10820 10799
10821 10800
10822 // static 10801 // static
10823 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) { 10802 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name,
10824 if (name->IsString()) return Handle<String>::cast(name); 10803 Handle<String> prefix) {
10825 // ES6 section 9.2.11 SetFunctionName, step 4. 10804 // ES6 section 9.2.11 SetFunctionName, step 4.
10826 Isolate* const isolate = name->GetIsolate(); 10805 Isolate* const isolate = name->GetIsolate();
10827 Handle<Object> description(Handle<Symbol>::cast(name)->name(), isolate);
10828 if (description->IsUndefined()) return isolate->factory()->empty_string();
10829 IncrementalStringBuilder builder(isolate); 10806 IncrementalStringBuilder builder(isolate);
10830 builder.AppendCharacter('['); 10807 if (prefix->length() != 0) {
10831 builder.AppendString(Handle<String>::cast(description)); 10808 builder.AppendString(prefix);
10832 builder.AppendCharacter(']'); 10809 builder.AppendCharacter(' ');
10810 }
10811 if (name->IsString()) {
10812 builder.AppendString(Handle<String>::cast(name));
10813 } else {
10814 Handle<Object> description(Handle<Symbol>::cast(name)->name(), isolate);
10815 if (!description->IsUndefined()) {
10816 builder.AppendCharacter('[');
10817 builder.AppendString(Handle<String>::cast(description));
10818 builder.AppendCharacter(']');
10819 }
10820 }
10833 return builder.Finish(); 10821 return builder.Finish();
10834 } 10822 }
10835 10823
10836 10824
10837 namespace { 10825 namespace {
10838 10826
10839 bool AreDigits(const uint8_t* s, int from, int to) { 10827 bool AreDigits(const uint8_t* s, int from, int to) {
10840 for (int i = from; i < to; i++) { 10828 for (int i = from; i < to; i++) {
10841 if (s[i] < '0' || s[i] > '9') return false; 10829 if (s[i] < '0' || s[i] > '9') return false;
10842 } 10830 }
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after
12816 case JS_SET_ITERATOR_TYPE: 12804 case JS_SET_ITERATOR_TYPE:
12817 case JS_MAP_ITERATOR_TYPE: 12805 case JS_MAP_ITERATOR_TYPE:
12818 case JS_ITERATOR_RESULT_TYPE: 12806 case JS_ITERATOR_RESULT_TYPE:
12819 case JS_WEAK_MAP_TYPE: 12807 case JS_WEAK_MAP_TYPE:
12820 case JS_WEAK_SET_TYPE: 12808 case JS_WEAK_SET_TYPE:
12821 case JS_PROMISE_TYPE: 12809 case JS_PROMISE_TYPE:
12822 case JS_REGEXP_TYPE: 12810 case JS_REGEXP_TYPE:
12823 case JS_FUNCTION_TYPE: 12811 case JS_FUNCTION_TYPE:
12824 return true; 12812 return true;
12825 12813
12814 case JS_BOUND_FUNCTION_TYPE:
12826 case JS_PROXY_TYPE: 12815 case JS_PROXY_TYPE:
12827 case JS_GLOBAL_PROXY_TYPE: 12816 case JS_GLOBAL_PROXY_TYPE:
12828 case JS_GLOBAL_OBJECT_TYPE: 12817 case JS_GLOBAL_OBJECT_TYPE:
12829 case FIXED_ARRAY_TYPE: 12818 case FIXED_ARRAY_TYPE:
12830 case FIXED_DOUBLE_ARRAY_TYPE: 12819 case FIXED_DOUBLE_ARRAY_TYPE:
12831 case ODDBALL_TYPE: 12820 case ODDBALL_TYPE:
12832 case FOREIGN_TYPE: 12821 case FOREIGN_TYPE:
12833 case MAP_TYPE: 12822 case MAP_TYPE:
12834 case CODE_TYPE: 12823 case CODE_TYPE:
12835 case CELL_TYPE: 12824 case CELL_TYPE:
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
13084 builder.AppendCString("() { [native code] }"); 13073 builder.AppendCString("() { [native code] }");
13085 return builder.Finish().ToHandleChecked(); 13074 return builder.Finish().ToHandleChecked();
13086 } 13075 }
13087 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource); 13076 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource);
13088 } 13077 }
13089 13078
13090 } // namespace 13079 } // namespace
13091 13080
13092 13081
13093 // static 13082 // static
13083 Handle<String> JSBoundFunction::ToString(Handle<JSBoundFunction> function) {
13084 Isolate* const isolate = function->GetIsolate();
13085 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource);
13086 }
13087
13088
13089 // static
13094 Handle<String> JSFunction::ToString(Handle<JSFunction> function) { 13090 Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
13095 Isolate* const isolate = function->GetIsolate(); 13091 Isolate* const isolate = function->GetIsolate();
13096 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate); 13092 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate);
13097 13093
13098 // Check if {function} should hide its source code. 13094 // Check if {function} should hide its source code.
13099 if (!shared_info->script()->IsScript() || 13095 if (!shared_info->script()->IsScript() ||
13100 Script::cast(shared_info->script())->hide_source()) { 13096 Script::cast(shared_info->script())->hide_source()) {
13101 return NativeCodeFunctionSourceString(shared_info); 13097 return NativeCodeFunctionSourceString(shared_info);
13102 } 13098 }
13103 13099
(...skipping 6351 matching lines...) Expand 10 before | Expand all | Expand 10 after
19455 if (cell->value() != *new_value) { 19451 if (cell->value() != *new_value) {
19456 cell->set_value(*new_value); 19452 cell->set_value(*new_value);
19457 Isolate* isolate = cell->GetIsolate(); 19453 Isolate* isolate = cell->GetIsolate();
19458 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19454 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19459 isolate, DependentCode::kPropertyCellChangedGroup); 19455 isolate, DependentCode::kPropertyCellChangedGroup);
19460 } 19456 }
19461 } 19457 }
19462 19458
19463 } // namespace internal 19459 } // namespace internal
19464 } // namespace v8 19460 } // namespace v8
OLDNEW
« src/json-stringifier.h ('K') | « src/objects.h ('k') | src/objects-body-descriptors-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698