Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 21623004: Remove unused functions from dart_mirrors_api. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/include/dart_mirrors_api.h ('k') | runtime/vm/mirrors_api_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
===================================================================
--- runtime/vm/dart_api_impl_test.cc (revision 25717)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -2694,54 +2694,6 @@
}
-TEST_CASE(ClassTypedefsEtc) {
- const char* kScriptChars =
- "class SomeClass {\n"
- "}\n"
- "typedef void SomeHandler(String a);\n";
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- EXPECT_VALID(lib);
- Dart_Handle normal_cls = Dart_GetClass(lib, NewString("SomeClass"));
- EXPECT_VALID(normal_cls);
- Dart_Handle typedef_cls = Dart_GetClass(lib, NewString("SomeHandler"));
- EXPECT_VALID(typedef_cls);
-
- EXPECT(Dart_IsClass(normal_cls));
- EXPECT(!Dart_ClassIsTypedef(normal_cls));
- EXPECT(!Dart_ClassIsFunctionType(normal_cls));
-
- EXPECT(Dart_IsClass(typedef_cls));
- EXPECT(Dart_ClassIsTypedef(typedef_cls));
- EXPECT(!Dart_ClassIsFunctionType(typedef_cls));
-
- // Exercise the typedef class api.
- Dart_Handle functype_cls = Dart_ClassGetTypedefReferent(typedef_cls);
- EXPECT_VALID(functype_cls);
-
- // Pass the wrong class kind to Dart_ClassGetTypedefReferent
- EXPECT_ERROR(Dart_ClassGetTypedefReferent(normal_cls),
- "class 'SomeClass' is not a typedef class.");
-
- EXPECT(Dart_IsClass(functype_cls));
- EXPECT(!Dart_ClassIsTypedef(functype_cls));
- EXPECT(Dart_ClassIsFunctionType(functype_cls));
-
- // Exercise the function type class.
- Dart_Handle sig_func = Dart_ClassGetFunctionTypeSignature(functype_cls);
- EXPECT_VALID(sig_func);
- EXPECT(Dart_IsFunction(sig_func));
- int64_t fixed_params = -1;
- int64_t opt_params = -1;
- EXPECT_VALID(
- Dart_FunctionParameterCounts(sig_func, &fixed_params, &opt_params));
- EXPECT_EQ(1, fixed_params);
- EXPECT_EQ(0, opt_params);
-
- // Pass the wrong class kind to Dart_ClassGetFunctionTypeSignature
- EXPECT_ERROR(Dart_ClassGetFunctionTypeSignature(normal_cls),
- "class 'SomeClass' is not a function-type class.");
-}
-
#define CHECK_CLASS(handle, name) \
{ \
Dart_Handle tmp = (handle); \
@@ -2755,73 +2707,6 @@
}
-TEST_CASE(ClassGetInterfaces) {
- const char* kScriptChars =
- "class MyClass0 {\n"
- "}\n"
- "\n"
- "class MyClass1 implements MyInterface1 {\n"
- "}\n"
- "\n"
- "class MyClass2 implements MyInterface0, MyInterface1 {\n"
- "}\n"
- "\n"
- "abstract class MyInterface0 {\n"
- "}\n"
- "\n"
- "abstract class MyInterface1 implements MyInterface0 {\n"
- "}\n";
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
-
- Dart_Handle cls0 = Dart_GetClass(lib, NewString("MyClass0"));
- Dart_Handle cls1 = Dart_GetClass(lib, NewString("MyClass1"));
- Dart_Handle cls2 = Dart_GetClass(lib, NewString("MyClass2"));
- Dart_Handle intf0 = Dart_GetClass(lib, NewString("MyInterface0"));
- Dart_Handle intf1 = Dart_GetClass(lib, NewString("MyInterface1"));
-
- intptr_t len = -1;
- EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len));
- EXPECT_EQ(0, len);
-
- EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls0, 0),
- "Dart_ClassGetInterfaceAt: argument 'index' out of bounds");
-
- len = -1;
- EXPECT_VALID(Dart_ClassGetInterfaceCount(cls1, &len));
- EXPECT_EQ(1, len);
- CHECK_CLASS(Dart_ClassGetInterfaceAt(cls1, 0), "MyInterface1");
-
- EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, -1),
- "Dart_ClassGetInterfaceAt: argument 'index' out of bounds");
- EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, 1),
- "Dart_ClassGetInterfaceAt: argument 'index' out of bounds");
-
- len = -1;
- EXPECT_VALID(Dart_ClassGetInterfaceCount(cls2, &len));
- EXPECT_EQ(2, len);
-
- // TODO(turnidge): The test relies on the ordering here. Sort this.
- CHECK_CLASS(Dart_ClassGetInterfaceAt(cls2, 0), "MyInterface0");
- CHECK_CLASS(Dart_ClassGetInterfaceAt(cls2, 1), "MyInterface1");
-
- len = -1;
- EXPECT_VALID(Dart_ClassGetInterfaceCount(intf0, &len));
- EXPECT_EQ(0, len);
-
- len = -1;
- EXPECT_VALID(Dart_ClassGetInterfaceCount(intf1, &len));
- EXPECT_EQ(1, len);
- CHECK_CLASS(Dart_ClassGetInterfaceAt(intf1, 0), "MyInterface0");
-
- // Error cases.
- EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_True(), &len),
- "Dart_ClassGetInterfaceCount expects argument 'object' to be of "
- "type Class/Type.");
- EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_NewApiError("MyError"), &len),
- "MyError");
-}
-
-
TEST_CASE(TypeGetNonParamtericTypes) {
const char* kScriptChars =
"class MyClass0 {\n"
@@ -4396,187 +4281,7 @@
"did not find top-level function '_imported'");
}
-TEST_CASE(ClosureFunction) {
- const char* kScriptChars =
- "Function getClosure() {\n"
- " return (x, y, [z]) => x + y + z;\n"
- "}\n"
- "class Foo {\n"
- " getInstanceClosure() {\n"
- " return () { return this; };\n"
- " }\n"
- " getInstanceClosureWithArgs() {\n"
- " return (x, y, [z]) { return this; };\n"
- " }\n"
- " static getStaticClosure() {\n"
- " return () { return 42; };\n"
- " }\n"
- " static getStaticClosureWithArgs() {\n"
- " return (x, y, [z]) { return 42; };\n"
- " }\n"
- "}\n"
- "Function getInstanceClosure() {\n"
- " return new Foo().getInstanceClosure();\n"
- "}\n"
- "Function getInstanceClosureWithArgs() {\n"
- " return new Foo().getInstanceClosureWithArgs();\n"
- "}\n"
- "Function getStaticClosure() {\n"
- " return Foo.getStaticClosure();\n"
- "}\n"
- "Function getStaticClosureWithArgs() {\n"
- " return Foo.getStaticClosureWithArgs();\n"
- "}\n";
- Dart_Handle result;
- Dart_Handle owner;
- Dart_Handle defining_function;
- DARTSCOPE(Isolate::Current());
- // Create a test library and Load up a test script in it.
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- EXPECT_VALID(lib);
- Dart_Handle type = Dart_GetType(lib, NewString("Foo"), 0, NULL);
- EXPECT_VALID(type);
-
- // Invoke a function which returns a closure.
- Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL);
- EXPECT_VALID(retobj);
-
- EXPECT(Dart_IsClosure(retobj));
- EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
-
- // Retrieve the closure's function
- result = Dart_ClosureFunction(retobj);
- EXPECT_VALID(result);
- EXPECT(Dart_IsFunction(result));
- owner = Dart_FunctionOwner(result);
- EXPECT_VALID(owner);
- defining_function = Dart_LookupFunction(lib, NewString("getClosure"));
- EXPECT(Dart_IdentityEquals(owner, defining_function));
- int64_t fixed_param_count = -999;
- int64_t opt_param_count = -999;
- result = Dart_FunctionParameterCounts(result,
- &fixed_param_count,
- &opt_param_count);
- EXPECT_VALID(result);
- EXPECT_EQ(2, fixed_param_count);
- EXPECT_EQ(1, opt_param_count);
-
- // Try to retrieve function from a non-closure object
- result = Dart_ClosureFunction(Dart_NewInteger(1));
- EXPECT(Dart_IsError(result));
-
- // Invoke a function which returns an "instance" closure.
- retobj = Dart_Invoke(lib, NewString("getInstanceClosure"), 0, NULL);
- EXPECT_VALID(retobj);
- EXPECT(Dart_IsClosure(retobj));
-
- // Retrieve the closure's function
- result = Dart_ClosureFunction(retobj);
- EXPECT_VALID(result);
- EXPECT(Dart_IsFunction(result));
- owner = Dart_FunctionOwner(result);
- EXPECT_VALID(owner);
- Isolate* isolate = Isolate::Current();
- Dart_Handle cls = Api::NewHandle(
- isolate, Api::UnwrapTypeHandle(isolate, type).type_class());
- defining_function = Dart_LookupFunction(cls,
- NewString("getInstanceClosure"));
- EXPECT(Dart_IdentityEquals(owner, defining_function));
- // -999: We want to distinguish between a non-answer and a wrong answer, and
- // -1 has been a previous wrong answer
- fixed_param_count = -999;
- opt_param_count = -999;
- result = Dart_FunctionParameterCounts(result,
- &fixed_param_count,
- &opt_param_count);
- EXPECT_VALID(result);
- EXPECT_EQ(0, fixed_param_count);
- EXPECT_EQ(0, opt_param_count);
-
- // Invoke a function which returns an "instance" closure with arguments.
- retobj = Dart_Invoke(lib,
- NewString("getInstanceClosureWithArgs"),
- 0,
- NULL);
- EXPECT_VALID(retobj);
- EXPECT(Dart_IsClosure(retobj));
-
- // Retrieve the closure's function
- result = Dart_ClosureFunction(retobj);
- EXPECT_VALID(result);
- EXPECT(Dart_IsFunction(result));
- owner = Dart_FunctionOwner(result);
- EXPECT_VALID(owner);
- defining_function =
- Dart_LookupFunction(cls, NewString("getInstanceClosureWithArgs"));
- EXPECT(Dart_IdentityEquals(owner, defining_function));
- // -999: We want to distinguish between a non-answer and a wrong answer, and
- // -1 has been a previous wrong answer
- fixed_param_count = -999;
- opt_param_count = -999;
- result = Dart_FunctionParameterCounts(result,
- &fixed_param_count,
- &opt_param_count);
- EXPECT_VALID(result);
- EXPECT_EQ(2, fixed_param_count);
- EXPECT_EQ(1, opt_param_count);
-
- // Invoke a function which returns a "static" closure.
- retobj = Dart_Invoke(lib, NewString("getStaticClosure"), 0, NULL);
- EXPECT_VALID(retobj);
- EXPECT(Dart_IsClosure(retobj));
-
- // Retrieve the closure's function
- result = Dart_ClosureFunction(retobj);
- EXPECT_VALID(result);
- EXPECT(Dart_IsFunction(result));
- owner = Dart_FunctionOwner(result);
- EXPECT_VALID(owner);
- defining_function = Dart_LookupFunction(cls,
- NewString("getStaticClosure"));
- EXPECT(Dart_IdentityEquals(owner, defining_function));
- // -999: We want to distinguish between a non-answer and a wrong answer, and
- // -1 has been a previous wrong answer
- fixed_param_count = -999;
- opt_param_count = -999;
- result = Dart_FunctionParameterCounts(result,
- &fixed_param_count,
- &opt_param_count);
- EXPECT_VALID(result);
- EXPECT_EQ(0, fixed_param_count);
- EXPECT_EQ(0, opt_param_count);
-
-
- // Invoke a function which returns a "static" closure with arguments.
- retobj = Dart_Invoke(lib,
- NewString("getStaticClosureWithArgs"),
- 0,
- NULL);
- EXPECT_VALID(retobj);
- EXPECT(Dart_IsClosure(retobj));
-
- // Retrieve the closure's function
- result = Dart_ClosureFunction(retobj);
- EXPECT_VALID(result);
- EXPECT(Dart_IsFunction(result));
- owner = Dart_FunctionOwner(result);
- EXPECT_VALID(owner);
- defining_function =
- Dart_LookupFunction(cls, NewString("getStaticClosureWithArgs"));
- EXPECT(Dart_IdentityEquals(owner, defining_function));
- // -999: We want to distinguish between a non-answer and a wrong answer, and
- // -1 has been a previous wrong answer
- fixed_param_count = -999;
- opt_param_count = -999;
- result = Dart_FunctionParameterCounts(result,
- &fixed_param_count,
- &opt_param_count);
- EXPECT_VALID(result);
- EXPECT_EQ(2, fixed_param_count);
- EXPECT_EQ(1, opt_param_count);
-}
-
TEST_CASE(InvokeClosure) {
const char* kScriptChars =
"class InvokeClosure {\n"
@@ -4772,684 +4477,6 @@
}
-static void BuildFunctionDescription(TextBuffer* buffer, Dart_Handle func) {
- buffer->Clear();
- if (Dart_IsNull(func)) {
- WARN("Function not found");
- return;
- }
- Dart_Handle name = Dart_FunctionName(func);
- EXPECT_VALID(name);
- const char* name_cstr = "";
- EXPECT_VALID(Dart_StringToCString(name, &name_cstr));
- bool is_abstract = false;
- bool is_static = false;
- bool is_getter = false;
- bool is_setter = false;
- bool is_constructor = false;
- int64_t fixed_param_count = -1;
- int64_t opt_param_count = -1;
- EXPECT_VALID(Dart_FunctionIsAbstract(func, &is_abstract));
- EXPECT_VALID(Dart_FunctionIsStatic(func, &is_static));
- EXPECT_VALID(Dart_FunctionIsGetter(func, &is_getter));
- EXPECT_VALID(Dart_FunctionIsSetter(func, &is_setter));
- EXPECT_VALID(Dart_FunctionIsConstructor(func, &is_constructor));
- EXPECT_VALID(Dart_FunctionParameterCounts(func,
- &fixed_param_count, &opt_param_count));
-
- buffer->Printf("%s %"Pd64" %"Pd64"",
- name_cstr,
- fixed_param_count,
- opt_param_count);
- if (is_abstract) {
- buffer->Printf(" abstract");
- }
- if (is_static) {
- buffer->Printf(" static");
- }
- if (is_getter) {
- buffer->Printf(" getter");
- }
- if (is_setter) {
- buffer->Printf(" setter");
- }
- if (is_constructor) {
- buffer->Printf(" constructor");
- }
-}
-
-
-TEST_CASE(FunctionReflection) {
- const char* kScriptChars =
- "a() => 'a';\n"
- "_b() => '_b';\n"
- "get c => 'bar';\n"
- "set d(x) {}\n"
- "get _e => 'bar';\n"
- "set _f(x) {}\n"
- "class MyClass {\n"
- " MyClass() {}\n"
- " MyClass.named() {}\n"
- " a() => 'a';\n"
- " _b() => '_b';\n"
- " get c => 'bar';\n"
- " set d(x) {}\n"
- " get _e => 'bar';\n"
- " set _f(x) {}\n"
- " static g() => 'g';\n"
- " static _h() => '_h';\n"
- " static get i => 'i';\n"
- " static set j(x) {}\n"
- " static get _k => 'k';\n"
- " static set _l(x) {}\n"
- " m();\n"
- " _n();\n"
- " get o;\n"
- " set p(x);\n"
- " get _q;\n"
- " set _r(x);\n"
- " s(x, [y, z]) {}\n"
- " t([x, y, z]) {}\n"
- " operator ==(x) {}\n"
- "}\n"
- "class _PrivateClass {\n"
- " _PrivateClass() {}\n"
- " _PrivateClass.named() {}\n"
- "}\n";
-
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- EXPECT_VALID(lib);
- Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass"));
- EXPECT_VALID(cls);
- Dart_Handle private_cls = Dart_GetClass(lib, NewString("_PrivateClass"));
- EXPECT_VALID(private_cls);
- TextBuffer buffer(128);
-
- // Lookup a top-level function.
- Dart_Handle func = Dart_LookupFunction(lib, NewString("a"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("a 0 0 static", buffer.buf());
- EXPECT(Dart_IsLibrary(Dart_FunctionOwner(func)));
- Dart_Handle owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, lib));
-
- // Lookup a private top-level function.
- func = Dart_LookupFunction(lib, NewString("_b"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_b 0 0 static", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, lib));
-
- // Lookup a top-level getter.
- func = Dart_LookupFunction(lib, NewString("c"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("c 0 0 static getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, lib));
-
- // Lookup a top-level setter.
- func = Dart_LookupFunction(lib, NewString("d="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("d= 1 0 static setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, lib));
-
- // Lookup a private top-level getter.
- func = Dart_LookupFunction(lib, NewString("_e"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_e 0 0 static getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, lib));
-
- // Lookup a private top-level setter.
- func = Dart_LookupFunction(lib, NewString("_f="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_f= 1 0 static setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, lib));
-
- // Lookup an unnamed constructor
- func = Dart_LookupFunction(cls, NewString("MyClass"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("MyClass 0 0 constructor", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a named constructor
- func = Dart_LookupFunction(cls, NewString("MyClass.named"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("MyClass.named 0 0 constructor", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup an private unnamed constructor
- func = Dart_LookupFunction(private_cls, NewString("_PrivateClass"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_PrivateClass 0 0 constructor", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, private_cls));
-
- // Lookup a private named constructor
- func = Dart_LookupFunction(private_cls,
- NewString("_PrivateClass.named"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_PrivateClass.named 0 0 constructor", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, private_cls));
-
- // Lookup a method.
- func = Dart_LookupFunction(cls, NewString("a"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("a 0 0", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private method.
- func = Dart_LookupFunction(cls, NewString("_b"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_b 0 0", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a instance getter.
- func = Dart_LookupFunction(cls, NewString("c"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("c 0 0 getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a instance setter.
- func = Dart_LookupFunction(cls, NewString("d="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("d= 1 0 setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private instance getter.
- func = Dart_LookupFunction(cls, NewString("_e"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_e 0 0 getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private instance setter.
- func = Dart_LookupFunction(cls, NewString("_f="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_f= 1 0 setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a static method.
- func = Dart_LookupFunction(cls, NewString("g"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("g 0 0 static", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private static method.
- func = Dart_LookupFunction(cls, NewString("_h"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_h 0 0 static", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a static getter.
- func = Dart_LookupFunction(cls, NewString("i"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("i 0 0 static getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a static setter.
- func = Dart_LookupFunction(cls, NewString("j="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("j= 1 0 static setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private static getter.
- func = Dart_LookupFunction(cls, NewString("_k"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_k 0 0 static getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private static setter.
- func = Dart_LookupFunction(cls, NewString("_l="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_l= 1 0 static setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup an abstract method.
- func = Dart_LookupFunction(cls, NewString("m"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("m 0 0 abstract", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private abstract method.
- func = Dart_LookupFunction(cls, NewString("_n"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_n 0 0 abstract", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a abstract getter.
- func = Dart_LookupFunction(cls, NewString("o"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("o 0 0 abstract getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a abstract setter.
- func = Dart_LookupFunction(cls, NewString("p="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("p= 1 0 abstract setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private abstract getter.
- func = Dart_LookupFunction(cls, NewString("_q"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_q 0 0 abstract getter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a private abstract setter.
- func = Dart_LookupFunction(cls, NewString("_r="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("_r= 1 0 abstract setter", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a method with fixed and optional parameters.
- func = Dart_LookupFunction(cls, NewString("s"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("s 1 2", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a method with only optional parameters.
- func = Dart_LookupFunction(cls, NewString("t"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("t 0 3", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup an operator
- func = Dart_LookupFunction(cls, NewString("=="));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
- BuildFunctionDescription(&buffer, func);
- EXPECT_STREQ("== 1 0", buffer.buf());
- owner = Dart_FunctionOwner(func);
- EXPECT_VALID(owner);
- EXPECT(Dart_IdentityEquals(owner, cls));
-
- // Lookup a function that does not exist from a library.
- func = Dart_LookupFunction(lib, NewString("DoesNotExist"));
- EXPECT(Dart_IsNull(func));
-
- // Lookup a function that does not exist from a class.
- func = Dart_LookupFunction(cls, NewString("DoesNotExist"));
- EXPECT(Dart_IsNull(func));
-
- // Lookup a class using an error class name. The error propagates.
- func = Dart_LookupFunction(cls, Api::NewError("myerror"));
- EXPECT_ERROR(func, "myerror");
-
- // Lookup a class from an error library. The error propagates.
- func = Dart_LookupFunction(Api::NewError("myerror"), NewString("foo"));
- EXPECT_ERROR(func, "myerror");
-}
-
-
-TEST_CASE(TypeReflection) {
- const char* kScriptChars =
- "void func(String a, int b) {}\n"
- "int variable;\n";
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- EXPECT_VALID(lib);
-
- Dart_Handle func = Dart_LookupFunction(lib, NewString("func"));
- EXPECT_VALID(func);
- EXPECT(Dart_IsFunction(func));
-
- // Make sure parameter counts are right.
- int64_t fixed_params = -1;
- int64_t opt_params = -1;
- EXPECT_VALID(Dart_FunctionParameterCounts(func, &fixed_params, &opt_params));
- EXPECT_EQ(2, fixed_params);
- EXPECT_EQ(0, opt_params);
-
- // Check the return type.
- Dart_Handle type = Dart_FunctionReturnType(func);
- EXPECT_VALID(type);
- Dart_Handle cls_name = Dart_ClassName(type);
- EXPECT_VALID(cls_name);
- const char* cls_name_cstr = "";
- EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr));
- EXPECT_STREQ("void", cls_name_cstr);
-
- // Check a parameter type.
- type = Dart_FunctionParameterType(func, 0);
- EXPECT_VALID(type);
- cls_name = Dart_ClassName(type);
- EXPECT_VALID(cls_name);
- cls_name_cstr = "";
- EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr));
- EXPECT_STREQ("String", cls_name_cstr);
-
- Dart_Handle var = Dart_LookupVariable(lib, NewString("variable"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
-
- // Check the variable type.
- type = Dart_VariableType(var);
- EXPECT_VALID(type);
- cls_name = Dart_ClassName(type);
- EXPECT_VALID(cls_name);
- cls_name_cstr = "";
- EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr));
- if (FLAG_enable_type_checks) {
- EXPECT_STREQ("int", cls_name_cstr);
- } else {
- EXPECT_STREQ("dynamic", cls_name_cstr);
- }
-}
-
-
-static void BuildVariableDescription(TextBuffer* buffer, Dart_Handle var) {
- buffer->Clear();
- Dart_Handle name = Dart_VariableName(var);
- EXPECT_VALID(name);
- const char* name_cstr = "";
- EXPECT_VALID(Dart_StringToCString(name, &name_cstr));
- bool is_static = false;
- bool is_final = false;
- EXPECT_VALID(Dart_VariableIsStatic(var, &is_static));
- EXPECT_VALID(Dart_VariableIsFinal(var, &is_final));
- buffer->Printf("%s", name_cstr);
- if (is_static) {
- buffer->Printf(" static");
- }
- if (is_final) {
- buffer->Printf(" final");
- }
-}
-
-
-TEST_CASE(VariableReflection) {
- const char* kScriptChars =
- "var a = 'a';\n"
- "var _b = '_b';\n"
- "final c = 'c';\n"
- "final _d = '_d';\n"
- "class MyClass {\n"
- " var a = 'a';\n"
- " var _b = '_b';\n"
- " final c = 'c';\n"
- " final _d = '_d';\n"
- " static var e = 'e';\n"
- " static var _f = '_f';\n"
- " static const g = 'g';\n"
- " static const _h = '_h';\n"
- "}\n";
-
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- EXPECT_VALID(lib);
- Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass"));
- EXPECT_VALID(cls);
- TextBuffer buffer(128);
-
- // Lookup a top-level variable.
- Dart_Handle var = Dart_LookupVariable(lib, NewString("a"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("a static", buffer.buf());
-
- // Lookup a private top-level variable.
- var = Dart_LookupVariable(lib, NewString("_b"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("_b static", buffer.buf());
-
- // Lookup a const top-level variable.
- var = Dart_LookupVariable(lib, NewString("c"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("c static final", buffer.buf());
-
- // Lookup a private const top-level variable.
- var = Dart_LookupVariable(lib, NewString("_d"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("_d static final", buffer.buf());
-
- // Lookup a instance variable.
- var = Dart_LookupVariable(cls, NewString("a"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("a", buffer.buf());
-
- // Lookup a private instance variable.
- var = Dart_LookupVariable(cls, NewString("_b"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("_b", buffer.buf());
-
- // Lookup a final instance variable.
- var = Dart_LookupVariable(cls, NewString("c"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("c final", buffer.buf());
-
- // Lookup a private final instance variable.
- var = Dart_LookupVariable(cls, NewString("_d"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("_d final", buffer.buf());
-
- // Lookup a static variable.
- var = Dart_LookupVariable(cls, NewString("e"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("e static", buffer.buf());
-
- // Lookup a private static variable.
- var = Dart_LookupVariable(cls, NewString("_f"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("_f static", buffer.buf());
-
- // Lookup a const static variable.
- var = Dart_LookupVariable(cls, NewString("g"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("g static final", buffer.buf());
-
- // Lookup a private const static variable.
- var = Dart_LookupVariable(cls, NewString("_h"));
- EXPECT_VALID(var);
- EXPECT(Dart_IsVariable(var));
- BuildVariableDescription(&buffer, var);
- EXPECT_STREQ("_h static final", buffer.buf());
-
- // Lookup a variable that does not exist from a library.
- var = Dart_LookupVariable(lib, NewString("DoesNotExist"));
- EXPECT(Dart_IsNull(var));
-
- // Lookup a variable that does not exist from a class.
- var = Dart_LookupVariable(cls, NewString("DoesNotExist"));
- EXPECT(Dart_IsNull(var));
-
- // Lookup a class from an error library. The error propagates.
- var = Dart_LookupVariable(Api::NewError("myerror"), NewString("foo"));
- EXPECT_ERROR(var, "myerror");
-
- // Lookup a class using an error class name. The error propagates.
- var = Dart_LookupVariable(lib, Api::NewError("myerror"));
- EXPECT_ERROR(var, "myerror");
-}
-
-
-TEST_CASE(TypeVariableReflection) {
- const char* kScriptChars =
- "abstract class UpperBound {}\n"
- "class GenericClass<U, T extends UpperBound> {\n"
- " T func1() { return null; }\n"
- " U func2() { return null; }\n"
- "}\n";
-
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- Dart_Handle cls = Dart_GetClass(lib, NewString("GenericClass"));
- EXPECT_VALID(cls);
-
- // Test Dart_GetTypeVariableNames.
- Dart_Handle names = Dart_GetTypeVariableNames(cls);
- EXPECT_VALID(names);
- Dart_Handle names_str = Dart_ToString(names);
- EXPECT_VALID(names_str);
- const char* cstr = "";
- EXPECT_VALID(Dart_StringToCString(names_str, &cstr));
- EXPECT_STREQ("[U, T]", cstr);
-
- // Test variable U.
- Dart_Handle type_var = Dart_LookupTypeVariable(cls, NewString("U"));
- EXPECT_VALID(type_var);
- EXPECT(Dart_IsTypeVariable(type_var));
- Dart_Handle type_var_name = Dart_TypeVariableName(type_var);
- EXPECT_VALID(type_var_name);
- EXPECT_VALID(Dart_StringToCString(type_var_name, &cstr));
- EXPECT_STREQ("U", cstr);
- Dart_Handle type_var_owner = Dart_TypeVariableOwner(type_var);
- EXPECT_VALID(type_var_owner);
- EXPECT(Dart_IdentityEquals(cls, type_var_owner));
- Dart_Handle type_var_bound = Dart_TypeVariableUpperBound(type_var);
- Dart_Handle bound_name = Dart_ClassName(type_var_bound);
- EXPECT_VALID(Dart_StringToCString(bound_name, &cstr));
- EXPECT_STREQ("Object", cstr);
-
- // Test variable T.
- type_var = Dart_LookupTypeVariable(cls, NewString("T"));
- EXPECT_VALID(type_var);
- EXPECT(Dart_IsTypeVariable(type_var));
- type_var_name = Dart_TypeVariableName(type_var);
- EXPECT_VALID(type_var_name);
- EXPECT_VALID(Dart_StringToCString(type_var_name, &cstr));
- EXPECT_STREQ("T", cstr);
- type_var_owner = Dart_TypeVariableOwner(type_var);
- EXPECT_VALID(type_var_owner);
- EXPECT(Dart_IdentityEquals(cls, type_var_owner));
- type_var_bound = Dart_TypeVariableUpperBound(type_var);
- bound_name = Dart_ClassName(type_var_bound);
- EXPECT_VALID(Dart_StringToCString(bound_name, &cstr));
- EXPECT_STREQ("UpperBound", cstr);
-}
-
-
TEST_CASE(InstanceOf) {
const char* kScriptChars =
"class OtherClass {\n"
@@ -5887,71 +4914,6 @@
}
-TEST_CASE(GetVariableNames) {
- const char* kLibraryChars =
- "library library_name;\n"
- "\n"
- "var A;\n"
- "get B => 12;\n"
- "set C(x) { }\n"
- "D(x) => (x + 1);\n"
- "var _A;\n"
- "get _B => 12;\n"
- "set _C(x) { }\n"
- "_D(x) => (x + 1);\n"
- "\n"
- "class MyClass {\n"
- " var A2;\n"
- " var _A2;\n"
- "}\n"
- "\n"
- "_compare(String a, String b) => a.compareTo(b);\n"
- "sort(list) => list.sort(_compare);\n";
-
- // Get the variables from a library.
- Dart_Handle url = NewString("library_url");
- Dart_Handle source = NewString(kLibraryChars);
- Dart_Handle lib = Dart_LoadLibrary(url, source);
- EXPECT_VALID(lib);
-
- Dart_Handle list = Dart_GetVariableNames(lib);
- EXPECT_VALID(list);
- EXPECT(Dart_IsList(list));
-
- // Sort the list.
- const int kNumArgs = 1;
- Dart_Handle args[1];
- args[0] = list;
- EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args));
-
- // Check list contents.
- Dart_Handle list_string = Dart_ToString(list);
- EXPECT_VALID(list_string);
- const char* list_cstr = "";
- EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr));
- EXPECT_STREQ("[A, _A]", list_cstr);
-
- // Get the variables from a class.
- Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass"));
- EXPECT_VALID(cls);
-
- list = Dart_GetVariableNames(cls);
- EXPECT_VALID(list);
- EXPECT(Dart_IsList(list));
-
- // Sort the list.
- args[0] = list;
- EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args));
-
- // Check list contents.
- list_string = Dart_ToString(list);
- EXPECT_VALID(list_string);
- list_cstr = "";
- EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr));
- EXPECT_STREQ("[A2, _A2]", list_cstr);
-}
-
-
TEST_CASE(LibraryImportLibrary) {
const char* kLibrary1Chars =
"library library1_name;";
@@ -8213,57 +7175,4 @@
EXPECT_EQ(8, value);
}
-
-TEST_CASE(AmbiguousReference) {
- const char* kImportedScript1Chars =
- "library library1.dart;\n"
- "var foo;\n"
- "var foo1;\n"
- "bar() => 'library1.dart bar()';\n"
- "bar1() => 'library1.dart bar1()';\n"
- "baz() => 'library1.dart baz()';\n"
- "var bay;\n"
- "typedef int bax(int a, int b);\n"
- "class baw {}\n";
- const char* kImportedScript2Chars =
- "library library2.dart;\n"
- "var foo;\n"
- "var foo2;\n"
- "bar() => 'library2.dart bar()';\n"
- "bar2() => 'library2.dart bar2()';\n"
- "var baz;\n"
- "bay() => 'library2.dart bay()';\n"
- "typedef double bax(int a, int b);\n"
- "var baw;\n";
- const char* kScriptChars =
- "import 'library1.dart';\n"
- "import 'library2.dart';\n";
-
- // Load imported libs.
- Dart_Handle url1 = NewString("library1.dart");
- Dart_Handle source1 = NewString(kImportedScript1Chars);
- Dart_Handle imported_lib1 = Dart_LoadLibrary(url1, source1);
- EXPECT_VALID(imported_lib1);
- Dart_Handle url2 = NewString("library2.dart");
- Dart_Handle source2 = NewString(kImportedScript2Chars);
- Dart_Handle imported_lib2 = Dart_LoadLibrary(url2, source2);
- EXPECT_VALID(imported_lib2);
- // Load main script.
- Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- EXPECT_VALID(lib);
- // Expect an error for ambiguous references.
- EXPECT(Dart_IsError(Dart_LookupVariable(lib, NewString("foo"))));
- EXPECT(Dart_IsError(Dart_LookupFunction(lib, NewString("bar"))));
- EXPECT(Dart_IsError(Dart_LookupFunction(lib, NewString("baz"))));
- EXPECT(Dart_IsError(Dart_LookupVariable(lib, NewString("bay"))));
- EXPECT(Dart_IsError(Dart_GetClass(lib, NewString("bax"))));
- EXPECT(Dart_IsError(Dart_GetClass(lib, NewString("baw"))));
- // Variables foo1 and foo2 are unambiguous.
- EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo1"))));
- EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo2"))));
- // Functions bar1 and bar2 are unambiguous.
- EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar1"))));
- EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar2"))));
-}
-
} // namespace dart
« no previous file with comments | « runtime/include/dart_mirrors_api.h ('k') | runtime/vm/mirrors_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698