From 9c95624a6307f09f1cdc49054bdd08125acb6f53 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Tue, 6 Nov 2018 23:59:11 +0000 Subject: [PATCH] Temporary revert to fix issue #35009 for 2.1. package:rpc relies on mirrors behaviour that is not valid for Dart 2, so these type checks cause the package to crash. Revert "[ VM / Mirrors ] Added type checking to enforce strong mode semantics when using dart:mirrors" This reverts commit 9f00eec55bc56dc7371ffcc509d4b7d6698fc51c. Change-Id: I82ce07d388ba9402f20caf700815b39c9bc418f6 Reviewed-on: https://dart-review.googlesource.com/c/83225 Reviewed-by: Ben Konyi Reviewed-by: Siva Annamalai Commit-Queue: Ben Konyi --- runtime/lib/mirrors.cc | 7 - runtime/tests/vm/vm.status | 1 + runtime/vm/dart_api_impl_test.cc | 92 -------- runtime/vm/object.cc | 208 ++---------------- runtime/vm/object.h | 7 - runtime/vm/service.cc | 1 + .../mirrors/bad_argument_types_test.dart | 157 ------------- 7 files changed, 25 insertions(+), 448 deletions(-) delete mode 100644 tests/lib_2/mirrors/bad_argument_types_test.dart diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc index a8b625e31def..9b5f895abc3e 100644 --- a/runtime/lib/mirrors.cc +++ b/runtime/lib/mirrors.cc @@ -1434,13 +1434,6 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 5) { InvocationMirror::kMethod); UNREACHABLE(); } - const Object& type_error = - Object::Handle(redirected_constructor.DoArgumentTypesMatch( - args, args_descriptor, type_arguments)); - if (!type_error.IsNull()) { - Exceptions::PropagateError(Error::Cast(type_error)); - UNREACHABLE(); - } Instance& new_object = Instance::Handle(); if (redirected_constructor.IsGenerativeConstructor()) { diff --git a/runtime/tests/vm/vm.status b/runtime/tests/vm/vm.status index 7c1b578b6b5d..a98cd53c240c 100644 --- a/runtime/tests/vm/vm.status +++ b/runtime/tests/vm/vm.status @@ -17,6 +17,7 @@ cc/IsolateReload_PendingStaticCall_NSMToDefined: Fail, Crash # Issue 32981. Fail cc/IsolateReload_PendingUnqualifiedCall_InstanceToStatic: Fail # Issue 32981 cc/IsolateReload_PendingUnqualifiedCall_StaticToInstance: Fail # Issue 32981 cc/IsolateReload_RunNewFieldInitializersWithGenerics: Fail # Issue 32299 +cc/Profiler_InliningIntervalBoundry: Skip # Differences in ia32, debug, release cc/SNPrint_BadArgs: Crash, Fail # These tests are expected to crash on all platforms. dart/data_uri_import_test/none: SkipByDesign dart/snapshot_version_test: Skip # This test is a Dart1 test (script snapshot) diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index c77865b8ff1f..28ec5ecec8c8 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -4184,16 +4184,6 @@ TEST_CASE(DartAPI_SetField_FunnyValue) { EXPECT_STREQ("myerror", Dart_GetError(result)); } -TEST_CASE(DartAPI_SetField_BadType) { - const char* kScriptChars = "int foo;\n"; - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle name = NewString("foo"); - Dart_Handle result = Dart_SetField(lib, name, Dart_True()); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING("type 'bool' is not a subtype of type 'int' of 'foo'", - Dart_GetError(result)); -} - void NativeFieldLookup(Dart_NativeArguments args) { UNREACHABLE(); } @@ -5178,88 +5168,6 @@ TEST_CASE(DartAPI_Invoke_FunnyArgs) { EXPECT_STREQ("myerror", Dart_GetError(result)); } -TEST_CASE(DartAPI_Invoke_BadArgs) { - const char* kScriptChars = - "class BaseMethods {\n" - " inheritedMethod(int arg) => 'inherited $arg';\n" - " static nonInheritedMethod(int arg) => 'noninherited $arg';\n" - "}\n" - "\n" - "class Methods extends BaseMethods {\n" - " instanceMethod(int arg) => 'instance $arg';\n" - " _instanceMethod(int arg) => 'hidden instance $arg';\n" - " static staticMethod(int arg) => 'static $arg';\n" - " static _staticMethod(int arg) => 'hidden static $arg';\n" - "}\n" - "\n" - "topMethod(int arg) => 'top $arg';\n" - "_topMethod(int arg) => 'hidden top $arg';\n" - "\n" - "Methods test() {\n" - " return new Methods();\n" - "}\n"; - -#if defined(PRODUCT) - const char* error_msg = - "type '_OneByteString' is not a subtype of type 'int' of 'arg'"; -#else - const char* error_msg = - "type 'String' is not a subtype of type 'int' of 'arg'"; -#endif // defined(PRODUCT) - - // Shared setup. - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL); - EXPECT_VALID(type); - Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); - EXPECT_VALID(instance); - Dart_Handle args[1]; - args[0] = NewString("!!!"); - Dart_Handle result; - Dart_Handle name; - - // Instance method. - name = NewString("instanceMethod"); - result = Dart_Invoke(instance, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); - - name = PrivateLibName(lib, "_instanceMethod"); - result = Dart_Invoke(instance, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); - - // Inherited method. - name = NewString("inheritedMethod"); - result = Dart_Invoke(instance, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); - - // Static method. - name = NewString("staticMethod"); - result = Dart_Invoke(type, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); - - // Hidden static method. - name = NewString("_staticMethod"); - result = Dart_Invoke(type, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); - - // Top-Level method. - name = NewString("topMethod"); - result = Dart_Invoke(lib, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); - - // Hidden top-level method. - name = NewString("_topMethod"); - result = Dart_Invoke(lib, name, 1, args); - EXPECT(Dart_IsError(result)); - EXPECT_SUBSTRING(error_msg, Dart_GetError(result)); -} - TEST_CASE(DartAPI_Invoke_Null) { Dart_Handle result = Dart_Invoke(Dart_Null(), NewString("toString"), 0, NULL); EXPECT_VALID(result); diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index f4f51297e072..1b5063a33ccc 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -3378,26 +3378,6 @@ static RawObject* ThrowNoSuchMethod(const Instance& receiver, return DartEntry::InvokeFunction(throwNew, args); } -static RawObject* ThrowTypeError(const TokenPosition token_pos, - const Instance& src_value, - const AbstractType& dst_type, - const String& dst_name) { - const Array& args = Array::Handle(Array::New(5)); - const Smi& pos = Smi::Handle(Smi::New(token_pos.value())); - args.SetAt(0, pos); - args.SetAt(1, src_value); - args.SetAt(2, dst_type); - args.SetAt(3, dst_name); - args.SetAt(4, String::Handle()); // bound error message - - const Library& libcore = Library::Handle(Library::CoreLibrary()); - const Class& TypeError = - Class::Handle(libcore.LookupClassAllowPrivate(Symbols::TypeError())); - const Function& throwNew = Function::Handle( - TypeError.LookupFunctionAllowPrivate(Symbols::ThrowNew())); - return DartEntry::InvokeFunction(throwNew, args); -} - RawObject* Class::InvokeGetter(const String& getter_name, bool throw_nsm_if_absent, bool respect_reflectable) const { @@ -3462,31 +3442,21 @@ RawObject* Class::InvokeSetter(const String& setter_name, const String& internal_setter_name = String::Handle(zone, Field::SetterName(setter_name)); - AbstractType& parameter_type = AbstractType::Handle(zone); - AbstractType& argument_type = - AbstractType::Handle(zone, value.GetType(Heap::kOld)); - if (field.IsNull()) { const Function& setter = Function::Handle(zone, LookupStaticFunction(internal_setter_name)); + const int kNumArgs = 1; const Array& args = Array::Handle(zone, Array::New(kNumArgs)); args.SetAt(0, value); + if (setter.IsNull() || (respect_reflectable && !setter.is_reflectable())) { return ThrowNoSuchMethod(AbstractType::Handle(zone, RareType()), internal_setter_name, args, Object::null_array(), InvocationMirror::kStatic, InvocationMirror::kSetter); } - parameter_type ^= setter.ParameterTypeAt(0); - if (!argument_type.IsNullType() && !parameter_type.IsDynamicType() && - !value.IsInstanceOf(parameter_type, Object::null_type_arguments(), - Object::null_type_arguments(), NULL)) { - const String& argument_name = - String::Handle(zone, setter.ParameterNameAt(0)); - return ThrowTypeError(setter.token_pos(), value, parameter_type, - argument_name); - } + // Invoke the setter and return the result. return DartEntry::InvokeFunction(setter, args); } @@ -3495,20 +3465,13 @@ RawObject* Class::InvokeSetter(const String& setter_name, const int kNumArgs = 1; const Array& args = Array::Handle(zone, Array::New(kNumArgs)); args.SetAt(0, value); + return ThrowNoSuchMethod(AbstractType::Handle(zone, RareType()), internal_setter_name, args, Object::null_array(), InvocationMirror::kStatic, InvocationMirror::kSetter); } - parameter_type ^= field.type(); - if (!argument_type.IsNullType() && !parameter_type.IsDynamicType() && - !value.IsInstanceOf(parameter_type, Object::null_type_arguments(), - Object::null_type_arguments(), NULL)) { - const String& argument_name = String::Handle(zone, field.name()); - return ThrowTypeError(field.token_pos(), value, parameter_type, - argument_name); - } field.SetStaticValue(value); return value.raw(); } @@ -3558,21 +3521,19 @@ RawObject* Class::Invoke(const String& function_name, return DartEntry::InvokeClosure(call_args, call_args_descriptor_array); } } + const Array& args_descriptor_array = Array::Handle( zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names)); + ArgumentsDescriptor args_descriptor(args_descriptor_array); - const TypeArguments& type_args = Object::null_type_arguments(); + if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) || (respect_reflectable && !function.is_reflectable())) { return ThrowNoSuchMethod( AbstractType::Handle(zone, RareType()), function_name, args, arg_names, InvocationMirror::kStatic, InvocationMirror::kMethod); } - RawObject* type_error = - function.DoArgumentTypesMatch(args, args_descriptor, type_args); - if (type_error != Error::null()) { - return type_error; - } + return DartEntry::InvokeFunction(function, args, args_descriptor_array); } @@ -7001,87 +6962,6 @@ bool Function::AreValidArguments(const ArgumentsDescriptor& args_desc, return true; } -RawObject* Function::DoArgumentTypesMatch( - const Array& args, - const ArgumentsDescriptor& args_desc, - const TypeArguments& instantiator_type_args) const { - Thread* thread = Thread::Current(); - Zone* zone = thread->zone(); - Function& instantiated_func = Function::Handle(zone, raw()); - - if (!HasInstantiatedSignature()) { - instantiated_func ^= InstantiateSignatureFrom(instantiator_type_args, - Object::null_type_arguments(), - kAllFree, Heap::kOld); - } - AbstractType& argument_type = AbstractType::Handle(zone); - AbstractType& parameter_type = AbstractType::Handle(zone); - Instance& argument = Instance::Handle(zone); - - // Check types of the provided arguments against the expected parameter types. - for (intptr_t i = args_desc.FirstArgIndex(); i < args_desc.PositionalCount(); - ++i) { - argument ^= args.At(i); - argument_type ^= argument.GetType(Heap::kOld); - parameter_type ^= instantiated_func.ParameterTypeAt(i); - - // If the argument type is dynamic or the parameter is null, move on. - if (parameter_type.IsDynamicType() || argument_type.IsNullType()) { - continue; - } - if (!argument.IsInstanceOf(parameter_type, instantiator_type_args, - Object::null_type_arguments(), NULL)) { - String& argument_name = String::Handle(zone, ParameterNameAt(i)); - return ThrowTypeError(token_pos(), argument, parameter_type, - argument_name); - } - } - - const intptr_t num_arguments = args_desc.Count(); - const intptr_t num_named_arguments = args_desc.NamedCount(); - if (num_named_arguments == 0) { - return Error::null(); - } - - String& argument_name = String::Handle(zone); - String& parameter_name = String::Handle(zone); - - // Check types of named arguments against expected parameter type. - for (intptr_t i = 0; i < num_named_arguments; i++) { - argument_name ^= args_desc.NameAt(i); - ASSERT(argument_name.IsSymbol()); - bool found = false; - const intptr_t num_positional_args = num_arguments - num_named_arguments; - const int num_parameters = NumParameters(); - - // Try to find the named parameter that matches the provided argument. - for (intptr_t j = num_positional_args; !found && (j < num_parameters); - j++) { - parameter_name = ParameterNameAt(j); - ASSERT(argument_name.IsSymbol()); - if (argument_name.Equals(parameter_name)) { - found = true; - argument ^= args.At(args_desc.PositionAt(i)); - argument_type ^= argument.GetType(Heap::kOld); - parameter_type ^= instantiated_func.ParameterTypeAt(j); - - // If the argument type is dynamic or the parameter is null, move on. - if (parameter_type.IsDynamicType() || argument_type.IsNullType()) { - continue; - } - if (!argument.IsInstanceOf(parameter_type, instantiator_type_args, - Object::null_type_arguments(), NULL)) { - String& argument_name = String::Handle(zone, ParameterNameAt(i)); - return ThrowTypeError(token_pos(), argument, parameter_type, - argument_name); - } - } - } - ASSERT(found); - } - return Error::null(); -} - // Helper allocating a C string buffer in the zone, printing the fully qualified // name of a function in it, and replacing ':' by '_' to make sure the // constructed name is a valid C++ identifier for debugging purpose. @@ -11244,14 +11124,12 @@ void Library::InitCoreLibrary(Isolate* isolate) { } // Invoke the function, or noSuchMethod if it is null. -static RawObject* InvokeInstanceFunction( - const Instance& receiver, - const Function& function, - const String& target_name, - const Array& args, - const Array& args_descriptor_array, - bool respect_reflectable, - const TypeArguments& instantiator_type_args) { +static RawObject* InvokeInstanceFunction(const Instance& receiver, + const Function& function, + const String& target_name, + const Array& args, + const Array& args_descriptor_array, + bool respect_reflectable) { // Note "args" is already the internal arguments with the receiver as the // first element. ArgumentsDescriptor args_descriptor(args_descriptor_array); @@ -11260,11 +11138,6 @@ static RawObject* InvokeInstanceFunction( return DartEntry::InvokeNoSuchMethod(receiver, target_name, args, args_descriptor_array); } - RawObject* type_error = function.DoArgumentTypesMatch(args, args_descriptor, - instantiator_type_args); - if (type_error != Error::null()) { - return type_error; - } return DartEntry::InvokeFunction(function, args, args_descriptor_array); } @@ -11326,16 +11199,9 @@ RawObject* Library::InvokeSetter(const String& setter_name, Object& obj = Object::Handle(LookupLocalOrReExportObject(setter_name)); const String& internal_setter_name = String::Handle(Field::SetterName(setter_name)); - AbstractType& setter_type = AbstractType::Handle(); - AbstractType& argument_type = AbstractType::Handle(value.GetType(Heap::kOld)); + if (obj.IsField()) { const Field& field = Field::Cast(obj); - setter_type ^= field.type(); - if (!argument_type.IsNullType() && !setter_type.IsDynamicType() && - !value.IsInstanceOf(setter_type, Object::null_type_arguments(), - Object::null_type_arguments(), NULL)) { - return ThrowTypeError(field.token_pos(), value, setter_type, setter_name); - } if (field.is_final() || (respect_reflectable && !field.is_reflectable())) { const int kNumArgs = 1; const Array& args = Array::Handle(Array::New(kNumArgs)); @@ -11366,13 +11232,6 @@ RawObject* Library::InvokeSetter(const String& setter_name, InvocationMirror::kTopLevel, InvocationMirror::kSetter); } - setter_type ^= setter.ParameterTypeAt(0); - if (!argument_type.IsNullType() && !setter_type.IsDynamicType() && - !value.IsInstanceOf(setter_type, Object::null_type_arguments(), - Object::null_type_arguments(), NULL)) { - return ThrowTypeError(setter.token_pos(), value, setter_type, setter_name); - } - return DartEntry::InvokeFunction(setter, args); } @@ -11414,7 +11273,7 @@ RawObject* Library::Invoke(const String& function_name, const Array& args_descriptor_array = Array::Handle( ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names)); ArgumentsDescriptor args_descriptor(args_descriptor_array); - const TypeArguments& type_args = Object::null_type_arguments(); + if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) || (respect_reflectable && !function.is_reflectable())) { return ThrowNoSuchMethod( @@ -11422,11 +11281,7 @@ RawObject* Library::Invoke(const String& function_name, function_name, args, arg_names, InvocationMirror::kTopLevel, InvocationMirror::kMethod); } - RawObject* type_error = - function.DoArgumentTypesMatch(args, args_descriptor, type_args); - if (type_error != Error::null()) { - return type_error; - } + return DartEntry::InvokeFunction(function, args, args_descriptor_array); } @@ -16014,10 +15869,6 @@ RawObject* Instance::InvokeGetter(const String& getter_name, Zone* zone = Thread::Current()->zone(); Class& klass = Class::Handle(zone, clazz()); - TypeArguments& type_args = TypeArguments::Handle(zone); - if (klass.NumTypeArguments() > 0) { - type_args ^= GetTypeArguments(); - } const String& internal_getter_name = String::Handle(zone, Field::GetterName(getter_name)); @@ -16042,8 +15893,7 @@ RawObject* Instance::InvokeGetter(const String& getter_name, zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length())); return InvokeInstanceFunction(*this, function, internal_getter_name, args, - args_descriptor, respect_reflectable, - type_args); + args_descriptor, respect_reflectable); } RawObject* Instance::InvokeSetter(const String& setter_name, @@ -16052,11 +15902,6 @@ RawObject* Instance::InvokeSetter(const String& setter_name, Zone* zone = Thread::Current()->zone(); const Class& klass = Class::Handle(zone, clazz()); - TypeArguments& type_args = TypeArguments::Handle(zone); - if (klass.NumTypeArguments() > 0) { - type_args ^= GetTypeArguments(); - } - const String& internal_setter_name = String::Handle(zone, Field::SetterName(setter_name)); const Function& setter = Function::Handle( @@ -16071,8 +15916,7 @@ RawObject* Instance::InvokeSetter(const String& setter_name, zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length())); return InvokeInstanceFunction(*this, setter, internal_setter_name, args, - args_descriptor, respect_reflectable, - type_args); + args_descriptor, respect_reflectable); } RawObject* Instance::Invoke(const String& function_name, @@ -16089,11 +15933,6 @@ RawObject* Instance::Invoke(const String& function_name, const Array& args_descriptor = Array::Handle( zone, ArgumentsDescriptor::New(kTypeArgsLen, args.Length(), arg_names)); - TypeArguments& type_args = TypeArguments::Handle(zone); - if (klass.NumTypeArguments() > 0) { - type_args ^= GetTypeArguments(); - } - if (function.IsNull()) { // Didn't find a method: try to find a getter and invoke call on its result. const String& getter_name = @@ -16108,9 +15947,9 @@ RawObject* Instance::Invoke(const String& function_name, const Array& getter_args_descriptor = Array::Handle( zone, ArgumentsDescriptor::New(kTypeArgsLen, getter_args.Length())); const Object& getter_result = Object::Handle( - zone, InvokeInstanceFunction(*this, function, getter_name, - getter_args, getter_args_descriptor, - respect_reflectable, type_args)); + zone, + InvokeInstanceFunction(*this, function, getter_name, getter_args, + getter_args_descriptor, respect_reflectable)); if (getter_result.IsError()) { return getter_result.raw(); } @@ -16123,8 +15962,7 @@ RawObject* Instance::Invoke(const String& function_name, // Found an ordinary method. return InvokeInstanceFunction(*this, function, function_name, args, - args_descriptor, respect_reflectable, - type_args); + args_descriptor, respect_reflectable); } RawObject* Instance::EvaluateCompiledExpression( diff --git a/runtime/vm/object.h b/runtime/vm/object.h index cf9d1a1c9fa8..fc2d139ecf2a 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -2666,13 +2666,6 @@ class Function : public Object { intptr_t num_named_arguments, String* error_message) const; - // Returns a TypeError if the provided arguments don't match the function - // parameter types, NULL otherwise. Assumes AreValidArguments is called first. - RawObject* DoArgumentTypesMatch( - const Array& args, - const ArgumentsDescriptor& arg_names, - const TypeArguments& instantiator_type_args) const; - // Returns true if the type argument count, total argument count and the names // of optional arguments are valid for calling this function. // Otherwise, it returns false and the reason (if error_message is not NULL). diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc index 1f5782abb746..eac344ae6de8 100644 --- a/runtime/vm/service.cc +++ b/runtime/vm/service.cc @@ -2401,6 +2401,7 @@ static bool Invoke(Thread* thread, JSONStream* js) { // We don't use Instance::Cast here because it doesn't allow null. Instance& instance = Instance::Handle(zone); instance ^= receiver.raw(); + const Object& result = Object::Handle(zone, instance.Invoke(selector, args, arg_names)); result.PrintJSON(js, true); diff --git a/tests/lib_2/mirrors/bad_argument_types_test.dart b/tests/lib_2/mirrors/bad_argument_types_test.dart deleted file mode 100644 index 806380354407..000000000000 --- a/tests/lib_2/mirrors/bad_argument_types_test.dart +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2018, 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:io'; -import 'dart:mirrors'; - -import 'package:expect/expect.dart'; - -int foobar = 1; - -set foobaz(int x) { - foobar = x; -} - -void foo(Map m) { - print(m); - print(m['bar']); -} - -void bar(T a) { - print(a); -} - -class Foo { - Map bork; - static Map bark; - static set woof(Map x) { - bark = x; - } - - Foo(Map m) { - print(m); - } - - Foo.a(); - - static void baz(Map m, {String bar}) { - print('baz'); - print(m['bar']); - print(bar); - } - - void bar(Map m) { - print('bar'); - print(m.runtimeType); - } -} - -class FooBar { - T bar; - FooBar(this.bar) { - print(bar); - } - - set barz(T x) { - bar = x; - } - - factory FooBar.baz(T bar) { - print(bar); - return FooBar(bar); - } - - void foobar(T a, S b) { - print(a); - print(b); - } -} - -void badClassStaticInvoke() { - Map map = Map(); - map['bar'] = 'Hello world!'; - final cm = reflectClass(Foo); - Expect.throwsTypeError(() => cm.invoke(#baz, [ - map - ], { - #bar: {'boo': 'bah'} - })); -} - -void badStaticInvoke() { - final ClosureMirror im = reflect(foo); - Expect.throwsTypeError(() => im.apply(['Hello world!'])); -} - -void badInstanceInvoke() { - final fooCls = Foo.a(); - final im = reflect(fooCls); - Expect.throwsTypeError(() => im.invoke(#bar, ['Hello World!'])); -} - -void badConstructorInvoke() { - final cm = reflectClass(Foo); - Expect.throwsTypeError(() => cm.newInstance(Symbol(''), ['Hello World!'])); -} - -void badSetterInvoke() { - final fooCls = Foo.a(); - final im = reflect(fooCls); - Expect.throwsTypeError(() => im.setField(#bork, 'Hello World!')); -} - -void badStaticSetterInvoke() { - final cm = reflectClass(Foo); - Expect.throwsTypeError(() => cm.setField(#bark, 'Hello World!')); - Expect.throwsTypeError(() => cm.setField(#woof, 'Hello World!')); -} - -void badGenericConstructorInvoke() { - final cm = reflectType(FooBar, [int]) as ClassMirror; - Expect.throwsTypeError(() => cm.newInstance(Symbol(''), ['Hello World!'])); -} - -void badGenericClassStaticInvoke() { - final cm = reflectType(FooBar, [int]) as ClassMirror; - final im = cm.newInstance(Symbol(''), [1]); - Expect.throwsTypeError(() => im.invoke(#foobar, ['Hello', 'World'])); -} - -void badGenericFactoryInvoke() { - final cm = reflectType(FooBar, [int]) as ClassMirror; - Expect.throwsTypeError(() => cm.newInstance(Symbol('baz'), ['Hello World!'])); -} - -void badGenericStaticInvoke() { - final ClosureMirror im = reflect(bar); - Expect.throwsTypeError(() => im.apply(['Hello world!'])); -} - -void badGenericSetterInvoke() { - final cm = reflectType(FooBar, [int]) as ClassMirror; - final im = cm.newInstance(Symbol(''), [0]); - Expect.throwsTypeError(() => im.setField(#bar, 'Hello world!')); - Expect.throwsTypeError(() => im.setField(#barz, 'Hello world!')); -} - -void badLibrarySetterInvoke() { - final lm = currentMirrorSystem().findLibrary(Symbol('')); - Expect.throwsTypeError(() => lm.setField(#foobar, 'Foobaz')); - Expect.throwsTypeError(() => lm.setField(#foobaz, 'Foobaz')); -} - -void main() { - badClassStaticInvoke(); - badStaticInvoke(); - badInstanceInvoke(); - badConstructorInvoke(); - badSetterInvoke(); - badStaticSetterInvoke(); - badGenericConstructorInvoke(); - badGenericClassStaticInvoke(); - badGenericFactoryInvoke(); - badGenericStaticInvoke(); - badGenericSetterInvoke(); - badLibrarySetterInvoke(); -}