Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.globalPropertyAccess(cls)); |
|
floitsch
2014/12/03 17:02:25
classAccess
Maybe even classPrototypeAccess
Inter
zarah
2014/12/05 08:22:50
Done.
| |
| 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 Loading... | |
| 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.globalPropertyAccess(compiler.objectClass), |
|
floitsch
2014/12/03 17:02:25
either classAccess or constructorAccess.
Both make
zarah
2014/12/05 08:22:50
Done.
| |
| 146 namer.elementAccess(backend.getNativeInterceptorMethod)])); | 146 backend.emitter.globalPropertyAccess(backend.getNativeInterceptorMetho d)])); |
|
floitsch
2014/12/03 17:02:25
staticFunctionAccess.
Long line.
zarah
2014/12/05 08:22:50
Done.
| |
| 147 | 147 |
| 148 } else { | 148 } else { |
| 149 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass; | 149 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass; |
| 150 if (compiler.codegenWorld | 150 if (compiler.codegenWorld |
| 151 .directlyInstantiatedClasses.contains(jsUnknown)) { | 151 .directlyInstantiatedClasses.contains(jsUnknown)) { |
| 152 statements.add( | 152 statements.add( |
| 153 js.statement('if (!(receiver instanceof #)) return #;', | 153 js.statement('if (!(receiver instanceof #)) return #;', |
| 154 [namer.elementAccess(compiler.objectClass), | 154 [backend.emitter.globalPropertyAccess(compiler.objectClass), |
|
floitsch
2014/12/03 17:02:25
as in line 145.
zarah
2014/12/05 08:22:51
Done.
| |
| 155 interceptorFor(jsUnknown)])); | 155 interceptorFor(jsUnknown)])); |
| 156 } | 156 } |
| 157 | 157 |
| 158 statements.add(js.statement('return receiver')); | 158 statements.add(js.statement('return receiver')); |
| 159 } | 159 } |
| 160 | 160 |
| 161 return js('''function(receiver) { #; }''', new jsAst.Block(statements)); | 161 return js('''function(receiver) { #; }''', new jsAst.Block(statements)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Returns a statement that takes care of performance critical | 164 // Returns a statement that takes care of performance critical |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 _fastPathForOneShotInterceptor(selector, classes); | 309 _fastPathForOneShotInterceptor(selector, classes); |
| 310 if (optimizedPath == null) optimizedPath = js.statement(';'); | 310 if (optimizedPath == null) optimizedPath = js.statement(';'); |
| 311 | 311 |
| 312 return js( | 312 return js( |
| 313 'function(#) { #; return #.#(receiver).#(#) }', | 313 'function(#) { #; return #.#(receiver).#(#) }', |
| 314 [parameterNames, | 314 [parameterNames, |
| 315 optimizedPath, | 315 optimizedPath, |
| 316 globalObject, getInterceptorName, invocationName, parameterNames]); | 316 globalObject, getInterceptorName, invocationName, parameterNames]); |
| 317 } | 317 } |
| 318 } | 318 } |
| OLD | NEW |