Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index 36d6ea870c493945536ed49df2ee99917782442b..c9e6f66a907a5d35e8fdeccd754383ea2817503e 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -1873,15 +1873,7 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) { |
| } |
| case JS_BOUND_FUNCTION_TYPE: { |
| JSBoundFunction* bound_function = JSBoundFunction::cast(this); |
| - Object* name = bound_function->name(); |
| accumulator->Add("<JS BoundFunction"); |
| - if (name->IsString()) { |
| - String* str = String::cast(name); |
| - if (str->length() > 0) { |
| - accumulator->Add(" "); |
| - accumulator->Put(str); |
| - } |
| - } |
| accumulator->Add( |
| " (BoundTargetFunction %p)>", |
| reinterpret_cast<void*>(bound_function->bound_target_function())); |
| @@ -5107,6 +5099,44 @@ MaybeHandle<Context> JSBoundFunction::GetFunctionRealm( |
| handle(function->bound_target_function())); |
| } |
| +// static |
| +MaybeHandle<String> JSBoundFunction::GetName(Isolate* isolate, |
| + Handle<JSBoundFunction> function) { |
| + Handle<String> prefix = isolate->factory()->bound__string(); |
| + if (!function->bound_target_function()->IsJSFunction()) return prefix; |
| + Handle<JSFunction> target( |
| + JSFunction::cast(function->bound_target_function())); |
|
Camillo Bruni
2016/04/07 13:04:20
nit: use isolate
|
| + Handle<Object> target_name = JSFunction::GetName(isolate, target); |
| + if (!target_name->IsString()) return prefix; |
| + Factory* factory = isolate->factory(); |
|
Camillo Bruni
2016/04/07 13:04:20
nit: no need for factory.
|
| + return factory->NewConsString(prefix, Handle<String>::cast(target_name)); |
| +} |
| + |
| +// static |
| +Handle<Object> JSFunction::GetName(Isolate* isolate, |
| + Handle<JSFunction> function) { |
| + if (function->shared()->name_should_print_as_anonymous()) { |
| + return isolate->factory()->anonymous_string(); |
| + } |
| + return handle(function->shared()->name(), isolate); |
| +} |
| + |
| +// static |
| +MaybeHandle<Smi> JSFunction::GetLength(Isolate* isolate, |
| + Handle<JSFunction> function) { |
| + int length = 0; |
| + if (function->shared()->is_compiled()) { |
| + length = function->shared()->length(); |
| + } else { |
| + // If the function isn't compiled yet, the length is not computed |
| + // correctly yet. Compile it now and return the right length. |
| + if (Compiler::Compile(function, Compiler::KEEP_EXCEPTION)) { |
| + length = function->shared()->length(); |
| + } |
| + if (isolate->has_pending_exception()) return MaybeHandle<Smi>(); |
| + } |
| + return handle(Smi::FromInt(length), isolate); |
| +} |
| // static |
| Handle<Context> JSFunction::GetFunctionRealm(Handle<JSFunction> function) { |