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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 'diffEncoding': js.string('$diffEncoding')})); | 271 'diffEncoding': js.string('$diffEncoding')})); |
272 if (!minify) { | 272 if (!minify) { |
273 statements.add(js.statement('var longNames = #longs.split(",")', | 273 statements.add(js.statement('var longNames = #longs.split(",")', |
274 {'longs': js.string(longs.join(','))})); | 274 {'longs': js.string(longs.join(','))})); |
275 } | 275 } |
276 statements.add(js.statement( | 276 statements.add(js.statement( |
277 'if (objectClassObject instanceof Array)' | 277 'if (objectClassObject instanceof Array)' |
278 ' objectClassObject = objectClassObject[1];')); | 278 ' objectClassObject = objectClassObject[1];')); |
279 } | 279 } |
280 | 280 |
281 List<jsAst.Expression> sliceOffsetArguments = | 281 dynamic isIntercepted = // jsAst.Expression or bool. |
floitsch
2015/06/19 21:22:15
firstNormalSelector != 0 &&
(firstNormalSelector =
sra1
2015/06/22 20:17:00
You can't use || to pick the jsAst. || is bool*bo
| |
282 firstNormalSelector == 0 | 282 firstNormalSelector == 0 |
283 ? [] | 283 ? false |
284 : (firstNormalSelector == shorts.length | 284 : firstNormalSelector == shorts.length |
285 ? [js.number(1)] | 285 ? true |
286 : [js('(j < #) ? 1 : 0', js.number(firstNormalSelector))]); | 286 : js('j < #', js.number(firstNormalSelector)); |
287 | |
288 var sliceOffsetParams = sliceOffsetArguments.isEmpty ? [] : ['sliceOffset']; | |
289 | 287 |
290 statements.add(js.statement(''' | 288 statements.add(js.statement(''' |
291 // If we are loading a deferred library the object class will not be in | 289 // If we are loading a deferred library the object class will not be in |
292 // the collectedClasses so objectClassObject is undefined, and we skip | 290 // the collectedClasses so objectClassObject is undefined, and we skip |
293 // setting up the names. | 291 // setting up the names. |
294 if (objectClassObject) { | 292 if (objectClassObject) { |
295 for (var j = 0; j < shortNames.length; j++) { | 293 for (var j = 0; j < shortNames.length; j++) { |
296 var type = 0; | 294 var type = 0; |
297 var short = shortNames[j]; | 295 var shortName = shortNames[j]; |
298 if (short[0] == "${namer.getterPrefix[0]}") type = 1; | 296 if (shortName[0] == "${namer.getterPrefix[0]}") type = 1; |
299 if (short[0] == "${namer.setterPrefix[0]}") type = 2; | 297 if (shortName[0] == "${namer.setterPrefix[0]}") type = 2; |
300 // Generate call to: | 298 // Generate call to: |
301 // | 299 // |
302 // createInvocationMirror(String name, internalName, type, | 300 // createInvocationMirror(String name, internalName, type, |
303 // arguments, argumentNames) | 301 // arguments, argumentNames) |
304 // | 302 // |
305 objectClassObject[short] = (function(name, short, | 303 |
306 type, #sliceOffsetParams) { | 304 // This 'if' is either a static choice or dynamic choice depending on |
307 return function() { | 305 // 'isIntercepted'. |
308 return this.#noSuchMethodName(this, | 306 if (#isIntercepted) { |
309 #createInvocationMirror(name, short, type, | 307 objectClassObject[shortName] = |
310 Array.prototype.slice.call(arguments, | 308 (function(name, shortName, type) { |
311 #sliceOffsetParams), | 309 return function(receiver) { |
312 [])); | 310 return this.#noSuchMethodName( |
313 } | 311 receiver, |
314 })(#names[j], short, type, #sliceOffsetArguments); | 312 #createInvocationMirror(name, shortName, type, |
313 Array.prototype.slice.call(arguments, 1), | |
floitsch
2015/06/19 21:22:15
add comment what the "1" is.
sra1
2015/06/22 20:17:00
Done.
| |
314 [])); | |
315 } | |
316 })(#names[j], shortName, type); | |
317 } else { | |
318 objectClassObject[shortName] = | |
319 (function(name, shortName, type) { | |
320 return function() { | |
321 return this.#noSuchMethodName( | |
322 this, // Could be dummy receiver. | |
floitsch
2015/06/19 21:22:15
how is that possible?
if the call is not intercept
sra1
2015/06/22 20:17:00
Done.
| |
323 #createInvocationMirror(name, shortName, type, | |
324 Array.prototype.slice.call(arguments), | |
Siggi Cherem (dart-lang)
2015/06/19 18:33:22
woudln't this return []? do we need splice here?
sra1
2015/06/19 18:59:38
slice copies a slice of the input.
'arguments' con
Siggi Cherem (dart-lang)
2015/06/19 19:46:00
Then are we missing the 0 argument here? That is:
sra1
2015/06/22 20:17:00
"If begin is omitted, slice begins from index 0."
Siggi Cherem (dart-lang)
2015/06/22 20:37:32
Sorry for all the silly questions here. Apparently
| |
325 [])); | |
326 } | |
327 })(#names[j], shortName, type); | |
328 } | |
315 } | 329 } |
316 }''', { | 330 }''', { |
317 'sliceOffsetParams': sliceOffsetParams, | |
318 'noSuchMethodName': namer.noSuchMethodName, | 331 'noSuchMethodName': namer.noSuchMethodName, |
319 'createInvocationMirror': createInvocationMirror, | 332 'createInvocationMirror': createInvocationMirror, |
320 'names': minify ? 'shortNames' : 'longNames', | 333 'names': minify ? 'shortNames' : 'longNames', |
321 'sliceOffsetArguments': sliceOffsetArguments})); | 334 'isIntercepted': isIntercepted})); |
322 | 335 |
323 return statements; | 336 return statements; |
324 } | 337 } |
325 } | 338 } |
OLD | NEW |