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

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

Issue 125033003: Version 1.1.0-dev.5.1 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 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
===================================================================
--- dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart (revision 31466)
+++ dart/sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart (working copy)
@@ -18,12 +18,21 @@
Namer namer = backend.namer;
Compiler compiler = backend.compiler;
Element closureFromTearOff = compiler.findHelper('closureFromTearOff');
- String tearOffAccess =
- // Default value for mocked-up test libraries.
- 'function () { throw "Helper \'closureFromTearOff\' missing." }';
+ String tearOffAccess;
+ String tearOffGlobalObjectName;
+ String tearOffGlobalObject;
if (closureFromTearOff != null) {
tearOffAccess = namer.isolateAccess(closureFromTearOff);
+ tearOffGlobalObjectName = tearOffGlobalObject =
+ namer.globalObjectFor(closureFromTearOff);
+ } else {
+ // Default values for mocked-up test libraries.
+ tearOffAccess =
+ 'function() { throw "Helper \'closureFromTearOff\' missing." }';
+ tearOffGlobalObjectName = 'MissingHelperFunction';
+ tearOffGlobalObject = '($tearOffAccess())';
}
+
String metadataField = '"${namer.metadataField}"';
String reflectableField = namer.reflectableField;
@@ -83,11 +92,13 @@
var optionalParameterInfo = ${readInt("array", "1")};
var optionalParameterCount = optionalParameterInfo >> 1;
var optionalParametersAreNamed = (optionalParameterInfo & 1) === 1;
+ var isIntercepted =''' // Break long line.
+ ''' requiredParameterCount + optionalParameterCount != funcs[0].length;
var functionTypeIndex = ${readFunctionType("array", "2")};
var isReflectable =''' // Break long line.
''' array.length > requiredParameterCount + optionalParameterCount + 3;
if (getterStubName) {
- f = tearOff(funcs, array, isStatic, name);
+ f = tearOff(funcs, array, isStatic, name, isIntercepted);
'''
/* Used to create an isolate using spawnFunction.*/
'''
@@ -129,15 +140,56 @@
''';
String tearOff = '''
- function tearOff(funcs, reflectionInfo, isStatic, name) {
- return function() {
- return $tearOffAccess(''' // Break long line.
- '''this, funcs, reflectionInfo, isStatic, arguments, name);
- }
+ function tearOffGetterNoCsp(funcs, reflectionInfo, name, isIntercepted) {
+ return isIntercepted
+ ? new Function("funcs", "reflectionInfo", "name",''' // Break long line.
+ ''' "$tearOffGlobalObjectName", "c",
+ "return function tearOff_" + name + (functionCounter++)+ "(x) {" +
+ "if (c === null) c = $tearOffAccess(" +
+ "this, funcs, reflectionInfo, false, [x], name);" +
+ "return new c(this, funcs[0], x, name);" +
+ "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null)
+ : new Function("funcs", "reflectionInfo", "name",''' // Break long line.
+ ''' "$tearOffGlobalObjectName", "c",
+ "return function tearOff_" + name + (functionCounter++)+ "() {" +
+ "if (c === null) c = $tearOffAccess(" +
+ "this, funcs, reflectionInfo, false, [], name);" +
+ "return new c(this, funcs[0], null, name);" +
+ "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null)
}
+ function tearOffGetterCsp(funcs, reflectionInfo, name, isIntercepted) {
+ var cache = null;
+ return isIntercepted
+ ? function(x) {
+ if (cache === null) cache = $tearOffAccess(''' // Break long line.
+ '''this, funcs, reflectionInfo, false, [x], name);
+ return new cache(this, funcs[0], x, name)
+ }
+ : function() {
+ if (cache === null) cache = $tearOffAccess(''' // Break long line.
+ '''this, funcs, reflectionInfo, false, [], name);
+ return new cache(this, funcs[0], null, name)
+ }
+ }
+ function tearOff(funcs, reflectionInfo, isStatic, name, isIntercepted) {
+ var cache;
+ return isStatic
+ ? function() {
+ if (cache === void 0) cache = $tearOffAccess(''' // Break long line.
+ '''this, funcs, reflectionInfo, true, [], name).prototype;
+ return cache;
+ }
+ : tearOffGetter(funcs, reflectionInfo, name, isIntercepted);
+ }
''';
+
+
+
String init = '''
+ var functionCounter = 0;
+ var tearOffGetter = (typeof dart_precompiled == "function")
+ ? tearOffGetterCsp : tearOffGetterNoCsp;
if (!init.libraries) init.libraries = [];
if (!init.mangledNames) init.mangledNames = map();
if (!init.mangledGlobalNames) init.mangledGlobalNames = map();

Powered by Google App Engine
This is Rietveld 408576698