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

Side by Side Diff: sdk/lib/js/dart2js/js_dart2js.dart

Issue 437733002: Fix inconsistency with null vs undefined in dart:js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/js/null_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 488 }
489 return null; 489 return null;
490 } 490 }
491 491
492 bool _isLocalObject(o) => JS('bool', '# instanceof Object', o); 492 bool _isLocalObject(o) => JS('bool', '# instanceof Object', o);
493 493
494 // The shared constructor function for proxies to Dart objects in JavaScript. 494 // The shared constructor function for proxies to Dart objects in JavaScript.
495 final _dartProxyCtor = JS('', 'function DartObject(o) { this.o = o; }'); 495 final _dartProxyCtor = JS('', 'function DartObject(o) { this.o = o; }');
496 496
497 dynamic _convertToJS(dynamic o) { 497 dynamic _convertToJS(dynamic o) {
498 if (o == null) { 498 // Note: we don't write `if (o == null) return null;` to make sure dart2js
499 return null; 499 // doesn't convert `return null;` into `return;` (which would make `null` be
500 } else if (o is String || o is num || o is bool) { 500 // `undefined` in Javascprit). See dartbug.com/20305 for details.
501 if (o == null || o is String || o is num || o is bool) {
501 return o; 502 return o;
502 } else if (o is Blob || o is Event || o is KeyRange || o is ImageData 503 } else if (o is Blob || o is Event || o is KeyRange || o is ImageData
503 || o is Node || o is TypedData || o is Window) { 504 || o is Node || o is TypedData || o is Window) {
504 return o; 505 return o;
505 } else if (o is DateTime) { 506 } else if (o is DateTime) {
506 return Primitives.lazyAsJsDate(o); 507 return Primitives.lazyAsJsDate(o);
507 } else if (o is JsObject) { 508 } else if (o is JsObject) {
508 return o._jsObject; 509 return o._jsObject;
509 } else if (o is Function) { 510 } else if (o is Function) {
510 return _getJsProxy(o, _JS_FUNCTION_PROPERTY_NAME, (o) { 511 return _getJsProxy(o, _JS_FUNCTION_PROPERTY_NAME, (o) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 // Dart in that context. The JS object will have a cached proxy 574 // Dart in that context. The JS object will have a cached proxy
574 // but it won't be a valid Dart object in this context. 575 // but it won't be a valid Dart object in this context.
575 // For now we throw away the cached proxy, but we should be able 576 // For now we throw away the cached proxy, but we should be able
576 // to cache proxies from multiple JS contexts and Dart isolates. 577 // to cache proxies from multiple JS contexts and Dart isolates.
577 if (dartProxy == null || !_isLocalObject(o)) { 578 if (dartProxy == null || !_isLocalObject(o)) {
578 dartProxy = createProxy(o); 579 dartProxy = createProxy(o);
579 _defineProperty(o, propertyName, dartProxy); 580 _defineProperty(o, propertyName, dartProxy);
580 } 581 }
581 return dartProxy; 582 return dartProxy;
582 } 583 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/js/null_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698