| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * Support for interoperating with JavaScript. | 6 * Support for interoperating with JavaScript. |
| 7 * | 7 * |
| 8 * This library provides access to JavaScript objects from Dart, allowing | 8 * This library provides access to JavaScript objects from Dart, allowing |
| 9 * Dart code to get and set properties, and call methods of JavaScript objects | 9 * Dart code to get and set properties, and call methods of JavaScript objects |
| 10 * and invoke JavaScript functions. The library takes care of converting | 10 * and invoke JavaScript functions. The library takes care of converting |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 if (_hasJsName(clazz)) { | 403 if (_hasJsName(clazz)) { |
| 404 // TODO(jacobr): verify class implements JavaScriptObject. | 404 // TODO(jacobr): verify class implements JavaScriptObject. |
| 405 String jsClassName = _getJsMemberName(clazz); | 405 String jsClassName = _getJsMemberName(clazz); |
| 406 var className = mirrors.MirrorSystem.getName(clazz.simpleName); | 406 var className = mirrors.MirrorSystem.getName(clazz.simpleName); |
| 407 var sbPatch = new StringBuffer(); | 407 var sbPatch = new StringBuffer(); |
| 408 jsInterfaceTypes.add(clazz); | 408 jsInterfaceTypes.add(clazz); |
| 409 clazz.declarations.forEach((name, declaration) { | 409 clazz.declarations.forEach((name, declaration) { |
| 410 if (declaration is! mirrors.MethodMirror || | 410 if (declaration is! mirrors.MethodMirror || |
| 411 !_isExternal(declaration)) return; | 411 !_isExternal(declaration)) return; |
| 412 if (declaration.isFactoryConstructor && _isAnonymousClass(clazz)) { | 412 if (declaration.isFactoryConstructor && _isAnonymousClass(clazz)) { |
| 413 sbPatch.write(" factory ${className}({"); | 413 sbPatch.write(" factory ${className}("); |
| 414 int i = 0; | 414 int i = 0; |
| 415 var args = <String>[]; | 415 var args = <String>[]; |
| 416 for (var p in declaration.parameters) { | 416 for (var p in declaration.parameters) { |
| 417 args.add(mirrors.MirrorSystem.getName(p.simpleName)); | 417 args.add(mirrors.MirrorSystem.getName(p.simpleName)); |
| 418 i++; | 418 i++; |
| 419 } | 419 } |
| 420 sbPatch | 420 if (args.isNotEmpty) { |
| 421 ..write( | 421 sbPatch |
| 422 args.map((name) => '$name:${_UNDEFINED_VAR}').join(", ")) | 422 ..write('{') |
| 423 ..write("}) {\n" | 423 ..write( |
| 424 args.map((name) => '$name:${_UNDEFINED_VAR}').join(", ")) |
| 425 ..write('}'); |
| 426 } |
| 427 sbPatch.write(") {\n" |
| 424 " var ret = new ${_JS_LIBRARY_PREFIX}.JsObject.jsify({});
\n"); | 428 " var ret = new ${_JS_LIBRARY_PREFIX}.JsObject.jsify({});
\n"); |
| 425 i = 0; | 429 i = 0; |
| 426 for (var p in declaration.parameters) { | 430 for (var p in declaration.parameters) { |
| 427 assert(p.isNamed); // XXX throw | 431 assert(p.isNamed); // XXX throw |
| 428 var name = args[i]; | 432 var name = args[i]; |
| 429 var jsName = mirrors.MirrorSystem.getName(p.simpleName); | 433 var jsName = mirrors.MirrorSystem.getName(p.simpleName); |
| 430 // XXX apply name conversion rules. | 434 // XXX apply name conversion rules. |
| 431 sbPatch.write( | 435 sbPatch.write( |
| 432 " if($name != ${_UNDEFINED_VAR}) ret['$jsName'] = $name;\
n"); | 436 " if($name != ${_UNDEFINED_VAR}) ret['$jsName'] = $name;\
n"); |
| 433 i++; | 437 i++; |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 return f; | 1359 return f; |
| 1356 } else { | 1360 } else { |
| 1357 var ret = _interopCaptureThisExpando[f]; | 1361 var ret = _interopCaptureThisExpando[f]; |
| 1358 if (ret == null) { | 1362 if (ret == null) { |
| 1359 ret = new JsFunction.withThis(f); | 1363 ret = new JsFunction.withThis(f); |
| 1360 _interopCaptureThisExpando[f] = ret; | 1364 _interopCaptureThisExpando[f] = ret; |
| 1361 } | 1365 } |
| 1362 return ret; | 1366 return ret; |
| 1363 } | 1367 } |
| 1364 } | 1368 } |
| OLD | NEW |