[ VM ] Migrate VM tests to support null safety and return errors from Dart_GetType and Dart_NewListOf when --null-safety is enabled

These methods return legacy types, which aren't valid with null safety
enabled.

Fixes https://github.com/dart-lang/sdk/issues/41154

Change-Id: I1181f0f3b9a8df156dea4dc4c82fef8afdf97ab9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148685
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ben Konyi 2020-05-26 22:40:52 +00:00 committed by commit-bot@chromium.org
parent e007545c42
commit c4b7097e97
24 changed files with 1288 additions and 955 deletions

View file

@ -1,8 +1,8 @@
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|3719|5|94|Const constructors can't throw exceptions.
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|7908|5|97|Const constructors can't throw exceptions.
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|7909|5|97|Const constructors can't throw exceptions.
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|940|5|95|Const constructors can't throw exceptions.
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|973|5|94|Const constructors can't throw exceptions.
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|3717|3|5|Only redirecting factory constructors can be declared to be 'const'.
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|7906|3|5|Only redirecting factory constructors can be declared to be 'const'.
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|7907|3|5|Only redirecting factory constructors can be declared to be 'const'.
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|938|3|5|Only redirecting factory constructors can be declared to be 'const'.
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|971|3|5|Only redirecting factory constructors can be declared to be 'const'.

View file

