Moved some MethodMirror getters from embedded API to lazy native calls.

The more complex ones (creating LazyXXXMirror) are still left and will be handled in a separate CL.

Tests are (still) excluded from dart2js, because of one regression test in the same file.

BUG=
R=asiva@google.com

Review URL: https://codereview.chromium.org//19299003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25081 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
mlippautz@google.com 2013-07-17 00:42:30 +00:00
parent 962d3fddb6
commit 8b65384ede
4 changed files with 99 additions and 56 deletions

View file

@ -559,69 +559,37 @@ static Dart_Handle CreateClassMirror(Dart_Handle intf,
static Dart_Handle CreateMethodMirror(Dart_Handle func,
Dart_Handle owner_mirror) {
ASSERT(Dart_IsFunction(func));
// TODO(11742): Unwrapping is needed until the whole method is converted.
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
const Function& func_obj = Api::UnwrapFunctionHandle(isolate, func);
Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl");
Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL);
if (Dart_IsError(mirror_type)) {
return mirror_type;
}
bool is_static = false;
bool is_abstract = false;
bool is_getter = false;
bool is_setter = false;
bool is_constructor = false;
Dart_Handle result = Dart_FunctionIsStatic(func, &is_static);
if (Dart_IsError(result)) {
return result;
}
result = Dart_FunctionIsAbstract(func, &is_abstract);
if (Dart_IsError(result)) {
return result;
}
result = Dart_FunctionIsGetter(func, &is_getter);
if (Dart_IsError(result)) {
return result;
}
result = Dart_FunctionIsSetter(func, &is_setter);
if (Dart_IsError(result)) {
return result;
}
result = Dart_FunctionIsConstructor(func, &is_constructor);
if (Dart_IsError(result)) {
return result;
}
Dart_Handle return_type = Dart_FunctionReturnType(func);
if (Dart_IsError(return_type)) {
return return_type;
}
int64_t fixed_param_count;
int64_t opt_param_count;
result = Dart_FunctionParameterCounts(func,
&fixed_param_count,
&opt_param_count);
if (Dart_IsError(result)) {
return result;
}
// TODO(turnidge): Implement constructor kinds (arguments 7 - 10).
Dart_Handle args[] = {
CreateMirrorReference(func),
owner_mirror,
CreateParameterMirrorList(func),
CreateLazyMirror(return_type),
Dart_NewBoolean(is_static),
Dart_NewBoolean(is_abstract),
Dart_NewBoolean(is_getter),
Dart_NewBoolean(is_setter),
Dart_NewBoolean(is_constructor),
Dart_False(),
Dart_False(),
Dart_False(),
Dart_False(),
func_obj.is_static() ? Api::True() : Api::False(),
func_obj.is_abstract() ? Api::True() : Api::False(),
func_obj.IsGetterFunction() ? Api::True() : Api::False(),
func_obj.IsSetterFunction() ? Api::True() : Api::False(),
func_obj.IsConstructor() ? Api::True() : Api::False(),
Api::False(),
Api::False(),
Api::False(),
Api::False()
};
Dart_Handle mirror =
Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args);

View file

@ -4,7 +4,8 @@
[ $compiler == dart2js ]
math/*: Skip
mirrors/method_mirror_test: Fail # Issue 6335
mirrors/method_mirror_name_test: Fail # Issue 6335
mirrors/method_mirror_properties_test: Fail # Issue 11861
mirrors/mirrors_test: Fail # TODO(ahe): I'm working on fixing this.
mirrors/library_uri_io_test: Skip # Not intended for dart2js as it uses dart:io.
async/run_async3_test: Fail # _enqueueImmediate runs after Timer. http://dartbug.com/9002

View file

@ -4,18 +4,14 @@
import "dart:mirrors";
import "../../../pkg/unittest/lib/unittest.dart";
String _symbolToString(Symbol sym) {
return MirrorSystem.getName(sym);
}
import "package:expect/expect.dart";
import "stringify.dart";
doNothing42() {}
main() {
// Regression test for http://www.dartbug.com/6335
test("NamedMethodName", () {
var closureMirror = reflect(doNothing42);
expect(_symbolToString(closureMirror.function.simpleName), "doNothing42");
});
var closureMirror = reflect(doNothing42);
Expect.equals(stringifySymbol(closureMirror.function.simpleName),
"s(doNothing42)");
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:mirrors";
import "package:expect/expect.dart";
doNothing42() {}
int _x = 5;
int get topGetter => _x;
void set topSetter(x) { _x = x; }
class AbstractC {
AbstractC();
void bar();
get priv;
set priv(value);
}
class C extends AbstractC {
static foo() {}
C();
C.other();
C.other2() : this.other();
var _priv;
get priv => _priv;
set priv(value) => _priv = value;
}
checkKinds(method, kinds) {
Expect.equals(method.isStatic, kinds[0]);
Expect.equals(method.isAbstract, kinds[1]);
Expect.equals(method.isGetter, kinds[2]);
Expect.equals(method.isSetter, kinds[3]);
Expect.equals(method.isConstructor, kinds[4]);
}
main() {
// Top level functions should be static.
var closureMirror = reflect(doNothing42);
checkKinds(closureMirror.function,
[true, false, false, false, false]);
var libraryMirror = reflectClass(C).owner;
checkKinds(libraryMirror.getters[const Symbol("topGetter")],
[true, false, true, false, false]);
checkKinds(libraryMirror.setters[const Symbol("topSetter=")],
[true, false, false, true, false]);
var classMirror;
classMirror = reflectClass(C);
checkKinds(classMirror.members[const Symbol("foo")],
[true, false, false, false, false]);
checkKinds(classMirror.members[const Symbol("priv")],
[false, false, true, false, false]);
checkKinds(classMirror.members[const Symbol("priv=")],
[false, false, false, true, false]);
checkKinds(classMirror.constructors[const Symbol("C")],
[false, false, false, false, true]);
checkKinds(classMirror.constructors[const Symbol("C.other")],
[false, false, false, false, true]);
checkKinds(classMirror.constructors[const Symbol("C.other2")],
[false, false, false, false, true]);
classMirror = reflectClass(AbstractC);
checkKinds(classMirror.constructors[const Symbol("AbstractC")],
[false, false, false, false, true]);
checkKinds(classMirror.members[const Symbol("bar")],
[false, true, false, false, false]);
checkKinds(classMirror.members[const Symbol("priv")],
[false, true, true, false, false]);
checkKinds(classMirror.members[const Symbol("priv=")],
[false, true, false, true, false]);
}