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

Side by Side Diff: sdk/lib/_internal/lib/native_helper.dart

Issue 86993002: Assume Document may be HtmlDocument (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 _js_helper; 5 part of _js_helper;
6 6
7 7
8 // TODO(ngeoffray): stop using this method once our optimizers can 8 // TODO(ngeoffray): stop using this method once our optimizers can
9 // change str1.contains(str2) into str1.indexOf(str2) != -1. 9 // change str1.contains(str2) into str1.indexOf(str2) != -1.
10 bool contains(String userAgent, String name) { 10 bool contains(String userAgent, String name) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 JS('', '#(#)', _fallbackConstructorHooksTransformerGenerator, 382 JS('', '#(#)', _fallbackConstructorHooksTransformerGenerator,
383 _constructorNameFallback); 383 _constructorNameFallback);
384 hooks = applyHooksTransformer(_fallbackConstructorHooksTransformer, hooks); 384 hooks = applyHooksTransformer(_fallbackConstructorHooksTransformer, hooks);
385 385
386 // Customize for browsers: 386 // Customize for browsers:
387 hooks = applyHooksTransformer(_firefoxHooksTransformer, hooks); 387 hooks = applyHooksTransformer(_firefoxHooksTransformer, hooks);
388 hooks = applyHooksTransformer(_ieHooksTransformer, hooks); 388 hooks = applyHooksTransformer(_ieHooksTransformer, hooks);
389 hooks = applyHooksTransformer(_operaHooksTransformer, hooks); 389 hooks = applyHooksTransformer(_operaHooksTransformer, hooks);
390 hooks = applyHooksTransformer(_safariHooksTransformer, hooks); 390 hooks = applyHooksTransformer(_safariHooksTransformer, hooks);
391 391
392 hooks = applyHooksTransformer(_fixDocumentHooksTransformer, hooks);
393
392 // TODO(sra): Update ShadowDOM polyfil to use 394 // TODO(sra): Update ShadowDOM polyfil to use
393 // [dartNativeDispatchHooksTransformer] and remove this hook. 395 // [dartNativeDispatchHooksTransformer] and remove this hook.
394 hooks = applyHooksTransformer(_dartExperimentalFixupGetTagHooksTransformer, 396 hooks = applyHooksTransformer(_dartExperimentalFixupGetTagHooksTransformer,
395 hooks); 397 hooks);
396 398
397 // Apply global hooks. 399 // Apply global hooks.
398 // 400 //
399 // If defined, dartNativeDispatchHookdTransformer should be a single function 401 // If defined, dartNativeDispatchHookdTransformer should be a single function
400 // of a JavaScript Array of functions. 402 // of a JavaScript Array of functions.
401 403
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 "HTMLDDElement": "HTMLElement", 541 "HTMLDDElement": "HTMLElement",
540 "HTMLDTElement": "HTMLElement", 542 "HTMLDTElement": "HTMLElement",
541 "HTMLPhraseElement": "HTMLElement", 543 "HTMLPhraseElement": "HTMLElement",
542 "Position": "Geoposition" 544 "Position": "Geoposition"
543 }; 545 };
544 546
545 function getTagIE(o) { 547 function getTagIE(o) {
546 var tag = getTag(o); 548 var tag = getTag(o);
547 var newTag = quickMap[tag]; 549 var newTag = quickMap[tag];
548 if (newTag) return newTag; 550 if (newTag) return newTag;
549 if (tag == "Document") {
550 // IE calls both HTML and XML documents "Document", so we check for the
551 // xmlVersion property, which is the empty string on HTML documents.
552 // Since both dart:html classes Document and HtmlDocument share the same
553 // type, we must patch the instances and not the prototype.
554 if (!!o.xmlVersion) return "!Document";
555 return "!HTMLDocument";
556 }
557 // Patches for types which report themselves as Objects. 551 // Patches for types which report themselves as Objects.
558 if (tag == "Object") { 552 if (tag == "Object") {
559 if (window.DataView && (o instanceof window.DataView)) return "DataView"; 553 if (window.DataView && (o instanceof window.DataView)) return "DataView";
560 } 554 }
561 return tag; 555 return tag;
562 } 556 }
563 557
564 function prototypeForTagIE(tag) { 558 function prototypeForTagIE(tag) {
565 if (tag == "Document") return null; // Do not pre-patch Document.
566 var constructor = window[tag]; 559 var constructor = window[tag];
567 if (constructor == null) return null; 560 if (constructor == null) return null;
568 return constructor.prototype; 561 return constructor.prototype;
569 } 562 }
570 563
571 hooks.getTag = getTagIE; 564 hooks.getTag = getTagIE;
572 hooks.prototypeForTag = prototypeForTagIE; 565 hooks.prototypeForTag = prototypeForTagIE;
573 }'''); 566 }''');
574 567
568 const _fixDocumentHooksTransformer = const JS_CONST(r'''
569 function(hooks) {
570 var getTag = hooks.getTag;
571 var prototypeForTag = hooks.prototypeForTag;
572 function getTagFixed(o) {
573 var tag = getTag(o);
574 if (tag == "Document") {
575 // Some browsers and the polymer polyfill call both HTML and XML documents
576 // "Document", so we check for the xmlVersion property, which is the empty
577 // string on HTML documents. Since both dart:html classes Document and
578 // HtmlDocument share the same type, we must patch the instances and not
579 // the prototype.
580 if (!!o.xmlVersion) return "!Document";
581 return "!HTMLDocument";
582 }
583 return tag;
584 }
585
586 function prototypeForTagFixed(tag) {
587 if (tag == "Document") return null; // Do not pre-patch Document.
588 return prototypeForTag(tag);
589 }
590
591 hooks.getTag = getTagFixed;
592 hooks.prototypeForTag = prototypeForTagFixed;
593 }''');
575 594
576 const _firefoxHooksTransformer = const JS_CONST(r''' 595 const _firefoxHooksTransformer = const JS_CONST(r'''
577 function(hooks) { 596 function(hooks) {
578 var userAgent = typeof navigator == "object" ? navigator.userAgent : ""; 597 var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
579 if (userAgent.indexOf("Firefox") == -1) return hooks; 598 if (userAgent.indexOf("Firefox") == -1) return hooks;
580 599
581 var getTag = hooks.getTag; 600 var getTag = hooks.getTag;
582 601
583 var quickMap = { 602 var quickMap = {
584 "BeforeUnloadEvent": "Event", 603 "BeforeUnloadEvent": "Event",
(...skipping 19 matching lines...) Expand all
604 const _safariHooksTransformer = const JS_CONST(r''' 623 const _safariHooksTransformer = const JS_CONST(r'''
605 function(hooks) { return hooks; } 624 function(hooks) { return hooks; }
606 '''); 625 ''');
607 626
608 627
609 const _dartExperimentalFixupGetTagHooksTransformer = const JS_CONST(r''' 628 const _dartExperimentalFixupGetTagHooksTransformer = const JS_CONST(r'''
610 function(hooks) { 629 function(hooks) {
611 if (typeof dartExperimentalFixupGetTag != "function") return hooks; 630 if (typeof dartExperimentalFixupGetTag != "function") return hooks;
612 hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag); 631 hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);
613 }'''); 632 }''');
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