Chromium Code Reviews| Index: sdk/lib/_internal/lib/native_helper.dart |
| diff --git a/sdk/lib/_internal/lib/native_helper.dart b/sdk/lib/_internal/lib/native_helper.dart |
| index 56c098f07f9473e33dc3e5b7b3d15504335ff2d2..4c66f658aaf7208225c04588f23036b0c8746433 100644 |
| --- a/sdk/lib/_internal/lib/native_helper.dart |
| +++ b/sdk/lib/_internal/lib/native_helper.dart |
| @@ -140,9 +140,33 @@ newJsObject() { |
| } |
| /** |
| - * Returns the function to use to get the type name of an object. |
| + * Cached value for the function to use to get the type name of an |
| + * object. |
| + */ |
| +Function _getTypeNameOf; |
|
ahe
2013/07/24 08:46:18
I would prefer this:
final Function getTypeNameOf
|
| + |
| +/** |
| + * Returns the type name of [obj]. |
| + */ |
| +String getTypeNameOf(var obj) { |
| + if (_getTypeNameOf == null) _getTypeNameOf = getFunctionForTypeNameOf(); |
| + return _getTypeNameOf(obj); |
| +} |
| + |
| +/** |
| + * Returns the function to use to get the type name (i.e. dispatch tag) of an |
| + * object. |
| */ |
| Function getFunctionForTypeNameOf() { |
| + var getTagFunction = _getFunctionForTypeNameOf(); |
| + if (JS('bool', 'typeof dartExperimentalFixupGetTag == "function"')) { |
|
ahe
2013/07/24 08:46:18
Which is better:
if (JS('bool', 'typeof dartExper
sra1
2013/07/25 21:47:09
I thing the first is better since it guarantees th
|
| + return _applyExperimentalFixup( |
| + JS('', 'dartExperimentalFixupGetTag'), getTagFunction); |
| + } |
| + return getTagFunction; |
| +} |
| + |
| +Function _getFunctionForTypeNameOf() { |
|
ahe
2013/07/24 08:46:18
Please don't make stuff private. Library privacy
sra1
2013/07/25 21:47:09
Done.
|
| // If we're not in the browser, we're almost certainly running on v8. |
| if (!identical(JS('String', 'typeof(navigator)'), 'object')) return typeNameInChrome; |
| @@ -167,21 +191,28 @@ Function getFunctionForTypeNameOf() { |
| } |
| } |
| +Function _applyExperimentalFixup(fixupJSFunction, |
|
ahe
2013/07/24 08:46:18
Please don't make stuff private.
sra1
2013/07/25 21:47:09
Done.
|
| + Function originalGetTagFunction) { |
| + // Since DART_CLOSURE_TO_JS works only for top level functions, store the |
| + // closed over JavaScript function in a top level variable and use a top level |
| + // function. This is fine since we have only one instance of the 'closure'. |
| + _getTagJSFunction = originalGetTagFunction; |
|
ahe
2013/07/24 08:46:18
I would prefer this:
var boundClosure =
JS(''
|
| + var newGetTagJSFunction = |
| + JS('', '#(#)', |
| + fixupJSFunction, DART_CLOSURE_TO_JS(_callGetTagJSFunction)); |
| -/** |
| - * Cached value for the function to use to get the type name of an |
| - * object. |
| - */ |
| -Function _getTypeNameOf; |
| + String newGetTagDartFunction(object) => |
| + JS('', '#(#)', newGetTagJSFunction, object); |
| -/** |
| - * Returns the type name of [obj]. |
| - */ |
| -String getTypeNameOf(var obj) { |
| - if (_getTypeNameOf == null) _getTypeNameOf = getFunctionForTypeNameOf(); |
| - return _getTypeNameOf(obj); |
| + return newGetTagDartFunction; |
| } |
| +var _getTagJSFunction; |
|
ahe
2013/07/24 08:46:18
Please don't make stuff private.
sra1
2013/07/25 21:47:09
Done.
|
| +_callGetTagJSFunction(object) => _getTagJSFunction(object); |
|
ahe
2013/07/24 08:46:18
Please don't make stuff private.
sra1
2013/07/25 21:47:09
Done.
|
| + |
| + |
|
ahe
2013/07/24 08:46:18
Extra lines.
sra1
2013/07/25 21:47:09
Done.
|
| + |
| + |
| String toStringForNativeObject(var obj) { |
| String name = JS('String', '#', getTypeNameOf(obj)); |
| return 'Instance of $name'; |