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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart

Issue 27524003: Generate tear-off closures dynamically. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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: dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart b/dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart
index d90caf63373636f2e0ee95f1f3658d0f6354a149..923fd838ee02ebf98d5b2412d842ea0c6c97583b 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart
@@ -4,8 +4,21 @@
part of dart2js.js_emitter;
+// TODO(ahe): Share these with js_helper.dart.
+const FUNCTION_INDEX = 0;
+const NAME_INDEX = 1;
+const CALL_NAME_INDEX = 2;
+const REQUIRED_PARAMETER_INDEX = 3;
+const OPTIONAL_PARAMETER_INDEX = 4;
+const DEFAULT_ARGUMENTS_INDEX = 5;
+
// TODO(ahe): This code should be integrated in CodeEmitterTask.finishClasses.
-String getReflectionDataParser(String classesCollector, Namer namer) {
+String getReflectionDataParser(String classesCollector,
+ JavaScriptBackend backend) {
+ Namer namer = backend.namer;
+ Compiler compiler = backend.compiler;
+ Element closureFromTearOff =
+ compiler.findHelper(const SourceString('closureFromTearOff'));
String metadataField = '"${namer.metadataField}"';
String reflectableField = namer.reflectableField;
String defaultValuesField = namer.defaultValuesField;
@@ -80,6 +93,8 @@ String getReflectionDataParser(String classesCollector, Namer namer) {
globalObject[previousProperty = property] = element;
functions.push(property);
init.globalFunctions[property] = element;
+ } else if (element.constructor === Array) {
+ addStubs(globalObject, element, property, true);
} else {
previousProperty = property;
var newDesc = {};
@@ -103,7 +118,12 @@ String getReflectionDataParser(String classesCollector, Namer namer) {
}
optionalMethods[prop] = previousProp;
} else {
- newDesc[previousProp = prop] = element[prop];
+ var elem = element[prop];
+ if (elem != null && elem.constructor === Array) {
+ addStubs(newDesc, elem, prop, false);
+ } else {
+ newDesc[previousProp = prop] = elem;
+ }
}
}
$classesCollector[property] = [globalObject, newDesc];
@@ -115,5 +135,28 @@ String getReflectionDataParser(String classesCollector, Namer namer) {
libraries.push([name, uri, classes, functions, metadata, fields, isRoot,
globalObject]);
}
+ function addStubs(descriptor, array, name, isStatic) {
+ descriptor[name] = array[0];
+ var getterStubName = array[1];
+ if (getterStubName != null) {
+ print("Patching getter stub " + getterStubName + " " + !!isStatic);
+ descriptor[getterStubName] = tearOff(array, isStatic);
+ }
+ var index = $DEFAULT_ARGUMENTS_INDEX + array[$OPTIONAL_PARAMETER_INDEX];
+ while (index < array.length) {
+ var stub = array[index++];
+ if (typeof stub != "function") break;
+ var stubName = array[index++];
+ print("Patching stub " + stubName + " " + !!isStatic);
+ index++''' // Skip "call" stub.
+''';
+ descriptor[stubName] = stub;
+ }
+ }
+ function tearOff(array, isStatic) {
+ return function() {
+ return ${namer.isolateAccess(closureFromTearOff)}(this, array, isStatic);
+ }
+ }
})''';
}

Powered by Google App Engine
This is Rietveld 408576698