Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/nsm_emitter.dart

Issue 202903006: Make deferred loading work with noSuchMethod. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/deferred_no_such_method_lib.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT); 274 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT);
275 var type = 0; 275 var type = 0;
276 if (useDiffEncoding) { 276 if (useDiffEncoding) {
277 statements.addAll([ 277 statements.addAll([
278 js('var objectClassObject = ' 278 js('var objectClassObject = '
279 ' collectedClasses["${namer.getNameOfClass(objectClass)}"],' 279 ' collectedClasses["${namer.getNameOfClass(objectClass)}"],'
280 ' shortNames = "$diffEncoding".split(","),' 280 ' shortNames = "$diffEncoding".split(","),'
281 ' nameNumber = 0,' 281 ' nameNumber = 0,'
282 ' diffEncodedString = shortNames[0],' 282 ' diffEncodedString = shortNames[0],'
283 ' calculatedShortNames = [0, 1]'), // 0, 1 are args for splice. 283 ' calculatedShortNames = [0, 1]'), // 0, 1 are args for splice.
284 js.if_('objectClassObject instanceof Array', 284 // If we are loading a deferred library the object class will not be in
285 js('objectClassObject = objectClassObject[1]')), 285 // the collectedClasses so objectClassObject is undefined, and we skip
286 js.for_('var i = 0', 'i < diffEncodedString.length', 'i++', [ 286 // setting up the names.
287 js('var codes = [],' 287 js.if_('objectClassObject', [
288 ' diff = 0,' 288 js.if_('objectClassObject instanceof Array',
289 ' digit = diffEncodedString.charCodeAt(i)'), 289 js('objectClassObject = objectClassObject[1]')),
290 js.if_('digit == ${$PERIOD}', [ 290 js.for_('var i = 0', 'i < diffEncodedString.length', 'i++', [
291 js('nameNumber = 0'), 291 js('var codes = [],'
292 js('digit = diffEncodedString.charCodeAt(++i)') 292 ' diff = 0,'
293 ' digit = diffEncodedString.charCodeAt(i)'),
294 js.if_('digit == ${$PERIOD}', [
295 js('nameNumber = 0'),
296 js('digit = diffEncodedString.charCodeAt(++i)')
297 ]),
298 js.while_('digit <= ${$Z}', [
299 js('diff *= 26'),
300 js('diff += (digit - ${$A})'),
301 js('digit = diffEncodedString.charCodeAt(++i)')
302 ]),
303 js('diff *= 26'),
304 js('diff += (digit - ${$a})'),
305 js('nameNumber += diff'),
306 js.for_('var remaining = nameNumber',
307 'remaining > 0',
308 'remaining = (remaining / 88) | 0', [
309 js('codes.unshift(${$HASH} + remaining % 88)')
310 ]),
311 js('calculatedShortNames.push('
312 ' String.fromCharCode.apply(String, codes))')
293 ]), 313 ]),
294 js.while_('digit <= ${$Z}', [ 314 js('shortNames.splice.apply(shortNames, calculatedShortNames)')])
295 js('diff *= 26'),
296 js('diff += (digit - ${$A})'),
297 js('digit = diffEncodedString.charCodeAt(++i)')
298 ]),
299 js('diff *= 26'),
300 js('diff += (digit - ${$a})'),
301 js('nameNumber += diff'),
302 js.for_('var remaining = nameNumber',
303 'remaining > 0',
304 'remaining = (remaining / 88) | 0', [
305 js('codes.unshift(${$HASH} + remaining % 88)')
306 ]),
307 js('calculatedShortNames.push('
308 ' String.fromCharCode.apply(String, codes))')
309 ]),
310 js('shortNames.splice.apply(shortNames, calculatedShortNames)')
311 ]); 315 ]);
312 } else { 316 } else {
313 // No useDiffEncoding version. 317 // No useDiffEncoding version.
314 Iterable<String> longs = trivialNsmHandlers.map((selector) => 318 Iterable<String> longs = trivialNsmHandlers.map((selector) =>
315 selector.invocationMirrorMemberName); 319 selector.invocationMirrorMemberName);
316 String longNamesConstant = minify ? "" : 320 String longNamesConstant = minify ? "" :
317 ',longNames = "${longs.join(",")}".split(",")'; 321 ',longNames = "${longs.join(",")}".split(",")';
318 statements.add( 322 statements.add(
319 js('var objectClassObject = ' 323 js('var objectClassObject = '
320 ' collectedClasses["${namer.getNameOfClass(objectClass)}"],' 324 ' collectedClasses["${namer.getNameOfClass(objectClass)}"],'
(...skipping 13 matching lines...) Expand all
334 "objectClassObject"; 338 "objectClassObject";
335 339
336 var params = ['name', 'short', 'type']; 340 var params = ['name', 'short', 'type'];
337 var sliceOffsetParam = ''; 341 var sliceOffsetParam = '';
338 var slice = 'Array.prototype.slice.call'; 342 var slice = 'Array.prototype.slice.call';
339 if (!sliceOffset.isEmpty) { 343 if (!sliceOffset.isEmpty) {
340 sliceOffsetParam = ', sliceOffset'; 344 sliceOffsetParam = ', sliceOffset';
341 params.add('sliceOffset'); 345 params.add('sliceOffset');
342 } 346 }
343 statements.addAll([ 347 statements.addAll([
344 js.for_('var j = 0', 'j < shortNames.length', 'j++', [ 348 // If we are loading a deferred library the object class will not be in
345 js('var type = 0'), 349 // the collectedClasses so objectClassObject is undefined, and we skip
346 js('var short = shortNames[j]'), 350 // setting up the names.
347 js.if_('short[0] == "${namer.getterPrefix[0]}"', js('type = 1')), 351 js.if_('objectClassObject', [
348 js.if_('short[0] == "${namer.setterPrefix[0]}"', js('type = 2')), 352 js.for_('var j = 0', 'j < shortNames.length', 'j++', [
349 // Generate call to: 353 js('var type = 0'),
350 // createInvocationMirror(String name, internalName, type, arguments, 354 js('var short = shortNames[j]'),
351 // argumentNames) 355 js.if_('short[0] == "${namer.getterPrefix[0]}"', js('type = 1')),
352 js('$whatToPatch[short] = #(${minify ? "shortNames" : "longNames"}[j], ' 356 js.if_('short[0] == "${namer.setterPrefix[0]}"', js('type = 2')),
353 'short, type$sliceOffset)', 357 // Generate call to:
354 js.fun(params, [js.return_(js.fun([], 358 // createInvocationMirror(String name, internalName, type, arguments,
355 [js.return_(js( 359 // argumentNames)
356 'this.$noSuchMethodName(' 360 js('$whatToPatch[short] = #(${minify ? "shortNames" : "longNames"}[j], '
357 'this, ' 361 'short, type$sliceOffset)',
358 '$createInvocationMirror(' 362 js.fun(params, [js.return_(js.fun([],
359 'name, short, type, ' 363 [js.return_(js(
360 '$slice(arguments$sliceOffsetParam), []))'))]))])) 364 'this.$noSuchMethodName('
365 'this, '
366 '$createInvocationMirror('
367 'name, short, type, '
368 '$slice(arguments$sliceOffsetParam), []))'))]))]))
369 ])
361 ]) 370 ])
362 ]); 371 ]);
363 } 372 }
364 } 373 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/deferred_no_such_method_lib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698