| 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 library dart2js.js_emitter.interceptor_stub_generator; | 5 library dart2js.js_emitter.interceptor_stub_generator; |
| 6 | 6 |
| 7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
| 9 import '../elements/entities.dart'; | 9 import '../elements/entities.dart'; |
| 10 import '../elements/types.dart' show InterfaceType; | 10 import '../elements/types.dart' show InterfaceType; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // if (typeof a0 === "number") { | 261 // if (typeof a0 === "number") { |
| 262 // if (receiver.constructor == Array && !receiver.immutable$list) { | 262 // if (receiver.constructor == Array && !receiver.immutable$list) { |
| 263 // if (a0 >>> 0 === a0 && a0 < receiver.length) { | 263 // if (a0 >>> 0 === a0 && a0 < receiver.length) { |
| 264 // return receiver[a0] = a1; | 264 // return receiver[a0] = a1; |
| 265 // } | 265 // } |
| 266 // } | 266 // } |
| 267 // } | 267 // } |
| 268 bool containsArray = classes.contains(helpers.jsArrayClass); | 268 bool containsArray = classes.contains(helpers.jsArrayClass); |
| 269 bool containsString = classes.contains(helpers.jsStringClass); | 269 bool containsString = classes.contains(helpers.jsStringClass); |
| 270 bool containsJsIndexable = | 270 bool containsJsIndexable = |
| 271 helpers.jsIndexingBehaviorInterface.isResolved && | 271 closedWorld.isImplemented(helpers.jsIndexingBehaviorInterface) && |
| 272 classes.any((cls) { | 272 classes.any((cls) { |
| 273 return closedWorld.isSubtypeOf( | 273 return closedWorld.isSubtypeOf( |
| 274 cls, helpers.jsIndexingBehaviorInterface); | 274 cls, helpers.jsIndexingBehaviorInterface); |
| 275 }); | 275 }); |
| 276 // The index set operator requires a check on its set value in | 276 // The index set operator requires a check on its set value in |
| 277 // checked mode, so we don't optimize the interceptor if the | 277 // checked mode, so we don't optimize the interceptor if the |
| 278 // compiler has type assertions enabled. | 278 // compiler has type assertions enabled. |
| 279 if (selector.isIndexSet && | 279 if (selector.isIndexSet && |
| 280 (compiler.options.enableTypeAssertions || !containsArray)) { | 280 (compiler.options.enableTypeAssertions || !containsArray)) { |
| 281 return null; | 281 return null; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 346 |
| 347 if (selector.isSetter) { | 347 if (selector.isSetter) { |
| 348 parameterNames.add('value'); | 348 parameterNames.add('value'); |
| 349 } else { | 349 } else { |
| 350 for (int i = 0; i < selector.argumentCount; i++) { | 350 for (int i = 0; i < selector.argumentCount; i++) { |
| 351 parameterNames.add('a$i'); | 351 parameterNames.add('a$i'); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 jsAst.Name invocationName = backend.namer.invocationName(selector); | 355 jsAst.Name invocationName = backend.namer.invocationName(selector); |
| 356 String globalObject = namer.globalObjectFor(helpers.interceptorsLibrary); | 356 String globalObject = |
| 357 namer.globalObjectForLibrary(helpers.interceptorsLibrary); |
| 357 | 358 |
| 358 jsAst.Statement optimizedPath = | 359 jsAst.Statement optimizedPath = |
| 359 _fastPathForOneShotInterceptor(selector, classes); | 360 _fastPathForOneShotInterceptor(selector, classes); |
| 360 if (optimizedPath == null) optimizedPath = js.statement(';'); | 361 if (optimizedPath == null) optimizedPath = js.statement(';'); |
| 361 | 362 |
| 362 return js('function(#) { #; return #.#(receiver).#(#) }', [ | 363 return js('function(#) { #; return #.#(receiver).#(#) }', [ |
| 363 parameterNames, | 364 parameterNames, |
| 364 optimizedPath, | 365 optimizedPath, |
| 365 globalObject, | 366 globalObject, |
| 366 getInterceptorName, | 367 getInterceptorName, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 411 } |
| 411 | 412 |
| 412 var map = new jsAst.ObjectInitializer(properties); | 413 var map = new jsAst.ObjectInitializer(properties); |
| 413 elements.add(map); | 414 elements.add(map); |
| 414 } | 415 } |
| 415 } | 416 } |
| 416 | 417 |
| 417 return new jsAst.ArrayInitializer(elements); | 418 return new jsAst.ArrayInitializer(elements); |
| 418 } | 419 } |
| 419 } | 420 } |
| OLD | NEW |