Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 class NativeEmitter { | 7 class NativeEmitter { |
| 8 | 8 |
| 9 CodeEmitterTask emitter; | 9 CodeEmitterTask emitter; |
| 10 CodeBuffer nativeBuffer; | 10 CodeBuffer nativeBuffer; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 } | 405 } |
| 406 | 406 |
| 407 if (!element.isClass()) { | 407 if (!element.isClass()) { |
| 408 compiler.cancel("Is check does not handle element", element: element); | 408 compiler.cancel("Is check does not handle element", element: element); |
| 409 return false; | 409 return false; |
| 410 } | 410 } |
| 411 | 411 |
| 412 return subtypes[element] != null; | 412 return subtypes[element] != null; |
| 413 } | 413 } |
| 414 | 414 |
| 415 bool requiresNativeIsCheck(Element element) { | 415 bool requiresNativeIsCheck(Element element) { |
|
ngeoffray
2013/04/16 07:47:12
Can't you remove this method, and the one above?
sra1
2013/04/16 21:15:10
It is still used ... I'll add a TODO.
| |
| 416 if (!element.isClass()) return false; | 416 if (!element.isClass()) return false; |
| 417 ClassElement cls = element; | 417 ClassElement cls = element; |
| 418 if (cls.isNative()) return true; | 418 if (cls.isNative()) return true; |
| 419 return isSupertypeOfNativeClass(element); | 419 return isSupertypeOfNativeClass(element); |
| 420 } | 420 } |
| 421 | 421 |
| 422 void assembleCode(CodeBuffer targetBuffer) { | 422 void assembleCode(CodeBuffer targetBuffer) { |
| 423 List<jsAst.Property> objectProperties = <jsAst.Property>[]; | 423 List<jsAst.Property> objectProperties = <jsAst.Property>[]; |
| 424 | 424 |
| 425 void addProperty(String name, jsAst.Expression value) { | 425 void addProperty(String name, jsAst.Expression value) { |
| 426 objectProperties.add(new jsAst.Property(js.string(name), value)); | 426 objectProperties.add(new jsAst.Property(js.string(name), value)); |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Because of native classes, we have to generate some is checks | |
| 430 // by calling a method, instead of accessing a property. So we | |
| 431 // attach to the JS Object prototype these methods that return | |
| 432 // false, and will be overridden by subclasses when they have to | |
| 433 // return true. | |
| 434 void emitIsChecks() { | |
| 435 for (ClassElement element in | |
| 436 Elements.sortedByPosition(emitter.checkedClasses)) { | |
| 437 if (!requiresNativeIsCheck(element)) continue; | |
| 438 if (element.isObject(compiler)) continue; | |
| 439 // Add function for the is-test. | |
| 440 String name = backend.namer.operatorIs(element); | |
| 441 addProperty(name, | |
| 442 js.fun([], js.return_(js('false')))); | |
| 443 // Add a function for the (trivial) substitution. | |
| 444 addProperty(backend.namer.substitutionName(element), | |
| 445 js.fun([], js.return_(js('null')))); | |
| 446 } | |
| 447 } | |
| 448 emitIsChecks(); | |
| 449 | |
| 450 if (!nativeClasses.isEmpty) { | 429 if (!nativeClasses.isEmpty) { |
| 451 // If the native emitter has been asked to take care of the | 430 // If the native emitter has been asked to take care of the |
| 452 // noSuchMethod handlers, we do that now. | 431 // noSuchMethod handlers, we do that now. |
| 453 if (handleNoSuchMethod) { | 432 if (handleNoSuchMethod) { |
| 454 emitter.emitNoSuchMethodHandlers(addProperty); | 433 emitter.emitNoSuchMethodHandlers(addProperty); |
| 455 } | 434 } |
| 456 } | 435 } |
| 457 | 436 |
| 458 // If we have any properties to add to Object.prototype, we run | 437 // If we have any properties to add to Object.prototype, we run |
| 459 // through them and add them using defineProperty. | 438 // through them and add them using defineProperty. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 473 if (emitter.compiler.enableMinification) targetBuffer.add(';'); | 452 if (emitter.compiler.enableMinification) targetBuffer.add(';'); |
| 474 targetBuffer.add(jsAst.prettyPrint( | 453 targetBuffer.add(jsAst.prettyPrint( |
| 475 new jsAst.ExpressionStatement(init), compiler)); | 454 new jsAst.ExpressionStatement(init), compiler)); |
| 476 targetBuffer.add('\n'); | 455 targetBuffer.add('\n'); |
| 477 } | 456 } |
| 478 | 457 |
| 479 targetBuffer.add(nativeBuffer); | 458 targetBuffer.add(nativeBuffer); |
| 480 targetBuffer.add('\n'); | 459 targetBuffer.add('\n'); |
| 481 } | 460 } |
| 482 } | 461 } |
| OLD | NEW |