| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 class NsmEmitter extends CodeEmitterHelper { | 7 class NsmEmitter extends CodeEmitterHelper { |
| 8 final List<Selector> trivialNsmHandlers = <Selector>[]; | 8 final List<Selector> trivialNsmHandlers = <Selector>[]; |
| 9 | 9 |
| 10 /// If this is true then we can generate the noSuchMethod handlers at startup | 10 /// If this is true then we can generate the noSuchMethod handlers at startup |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 'diffEncoding': js.string('$diffEncoding')})); | 273 'diffEncoding': js.string('$diffEncoding')})); |
| 274 if (!minify) { | 274 if (!minify) { |
| 275 statements.add(js.statement('var longNames = #longs.split(",")', | 275 statements.add(js.statement('var longNames = #longs.split(",")', |
| 276 {'longs': js.string(longs.join(','))})); | 276 {'longs': js.string(longs.join(','))})); |
| 277 } | 277 } |
| 278 statements.add(js.statement( | 278 statements.add(js.statement( |
| 279 'if (objectClassObject instanceof Array)' | 279 'if (objectClassObject instanceof Array)' |
| 280 ' objectClassObject = objectClassObject[1];')); | 280 ' objectClassObject = objectClassObject[1];')); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // TODO(9631): This is no longer valid for native methods. | |
| 284 String whatToPatch = emitter.nativeEmitter.handleNoSuchMethod ? | |
| 285 "Object.prototype" : | |
| 286 "objectClassObject"; | |
| 287 | |
| 288 List<jsAst.Expression> sliceOffsetArguments = | 283 List<jsAst.Expression> sliceOffsetArguments = |
| 289 firstNormalSelector == 0 | 284 firstNormalSelector == 0 |
| 290 ? [] | 285 ? [] |
| 291 : (firstNormalSelector == shorts.length | 286 : (firstNormalSelector == shorts.length |
| 292 ? [js.number(1)] | 287 ? [js.number(1)] |
| 293 : [js('(j < #) ? 1 : 0', js.number(firstNormalSelector))]); | 288 : [js('(j < #) ? 1 : 0', js.number(firstNormalSelector))]); |
| 294 | 289 |
| 295 var sliceOffsetParams = sliceOffsetArguments.isEmpty ? [] : ['sliceOffset']; | 290 var sliceOffsetParams = sliceOffsetArguments.isEmpty ? [] : ['sliceOffset']; |
| 296 | 291 |
| 297 statements.add(js.statement(''' | 292 statements.add(js.statement(''' |
| 298 // If we are loading a deferred library the object class will not be in | 293 // If we are loading a deferred library the object class will not be in |
| 299 // the collectedClasses so objectClassObject is undefined, and we skip | 294 // the collectedClasses so objectClassObject is undefined, and we skip |
| 300 // setting up the names. | 295 // setting up the names. |
| 301 if (objectClassObject) { | 296 if (objectClassObject) { |
| 302 for (var j = 0; j < shortNames.length; j++) { | 297 for (var j = 0; j < shortNames.length; j++) { |
| 303 var type = 0; | 298 var type = 0; |
| 304 var short = shortNames[j]; | 299 var short = shortNames[j]; |
| 305 if (short[0] == "${namer.getterPrefix[0]}") type = 1; | 300 if (short[0] == "${namer.getterPrefix[0]}") type = 1; |
| 306 if (short[0] == "${namer.setterPrefix[0]}") type = 2; | 301 if (short[0] == "${namer.setterPrefix[0]}") type = 2; |
| 307 // Generate call to: | 302 // Generate call to: |
| 308 // | 303 // |
| 309 // createInvocationMirror(String name, internalName, type, | 304 // createInvocationMirror(String name, internalName, type, |
| 310 // arguments, argumentNames) | 305 // arguments, argumentNames) |
| 311 // | 306 // |
| 312 $whatToPatch[short] = (function(name, short, | 307 objectClassObject[short] = (function(name, short, |
| 313 type, #sliceOffsetParams) { | 308 type, #sliceOffsetParams) { |
| 314 return function() { | 309 return function() { |
| 315 return this.#noSuchMethodName(this, | 310 return this.#noSuchMethodName(this, |
| 316 #createInvocationMirror(name, short, type, | 311 #createInvocationMirror(name, short, type, |
| 317 Array.prototype.slice.call(arguments, | 312 Array.prototype.slice.call(arguments, |
| 318 #sliceOffsetParams), | 313 #sliceOffsetParams), |
| 319 [])); | 314 [])); |
| 320 } | 315 } |
| 321 })(#names[j], short, type, #sliceOffsetArguments); | 316 })(#names[j], short, type, #sliceOffsetArguments); |
| 322 } | 317 } |
| 323 }''', { | 318 }''', { |
| 324 'sliceOffsetParams': sliceOffsetParams, | 319 'sliceOffsetParams': sliceOffsetParams, |
| 325 'noSuchMethodName': namer.noSuchMethodName, | 320 'noSuchMethodName': namer.noSuchMethodName, |
| 326 'createInvocationMirror': createInvocationMirror, | 321 'createInvocationMirror': createInvocationMirror, |
| 327 'names': minify ? 'shortNames' : 'longNames', | 322 'names': minify ? 'shortNames' : 'longNames', |
| 328 'sliceOffsetArguments': sliceOffsetArguments})); | 323 'sliceOffsetArguments': sliceOffsetArguments})); |
| 329 | 324 |
| 330 return statements; | 325 return statements; |
| 331 } | 326 } |
| 332 } | 327 } |
| OLD | NEW |