Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 // print(this.x + y); | 327 // print(this.x + y); |
| 328 // }, | 328 // }, |
| 329 // bar$2: function(t, v) { | 329 // bar$2: function(t, v) { |
| 330 // this.x = t - v; | 330 // this.x = t - v; |
| 331 // }, | 331 // }, |
| 332 // }); | 332 // }); |
| 333 | 333 |
| 334 bool hasIsolateSupport = compiler.hasIsolateSupport; | 334 bool hasIsolateSupport = compiler.hasIsolateSupport; |
| 335 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; | 335 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; |
| 336 | 336 |
| 337 jsAst.Expression defineClass = js(''' | 337 jsAst.Expression defineClass = js(r''' |
| 338 function(name, fields) { | 338 function(name, fields) { |
| 339 var accessors = []; | 339 var accessors = []; |
| 340 | 340 |
| 341 var str = "function " + name + "("; | 341 var str = "function " + name + "("; |
| 342 var body = ""; | 342 var body = ""; |
| 343 if (#hasIsolateSupport) { var fieldNames = ""; } | 343 if (#hasIsolateSupport) { var fieldNames = ""; } |
| 344 | 344 |
| 345 for (var i = 0; i < fields.length; i++) { | 345 for (var i = 0; i < fields.length; i++) { |
| 346 if(i != 0) str += ", "; | 346 if(i != 0) str += ", "; |
| 347 | 347 |
| 348 var field = generateAccessor(fields[i], accessors, name); | 348 var field = generateAccessor(fields[i], accessors, name); |
| 349 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } | 349 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } |
| 350 var parameter = "parameter_" + field; | 350 var parameter = "parameter_" + field; |
| 351 str += parameter; | 351 str += parameter; |
| 352 body += ("this." + field + " = " + parameter + ";\\n"); | 352 body += ("this." + field + " = " + parameter + ";\n"); |
| 353 } | 353 } |
| 354 str += ") {\\n" + body + "}\\n"; | 354 str += ") {\n" + body + "}\n"; |
| 355 str += name + ".builtin\$cls=\\"" + name + "\\";\\n"; | 355 str += name + ".builtin$cls=\"" + name + "\";\n"; |
| 356 str += "\$desc=\$collectedClasses." + name + ";\\n"; | 356 str += "$desc=$collectedClasses." + name + ";\n"; |
| 357 str += "if(\$desc instanceof Array) \$desc = \$desc[1];\\n"; | 357 str += "if($desc instanceof Array) $desc = \$desc[1];\n"; |
| 358 str += name + ".prototype = \$desc;\\n"; | 358 str += name + ".prototype = $desc;\n"; |
| 359 if (typeof defineClass.name != "string") { | 359 if (typeof defineClass.name != "string") { |
| 360 str += name + ".name=\\"" + name + "\\";\\n"; | 360 str += name + ".name=\"" + name + "\";\n"; |
| 361 } | 361 } |
| 362 if (#hasIsolateSupport) { | 362 if (#hasIsolateSupport) { |
| 363 str += name + ".$fieldNamesProperty=[" + fieldNames + "];\\n"; | 363 str += name + "." + #fieldNamesProperty + "=[" + fieldNames + "];\n" ; |
|
floitsch
2015/01/26 16:19:29
long line.
herhut
2015/01/27 11:37:19
Oops. Done.
| |
| 364 } | 364 } |
| 365 str += accessors.join(""); | 365 str += accessors.join(""); |
| 366 | 366 |
| 367 return str; | 367 return str; |
| 368 }''', { 'hasIsolateSupport': hasIsolateSupport }); | 368 }''', { 'hasIsolateSupport': hasIsolateSupport, |
| 369 'fieldNamesProperty': js.string(fieldNamesProperty)}); | |
| 369 | 370 |
| 370 // Declare a function called "generateAccessor". This is used in | 371 // Declare a function called "generateAccessor". This is used in |
| 371 // defineClassFunction. | 372 // defineClassFunction. |
| 372 List result = <jsAst.Node>[ | 373 List result = <jsAst.Node>[ |
| 373 generateAccessorFunction, | 374 generateAccessorFunction, |
| 374 new jsAst.FunctionDeclaration( | 375 new jsAst.FunctionDeclaration( |
| 375 new jsAst.VariableDeclaration('defineClass'), defineClass) ]; | 376 new jsAst.VariableDeclaration('defineClass'), defineClass) ]; |
| 376 | 377 |
| 377 if (compiler.hasIncrementalSupport) { | 378 if (compiler.hasIncrementalSupport) { |
| 378 result.add( | 379 result.add( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 } | 427 } |
| 427 | 428 |
| 428 /** Needs defineClass to be defined. */ | 429 /** Needs defineClass to be defined. */ |
| 429 jsAst.Expression buildInheritFrom() { | 430 jsAst.Expression buildInheritFrom() { |
| 430 jsAst.Expression result = js(r''' | 431 jsAst.Expression result = js(r''' |
| 431 function() { | 432 function() { |
| 432 function tmp() {} | 433 function tmp() {} |
| 433 var hasOwnProperty = Object.prototype.hasOwnProperty; | 434 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 434 return function (constructor, superConstructor) { | 435 return function (constructor, superConstructor) { |
| 435 if (superConstructor == null) { | 436 if (superConstructor == null) { |
| 436 // TODO(21896): this test shouldn't be necessary. Without it | 437 // TODO(21896): this test shouldn't be necessary. Without it |
|
floitsch
2015/01/26 16:19:29
you should rebase. That TODO has been fixed some t
herhut
2015/01/27 11:37:19
Done.
| |
| 437 // we have a crash in language/mixin_only_for_rti and | 438 // we have a crash in language/mixin_only_for_rti and |
| 438 // pkg/analysis_server/tool/spec/check_all_test. | 439 // pkg/analysis_server/tool/spec/check_all_test. |
| 439 if (constructor == null) return; | 440 if (constructor == null) return; |
| 440 | 441 |
| 441 // Fix up the the Dart Object class' prototype. | 442 // Fix up the the Dart Object class' prototype. |
| 442 var prototype = constructor.prototype; | 443 var prototype = constructor.prototype; |
| 443 prototype.constructor = constructor; | 444 prototype.constructor = constructor; |
| 445 prototype.$isObject = 1; | |
|
floitsch
2015/01/26 16:19:29
I think we discussed it, but I changed my mind: th
floitsch
2015/01/26 16:19:29
Are you sure this works? In minified code the name
herhut
2015/01/27 11:37:19
I use the constructor now, which should be a funct
herhut
2015/01/27 11:37:19
Of course it does not :) This was a bit rushed yes
| |
| 444 return prototype; | 446 return prototype; |
| 445 } | 447 } |
| 446 tmp.prototype = superConstructor.prototype; | 448 tmp.prototype = superConstructor.prototype; |
| 447 var object = new tmp(); | 449 var object = new tmp(); |
| 448 var properties = constructor.prototype; | 450 var properties = constructor.prototype; |
| 449 for (var member in properties) { | 451 for (var member in properties) { |
| 450 if (hasOwnProperty.call(properties, member)) { | 452 if (hasOwnProperty.call(properties, member)) { |
| 451 object[member] = properties[member]; | 453 object[member] = properties[member]; |
| 452 } | 454 } |
| 453 } | 455 } |
| 456 object["$is" + constructor.name] = 1; | |
|
floitsch
2015/01/26 16:19:29
Don't just use a magic prefix.
I believe that the
herhut
2015/01/27 11:37:19
Done.
| |
| 454 object.constructor = constructor; | 457 object.constructor = constructor; |
| 455 constructor.prototype = object; | 458 constructor.prototype = object; |
| 456 return object; | 459 return object; |
| 457 }; | 460 }; |
| 458 }() | 461 }() |
| 459 '''); | 462 '''); |
| 460 if (compiler.hasIncrementalSupport) { | 463 if (compiler.hasIncrementalSupport) { |
| 461 result = js( | 464 result = js( |
| 462 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); | 465 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); |
| 463 } | 466 } |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2070 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2073 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2071 if (element.isInstanceMember) { | 2074 if (element.isInstanceMember) { |
| 2072 cachedClassBuilders.remove(element.enclosingClass); | 2075 cachedClassBuilders.remove(element.enclosingClass); |
| 2073 | 2076 |
| 2074 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2077 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2075 | 2078 |
| 2076 } | 2079 } |
| 2077 } | 2080 } |
| 2078 } | 2081 } |
| 2079 } | 2082 } |
| OLD | NEW |