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

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

Issue 10978017: Make sure we can use JavaScript properties on Object as classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
« no previous file with comments | « no previous file | tests/language/js_properties_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // - its internal prototype (__proto__) points to the superclass' 188 // - its internal prototype (__proto__) points to the superclass'
189 // prototype field. 189 // prototype field.
190 // - the prototype's constructor field points to the JavaScript 190 // - the prototype's constructor field points to the JavaScript
191 // constructor. 191 // constructor.
192 // For engines where we have access to the '__proto__' we can manipulate 192 // For engines where we have access to the '__proto__' we can manipulate
193 // the object literal directly. For other engines we have to create a new 193 // the object literal directly. For other engines we have to create a new
194 // object and copy over the members. 194 // object and copy over the members.
195 return ''' 195 return '''
196 function(collectedClasses) { 196 function(collectedClasses) {
197 for (var cls in collectedClasses) { 197 for (var cls in collectedClasses) {
198 if (Object.prototype.hasOwnProperty.call(collectedClasses, cls)) { 198 if (Object.prototype.hasOwnProperty.call(collectedClasses, cls)) {
Lasse Reichstein Nielsen 2012/09/25 08:30:53 Move hasOwnProperty variable before this use too?
ngeoffray 2012/09/25 08:32:28 Done.
199 var desc = collectedClasses[cls]; 199 var desc = collectedClasses[cls];
200 $isolatePropertiesName[cls] = $defineClassName(cls, desc[''], desc); 200 $isolatePropertiesName[cls] = $defineClassName(cls, desc[''], desc);
201 if (desc['super'] !== "") $pendingClassesName[cls] = desc['super']; 201 if (desc['super'] !== "") $pendingClassesName[cls] = desc['super'];
202 } 202 }
203 } 203 }
204 var pendingClasses = $pendingClassesName; 204 var pendingClasses = $pendingClassesName;
205 '''/* FinishClasses can be called multiple times. This means that we need to 205 '''/* FinishClasses can be called multiple times. This means that we need to
206 clear the pendingClasses property. */''' 206 clear the pendingClasses property. */'''
207 $pendingClassesName = {}; 207 $pendingClassesName = {};
208 var finishedClasses = {}; 208 var finishedClasses = {};
209 function finishClass(cls) { 209 function finishClass(cls) {
210 if (finishedClasses[cls]) return; 210 '''/* Opera does not support 'getOwnPropertyNames'. Therefore we use
211 hasOwnProperty instead. */'''
212 var hasOwnProperty = Object.prototype.hasOwnProperty;
Lasse Reichstein Nielsen 2012/09/25 08:30:53 indentation?
ngeoffray 2012/09/25 08:32:28 Done.
213 if (hasOwnProperty.call(finishedClasses, cls)) return;
211 finishedClasses[cls] = true; 214 finishedClasses[cls] = true;
212 var superclass = pendingClasses[cls]; 215 var superclass = pendingClasses[cls];
213 '''/* The superclass is only false (empty string) for Dart's Object class. */''' 216 '''/* The superclass is only false (empty string) for Dart's Object class. */'''
214 if (!superclass) return; 217 if (!superclass) return;
215 finishClass(superclass); 218 finishClass(superclass);
216 var constructor = $isolatePropertiesName[cls]; 219 var constructor = $isolatePropertiesName[cls];
217 var superConstructor = $isolatePropertiesName[superclass]; 220 var superConstructor = $isolatePropertiesName[superclass];
218 var prototype = constructor.prototype; 221 var prototype = constructor.prototype;
219 if ($supportsProtoName) { 222 if ($supportsProtoName) {
220 prototype.__proto__ = superConstructor.prototype; 223 prototype.__proto__ = superConstructor.prototype;
221 prototype.constructor = constructor; 224 prototype.constructor = constructor;
222 } else { 225 } else {
223 function tmp() {}; 226 function tmp() {};
224 tmp.prototype = superConstructor.prototype; 227 tmp.prototype = superConstructor.prototype;
225 var newPrototype = new tmp(); 228 var newPrototype = new tmp();
226 constructor.prototype = newPrototype; 229 constructor.prototype = newPrototype;
227 newPrototype.constructor = constructor; 230 newPrototype.constructor = constructor;
228 '''/* Opera does not support 'getOwnPropertyNames'. Therefore we use
229 hosOwnProperty instead. */'''
230 var hasOwnProperty = Object.prototype.hasOwnProperty;
231 for (var member in prototype) { 231 for (var member in prototype) {
232 if (member == '' || member == 'super') continue; 232 if (member == '' || member == 'super') continue;
233 if (hasOwnProperty.call(prototype, member)) { 233 if (hasOwnProperty.call(prototype, member)) {
234 newPrototype[member] = prototype[member]; 234 newPrototype[member] = prototype[member];
235 } 235 }
236 } 236 }
237 } 237 }
238 } 238 }
239 for (var cls in pendingClasses) finishClass(cls); 239 for (var cls in pendingClasses) finishClass(cls);
240 }'''; 240 }''';
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 const String HOOKS_API_USAGE = """ 1434 const String HOOKS_API_USAGE = """
1435 // Generated by dart2js, the Dart to JavaScript compiler. 1435 // Generated by dart2js, the Dart to JavaScript compiler.
1436 // The code supports the following hooks: 1436 // The code supports the following hooks:
1437 // dartPrint(message) - if this function is defined it is called 1437 // dartPrint(message) - if this function is defined it is called
1438 // instead of the Dart [print] method. 1438 // instead of the Dart [print] method.
1439 // dartMainRunner(main) - if this function is defined, the Dart [main] 1439 // dartMainRunner(main) - if this function is defined, the Dart [main]
1440 // method will not be invoked directly. 1440 // method will not be invoked directly.
1441 // Instead, a closure that will invoke [main] is 1441 // Instead, a closure that will invoke [main] is
1442 // passed to [dartMainRunner]. 1442 // passed to [dartMainRunner].
1443 """; 1443 """;
OLDNEW
« no previous file with comments | « no previous file | tests/language/js_properties_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698