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

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

Issue 779593002: Move elementAccess() from namer to emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 6 years 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) 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;
11 11
12 InterceptorStubGenerator(this.compiler, this.namer, this.backend); 12 InterceptorStubGenerator(this.compiler, this.namer, this.backend);
13 13
14 jsAst.Expression generateGetInterceptorMethod(Set<ClassElement> classes) { 14 jsAst.Expression generateGetInterceptorMethod(Set<ClassElement> classes) {
15 jsAst.Expression interceptorFor(ClassElement cls) { 15 jsAst.Expression interceptorFor(ClassElement cls) {
16 return js('#.prototype', namer.elementAccess(cls)); 16 return js('#.prototype', backend.emitter.classAccess(cls));
17 } 17 }
18 18
19 /** 19 /**
20 * Build a JavaScrit AST node for doing a type check on 20 * Build a JavaScrit AST node for doing a type check on
21 * [cls]. [cls] must be a non-native interceptor class. 21 * [cls]. [cls] must be a non-native interceptor class.
22 */ 22 */
23 jsAst.Statement buildInterceptorCheck(ClassElement cls) { 23 jsAst.Statement buildInterceptorCheck(ClassElement cls) {
24 jsAst.Expression condition; 24 jsAst.Expression condition;
25 assert(backend.isInterceptorClass(cls)); 25 assert(backend.isInterceptorClass(cls));
26 if (cls == backend.jsBoolClass) { 26 if (cls == backend.jsBoolClass) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (hasArray) { 135 if (hasArray) {
136 statements.add(buildInterceptorCheck(backend.jsArrayClass)); 136 statements.add(buildInterceptorCheck(backend.jsArrayClass));
137 } 137 }
138 138
139 if (hasNative) { 139 if (hasNative) {
140 statements.add(js.statement(r'''{ 140 statements.add(js.statement(r'''{
141 if (typeof receiver != "object") return receiver; 141 if (typeof receiver != "object") return receiver;
142 if (receiver instanceof #) return receiver; 142 if (receiver instanceof #) return receiver;
143 return #(receiver); 143 return #(receiver);
144 }''', [ 144 }''', [
145 namer.elementAccess(compiler.objectClass), 145 backend.emitter.classAccess(compiler.objectClass),
146 namer.elementAccess(backend.getNativeInterceptorMethod)])); 146 backend.emitter
147 .staticFunctionAccess(backend.getNativeInterceptorMethod)]));
147 148
148 } else { 149 } else {
149 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass; 150 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass;
150 if (compiler.codegenWorld 151 if (compiler.codegenWorld
151 .directlyInstantiatedClasses.contains(jsUnknown)) { 152 .directlyInstantiatedClasses.contains(jsUnknown)) {
152 statements.add( 153 statements.add(
153 js.statement('if (!(receiver instanceof #)) return #;', 154 js.statement('if (!(receiver instanceof #)) return #;',
154 [namer.elementAccess(compiler.objectClass), 155 [backend.emitter.classAccess(compiler.objectClass),
155 interceptorFor(jsUnknown)])); 156 interceptorFor(jsUnknown)]));
156 } 157 }
157 158
158 statements.add(js.statement('return receiver')); 159 statements.add(js.statement('return receiver'));
159 } 160 }
160 161
161 return js('''function(receiver) { #; }''', new jsAst.Block(statements)); 162 return js('''function(receiver) { #; }''', new jsAst.Block(statements));
162 } 163 }
163 164
164 // Returns a statement that takes care of performance critical 165 // Returns a statement that takes care of performance critical
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 _fastPathForOneShotInterceptor(selector, classes); 310 _fastPathForOneShotInterceptor(selector, classes);
310 if (optimizedPath == null) optimizedPath = js.statement(';'); 311 if (optimizedPath == null) optimizedPath = js.statement(';');
311 312
312 return js( 313 return js(
313 'function(#) { #; return #.#(receiver).#(#) }', 314 'function(#) { #; return #.#(receiver).#(#) }',
314 [parameterNames, 315 [parameterNames,
315 optimizedPath, 316 optimizedPath,
316 globalObject, getInterceptorName, invocationName, parameterNames]); 317 globalObject, getInterceptorName, invocationName, parameterNames]);
317 } 318 }
318 } 319 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/code_emitter_task.dart ('k') | pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698