@ -305,15 +305,16 @@ class VMTestSuite extends TestSuite {
hasRuntimeError: testExpectation == Expectation.runtimeError,
hasStaticWarning: false,
hasCrash: testExpectation == Expectation.crash);
var filename = configuration.architecture == Architecture.x64
? '$buildDir/gen/kernel-service.dart.snapshot'
: '$buildDir/gen/kernel_service.dill';
var dfePath = Path(filename).absolute.toNativePath();
var args = [
if (expectations.contains(Expectation.crash)) '--suppress-core-dump',
// '--dfe' has to be the first argument for run_vm_test to pick it up.
'--dfe=$dfePath',
if (expectations.contains(Expectation.crash)) '--suppress-core-dump',
if (configuration.experiments.isNotEmpty)
'--enable-experiment=${configuration.experiments.join(",")}',
...configuration.standardOptions,
...configuration.vmOptions,
test.name

View file

@ -652,8 +652,8 @@ bool DartUtils::PostInt64(Dart_Port port_id, int64_t value) {
Dart_Handle DartUtils::GetDartType(const char* library_url,
const char* class_name) {
return Dart_GetType(Dart_LookupLibrary(NewString(library_url)),
NewString(class_name), 0, NULL);
return Dart_GetNonNullableType(Dart_LookupLibrary(NewString(library_url)),
NewString(class_name), 0, NULL);
}
Dart_Handle DartUtils::NewDartOSError() {

View file

@ -76,8 +76,12 @@ static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size);
static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) {
int options_count = options->count();
Dart_Handle string_type = DartUtils::GetDartType("dart:core", "String");
if (Dart_IsError(string_type)) {
return string_type;
}
Dart_Handle dart_arguments =
Dart_NewListOf(Dart_CoreType_String, options_count);
Dart_NewListOfTypeFilled(string_type, Dart_EmptyString(), options_count);
if (Dart_IsError(dart_arguments)) {
return dart_arguments;
}

View file

@ -72,7 +72,10 @@ void FUNCTION_NAME(Platform_ResolvedExecutableName)(Dart_NativeArguments args) {
void FUNCTION_NAME(Platform_ExecutableArguments)(Dart_NativeArguments args) {
int end = Platform::GetScriptIndex();
char** argv = Platform::GetArgv();
Dart_Handle result = Dart_NewListOf(Dart_CoreType_String, end - 1);
Dart_Handle string_type = DartUtils::GetDartType("dart:core", "String");
ThrowIfError(string_type);
Dart_Handle result =
Dart_NewListOfTypeFilled(string_type, Dart_EmptyString(), end - 1);
for (intptr_t i = 1; i < end; i++) {
Dart_Handle str = DartUtils::NewString(argv[i]);
ThrowIfError(str);

View file

@ -268,12 +268,12 @@ BENCHMARK(UseDartApi) {
const char* kScriptChars =
"import 'dart:nativewrappers';\n"
"class Class extends NativeFieldWrapperClass1 {\n"
" int init() native 'init';\n"
" void init() native 'init';\n"
" int method(int param1, int param2) native 'method';\n"
"}\n"
"\n"
"void benchmark(int count) {\n"
" Class c = new Class();\n"
" Class c = Class();\n"
" c.init();\n"
" for (int i = 0; i < count; i++) {\n"
" c.method(i,7);\n"
@ -359,6 +359,10 @@ static Dart_NativeFunction NativeResolver(Dart_Handle name,
// Measure compile of all kernel Service(CFE) functions.
//
BENCHMARK(KernelServiceCompileAll) {
if (FLAG_null_safety == kNullSafetyOptionStrong) {
// TODO(bkonyi): remove this check when we build the CFE in strong mode.
return;
}
bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary);
bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary);
bin::Builtin::SetNativeResolver(bin::Builtin::kCLILibrary);

View file

@ -52,7 +52,7 @@ TEST_CASE(StackMapGC) {
" i = 10; s1 = 'abcd'; k = 20; s2 = 'B'; s3 = 'C';"
" func(i, k);"
" return i + k; }"
" static int moo() {"
" static void moo() {"
" var i = A.foo();"
" if (i != 30) throw '$i != 30';"
" }\n"

View file

@ -145,7 +145,7 @@ ISOLATE_UNIT_TEST_CASE(BCEModulo) {
const char* kScriptChars =
R"(
foo(int i) {
var l = new List<int>(3);
var l = List<int>.filled(3, 0);
return l[i % 3] ?? l[i % (-3)];
}
main() {
@ -278,7 +278,7 @@ ISOLATE_UNIT_TEST_CASE(BCEListNamedAndPlainLength) {
const char* kScriptChars =
R"(
List<int> foo(int count) {
var x = new List<int>(count);
var x = new List<int>.filled(count, 42);
for (int i = 0; i < count; i++) {
x[i] = 0;
}
@ -291,7 +291,7 @@ ISOLATE_UNIT_TEST_CASE(BCEListNamedAndPlainLength) {
foo(100);
}
)";
TestScriptJIT(kScriptChars, 2, 0);
TestScriptJIT(kScriptChars, 2, 1);
}
} // namespace dart

View file

@ -6,6 +6,7 @@
#include <vector>
#include "platform/utils.h"
#include "vm/compiler/backend/il_test_helper.h"
#include "vm/unit_test.h"
@ -45,26 +46,28 @@ ISOLATE_UNIT_TEST_CASE(OptimizationTests) {
}
ISOLATE_UNIT_TEST_CASE(IRTest_EliminateWriteBarrier) {
const char* kScript =
R"(
const char* tag = (FLAG_null_safety == kNullSafetyOptionStrong) ? "?" : "";
// clang-format off
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
class Container<T> {
operator []=(var index, var value) {
return data[index] = value;
}
List<T> data = new List<T>()..length = 10;
List<T%s> data = List<T%s>.filled(10, null);
}
Container<int> x = new Container<int>();
Container<int> x = Container<int>();
foo() {
for (int i = 0; i < 10; ++i) {
x[i] = i;
}
}
)";
)", tag, tag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript));
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
const auto& function = Function::Handle(GetFunction(root_library, "foo"));
Invoke(root_library, "foo");
@ -128,7 +131,9 @@ static void RunInitializingStoresTest(
}
ISOLATE_UNIT_TEST_CASE(IRTest_InitializingStores) {
const char* kScript = R"(
const char* tag = (FLAG_null_safety == kNullSafetyOptionStrong) ? "?" : "";
// clang-format off
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
class Bar {
var f;
var g;
@ -140,7 +145,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_InitializingStores) {
f3() {
return () { };
}
f4<T>({T value}) {
f4<T>({T%s value}) {
return () { return value; };
}
main() {
@ -149,8 +154,11 @@ ISOLATE_UNIT_TEST_CASE(IRTest_InitializingStores) {
f3();
f4();
}
)";
const auto& root_library = Library::Handle(LoadTestScript(kScript));
)",
tag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");
RunInitializingStoresTest(root_library, "f1", CompilerPass::kJIT,

View file

@ -15,14 +15,19 @@
namespace dart {
ISOLATE_UNIT_TEST_CASE(ReachabilityFence_Simple) {
const char* kScript =
R"(
const bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
const char* nullAssertTag = null_safety ? "!" : "";
// clang-format off
auto kScript =
Utils::CStringUniquePtr(OS::SCreate(nullptr,
R"(
import 'dart:_internal' show reachabilityFence;
int someGlobal = 0;
class A {
int a;
int%s a;
}
void someFunction(int arg) {
@ -31,12 +36,14 @@ ISOLATE_UNIT_TEST_CASE(ReachabilityFence_Simple) {
main() {
final object = A()..a = 10;
someFunction(object.a);
someFunction(object.a%s);
reachabilityFence(object);
}
)";
)",
nullableTag, nullAssertTag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript));
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");
@ -71,14 +78,18 @@ ISOLATE_UNIT_TEST_CASE(ReachabilityFence_Simple) {
}
ISOLATE_UNIT_TEST_CASE(ReachabilityFence_Loop) {
const char* kScript =
R"(
const bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
const char* nullAssertTag = null_safety ? "!" : "";
// clang-format off
auto kScript =
Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
import 'dart:_internal' show reachabilityFence;
int someGlobal = 0;
class A {
int a;
int%s a;
}
@pragma('vm:never-inline')
@ -93,13 +104,14 @@ ISOLATE_UNIT_TEST_CASE(ReachabilityFence_Loop) {
main() {
final object = makeSomeA();
for(int i = 0; i < 100000; i++) {
someFunction(object.a);
someFunction(object.a%s);
reachabilityFence(object);
}
}
)";
)", nullableTag, nullAssertTag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript));
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");
@ -134,14 +146,18 @@ ISOLATE_UNIT_TEST_CASE(ReachabilityFence_Loop) {
}
ISOLATE_UNIT_TEST_CASE(ReachabilityFence_NoCanonicalize) {
const char* kScript =
R"(
const bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
const char* nullAssertTag = null_safety ? "!" : "";
// clang-format off
auto kScript =
Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
import 'dart:_internal' show reachabilityFence;
int someGlobal = 0;
class A {
int a;
int%s a;
}
@pragma('vm:never-inline')
@ -157,15 +173,16 @@ ISOLATE_UNIT_TEST_CASE(ReachabilityFence_NoCanonicalize) {
final object = makeSomeA();
reachabilityFence(object);
for(int i = 0; i < 100000; i++) {
someFunction(object.a);
someFunction(object.a%s);
reachabilityFence(object);
}
reachabilityFence(object);
reachabilityFence(object);
}
)";
)", nullableTag, nullAssertTag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript));
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");

View file

@ -905,7 +905,7 @@ ISOLATE_UNIT_TEST_CASE(LoadOptimizer_RedundantStoresAndLoads) {
const char* kScript = R"(
class Bar {
Bar() { a = null; }
Object a;
dynamic a;
}
Bar foo() {

View file

@ -13,28 +13,32 @@ DEBUG_ONLY(DECLARE_FLAG(bool, trace_write_barrier_elimination);)
ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_JoinSuccessors) {
DEBUG_ONLY(FLAG_trace_write_barrier_elimination = true);
const bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
const char* nullAssertTag = null_safety ? "!" : "";
// This is a regression test for a bug where we were using
// JoinEntry::SuccessorCount() to determine the number of outgoing blocks
// from the join block. JoinEntry::SuccessorCount() is in fact always 0;
// JoinEntry::last_instruction()->SuccessorCount() should be used instead.
const char* kScript =
R"(
// clang-format off
auto kScript = Utils::CStringUniquePtr(
OS::SCreate(nullptr, R"(
class C {
int value;
C next;
C prev;
int%s value;
C%s next;
C%s prev;
}
@pragma("vm:never-inline")
fn() {}
foo(int x) {
C prev = C();
C next;
C%s prev = C();
C%s next;
while (x --> 0) {
next = C();
next.prev = prev;
next%s.prev = prev;
prev?.next = next;
prev = next;
fn();
@ -43,9 +47,12 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_JoinSuccessors) {
}
main() { foo(10); }
)";
)",
nullableTag, nullableTag, nullableTag, nullableTag,
nullableTag, nullAssertTag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript));
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");
@ -77,15 +84,17 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_JoinSuccessors) {
ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_AtLeastOnce) {
DEBUG_ONLY(FLAG_trace_write_barrier_elimination = true);
const bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* lateTag = null_safety ? "late" : "";
// Ensure that we process every block at least once during the analysis
// phase so that the out-sets will be initialized. If we don't process
// each block at least once, the store "c.next = n" will be marked
// NoWriteBarrier.
const char* kScript =
R"(
// clang-format off
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr,
R"(
class C {
C next;
%s C next;
}
@pragma("vm:never-inline")
@ -102,9 +111,9 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_AtLeastOnce) {
}
main() { foo(0); foo(10); }
)";
const auto& root_library = Library::Handle(LoadTestScript(kScript));
)", lateTag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");
@ -133,13 +142,18 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_AtLeastOnce) {
ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_Arrays) {
DEBUG_ONLY(FLAG_trace_write_barrier_elimination = true);
const bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
const char* lateTag = null_safety ? "late" : "";
// Test that array allocations are not considered usable after a
// may-trigger-GC instruction (in this case CheckStackOverflow), unlike
// normal allocations, which are only interruped by a Dart call.
const char* kScript =
R"(
// clang-format off
auto kScript =
Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
class C {
C next;
%s C next;
}
@pragma("vm:never-inline")
@ -148,7 +162,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_Arrays) {
foo(int x) {
C c = C();
C n = C();
List<C> array = List<C>(1);
List<C%s> array = List<C%s>.filled(1, null);
while (x --> 0) {
c.next = n;
n = c;
@ -159,9 +173,10 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_Arrays) {
}
main() { foo(10); }
)";
)", lateTag, nullableTag, nullableTag), std::free);
// clang-format on
const auto& root_library = Library::Handle(LoadTestScript(kScript));
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Invoke(root_library, "main");

View file

@ -3033,12 +3033,17 @@ static TypeArgumentsPtr TypeArgumentsForElementType(
return store->type_argument_legacy_string();
}
UNREACHABLE();
return NULL;
return TypeArguments::null();
}
DART_EXPORT Dart_Handle Dart_NewListOf(Dart_CoreType_Id element_type_id,
intptr_t length) {
DARTSCOPE(Thread::Current());
if (T->isolate()->null_safety() && element_type_id != Dart_CoreType_Dynamic) {
return Api::NewError(
"Cannot use legacy types with --null-safety enabled. "
"Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead.");
}
CHECK_LENGTH(length, Array::kMaxElements);
CHECK_CALLBACK_STATE(T);
const Array& arr = Array::Handle(Z, Array::New(length));
@ -5584,6 +5589,11 @@ DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library,
Dart_Handle class_name,
intptr_t number_of_type_arguments,
Dart_Handle* type_arguments) {
if (Thread::Current()->isolate()->null_safety()) {
return Api::NewError(
"Cannot use legacy types with --null-safety enabled. "
"Use Dart_GetNullableType or Dart_GetNonNullableType instead.");
}
return GetTypeCommon(library, class_name, number_of_type_arguments,
type_arguments, Nullability::kLegacy);
}

View file

@ -1079,7 +1079,7 @@ TEST_CASE(DartAPI_FunctionIsStatic) {
EXPECT_VALID(result);
EXPECT(is_static);
Dart_Handle klass = Dart_GetType(lib, NewString("Foo"), 0, NULL);
Dart_Handle klass = Dart_GetNonNullableType(lib, NewString("Foo"), 0, NULL);
EXPECT_VALID(klass);
Dart_Handle instance = Dart_Allocate(klass);
@ -1174,7 +1174,7 @@ TEST_CASE(DartAPI_GetStaticMethodClosure) {
TEST_CASE(DartAPI_ClassLibrary) {
Dart_Handle lib = Dart_LookupLibrary(NewString("dart:core"));
EXPECT_VALID(lib);
Dart_Handle type = Dart_GetType(lib, NewString("int"), 0, NULL);
Dart_Handle type = Dart_GetNonNullableType(lib, NewString("int"), 0, NULL);
EXPECT_VALID(type);
Dart_Handle result = Dart_ClassLibrary(type);
EXPECT_VALID(result);
@ -1695,7 +1695,7 @@ TEST_CASE(DartAPI_ExternalTypedDataPretenure) {
TEST_CASE(DartAPI_ListAccess) {
const char* kScriptChars =
"List testMain() {"
" List a = new List();"
" List a = List.empty(growable: true);"
" a.add(10);"
" a.add(20);"
" a.add(30);"
@ -4034,7 +4034,9 @@ TEST_CASE(DartAPI_TypeGetParameterizedTypes) {
EXPECT_VALID(double_type);
EXPECT_VALID(Dart_ListSetAt(type_args, 1, double_type));
Dart_Handle myclass0_type =
Dart_GetType(lib, NewString("MyClass0"), 2, &type_args);
(FLAG_null_safety == kNullSafetyOptionStrong)
? Dart_GetNonNullableType(lib, NewString("MyClass0"), 2, &type_args)
: Dart_GetType(lib, NewString("MyClass0"), 2, &type_args);
EXPECT_VALID(myclass0_type);
type_args = Dart_NewList(2);
@ -4046,7 +4048,9 @@ TEST_CASE(DartAPI_TypeGetParameterizedTypes) {
EXPECT_VALID(list_type);
EXPECT_VALID(Dart_ListSetAt(type_args, 1, list_type));
Dart_Handle myclass1_type =
Dart_GetType(lib, NewString("MyClass1"), 2, &type_args);
(FLAG_null_safety == kNullSafetyOptionStrong)
? Dart_GetNonNullableType(lib, NewString("MyClass1"), 2, &type_args)
: Dart_GetType(lib, NewString("MyClass1"), 2, &type_args);
EXPECT_VALID(myclass1_type);
// Now create objects of the type and validate the object type matches
@ -4220,7 +4224,7 @@ TEST_CASE(DartAPI_FieldAccess) {
// Shared setup.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("Fields"), 0, NULL);
Dart_Handle type = Dart_GetNonNullableType(lib, NewString("Fields"), 0, NULL);
EXPECT_VALID(type);
Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL);
EXPECT_VALID(instance);
@ -4413,7 +4417,9 @@ TEST_CASE(DartAPI_SetField_FunnyValue) {
}
TEST_CASE(DartAPI_SetField_BadType) {
const char* kScriptChars = "int foo;\n";
const char* kScriptChars = (FLAG_null_safety == kNullSafetyOptionStrong)
? "late int foo;\n"
: "int foo;\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle name = NewString("foo");
Dart_Handle result = Dart_SetField(lib, name, Dart_True());
@ -4435,22 +4441,29 @@ static Dart_NativeFunction native_field_lookup(Dart_Handle name,
}
TEST_CASE(DartAPI_InjectNativeFields2) {
const char* kScriptChars =
"class NativeFields extends NativeFieldsWrapper {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n";
bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(nullptr,
"class NativeFields extends NativeFieldsWrapper {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld;\n"
" static int%s fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n",
nullableTag), std::free);
// clang-format on
Dart_Handle result;
// Create a test library and Load up a test script in it.
Dart_Handle lib =
TestCase::LoadTestScript(kScriptChars, NULL, USER_TEST_URI, false);
TestCase::LoadTestScript(kScriptChars.get(), NULL, USER_TEST_URI, false);
// Invoke a function which returns an object of type NativeFields.
result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
@ -4462,24 +4475,31 @@ TEST_CASE(DartAPI_InjectNativeFields2) {
}
TEST_CASE(DartAPI_InjectNativeFields3) {
const char* kScriptChars =
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass2 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n";
bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(nullptr,
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass2 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int%s fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n",
nullableTag), std::free);
// clang-format on
Dart_Handle result;
const int kNumNativeFields = 2;
// Load up a test script in the test library.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup);
Dart_Handle lib =
TestCase::LoadTestScript(kScriptChars.get(), native_field_lookup);
// Invoke a function which returns an object of type NativeFields.
result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
@ -4504,22 +4524,27 @@ TEST_CASE(DartAPI_InjectNativeFields3) {
}
TEST_CASE(DartAPI_InjectNativeFields4) {
const char* kScriptChars =
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass2 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n";
bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(nullptr,
"class NativeFields extends NativeFieldsWrapperClass2 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld;\n"
" static int%s fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n",
nullableTag), std::free);
// clang-format on
Dart_Handle result;
// Load up a test script in the test library.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars.get(), NULL);
// Invoke a function which returns an object of type NativeFields.
result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
@ -4585,27 +4610,36 @@ static Dart_NativeFunction TestNativeFieldsAccess_lookup(Dart_Handle name,
}
TEST_CASE(DartAPI_TestNativeFieldsAccess) {
const char* kScriptChars =
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass2 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int fld3;\n"
" static const int fld4 = 10;\n"
" int initNativeFlds() native 'TestNativeFieldsAccess_init';\n"
" int accessNativeFlds(int i) native 'TestNativeFieldsAccess_access';\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" obj.initNativeFlds();\n"
" obj.accessNativeFlds(null);\n"
" return obj;\n"
"}\n";
bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(
nullptr,
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass2 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int%s fld3;\n"
" static const int fld4 = 10;\n"
" int%s initNativeFlds() native 'TestNativeFieldsAccess_init';\n"
" int%s accessNativeFlds(int%s i) native "
"'TestNativeFieldsAccess_access';\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" obj.initNativeFlds();\n"
" obj.accessNativeFlds(null);\n"
" return obj;\n"
"}\n",
nullableTag, nullableTag, nullableTag, nullableTag),
std::free);
// clang-format on
// Load up a test script in the test library.
Dart_Handle lib =
TestCase::LoadTestScript(kScriptChars, TestNativeFieldsAccess_lookup);
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars.get(),
TestNativeFieldsAccess_lookup);
// Invoke a function which returns an object of type NativeFields.
Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
@ -4717,22 +4751,30 @@ static void TestNativeFields(Dart_Handle retobj) {
}
TEST_CASE(DartAPI_ImplicitNativeFieldAccess) {
const char* kScriptChars =
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass4 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld0;\n"
" int fld1;\n"
" final int fld2;\n"
" static int fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n";
bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(nullptr,
"import 'dart:nativewrappers';"
"class NativeFields extends NativeFieldWrapperClass4 {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int%s fld0;\n"
" int fld1;\n"
" final int fld2;\n"
" static int%s fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n",
nullableTag, nullableTag),
std::free);
// clang-format on
// Load up a test script in the test library.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup);
Dart_Handle lib =
TestCase::LoadTestScript(kScriptChars.get(), native_field_lookup);
// Invoke a function which returns an object of type NativeFields.
Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
@ -4743,26 +4785,35 @@ TEST_CASE(DartAPI_ImplicitNativeFieldAccess) {
}
TEST_CASE(DartAPI_NegativeNativeFieldAccess) {
const char* kScriptChars =
"class NativeFields {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain1() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n"
"Function testMain2() {\n"
" return () {};\n"
"}\n";
bool null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = null_safety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(nullptr,
"import 'dart:nativewrappers';\n"
"class NativeFields {\n"
" NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" static int%s fld3;\n"
" static const int fld4 = 10;\n"
"}\n"
"NativeFields testMain1() {\n"
" NativeFields obj = new NativeFields(10, 20);\n"
" return obj;\n"
"}\n"
"Function testMain2() {\n"
" return () {};\n"
"}\n",
nullableTag),
std::free);
// clang-format on
Dart_Handle result;
CHECK_API_SCOPE(thread);
// Create a test library and Load up a test script in it.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars.get(), NULL);
// Invoke a function which returns an object of type NativeFields.
Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL);
@ -4823,7 +4874,8 @@ TEST_CASE(DartAPI_GetStaticField_RunsInitializer) {
Dart_Handle result;
// Create a test library and Load up a test script in it.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("TestClass"), 0, NULL);
EXPECT_VALID(type);
// Invoke a function which returns an object.
@ -4865,7 +4917,8 @@ TEST_CASE(DartAPI_GetField_CheckIsolate) {
// Create a test library and Load up a test script in it.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("TestClass"), 0, NULL);
EXPECT_VALID(type);
result = Dart_GetField(type, NewString("fld2"));
@ -4886,7 +4939,8 @@ TEST_CASE(DartAPI_SetField_CheckIsolate) {
// Create a test library and Load up a test script in it.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("TestClass"), 0, NULL);
EXPECT_VALID(type);
result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13));
@ -4927,9 +4981,11 @@ TEST_CASE(DartAPI_New) {
"}\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("MyClass"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("MyClass"), 0, NULL);
EXPECT_VALID(type);
Dart_Handle intf = Dart_GetType(lib, NewString("MyInterface"), 0, NULL);
Dart_Handle intf =
Dart_GetNonNullableType(lib, NewString("MyInterface"), 0, NULL);
EXPECT_VALID(intf);
Dart_Handle args[1];
args[0] = Dart_NewInteger(11);
@ -5135,7 +5191,8 @@ TEST_CASE(DartAPI_New_Issue2971) {
// factories.
Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core"));
EXPECT_VALID(core_lib);
Dart_Handle list_type = Dart_GetType(core_lib, NewString("List"), 0, NULL);
Dart_Handle list_type =
Dart_GetNonNullableType(core_lib, NewString("List"), 0, NULL);
EXPECT_VALID(list_type);
const int kNumArgs = 1;
@ -5156,16 +5213,21 @@ TEST_CASE(DartAPI_NewListOf) {
const int kNumArgs = 1;
Dart_Handle args[kNumArgs];
const char* str;
Dart_Handle result;
Dart_Handle string_list = Dart_NewListOf(Dart_CoreType_String, 1);
EXPECT_VALID(string_list);
args[0] = string_list;
Dart_Handle result =
Dart_Invoke(lib, NewString("expectListOfString"), kNumArgs, args);
EXPECT_VALID(result);
result = Dart_StringToCString(result, &str);
EXPECT_VALID(result);
EXPECT_STREQ("null", str);
if (!Dart_IsError(string_list)) {
args[0] = string_list;
Dart_Handle result =
Dart_Invoke(lib, NewString("expectListOfString"), kNumArgs, args);
EXPECT_VALID(result);
result = Dart_StringToCString(result, &str);
EXPECT_VALID(result);
EXPECT_STREQ("null", str);
} else {
EXPECT_ERROR(string_list,
"Cannot use legacy types with --null-safety enabled. "
"Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead.");
}
Dart_Handle dynamic_list = Dart_NewListOf(Dart_CoreType_Dynamic, 1);
EXPECT_VALID(dynamic_list);
@ -5176,12 +5238,17 @@ TEST_CASE(DartAPI_NewListOf) {
EXPECT_STREQ("null", str);
Dart_Handle int_list = Dart_NewListOf(Dart_CoreType_Int, 1);
EXPECT_VALID(int_list);
args[0] = int_list;
result = Dart_Invoke(lib, NewString("expectListOfInt"), kNumArgs, args);
EXPECT_VALID(result);
result = Dart_StringToCString(result, &str);
EXPECT_STREQ("null", str);
if (!Dart_IsError(int_list)) {
args[0] = int_list;
result = Dart_Invoke(lib, NewString("expectListOfInt"), kNumArgs, args);
EXPECT_VALID(result);
result = Dart_StringToCString(result, &str);
EXPECT_STREQ("null", str);
} else {
EXPECT_ERROR(int_list,
"Cannot use legacy types with --null-safety enabled. "
"Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead.");
}
}
TEST_CASE(DartAPI_NewListOfType) {
@ -5197,7 +5264,8 @@ TEST_CASE(DartAPI_NewListOfType) {
"void expectListOfNever(List<Never> _) {}\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle zxhandle_type = Dart_GetType(lib, NewString("ZXHandle"), 0, NULL);
Dart_Handle zxhandle_type =
Dart_GetNullableType(lib, NewString("ZXHandle"), 0, NULL);
EXPECT_VALID(zxhandle_type);
Dart_Handle zxhandle = Dart_New(zxhandle_type, Dart_Null(), 0, NULL);
@ -5209,7 +5277,7 @@ TEST_CASE(DartAPI_NewListOfType) {
EXPECT_VALID(Dart_ListSetAt(zxhandle_list, 0, zxhandle));
Dart_Handle readresult_type =
Dart_GetType(lib, NewString("ChannelReadResult"), 0, NULL);
Dart_GetNonNullableType(lib, NewString("ChannelReadResult"), 0, NULL);
EXPECT_VALID(zxhandle_type);
const int kNumArgs = 1;
@ -5228,7 +5296,7 @@ TEST_CASE(DartAPI_NewListOfType) {
EXPECT_VALID(dart_core);
Dart_Handle string_type =
Dart_GetType(dart_core, NewString("String"), 0, NULL);
Dart_GetNonNullableType(dart_core, NewString("String"), 0, NULL);
EXPECT_VALID(string_type);
Dart_Handle string_list = Dart_NewListOfType(string_type, 0);
EXPECT_VALID(string_list);
@ -5293,7 +5361,7 @@ TEST_CASE(DartAPI_NewListOfTypeFilled) {
EXPECT(Dart_IdentityEquals(result, zxhandle));
Dart_Handle readresult_type =
Dart_GetType(lib, NewString("ChannelReadResult"), 0, NULL);
Dart_GetNonNullableType(lib, NewString("ChannelReadResult"), 0, NULL);
EXPECT_VALID(zxhandle_type);
const int kNumArgs = 1;
@ -5355,7 +5423,8 @@ TEST_CASE(DartAPI_Invoke) {
// Shared setup.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("Methods"), 0, NULL);
EXPECT_VALID(type);
Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL);
EXPECT_VALID(instance);
@ -5461,7 +5530,8 @@ TEST_CASE(DartAPI_Invoke_PrivateStatic) {
// Shared setup.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("Methods"), 0, NULL);
Dart_Handle result;
EXPECT_VALID(type);
Dart_Handle name = NewString("_staticMethod");
@ -5554,7 +5624,8 @@ TEST_CASE(DartAPI_Invoke_BadArgs) {
// Shared setup.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("Methods"), 0, NULL);
EXPECT_VALID(type);
Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL);
EXPECT_VALID(instance);
@ -5672,7 +5743,8 @@ TEST_CASE(DartAPI_InvokeNoSuchMethod) {
// Create a test library and Load up a test script in it.
// The test library must have a dart: url so it can import dart:_internal.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("TestClass"), 0, NULL);
EXPECT_VALID(type);
// Invoke a function which returns an object.
@ -5806,7 +5878,8 @@ static intptr_t kNativeArgumentNativeField2Value = 40;
static intptr_t native_arg_str_peer = 100;
static void NativeArgumentCreate(Dart_NativeArguments args) {
Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url()));
Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("MyObject"), 0, NULL);
EXPECT_VALID(type);
// Allocate without a constructor.
@ -6038,94 +6111,53 @@ TEST_CASE(DartAPI_TypeToNullability) {
const Dart_Handle name = NewString("Class");
// Lookup the legacy type for Class.
Dart_Handle type = Dart_GetType(lib, name, 0, NULL);
EXPECT_VALID(type);
bool result = false;
EXPECT_VALID(Dart_IsLegacyType(type, &result));
EXPECT(result);
Dart_Handle nonNullableType;
Dart_Handle nullableType;
if (Dart_IsError(type)) {
EXPECT_ERROR(
type,
"Cannot use legacy types with --null-safety enabled. "
"Use Dart_GetNullableType or Dart_GetNonNullableType instead.");
// Legacy -> Nullable
Dart_Handle nullableType = Dart_TypeToNullableType(type);
EXPECT_VALID(nullableType);
result = false;
EXPECT_VALID(Dart_IsNullableType(nullableType, &result));
EXPECT(result);
EXPECT(Dart_IdentityEquals(nullableType,
Dart_GetNullableType(lib, name, 0, nullptr)));
nonNullableType = Dart_GetNonNullableType(lib, name, 0, nullptr);
EXPECT_VALID(nonNullableType);
nullableType = Dart_GetNullableType(lib, name, 0, nullptr);
} else {
EXPECT_VALID(type);
bool result = false;
EXPECT_VALID(Dart_IsLegacyType(type, &result));
EXPECT(result);
// Legacy -> Non-Nullable
Dart_Handle nonNullableType = Dart_TypeToNonNullableType(type);
EXPECT_VALID(nonNullableType);
result = false;
EXPECT_VALID(Dart_IsNonNullableType(nonNullableType, &result));
EXPECT(result);
EXPECT(Dart_IdentityEquals(nonNullableType,
Dart_GetNonNullableType(lib, name, 0, nullptr)));
// Legacy -> Nullable
nullableType = Dart_TypeToNullableType(type);
EXPECT_VALID(nullableType);
result = false;
EXPECT_VALID(Dart_IsNullableType(nullableType, &result));
EXPECT(result);
EXPECT(Dart_IdentityEquals(nullableType,
Dart_GetNullableType(lib, name, 0, nullptr)));
// Legacy -> Non-Nullable
nonNullableType = Dart_TypeToNonNullableType(type);
EXPECT_VALID(nonNullableType);
result = false;
EXPECT_VALID(Dart_IsNonNullableType(nonNullableType, &result));
EXPECT(result);
EXPECT(Dart_IdentityEquals(nonNullableType,
Dart_GetNonNullableType(lib, name, 0, nullptr)));
}
// Nullable -> Non-Nullable
EXPECT(Dart_IdentityEquals(
nonNullableType,
Dart_TypeToNonNullableType(Dart_GetNullableType(lib, name, 0, nullptr))));
// Nullable -> Non-Nullable
// Non-Nullable -> Nullable
EXPECT(Dart_IdentityEquals(
nullableType,
Dart_TypeToNullableType(Dart_GetNonNullableType(lib, name, 0, nullptr))));
}
TEST_CASE(DartAPI_GetType) {
const char* kScriptChars =
"library testlib;\n"
"class Class {\n"
" static var name = 'Class';\n"
"}\n"
"\n"
"class _Class {\n"
" static var name = '_Class';\n"
"}\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
// Lookup a class.
Dart_Handle type = Dart_GetType(lib, NewString("Class"), 0, NULL);
EXPECT_VALID(type);
bool result = false;
EXPECT_VALID(Dart_IsLegacyType(type, &result));
EXPECT(result);
Dart_Handle name = Dart_GetField(type, NewString("name"));
EXPECT_VALID(name);
const char* name_cstr = "";
EXPECT_VALID(Dart_StringToCString(name, &name_cstr));
EXPECT_STREQ("Class", name_cstr);
// Lookup a private class.
type = Dart_GetType(lib, NewString("_Class"), 0, NULL);
EXPECT_VALID(type);
result = false;
EXPECT_VALID(Dart_IsLegacyType(type, &result));
EXPECT(result);
name = Dart_GetField(type, NewString("name"));
EXPECT_VALID(name);
name_cstr = "";
EXPECT_VALID(Dart_StringToCString(name, &name_cstr));
EXPECT_STREQ("_Class", name_cstr);
// Lookup a class that does not exist.
type = Dart_GetType(lib, NewString("DoesNotExist"), 0, NULL);
EXPECT(Dart_IsError(type));
EXPECT_STREQ("Type 'DoesNotExist' not found in library 'testlib'.",
Dart_GetError(type));
// Lookup a class from an error library. The error propagates.
type = Dart_GetType(Api::NewError("myerror"), NewString("Class"), 0, NULL);
EXPECT(Dart_IsError(type));
EXPECT_STREQ("myerror", Dart_GetError(type));
// Lookup a type using an error class name. The error propagates.
type = Dart_GetType(lib, Api::NewError("myerror"), 0, NULL);
EXPECT(Dart_IsError(type));
EXPECT_STREQ("myerror", Dart_GetError(type));
}
TEST_CASE(DartAPI_GetNullableType) {
const char* kScriptChars =
"library testlib;\n"
@ -6263,7 +6295,8 @@ TEST_CASE(DartAPI_InstanceOf) {
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
// Fetch InstanceOfTest class.
Dart_Handle type = Dart_GetType(lib, NewString("InstanceOfTest"), 0, NULL);
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("InstanceOfTest"), 0, NULL);
EXPECT_VALID(type);
// Invoke a function which returns an object of type InstanceOf..
@ -6279,7 +6312,8 @@ TEST_CASE(DartAPI_InstanceOf) {
EXPECT(is_instance);
// Fetch OtherClass and check if instanceOfTestObj is instance of it.
Dart_Handle otherType = Dart_GetType(lib, NewString("OtherClass"), 0, NULL);
Dart_Handle otherType =
Dart_GetNonNullableType(lib, NewString("OtherClass"), 0, NULL);
EXPECT_VALID(otherType);
result = Dart_ObjectIsType(instanceOfTestObj, otherType, &is_instance);
@ -6472,7 +6506,7 @@ TEST_CASE(DartAPI_SetNativeResolver) {
result = Dart_FinalizeLoading(false);
EXPECT_VALID(result);
EXPECT(Dart_IsLibrary(lib));
Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL);
Dart_Handle type = Dart_GetNonNullableType(lib, NewString("Test"), 0, NULL);
EXPECT_VALID(type);
result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL);
@ -8206,9 +8240,9 @@ TEST_CASE(DartAPI_NotifyIdleShort) {
"void main() {\n"
" var v;\n"
" for (var i = 0; i < 100; i++) {\n"
" var t = new List();\n"
" var t = [];\n"
" for (var j = 0; j < 10000; j++) {\n"
" t.add(new List(100));\n"
" t.add(List.filled(100, null));\n"
" }\n"
" v = t;\n"
" notifyIdle();\n"
@ -8237,9 +8271,9 @@ TEST_CASE(DartAPI_NotifyIdleLong) {
"void main() {\n"
" var v;\n"
" for (var i = 0; i < 100; i++) {\n"
" var t = new List();\n"
" var t = [];\n"
" for (var j = 0; j < 10000; j++) {\n"
" t.add(new List(100));\n"
" t.add(List.filled(100, null));\n"
" }\n"
" v = t;\n"
" notifyIdle();\n"
@ -8269,9 +8303,9 @@ TEST_CASE(DartAPI_NotifyLowMemory) {
"void main() {\n"
" var v;\n"
" for (var i = 0; i < 100; i++) {\n"
" var t = new List();\n"
" var t = [];\n"
" for (var j = 0; j < 10000; j++) {\n"
" t.add(new List(100));\n"
" t.add(List.filled(100, null));\n"
" }\n"
" v = t;\n"
" notifyLowMemory();\n"
@ -8346,6 +8380,7 @@ TEST_CASE(DartAPI_InvokeVMServiceMethod) {
if (!condition) {
throw 'Failed to validate InvokeVMServiceMethod() response.';
}
return false;
}
bool validateResult(Uint8List bytes) {
final map = json.decode(utf8.decode(bytes));

View file

@ -32,7 +32,7 @@ TEST_CASE(GuardFieldSimpleTest) {
"class A {\n"
" var f1 = 3.0;\n"
" dynamic f2 = 3;\n"
" var f3 = new List(4);\n"
" var f3 = List<dynamic>.filled(4, null);\n"
" foo() {\n"
" f1 = f1 + f1;\n"
" }\n"
@ -43,14 +43,14 @@ TEST_CASE(GuardFieldSimpleTest) {
"}\n"
"\n"
"runFoo() {\n"
" var a = new A();\n"
" var a = A();\n"
" for (int i = 0; i < 2000; i++) {\n"
" a.foo();\n"
" }\n"
"}\n"
"\n"
"runBar() {\n"
" var a = new A();\n"
" var a = A();\n"
" for (int i = 0; i < 2000; i++) {\n"
" a.bar();\n"
" }\n"
@ -83,7 +83,7 @@ TEST_CASE(GuardFieldFinalListTest) {
"class A {\n"
" var f1 = 3.0;\n"
" dynamic f2 = 3;\n"
" final f3 = new List(4);\n"
" final f3 = List<dynamic>.filled(4, null);\n"
" foo() {\n"
" f1 = f1 + f1;\n"
" }\n"
@ -94,14 +94,14 @@ TEST_CASE(GuardFieldFinalListTest) {
"}\n"
"\n"
"runFoo() {\n"
" var a = new A();\n"
" var a = A();\n"
" for (int i = 0; i < 2000; i++) {\n"
" a.foo();\n"
" }\n"
"}\n"
"\n"
"runBar() {\n"
" var a = new A();\n"
" var a = A();\n"
" for (int i = 0; i < 2000; i++) {\n"
" a.bar();\n"
" }\n"
@ -136,7 +136,7 @@ TEST_CASE(GuardFieldFinalVariableLengthListTest) {
"class A {\n"
" var f1 = 3.0;\n"
" dynamic f2 = 3;\n"
" final f3 = new List();\n"
" final f3 = List.empty(growable: true);\n"
" foo() {\n"
" f1 = f1 + f1;\n"
" }\n"
@ -147,14 +147,14 @@ TEST_CASE(GuardFieldFinalVariableLengthListTest) {
"}\n"
"\n"
"runFoo() {\n"
" var a = new A();\n"
" var a = A();\n"
" for (int i = 0; i < 2000; i++) {\n"
" a.foo();\n"
" }\n"
"}\n"
"\n"
"runBar() {\n"
" var a = new A();\n"
" var a = A();\n"
" for (int i = 0; i < 2000; i++) {\n"
" a.bar();\n"
" }\n"

View file

@ -68,7 +68,7 @@ TEST_CASE(OldGC_Unsync) {
TEST_CASE(LargeSweep) {
const char* kScriptChars =
"main() {\n"
" return new List(8 * 1024 * 1024);\n"
" return List.filled(8 * 1024 * 1024, null);\n"
"}\n";
NOT_IN_PRODUCT(FLAG_verbose_gc = true);
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);

File diff suppressed because it is too large Load diff

View file

@ -28,11 +28,11 @@ TEST_CASE(IsolateSpawn) {
// Ignores printed lines.
"var _nullPrintClosure = (String line) {};\n"
"void entry(message) {}\n"
"int testMain() {\n"
"void testMain() {\n"
" Isolate.spawn(entry, null);\n"
// TODO(floitsch): the following code is only to bump the event loop
// so it executes asynchronous microtasks.
" var rp = new RawReceivePort();\n"
" var rp = RawReceivePort();\n"
" rp.sendPort.send(null);\n"
" rp.handler = (_) { rp.close(); };\n"
"}\n";

View file

@ -1814,8 +1814,8 @@ static void TestIllegalArrayLength(intptr_t length) {
char buffer[1024];
Utils::SNPrint(buffer, sizeof(buffer),
"main() {\n"
" new List(%" Pd
");\n"
" List.filled(%" Pd
", null);\n"
"}\n",
length);
Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
@ -1843,8 +1843,8 @@ TEST_CASE(ArrayLengthOneTooMany) {
char buffer[1024];
Utils::SNPrint(buffer, sizeof(buffer),
"main() {\n"
" return new List(%" Pd
");\n"
" return List.filled(%" Pd
", null);\n"
"}\n",
kOneTooMany);
Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
@ -1857,8 +1857,8 @@ TEST_CASE(ArrayLengthMaxElements) {
char buffer[1024];
Utils::SNPrint(buffer, sizeof(buffer),
"main() {\n"
" return new List(%" Pd
");\n"
" return List.filled(%" Pd
", null);\n"
"}\n",
Array::kMaxElements);
Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL);
@ -3748,39 +3748,45 @@ static void PrintMetadata(const char* name, const Object& data) {
}
TEST_CASE(Metadata) {
const char* kScriptChars =
"@metafoo \n"
"class Meta { \n"
" final m; \n"
" const Meta(this.m); \n"
"} \n"
" \n"
"const metafoo = 'metafoo'; \n"
"const metabar = 'meta' 'bar'; \n"
" \n"
"@metafoo \n"
"@Meta(0) String gVar; \n"
" \n"
"@metafoo \n"
"get tlGetter => gVar; \n"
" \n"
"@metabar \n"
"class A { \n"
" @metafoo \n"
" @metabar \n"
" @Meta('baz') \n"
" var aField; \n"
" \n"
" @metabar @Meta('baa') \n"
" int aFunc(a,b) => a + b; \n"
"} \n"
" \n"
"@Meta('main') \n"
"A main() { \n"
" return new A(); \n"
"} \n";
bool nullSafety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = nullSafety ? "?" : "";
// clang-format off
auto kScriptChars =
Utils::CStringUniquePtr(OS::SCreate(nullptr,
"@metafoo \n"
"class Meta { \n"
" final m; \n"
" const Meta(this.m); \n"
"} \n"
" \n"
"const metafoo = 'metafoo'; \n"
"const metabar = 'meta' 'bar'; \n"
" \n"
"@metafoo \n"
"@Meta(0) String%s gVar; \n"
" \n"
"@metafoo \n"
"get tlGetter => gVar; \n"
" \n"
"@metabar \n"
"class A { \n"
" @metafoo \n"
" @metabar \n"
" @Meta('baz') \n"
" var aField; \n"
" \n"
" @metabar @Meta('baa') \n"
" int aFunc(a,b) => a + b; \n"
"} \n"
" \n"
"@Meta('main') \n"
"A main() { \n"
" return A(); \n"
"} \n",
nullableTag), std::free);
// clang-format on
Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL);
Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars.get(), NULL);
EXPECT_VALID(h_lib);
Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
EXPECT_VALID(result);
@ -4412,8 +4418,8 @@ TEST_CASE(LinkedHashMap) {
const char* kScript =
"import 'dart:collection';\n"
"makeMap() {\n"
" Function eq = (a, b) => true;\n"
" Function hc = (a) => 42;\n"
" bool Function(dynamic, dynamic) eq = (a, b) => true;\n"
" int Function(dynamic) hc = (a) => 42;\n"
" return new LinkedHashMap(equals: eq, hashCode: hc);\n"
"}";
Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);

View file

@ -936,8 +936,8 @@ ISOLATE_UNIT_TEST_CASE(Profiler_ArrayAllocation) {
DisableNativeProfileScope dnps;
DisableBackgroundCompilationScope dbcs;
const char* kScript =
"List foo() => new List(4);\n"
"List bar() => new List();\n";
"List foo() => List.filled(4, null);\n"
"List bar() => List.empty(growable: true);\n";
const Library& root_library = Library::Handle(LoadTestScript(kScript));
Isolate* isolate = thread->isolate();
@ -2437,20 +2437,20 @@ static uword FindPCForTokenPosition(const Code& code, TokenPosition tp) {
ISOLATE_UNIT_TEST_CASE(Profiler_GetSourceReport) {
EnableProfiler();
const char* kScript =
"doWork(i) => i * i;\n"
"main() {\n"
" var sum = 0;\n"
" for (var i = 0; i < 100; i++) {\n"
"int doWork(i) => i * i;\n"
"int main() {\n"
" int sum = 0;\n"
" for (int i = 0; i < 100; i++) {\n"
" sum += doWork(i);\n"
" }\n"
" return sum;\n"
"}\n";
// Token position of * in `i * i`.
const TokenPosition squarePosition = TokenPosition(15);
const TokenPosition squarePosition = TokenPosition(19);
// Token position of the call to `doWork`.
const TokenPosition callPosition = TokenPosition(90);
const TokenPosition callPosition = TokenPosition(95);
DisableNativeProfileScope dnps;
// Disable profiling for this thread.
@ -2542,14 +2542,14 @@ ISOLATE_UNIT_TEST_CASE(Profiler_GetSourceReport) {
}
// Verify positions in do_work.
EXPECT_SUBSTRING("\"positions\":[\"ControlFlow\",15]", js.ToCString());
EXPECT_SUBSTRING("\"positions\":[\"ControlFlow\",19]", js.ToCString());
// Verify exclusive ticks in do_work.
EXPECT_SUBSTRING("\"exclusiveTicks\":[1,2]", js.ToCString());
// Verify inclusive ticks in do_work.
EXPECT_SUBSTRING("\"inclusiveTicks\":[1,2]", js.ToCString());
// Verify positions in main.
EXPECT_SUBSTRING("\"positions\":[90]", js.ToCString());
EXPECT_SUBSTRING("\"positions\":[95]", js.ToCString());
// Verify exclusive ticks in main.
EXPECT_SUBSTRING("\"exclusiveTicks\":[0]", js.ToCString());
// Verify inclusive ticks in main.

View file

@ -699,29 +699,37 @@ ISOLATE_UNIT_TEST_CASE(SerializeEmptyByteArray) {
}
VM_UNIT_TEST_CASE(FullSnapshot) {
const char* kScriptChars =
"class Fields {\n"
" Fields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" final int bigint_fld = 0xfffffffffff;\n"
" static int fld3;\n"
" static const int smi_sfld = 10;\n"
" static const int bigint_sfld = 0xfffffffffff;\n"
"}\n"
"class Expect {\n"
" static void equals(x, y) {\n"
" if (x != y) throw new ArgumentError('not equal');\n"
" }\n"
"}\n"
"class FieldsTest {\n"
" static Fields testMain() {\n"
" Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n"
" Fields obj = new Fields(10, 20);\n"
" Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n"
" return obj;\n"
" }\n"
"}\n";
bool nullSafety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = nullSafety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(
nullptr,
"class Fields {\n"
" Fields(int i, int j) : fld1 = i, fld2 = j {}\n"
" int fld1;\n"
" final int fld2;\n"
" final int bigint_fld = 0xfffffffffff;\n"
" static int%s fld3;\n"
" static const int smi_sfld = 10;\n"
" static const int bigint_sfld = 0xfffffffffff;\n"
"}\n"
"class Expect {\n"
" static void equals(x, y) {\n"
" if (x != y) throw new ArgumentError('not equal');\n"
" }\n"
"}\n"
"class FieldsTest {\n"
" static Fields testMain() {\n"
" Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n"
" Fields obj = new Fields(10, 20);\n"
" Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n"
" return obj;\n"
" }\n"
"}\n",
nullableTag),
std::free);
// clang-format on
Dart_Handle result;
uint8_t* isolate_snapshot_data_buffer;
@ -733,7 +741,7 @@ VM_UNIT_TEST_CASE(FullSnapshot) {
TestIsolateScope __test_isolate__;
// Create a test library and Load up a test script in it.
TestCase::LoadTestScript(kScriptChars, NULL);
TestCase::LoadTestScript(kScriptChars.get(), NULL);
Thread* thread = Thread::Current();
TransitionNativeToVM transition(thread);
@ -848,19 +856,19 @@ VM_UNIT_TEST_CASE(DartGeneratedMessages) {
" return \"\\u{10000}\\u{1F601}\\u{1F637}\\u{20000}\";\n"
"}\n"
"getLeadSurrogateString() {\n"
" return new String.fromCharCodes([0xd800]);\n"
" return String.fromCharCodes([0xd800]);\n"
"}\n"
"getTrailSurrogateString() {\n"
" return \"\\u{10000}\".substring(1);\n"
"}\n"
"getSurrogatesString() {\n"
" return new String.fromCharCodes([0xdc00, 0xdc00, 0xd800, 0xd800]);\n"
" return String.fromCharCodes([0xdc00, 0xdc00, 0xd800, 0xd800]);\n"
"}\n"
"getCrappyString() {\n"
" return new String.fromCharCodes([0xd800, 32, 0xdc00, 32]);\n"
" return String.fromCharCodes([0xd800, 32, 0xdc00, 32]);\n"
"}\n"
"getList() {\n"
" return new List(kArrayLength);\n"
" return List.filled(kArrayLength, null);\n"
"}\n";
TestCase::CreateTestIsolate();
@ -959,20 +967,20 @@ VM_UNIT_TEST_CASE(DartGeneratedListMessages) {
static const char* kScriptChars =
"final int kArrayLength = 10;\n"
"getList() {\n"
" return new List(kArrayLength);\n"
" return List.filled(kArrayLength, null);\n"
"}\n"
"getIntList() {\n"
" var list = new List<int>(kArrayLength);\n"
" var list = List<int>.filled(kArrayLength, 0);\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = i;\n"
" return list;\n"
"}\n"
"getStringList() {\n"
" var list = new List<String>(kArrayLength);\n"
" var list = List<String>.filled(kArrayLength, '');\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = i.toString();\n"
" return list;\n"
"}\n"
"getMixedList() {\n"
" var list = new List(kArrayLength);\n"
" var list = List<dynamic>.filled(kArrayLength, null);\n"
" list[0] = 0;\n"
" list[1] = '1';\n"
" list[2] = 2.2;\n"
@ -1291,46 +1299,46 @@ VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
"final int kArrayLength = 10;\n"
"getStringList() {\n"
" var s = 'Hello, world!';\n"
" var list = new List<String>(kArrayLength);\n"
" var list = List<String>.filled(kArrayLength, '');\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = s;\n"
" return list;\n"
"}\n"
"getMintList() {\n"
" var mint = 0x7FFFFFFFFFFFFFFF;\n"
" var list = new List(kArrayLength);\n"
" var list = List.filled(kArrayLength, 0);\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = mint;\n"
" return list;\n"
"}\n"
"getDoubleList() {\n"
" var d = 3.14;\n"
" var list = new List<double>(kArrayLength);\n"
" var list = List<double>.filled(kArrayLength, 0.0);\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = d;\n"
" return list;\n"
"}\n"
"getTypedDataList() {\n"
" var byte_array = new Uint8List(256);\n"
" var list = new List(kArrayLength);\n"
" var byte_array = Uint8List(256);\n"
" var list = List<dynamic>.filled(kArrayLength, null);\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = byte_array;\n"
" return list;\n"
"}\n"
"getTypedDataViewList() {\n"
" var uint8_list = new Uint8List(256);\n"
" var uint8_list = Uint8List(256);\n"
" uint8_list[64] = 1;\n"
" var uint8_list_view =\n"
" new Uint8List.view(uint8_list.buffer, 64, 128);\n"
" var list = new List(kArrayLength);\n"
" Uint8List.view(uint8_list.buffer, 64, 128);\n"
" var list = List<dynamic>.filled(kArrayLength, null);\n"
" for (var i = 0; i < kArrayLength; i++) list[i] = uint8_list_view;\n"
" return list;\n"
"}\n"
"getMixedList() {\n"
" var list = new List(kArrayLength);\n"
" var list = List<dynamic>.filled(kArrayLength, null);\n"
" for (var i = 0; i < kArrayLength; i++) {\n"
" list[i] = ((i % 2) == 0) ? 'A' : 2.72;\n"
" }\n"
" return list;\n"
"}\n"
"getSelfRefList() {\n"
" var list = new List(kArrayLength);\n"
" var list = List<dynamic>.filled(kArrayLength, null, growable: true);\n"
" for (var i = 0; i < kArrayLength; i++) {\n"
" list[i] = list;\n"
" }\n"
@ -1697,71 +1705,71 @@ VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) {
static const char* kScriptChars =
"import 'dart:typed_data';\n"
"getTypedDataList() {\n"
" var list = new List(10);\n"
" var list = List<dynamic>.filled(10, null);\n"
" var index = 0;\n"
" list[index++] = new Int8List(256);\n"
" list[index++] = new Uint8List(256);\n"
" list[index++] = new Int16List(256);\n"
" list[index++] = new Uint16List(256);\n"
" list[index++] = new Int32List(256);\n"
" list[index++] = new Uint32List(256);\n"
" list[index++] = new Int64List(256);\n"
" list[index++] = new Uint64List(256);\n"
" list[index++] = new Float32List(256);\n"
" list[index++] = new Float64List(256);\n"
" list[index++] = Int8List(256);\n"
" list[index++] = Uint8List(256);\n"
" list[index++] = Int16List(256);\n"
" list[index++] = Uint16List(256);\n"
" list[index++] = Int32List(256);\n"
" list[index++] = Uint32List(256);\n"
" list[index++] = Int64List(256);\n"
" list[index++] = Uint64List(256);\n"
" list[index++] = Float32List(256);\n"
" list[index++] = Float64List(256);\n"
" return list;\n"
"}\n"
"getTypedDataViewList() {\n"
" var list = new List(30);\n"
" var list = List<dynamic>.filled(30, null);\n"
" var index = 0;\n"
" list[index++] = new Int8List.view(new Int8List(256).buffer);\n"
" list[index++] = new Uint8List.view(new Uint8List(256).buffer);\n"
" list[index++] = new Int16List.view(new Int16List(256).buffer);\n"
" list[index++] = new Uint16List.view(new Uint16List(256).buffer);\n"
" list[index++] = new Int32List.view(new Int32List(256).buffer);\n"
" list[index++] = new Uint32List.view(new Uint32List(256).buffer);\n"
" list[index++] = new Int64List.view(new Int64List(256).buffer);\n"
" list[index++] = new Uint64List.view(new Uint64List(256).buffer);\n"
" list[index++] = new Float32List.view(new Float32List(256).buffer);\n"
" list[index++] = new Float64List.view(new Float64List(256).buffer);\n"
" list[index++] = Int8List.view(Int8List(256).buffer);\n"
" list[index++] = Uint8List.view(Uint8List(256).buffer);\n"
" list[index++] = Int16List.view(new Int16List(256).buffer);\n"
" list[index++] = Uint16List.view(new Uint16List(256).buffer);\n"
" list[index++] = Int32List.view(new Int32List(256).buffer);\n"
" list[index++] = Uint32List.view(new Uint32List(256).buffer);\n"
" list[index++] = Int64List.view(new Int64List(256).buffer);\n"
" list[index++] = Uint64List.view(new Uint64List(256).buffer);\n"
" list[index++] = Float32List.view(new Float32List(256).buffer);\n"
" list[index++] = Float64List.view(new Float64List(256).buffer);\n"
" list[index++] = new Int8List.view(new Int16List(256).buffer);\n"
" list[index++] = new Uint8List.view(new Uint16List(256).buffer);\n"
" list[index++] = new Int8List.view(new Int32List(256).buffer);\n"
" list[index++] = new Uint8List.view(new Uint32List(256).buffer);\n"
" list[index++] = new Int8List.view(new Int64List(256).buffer);\n"
" list[index++] = new Uint8List.view(new Uint64List(256).buffer);\n"
" list[index++] = new Int8List.view(new Float32List(256).buffer);\n"
" list[index++] = new Uint8List.view(new Float32List(256).buffer);\n"
" list[index++] = new Int8List.view(new Float64List(256).buffer);\n"
" list[index++] = new Uint8List.view(new Float64List(256).buffer);\n"
" list[index++] = Int8List.view(new Int16List(256).buffer);\n"
" list[index++] = Uint8List.view(new Uint16List(256).buffer);\n"
" list[index++] = Int8List.view(new Int32List(256).buffer);\n"
" list[index++] = Uint8List.view(new Uint32List(256).buffer);\n"
" list[index++] = Int8List.view(new Int64List(256).buffer);\n"
" list[index++] = Uint8List.view(new Uint64List(256).buffer);\n"
" list[index++] = Int8List.view(new Float32List(256).buffer);\n"
" list[index++] = Uint8List.view(new Float32List(256).buffer);\n"
" list[index++] = Int8List.view(new Float64List(256).buffer);\n"
" list[index++] = Uint8List.view(new Float64List(256).buffer);\n"
" list[index++] = new Int16List.view(new Int8List(256).buffer);\n"
" list[index++] = new Uint16List.view(new Uint8List(256).buffer);\n"
" list[index++] = new Int16List.view(new Int32List(256).buffer);\n"
" list[index++] = new Uint16List.view(new Uint32List(256).buffer);\n"
" list[index++] = new Int16List.view(new Int64List(256).buffer);\n"
" list[index++] = new Uint16List.view(new Uint64List(256).buffer);\n"
" list[index++] = new Int16List.view(new Float32List(256).buffer);\n"
" list[index++] = new Uint16List.view(new Float32List(256).buffer);\n"
" list[index++] = new Int16List.view(new Float64List(256).buffer);\n"
" list[index++] = new Uint16List.view(new Float64List(256).buffer);\n"
" list[index++] = Int16List.view(new Int8List(256).buffer);\n"
" list[index++] = Uint16List.view(new Uint8List(256).buffer);\n"
" list[index++] = Int16List.view(new Int32List(256).buffer);\n"
" list[index++] = Uint16List.view(new Uint32List(256).buffer);\n"
" list[index++] = Int16List.view(new Int64List(256).buffer);\n"
" list[index++] = Uint16List.view(new Uint64List(256).buffer);\n"
" list[index++] = Int16List.view(new Float32List(256).buffer);\n"
" list[index++] = Uint16List.view(new Float32List(256).buffer);\n"
" list[index++] = Int16List.view(new Float64List(256).buffer);\n"
" list[index++] = Uint16List.view(new Float64List(256).buffer);\n"
" return list;\n"
"}\n"
"getMultipleTypedDataViewList() {\n"
" var list = new List(10);\n"
" var list = List<dynamic>.filled(10, null);\n"
" var index = 0;\n"
" var data = new Uint8List(256).buffer;\n"
" list[index++] = new Int8List.view(data);\n"
" list[index++] = new Uint8List.view(data);\n"
" list[index++] = new Int16List.view(data);\n"
" list[index++] = new Uint16List.view(data);\n"
" list[index++] = new Int32List.view(data);\n"
" list[index++] = new Uint32List.view(data);\n"
" list[index++] = new Int64List.view(data);\n"
" list[index++] = new Uint64List.view(data);\n"
" list[index++] = new Float32List.view(data);\n"
" list[index++] = new Float64List.view(data);\n"
" var data = Uint8List(256).buffer;\n"
" list[index++] = Int8List.view(data);\n"
" list[index++] = Uint8List.view(data);\n"
" list[index++] = Int16List.view(data);\n"
" list[index++] = Uint16List.view(data);\n"
" list[index++] = Int32List.view(data);\n"
" list[index++] = Uint32List.view(data);\n"
" list[index++] = Int64List.view(data);\n"
" list[index++] = Uint64List.view(data);\n"
" list[index++] = Float32List.view(data);\n"
" list[index++] = Float64List.view(data);\n"
" return list;\n"
"}\n";

View file

@ -159,86 +159,97 @@ static Dart_NativeFunction native_lookup(Dart_Handle name,
// Unit test case to verify stack frame iteration.
TEST_CASE(ValidateStackFrameIteration) {
const char* kScriptChars =
"class StackFrame {"
" static equals(var obj1, var obj2) native \"StackFrame_equals\";"
" static int frameCount() native \"StackFrame_frameCount\";"
" static int dartFrameCount() native \"StackFrame_dartFrameCount\";"
" static validateFrame(int index,"
" String name) native \"StackFrame_validateFrame\";"
"} "
"class First {"
" First() { }"
" int method1(int param) {"
" if (param == 1) {"
" param = method2(200);"
" } else {"
" param = method2(100);"
" }"
" }"
" int method2(int param) {"
" if (param == 200) {"
" First.staticmethod(this, param);"
" } else {"
" First.staticmethod(this, 10);"
" }"
" }"
" static int staticmethod(First obj, int param) {"
" if (param == 10) {"
" obj.method3(10);"
" } else {"
" obj.method3(200);"
" }"
" }"
" method3(int param) {"
" StackFrame.equals(9, StackFrame.frameCount());"
" StackFrame.equals(7, StackFrame.dartFrameCount());"
" StackFrame.validateFrame(0, \"StackFrame_validateFrame\");"
" StackFrame.validateFrame(1, \"First_method3\");"
" StackFrame.validateFrame(2, \"First_staticmethod\");"
" StackFrame.validateFrame(3, \"First_method2\");"
" StackFrame.validateFrame(4, \"First_method1\");"
" StackFrame.validateFrame(5, \"Second_method1\");"
" StackFrame.validateFrame(6, \"StackFrameTest_testMain\");"
" }"
"}"
"class Second {"
" Second() { }"
" int method1(int param) {"
" if (param == 1) {"
" param = method2(200);"
" } else {"
" First obj = new First();"
" param = obj.method1(1);"
" param = obj.method1(2);"
" }"
" }"
" int method2(int param) {"
" Second.staticmethod(this, param);"
" }"
" static int staticmethod(Second obj, int param) {"
" obj.method3(10);"
" }"
" method3(int param) {"
" StackFrame.equals(8, StackFrame.frameCount());"
" StackFrame.equals(6, StackFrame.dartFrameCount());"
" StackFrame.validateFrame(0, \"StackFrame_validateFrame\");"
" StackFrame.validateFrame(1, \"Second_method3\");"
" StackFrame.validateFrame(2, \"Second_staticmethod\");"
" StackFrame.validateFrame(3, \"Second_method2\");"
" StackFrame.validateFrame(4, \"Second_method1\");"
" StackFrame.validateFrame(5, \"StackFrameTest_testMain\");"
" }"
"}"
"class StackFrameTest {"
" static testMain() {"
" Second obj = new Second();"
" obj.method1(1);"
" obj.method1(2);"
" }"
"}";
bool nullSafety = (FLAG_null_safety == kNullSafetyOptionStrong);
const char* nullableTag = nullSafety ? "?" : "";
// clang-format off
auto kScriptChars = Utils::CStringUniquePtr(
OS::SCreate(
nullptr,
"class StackFrame {"
" static equals(var obj1, var obj2) native \"StackFrame_equals\";"
" static int frameCount() native \"StackFrame_frameCount\";"
" static int dartFrameCount() native \"StackFrame_dartFrameCount\";"
" static validateFrame(int index,"
" String name) native "
"\"StackFrame_validateFrame\";"
"} "
"class First {"
" First() { }"
" int%s method1(int%s param) {"
" if (param == 1) {"
" param = method2(200);"
" } else {"
" param = method2(100);"
" }"
" }"
" int%s method2(int param) {"
" if (param == 200) {"
" First.staticmethod(this, param);"
" } else {"
" First.staticmethod(this, 10);"
" }"
" }"
" static int%s staticmethod(First obj, int param) {"
" if (param == 10) {"
" obj.method3(10);"
" } else {"
" obj.method3(200);"
" }"
" }"
" method3(int param) {"
" StackFrame.equals(9, StackFrame.frameCount());"
" StackFrame.equals(7, StackFrame.dartFrameCount());"
" StackFrame.validateFrame(0, \"StackFrame_validateFrame\");"
" StackFrame.validateFrame(1, \"First_method3\");"
" StackFrame.validateFrame(2, \"First_staticmethod\");"
" StackFrame.validateFrame(3, \"First_method2\");"
" StackFrame.validateFrame(4, \"First_method1\");"
" StackFrame.validateFrame(5, \"Second_method1\");"
" StackFrame.validateFrame(6, \"StackFrameTest_testMain\");"
" }"
"}"
"class Second {"
" Second() { }"
" int%s method1(int%s param) {"
" if (param == 1) {"
" param = method2(200);"
" } else {"
" First obj = new First();"
" param = obj.method1(1);"
" param = obj.method1(2);"
" }"
" }"
" int%s method2(int param) {"
" Second.staticmethod(this, param);"
" }"
" static int%s staticmethod(Second obj, int param) {"
" obj.method3(10);"
" }"
" method3(int param) {"
" StackFrame.equals(8, StackFrame.frameCount());"
" StackFrame.equals(6, StackFrame.dartFrameCount());"
" StackFrame.validateFrame(0, \"StackFrame_validateFrame\");"
" StackFrame.validateFrame(1, \"Second_method3\");"
" StackFrame.validateFrame(2, \"Second_staticmethod\");"
" StackFrame.validateFrame(3, \"Second_method2\");"
" StackFrame.validateFrame(4, \"Second_method1\");"
" StackFrame.validateFrame(5, \"StackFrameTest_testMain\");"
" }"
"}"
"class StackFrameTest {"
" static testMain() {"
" Second obj = new Second();"
" obj.method1(1);"
" obj.method1(2);"
" }"
"}",
nullableTag, nullableTag, nullableTag, nullableTag, nullableTag,
nullableTag, nullableTag, nullableTag),
std::free);
// clang-format on
Dart_Handle lib = TestCase::LoadTestScript(
kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
kScriptChars.get(),
reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest"));
EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL));
}

View file

@ -99,6 +99,7 @@ part of dart.core;
* for String examples and recipes.
* * [Dart Up and Running](https://www.dartlang.org/docs/dart-up-and-running/ch03.html#strings-and-regular-expressions)
*/
@pragma('vm:entry-point')
abstract class String implements Comparable<String>, Pattern {
/**
* Allocates a new String for the specified [charCodes].

View file

@ -97,6 +97,7 @@ part of dart.core;
* for String examples and recipes.
* * [Dart Up and Running](https://www.dartlang.org/docs/dart-up-and-running/ch03.html#strings-and-regular-expressions)
*/
@pragma('vm:entry-point')
abstract class String implements Comparable<String>, Pattern {
/**
* Allocates a new String for the specified [charCodes].