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

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

Issue 1318043005: Support user generated custom native JS classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: about to land Created 5 years, 2 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 statements.add(buildInterceptorCheck(backend.jsBoolClass)); 133 statements.add(buildInterceptorCheck(backend.jsBoolClass));
134 } 134 }
135 // TODO(ahe): It might be faster to check for Array before 135 // TODO(ahe): It might be faster to check for Array before
136 // function and bool. 136 // function and bool.
137 if (hasArray) { 137 if (hasArray) {
138 statements.add(buildInterceptorCheck(backend.jsArrayClass)); 138 statements.add(buildInterceptorCheck(backend.jsArrayClass));
139 } 139 }
140 140
141 if (hasNative) { 141 if (hasNative) {
142 statements.add(js.statement(r'''{ 142 statements.add(js.statement(r'''{
143 if (typeof receiver != "object") return receiver; 143 if (typeof receiver != "object") {
144 if (typeof receiver == "function" ) return #;
145 return receiver;
146 }
144 if (receiver instanceof #) return receiver; 147 if (receiver instanceof #) return receiver;
145 return #(receiver); 148 return #(receiver);
146 }''', [ 149 }''', [
150 interceptorFor(backend.jsJavaScriptFunctionClass),
147 backend.emitter.constructorAccess(compiler.objectClass), 151 backend.emitter.constructorAccess(compiler.objectClass),
148 backend.emitter 152 backend.emitter
149 .staticFunctionAccess(backend.getNativeInterceptorMethod)])); 153 .staticFunctionAccess(backend.getNativeInterceptorMethod)]));
150 154
151 } else { 155 } else {
152 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass; 156 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass;
153 if (compiler.codegenWorld 157 if (compiler.codegenWorld
154 .directlyInstantiatedClasses.contains(jsUnknown)) { 158 .directlyInstantiatedClasses.contains(jsUnknown)) {
155 statements.add( 159 statements.add(
156 js.statement('if (!(receiver instanceof #)) return #;', 160 js.statement('if (!(receiver instanceof #)) return #;',
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 367
364 var map = new jsAst.ObjectInitializer(properties); 368 var map = new jsAst.ObjectInitializer(properties);
365 elements.add(map); 369 elements.add(map);
366 } 370 }
367 } 371 }
368 } 372 }
369 373
370 return new jsAst.ArrayInitializer(elements); 374 return new jsAst.ArrayInitializer(elements);
371 } 375 }
372 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698