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

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

Issue 650093002: Avoid throwing exceptions on inter-frame communication (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r41115 and addedTODO with reference to bug. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 final String _DART_OBJECT_PROPERTY_NAME = 464 final String _DART_OBJECT_PROPERTY_NAME =
465 getIsolateAffinityTag(r'_$dart_dartObject'); 465 getIsolateAffinityTag(r'_$dart_dartObject');
466 final String _DART_CLOSURE_PROPERTY_NAME = 466 final String _DART_CLOSURE_PROPERTY_NAME =
467 getIsolateAffinityTag(r'_$dart_dartClosure'); 467 getIsolateAffinityTag(r'_$dart_dartClosure');
468 468
469 // property added to a JS object referencing its Dart-side JsObject proxy 469 // property added to a JS object referencing its Dart-side JsObject proxy
470 const _JS_OBJECT_PROPERTY_NAME = r'_$dart_jsObject'; 470 const _JS_OBJECT_PROPERTY_NAME = r'_$dart_jsObject';
471 const _JS_FUNCTION_PROPERTY_NAME = r'$dart_jsFunction'; 471 const _JS_FUNCTION_PROPERTY_NAME = r'$dart_jsFunction';
472 472
473 bool _defineProperty(o, String name, value) { 473 bool _defineProperty(o, String name, value) {
474 if (JS('bool', 'Object.isExtensible(#)', o)) { 474 if (_isExtensible(o) &&
475 // TODO(ahe): Calling _hasOwnProperty to work around
476 // https://code.google.com/p/dart/issues/detail?id=21331.
477 !_hasOwnProperty(o, name)) {
475 try { 478 try {
476 JS('void', 'Object.defineProperty(#, #, { value: #})', o, name, value); 479 JS('void', 'Object.defineProperty(#, #, { value: #})', o, name, value);
477 return true; 480 return true;
478 } catch(e) { 481 } catch (e) {
479 // object is native and lies about being extensible 482 // object is native and lies about being extensible
480 // see https://bugzilla.mozilla.org/show_bug.cgi?id=775185 483 // see https://bugzilla.mozilla.org/show_bug.cgi?id=775185
481 } 484 }
482 } 485 }
483 return false; 486 return false;
484 } 487 }
485 488
489 bool _hasOwnProperty(o, String name) {
490 return JS('bool', 'Object.prototype.hasOwnProperty.call(#, #)', o, name);
491 }
492
493 bool _isExtensible(o) => JS('bool', 'Object.isExtensible(#)', o);
494
486 Object _getOwnProperty(o, String name) { 495 Object _getOwnProperty(o, String name) {
487 if (JS('bool', 'Object.prototype.hasOwnProperty.call(#, #)', o, name)) { 496 if (_hasOwnProperty(o, name)) {
488 return JS('', '#[#]', o, name); 497 return JS('', '#[#]', o, name);
489 } 498 }
490 return null; 499 return null;
491 } 500 }
492 501
493 bool _isLocalObject(o) => JS('bool', '# instanceof Object', o); 502 bool _isLocalObject(o) => JS('bool', '# instanceof Object', o);
494 503
495 // The shared constructor function for proxies to Dart objects in JavaScript. 504 // The shared constructor function for proxies to Dart objects in JavaScript.
496 final _dartProxyCtor = JS('', 'function DartObject(o) { this.o = o; }'); 505 final _dartProxyCtor = JS('', 'function DartObject(o) { this.o = o; }');
497 506
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // Dart in that context. The JS object will have a cached proxy 584 // Dart in that context. The JS object will have a cached proxy
576 // but it won't be a valid Dart object in this context. 585 // but it won't be a valid Dart object in this context.
577 // For now we throw away the cached proxy, but we should be able 586 // For now we throw away the cached proxy, but we should be able
578 // to cache proxies from multiple JS contexts and Dart isolates. 587 // to cache proxies from multiple JS contexts and Dart isolates.
579 if (dartProxy == null || !_isLocalObject(o)) { 588 if (dartProxy == null || !_isLocalObject(o)) {
580 dartProxy = createProxy(o); 589 dartProxy = createProxy(o);
581 _defineProperty(o, propertyName, dartProxy); 590 _defineProperty(o, propertyName, dartProxy);
582 } 591 }
583 return dartProxy; 592 return dartProxy;
584 } 593 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698