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

Side by Side Diff: runtime/vm/dart_entry_test.cc

Issue 12315087: Hook up simulator (if needed) when calling Dart code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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.cc » ('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/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 22 matching lines...) Expand all
33 Class& cls = Class::Handle( 33 Class& cls = Class::Handle(
34 lib.LookupClass(String::Handle(Symbols::New("A")))); 34 lib.LookupClass(String::Handle(Symbols::New("A"))));
35 EXPECT(!cls.IsNull()); 35 EXPECT(!cls.IsNull());
36 String& name = String::Handle(String::New("foo")); 36 String& name = String::Handle(String::New("foo"));
37 Function& function = Function::Handle(cls.LookupStaticFunction(name)); 37 Function& function = Function::Handle(cls.LookupStaticFunction(name));
38 EXPECT(!function.IsNull()); 38 EXPECT(!function.IsNull());
39 39
40 EXPECT(CompilerTest::TestCompileFunction(function)); 40 EXPECT(CompilerTest::TestCompileFunction(function));
41 EXPECT(function.HasCode()); 41 EXPECT(function.HasCode());
42 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( 42 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>(
43 DartEntry::InvokeStatic(function, Object::empty_array()))); 43 DartEntry::InvokeFunction(function, Object::empty_array())));
44 EXPECT_EQ(Smi::New(42), retval.raw()); 44 EXPECT_EQ(Smi::New(42), retval.raw());
45 } 45 }
46 46
47 47
48 TEST_CASE(InvokeStatic_CompileError) { 48 TEST_CASE(InvokeStatic_CompileError) {
49 const char* kScriptChars = 49 const char* kScriptChars =
50 "class A {\n" 50 "class A {\n"
51 " static foo() { return ++++; }\n" 51 " static foo() { return ++++; }\n"
52 "}\n"; 52 "}\n";
53 String& url = String::Handle(String::New("dart-test:DartEntry")); 53 String& url = String::Handle(String::New("dart-test:DartEntry"));
54 String& source = String::Handle(String::New(kScriptChars)); 54 String& source = String::Handle(String::New(kScriptChars));
55 Script& script = Script::Handle(Script::New(url, 55 Script& script = Script::Handle(Script::New(url,
56 source, 56 source,
57 RawScript::kScriptTag)); 57 RawScript::kScriptTag));
58 Library& lib = Library::Handle(Library::CoreLibrary()); 58 Library& lib = Library::Handle(Library::CoreLibrary());
59 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 59 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
60 EXPECT(ClassFinalizer::FinalizePendingClasses()); 60 EXPECT(ClassFinalizer::FinalizePendingClasses());
61 Class& cls = Class::Handle( 61 Class& cls = Class::Handle(
62 lib.LookupClass(String::Handle(Symbols::New("A")))); 62 lib.LookupClass(String::Handle(Symbols::New("A"))));
63 EXPECT(!cls.IsNull()); 63 EXPECT(!cls.IsNull());
64 String& name = String::Handle(String::New("foo")); 64 String& name = String::Handle(String::New("foo"));
65 Function& function = Function::Handle(cls.LookupStaticFunction(name)); 65 Function& function = Function::Handle(cls.LookupStaticFunction(name));
66 EXPECT(!function.IsNull()); 66 EXPECT(!function.IsNull());
67 GrowableArray<const Object*> arguments; 67 GrowableArray<const Object*> arguments;
68 const Object& retval = Object::Handle( 68 const Object& retval = Object::Handle(
69 DartEntry::InvokeStatic(function, Object::empty_array())); 69 DartEntry::InvokeFunction(function, Object::empty_array()));
70 EXPECT(retval.IsError()); 70 EXPECT(retval.IsError());
71 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); 71 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
72 } 72 }
73 73
74 74
75 TEST_CASE(InvokeDynamic_CompileError) { 75 TEST_CASE(InvokeDynamic_CompileError) {
76 const char* kScriptChars = 76 const char* kScriptChars =
77 "class A {\n" 77 "class A {\n"
78 " foo() { return ++++; }\n" 78 " foo() { return ++++; }\n"
79 "}\n"; 79 "}\n";
(...skipping 12 matching lines...) Expand all
92 // Invoke the constructor. 92 // Invoke the constructor.
93 const Instance& instance = Instance::Handle(Instance::New(cls)); 93 const Instance& instance = Instance::Handle(Instance::New(cls));
94 const Array& constructor_arguments = Array::Handle(Array::New(2)); 94 const Array& constructor_arguments = Array::Handle(Array::New(2));
95 constructor_arguments.SetAt(0, instance); 95 constructor_arguments.SetAt(0, instance);
96 constructor_arguments.SetAt( 96 constructor_arguments.SetAt(
97 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); 97 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
98 String& constructor_name = String::Handle(Symbols::New("A.")); 98 String& constructor_name = String::Handle(Symbols::New("A."));
99 Function& constructor = 99 Function& constructor =
100 Function::Handle(cls.LookupConstructor(constructor_name)); 100 Function::Handle(cls.LookupConstructor(constructor_name));
101 ASSERT(!constructor.IsNull()); 101 ASSERT(!constructor.IsNull());
102 DartEntry::InvokeStatic(constructor, constructor_arguments); 102 DartEntry::InvokeFunction(constructor, constructor_arguments);
103 103
104 // Call foo. 104 // Call foo.
105 String& name = String::Handle(String::New("foo")); 105 String& name = String::Handle(String::New("foo"));
106 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); 106 Function& function = Function::Handle(cls.LookupDynamicFunction(name));
107 EXPECT(!function.IsNull()); 107 EXPECT(!function.IsNull());
108 const Array& args = Array::Handle(Array::New(1)); 108 const Array& args = Array::Handle(Array::New(1));
109 args.SetAt(0, instance); 109 args.SetAt(0, instance);
110 const Object& retval = Object::Handle(DartEntry::InvokeDynamic(function, 110 const Object& retval = Object::Handle(DartEntry::InvokeFunction(function,
111 args)); 111 args));
112 EXPECT(retval.IsError()); 112 EXPECT(retval.IsError());
113 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); 113 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
114 } 114 }
115 115
116 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64. 116 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64.
117 117
118 } // namespace dart 118 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698