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

Unified Diff: pkg/compiler/lib/src/native/behavior.dart

Issue 1074043003: Compute default throws behavior from JavaScript. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | pkg/compiler/lib/src/native/js.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/native/behavior.dart
diff --git a/pkg/compiler/lib/src/native/behavior.dart b/pkg/compiler/lib/src/native/behavior.dart
index 3898e7db765a7aab6f209b34e31f53cf85089da3..9f825de381c324302e01e65ad72c6238acfae0d6 100644
--- a/pkg/compiler/lib/src/native/behavior.dart
+++ b/pkg/compiler/lib/src/native/behavior.dart
@@ -29,6 +29,8 @@ class NativeThrowBehavior {
final int _bits;
const NativeThrowBehavior._(this._bits);
+ bool get canThrow => this != NEVER;
+
String toString() {
if (this == NEVER) return 'never';
if (this == MAY) return 'may';
@@ -87,17 +89,31 @@ class NativeBehavior {
bool isAllocation = false;
bool useGvn = false;
+ // TODO(sra): Make NativeBehavior immutable so PURE and PURE_ALLOCATION can be
+ // final constant-like objects.
+ static NativeBehavior get PURE => NativeBehavior._makePure();
+ static NativeBehavior get PURE_ALLOCATION =>
+ NativeBehavior._makePure(isAllocation: true);
+
String toString() {
return 'NativeBehavior('
- 'returns: ${typesReturned}, '
- 'creates: ${typesInstantiated}, '
- 'sideEffects: ${sideEffects}, '
- 'throws: ${throwBehavior}'
+ 'returns: ${typesReturned}'
+ ', creates: ${typesInstantiated}'
+ ', sideEffects: ${sideEffects}'
+ ', throws: ${throwBehavior}'
'${isAllocation ? ", isAllocation" : ""}'
'${useGvn ? ", useGvn" : ""}'
')';
}
+ static NativeBehavior _makePure({bool isAllocation: false}) {
+ NativeBehavior behavior = new NativeBehavior();
+ behavior.sideEffects.clearAllDependencies();
+ behavior.sideEffects.clearAllSideEffects();
+ behavior.throwBehavior = NativeThrowBehavior.NEVER;
+ behavior.isAllocation = isAllocation;
+ return behavior;
+ }
/// Processes the type specification string of a call to JS and stores the
/// result in the [typesReturned] and [typesInstantiated]. It furthermore
@@ -470,6 +486,10 @@ class NativeBehavior {
new SideEffectsVisitor(behavior.sideEffects)
.visit(behavior.codeTemplate.ast);
}
+ if (!throwBehaviorFromSpecString) {
+ behavior.throwBehavior =
+ new ThrowBehaviorVisitor().analyze(behavior.codeTemplate.ast);
+ }
return behavior;
}
@@ -528,6 +548,13 @@ class NativeBehavior {
objectType: compiler.objectClass.computeType(compiler),
nullType: compiler.nullClass.computeType(compiler));
+ // Embedded globals are usually pre-computed data structures or JavaScript
+ // functions that never change.
+ // TODO(sra): Allow the use site to override these defaults.
+ behavior.sideEffects.clearAllDependencies();
+ behavior.sideEffects.clearAllSideEffects();
+ behavior.throwBehavior = NativeThrowBehavior.NEVER;
+
return behavior;
}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/native/js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698