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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart

Issue 828753002: dart2js OldEmitter: Change to named holes in js output strings plus some extra clean-ups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 5 years, 11 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
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 String internalName = namer.invocationMirrorInternalName(selector); 74 String internalName = namer.invocationMirrorInternalName(selector);
75 String reflectionName = emitter.getReflectionName(selector, internalName); 75 String reflectionName = emitter.getReflectionName(selector, internalName);
76 if (!haveVeryFewNoSuchMemberHandlers && 76 if (!haveVeryFewNoSuchMemberHandlers &&
77 isTrivialNsmHandler(type, argNames, selector, internalName) && 77 isTrivialNsmHandler(type, argNames, selector, internalName) &&
78 reflectionName == null) { 78 reflectionName == null) {
79 trivialNsmHandlers.add(selector); 79 trivialNsmHandlers.add(selector);
80 return null; 80 return null;
81 } 81 }
82 82
83 assert(backend.isInterceptedName(Compiler.NO_SUCH_METHOD)); 83 assert(backend.isInterceptedName(Compiler.NO_SUCH_METHOD));
84 jsAst.Expression expression = js('this.#(this, #(#, #, #, #, #))', [ 84 jsAst.Expression expression =
85 noSuchMethodName, 85 js('''this.#noSuchMethodName(this,
86 backend.emitter.staticFunctionAccess( 86 #createInvocationMirror(#methodName,
87 backend.getCreateInvocationMirror()), 87 #internalName,
88 js.string(compiler.enableMinification ? 88 #type,
89 internalName : methodName), 89 #arguments,
90 js.string(internalName), 90 #namedArguments))''',
91 js.number(type), 91 {'noSuchMethodName': noSuchMethodName,
92 new jsAst.ArrayInitializer(parameterNames.map(js).toList()), 92 'createInvocationMirror':
93 new jsAst.ArrayInitializer(argNames)]); 93 backend.emitter.staticFunctionAccess(
94 backend.getCreateInvocationMirror()),
95 'methodName':
96 js.string(compiler.enableMinification
97 ? internalName : methodName),
98 'internalName': js.string(internalName),
99 'type': js.number(type),
100 'arguments':
101 new jsAst.ArrayInitializer(parameterNames.map(js).toList()),
102 'namedArguments': new jsAst.ArrayInitializer(argNames)});
94 103
95 if (backend.isInterceptedName(selector.name)) { 104 if (backend.isInterceptedName(selector.name)) {
96 return js(r'function($receiver, #) { return # }', 105 return js(r'function($receiver, #) { return # }',
97 [parameterNames, expression]); 106 [parameterNames, expression]);
98 } else { 107 } else {
99 return js(r'function(#) { return # }', [parameterNames, expression]); 108 return js(r'function(#) { return # }', [parameterNames, expression]);
100 } 109 }
101 } 110 }
102 111
103 for (String jsName in addedJsNames.keys.toList()..sort()) { 112 for (String jsName in addedJsNames.keys.toList()..sort()) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // Startup code that loops over the method names and puts handlers on the 279 // Startup code that loops over the method names and puts handlers on the
271 // Object class to catch noSuchMethod invocations. 280 // Object class to catch noSuchMethod invocations.
272 ClassElement objectClass = compiler.objectClass; 281 ClassElement objectClass = compiler.objectClass;
273 jsAst.Expression createInvocationMirror = backend.emitter 282 jsAst.Expression createInvocationMirror = backend.emitter
274 .staticFunctionAccess(backend.getCreateInvocationMirror()); 283 .staticFunctionAccess(backend.getCreateInvocationMirror());
275 String noSuchMethodName = namer.publicInstanceMethodNameByArity( 284 String noSuchMethodName = namer.publicInstanceMethodNameByArity(
276 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT); 285 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT);
277 var type = 0; 286 var type = 0;
278 if (useDiffEncoding) { 287 if (useDiffEncoding) {
279 statements.add(js.statement('''{ 288 statements.add(js.statement('''{
280 var objectClassObject = 289 var objectClassObject = collectedClasses[#objectClass],
281 collectedClasses[#], // # is name of class Object. 290 shortNames = #diffEncoding.split(","),
282 shortNames = #.split(","), // # is diffEncoding.
283 nameNumber = 0, 291 nameNumber = 0,
284 diffEncodedString = shortNames[0], 292 diffEncodedString = shortNames[0],
285 calculatedShortNames = [0, 1]; // 0, 1 are args for splice. 293 calculatedShortNames = [0, 1]; // 0, 1 are args for splice.
286 // If we are loading a deferred library the object class will not be i n 294 // If we are loading a deferred library the object class will not be i n
287 // the collectedClasses so objectClassObject is undefined, and we skip 295 // the collectedClasses so objectClassObject is undefined, and we skip
288 // setting up the names. 296 // setting up the names.
289 297
290 if (objectClassObject) { 298 if (objectClassObject) {
291 if (objectClassObject instanceof Array) 299 if (objectClassObject instanceof Array)
292 objectClassObject = objectClassObject[1]; 300 objectClassObject = objectClassObject[1];
(...skipping 16 matching lines...) Expand all
309 for (var remaining = nameNumber; 317 for (var remaining = nameNumber;
310 remaining > 0; 318 remaining > 0;
311 remaining = (remaining / 88) | 0) { 319 remaining = (remaining / 88) | 0) {
312 codes.unshift(${$HASH} + remaining % 88); 320 codes.unshift(${$HASH} + remaining % 88);
313 } 321 }
314 calculatedShortNames.push( 322 calculatedShortNames.push(
315 String.fromCharCode.apply(String, codes)); 323 String.fromCharCode.apply(String, codes));
316 } 324 }
317 shortNames.splice.apply(shortNames, calculatedShortNames); 325 shortNames.splice.apply(shortNames, calculatedShortNames);
318 } 326 }
319 }''', [ 327 }''', {'objectClass': js.string(namer.getNameOfClass(objectClass)),
320 js.string(namer.getNameOfClass(objectClass)), 328 'diffEncoding': js.string('$diffEncoding')}));
321 js.string('$diffEncoding')]));
322 } else { 329 } else {
323 // No useDiffEncoding version. 330 // No useDiffEncoding version.
324 Iterable<String> longs = trivialNsmHandlers.map((selector) => 331 Iterable<String> longs = trivialNsmHandlers.map((selector) =>
325 selector.invocationMirrorMemberName); 332 selector.invocationMirrorMemberName);
326 statements.add(js.statement( 333 statements.add(js.statement(
327 'var objectClassObject = collectedClasses[#],' 334 'var objectClassObject = collectedClasses[#objectClass],'
328 ' shortNames = #.split(",")', [ 335 ' shortNames = #diffEncoding.split(",")',
329 js.string(namer.getNameOfClass(objectClass)), 336 {'objectClass': js.string(namer.getNameOfClass(objectClass)),
330 js.string('$diffEncoding')])); 337 'diffEncoding': js.string('$diffEncoding')}));
331 if (!minify) { 338 if (!minify) {
332 statements.add(js.statement('var longNames = #.split(",")', 339 statements.add(js.statement('var longNames = #longs.split(",")',
333 js.string(longs.join(',')))); 340 {'longs': js.string(longs.join(','))}));
334 } 341 }
335 statements.add(js.statement( 342 statements.add(js.statement(
336 'if (objectClassObject instanceof Array)' 343 'if (objectClassObject instanceof Array)'
337 ' objectClassObject = objectClassObject[1];')); 344 ' objectClassObject = objectClassObject[1];'));
338 } 345 }
339 346
340 // TODO(9631): This is no longer valid for native methods. 347 // TODO(9631): This is no longer valid for native methods.
341 String whatToPatch = emitter.nativeEmitter.handleNoSuchMethod ? 348 String whatToPatch = emitter.nativeEmitter.handleNoSuchMethod ?
342 "Object.prototype" : 349 "Object.prototype" :
343 "objectClassObject"; 350 "objectClassObject";
(...skipping 15 matching lines...) Expand all
359 for (var j = 0; j < shortNames.length; j++) { 366 for (var j = 0; j < shortNames.length; j++) {
360 var type = 0; 367 var type = 0;
361 var short = shortNames[j]; 368 var short = shortNames[j];
362 if (short[0] == "${namer.getterPrefix[0]}") type = 1; 369 if (short[0] == "${namer.getterPrefix[0]}") type = 1;
363 if (short[0] == "${namer.setterPrefix[0]}") type = 2; 370 if (short[0] == "${namer.setterPrefix[0]}") type = 2;
364 // Generate call to: 371 // Generate call to:
365 // 372 //
366 // createInvocationMirror(String name, internalName, type, 373 // createInvocationMirror(String name, internalName, type,
367 // arguments, argumentNames) 374 // arguments, argumentNames)
368 // 375 //
369 $whatToPatch[short] = (function(name, short, type, #) { 376 $whatToPatch[short] = (function(name, short,
377 type, #sliceOffsetParams) {
370 return function() { 378 return function() {
371 return this.#(this, 379 return this.#noSuchMethodName(this,
372 #(name, short, type, 380 #createInvocationMirror(name, short, type,
373 Array.prototype.slice.call(arguments, #), 381 Array.prototype.slice.call(arguments,
374 [])); 382 #sliceOffsetParams),
383 []));
375 } 384 }
376 })(#[j], short, type, #); 385 })(#names[j], short, type, #sliceOffsetArguments);
377 } 386 }
378 }''', [ 387 }''', {
379 sliceOffsetParams, // parameter 388 'sliceOffsetParams': sliceOffsetParams,
380 noSuchMethodName, 389 'noSuchMethodName': noSuchMethodName,
381 createInvocationMirror, 390 'createInvocationMirror': createInvocationMirror,
382 sliceOffsetParams, // argument to slice 391 'names': minify ? 'shortNames' : 'longNames',
383 minify ? 'shortNames' : 'longNames', 392 'sliceOffsetArguments': sliceOffsetArguments}));
384 sliceOffsetArguments
385 ]));
386 393
387 return statements; 394 return statements;
388 } 395 }
389 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698