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

Unified Diff: runtime/vm/code_generator_ia32.cc

Issue 9615035: Generate dynamic type errors according to spec. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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: runtime/vm/code_generator_ia32.cc
===================================================================
--- runtime/vm/code_generator_ia32.cc (revision 5060)
+++ runtime/vm/code_generator_ia32.cc (working copy)
@@ -1314,7 +1314,9 @@
// All instances are of a subtype of the Object type.
const Type& object_type =
Type::Handle(Isolate::Current()->object_store()->object_type());
- if (type.IsInstantiated() && object_type.IsSubtypeOf(type)) {
+ Error& malformed_error = Error::Handle();
+ if (type.IsInstantiated() &&
+ object_type.IsSubtypeOf(type, &malformed_error)) {
__ PushObject(negate_result ? bool_false : bool_true);
return;
}
@@ -1383,9 +1385,11 @@
// Object is Smi.
const Class& smi_class = Class::Handle(Smi::Class());
// TODO(regis): We should introduce a SmiType.
+ Error& malformed_error = Error::Handle();
if (smi_class.IsSubtypeOf(TypeArguments::Handle(),
type_class,
- TypeArguments::Handle())) {
+ TypeArguments::Handle(),
+ &malformed_error)) {
__ PushObject(negate_result ? bool_false : bool_true);
} else {
__ PushObject(negate_result ? bool_true : bool_false);
@@ -1416,6 +1420,9 @@
}
}
__ PushObject(Object::ZoneHandle()); // Make room for the result.
+ const Immediate location =
+ Immediate(reinterpret_cast<int32_t>(Smi::New(token_index)));
+ __ pushl(location); // Push the source location.
__ pushl(EAX); // Push the instance.
__ PushObject(type); // Push the type.
if (!type.IsInstantiated()) {
@@ -1426,7 +1433,7 @@
GenerateCallRuntime(node_id, token_index, kInstanceofRuntimeEntry);
// Pop the two parameters supplied to the runtime entry. The result of the
// instanceof runtime call will be left as the result of the operation.
- __ addl(ESP, Immediate(3 * kWordSize));
+ __ addl(ESP, Immediate(4 * kWordSize));
if (negate_result) {
Label negate_done;
__ popl(EDX);
@@ -1468,23 +1475,6 @@
ASSERT(!dst_type.IsNull());
ASSERT(dst_type.IsFinalized());
- // Generate throw new TypeError() if the type is malformed.
- if (dst_type.IsMalformed()) {
- const Error& error = Error::Handle(dst_type.malformed_error());
- const String& error_message = String::ZoneHandle(
- String::NewSymbol(error.ToErrorCString()));
- __ PushObject(Object::ZoneHandle()); // Make room for the result.
- const Immediate location =
- Immediate(reinterpret_cast<int32_t>(Smi::New(token_index)));
- __ pushl(location); // Push the source location.
- __ pushl(EAX); // Push the source object.
- __ PushObject(error_message);
- GenerateCallRuntime(node_id, token_index, kMalformedTypeErrorRuntimeEntry);
- // We should never return here.
- __ int3();
- return;
- }
-
// Any expression is assignable to the Dynamic type and to the Object type.
// Skip the test.
if (dst_type.IsDynamicType() || dst_type.IsObjectType()) {
@@ -1500,13 +1490,31 @@
return;
}
- // A NULL object is always assignable and is returned as result.
+ // A null object is always assignable and is returned as result.
const Immediate raw_null =
Immediate(reinterpret_cast<intptr_t>(Object::null()));
Label done, runtime_call;
__ cmpl(EAX, raw_null);
__ j(EQUAL, &done, Assembler::kNearJump);
+ // Generate throw new TypeError() if the type is malformed.
+ if (dst_type.IsMalformed()) {
+ const Error& error = Error::Handle(dst_type.malformed_error());
+ const String& error_message = String::ZoneHandle(
+ String::NewSymbol(error.ToErrorCString()));
+ __ PushObject(Object::ZoneHandle()); // Make room for the result.
+ const Immediate location =
+ Immediate(reinterpret_cast<int32_t>(Smi::New(token_index)));
+ __ pushl(location); // Push the source location.
+ __ pushl(EAX); // Push the source object.
+ __ PushObject(dst_name); // Push the name of the destination.
+ __ PushObject(error_message);
+ GenerateCallRuntime(node_id, token_index, kMalformedTypeErrorRuntimeEntry);
+ // We should never return here.
+ __ int3();
+ return;
+ }
+
// If dst_type is instantiated and non-parameterized, we can inline code
// checking whether the assigned instance is a Smi.
if (dst_type.IsInstantiated()) {
@@ -1544,9 +1552,11 @@
// Object is Smi.
const Class& smi_class = Class::Handle(Smi::Class());
// TODO(regis): We should introduce a SmiType.
+ Error& malformed_error = Error::Handle();
if (smi_class.IsSubtypeOf(TypeArguments::Handle(),
dst_type_class,
- TypeArguments::Handle())) {
+ TypeArguments::Handle(),
+ &malformed_error)) {
// Successful assignable type check: return object in EAX.
__ jmp(&done, Assembler::kNearJump);
} else {
@@ -1563,13 +1573,14 @@
} else {
// However, for specific core library interfaces, we can check for
// specific core library classes.
+ Error& malformed_error = Error::Handle();
if (dst_type.IsBoolInterface()) {
__ movl(ECX, FieldAddress(EAX, Object::class_offset()));
const Class& bool_class = Class::ZoneHandle(
Isolate::Current()->object_store()->bool_class());
TestClassAndJump(bool_class, &done);
} else if (dst_type.IsSubtypeOf(
- Type::Handle(Type::NumberInterface()))) {
+ Type::Handle(Type::NumberInterface()), &malformed_error)) {
__ movl(ECX, FieldAddress(EAX, Object::class_offset()));
if (dst_type.IsIntInterface() || dst_type.IsNumberInterface()) {
// We already checked for Smi above.

Powered by Google App Engine
This is Rietveld 408576698