| 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 * The js.dart library provides simple JavaScript invocation from Dart that | 6 * The js.dart library provides simple JavaScript invocation from Dart that |
| 7 * works on both Dartium and on other modern browsers via Dart2JS. | 7 * works on both Dartium and on other modern browsers via Dart2JS. |
| 8 * | 8 * |
| 9 * It provides a model based on scoped [JsObject] objects. Proxies give Dart | 9 * It provides a model based on scoped [JsObject] objects. Proxies give Dart |
| 10 * code access to JavaScript objects, fields, and functions as well as the | 10 * code access to JavaScript objects, fields, and functions as well as the |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // Global ports to manage communication from Dart to JS. | 72 // Global ports to manage communication from Dart to JS. |
| 73 SendPortSync _jsPortSync = window.lookupPort('dart-js-context'); | 73 SendPortSync _jsPortSync = window.lookupPort('dart-js-context'); |
| 74 SendPortSync _jsPortCreate = window.lookupPort('dart-js-create'); | 74 SendPortSync _jsPortCreate = window.lookupPort('dart-js-create'); |
| 75 SendPortSync _jsPortInstanceof = window.lookupPort('dart-js-instanceof'); | 75 SendPortSync _jsPortInstanceof = window.lookupPort('dart-js-instanceof'); |
| 76 SendPortSync _jsPortDeleteProperty = window.lookupPort('dart-js-delete-property'
); | 76 SendPortSync _jsPortDeleteProperty = window.lookupPort('dart-js-delete-property'
); |
| 77 SendPortSync _jsPortConvert = window.lookupPort('dart-js-convert'); | 77 SendPortSync _jsPortConvert = window.lookupPort('dart-js-convert'); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Returns a proxy to the global JavaScript context for this page. | 80 * Returns a proxy to the global JavaScript context for this page. |
| 81 */ | 81 */ |
| 82 JsObject get context => _deserialize(_jsPortSync.callSync([])); | 82 JsObject get context { |
| 83 var port = _jsPortSync; |
| 84 if (port == null) { |
| 85 return null; |
| 86 } |
| 87 return _deserialize(_jsPortSync.callSync([])); |
| 88 } |
| 83 | 89 |
| 84 /** | 90 /** |
| 85 * Converts a json-like [data] to a JavaScript map or array and return a | 91 * Converts a json-like [data] to a JavaScript map or array and return a |
| 86 * [JsObject] to it. | 92 * [JsObject] to it. |
| 87 */ | 93 */ |
| 88 JsObject jsify(dynamic data) => data == null ? null : new JsObject._json(data); | 94 JsObject jsify(dynamic data) => data == null ? null : new JsObject._json(data); |
| 89 | 95 |
| 90 /** | 96 /** |
| 91 * Converts a local Dart function to a callback that can be passed to | 97 * Converts a local Dart function to a callback that can be passed to |
| 92 * JavaScript. | 98 * JavaScript. |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // Serialized type. | 368 // Serialized type. |
| 363 return message; | 369 return message; |
| 364 } | 370 } |
| 365 var tag = message[0]; | 371 var tag = message[0]; |
| 366 switch (tag) { | 372 switch (tag) { |
| 367 case 'funcref': return deserializeFunction(message); | 373 case 'funcref': return deserializeFunction(message); |
| 368 case 'objref': return deserializeObject(message); | 374 case 'objref': return deserializeObject(message); |
| 369 } | 375 } |
| 370 throw 'Unsupported serialized data: $message'; | 376 throw 'Unsupported serialized data: $message'; |
| 371 } | 377 } |
| OLD | NEW |