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

Side by Side 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, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/object_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/stack_frame.h"
11 #include "vm/symbols.h"
10 12
11 namespace dart { 13 namespace dart {
12 14
13 DEFINE_NATIVE_ENTRY(Object_toString, 1) { 15 DEFINE_NATIVE_ENTRY(Object_toString, 1) {
14 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); 16 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
15 const char* c_str = instance.ToCString(); 17 const char* c_str = instance.ToCString();
16 return String::New(c_str); 18 return String::New(c_str);
17 } 19 }
18 20
19 21
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 58 }
57 59
58 60
59 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { 61 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) {
60 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); 62 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
61 const Type& type = Type::Handle(instance.GetType()); 63 const Type& type = Type::Handle(instance.GetType());
62 return type.Canonicalize(); 64 return type.Canonicalize();
63 } 65 }
64 66
65 67
68
69 DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) {
70 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
71 // Instantiator at position 1 is not used. It is passed along so that the call
72 // can be easily converted to an optimized implementation. Instantiator is
73 // used to populate the subtype cache.
74 const AbstractTypeArguments& instantiator_type_arguments =
75 AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(2));
76 const AbstractType& type =
77 AbstractType::CheckedHandle(arguments->NativeArgAt(3));
78 const Bool& negate = Bool::CheckedHandle(arguments->NativeArgAt(4));
79 ASSERT(type.IsFinalized());
80 Error& malformed_error = Error::Handle();
81 const bool is_instance_of = instance.IsInstanceOf(type,
82 instantiator_type_arguments,
83 &malformed_error);
84 if (!is_instance_of && !malformed_error.IsNull()) {
85 // Throw a dynamic type error only if the instanceof test fails.
86 DartFrameIterator iterator;
87 StackFrame* caller_frame = iterator.NextFrame();
88 ASSERT(caller_frame != NULL);
89 const intptr_t location = caller_frame->GetTokenPos();
90 String& malformed_error_message = String::Handle(
91 String::New(malformed_error.ToErrorCString()));
92 Exceptions::CreateAndThrowTypeError(
93 location, Symbols::Empty(), Symbols::Empty(),
94 Symbols::Empty(), malformed_error_message);
95 UNREACHABLE();
96 }
97 if (negate.value()) {
98 return is_instance_of ? Bool::False() : Bool::True();
99 } else {
100 return is_instance_of ? Bool::True() : Bool::False();
101 }
102 }
103
104
66 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { 105 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) {
67 const AbstractType& type = 106 const AbstractType& type =
68 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); 107 AbstractType::CheckedHandle(arguments->NativeArgAt(0));
69 return type.UserVisibleName(); 108 return type.UserVisibleName();
70 } 109 }
71 110
72 } // namespace dart 111 } // namespace dart
OLDNEW
« 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