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

Unified Diff: runtime/vm/dart_entry_test.cc

Issue 9169102: Add Dart_PropagateError. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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/vm/dart_entry.cc ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_entry_test.cc
===================================================================
--- runtime/vm/dart_entry_test.cc (revision 3804)
+++ runtime/vm/dart_entry_test.cc (working copy)
@@ -4,6 +4,7 @@
#include "platform/assert.h"
#include "vm/assembler.h"
+#include "vm/class_finalizer.h"
#include "vm/compiler.h"
#include "vm/dart_entry.h"
#include "vm/object.h"
@@ -43,6 +44,77 @@
EXPECT_EQ(Smi::New(42), retval.raw());
}
+
+TEST_CASE(InvokeStatic_CompileError) {
+ const char* kScriptChars =
+ "class A {\n"
+ " static foo() { return ++++; }\n"
+ "}\n";
+ String& url = String::Handle(String::New("dart-test:DartEntry"));
+ String& source = String::Handle(String::New(kScriptChars));
+ Script& script = Script::Handle(Script::New(url, source, RawScript::kScript));
+ Library& lib = Library::Handle(Library::CoreLibrary());
+ EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
+ EXPECT(ClassFinalizer::FinalizePendingClasses());
+ Class& cls = Class::Handle(
+ lib.LookupClass(String::Handle(String::NewSymbol("A"))));
+ EXPECT(!cls.IsNull());
+ String& name = String::Handle(String::New("foo"));
+ Function& function = Function::Handle(cls.LookupStaticFunction(name));
+ EXPECT(!function.IsNull());
+ GrowableArray<const Object*> arguments;
+ const Array& kNoArgumentNames = Array::Handle();
+ const Object& retval = Object::Handle(
+ DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
+ EXPECT(retval.IsError());
+ Error& error = Error::Handle();
+ error ^= retval.raw();
+ EXPECT_SUBSTRING("++++", error.ToErrorCString());
+}
+
+
+TEST_CASE(InvokeDynamic_CompileError) {
+ const char* kScriptChars =
+ "class A {\n"
+ " foo() { return ++++; }\n"
+ "}\n";
+ String& url = String::Handle(String::New("dart-test:DartEntry"));
+ String& source = String::Handle(String::New(kScriptChars));
+ Script& script = Script::Handle(Script::New(url, source, RawScript::kScript));
+ Library& lib = Library::Handle(Library::CoreLibrary());
+ EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
+ EXPECT(ClassFinalizer::FinalizePendingClasses());
+ Class& cls = Class::Handle(
+ lib.LookupClass(String::Handle(String::NewSymbol("A"))));
+ EXPECT(!cls.IsNull());
+
+ // Invoke the constructor.
+ const Instance& instance = Instance::Handle(Instance::New(cls));
+ GrowableArray<const Object*> constructor_arguments(2);
+ constructor_arguments.Add(&instance);
+ constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
+ const String& period = String::Handle(String::New("."));
+ String& constructor_name = String::Handle(String::NewSymbol("A."));
+ Function& constructor =
+ Function::Handle(cls.LookupConstructor(constructor_name));
+ ASSERT(!constructor.IsNull());
+ const Array& kNoArgumentNames = Array::Handle();
+ DartEntry::InvokeStatic(constructor, constructor_arguments, kNoArgumentNames);
+
+ // Call foo.
+ String& name = String::Handle(String::New("foo"));
+ Function& function = Function::Handle(cls.LookupDynamicFunction(name));
+ EXPECT(!function.IsNull());
+ GrowableArray<const Object*> arguments;
+ const Object& retval = Object::Handle(
+ DartEntry::InvokeDynamic(
+ instance, function, arguments, kNoArgumentNames));
+ EXPECT(retval.IsError());
+ Error& error = Error::Handle();
+ error ^= retval.raw();
+ EXPECT_SUBSTRING("++++", error.ToErrorCString());
+}
+
#endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64.
} // namespace dart
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698