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

Side by Side Diff: lib/compiler/implementation/js_backend/native_emitter.dart

Issue 11188004: Add a content-security-policy (CSP) flag. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More fixes. Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class NativeEmitter { 5 class NativeEmitter {
6 6
7 CodeEmitterTask emitter; 7 CodeEmitterTask emitter;
8 CodeBuffer nativeBuffer; 8 CodeBuffer nativeBuffer;
9 9
10 // Classes that participate in dynamic dispatch. These are the 10 // Classes that participate in dynamic dispatch. These are the
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 Element element = compiler.findHelper( 88 Element element = compiler.findHelper(
89 const SourceString('hashCodeForNativeObject')); 89 const SourceString('hashCodeForNativeObject'));
90 return backend.namer.isolateAccess(element); 90 return backend.namer.isolateAccess(element);
91 } 91 }
92 92
93 String get defineNativeClassName 93 String get defineNativeClassName
94 => '${backend.namer.CURRENT_ISOLATE}.\$defineNativeClass'; 94 => '${backend.namer.CURRENT_ISOLATE}.\$defineNativeClass';
95 95
96 String get defineNativeClassFunction { 96 String get defineNativeClassFunction {
97 return """ 97 return """
98 function(cls, fields, methods) { 98 function(cls, desc) {
99 var fields = desc[''] || [];
99 var generateGetterSetter = ${emitter.generateGetterSetterFunction}; 100 var generateGetterSetter = ${emitter.generateGetterSetterFunction};
100 for (var i = 0; i < fields.length; i++) { 101 for (var i = 0; i < fields.length; i++) {
101 generateGetterSetter(fields[i], methods); 102 generateGetterSetter(fields[i], desc);
102 } 103 }
103 for (var method in methods) { 104 var hasOwnProperty = Object.prototype.hasOwnProperty;
104 $dynamicName(method)[cls] = methods[method]; 105 for (var method in desc) {
106 if (method !== '') {
107 if (hasOwnProperty.call(desc, method)) {
108 $dynamicName(method)[cls] = desc[method];
109 }
110 }
105 } 111 }
106 }"""; 112 }""";
107 } 113 }
108 114
109 void generateNativeLiteral(ClassElement classElement) { 115 void generateNativeLiteral(ClassElement classElement) {
110 String quotedNative = classElement.nativeName.slowToString(); 116 String quotedNative = classElement.nativeName.slowToString();
111 String nativeCode = quotedNative.substring(2, quotedNative.length - 1); 117 String nativeCode = quotedNative.substring(2, quotedNative.length - 1);
112 String className = backend.namer.getName(classElement); 118 String className = backend.namer.getName(classElement);
113 nativeBuffer.add(className); 119 nativeBuffer.add(className);
114 nativeBuffer.add(' = '); 120 nativeBuffer.add(' = ');
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 assert(classElement.backendMembers.isEmpty()); 156 assert(classElement.backendMembers.isEmpty());
151 String quotedName = classElement.nativeName.slowToString(); 157 String quotedName = classElement.nativeName.slowToString();
152 if (isNativeLiteral(quotedName)) { 158 if (isNativeLiteral(quotedName)) {
153 generateNativeLiteral(classElement); 159 generateNativeLiteral(classElement);
154 // The native literal kind needs to be dealt with specially when 160 // The native literal kind needs to be dealt with specially when
155 // generating code for it. 161 // generating code for it.
156 return; 162 return;
157 } 163 }
158 164
159 CodeBuffer fieldBuffer = new CodeBuffer(); 165 CodeBuffer fieldBuffer = new CodeBuffer();
160 List<String> checkedSetters = 166 CodeBuffer getterSetterBuffer = new CodeBuffer();
161 emitter.emitClassFields(classElement, fieldBuffer); 167
168 emitter.emitClassFields(classElement, fieldBuffer);
169 emitter.emitClassGettersSetters(classElement, getterSetterBuffer,
170 omitLeadingComma: true);
162 171
163 CodeBuffer methodBuffer = new CodeBuffer(); 172 CodeBuffer methodBuffer = new CodeBuffer();
164 emitter.emitInstanceMembers(classElement, methodBuffer, false); 173 emitter.emitInstanceMembers(classElement, methodBuffer, false);
165 174
166 if (methodBuffer.isEmpty() && fieldBuffer.isEmpty()) return; 175 if (methodBuffer.isEmpty()
176 && fieldBuffer.isEmpty()
177 && getterSetterBuffer.isEmpty()) {
178 return;
179 }
167 180
168 String nativeName = toNativeName(classElement); 181 String nativeName = toNativeName(classElement);
169 nativeBuffer.add("$defineNativeClassName('$nativeName', ["); 182 nativeBuffer.add("$defineNativeClassName('$nativeName', ");
170 nativeBuffer.add(fieldBuffer); 183 nativeBuffer.add('{');
171 nativeBuffer.add('], {'); 184 bool firstInMap = true;
172 if (!checkedSetters.isEmpty()) { 185 if (!fieldBuffer.isEmpty()) {
173 nativeBuffer.add('${Strings.join(checkedSetters, ",\n")}'); 186 firstInMap = false;
174 nativeBuffer.add(',\n'); 187 nativeBuffer.add(fieldBuffer);
175 } 188 }
176 nativeBuffer.add(methodBuffer); 189 if (!getterSetterBuffer.isEmpty()) {
190 if (!firstInMap) nativeBuffer.add(",");
191 firstInMap = false;
192 nativeBuffer.add("\n ");
193 nativeBuffer.add(getterSetterBuffer);
194 }
195 if (!methodBuffer.isEmpty()) {
196 if (!firstInMap) nativeBuffer.add(",");
197 nativeBuffer.add(methodBuffer);
198 }
177 nativeBuffer.add('\n});\n\n'); 199 nativeBuffer.add('\n});\n\n');
178 200
179 classesWithDynamicDispatch.add(classElement); 201 classesWithDynamicDispatch.add(classElement);
180 } 202 }
181 203
182 List<ClassElement> getDirectSubclasses(ClassElement cls) { 204 List<ClassElement> getDirectSubclasses(ClassElement cls) {
183 List<ClassElement> result = directSubtypes[cls]; 205 List<ClassElement> result = directSubtypes[cls];
184 return result == null ? const<ClassElement>[] : result; 206 return result == null ? const<ClassElement>[] : result;
185 } 207 }
186 208
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (!first) targetBuffer.add(",\n"); 473 if (!first) targetBuffer.add(",\n");
452 targetBuffer.add(" $name: $function"); 474 targetBuffer.add(" $name: $function");
453 first = false; 475 first = false;
454 }); 476 });
455 targetBuffer.add("\n});\n\n"); 477 targetBuffer.add("\n});\n\n");
456 } 478 }
457 targetBuffer.add('$nativeBuffer'); 479 targetBuffer.add('$nativeBuffer');
458 targetBuffer.add('\n'); 480 targetBuffer.add('\n');
459 } 481 }
460 } 482 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/js_backend/js_backend.dart ('k') | tests/compiler/dart2js/class_codegen_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698