Chromium Code Reviews| Index: frog/corejs.dart |
| diff --git a/frog/corejs.dart b/frog/corejs.dart |
| index 9df6b77b3939b993c9f658193a893c4593047e42..424cabae74c7d0416901609c5cc71c176a01b420 100644 |
| --- a/frog/corejs.dart |
| +++ b/frog/corejs.dart |
| @@ -389,30 +389,55 @@ function $dynamicSetMetadata(inputTable) { |
| /** Snippet for `$typeNameOf`. */ |
| final String _TYPE_NAME_OF_FUNCTION = @""" |
| -$defProp(Object.prototype, '$typeNameOf', function() { |
| - var constructor = this.constructor; |
| - if (typeof(constructor) == 'function') { |
| - // The constructor isn't null or undefined at this point. Try |
| - // to grab hold of its name. |
| - var name = constructor.name; |
| - // If the name is a non-empty string, we use that as the type |
| - // name of this object. On Firefox, we often get 'Object' as |
| - // the constructor name even for more specialized objects so |
| - // we have to fall through to the toString() based implementation |
| - // below in that case. |
| - if (name && typeof(name) == 'string' && name != 'Object') return name; |
| +$defProp(Object.prototype, '$typeNameOf', (function() { |
| + function constructorNameWithFallback(obj) { |
| + var constructor = obj.constructor; |
| + if (typeof(constructor) == 'function') { |
| + // The constructor isn't null or undefined at this point. Try |
| + // to grab hold of its name. |
| + var name = constructor.name; |
| + // If the name is a non-empty string, we use that as the type |
| + // name of this object. On Firefox, we often get 'Object' as |
| + // the constructor name even for more specialized objects so |
| + // we have to fall through to the toString() based implementation |
| + // below in that case. |
| + if (name && typeof(name) == 'string' && name != 'Object') return name; |
|
sra1
2012/02/29 01:28:55
Nit: I'd put typeof first (assuming name && is pro
nweiz
2012/02/29 01:54:28
Done.
|
| + } |
| + var string = Object.prototype.toString.call(obj); |
| + return string.substring(8, string.length - 1); |
| } |
| - var string = Object.prototype.toString.call(this); |
| - var name = string.substring(8, string.length - 1); |
| - if (name == 'Window') { |
| - name = 'DOMWindow'; |
| - } else if (name == 'Document') { |
| - name = 'HTMLDocument'; |
| - } else if (name == 'XMLDocument') { |
| - name = 'Document'; |
| + |
| + // If we're not in the browser, we don't have to worry about any compatibility |
| + // headaches. |
| + if (typeof(navigator) != 'object') { |
|
sra1
2012/02/29 01:28:55
Nit: typeof is an operator and does not need paren
nweiz
2012/02/29 01:54:28
I believe the style is to use parens with typeof.
|
| + return function() { return this.constructor.name; }; |
| } |
| - return name; |
| -});"""; |
| + |
| + var userAgent = navigator.userAgent; |
| + if (/Chrome/.test(userAgent)) { |
| + return function() { return this.constructor.name; }; |
|
sra1
2012/02/29 01:28:55
This function occurs twice.
Which makes me think a
nweiz
2012/02/29 01:54:28
Done.
|
| + } else if (/Firefox/.test(userAgent)) { |
| + return function() { |
| + var name = constructorNameWithFallback(this); |
| + if (name == 'Window') return 'DOMWindow'; |
| + if (name == 'Document') return 'HTMLDocument'; |
| + if (name == 'XMLDocument') return 'Document'; |
| + return name; |
| + }; |
| + } else if (/MSIE/.test(userAgent)) { |
| + return function() { |
| + var name = constructorNameWithFallback(this); |
| + if (name == 'Window') return 'DOMWindow'; |
| + // IE calls both HTML and XML documents 'Document', so we check for the |
| + // xmlVersion property, which is the empty string on HTML documents. |
| + if (name == 'Document' && this.xmlVersion) return 'Document'; |
| + if (name == 'Document') return 'HTMLDocument'; |
| + return name; |
| + }; |
| + } else { |
| + return function() { return constructorNameWithFallback(this); }; |
| + } |
| +})());"""; |
| /** Snippet for `$inherits`. */ |
| final String _INHERITS_FUNCTION = @""" |