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

Unified Diff: runtime/lib/object.cc

Issue 11694003: In unoptimized code use call for instanceof instead of inlined checks. This allows us to collect ty… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/object_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/object.cc
===================================================================
--- runtime/lib/object.cc (revision 16586)
+++ runtime/lib/object.cc (working copy)
@@ -7,6 +7,8 @@
#include "vm/exceptions.h"
#include "vm/native_entry.h"
#include "vm/object.h"
+#include "vm/stack_frame.h"
+#include "vm/symbols.h"
namespace dart {
@@ -63,6 +65,43 @@
}
+
+DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) {
+ const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
+ // Instantiator at position 1 is not used. It is passed along so that the call
+ // can be easily converted to an optimized implementation. Instantiator is
+ // used to populate the subtype cache.
+ const AbstractTypeArguments& instantiator_type_arguments =
+ AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(2));
+ const AbstractType& type =
+ AbstractType::CheckedHandle(arguments->NativeArgAt(3));
+ const Bool& negate = Bool::CheckedHandle(arguments->NativeArgAt(4));
+ ASSERT(type.IsFinalized());
+ Error& malformed_error = Error::Handle();
+ const bool is_instance_of = instance.IsInstanceOf(type,
+ instantiator_type_arguments,
+ &malformed_error);
+ if (!is_instance_of && !malformed_error.IsNull()) {
+ // Throw a dynamic type error only if the instanceof test fails.
+ DartFrameIterator iterator;
+ StackFrame* caller_frame = iterator.NextFrame();
+ ASSERT(caller_frame != NULL);
+ const intptr_t location = caller_frame->GetTokenPos();
+ String& malformed_error_message = String::Handle(
+ String::New(malformed_error.ToErrorCString()));
+ Exceptions::CreateAndThrowTypeError(
+ location, Symbols::Empty(), Symbols::Empty(),
+ Symbols::Empty(), malformed_error_message);
+ UNREACHABLE();
+ }
+ if (negate.value()) {
+ return is_instance_of ? Bool::False() : Bool::True();
+ } else {
+ return is_instance_of ? Bool::True() : Bool::False();
+ }
+}
+
+
DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) {
const AbstractType& type =
AbstractType::CheckedHandle(arguments->NativeArgAt(0));
« no previous file with comments | « no previous file | runtime/lib/object_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698