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

Unified Diff: pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart

Issue 797513004: Emit either csp or non-csp versions of the program. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 6 years 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_emitter/old_emitter/emitter.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart
diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart
index 62841e6bc9b83842748be1d37e763257893fb4a0..550cd71181c6891a643d0e850a9c80feb81332cc 100644
--- a/pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart
+++ b/pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart
@@ -227,8 +227,6 @@ jsAst.Expression getReflectionDataParser(String classesCollector,
jsAst.Statement init = js.statement('''{
var functionCounter = 0;
- var tearOffGetter = (typeof dart_precompiled == "function")
- ? tearOffGetterCsp : tearOffGetterNoCsp;
if (!#) # = []; // embedded libraries.
if (!#) # = map(); // embedded mangledNames.
if (!#) # = map(); // embedded mangledGlobalNames.
@@ -333,44 +331,47 @@ List<jsAst.Statement> buildTearOffCode(JavaScriptBackend backend) {
tearOffGlobalObject = '($tearOffAccessText())';
}
- // This template is uncached because it is constructed from code fragments
- // that can change from compilation to compilation. Some of these could be
- // avoided, except for the string literals that contain the compiled access
- // path to 'closureFromTearOff'.
- jsAst.Statement tearOffGetterNoCsp = js.uncachedStatementTemplate('''
- function tearOffGetterNoCsp(funcs, reflectionInfo, name, isIntercepted) {
- return isIntercepted
- ? new Function("funcs", "reflectionInfo", "name",
- "$tearOffGlobalObjectName", "c",
- "return function tearOff_" + name + (functionCounter++)+ "(x) {" +
- "if (c === null) c = $tearOffAccessText(" +
- "this, funcs, reflectionInfo, false, [x], name);" +
- "return new c(this, funcs[0], x, name);" +
- "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null)
- : new Function("funcs", "reflectionInfo", "name",
- "$tearOffGlobalObjectName", "c",
- "return function tearOff_" + name + (functionCounter++)+ "() {" +
- "if (c === null) c = $tearOffAccessText(" +
- "this, funcs, reflectionInfo, false, [], name);" +
- "return new c(this, funcs[0], null, name);" +
- "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null);
- }''').instantiate([]);
-
- jsAst.Statement tearOffGetterCsp = js.statement('''
- function tearOffGetterCsp(funcs, reflectionInfo, name, isIntercepted) {
- var cache = null;
- return isIntercepted
- ? function(x) {
- if (cache === null) cache = #(
- this, funcs, reflectionInfo, false, [x], name);
- return new cache(this, funcs[0], x, name);
- }
- : function() {
- if (cache === null) cache = #(
- this, funcs, reflectionInfo, false, [], name);
- return new cache(this, funcs[0], null, name);
- };
- }''', [tearOffAccessExpression, tearOffAccessExpression]);
+ jsAst.Statement tearOffGetter;
+ if (!compiler.useContentSecurityPolicy) {
+ // This template is uncached because it is constructed from code fragments
+ // that can change from compilation to compilation. Some of these could be
+ // avoided, except for the string literals that contain the compiled access
+ // path to 'closureFromTearOff'.
+ tearOffGetter = js.uncachedStatementTemplate('''
+ function tearOffGetter(funcs, reflectionInfo, name, isIntercepted) {
+ return isIntercepted
+ ? new Function("funcs", "reflectionInfo", "name",
+ "$tearOffGlobalObjectName", "c",
+ "return function tearOff_" + name + (functionCounter++)+ "(x) {" +
+ "if (c === null) c = $tearOffAccessText(" +
+ "this, funcs, reflectionInfo, false, [x], name);" +
+ "return new c(this, funcs[0], x, name);" +
+ "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null)
+ : new Function("funcs", "reflectionInfo", "name",
+ "$tearOffGlobalObjectName", "c",
+ "return function tearOff_" + name + (functionCounter++)+ "() {" +
+ "if (c === null) c = $tearOffAccessText(" +
+ "this, funcs, reflectionInfo, false, [], name);" +
+ "return new c(this, funcs[0], null, name);" +
+ "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null);
+ }''').instantiate([]);
+ } else {
+ tearOffGetter = js.statement('''
+ function tearOffGetter(funcs, reflectionInfo, name, isIntercepted) {
+ var cache = null;
+ return isIntercepted
+ ? function(x) {
+ if (cache === null) cache = #(
+ this, funcs, reflectionInfo, false, [x], name);
+ return new cache(this, funcs[0], x, name);
+ }
+ : function() {
+ if (cache === null) cache = #(
+ this, funcs, reflectionInfo, false, [], name);
+ return new cache(this, funcs[0], null, name);
+ };
+ }''', [tearOffAccessExpression, tearOffAccessExpression]);
+ }
jsAst.Statement tearOff = js.statement('''
function tearOff(funcs, reflectionInfo, isStatic, name, isIntercepted) {
@@ -384,10 +385,9 @@ List<jsAst.Statement> buildTearOffCode(JavaScriptBackend backend) {
: tearOffGetter(funcs, reflectionInfo, name, isIntercepted);
}''', tearOffAccessExpression);
- return <jsAst.Statement>[tearOffGetterNoCsp, tearOffGetterCsp, tearOff];
+ return <jsAst.Statement>[tearOffGetter, tearOff];
}
-
String readString(String array, String index) {
return readChecked(
array, index, 'result != null && typeof result != "string"', 'string');
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698