mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
![Daco Harkes](/assets/img/avatar_default.png)
Changes Dart_NewWeakPersistentHandle to no longer auto delete the weak persistent handle. Changes the signatures of WeakPersistentHandleFinalizers to no longer have access to the handle. Flutter PR: https://github.com/flutter/engine/pull/19843 g3 presubmit: cl/318028238 Issue: https://github.com/dart-lang/sdk/issues/42312 TEST=runtime/vm/dart_api_impl_test.cc Change-Id: I3f77db9954d9486759f903b78c03a494f73c68ba Cq-Include-Trybots:dart/try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-msan-linux-release-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-mac-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-nnbd-linux-debug-x64-try,analyzer-nnbd-linux-release-try,front-end-nnbd-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151525 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
112 lines
3.5 KiB
C++
112 lines
3.5 KiB
C++
// Copyright (c) 2014, 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 "vm/isolate.h"
|
|
#include "vm/object.h"
|
|
#include "vm/regexp.h"
|
|
#include "vm/regexp_assembler_ir.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
static ArrayPtr Match(const String& pat, const String& str) {
|
|
Thread* thread = Thread::Current();
|
|
Zone* zone = thread->zone();
|
|
const RegExp& regexp =
|
|
RegExp::Handle(RegExpEngine::CreateRegExp(thread, pat, RegExpFlags()));
|
|
const Smi& idx = Object::smi_zero();
|
|
return IRRegExpMacroAssembler::Execute(regexp, str, idx, /*sticky=*/false,
|
|
zone);
|
|
}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(RegExp_OneByteString) {
|
|
uint8_t chars[] = {'a', 'b', 'c', 'b', 'a'};
|
|
intptr_t len = ARRAY_SIZE(chars);
|
|
const String& str =
|
|
String::Handle(OneByteString::New(chars, len, Heap::kNew));
|
|
|
|
const String& pat = String::Handle(String::New("bc"));
|
|
const Array& res = Array::Handle(Match(pat, str));
|
|
EXPECT_EQ(2, res.Length());
|
|
|
|
const Object& res_1 = Object::Handle(res.At(0));
|
|
const Object& res_2 = Object::Handle(res.At(1));
|
|
EXPECT(res_1.IsSmi());
|
|
EXPECT(res_2.IsSmi());
|
|
|
|
const Smi& smi_1 = Smi::Cast(res_1);
|
|
const Smi& smi_2 = Smi::Cast(res_2);
|
|
EXPECT_EQ(1, smi_1.Value());
|
|
EXPECT_EQ(3, smi_2.Value());
|
|
}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(RegExp_TwoByteString) {
|
|
uint16_t chars[] = {'a', 'b', 'c', 'b', 'a'};
|
|
intptr_t len = ARRAY_SIZE(chars);
|
|
const String& str =
|
|
String::Handle(TwoByteString::New(chars, len, Heap::kNew));
|
|
|
|
const String& pat = String::Handle(String::New("bc"));
|
|
const Array& res = Array::Handle(Match(pat, str));
|
|
EXPECT_EQ(2, res.Length());
|
|
|
|
const Object& res_1 = Object::Handle(res.At(0));
|
|
const Object& res_2 = Object::Handle(res.At(1));
|
|
EXPECT(res_1.IsSmi());
|
|
EXPECT(res_2.IsSmi());
|
|
|
|
const Smi& smi_1 = Smi::Cast(res_1);
|
|
const Smi& smi_2 = Smi::Cast(res_2);
|
|
EXPECT_EQ(1, smi_1.Value());
|
|
EXPECT_EQ(3, smi_2.Value());
|
|
}
|
|
|
|
static void NoopFinalizer(void* isolate_callback_data, void* peer) {}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(RegExp_ExternalOneByteString) {
|
|
uint8_t chars[] = {'a', 'b', 'c', 'b', 'a'};
|
|
intptr_t len = ARRAY_SIZE(chars);
|
|
const String& str = String::Handle(ExternalOneByteString::New(
|
|
chars, len, NULL, 0, NoopFinalizer, Heap::kNew));
|
|
|
|
const String& pat = String::Handle(String::New("bc"));
|
|
const Array& res = Array::Handle(Match(pat, str));
|
|
EXPECT_EQ(2, res.Length());
|
|
|
|
const Object& res_1 = Object::Handle(res.At(0));
|
|
const Object& res_2 = Object::Handle(res.At(1));
|
|
EXPECT(res_1.IsSmi());
|
|
EXPECT(res_2.IsSmi());
|
|
|
|
const Smi& smi_1 = Smi::Cast(res_1);
|
|
const Smi& smi_2 = Smi::Cast(res_2);
|
|
EXPECT_EQ(1, smi_1.Value());
|
|
EXPECT_EQ(3, smi_2.Value());
|
|
}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(RegExp_ExternalTwoByteString) {
|
|
uint16_t chars[] = {'a', 'b', 'c', 'b', 'a'};
|
|
intptr_t len = ARRAY_SIZE(chars);
|
|
const String& str = String::Handle(ExternalTwoByteString::New(
|
|
chars, len, NULL, 0, NoopFinalizer, Heap::kNew));
|
|
|
|
const String& pat = String::Handle(String::New("bc"));
|
|
const Array& res = Array::Handle(Match(pat, str));
|
|
EXPECT_EQ(2, res.Length());
|
|
|
|
const Object& res_1 = Object::Handle(res.At(0));
|
|
const Object& res_2 = Object::Handle(res.At(1));
|
|
EXPECT(res_1.IsSmi());
|
|
EXPECT(res_2.IsSmi());
|
|
|
|
const Smi& smi_1 = Smi::Cast(res_1);
|
|
const Smi& smi_2 = Smi::Cast(res_2);
|
|
EXPECT_EQ(1, smi_1.Value());
|
|
EXPECT_EQ(3, smi_2.Value());
|
|
}
|
|
|
|
} // namespace dart
|