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

Side by Side Diff: runtime/lib/object.cc

Issue 21049012: Update VM to handle malformed types according to revised spec (issues 9055, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | « runtime/lib/map_patch.dart ('k') | runtime/vm/class_finalizer.h » ('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/heap.h" 8 #include "vm/heap.h"
9 #include "vm/native_entry.h" 9 #include "vm/native_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const AbstractTypeArguments& instantiator_type_arguments = 108 const AbstractTypeArguments& instantiator_type_arguments =
109 AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(2)); 109 AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(2));
110 const AbstractType& type = 110 const AbstractType& type =
111 AbstractType::CheckedHandle(arguments->NativeArgAt(3)); 111 AbstractType::CheckedHandle(arguments->NativeArgAt(3));
112 const Bool& negate = Bool::CheckedHandle(arguments->NativeArgAt(4)); 112 const Bool& negate = Bool::CheckedHandle(arguments->NativeArgAt(4));
113 ASSERT(type.IsFinalized()); 113 ASSERT(type.IsFinalized());
114 Error& malformed_error = Error::Handle(); 114 Error& malformed_error = Error::Handle();
115 const bool is_instance_of = instance.IsInstanceOf(type, 115 const bool is_instance_of = instance.IsInstanceOf(type,
116 instantiator_type_arguments, 116 instantiator_type_arguments,
117 &malformed_error); 117 &malformed_error);
118 if (FLAG_trace_type_checks) {
119 const char* result_str = is_instance_of ? "true" : "false";
120 OS::Print("Object.instanceOf: result %s\n", result_str);
121 const Type& instance_type = Type::Handle(instance.GetType());
122 OS::Print(" instance type: %s\n",
123 String::Handle(instance_type.Name()).ToCString());
124 OS::Print(" test type: %s\n", String::Handle(type.Name()).ToCString());
125 if (!malformed_error.IsNull()) {
126 OS::Print(" malformed error: %s\n", malformed_error.ToErrorCString());
127 }
128 }
118 if (!is_instance_of && !malformed_error.IsNull()) { 129 if (!is_instance_of && !malformed_error.IsNull()) {
119 // Throw a dynamic type error only if the instanceof test fails. 130 // Throw a dynamic type error only if the instanceof test fails.
120 DartFrameIterator iterator; 131 DartFrameIterator iterator;
121 StackFrame* caller_frame = iterator.NextFrame(); 132 StackFrame* caller_frame = iterator.NextFrame();
122 ASSERT(caller_frame != NULL); 133 ASSERT(caller_frame != NULL);
123 const intptr_t location = caller_frame->GetTokenPos(); 134 const intptr_t location = caller_frame->GetTokenPos();
124 String& malformed_error_message = String::Handle( 135 String& malformed_error_message = String::Handle(
125 String::New(malformed_error.ToErrorCString())); 136 String::New(malformed_error.ToErrorCString()));
126 Exceptions::CreateAndThrowTypeError( 137 Exceptions::CreateAndThrowTypeError(
127 location, Symbols::Empty(), Symbols::Empty(), 138 location, Symbols::Empty(), Symbols::Empty(),
128 Symbols::Empty(), malformed_error_message); 139 Symbols::Empty(), malformed_error_message);
129 UNREACHABLE(); 140 UNREACHABLE();
130 } 141 }
131
132 if (FLAG_trace_type_checks) {
133 const char* result_str = is_instance_of ? "true" : "false";
134 OS::Print("Object.instanceOf: result %s\n", result_str);
135 const Class& instance_class = Class::Handle(instance.clazz());
136 OS::Print(" instance [class: %s]\n",
137 String::Handle(instance_class.Name()).ToCString());
138 OS::Print(" test-type [class: %s]\n",
139 String::Handle(Class::Handle(type.type_class()).Name()).ToCString());
140 OS::Print(" type-args %s\n", instantiator_type_arguments.ToCString());
141 }
142 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of); 142 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of);
143 } 143 }
144 144
145 145
146 DEFINE_NATIVE_ENTRY(Object_as, 4) { 146 DEFINE_NATIVE_ENTRY(Object_as, 4) {
147 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); 147 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
148 // Instantiator at position 1 is not used. It is passed along so that the call 148 // Instantiator at position 1 is not used. It is passed along so that the call
149 // can be easily converted to an optimized implementation. Instantiator is 149 // can be easily converted to an optimized implementation. Instantiator is
150 // used to populate the subtype cache. 150 // used to populate the subtype cache.
151 const AbstractTypeArguments& instantiator_type_arguments = 151 const AbstractTypeArguments& instantiator_type_arguments =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 201 }
202 202
203 203
204 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { 204 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) {
205 const AbstractType& type = 205 const AbstractType& type =
206 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); 206 AbstractType::CheckedHandle(arguments->NativeArgAt(0));
207 return type.UserVisibleName(); 207 return type.UserVisibleName();
208 } 208 }
209 209
210 } // namespace dart 210 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/map_patch.dart ('k') | runtime/vm/class_finalizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698