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

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

Issue 1198293002: dart2js: Use an abstract Name class for names in the generated JavaScript ast. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix new emitter. Created 5 years, 6 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
OLDNEW
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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class InterceptorStubGenerator { 7 class InterceptorStubGenerator {
8 final Compiler compiler; 8 final Compiler compiler;
9 final Namer namer; 9 final Namer namer;
10 final JavaScriptBackend backend; 10 final JavaScriptBackend backend;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return js.statement(r''' 280 return js.statement(r'''
281 if (# && !receiver.immutable$list && 281 if (# && !receiver.immutable$list &&
282 (a0 >>> 0) === a0 && a0 < receiver.length) 282 (a0 >>> 0) === a0 && a0 < receiver.length)
283 return receiver[a0] = a1; 283 return receiver[a0] = a1;
284 ''', typeCheck); 284 ''', typeCheck);
285 } 285 }
286 } 286 }
287 return null; 287 return null;
288 } 288 }
289 289
290 jsAst.Expression generateOneShotInterceptor(String name) { 290 jsAst.Expression generateOneShotInterceptor(jsAst.Name name) {
291 Selector selector = backend.oneShotInterceptors[name]; 291 Selector selector = backend.oneShotInterceptors[name];
292 Set<ClassElement> classes = 292 Set<ClassElement> classes =
293 backend.getInterceptedClassesOn(selector.name); 293 backend.getInterceptedClassesOn(selector.name);
294 String getInterceptorName = namer.nameForGetInterceptor(classes); 294 jsAst.Name getInterceptorName = namer.nameForGetInterceptor(classes);
295 295
296 List<String> parameterNames = <String>[]; 296 List<String> parameterNames = <String>[];
297 parameterNames.add('receiver'); 297 parameterNames.add('receiver');
298 298
299 if (selector.isSetter) { 299 if (selector.isSetter) {
300 parameterNames.add('value'); 300 parameterNames.add('value');
301 } else { 301 } else {
302 for (int i = 0; i < selector.argumentCount; i++) { 302 for (int i = 0; i < selector.argumentCount; i++) {
303 parameterNames.add('a$i'); 303 parameterNames.add('a$i');
304 } 304 }
305 } 305 }
306 306
307 String invocationName = backend.namer.invocationName(selector); 307 jsAst.Name invocationName = backend.namer.invocationName(selector);
308 String globalObject = namer.globalObjectFor(backend.interceptorsLibrary); 308 String globalObject = namer.globalObjectFor(backend.interceptorsLibrary);
309 309
310 jsAst.Statement optimizedPath = 310 jsAst.Statement optimizedPath =
311 _fastPathForOneShotInterceptor(selector, classes); 311 _fastPathForOneShotInterceptor(selector, classes);
312 if (optimizedPath == null) optimizedPath = js.statement(';'); 312 if (optimizedPath == null) optimizedPath = js.statement(';');
313 313
314 return js( 314 return js(
315 'function(#) { #; return #.#(receiver).#(#) }', 315 'function(#) { #; return #.#(receiver).#(#) }',
316 [parameterNames, 316 [parameterNames,
317 optimizedPath, 317 optimizedPath,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 363
364 var map = new jsAst.ObjectInitializer(properties); 364 var map = new jsAst.ObjectInitializer(properties);
365 elements.add(map); 365 elements.add(map);
366 } 366 }
367 } 367 }
368 } 368 }
369 369
370 return new jsAst.ArrayInitializer(elements); 370 return new jsAst.ArrayInitializer(elements);
371 } 371 }
372 } 372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698