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

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

Issue 2680823002: Extract InterceptorData from JavaScriptBackend. (Closed)
Patch Set: Updated cf. comments Created 3 years, 10 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 library dart2js.js_emitter.interceptor_stub_generator; 5 library dart2js.js_emitter.interceptor_stub_generator;
6 6
7 import '../compiler.dart' show Compiler; 7 import '../compiler.dart' show Compiler;
8 import '../constants/values.dart'; 8 import '../constants/values.dart';
9 import '../elements/entities.dart'; 9 import '../elements/entities.dart';
10 import '../elements/types.dart' show InterfaceType; 10 import '../elements/types.dart' show InterfaceType;
(...skipping 28 matching lines...) Expand all
39 jsAst.Expression interceptorFor(ClassEntity cls) { 39 jsAst.Expression interceptorFor(ClassEntity cls) {
40 return backend.emitter.interceptorPrototypeAccess(cls); 40 return backend.emitter.interceptorPrototypeAccess(cls);
41 } 41 }
42 42
43 /** 43 /**
44 * Build a JavaScrit AST node for doing a type check on 44 * Build a JavaScrit AST node for doing a type check on
45 * [cls]. [cls] must be a non-native interceptor class. 45 * [cls]. [cls] must be a non-native interceptor class.
46 */ 46 */
47 jsAst.Statement buildInterceptorCheck(ClassEntity cls) { 47 jsAst.Statement buildInterceptorCheck(ClassEntity cls) {
48 jsAst.Expression condition; 48 jsAst.Expression condition;
49 assert(backend.isInterceptorClass(cls)); 49 assert(backend.interceptorData.isInterceptorClass(cls));
50 if (cls == helpers.jsBoolClass) { 50 if (cls == helpers.jsBoolClass) {
51 condition = js('(typeof receiver) == "boolean"'); 51 condition = js('(typeof receiver) == "boolean"');
52 } else if (cls == helpers.jsIntClass || 52 } else if (cls == helpers.jsIntClass ||
53 cls == helpers.jsDoubleClass || 53 cls == helpers.jsDoubleClass ||
54 cls == helpers.jsNumberClass) { 54 cls == helpers.jsNumberClass) {
55 throw 'internal error'; 55 throw 'internal error';
56 } else if (cls == helpers.jsArrayClass || 56 } else if (cls == helpers.jsArrayClass ||
57 cls == helpers.jsMutableArrayClass || 57 cls == helpers.jsMutableArrayClass ||
58 cls == helpers.jsFixedArrayClass || 58 cls == helpers.jsFixedArrayClass ||
59 cls == helpers.jsExtendableArrayClass) { 59 cls == helpers.jsExtendableArrayClass) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // The set of classes includes classes mixed-in to interceptor classes 101 // The set of classes includes classes mixed-in to interceptor classes
102 // and user extensions of native classes. 102 // and user extensions of native classes.
103 // 103 //
104 // The set of classes also includes the 'primitive' interceptor 104 // The set of classes also includes the 'primitive' interceptor
105 // PlainJavaScriptObject even when it has not been resolved, since it is 105 // PlainJavaScriptObject even when it has not been resolved, since it is
106 // only resolved through the reference in getNativeInterceptor when 106 // only resolved through the reference in getNativeInterceptor when
107 // getNativeInterceptor is marked as used. Guard against probing 107 // getNativeInterceptor is marked as used. Guard against probing
108 // unresolved PlainJavaScriptObject by testing for anyNativeClasses. 108 // unresolved PlainJavaScriptObject by testing for anyNativeClasses.
109 109
110 if (anyNativeClasses) { 110 if (anyNativeClasses) {
111 if (backend.isNativeOrExtendsNative(cls)) hasNative = true; 111 if (backend.nativeData.isNativeOrExtendsNative(cls)) hasNative = true;
112 } 112 }
113 } 113 }
114 } 114 }
115 if (hasDouble) { 115 if (hasDouble) {
116 hasNumber = true; 116 hasNumber = true;
117 } 117 }
118 if (hasInt) hasNumber = true; 118 if (hasInt) hasNumber = true;
119 119
120 if (classes.containsAll(backend.interceptedClasses)) { 120 if (classes.containsAll(backend.interceptorData.interceptedClasses)) {
121 // I.e. this is the general interceptor. 121 // I.e. this is the general interceptor.
122 hasNative = anyNativeClasses; 122 hasNative = anyNativeClasses;
123 } 123 }
124 124
125 List<jsAst.Statement> statements = <jsAst.Statement>[]; 125 List<jsAst.Statement> statements = <jsAst.Statement>[];
126 126
127 if (hasNumber) { 127 if (hasNumber) {
128 jsAst.Statement whenNumber; 128 jsAst.Statement whenNumber;
129 129
130 /// Note: there are two number classes in play: Dart's [num], 130 /// Note: there are two number classes in play: Dart's [num],
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 (a0 >>> 0) === a0 && a0 < receiver.length) 330 (a0 >>> 0) === a0 && a0 < receiver.length)
331 return receiver[a0] = a1; 331 return receiver[a0] = a1;
332 ''', 332 ''',
333 typeCheck); 333 typeCheck);
334 } 334 }
335 } 335 }
336 return null; 336 return null;
337 } 337 }
338 338
339 jsAst.Expression generateOneShotInterceptor(jsAst.Name name) { 339 jsAst.Expression generateOneShotInterceptor(jsAst.Name name) {
340 Selector selector = backend.oneShotInterceptors[name]; 340 Selector selector = backend.interceptorData.oneShotInterceptors[name];
341 Set<ClassEntity> classes = backend.getInterceptedClassesOn(selector.name); 341 Set<ClassEntity> classes =
342 backend.interceptorData.getInterceptedClassesOn(selector.name);
342 jsAst.Name getInterceptorName = namer.nameForGetInterceptor(classes); 343 jsAst.Name getInterceptorName = namer.nameForGetInterceptor(classes);
343 344
344 List<String> parameterNames = <String>[]; 345 List<String> parameterNames = <String>[];
345 parameterNames.add('receiver'); 346 parameterNames.add('receiver');
346 347
347 if (selector.isSetter) { 348 if (selector.isSetter) {
348 parameterNames.add('value'); 349 parameterNames.add('value');
349 } else { 350 } else {
350 for (int i = 0; i < selector.argumentCount; i++) { 351 for (int i = 0; i < selector.argumentCount; i++) {
351 parameterNames.add('a$i'); 352 parameterNames.add('a$i');
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 412 }
412 413
413 var map = new jsAst.ObjectInitializer(properties); 414 var map = new jsAst.ObjectInitializer(properties);
414 elements.add(map); 415 elements.add(map);
415 } 416 }
416 } 417 }
417 418
418 return new jsAst.ArrayInitializer(elements); 419 return new jsAst.ArrayInitializer(elements);
419 } 420 }
420 } 421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698