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

Unified Diff: src/ic.cc

Issue 1604: Fix issue http://code.google.com/p/v8/issues/detail?id=32... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years, 3 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
Index: src/ic.cc
===================================================================
--- src/ic.cc (revision 184)
+++ src/ic.cc (working copy)
@@ -250,6 +250,26 @@
}
+Object* CallIC::TryCallAsFunction(Object* object) {
+ HandleScope scope;
+ Handle<Object> target(object);
+ Handle<Object> delegate = Execution::GetFunctionDelegate(target);
+
+ if (delegate->IsJSFunction()) {
+ // Patch the receiver and use the delegate as the function to
+ // invoke. This is used for invoking objects as if they were
+ // functions.
+ const int argc = this->target()->arguments_count();
+ StackFrameLocator locator;
+ JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
+ int index = frame->ComputeExpressionsCount() - (argc + 1);
+ frame->SetExpression(index, *target);
+ }
+
+ return *delegate;
+}
+
+
Object* CallIC::LoadFunction(State state,
Handle<Object> object,
Handle<String> name) {
@@ -259,12 +279,24 @@
return TypeError("non_object_property_call", object, name);
}
+ Object* result = Heap::the_hole_value();
+
+ // Check if the name is trivially convertible to an index and get
+ // the element if so.
+ uint32_t index;
+ if (name->AsArrayIndex(&index)) {
+ result = object->GetElement(index);
+ if (result->IsJSFunction()) return result;
+
+ // Try to find a suitable function delegate for the object at hand.
+ result = TryCallAsFunction(result);
+ if (result->IsJSFunction()) return result;
Kasper Lund 2008/09/08 05:27:21 Do you really want to continue with a doing a norm
Feng Qian 2008/09/08 18:58:48 It will fail in lookup step, a comment is sufficie
+ }
+
// Lookup the property in the object.
LookupResult lookup;
object->Lookup(*name, &lookup);
- Object* result = Heap::the_hole_value();
-
if (!lookup.IsValid()) {
// If the object does not have the requested property, check which
// exception we need to throw.
@@ -328,23 +360,9 @@
}
// Try to find a suitable function delegate for the object at hand.
- HandleScope scope;
- Handle<Object> target(result);
- Handle<Object> delegate = Execution::GetFunctionDelegate(target);
-
- if (delegate->IsJSFunction()) {
- // Patch the receiver and use the delegate as the function to
- // invoke. This is used for invoking objects as if they were
- // functions.
- const int argc = this->target()->arguments_count();
- StackFrameLocator locator;
- JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
- int index = frame->ComputeExpressionsCount() - (argc + 1);
- frame->SetExpression(index, *target);
- return *delegate;
- } else {
- return TypeError("property_not_function", object, name);
- }
+ result = TryCallAsFunction(result);
+ return result->IsJSFunction() ?
+ result : TypeError("property_not_function", object, name);
Kasper Lund 2008/09/08 05:27:21 Isn't this usually indented with 4 spaces? I can't
Feng Qian 2008/09/08 18:58:48 Done.
}

Powered by Google App Engine
This is Rietveld 408576698