OLD | NEW |
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 /** | 477 /** |
478 * Returns the name of the constructor function for browsers where | 478 * Returns the name of the constructor function for browsers where |
479 * `object.constructor.name` is not reliable. | 479 * `object.constructor.name` is not reliable. |
480 * | 480 * |
481 * This function is split out of [_fallbackConstructorHooksTransformerGenerator] | 481 * This function is split out of [_fallbackConstructorHooksTransformerGenerator] |
482 * as it is called from both the dispatch hooks and via | 482 * as it is called from both the dispatch hooks and via |
483 * [constructorNameFallback] from objectToString. | 483 * [constructorNameFallback] from objectToString. |
484 */ | 484 */ |
485 const _constructorNameFallback = const JS_CONST(r''' | 485 const _constructorNameFallback = const JS_CONST(r''' |
486 function getTagFallback(o) { | 486 function getTagFallback(o) { |
487 if (o == null) return "Null"; | |
488 var constructor = o.constructor; | 487 var constructor = o.constructor; |
489 if (typeof constructor == "function") { | 488 if (typeof constructor == "function") { |
490 var name = constructor.builtin$cls; | |
491 if (typeof name == "string") return name; | |
492 // The constructor is not null or undefined at this point. Try | |
493 // to grab hold of its name. | |
494 name = constructor.name; | 489 name = constructor.name; |
495 // If the name is a non-empty string, we use that as the type name of this | 490 // If the name is a non-empty string, we use that as the type name of this |
496 // object. On Firefox, we often get "Object" as the constructor name even | 491 // object. On Firefox, we often get "Object" as the constructor name even |
497 // for more specialized objects so we have to fall through to the toString() | 492 // for more specialized objects so we have to fall through to the toString() |
498 // based implementation below in that case. | 493 // based implementation below in that case. |
499 if (typeof name == "string" | 494 if (typeof name == "string" |
500 && name !== "" | 495 && name !== "" |
501 && name !== "Object" | 496 && name !== "Object" |
502 && name !== "Function.prototype") { // Can happen in Opera. | 497 && name !== "Function.prototype") { // Can happen in Opera. |
503 return name; | 498 return name; |
504 } | 499 } |
505 } | 500 } |
506 var s = Object.prototype.toString.call(o); | 501 var s = Object.prototype.toString.call(o); |
507 return s.substring(8, s.length - 1); | 502 return s.substring(8, s.length - 1); |
508 }'''); | 503 }'''); |
509 | 504 |
510 | 505 |
511 const _fallbackConstructorHooksTransformerGenerator = const JS_CONST(r''' | 506 const _fallbackConstructorHooksTransformerGenerator = const JS_CONST(r''' |
512 function(getTagFallback) { | 507 function(getTagFallback) { |
513 return function(hooks) { | 508 return function(hooks) { |
514 // If we are not in a browser, assume we are in d8. | 509 // If we are not in a browser, assume we are in d8. |
515 // TODO(sra): Recognize jsshell. | 510 // TODO(sra): Recognize jsshell. |
516 if (typeof navigator != "object") return hooks; | 511 if (typeof navigator != "object") return hooks; |
517 | 512 |
518 var userAgent = navigator.userAgent; | 513 var ua = navigator.userAgent; |
519 // TODO(antonm): remove a reference to DumpRenderTree. | 514 // TODO(antonm): remove a reference to DumpRenderTree. |
520 if (userAgent.indexOf("Chrome") >= 0 || | 515 if (ua.indexOf("DumpRenderTree") >= 0) return hooks; |
521 userAgent.indexOf("DumpRenderTree") >= 0) { | 516 if (ua.indexOf("Chrome") >= 0) { |
522 return hooks; | 517 // Confirm constructor name is usable for dispatch. |
| 518 function confirm(p) { |
| 519 return typeof window == "object" && window[p] && window[p].name == p; |
| 520 } |
| 521 if (confirm("Window") && confirm("HTMLElement")) return hooks; |
523 } | 522 } |
524 | 523 |
525 hooks.getTag = getTagFallback; | 524 hooks.getTag = getTagFallback; |
526 }; | 525 }; |
527 }'''); | 526 }'''); |
528 | 527 |
529 | 528 |
530 const _ieHooksTransformer = const JS_CONST(r''' | 529 const _ieHooksTransformer = const JS_CONST(r''' |
531 function(hooks) { | 530 function(hooks) { |
532 var userAgent = typeof navigator == "object" ? navigator.userAgent : ""; | 531 var userAgent = typeof navigator == "object" ? navigator.userAgent : ""; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 const _safariHooksTransformer = const JS_CONST(r''' | 604 const _safariHooksTransformer = const JS_CONST(r''' |
606 function(hooks) { return hooks; } | 605 function(hooks) { return hooks; } |
607 '''); | 606 '''); |
608 | 607 |
609 | 608 |
610 const _dartExperimentalFixupGetTagHooksTransformer = const JS_CONST(r''' | 609 const _dartExperimentalFixupGetTagHooksTransformer = const JS_CONST(r''' |
611 function(hooks) { | 610 function(hooks) { |
612 if (typeof dartExperimentalFixupGetTag != "function") return hooks; | 611 if (typeof dartExperimentalFixupGetTag != "function") return hooks; |
613 hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag); | 612 hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag); |
614 }'''); | 613 }'''); |
OLD | NEW |