From 9d6914ec72677a4ae5c6ad9cb88c8e5e96c1efb0 Mon Sep 17 00:00:00 2001 From: Kasper Lund Date: Fri, 10 Jan 2014 11:12:33 +0100 Subject: [PATCH] fix(sdk): Add support for Dart SDK 1.1 Start using ClassMirror.instanceMembers (if available) or ClassMirror.declarations (SDK 1.1+). --- .travis.yml | 2 +- lib/core/parser/eval_access.dart | 25 +++++++++++++++---------- lib/core/scope.dart | 4 +++- scripts/travis/setup.sh | 4 +++- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1475751e3..c7e4df576 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ node_js: env: matrix: - JOB=unit-stable - # - JOB=unit-dev + - JOB=unit-dev global: - CHROME_BIN=/usr/bin/google-chrome diff --git a/lib/core/parser/eval_access.dart b/lib/core/parser/eval_access.dart index da3b2246d..0cdcd663b 100644 --- a/lib/core/parser/eval_access.dart +++ b/lib/core/parser/eval_access.dart @@ -132,20 +132,25 @@ abstract class AccessReflective { } static bool hasMember(InstanceMirror mirror, Symbol symbol) { - var type = mirror.type as dynamic; - var members = useInstanceMembers ? type.instanceMembers : type.members; - return members.containsKey(symbol); + return hasMethodHelper(mirror.type, symbol); } - static final bool useInstanceMembers = computeUseInstanceMembers(); - static bool computeUseInstanceMembers() { + static final Function hasMethodHelper = (() { + var objectType = reflect(Object).type; try { - reflect(Object).type.instanceMembers; - return true; - } catch (e) { - return false; + // Use ClassMirror.instanceMembers if available. It contains local + // as well as inherited members. + objectType.instanceMembers; + return (type, symbol) => type.instanceMembers[symbol] is MethodMirror; + } on NoSuchMethodError catch (e) { + // For SDK 1.0 we fall back to just using the local members. + return (type, symbol) => type.members[symbol] is MethodMirror; + } on UnimplementedError catch (e) { + // For SDK 1.1 we fall back to just using the local declarations. + return (type, symbol) => type.declarations[symbol] is MethodMirror; } - } + return null; + })(); } /** diff --git a/lib/core/scope.dart b/lib/core/scope.dart index 08b60ff37..b24fa1676 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -870,7 +870,9 @@ _toJson(obj) { // work-around dartbug.com/14130 try { ret = mirror.function.source; - } on NoSuchMethodError catch (e) {} + } on NoSuchMethodError catch (e) { + } on UnimplementedError catch (e) { + } } return true; })()); diff --git a/scripts/travis/setup.sh b/scripts/travis/setup.sh index d9f1c30e3..9836cbd2f 100755 --- a/scripts/travis/setup.sh +++ b/scripts/travis/setup.sh @@ -16,13 +16,15 @@ esac CHANNEL=`echo $JOB | cut -f 2 -d -` echo Fetch Dart channel: $CHANNEL +echo http://storage.googleapis.com/dart-archive/channels/$CHANNEL/release/latest/sdk/$DART_SDK_ZIP curl http://storage.googleapis.com/dart-archive/channels/$CHANNEL/release/latest/sdk/$DART_SDK_ZIP > $DART_SDK_ZIP echo Fetched new dart version $(unzip -p $DART_SDK_ZIP dart-sdk/version) rm -rf dart-sdk unzip $DART_SDK_ZIP > /dev/null rm $DART_SDK_ZIP -curl http://storage.googleapis.com/dart-archive/channels/$CHANNEL/release/latest/dartium/$DARTIUM_ZIP > $DARTIUM_ZIP +echo http://storage.googleapis.com/dart-archive/channels/$CHANNEL/raw/latest/dartium/$DARTIUM_ZIP +curl http://storage.googleapis.com/dart-archive/channels/$CHANNEL/raw/latest/dartium/$DARTIUM_ZIP > $DARTIUM_ZIP unzip $DARTIUM_ZIP > /dev/null rm -rf dartium rm $DARTIUM_ZIP