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

Side by Side Diff: src/objects.cc

Issue 1540953004: [runtime] Rewrite Function.prototype.toString in C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix typos. Created 5 years 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 13051 matching lines...) Expand 10 before | Expand all | Expand 10 after
13062 13062
13063 Handle<String> JSFunction::GetDebugName(Handle<JSFunction> function) { 13063 Handle<String> JSFunction::GetDebugName(Handle<JSFunction> function) {
13064 Isolate* isolate = function->GetIsolate(); 13064 Isolate* isolate = function->GetIsolate();
13065 Handle<Object> name = JSReceiver::GetDataProperty( 13065 Handle<Object> name = JSReceiver::GetDataProperty(
13066 function, isolate->factory()->display_name_string()); 13066 function, isolate->factory()->display_name_string());
13067 if (name->IsString()) return Handle<String>::cast(name); 13067 if (name->IsString()) return Handle<String>::cast(name);
13068 return JSFunction::GetName(function); 13068 return JSFunction::GetName(function);
13069 } 13069 }
13070 13070
13071 13071
13072 namespace {
13073
13074 char const kNativeCodeSource[] = "function () { [native code] }";
13075
13076
13077 Handle<String> NativeCodeFunctionSourceString(
13078 Handle<SharedFunctionInfo> shared_info) {
13079 Isolate* const isolate = shared_info->GetIsolate();
13080 if (shared_info->name()->IsString()) {
13081 IncrementalStringBuilder builder(isolate);
13082 builder.AppendCString("function ");
13083 builder.AppendString(handle(String::cast(shared_info->name()), isolate));
13084 builder.AppendCString("() { [native code] }");
13085 return builder.Finish().ToHandleChecked();
13086 }
13087 return isolate->factory()->NewStringFromAsciiChecked(kNativeCodeSource);
13088 }
13089
13090 } // namespace
13091
13092
13093 // static
13094 Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
13095 Isolate* const isolate = function->GetIsolate();
13096 Handle<SharedFunctionInfo> shared_info(function->shared(), isolate);
13097
13098 // Check if {function} should hide its source code.
13099 if (!shared_info->script()->IsScript() ||
13100 Script::cast(shared_info->script())->hide_source()) {
13101 return NativeCodeFunctionSourceString(shared_info);
13102 }
13103
13104 // Check if we should print {function} as a class.
13105 Handle<Object> class_start_position = JSReceiver::GetDataProperty(
13106 function, isolate->factory()->class_start_position_symbol());
13107 if (class_start_position->IsSmi()) {
13108 Handle<Object> class_end_position = JSReceiver::GetDataProperty(
13109 function, isolate->factory()->class_end_position_symbol());
13110 Handle<String> script_source(
13111 String::cast(Script::cast(shared_info->script())->source()), isolate);
13112 return isolate->factory()->NewSubString(
13113 script_source, Handle<Smi>::cast(class_start_position)->value(),
13114 Handle<Smi>::cast(class_end_position)->value());
13115 }
13116
13117 // Check if we have source code for the {function}.
13118 if (!shared_info->HasSourceCode()) {
13119 return NativeCodeFunctionSourceString(shared_info);
13120 }
13121
13122 IncrementalStringBuilder builder(isolate);
13123 if (!shared_info->is_arrow()) {
13124 if (shared_info->is_concise_method()) {
13125 if (shared_info->is_generator()) builder.AppendCharacter('*');
13126 } else {
13127 if (shared_info->is_generator()) {
13128 builder.AppendCString("function* ");
13129 } else {
13130 builder.AppendCString("function ");
13131 }
13132 }
13133 if (shared_info->name_should_print_as_anonymous()) {
13134 builder.AppendCString("anonymous");
13135 } else {
13136 builder.AppendString(handle(String::cast(shared_info->name()), isolate));
13137 }
13138 }
13139 builder.AppendString(Handle<String>::cast(shared_info->GetSourceCode()));
13140 return builder.Finish().ToHandleChecked();
13141 }
13142
13143
13072 void Oddball::Initialize(Isolate* isolate, Handle<Oddball> oddball, 13144 void Oddball::Initialize(Isolate* isolate, Handle<Oddball> oddball,
13073 const char* to_string, Handle<Object> to_number, 13145 const char* to_string, Handle<Object> to_number,
13074 const char* type_of, byte kind) { 13146 const char* type_of, byte kind) {
13075 Handle<String> internalized_to_string = 13147 Handle<String> internalized_to_string =
13076 isolate->factory()->InternalizeUtf8String(to_string); 13148 isolate->factory()->InternalizeUtf8String(to_string);
13077 Handle<String> internalized_type_of = 13149 Handle<String> internalized_type_of =
13078 isolate->factory()->InternalizeUtf8String(type_of); 13150 isolate->factory()->InternalizeUtf8String(type_of);
13079 oddball->set_to_number(*to_number); 13151 oddball->set_to_number(*to_number);
13080 oddball->set_to_string(*internalized_to_string); 13152 oddball->set_to_string(*internalized_to_string);
13081 oddball->set_type_of(*internalized_type_of); 13153 oddball->set_type_of(*internalized_type_of);
(...skipping 6301 matching lines...) Expand 10 before | Expand all | Expand 10 after
19383 if (cell->value() != *new_value) { 19455 if (cell->value() != *new_value) {
19384 cell->set_value(*new_value); 19456 cell->set_value(*new_value);
19385 Isolate* isolate = cell->GetIsolate(); 19457 Isolate* isolate = cell->GetIsolate();
19386 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19458 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19387 isolate, DependentCode::kPropertyCellChangedGroup); 19459 isolate, DependentCode::kPropertyCellChangedGroup);
19388 } 19460 }
19389 } 19461 }
19390 19462
19391 } // namespace internal 19463 } // namespace internal
19392 } // namespace v8 19464 } // namespace v8
OLDNEW
« src/debug/mirrors.js ('K') | « src/objects.h ('k') | src/profiler/profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698