mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
14db718ed5
Mostly tests; 1 non-test bug in propagating an error through Dart_SetReturnValue. This is progress towards asserting thread->excution_state() == kThreadInVM in Object::Allocate. Change-Id: I6a59549868ab317b3c0d32aa42f3661289cbf456 Reviewed-on: https://dart-review.googlesource.com/71720 Reviewed-by: Siva Annamalai <asiva@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
107 lines
4.2 KiB
C++
107 lines
4.2 KiB
C++
// Copyright (c) 2012, 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.
|
|
|
|
#include "platform/globals.h"
|
|
|
|
#include "platform/assert.h"
|
|
#include "vm/class_finalizer.h"
|
|
#include "vm/compiler/assembler/assembler.h"
|
|
#include "vm/compiler/jit/compiler.h"
|
|
#include "vm/dart_entry.h"
|
|
#include "vm/object.h"
|
|
#include "vm/resolver.h"
|
|
#include "vm/symbols.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
ISOLATE_UNIT_TEST_CASE(DartEntry) {
|
|
const char* kScriptChars =
|
|
"class A {\n"
|
|
" static foo() { return 42; }\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::kScriptTag));
|
|
Library& lib = Library::Handle(Library::CoreLibrary());
|
|
EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
|
|
EXPECT(ClassFinalizer::ProcessPendingClasses());
|
|
Class& cls =
|
|
Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A"))));
|
|
EXPECT(!cls.IsNull()); // No ambiguity error expected.
|
|
String& name = String::Handle(String::New("foo"));
|
|
Function& function = Function::Handle(cls.LookupStaticFunction(name));
|
|
EXPECT(!function.IsNull());
|
|
|
|
EXPECT(CompilerTest::TestCompileFunction(function));
|
|
EXPECT(function.HasCode());
|
|
const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>(
|
|
DartEntry::InvokeFunction(function, Object::empty_array())));
|
|
EXPECT_EQ(Smi::New(42), retval.raw());
|
|
}
|
|
|
|
ISOLATE_UNIT_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::kScriptTag));
|
|
Library& lib = Library::Handle(Library::CoreLibrary());
|
|
EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
|
|
EXPECT(ClassFinalizer::ProcessPendingClasses());
|
|
Class& cls =
|
|
Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A"))));
|
|
EXPECT(!cls.IsNull()); // No ambiguity error expected.
|
|
String& name = String::Handle(String::New("foo"));
|
|
Function& function = Function::Handle(cls.LookupStaticFunction(name));
|
|
EXPECT(!function.IsNull());
|
|
const Object& retval = Object::Handle(
|
|
DartEntry::InvokeFunction(function, Object::empty_array()));
|
|
EXPECT(retval.IsError());
|
|
EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
|
|
}
|
|
|
|
ISOLATE_UNIT_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::kScriptTag));
|
|
Library& lib = Library::Handle(Library::CoreLibrary());
|
|
EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
|
|
EXPECT(ClassFinalizer::ProcessPendingClasses());
|
|
Class& cls =
|
|
Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A"))));
|
|
EXPECT(!cls.IsNull()); // No ambiguity error expected.
|
|
|
|
// Invoke the constructor.
|
|
const Instance& instance = Instance::Handle(Instance::New(cls));
|
|
const Array& constructor_arguments = Array::Handle(Array::New(1));
|
|
constructor_arguments.SetAt(0, instance);
|
|
String& constructor_name = String::Handle(Symbols::New(thread, "A."));
|
|
Function& constructor =
|
|
Function::Handle(cls.LookupConstructor(constructor_name));
|
|
ASSERT(!constructor.IsNull());
|
|
DartEntry::InvokeFunction(constructor, constructor_arguments);
|
|
|
|
// Call foo.
|
|
String& name = String::Handle(String::New("foo"));
|
|
Function& function = Function::Handle(cls.LookupDynamicFunction(name));
|
|
EXPECT(!function.IsNull());
|
|
const Array& args = Array::Handle(Array::New(1));
|
|
args.SetAt(0, instance);
|
|
const Object& retval =
|
|
Object::Handle(DartEntry::InvokeFunction(function, args));
|
|
EXPECT(retval.IsError());
|
|
EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
|
|
}
|
|
|
|
} // namespace dart
|