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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 // specializations. | 348 // specializations. |
349 } | 349 } |
350 | 350 |
351 void potentiallyConvertDartClosuresToJs( | 351 void potentiallyConvertDartClosuresToJs( |
352 List<jsAst.Statement> statements, | 352 List<jsAst.Statement> statements, |
353 FunctionElement member, | 353 FunctionElement member, |
354 List<jsAst.Parameter> stubParameters) { | 354 List<jsAst.Parameter> stubParameters) { |
355 FunctionSignature parameters = member.functionSignature; | 355 FunctionSignature parameters = member.functionSignature; |
356 Element converter = | 356 Element converter = |
357 compiler.findHelper('convertDartClosureToJS'); | 357 compiler.findHelper('convertDartClosureToJS'); |
358 String closureConverter = backend.namer.isolateAccess(converter); | 358 jsAst.Expression closureConverter = backend.namer.elementAccess(converter); |
359 Set<String> stubParameterNames = new Set<String>.from( | |
360 stubParameters.map((param) => param.name)); | |
361 parameters.forEachParameter((ParameterElement parameter) { | 359 parameters.forEachParameter((ParameterElement parameter) { |
362 String name = parameter.name; | 360 String name = parameter.name; |
363 // If [name] is not in [stubParameters], then the parameter is an optional | 361 // If [name] is not in [stubParameters], then the parameter is an optional |
364 // parameter that was not provided for this stub. | 362 // parameter that was not provided for this stub. |
365 for (jsAst.Parameter stubParameter in stubParameters) { | 363 for (jsAst.Parameter stubParameter in stubParameters) { |
366 if (stubParameter.name == name) { | 364 if (stubParameter.name == name) { |
367 DartType type = parameter.type.unalias(compiler); | 365 DartType type = parameter.type.unalias(compiler); |
368 if (type is FunctionType) { | 366 if (type is FunctionType) { |
369 // The parameter type is a function type either directly or through | 367 // The parameter type is a function type either directly or through |
370 // typedef(s). | 368 // typedef(s). |
371 FunctionType functionType = type; | 369 FunctionType functionType = type; |
372 int arity = functionType.computeArity(); | 370 int arity = functionType.computeArity(); |
373 statements.add( | 371 statements.add( |
374 js('$name = $closureConverter($name, $arity)').toStatement()); | 372 js.statement('# = #(#, $arity)', |
373 [name, closureConverter, name])); | |
375 break; | 374 break; |
376 } | 375 } |
377 } | 376 } |
378 } | 377 } |
379 }); | 378 }); |
380 } | 379 } |
381 | 380 |
382 List<jsAst.Statement> generateParameterStubStatements( | 381 List<jsAst.Statement> generateParameterStubStatements( |
383 Element member, | 382 Element member, |
384 bool isInterceptedMethod, | 383 bool isInterceptedMethod, |
(...skipping 26 matching lines...) Expand all Loading... | |
411 | 410 |
412 if (isInterceptedMethod) { | 411 if (isInterceptedMethod) { |
413 receiver = argumentsBuffer[0]; | 412 receiver = argumentsBuffer[0]; |
414 arguments = argumentsBuffer.sublist(1, | 413 arguments = argumentsBuffer.sublist(1, |
415 indexOfLastOptionalArgumentInParameters + 1); | 414 indexOfLastOptionalArgumentInParameters + 1); |
416 } else { | 415 } else { |
417 receiver = js('this'); | 416 receiver = js('this'); |
418 arguments = argumentsBuffer.sublist(0, | 417 arguments = argumentsBuffer.sublist(0, |
419 indexOfLastOptionalArgumentInParameters + 1); | 418 indexOfLastOptionalArgumentInParameters + 1); |
420 } | 419 } |
421 statements.add(new jsAst.Return(receiver[target](arguments))); | 420 //statements.add(new jsAst.Return(receiver[target](arguments))); |
floitsch
2014/04/22 16:11:18
dead code.
sra1
2014/04/23 02:33:50
Done.
| |
421 statements.add( | |
422 js.statement('return #.#(#)', [receiver, target, arguments])); | |
422 | 423 |
423 return statements; | 424 return statements; |
424 } | 425 } |
425 | 426 |
426 bool isSupertypeOfNativeClass(Element element) { | 427 bool isSupertypeOfNativeClass(Element element) { |
427 if (element.isTypeVariable()) { | 428 if (element.isTypeVariable()) { |
428 compiler.internalError(element, "Is check for type variable."); | 429 compiler.internalError(element, "Is check for type variable."); |
429 return false; | 430 return false; |
430 } | 431 } |
431 if (element.computeType(compiler).unalias(compiler) is FunctionType) { | 432 if (element.computeType(compiler).unalias(compiler) is FunctionType) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 // If the native emitter has been asked to take care of the | 471 // If the native emitter has been asked to take care of the |
471 // noSuchMethod handlers, we do that now. | 472 // noSuchMethod handlers, we do that now. |
472 if (handleNoSuchMethod) { | 473 if (handleNoSuchMethod) { |
473 emitter.nsmEmitter.emitNoSuchMethodHandlers(addProperty); | 474 emitter.nsmEmitter.emitNoSuchMethodHandlers(addProperty); |
474 } | 475 } |
475 } | 476 } |
476 | 477 |
477 // If we have any properties to add to Object.prototype, we run | 478 // If we have any properties to add to Object.prototype, we run |
478 // through them and add them using defineProperty. | 479 // through them and add them using defineProperty. |
479 if (!objectProperties.isEmpty) { | 480 if (!objectProperties.isEmpty) { |
480 jsAst.Expression init = | 481 jsAst.Expression init = js(''' |
481 js.fun(['table'], | 482 (function(table) { |
482 new jsAst.ForIn( | 483 for(var key in table) |
483 new jsAst.VariableDeclarationList( | 484 $defPropName(Object.prototype, key, table[key]); |
floitsch
2014/04/22 16:11:18
We could make defPropAccess a template, and thus a
sra1
2014/04/23 02:33:50
Done.
| |
484 [new jsAst.VariableInitialization( | 485 })(#)''', |
485 new jsAst.VariableDeclaration('key'), | 486 new jsAst.ObjectInitializer(objectProperties)); |
486 null)]), | |
487 js('table'), | |
488 new jsAst.ExpressionStatement( | |
489 js('$defPropName(Object.prototype, key, table[key])'))))( | |
490 new jsAst.ObjectInitializer(objectProperties)); | |
491 | 487 |
492 if (emitter.compiler.enableMinification) targetBuffer.add(';'); | 488 if (emitter.compiler.enableMinification) targetBuffer.add(';'); |
493 targetBuffer.add(jsAst.prettyPrint( | 489 targetBuffer.add(jsAst.prettyPrint( |
494 new jsAst.ExpressionStatement(init), compiler)); | 490 new jsAst.ExpressionStatement(init), compiler)); |
495 targetBuffer.add('\n'); | 491 targetBuffer.add('\n'); |
496 } | 492 } |
497 | 493 |
498 targetBuffer.add(nativeBuffer); | 494 targetBuffer.add(nativeBuffer); |
499 targetBuffer.add('\n'); | 495 targetBuffer.add('\n'); |
500 } | 496 } |
501 } | 497 } |
OLD | NEW |