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

Unified Diff: src/objects.cc

Issue 1871503002: Lazily compute boundfunction .name and .length if possible (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 36d6ea870c493945536ed49df2ee99917782442b..b6070aaf12784d0a35a53c146c6b6eb32d1d28d5 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()),
+ isolate);
+ Handle<Object> target_name = JSFunction::GetName(isolate, target);
+ if (!target_name->IsString()) return prefix;
+ Factory* factory = isolate->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) {
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698