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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart

Issue 1123343008: Implement raw list checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update test expectations. Created 5 years, 7 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 | « pkg/compiler/lib/src/js_backend/codegen/glue.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart b/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
index 4a697a4239e19698361e844763578515a01f370f..959756f8e5b9316ec282a68116594432a46120f3 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
@@ -32,13 +32,28 @@ abstract class TypeTestEmitter {
}
}
+ js.Expression _emitNativeListCheck(js.Expression value) {
+ return identical(
sra1 2015/05/13 19:17:00 This would be simpler and not need helper function
+ new js.PropertyAccess.field(value, 'constructor'),
+ new js.VariableUse('Array'));
+ }
+
+ js.Expression emitPropertyTypeTest(tree_ir.Node node,
+ js.Expression value,
+ InterfaceType type) {
+ return and(
+ boolify(value),
+ boolify(new js.PropertyAccess.field(value, glue.getTypeTestTag(type))));
+ }
+
js.Expression emitGeneralSubtypeTest(tree_ir.Node node,
js.Expression value,
InterfaceType type) {
- return new js.Binary('&&',
- new js.Prefix('!!', value),
- new js.Prefix('!!',
- new js.PropertyAccess.field(value, glue.getTypeTestTag(type))));
+ if (glue.isListClass(type.element)) {
+ return or(_emitNativeListCheck(value),
+ emitPropertyTypeTest(node, value, type));
+ }
+ return emitPropertyTypeTest(node, value, type);
}
js.Expression _emitNumCheck(js.Expression value) {
@@ -50,14 +65,28 @@ abstract class TypeTestEmitter {
}
js.Expression _emitIntCheck(js.Expression value) {
- return new js.Binary('&&',
- _emitNumCheck(value),
- _emitBigIntCheck(value));
+ return and(_emitNumCheck(value), _emitBigIntCheck(value));
}
js.Expression _emitTypeofCheck(js.Expression value, String type) {
- return new js.Binary('===',
- new js.Prefix("typeof", value),
- js.string(type));
+ return identical(new js.Prefix("typeof", value), js.string(type));
+ }
+
+ // Static helpers to generate common JavaScript expressions.
+
+ static js.Expression or(js.Expression left, js.Expression right) {
+ return new js.Binary('||', left, right);
+ }
+
+ static js.Expression and(js.Expression left, js.Expression right) {
+ return new js.Binary('&&', left, right);
+ }
+
+ static js.Expression identical(js.Expression left, js.Expression right) {
+ return new js.Binary('===', left, right);
+ }
+
+ static js.Expression boolify(js.Expression value) {
+ return new js.Prefix('!!', value);
}
-}
+}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/glue.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698