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

Side by Side 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, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/class_finalizer.h"
7 #include "vm/compiler.h" 8 #include "vm/compiler.h"
8 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
9 #include "vm/object.h" 10 #include "vm/object.h"
10 #include "vm/resolver.h" 11 #include "vm/resolver.h"
11 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 // Only ia32 and x64 can run execution tests. 16 // Only ia32 and x64 can run execution tests.
16 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 17 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
(...skipping 19 matching lines...) Expand all
36 EXPECT(function.HasCode()); 37 EXPECT(function.HasCode());
37 GrowableArray<const Object*> arguments; 38 GrowableArray<const Object*> arguments;
38 const Array& kNoArgumentNames = Array::Handle(); 39 const Array& kNoArgumentNames = Array::Handle();
39 const Smi& retval = Smi::Handle( 40 const Smi& retval = Smi::Handle(
40 reinterpret_cast<RawSmi*>(DartEntry::InvokeStatic(function, 41 reinterpret_cast<RawSmi*>(DartEntry::InvokeStatic(function,
41 arguments, 42 arguments,
42 kNoArgumentNames))); 43 kNoArgumentNames)));
43 EXPECT_EQ(Smi::New(42), retval.raw()); 44 EXPECT_EQ(Smi::New(42), retval.raw());
44 } 45 }
45 46
47
48 TEST_CASE(InvokeStatic_CompileError) {
49 const char* kScriptChars =
50 "class A {\n"
51 " static foo() { return ++++; }\n"
52 "}\n";
53 String& url = String::Handle(String::New("dart-test:DartEntry"));
54 String& source = String::Handle(String::New(kScriptChars));
55 Script& script = Script::Handle(Script::New(url, source, RawScript::kScript));
56 Library& lib = Library::Handle(Library::CoreLibrary());
57 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
58 EXPECT(ClassFinalizer::FinalizePendingClasses());
59 Class& cls = Class::Handle(
60 lib.LookupClass(String::Handle(String::NewSymbol("A"))));
61 EXPECT(!cls.IsNull());
62 String& name = String::Handle(String::New("foo"));
63 Function& function = Function::Handle(cls.LookupStaticFunction(name));
64 EXPECT(!function.IsNull());
65 GrowableArray<const Object*> arguments;
66 const Array& kNoArgumentNames = Array::Handle();
67 const Object& retval = Object::Handle(
68 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
69 EXPECT(retval.IsError());
70 Error& error = Error::Handle();
71 error ^= retval.raw();
72 EXPECT_SUBSTRING("++++", error.ToErrorCString());
73 }
74
75
76 TEST_CASE(InvokeDynamic_CompileError) {
77 const char* kScriptChars =
78 "class A {\n"
79 " foo() { return ++++; }\n"
80 "}\n";
81 String& url = String::Handle(String::New("dart-test:DartEntry"));
82 String& source = String::Handle(String::New(kScriptChars));
83 Script& script = Script::Handle(Script::New(url, source, RawScript::kScript));
84 Library& lib = Library::Handle(Library::CoreLibrary());
85 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
86 EXPECT(ClassFinalizer::FinalizePendingClasses());
87 Class& cls = Class::Handle(
88 lib.LookupClass(String::Handle(String::NewSymbol("A"))));
89 EXPECT(!cls.IsNull());
90
91 // Invoke the constructor.
92 const Instance& instance = Instance::Handle(Instance::New(cls));
93 GrowableArray<const Object*> constructor_arguments(2);
94 constructor_arguments.Add(&instance);
95 constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
96 const String& period = String::Handle(String::New("."));
97 String& constructor_name = String::Handle(String::NewSymbol("A."));
98 Function& constructor =
99 Function::Handle(cls.LookupConstructor(constructor_name));
100 ASSERT(!constructor.IsNull());
101 const Array& kNoArgumentNames = Array::Handle();
102 DartEntry::InvokeStatic(constructor, constructor_arguments, kNoArgumentNames);
103
104 // Call foo.
105 String& name = String::Handle(String::New("foo"));
106 Function& function = Function::Handle(cls.LookupDynamicFunction(name));
107 EXPECT(!function.IsNull());
108 GrowableArray<const Object*> arguments;
109 const Object& retval = Object::Handle(
110 DartEntry::InvokeDynamic(
111 instance, function, arguments, kNoArgumentNames));
112 EXPECT(retval.IsError());
113 Error& error = Error::Handle();
114 error ^= retval.raw();
115 EXPECT_SUBSTRING("++++", error.ToErrorCString());
116 }
117
46 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64. 118 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64.
47 119
48 } // namespace dart 120 } // namespace dart
OLDNEW
« 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