- Represent strings internally in UTF-16 format, this makes it
compatible with webkit and will allow for easy externalization of strings. One byte strings are retained for pure ASCII strings. (The language specification was changed recently to reflect this as follows "A string is a sequence of UTF-16 code units"). - Remove four byte string class and all references to it. - Rename some of the string functions in Dart API to make them consistent and better describe the underlying functionality Dart_NewString => Dart_NewStringFromCString Dart_NewString8 => Dart_NewStringFromUTF8 Dart_NewString16 => Dart_NewStringFromUTF16 Dart_NewString32 => Dart_NewStringFromUTF32 Dart_NewExternalString8 => Dart_NewExternalUTF8String Dart_NewExternalString16 => Dart_NewExternalUTF16String Dart_NewExternalString32 => Dart_NewExternalUTF32String Dart_StringGet8 => Dart_StringToUTF8 Dart_StringGet16 => Dart_StringToUTF16 Dart_StringToCString => Dart_StringToCString Dart_IsString8 => Removed Dart_IsString16 -> Removed Dart_StringToBytes -> Removed Dart_StringGet32 -> Removed Review URL: https://codereview.chromium.org//11318018 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14357 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -26,7 +26,7 @@ Dart_Handle Builtin::Source(BuiltinLibraryId id) {
|
||||
ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
|
||||
kInvalidLibrary);
|
||||
ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
|
||||
return Dart_NewString(builtin_libraries_[id].source_);
|
||||
return DartUtils::NewString(builtin_libraries_[id].source_);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
|
||||
ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
|
||||
kInvalidLibrary);
|
||||
ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
|
||||
Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_);
|
||||
Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
|
||||
Dart_Handle library = Dart_LookupLibrary(url);
|
||||
if (Dart_IsError(library)) {
|
||||
library = Dart_LoadLibrary(url, Source(id));
|
||||
@@ -49,9 +49,10 @@ Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
|
||||
}
|
||||
if (builtin_libraries_[id].patch_url_ != NULL) {
|
||||
ASSERT(builtin_libraries_[id].patch_source_ != NULL);
|
||||
Dart_Handle patch_url = Dart_NewString(builtin_libraries_[id].patch_url_);
|
||||
Dart_Handle patch_url =
|
||||
DartUtils::NewString(builtin_libraries_[id].patch_url_);
|
||||
Dart_Handle patch_source =
|
||||
Dart_NewString(builtin_libraries_[id].patch_source_);
|
||||
DartUtils::NewString(builtin_libraries_[id].patch_source_);
|
||||
DART_CHECK_VALID(Dart_LoadPatch(library, patch_url, patch_source));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,11 @@ Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
|
||||
// test/debug functionality in standalone dart mode.
|
||||
|
||||
void Builtin::PrintString(FILE* out, Dart_Handle str) {
|
||||
const uint8_t* characters = NULL;
|
||||
intptr_t length;
|
||||
Dart_Handle result = Dart_StringToBytes(str, &characters, &length);
|
||||
intptr_t length = 0;
|
||||
Dart_Handle result = Dart_StringLength(str, &length);
|
||||
DART_CHECK_VALID(result);
|
||||
uint8_t* chars = reinterpret_cast<uint8_t*>(malloc(length * sizeof(uint8_t)));
|
||||
result = Dart_StringToUTF8(str, chars, &length);
|
||||
if (Dart_IsError(result)) {
|
||||
// TODO(turnidge): Consider propagating some errors here. What if
|
||||
// an isolate gets interrupted by the embedder in the middle of
|
||||
@@ -113,10 +115,11 @@ void Builtin::PrintString(FILE* out, Dart_Handle str) {
|
||||
// interrupt.
|
||||
fputs(Dart_GetError(result), out);
|
||||
} else {
|
||||
fwrite(characters, sizeof(*characters), length, out);
|
||||
fwrite(chars, sizeof(*chars), length, out);
|
||||
}
|
||||
fputc('\n', out);
|
||||
fflush(out);
|
||||
free(chars);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ void Builtin::SetNativeResolver(BuiltinLibraryId id) {
|
||||
kInvalidLibrary);
|
||||
ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
|
||||
if (builtin_libraries_[id].has_natives_) {
|
||||
Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_);
|
||||
Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
|
||||
Dart_Handle library = Dart_LookupLibrary(url);
|
||||
ASSERT(!Dart_IsError(library));
|
||||
// Setup the native resolver for built in library functions.
|
||||
@@ -46,7 +46,7 @@ Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
|
||||
ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
|
||||
kInvalidLibrary);
|
||||
ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
|
||||
Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_);
|
||||
Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
|
||||
Dart_Handle library = Dart_LookupLibrary(url);
|
||||
if (Dart_IsError(library)) {
|
||||
ASSERT(id > kUtfLibrary);
|
||||
|
||||
@@ -24,16 +24,16 @@ void FUNCTION_NAME(Common_IsBuiltinList)(Dart_NativeArguments args) {
|
||||
// look them up and cache them now.
|
||||
if (object_array_class == NULL) {
|
||||
Dart_Handle core_lib =
|
||||
Dart_LookupLibrary(Dart_NewString("dart:core"));
|
||||
Dart_LookupLibrary(Dart_NewStringFromCString("dart:core"));
|
||||
ASSERT(!Dart_IsError(core_lib));
|
||||
object_array_class =
|
||||
Dart_GetClass(core_lib, Dart_NewString("_ObjectArray"));
|
||||
Dart_GetClass(core_lib, Dart_NewStringFromCString("_ObjectArray"));
|
||||
ASSERT(!Dart_IsError(object_array_class));
|
||||
immutable_array_class =
|
||||
Dart_GetClass(core_lib, Dart_NewString("_ImmutableArray"));
|
||||
Dart_GetClass(core_lib, Dart_NewStringFromCString("_ImmutableArray"));
|
||||
ASSERT(!Dart_IsError(immutable_array_class));
|
||||
growable_object_array_class =
|
||||
Dart_GetClass(core_lib, Dart_NewString("_GrowableObjectArray"));
|
||||
growable_object_array_class = Dart_GetClass(
|
||||
core_lib, Dart_NewStringFromCString("_GrowableObjectArray"));
|
||||
ASSERT(!Dart_IsError(growable_object_array_class));
|
||||
// Update the cache.
|
||||
isolate_data->object_array_class =
|
||||
|
||||
@@ -13,7 +13,8 @@ void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
|
||||
Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
|
||||
int64_t count = 0;
|
||||
if (!DartUtils::GetInt64Value(count_obj, &count)) {
|
||||
Dart_Handle error = Dart_NewString("Invalid argument, must be an int.");
|
||||
Dart_Handle error =
|
||||
DartUtils::NewString("Invalid argument, must be an int.");
|
||||
Dart_ThrowException(error);
|
||||
}
|
||||
uint8_t* buffer = new uint8_t[count];
|
||||
@@ -25,7 +26,7 @@ void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
|
||||
Dart_Handle result = Dart_NewByteArray(count);
|
||||
if (Dart_IsError(result)) {
|
||||
delete[] buffer;
|
||||
Dart_Handle error = Dart_NewString("Failed to allocate storage.");
|
||||
Dart_Handle error = DartUtils::NewString("Failed to allocate storage.");
|
||||
Dart_ThrowException(error);
|
||||
}
|
||||
Dart_ListSetAsBytes(result, 0, buffer, count);
|
||||
@@ -33,4 +34,3 @@ void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
|
||||
delete[] buffer;
|
||||
Dart_ExitScope();
|
||||
}
|
||||
|
||||
|
||||
+35
-33
@@ -99,15 +99,15 @@ void DartUtils::SetIntegerField(Dart_Handle handle,
|
||||
const char* name,
|
||||
intptr_t val) {
|
||||
Dart_Handle result = Dart_SetField(handle,
|
||||
Dart_NewString(name),
|
||||
NewString(name),
|
||||
Dart_NewInteger(val));
|
||||
ASSERT(!Dart_IsError(result));
|
||||
}
|
||||
|
||||
|
||||
intptr_t DartUtils::GetIntegerField(Dart_Handle handle,
|
||||
const char* name) {
|
||||
Dart_Handle result = Dart_GetField(handle, Dart_NewString(name));
|
||||
const char* name) {
|
||||
Dart_Handle result = Dart_GetField(handle, NewString(name));
|
||||
ASSERT(!Dart_IsError(result));
|
||||
intptr_t value = DartUtils::GetIntegerValue(result);
|
||||
return value;
|
||||
@@ -117,9 +117,7 @@ intptr_t DartUtils::GetIntegerField(Dart_Handle handle,
|
||||
void DartUtils::SetStringField(Dart_Handle handle,
|
||||
const char* name,
|
||||
const char* val) {
|
||||
Dart_Handle result = Dart_SetField(handle,
|
||||
Dart_NewString(name),
|
||||
Dart_NewString(val));
|
||||
Dart_Handle result = Dart_SetField(handle, NewString(name), NewString(val));
|
||||
ASSERT(!Dart_IsError(result));
|
||||
}
|
||||
|
||||
@@ -174,7 +172,7 @@ Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping,
|
||||
if (Dart_IsError(library_url)) {
|
||||
return Dart_Error("accessing library url failed");
|
||||
}
|
||||
if (!Dart_IsString8(library_url)) {
|
||||
if (!Dart_IsString(library_url)) {
|
||||
return Dart_Error("library url is not a string");
|
||||
}
|
||||
const char* library_url_str = NULL;
|
||||
@@ -191,7 +189,7 @@ Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping,
|
||||
}
|
||||
// Calculate the canonical path.
|
||||
const char* canon_url_str = GetCanonicalPath(library_url_str, url_str);
|
||||
Dart_Handle canon_url = Dart_NewString(canon_url_str);
|
||||
Dart_Handle canon_url = NewString(canon_url_str);
|
||||
free(const_cast<char*>(canon_url_str));
|
||||
|
||||
return canon_url;
|
||||
@@ -210,18 +208,18 @@ Dart_Handle DartUtils::ReadStringFromFile(const char* filename) {
|
||||
return Dart_Error(error_msg);
|
||||
}
|
||||
intptr_t len = file->Length();
|
||||
char* text_buffer = reinterpret_cast<char*>(malloc(len + 1));
|
||||
uint8_t* text_buffer = reinterpret_cast<uint8_t*>(malloc(len));
|
||||
if (text_buffer == NULL) {
|
||||
delete file;
|
||||
return Dart_Error("Unable to allocate buffer");
|
||||
}
|
||||
if (!file->ReadFully(text_buffer, len)) {
|
||||
delete file;
|
||||
free(text_buffer);
|
||||
return Dart_Error("Unable to fully read contents");
|
||||
}
|
||||
text_buffer[len] = '\0';
|
||||
delete file;
|
||||
Dart_Handle str = Dart_NewString(text_buffer);
|
||||
Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len);
|
||||
free(text_buffer);
|
||||
return str;
|
||||
}
|
||||
@@ -231,11 +229,13 @@ static Dart_Handle ResolveScriptUri(Dart_Handle script_uri,
|
||||
Dart_Handle builtin_lib) {
|
||||
const int kNumArgs = 3;
|
||||
Dart_Handle dart_args[kNumArgs];
|
||||
dart_args[0] = Dart_NewString(DartUtils::original_working_directory);
|
||||
dart_args[0] = DartUtils::NewString(DartUtils::original_working_directory);
|
||||
dart_args[1] = script_uri;
|
||||
dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False());
|
||||
return Dart_Invoke(
|
||||
builtin_lib, Dart_NewString("_resolveScriptUri"), kNumArgs, dart_args);
|
||||
return Dart_Invoke(builtin_lib,
|
||||
DartUtils::NewString("_resolveScriptUri"),
|
||||
kNumArgs,
|
||||
dart_args);
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,10 @@ static Dart_Handle FilePathFromUri(Dart_Handle script_uri,
|
||||
dart_args[0] = script_uri;
|
||||
dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False());
|
||||
Dart_Handle script_path = Dart_Invoke(
|
||||
builtin_lib, Dart_NewString("_filePathFromUri"), kNumArgs, dart_args);
|
||||
builtin_lib,
|
||||
DartUtils::NewString("_filePathFromUri"),
|
||||
kNumArgs,
|
||||
dart_args);
|
||||
return script_path;
|
||||
}
|
||||
|
||||
@@ -257,7 +260,7 @@ Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag,
|
||||
if (!Dart_IsLibrary(library)) {
|
||||
return Dart_Error("not a library");
|
||||
}
|
||||
if (!Dart_IsString8(url)) {
|
||||
if (!Dart_IsString(url)) {
|
||||
return Dart_Error("url is not a string");
|
||||
}
|
||||
const char* url_string = NULL;
|
||||
@@ -285,7 +288,7 @@ Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag,
|
||||
dart_args[0] = library_url;
|
||||
dart_args[1] = url;
|
||||
return Dart_Invoke(
|
||||
builtin_lib, Dart_NewString("_resolveUri"), kNumArgs, dart_args);
|
||||
builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args);
|
||||
}
|
||||
if (is_dart_scheme_url) {
|
||||
ASSERT(tag == kImportTag);
|
||||
@@ -346,8 +349,7 @@ static Dart_Handle ReadSource(Dart_Handle script_uri,
|
||||
Dart_Handle DartUtils::LoadScript(const char* script_uri,
|
||||
Dart_Handle builtin_lib) {
|
||||
Dart_Handle resolved_script_uri;
|
||||
resolved_script_uri = ResolveScriptUri(Dart_NewString(script_uri),
|
||||
builtin_lib);
|
||||
resolved_script_uri = ResolveScriptUri(NewString(script_uri), builtin_lib);
|
||||
if (Dart_IsError(resolved_script_uri)) {
|
||||
return resolved_script_uri;
|
||||
}
|
||||
@@ -392,35 +394,35 @@ Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping,
|
||||
Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root,
|
||||
Dart_Handle builtin_lib) {
|
||||
// Setup the corelib 'print' function.
|
||||
Dart_Handle print =
|
||||
Dart_Invoke(builtin_lib, Dart_NewString("_getPrintClosure"), 0, 0);
|
||||
Dart_Handle corelib = Dart_LookupLibrary(Dart_NewString("dart:core"));
|
||||
Dart_Handle print = Dart_Invoke(
|
||||
builtin_lib, NewString("_getPrintClosure"), 0, 0);
|
||||
Dart_Handle corelib = Dart_LookupLibrary(NewString("dart:core"));
|
||||
Dart_Handle result = Dart_SetField(corelib,
|
||||
Dart_NewString("_printClosure"), print);
|
||||
NewString("_printClosure"),
|
||||
print);
|
||||
|
||||
// Setup the 'timer' factory.
|
||||
Dart_Handle url = Dart_NewString(kIsolateLibURL);
|
||||
Dart_Handle url = NewString(kIsolateLibURL);
|
||||
DART_CHECK_VALID(url);
|
||||
Dart_Handle isolate_lib = Dart_LookupLibrary(url);
|
||||
DART_CHECK_VALID(isolate_lib);
|
||||
Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
|
||||
Dart_Handle timer_closure =
|
||||
Dart_Invoke(io_lib, Dart_NewString("_getTimerFactoryClosure"), 0, NULL);
|
||||
Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL);
|
||||
Dart_Handle args[1];
|
||||
args[0] = timer_closure;
|
||||
DART_CHECK_VALID(Dart_Invoke(isolate_lib,
|
||||
Dart_NewString("_setTimerFactoryClosure"),
|
||||
1, args));
|
||||
DART_CHECK_VALID(Dart_Invoke(
|
||||
isolate_lib, NewString("_setTimerFactoryClosure"), 1, args));
|
||||
|
||||
// Set up package root if specified.
|
||||
if (package_root != NULL) {
|
||||
result = Dart_NewString(package_root);
|
||||
result = NewString(package_root);
|
||||
if (!Dart_IsError(result)) {
|
||||
const int kNumArgs = 1;
|
||||
Dart_Handle dart_args[kNumArgs];
|
||||
dart_args[0] = result;
|
||||
return Dart_Invoke(builtin_lib,
|
||||
Dart_NewString("_setPackageRoot"),
|
||||
NewString("_setPackageRoot"),
|
||||
kNumArgs,
|
||||
dart_args);
|
||||
}
|
||||
@@ -492,16 +494,16 @@ Dart_Handle DartUtils::NewDartOSError() {
|
||||
|
||||
Dart_Handle DartUtils::NewDartOSError(OSError* os_error) {
|
||||
// Create a Dart OSError object with the information retrieved from the OS.
|
||||
Dart_Handle url = Dart_NewString("dart:io");
|
||||
Dart_Handle url = NewString("dart:io");
|
||||
if (Dart_IsError(url)) return url;
|
||||
Dart_Handle lib = Dart_LookupLibrary(url);
|
||||
if (Dart_IsError(lib)) return lib;
|
||||
Dart_Handle class_name = Dart_NewString("OSError");
|
||||
Dart_Handle class_name = NewString("OSError");
|
||||
if (Dart_IsError(class_name)) return class_name;
|
||||
Dart_Handle clazz = Dart_GetClass(lib, class_name);
|
||||
if (Dart_IsError(clazz)) return clazz;
|
||||
Dart_Handle args[2];
|
||||
args[0] = Dart_NewString(os_error->message());
|
||||
args[0] = NewString(os_error->message());
|
||||
if (Dart_IsError(args[0])) return args[0];
|
||||
args[1] = Dart_NewInteger(os_error->code());
|
||||
if (Dart_IsError(args[1])) return args[1];
|
||||
|
||||
@@ -110,6 +110,13 @@ class DartUtils {
|
||||
// Create a new Dart OSError object with the provided OS error.
|
||||
static Dart_Handle NewDartOSError(OSError* os_error);
|
||||
|
||||
// Create a new Dart String object from a C String.
|
||||
static Dart_Handle NewString(const char* str) {
|
||||
ASSERT((str != NULL) && (strlen(str) != 0));
|
||||
return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str),
|
||||
strlen(str));
|
||||
}
|
||||
|
||||
static void SetOriginalWorkingDirectory();
|
||||
|
||||
// Global state that stores the original working directory..
|
||||
|
||||
@@ -109,11 +109,11 @@ static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) {
|
||||
intptr_t str_len = 0;
|
||||
Dart_Handle res = Dart_StringLength(str, &str_len);
|
||||
ASSERT_NOT_ERROR(res);
|
||||
uint32_t* codepoints =
|
||||
reinterpret_cast<uint32_t*>(malloc(str_len * sizeof(uint32_t)));
|
||||
uint16_t* codepoints =
|
||||
reinterpret_cast<uint16_t*>(malloc(str_len * sizeof(uint16_t)));
|
||||
ASSERT(codepoints != NULL);
|
||||
intptr_t actual_len = str_len;
|
||||
res = Dart_StringGet32(str, codepoints, &actual_len);
|
||||
res = Dart_StringToUTF16(str, codepoints, &actual_len);
|
||||
ASSERT_NOT_ERROR(res);
|
||||
ASSERT(str_len == actual_len);
|
||||
buf->AddChar('\"');
|
||||
@@ -692,7 +692,7 @@ bool DbgMessage::HandleGetSourceCmd(DbgMessage* in_msg) {
|
||||
intptr_t lib_id = msg_parser.GetIntParam("libraryId");
|
||||
char* url_chars = msg_parser.GetStringParam("url");
|
||||
ASSERT(url_chars != NULL);
|
||||
Dart_Handle url = Dart_NewString(url_chars);
|
||||
Dart_Handle url = DartUtils::NewString(url_chars);
|
||||
ASSERT_NOT_ERROR(url);
|
||||
free(url_chars);
|
||||
url_chars = NULL;
|
||||
@@ -732,7 +732,7 @@ bool DbgMessage::HandleSetBpCmd(DbgMessage* in_msg) {
|
||||
int msg_id = msg_parser.MessageId();
|
||||
char* url_chars = msg_parser.GetStringParam("url");
|
||||
ASSERT(url_chars != NULL);
|
||||
Dart_Handle url = Dart_NewString(url_chars);
|
||||
Dart_Handle url = DartUtils::NewString(url_chars);
|
||||
ASSERT_NOT_ERROR(url);
|
||||
free(url_chars);
|
||||
url_chars = NULL;
|
||||
|
||||
@@ -18,7 +18,7 @@ void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) {
|
||||
Dart_EnterScope();
|
||||
char* current = Directory::Current();
|
||||
if (current != NULL) {
|
||||
Dart_SetReturnValue(args, Dart_NewString(current));
|
||||
Dart_SetReturnValue(args, DartUtils::NewString(current));
|
||||
free(current);
|
||||
}
|
||||
Dart_ExitScope();
|
||||
@@ -64,7 +64,7 @@ void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) {
|
||||
Dart_Handle path = Dart_GetNativeArgument(args, 0);
|
||||
char* result = Directory::CreateTemp(DartUtils::GetStringValue(path));
|
||||
if (result != NULL) {
|
||||
Dart_SetReturnValue(args, Dart_NewString(result));
|
||||
Dart_SetReturnValue(args, DartUtils::NewString(result));
|
||||
free(result);
|
||||
} else {
|
||||
Dart_Handle err = DartUtils::NewDartOSError();
|
||||
|
||||
+2
-2
@@ -411,7 +411,7 @@ void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) {
|
||||
char* path = File::GetContainingDirectory(str_copy);
|
||||
free(str_copy);
|
||||
if (path != NULL) {
|
||||
Dart_SetReturnValue(args, Dart_NewString(path));
|
||||
Dart_SetReturnValue(args, DartUtils::NewString(path));
|
||||
free(path);
|
||||
} else {
|
||||
Dart_Handle err = DartUtils::NewDartOSError();
|
||||
@@ -428,7 +428,7 @@ void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) {
|
||||
DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
|
||||
char* path = File::GetCanonicalPath(str);
|
||||
if (path != NULL) {
|
||||
Dart_SetReturnValue(args, Dart_NewString(path));
|
||||
Dart_SetReturnValue(args, DartUtils::NewString(path));
|
||||
free(path);
|
||||
} else {
|
||||
Dart_Handle err = DartUtils::NewDartOSError();
|
||||
|
||||
@@ -153,7 +153,7 @@ static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
|
||||
if (!Dart_IsLibrary(library)) {
|
||||
return Dart_Error("not a library");
|
||||
}
|
||||
if (!Dart_IsString8(url)) {
|
||||
if (!Dart_IsString(url)) {
|
||||
return Dart_Error("url is not a string");
|
||||
}
|
||||
const char* url_string = NULL;
|
||||
@@ -183,7 +183,7 @@ static Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
|
||||
if (Dart_IsError(source)) {
|
||||
return source; // source contains the error string.
|
||||
}
|
||||
Dart_Handle url = Dart_NewString(script_name);
|
||||
Dart_Handle url = DartUtils::NewString(script_name);
|
||||
|
||||
return Dart_LoadScript(url, source);
|
||||
}
|
||||
|
||||
+17
-14
@@ -300,11 +300,11 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
const char* executable_name,
|
||||
const char* script_name) {
|
||||
int options_count = options->count();
|
||||
Dart_Handle dart_executable = Dart_NewString(executable_name);
|
||||
Dart_Handle dart_executable = DartUtils::NewString(executable_name);
|
||||
if (Dart_IsError(dart_executable)) {
|
||||
return dart_executable;
|
||||
}
|
||||
Dart_Handle dart_script = Dart_NewString(script_name);
|
||||
Dart_Handle dart_script = DartUtils::NewString(script_name);
|
||||
if (Dart_IsError(dart_script)) {
|
||||
return dart_script;
|
||||
}
|
||||
@@ -313,7 +313,8 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
return dart_arguments;
|
||||
}
|
||||
for (int i = 0; i < options_count; i++) {
|
||||
Dart_Handle argument_value = Dart_NewString(options->GetArgument(i));
|
||||
Dart_Handle argument_value =
|
||||
DartUtils::NewString(options->GetArgument(i));
|
||||
if (Dart_IsError(argument_value)) {
|
||||
return argument_value;
|
||||
}
|
||||
@@ -322,7 +323,7 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Dart_Handle core_lib_url = Dart_NewString("dart:core");
|
||||
Dart_Handle core_lib_url = DartUtils::NewString("dart:core");
|
||||
if (Dart_IsError(core_lib_url)) {
|
||||
return core_lib_url;
|
||||
}
|
||||
@@ -330,7 +331,8 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
if (Dart_IsError(core_lib)) {
|
||||
return core_lib;
|
||||
}
|
||||
Dart_Handle runtime_options_class_name = Dart_NewString("_OptionsImpl");
|
||||
Dart_Handle runtime_options_class_name =
|
||||
DartUtils::NewString("_OptionsImpl");
|
||||
if (Dart_IsError(runtime_options_class_name)) {
|
||||
return runtime_options_class_name;
|
||||
}
|
||||
@@ -339,7 +341,8 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
if (Dart_IsError(runtime_options_class)) {
|
||||
return runtime_options_class;
|
||||
}
|
||||
Dart_Handle executable_name_name = Dart_NewString("_nativeExecutable");
|
||||
Dart_Handle executable_name_name =
|
||||
DartUtils::NewString("_nativeExecutable");
|
||||
if (Dart_IsError(executable_name_name)) {
|
||||
return executable_name_name;
|
||||
}
|
||||
@@ -350,7 +353,7 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
if (Dart_IsError(set_executable_name)) {
|
||||
return set_executable_name;
|
||||
}
|
||||
Dart_Handle script_name_name = Dart_NewString("_nativeScript");
|
||||
Dart_Handle script_name_name = DartUtils::NewString("_nativeScript");
|
||||
if (Dart_IsError(script_name_name)) {
|
||||
return script_name_name;
|
||||
}
|
||||
@@ -359,7 +362,7 @@ static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
|
||||
if (Dart_IsError(set_script_name)) {
|
||||
return set_script_name;
|
||||
}
|
||||
Dart_Handle native_name = Dart_NewString("_nativeArguments");
|
||||
Dart_Handle native_name = DartUtils::NewString("_nativeArguments");
|
||||
if (Dart_IsError(native_name)) {
|
||||
return native_name;
|
||||
}
|
||||
@@ -554,7 +557,7 @@ static Dart_Handle SetBreakpoint(const char* breakpoint_at,
|
||||
char* colon = strchr(bpt_line, ':');
|
||||
ASSERT(colon != NULL);
|
||||
*colon = '\0';
|
||||
Dart_Handle url = Dart_NewString(bpt_line);
|
||||
Dart_Handle url = DartUtils::NewString(bpt_line);
|
||||
Dart_Handle line_number = Dart_NewInteger(atoi(colon + 1));
|
||||
free(bpt_line);
|
||||
Dart_Breakpoint bpt;
|
||||
@@ -565,12 +568,12 @@ static Dart_Handle SetBreakpoint(const char* breakpoint_at,
|
||||
Dart_Handle function_name;
|
||||
char* dot = strchr(bpt_function, '.');
|
||||
if (dot == NULL) {
|
||||
class_name = Dart_NewString("");
|
||||
function_name = Dart_NewString(breakpoint_at);
|
||||
class_name = DartUtils::NewString("");
|
||||
function_name = DartUtils::NewString(breakpoint_at);
|
||||
} else {
|
||||
*dot = '\0';
|
||||
class_name = Dart_NewString(bpt_function);
|
||||
function_name = Dart_NewString(dot + 1);
|
||||
class_name = DartUtils::NewString(bpt_function);
|
||||
function_name = DartUtils::NewString(dot + 1);
|
||||
}
|
||||
free(bpt_function);
|
||||
Dart_Breakpoint bpt;
|
||||
@@ -727,7 +730,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
// Lookup and invoke the top level main function.
|
||||
result = Dart_Invoke(library, Dart_NewString("main"), 0, NULL);
|
||||
result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
|
||||
if (Dart_IsError(result)) {
|
||||
return ErrorExit("%s\n", Dart_GetError(result));
|
||||
}
|
||||
|
||||
@@ -16,14 +16,15 @@ void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) {
|
||||
|
||||
void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) {
|
||||
Dart_EnterScope();
|
||||
Dart_SetReturnValue(args, Dart_NewString(Platform::OperatingSystem()));
|
||||
Dart_SetReturnValue(args,
|
||||
Dart_NewStringFromCString(Platform::OperatingSystem()));
|
||||
Dart_ExitScope();
|
||||
}
|
||||
|
||||
|
||||
void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) {
|
||||
Dart_EnterScope();
|
||||
Dart_SetReturnValue(args, Dart_NewString(File::PathSeparator()));
|
||||
Dart_SetReturnValue(args, Dart_NewStringFromCString(File::PathSeparator()));
|
||||
Dart_ExitScope();
|
||||
}
|
||||
|
||||
@@ -33,7 +34,7 @@ void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) {
|
||||
const intptr_t HOSTNAME_LENGTH = 256;
|
||||
char hostname[HOSTNAME_LENGTH];
|
||||
if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) {
|
||||
Dart_SetReturnValue(args, Dart_NewString(hostname));
|
||||
Dart_SetReturnValue(args, Dart_NewStringFromCString(hostname));
|
||||
} else {
|
||||
Dart_SetReturnValue(args, DartUtils::NewDartOSError());
|
||||
}
|
||||
@@ -56,7 +57,7 @@ void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
for (intptr_t i = 0; i < count; i++) {
|
||||
Dart_Handle str = Dart_NewString(env[i]);
|
||||
Dart_Handle str = Dart_NewStringFromCString(env[i]);
|
||||
if (Dart_IsError(str)) {
|
||||
Dart_PropagateError(str);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) {
|
||||
char host[INET_ADDRSTRLEN];
|
||||
if (Socket::GetRemotePeer(socket, host, &port)) {
|
||||
Dart_Handle list = Dart_NewList(2);
|
||||
Dart_ListSetAt(list, 0, Dart_NewString(host));
|
||||
Dart_ListSetAt(list, 0, Dart_NewStringFromCString(host));
|
||||
Dart_ListSetAt(list, 1, Dart_NewInteger(port));
|
||||
Dart_SetReturnValue(args, list);
|
||||
} else {
|
||||
|
||||
@@ -26,7 +26,7 @@ void IfNull(Dart_NativeArguments arguments) {
|
||||
}
|
||||
|
||||
Dart_NativeFunction ResolveName(Dart_Handle name, int argc) {
|
||||
assert(Dart_IsString8(name));
|
||||
assert(Dart_IsString(name));
|
||||
const char* cname;
|
||||
Dart_Handle check_error;
|
||||
|
||||
|
||||
+64
-115
@@ -1323,15 +1323,12 @@ DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double* value);
|
||||
*/
|
||||
DART_EXPORT bool Dart_IsString(Dart_Handle object);
|
||||
|
||||
/**
|
||||
* Is this object a String whose codepoints all fit into 8 bits?
|
||||
*/
|
||||
DART_EXPORT bool Dart_IsString8(Dart_Handle object);
|
||||
|
||||
/**
|
||||
* Is this object a String whose codepoints all fit into 16 bits?
|
||||
* Is this object an ASCII String?
|
||||
*/
|
||||
DART_EXPORT bool Dart_IsString16(Dart_Handle object);
|
||||
DART_EXPORT bool Dart_IsAsciiString(Dart_Handle object);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the length of a String.
|
||||
@@ -1345,51 +1342,54 @@ DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length);
|
||||
|
||||
/**
|
||||
* Returns a String built from the provided C string
|
||||
* (There is an implicit assumption that the C string passed in contains
|
||||
* UTF-8 encoded characters and '\0' is considered as a termination
|
||||
* character).
|
||||
*
|
||||
* \param value A C String
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewString(const char* str);
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str);
|
||||
// TODO(turnidge): Document what happens when we run out of memory
|
||||
// during this call.
|
||||
|
||||
/**
|
||||
* Returns a String built from an array of 8-bit codepoints.
|
||||
* Returns a String built from an array of UTF-8 encoded characters.
|
||||
*
|
||||
* \param value An array of 8-bit codepoints.
|
||||
* \param utf8_array An array of UTF-8 encoded characters.
|
||||
* \param length The length of the codepoints array.
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints,
|
||||
intptr_t length);
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array,
|
||||
intptr_t length);
|
||||
|
||||
/**
|
||||
* Returns a String built from an array of 16-bit codepoints.
|
||||
* Returns a String built from an array of UTF-16 encoded characters.
|
||||
*
|
||||
* \param value An array of 16-bit codepoints.
|
||||
* \param utf16_array An array of UTF-16 encoded characters.
|
||||
* \param length The length of the codepoints array.
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints,
|
||||
intptr_t length);
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array,
|
||||
intptr_t length);
|
||||
|
||||
/**
|
||||
* Returns a String built from an array of 32-bit codepoints.
|
||||
* Returns a String built from an array of UTF-32 encoded characters.
|
||||
*
|
||||
* \param value An array of 32-bit codepoints.
|
||||
* \param utf32_array An array of UTF-32 encoded characters.
|
||||
* \param length The length of the codepoints array.
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
|
||||
intptr_t length);
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const uint32_t* utf32_array,
|
||||
intptr_t length);
|
||||
|
||||
/**
|
||||
* Is this object an external String?
|
||||
@@ -1405,136 +1405,85 @@ DART_EXPORT bool Dart_IsExternalString(Dart_Handle object);
|
||||
DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
|
||||
void** peer);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a String which references an external array of 8-bit codepoints.
|
||||
* Returns a String which references an external array of UTF-8 encoded
|
||||
* characters.
|
||||
*
|
||||
* \param value An array of 8-bit codepoints. This array must not move.
|
||||
* \param length The length of the codepoints array.
|
||||
* \param utf8_array An array of UTF-8 encoded characters. This must not move.
|
||||
* \param length The length of the characters array.
|
||||
* \param peer An external pointer to associate with this string.
|
||||
* \param callback A callback to be called when this string is finalized.
|
||||
* \param cback A callback to be called when this string is finalized.
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback);
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalUTF8String(const uint8_t* utf8_array,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer cback);
|
||||
|
||||
/**
|
||||
* Returns a String which references an external array of 16-bit codepoints.
|
||||
* Returns a String which references an external array of UTF-16 encoded
|
||||
* characters.
|
||||
*
|
||||
* \param value An array of 16-bit codepoints. This array must not move.
|
||||
* \param length The length of the codepoints array.
|
||||
* \param utf16_array An array of UTF-16 encoded characters. This must not move.
|
||||
* \param length The length of the characters array.
|
||||
* \param peer An external pointer to associate with this string.
|
||||
* \param callback A callback to be called when this string is finalized.
|
||||
* \param cback A callback to be called when this string is finalized.
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback);
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer cback);
|
||||
|
||||
/**
|
||||
* Returns a String which references an external array of 32-bit codepoints.
|
||||
*
|
||||
* \param value An array of 32-bit codepoints. This array must not move.
|
||||
* \param length The length of the codepoints array.
|
||||
* \param peer An external pointer to associate with this string.
|
||||
* \param callback A callback to be called when this string is finalized.
|
||||
*
|
||||
* \return The String object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback);
|
||||
|
||||
/**
|
||||
* Gets the codepoints from a String.
|
||||
*
|
||||
* This function is only valid on strings for which Dart_IsString8 is
|
||||
* true. Otherwise an error occurs.
|
||||
* Gets the C string representation of a String.
|
||||
* (It is a sequence of UTF-8 encoded values with a '\0' termination.)
|
||||
*
|
||||
* \param str A string.
|
||||
* \param codepoints An array allocated by the caller, used to return
|
||||
* the array of codepoints.
|
||||
* \param length Used to pass in the length of the provided array.
|
||||
* Used to return the length of the array which was actually used.
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
|
||||
uint8_t* codepoints,
|
||||
intptr_t* length);
|
||||
// TODO(turnidge): Rename to GetString8 to be consistent with the Is*
|
||||
// and New* functions above?
|
||||
|
||||
/**
|
||||
* Gets the codepoints from a String.
|
||||
*
|
||||
* This function is only valid on strings for which Dart_IsString8 or
|
||||
* Dart_IsString16 is true. Otherwise an error occurs.
|
||||
*
|
||||
* \param str A string.
|
||||
* \param codepoints An array allocated by the caller, used to return
|
||||
* the array of codepoints.
|
||||
* \param length Used to pass in the length of the provided array.
|
||||
* Used to return the length of the array which was actually used.
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
|
||||
uint16_t* codepoints,
|
||||
intptr_t* length);
|
||||
|
||||
/**
|
||||
* Gets the codepoints from a String
|
||||
*
|
||||
* \param str A string.
|
||||
* \param codepoints An array allocated by the caller, used to return
|
||||
* the array of codepoints.
|
||||
* \param length Used to pass in the length of the provided array.
|
||||
* Used to return the length of the array which was actually used.
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
|
||||
uint32_t* codepoints,
|
||||
intptr_t* length);
|
||||
|
||||
/**
|
||||
* Gets the utf8 encoded representation of a String.
|
||||
*
|
||||
* \param str A string.
|
||||
* \param utf8 Returns the String represented as a utf8 encoded C
|
||||
* string. This C string is scope allocated and is only valid until
|
||||
* \param cstr Returns the String represented as a C string.
|
||||
* This C string is scope allocated and is only valid until
|
||||
* the next call to Dart_ExitScope.
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str,
|
||||
const char** utf8);
|
||||
const char** cstr);
|
||||
|
||||
/**
|
||||
* Gets a UTF-8 encoded representation of a String.
|
||||
*
|
||||
* \param str A string.
|
||||
* \param bytes Returns the String represented as an array of UTF-8
|
||||
* code units. This array is scope allocated and is only valid until
|
||||
* the next call to Dart_ExitScope.
|
||||
* \param length Returns the length of the code units array, in bytes.
|
||||
* \param utf8_array An array allocated by the caller, used to return
|
||||
* the array of UTF-8 encoded characters.
|
||||
* \param length Used to pass in the length of the provided array.
|
||||
* Used to return the length of the array which was actually used.
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle str,
|
||||
const uint8_t** bytes,
|
||||
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
|
||||
uint8_t* utf8_array,
|
||||
intptr_t* length);
|
||||
|
||||
/**
|
||||
* Gets the UTF-16 encoded representation of a string.
|
||||
*
|
||||
* \param str A string.
|
||||
* \param utf16_array An array allocated by the caller, used to return
|
||||
* the array of UTF-16 encoded characters.
|
||||
* \param length Used to pass in the length of the provided array.
|
||||
* Used to return the length of the array which was actually used.
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str,
|
||||
uint16_t* utf16_array,
|
||||
intptr_t* length);
|
||||
|
||||
|
||||
// --- Lists ---
|
||||
|
||||
/**
|
||||
|
||||
+34
-29
@@ -14,6 +14,11 @@
|
||||
|
||||
namespace dart {
|
||||
|
||||
inline Dart_Handle NewString(const char* str) {
|
||||
return Dart_NewStringFromCString(str);
|
||||
}
|
||||
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) {
|
||||
GET_NATIVE_ARGUMENT(Instance, port, arguments->At(0));
|
||||
|
||||
@@ -34,14 +39,14 @@ DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) {
|
||||
// TODO(turnidge): Add Map support to the dart embedding api instead
|
||||
// of implementing it here.
|
||||
static Dart_Handle CoreLib() {
|
||||
Dart_Handle core_lib_name = Dart_NewString("dart:core");
|
||||
Dart_Handle core_lib_name = NewString("dart:core");
|
||||
return Dart_LookupLibrary(core_lib_name);
|
||||
}
|
||||
|
||||
|
||||
static Dart_Handle MapNew() {
|
||||
// TODO(turnidge): Switch to an order-preserving map type.
|
||||
Dart_Handle cls = Dart_GetClass(CoreLib(), Dart_NewString("Map"));
|
||||
Dart_Handle cls = Dart_GetClass(CoreLib(), NewString("Map"));
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
}
|
||||
@@ -51,18 +56,18 @@ static Dart_Handle MapNew() {
|
||||
|
||||
static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) {
|
||||
Dart_Handle args[] = { key, value };
|
||||
return Dart_Invoke(map, Dart_NewString("[]="), ARRAY_SIZE(args), args);
|
||||
return Dart_Invoke(map, NewString("[]="), ARRAY_SIZE(args), args);
|
||||
}
|
||||
|
||||
|
||||
static Dart_Handle MirrorLib() {
|
||||
Dart_Handle mirror_lib_name = Dart_NewString("dart:mirrors");
|
||||
Dart_Handle mirror_lib_name = NewString("dart:mirrors");
|
||||
return Dart_LookupLibrary(mirror_lib_name);
|
||||
}
|
||||
|
||||
|
||||
static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) {
|
||||
Dart_Handle cls_name = Dart_NewString("Mirror");
|
||||
Dart_Handle cls_name = NewString("Mirror");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -92,7 +97,7 @@ static void FreeVMReference(Dart_Handle weak_ref, void* data) {
|
||||
|
||||
static Dart_Handle CreateVMReference(Dart_Handle handle) {
|
||||
// Create the VMReference object.
|
||||
Dart_Handle cls_name = Dart_NewString("VMReference");
|
||||
Dart_Handle cls_name = NewString("VMReference");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -148,7 +153,7 @@ static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) {
|
||||
|
||||
|
||||
static Dart_Handle UnwrapMirror(Dart_Handle mirror) {
|
||||
Dart_Handle field_name = Dart_NewString("_reference");
|
||||
Dart_Handle field_name = NewString("_reference");
|
||||
Dart_Handle vm_ref = Dart_GetField(mirror, field_name);
|
||||
if (Dart_IsError(vm_ref)) {
|
||||
return vm_ref;
|
||||
@@ -213,7 +218,7 @@ static Dart_Handle CreateParameterMirrorList(Dart_Handle func) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Dart_Handle param_cls_name = Dart_NewString("_LocalParameterMirrorImpl");
|
||||
Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl");
|
||||
Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name);
|
||||
if (Dart_IsError(param_cls)) {
|
||||
return param_cls;
|
||||
@@ -248,7 +253,7 @@ static Dart_Handle CreateLazyMirror(Dart_Handle target) {
|
||||
}
|
||||
|
||||
if (Dart_IsLibrary(target)) {
|
||||
Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror");
|
||||
Dart_Handle cls_name = NewString("_LazyLibraryMirror");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
Dart_Handle args[] = { Dart_LibraryName(target) };
|
||||
return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
|
||||
@@ -256,7 +261,7 @@ static Dart_Handle CreateLazyMirror(Dart_Handle target) {
|
||||
|
||||
if (Dart_IsClass(target) || Dart_IsInterface(target)) {
|
||||
if (Dart_ClassIsFunctionType(target)) {
|
||||
Dart_Handle cls_name = Dart_NewString("_LazyFunctionTypeMirror");
|
||||
Dart_Handle cls_name = NewString("_LazyFunctionTypeMirror");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
|
||||
Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target);
|
||||
@@ -271,7 +276,7 @@ static Dart_Handle CreateLazyMirror(Dart_Handle target) {
|
||||
};
|
||||
return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
|
||||
} else {
|
||||
Dart_Handle cls_name = Dart_NewString("_LazyTypeMirror");
|
||||
Dart_Handle cls_name = NewString("_LazyTypeMirror");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
Dart_Handle lib = Dart_ClassGetLibrary(target);
|
||||
Dart_Handle lib_name;
|
||||
@@ -290,7 +295,7 @@ static Dart_Handle CreateLazyMirror(Dart_Handle target) {
|
||||
Dart_Handle owner = Dart_TypeVariableOwner(target);
|
||||
Dart_Handle owner_mirror = CreateLazyMirror(owner);
|
||||
|
||||
Dart_Handle cls_name = Dart_NewString("_LazyTypeVariableMirror");
|
||||
Dart_Handle cls_name = NewString("_LazyTypeVariableMirror");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
|
||||
Dart_Handle args[] = { var_name, owner_mirror };
|
||||
@@ -336,7 +341,7 @@ static Dart_Handle CreateTypeVariableMirror(Dart_Handle type_var,
|
||||
Dart_Handle type_var_name,
|
||||
Dart_Handle owner_mirror) {
|
||||
ASSERT(Dart_IsTypeVariable(type_var));
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalTypeVariableMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalTypeVariableMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -400,7 +405,7 @@ static Dart_Handle CreateTypedefMirror(Dart_Handle cls,
|
||||
Dart_Handle cls_name,
|
||||
Dart_Handle owner,
|
||||
Dart_Handle owner_mirror) {
|
||||
Dart_Handle mirror_cls_name = Dart_NewString("_LocalTypedefMirrorImpl");
|
||||
Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl");
|
||||
Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name);
|
||||
if (Dart_IsError(mirror_cls)) {
|
||||
return mirror_cls;
|
||||
@@ -438,7 +443,7 @@ static Dart_Handle CreateClassMirror(Dart_Handle intf,
|
||||
return CreateTypedefMirror(intf, intf_name, lib, lib_mirror);
|
||||
}
|
||||
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalClassMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -447,7 +452,7 @@ static Dart_Handle CreateClassMirror(Dart_Handle intf,
|
||||
// TODO(turnidge): Why am I getting Null when I expect Object?
|
||||
Dart_Handle super_class = Dart_GetSuperclass(intf);
|
||||
if (Dart_IsNull(super_class)) {
|
||||
super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object"));
|
||||
super_class = Dart_GetClass(CoreLib(), NewString("Object"));
|
||||
}
|
||||
Dart_Handle default_class = Dart_ClassGetDefault(intf);
|
||||
|
||||
@@ -489,7 +494,7 @@ static Dart_Handle CreateMethodMirror(Dart_Handle func,
|
||||
Dart_Handle func_name,
|
||||
Dart_Handle owner_mirror) {
|
||||
ASSERT(Dart_IsFunction(func));
|
||||
Dart_Handle mirror_cls_name = Dart_NewString("_LocalMethodMirrorImpl");
|
||||
Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl");
|
||||
Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name);
|
||||
if (Dart_IsError(mirror_cls)) {
|
||||
return mirror_cls;
|
||||
@@ -562,7 +567,7 @@ static Dart_Handle CreateVariableMirror(Dart_Handle var,
|
||||
Dart_Handle var_name,
|
||||
Dart_Handle lib_mirror) {
|
||||
ASSERT(Dart_IsVariable(var));
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalVariableMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -795,7 +800,7 @@ static Dart_Handle CreateConstructorMap(Dart_Handle owner,
|
||||
|
||||
|
||||
static Dart_Handle CreateLibraryMirror(Dart_Handle lib) {
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -855,7 +860,7 @@ static Dart_Handle CreateLibrariesMap() {
|
||||
|
||||
|
||||
static Dart_Handle CreateIsolateMirror() {
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalIsolateMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalIsolateMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -869,7 +874,7 @@ static Dart_Handle CreateIsolateMirror() {
|
||||
|
||||
|
||||
static Dart_Handle CreateMirrorSystem() {
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalMirrorSystemImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalMirrorSystemImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -894,14 +899,14 @@ static Dart_Handle CreateMirrorSystem() {
|
||||
|
||||
|
||||
static Dart_Handle CreateNullMirror() {
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalInstanceMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
}
|
||||
|
||||
// TODO(turnidge): This is wrong. The Null class is distinct from object.
|
||||
Dart_Handle object_class = Dart_GetClass(CoreLib(), Dart_NewString("Object"));
|
||||
Dart_Handle object_class = Dart_GetClass(CoreLib(), NewString("Object"));
|
||||
|
||||
Dart_Handle args[] = {
|
||||
CreateVMReference(Dart_Null()),
|
||||
@@ -925,7 +930,7 @@ static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
|
||||
}
|
||||
|
||||
if (Dart_IsClosure(instance)) {
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalClosureMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalClosureMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -938,7 +943,7 @@ static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
|
||||
}
|
||||
|
||||
// TODO(turnidge): Why not use the real function name here?
|
||||
Dart_Handle func_name = Dart_NewString("call");
|
||||
Dart_Handle func_name = NewString("call");
|
||||
Dart_Handle func_owner = Dart_FunctionOwner(func);
|
||||
if (Dart_IsError(func_owner)) {
|
||||
return func_owner;
|
||||
@@ -960,7 +965,7 @@ static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
|
||||
return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
|
||||
|
||||
} else {
|
||||
Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl");
|
||||
Dart_Handle cls_name = NewString("_LocalInstanceMirrorImpl");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
if (Dart_IsError(cls)) {
|
||||
return cls;
|
||||
@@ -995,7 +1000,7 @@ static Dart_Handle CreateMirroredError(Dart_Handle error) {
|
||||
if (Dart_IsError(stack)) {
|
||||
return stack;
|
||||
}
|
||||
Dart_Handle cls_name = Dart_NewString("MirroredUncaughtExceptionError");
|
||||
Dart_Handle cls_name = NewString("MirroredUncaughtExceptionError");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
Dart_Handle args[] = {
|
||||
CreateInstanceMirror(exc),
|
||||
@@ -1007,9 +1012,9 @@ static Dart_Handle CreateMirroredError(Dart_Handle error) {
|
||||
return Dart_NewUnhandledExceptionError(mirrored_exc);
|
||||
} else if (Dart_IsApiError(error) ||
|
||||
Dart_IsCompilationError(error)) {
|
||||
Dart_Handle cls_name = Dart_NewString("MirroredCompilationError");
|
||||
Dart_Handle cls_name = NewString("MirroredCompilationError");
|
||||
Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
|
||||
Dart_Handle args[] = { Dart_NewString(Dart_GetError(error)) };
|
||||
Dart_Handle args[] = { NewString(Dart_GetError(error)) };
|
||||
Dart_Handle mirrored_exc =
|
||||
Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
|
||||
return Dart_NewUnhandledExceptionError(mirrored_exc);
|
||||
|
||||
+14
-15
@@ -15,14 +15,14 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
|
||||
GET_NATIVE_ARGUMENT(Array, a, arguments->At(0));
|
||||
// TODO(srdjan): Check that parameterized type is an int.
|
||||
Zone* zone = isolate->current_zone();
|
||||
intptr_t len = a.Length();
|
||||
intptr_t array_len = a.Length();
|
||||
|
||||
// Unbox the array and determine the maximum element width.
|
||||
bool is_one_byte_string = true;
|
||||
bool is_two_byte_string = true;
|
||||
uint32_t* temp = zone->Alloc<uint32_t>(len);
|
||||
intptr_t utf16_len = array_len;
|
||||
uint32_t* utf32_array = zone->Alloc<uint32_t>(array_len);
|
||||
Object& index_object = Object::Handle(isolate);
|
||||
for (intptr_t i = 0; i < len; i++) {
|
||||
for (intptr_t i = 0; i < array_len; i++) {
|
||||
index_object = a.At(i);
|
||||
if (!index_object.IsSmi()) {
|
||||
GrowableArray<const Object*> args;
|
||||
@@ -33,21 +33,20 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
|
||||
if (value < 0) {
|
||||
GrowableArray<const Object*> args;
|
||||
Exceptions::ThrowByType(Exceptions::kArgument, args);
|
||||
} else if (value > 0xFFFF) {
|
||||
is_one_byte_string = false;
|
||||
is_two_byte_string = false;
|
||||
} else if (value > 0xFF) {
|
||||
is_one_byte_string = false;
|
||||
} else {
|
||||
if (value > 0x7F) {
|
||||
is_one_byte_string = false;
|
||||
}
|
||||
if (value > 0xFFFF) {
|
||||
utf16_len += 1;
|
||||
}
|
||||
}
|
||||
temp[i] = value;
|
||||
utf32_array[i] = value;
|
||||
}
|
||||
if (is_one_byte_string) {
|
||||
return OneByteString::New(temp, len, Heap::kNew);
|
||||
} else if (is_two_byte_string) {
|
||||
return TwoByteString::New(temp, len, Heap::kNew);
|
||||
} else {
|
||||
return FourByteString::New(temp, len, Heap::kNew);
|
||||
return OneByteString::New(utf32_array, array_len, Heap::kNew);
|
||||
}
|
||||
return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -173,26 +173,18 @@ BENCHMARK(UseDartApi) {
|
||||
|
||||
// Create a native wrapper class with native fields.
|
||||
Dart_Handle result = Dart_CreateNativeWrapperClass(
|
||||
lib,
|
||||
Dart_NewString("NativeFieldsWrapper"),
|
||||
1);
|
||||
lib, NewString("NativeFieldsWrapper"), 1);
|
||||
EXPECT_VALID(result);
|
||||
|
||||
Dart_Handle args[1];
|
||||
args[0] = Dart_NewInteger(kNumIterations);
|
||||
|
||||
// Warmup first to avoid compilation jitters.
|
||||
Dart_Invoke(lib,
|
||||
Dart_NewString("benchmark"),
|
||||
1,
|
||||
args);
|
||||
Dart_Invoke(lib, NewString("benchmark"), 1, args);
|
||||
|
||||
Timer timer(true, "UseDartApi benchmark");
|
||||
timer.Start();
|
||||
Dart_Invoke(lib,
|
||||
Dart_NewString("benchmark"),
|
||||
1,
|
||||
args);
|
||||
Dart_Invoke(lib, NewString("benchmark"), 1, args);
|
||||
timer.Stop();
|
||||
int64_t elapsed_time = timer.TotalElapsedTime();
|
||||
benchmark->set_score(elapsed_time);
|
||||
@@ -211,17 +203,15 @@ BENCHMARK(DartStringAccess) {
|
||||
// Create strings.
|
||||
uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
|
||||
int external_peer_data = 123;
|
||||
Dart_Handle external_string = Dart_NewExternalString8(data8,
|
||||
ARRAY_SIZE(data8),
|
||||
&external_peer_data,
|
||||
NULL);
|
||||
Dart_Handle internal_string = Dart_NewString("two");
|
||||
Dart_Handle external_string = Dart_NewExternalUTF8String(data8,
|
||||
ARRAY_SIZE(data8),
|
||||
&external_peer_data,
|
||||
NULL);
|
||||
Dart_Handle internal_string = NewString("two");
|
||||
|
||||
// Run benchmark.
|
||||
for (int64_t i = 0; i < kNumIterations; i++) {
|
||||
EXPECT(Dart_IsString(internal_string));
|
||||
EXPECT(Dart_IsString8(internal_string));
|
||||
EXPECT(Dart_IsString16(internal_string));
|
||||
EXPECT(!Dart_IsExternalString(internal_string));
|
||||
EXPECT_VALID(external_string);
|
||||
EXPECT(Dart_IsExternalString(external_string));
|
||||
@@ -387,8 +377,8 @@ BENCHMARK(FrameLookup) {
|
||||
Dart_Handle lib = TestCase::LoadTestScript(
|
||||
kScriptChars,
|
||||
reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver));
|
||||
Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest"));
|
||||
Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
|
||||
Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest"));
|
||||
Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
int64_t elapsed_time = 0;
|
||||
result = Dart_IntegerToInt64(result, &elapsed_time);
|
||||
|
||||
@@ -35,6 +35,11 @@ DECLARE_FLAG(int, heap_growth_space_ratio);
|
||||
static void Dart_BenchmarkHelper##name(Benchmark* benchmark)
|
||||
|
||||
|
||||
inline Dart_Handle NewString(const char* str) {
|
||||
return Dart_NewStringFromCString(str);
|
||||
}
|
||||
|
||||
|
||||
class Benchmark {
|
||||
public:
|
||||
typedef void (RunEntry)(Benchmark* benchmark);
|
||||
|
||||
@@ -127,14 +127,10 @@ void ClassFinalizer::VerifyBootstrapClasses() {
|
||||
ASSERT(OneByteString::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->two_byte_string_class();
|
||||
ASSERT(TwoByteString::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->four_byte_string_class();
|
||||
ASSERT(FourByteString::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->external_one_byte_string_class();
|
||||
ASSERT(ExternalOneByteString::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->external_two_byte_string_class();
|
||||
ASSERT(ExternalTwoByteString::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->external_four_byte_string_class();
|
||||
ASSERT(ExternalFourByteString::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->double_class();
|
||||
ASSERT(Double::InstanceSize() == cls.instance_size());
|
||||
cls = object_store->bool_class();
|
||||
@@ -269,10 +265,8 @@ void ClassFinalizer::ResolveSuperType(const Class& cls) {
|
||||
case kDoubleCid:
|
||||
case kOneByteStringCid:
|
||||
case kTwoByteStringCid:
|
||||
case kFourByteStringCid:
|
||||
case kExternalOneByteStringCid:
|
||||
case kExternalTwoByteStringCid:
|
||||
case kExternalFourByteStringCid:
|
||||
case kBoolCid:
|
||||
case kArrayCid:
|
||||
case kImmutableArrayCid:
|
||||
|
||||
@@ -179,10 +179,10 @@ void StartEvent::Process() {
|
||||
|
||||
Dart_Handle recv_port = Dart_GetReceivePort(Dart_GetMainPortId());
|
||||
EXPECT_VALID(recv_port);
|
||||
result = Dart_SetField(lib, Dart_NewString("mainPort"), recv_port);
|
||||
result = Dart_SetField(lib, NewString("mainPort"), recv_port);
|
||||
EXPECT_VALID(result);
|
||||
|
||||
result = Dart_Invoke(lib, Dart_NewString(main_), 0, NULL);
|
||||
result = Dart_Invoke(lib, NewString(main_), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
free(const_cast<char*>(main_));
|
||||
main_ = NULL;
|
||||
@@ -317,7 +317,7 @@ UNIT_TEST_CASE(CustomIsolates) {
|
||||
EXPECT_VALID(lib);
|
||||
|
||||
// Run main.
|
||||
result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
|
||||
result = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
EXPECT(Dart_IsString(result));
|
||||
const char* result_str = NULL;
|
||||
|
||||
+67
-143
@@ -273,13 +273,6 @@ bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) {
|
||||
*peer = data->peer();
|
||||
return true;
|
||||
}
|
||||
case kExternalFourByteStringCid: {
|
||||
RawExternalFourByteString* raw_string =
|
||||
reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
|
||||
ExternalStringData<uint32_t>* data = raw_string->external_data_;
|
||||
*peer = data->peer();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1522,16 +1515,11 @@ DART_EXPORT bool Dart_IsString(Dart_Handle object) {
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
|
||||
DART_EXPORT bool Dart_IsAsciiString(Dart_Handle object) {
|
||||
return RawObject::IsOneByteStringClassId(Api::ClassId(object));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
|
||||
return RawObject::IsTwoByteStringClassId(Api::ClassId(object));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
@@ -1544,53 +1532,53 @@ DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewString(const char* str) {
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (str == NULL) {
|
||||
RETURN_NULL_ERROR(str);
|
||||
}
|
||||
if (!Utf8::IsValid(str)) {
|
||||
return Api::NewError("%s expects argument 'str' to be valid UTF-8.",
|
||||
CURRENT_FUNC);
|
||||
}
|
||||
return Api::NewHandle(isolate, String::New(str));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints,
|
||||
intptr_t length) {
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array,
|
||||
intptr_t length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (codepoints == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(codepoints);
|
||||
if (utf8_array == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(utf8_array);
|
||||
}
|
||||
CHECK_LENGTH(length, String::kMaxElements);
|
||||
return Api::NewHandle(isolate, String::New(codepoints, length));
|
||||
if (!Utf8::IsValid(utf8_array, length)) {
|
||||
return Api::NewError("%s expects argument 'str' to be valid UTF-8.",
|
||||
CURRENT_FUNC);
|
||||
}
|
||||
return Api::NewHandle(isolate, String::New(utf8_array, length));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints,
|
||||
intptr_t length) {
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array,
|
||||
intptr_t length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (codepoints == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(codepoints);
|
||||
if (utf16_array == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(utf16_array);
|
||||
}
|
||||
CHECK_LENGTH(length, String::kMaxElements);
|
||||
return Api::NewHandle(isolate, String::New(codepoints, length));
|
||||
return Api::NewHandle(isolate, String::New(utf16_array, length));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
|
||||
intptr_t length) {
|
||||
DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const uint32_t* utf32_array,
|
||||
intptr_t length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (codepoints == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(codepoints);
|
||||
if (utf32_array == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(utf32_array);
|
||||
}
|
||||
CHECK_LENGTH(length, String::kMaxElements);
|
||||
return Api::NewHandle(isolate, String::New(codepoints, length));
|
||||
return Api::NewHandle(isolate, String::New(utf32_array, length));
|
||||
}
|
||||
|
||||
|
||||
@@ -1623,113 +1611,38 @@ DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback) {
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalUTF8String(const uint8_t* utf8_array,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer cback) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (codepoints == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(codepoints);
|
||||
if (utf8_array == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(utf8_array);
|
||||
}
|
||||
CHECK_LENGTH(length, String::kMaxElements);
|
||||
return Api::NewHandle(
|
||||
isolate, String::NewExternal(codepoints, length, peer, callback));
|
||||
return Api::NewHandle(isolate,
|
||||
String::NewExternal(utf8_array, length, peer, cback));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback) {
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer cback) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (codepoints == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(codepoints);
|
||||
if (utf16_array == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(utf16_array);
|
||||
}
|
||||
CHECK_LENGTH(length, String::kMaxElements);
|
||||
return Api::NewHandle(
|
||||
isolate, String::NewExternal(codepoints, length, peer, callback));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints,
|
||||
intptr_t length,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
if (codepoints == NULL && length != 0) {
|
||||
RETURN_NULL_ERROR(codepoints);
|
||||
}
|
||||
CHECK_LENGTH(length, String::kMaxElements);
|
||||
return Api::NewHandle(
|
||||
isolate, String::NewExternal(codepoints, length, peer, callback));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
|
||||
uint8_t* codepoints,
|
||||
intptr_t* length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const OneByteString& str_obj = Api::UnwrapOneByteStringHandle(isolate, str);
|
||||
if (str_obj.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, str, String8);
|
||||
}
|
||||
intptr_t str_len = str_obj.Length();
|
||||
intptr_t copy_len = (str_len > *length) ? *length : str_len;
|
||||
for (intptr_t i = 0; i < copy_len; i++) {
|
||||
codepoints[i] = static_cast<uint8_t>(str_obj.CharAt(i));
|
||||
}
|
||||
*length= copy_len;
|
||||
return Api::Success(isolate);
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
|
||||
uint16_t* codepoints,
|
||||
intptr_t* length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const String& str_obj = Api::UnwrapStringHandle(isolate, str);
|
||||
if (str_obj.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, str, String);
|
||||
}
|
||||
if (str_obj.CharSize() > String::kTwoByteChar) {
|
||||
return Api::NewError("Object is not a String16 or String8");
|
||||
}
|
||||
intptr_t str_len = str_obj.Length();
|
||||
intptr_t copy_len = (str_len > *length) ? *length : str_len;
|
||||
for (intptr_t i = 0; i < copy_len; i++) {
|
||||
codepoints[i] = static_cast<uint16_t>(str_obj.CharAt(i));
|
||||
}
|
||||
*length = copy_len;
|
||||
return Api::Success(isolate);
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
|
||||
uint32_t* codepoints,
|
||||
intptr_t* length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const String& str_obj = Api::UnwrapStringHandle(isolate, str);
|
||||
if (str_obj.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, str, String);
|
||||
}
|
||||
intptr_t str_len = str_obj.Length();
|
||||
intptr_t copy_len = (str_len > *length) ? *length : str_len;
|
||||
for (intptr_t i = 0; i < copy_len; i++) {
|
||||
codepoints[i] = static_cast<uint32_t>(str_obj.CharAt(i));
|
||||
}
|
||||
*length = copy_len;
|
||||
return Api::Success(isolate);
|
||||
return Api::NewHandle(isolate,
|
||||
String::NewExternal(utf16_array, length, peer, cback));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
|
||||
const char** result) {
|
||||
const char** cstr) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const String& str_obj = Api::UnwrapStringHandle(isolate, object);
|
||||
@@ -1744,34 +1657,45 @@ DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
|
||||
const char* string_value = str_obj.ToCString();
|
||||
memmove(res, string_value, string_length + 1);
|
||||
ASSERT(res[string_length] == '\0');
|
||||
*result = res;
|
||||
*cstr = res;
|
||||
return Api::Success(isolate);
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object,
|
||||
const uint8_t** bytes,
|
||||
intptr_t *length) {
|
||||
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
|
||||
uint8_t* utf8_array,
|
||||
intptr_t* length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const String& str = Api::UnwrapStringHandle(isolate, object);
|
||||
if (str.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, object, String);
|
||||
const String& str_obj = Api::UnwrapStringHandle(isolate, str);
|
||||
if (str_obj.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, str, String);
|
||||
}
|
||||
if (bytes == NULL) {
|
||||
RETURN_NULL_ERROR(bytes);
|
||||
intptr_t str_len = str_obj.Length();
|
||||
if (str_len > *length) {
|
||||
return Api::NewError("Input array is not large enough to hold the result");
|
||||
}
|
||||
if (length == NULL) {
|
||||
RETURN_NULL_ERROR(length);
|
||||
str_obj.ToUTF8(utf8_array, str_len);
|
||||
*length= str_len;
|
||||
return Api::Success(isolate);
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str,
|
||||
uint16_t* utf16_array,
|
||||
intptr_t* length) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
const String& str_obj = Api::UnwrapStringHandle(isolate, str);
|
||||
if (str_obj.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, str, String);
|
||||
}
|
||||
const char* cstring = str.ToCString();
|
||||
*length = Utf8::Length(str);
|
||||
uint8_t* result = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(*length);
|
||||
if (result == NULL) {
|
||||
return Api::NewError("Unable to allocate memory");
|
||||
intptr_t str_len = str_obj.Length();
|
||||
intptr_t copy_len = (str_len > *length) ? *length : str_len;
|
||||
for (intptr_t i = 0; i < copy_len; i++) {
|
||||
utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i));
|
||||
}
|
||||
memmove(result, cstring, *length);
|
||||
*bytes = result;
|
||||
*length = copy_len;
|
||||
return Api::Success(isolate);
|
||||
}
|
||||
|
||||
|
||||
+398
-428
File diff suppressed because it is too large
Load Diff
@@ -358,9 +358,6 @@ Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id,
|
||||
case kTwoByteStringCid:
|
||||
// Two byte strings not supported.
|
||||
return AllocateDartCObjectUnsupported();
|
||||
case kFourByteStringCid:
|
||||
// Four byte strings not supported.
|
||||
return AllocateDartCObjectUnsupported();
|
||||
case kUint8ArrayCid: {
|
||||
intptr_t len = ReadSmiValue();
|
||||
Dart_CObject* object = AllocateDartCObjectUint8Array(len);
|
||||
|
||||
@@ -31,8 +31,8 @@ static void SetBreakpointAtEntry(const char* cname, const char* fname) {
|
||||
ASSERT(Dart_IsLibrary(script_lib));
|
||||
Dart_Breakpoint bpt;
|
||||
Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib,
|
||||
Dart_NewString(cname),
|
||||
Dart_NewString(fname),
|
||||
NewString(cname),
|
||||
NewString(fname),
|
||||
&bpt);
|
||||
EXPECT_VALID(res);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ static Dart_Handle Invoke(const char* func_name) {
|
||||
ASSERT(script_lib != NULL);
|
||||
ASSERT(!Dart_IsError(script_lib));
|
||||
ASSERT(Dart_IsLibrary(script_lib));
|
||||
return Dart_Invoke(script_lib, Dart_NewString(func_name), 0, NULL);
|
||||
return Dart_Invoke(script_lib, NewString(func_name), 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -632,9 +632,9 @@ static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id,
|
||||
Dart_StackTrace trace) {
|
||||
static const char* expected_trace[] = {"add", "main"};
|
||||
Dart_Handle add_locals = Dart_NewList(4);
|
||||
Dart_ListSetAt(add_locals, 0, Dart_NewString("a"));
|
||||
Dart_ListSetAt(add_locals, 0, NewString("a"));
|
||||
Dart_ListSetAt(add_locals, 1, Dart_NewInteger(10));
|
||||
Dart_ListSetAt(add_locals, 2, Dart_NewString("b"));
|
||||
Dart_ListSetAt(add_locals, 2, NewString("b"));
|
||||
Dart_ListSetAt(add_locals, 3, Dart_NewInteger(20));
|
||||
Dart_Handle expected_locals[] = {add_locals, Dart_Null()};
|
||||
breakpoint_hit_counter++;
|
||||
@@ -657,7 +657,7 @@ TEST_CASE(Debug_ExprClosureBreakpoint) {
|
||||
LoadScript(kScriptChars);
|
||||
Dart_SetBreakpointHandler(&ExprClosureBreakpointHandler);
|
||||
|
||||
Dart_Handle script_url = Dart_NewString(TestCase::url());
|
||||
Dart_Handle script_url = NewString(TestCase::url());
|
||||
intptr_t line_no = 5; // In closure 'add'.
|
||||
Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
|
||||
EXPECT_VALID(res);
|
||||
@@ -723,7 +723,7 @@ TEST_CASE(Debug_DeleteBreakpoint) {
|
||||
|
||||
LoadScript(kScriptChars);
|
||||
|
||||
Dart_Handle script_url = Dart_NewString(TestCase::url());
|
||||
Dart_Handle script_url = NewString(TestCase::url());
|
||||
intptr_t line_no = 4; // In function 'foo'.
|
||||
|
||||
Dart_SetBreakpointHandler(&DeleteBreakpointHandler);
|
||||
@@ -751,7 +751,7 @@ static void InspectStaticFieldHandler(Dart_IsolateId isolate_id,
|
||||
ASSERT(script_lib != NULL);
|
||||
ASSERT(!Dart_IsError(script_lib));
|
||||
ASSERT(Dart_IsLibrary(script_lib));
|
||||
Dart_Handle class_A = Dart_GetClass(script_lib, Dart_NewString("A"));
|
||||
Dart_Handle class_A = Dart_GetClass(script_lib, NewString("A"));
|
||||
EXPECT_VALID(class_A);
|
||||
|
||||
const int expected_num_fields = 2;
|
||||
@@ -1015,7 +1015,7 @@ TEST_CASE(Debug_LookupSourceLine) {
|
||||
}
|
||||
}
|
||||
|
||||
Dart_Handle lib_url = Dart_NewString(TestCase::url());
|
||||
Dart_Handle lib_url = NewString(TestCase::url());
|
||||
Dart_Handle source = Dart_GetScriptSource(lib_url, lib_url);
|
||||
EXPECT(Dart_IsString(source));
|
||||
char const* source_chars;
|
||||
@@ -1040,8 +1040,8 @@ TEST_CASE(GetLibraryURLs) {
|
||||
EXPECT_NOTSUBSTRING(TestCase::url(), list_cstr);
|
||||
|
||||
// Load a script.
|
||||
Dart_Handle url = Dart_NewString(TestCase::url());
|
||||
Dart_Handle source = Dart_NewString(kScriptChars);
|
||||
Dart_Handle url = NewString(TestCase::url());
|
||||
Dart_Handle source = NewString(kScriptChars);
|
||||
EXPECT_VALID(Dart_LoadScript(url, source));
|
||||
|
||||
lib_list = Dart_GetLibraryURLs();
|
||||
|
||||
@@ -30,9 +30,9 @@ void FUNCTION_NAME(Unhandled_equals)(Dart_NativeArguments args) {
|
||||
|
||||
void FUNCTION_NAME(Unhandled_invoke)(Dart_NativeArguments args) {
|
||||
// Invoke the specified entry point.
|
||||
Dart_Handle cls = Dart_GetClass(TestCase::lib(), Dart_NewString("Second"));
|
||||
Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("Second"));
|
||||
Dart_Handle result = Dart_Invoke(cls,
|
||||
Dart_NewString("method2"),
|
||||
NewString("method2"),
|
||||
0,
|
||||
NULL);
|
||||
ASSERT(Dart_IsError(result));
|
||||
@@ -43,9 +43,9 @@ void FUNCTION_NAME(Unhandled_invoke)(Dart_NativeArguments args) {
|
||||
|
||||
void FUNCTION_NAME(Unhandled_invoke2)(Dart_NativeArguments args) {
|
||||
// Invoke the specified entry point.
|
||||
Dart_Handle cls = Dart_GetClass(TestCase::lib(), Dart_NewString("Second"));
|
||||
Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("Second"));
|
||||
Dart_Handle result = Dart_Invoke(cls,
|
||||
Dart_NewString("method2"),
|
||||
NewString("method2"),
|
||||
0,
|
||||
NULL);
|
||||
ASSERT(Dart_IsError(result));
|
||||
@@ -127,7 +127,7 @@ TEST_CASE(UnhandledExceptions) {
|
||||
Dart_Handle lib = TestCase::LoadTestScript(
|
||||
kScriptChars,
|
||||
reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
|
||||
EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL));
|
||||
EXPECT_VALID(Dart_Invoke(lib, NewString("testMain"), 0, NULL));
|
||||
}
|
||||
#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
|
||||
|
||||
|
||||
@@ -539,10 +539,8 @@ void FlowGraphCompiler::GenerateStringTypeCheck(Register kClassIdReg,
|
||||
GrowableArray<intptr_t> args;
|
||||
args.Add(kOneByteStringCid);
|
||||
args.Add(kTwoByteStringCid);
|
||||
args.Add(kFourByteStringCid);
|
||||
args.Add(kExternalOneByteStringCid);
|
||||
args.Add(kExternalTwoByteStringCid);
|
||||
args.Add(kExternalFourByteStringCid);
|
||||
CheckClassIds(kClassIdReg, args, is_instance_lbl, is_not_instance_lbl);
|
||||
}
|
||||
|
||||
|
||||
@@ -278,10 +278,8 @@ void HeapProfiler::WriteObject(const RawObject* raw_obj) {
|
||||
}
|
||||
case kOneByteStringCid:
|
||||
case kTwoByteStringCid:
|
||||
case kFourByteStringCid:
|
||||
case kExternalOneByteStringCid:
|
||||
case kExternalTwoByteStringCid:
|
||||
case kExternalFourByteStringCid: {
|
||||
case kExternalTwoByteStringCid: {
|
||||
WriteInstanceDump(StringId(reinterpret_cast<const RawString*>(raw_obj)));
|
||||
break;
|
||||
}
|
||||
@@ -355,7 +353,8 @@ void HeapProfiler::WriteStringInUtf8(const RawString* raw_string) {
|
||||
int32_t ch = onestr->ptr()->data_[i];
|
||||
j += Utf8::Encode(ch, &characters[j]);
|
||||
}
|
||||
} else if (class_id == kTwoByteStringCid) {
|
||||
} else {
|
||||
ASSERT(class_id == kTwoByteStringCid);
|
||||
const RawTwoByteString* twostr =
|
||||
reinterpret_cast<const RawTwoByteString*>(raw_string);
|
||||
for (intptr_t i = 0; i < Smi::Value(twostr->ptr()->length_); ++i) {
|
||||
@@ -366,18 +365,6 @@ void HeapProfiler::WriteStringInUtf8(const RawString* raw_string) {
|
||||
int32_t ch = twostr->ptr()->data_[i];
|
||||
j += Utf8::Encode(ch, &characters[j]);
|
||||
}
|
||||
} else {
|
||||
ASSERT(class_id == kFourByteStringCid);
|
||||
const RawFourByteString* fourstr =
|
||||
reinterpret_cast<const RawFourByteString*>(raw_string);
|
||||
for (intptr_t i = 0; i < Smi::Value(fourstr->ptr()->length_); ++i) {
|
||||
length += Utf8::Length(fourstr->ptr()->data_[i]);
|
||||
}
|
||||
characters = new char[length];
|
||||
for (intptr_t i = 0, j = 0; i < Smi::Value(fourstr->ptr()->length_); ++i) {
|
||||
int32_t ch = fourstr->ptr()->data_[i];
|
||||
j += Utf8::Encode(ch, &characters[j]);
|
||||
}
|
||||
}
|
||||
Record record(kStringInUtf8, this);
|
||||
record.WritePointer(ObjectId(raw_string));
|
||||
|
||||
@@ -18,9 +18,7 @@ TEST_CASE(OldGC) {
|
||||
"}\n";
|
||||
FLAG_verbose_gc = true;
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
||||
Dart_Handle result = Dart_Invoke(lib,
|
||||
Dart_NewString("main"),
|
||||
0, NULL);
|
||||
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
||||
|
||||
EXPECT_VALID(result);
|
||||
EXPECT(!Dart_IsNull(result));
|
||||
@@ -39,9 +37,7 @@ TEST_CASE(LargeSweep) {
|
||||
FLAG_verbose_gc = true;
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
||||
Dart_EnterScope();
|
||||
Dart_Handle result = Dart_Invoke(lib,
|
||||
Dart_NewString("main"),
|
||||
0, NULL);
|
||||
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
||||
|
||||
EXPECT_VALID(result);
|
||||
EXPECT(!Dart_IsNull(result));
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_CASE(IsolateSpawn) {
|
||||
" return 0;\n"
|
||||
"}\n";
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
||||
Dart_Handle result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL);
|
||||
Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
|
||||
EXPECT_ERROR(result, "Null callback specified for isolate creation");
|
||||
EXPECT(Dart_ErrorHasException(result));
|
||||
Dart_Handle exception_result = Dart_ErrorGetException(result);
|
||||
|
||||
+125
-363
@@ -612,12 +612,6 @@ RawError* Object::Init(Isolate* isolate) {
|
||||
RegisterPrivateClass(cls, name, core_lib);
|
||||
pending_classes.Add(cls, Heap::kOld);
|
||||
|
||||
cls = Class::New<FourByteString>();
|
||||
object_store->set_four_byte_string_class(cls);
|
||||
name = Symbols::FourByteString();
|
||||
RegisterPrivateClass(cls, name, core_lib);
|
||||
pending_classes.Add(cls, Heap::kOld);
|
||||
|
||||
cls = Class::New<ExternalOneByteString>();
|
||||
object_store->set_external_one_byte_string_class(cls);
|
||||
name = Symbols::ExternalOneByteString();
|
||||
@@ -630,12 +624,6 @@ RawError* Object::Init(Isolate* isolate) {
|
||||
RegisterPrivateClass(cls, name, core_lib);
|
||||
pending_classes.Add(cls, Heap::kOld);
|
||||
|
||||
cls = Class::New<ExternalFourByteString>();
|
||||
object_store->set_external_four_byte_string_class(cls);
|
||||
name = Symbols::ExternalFourByteString();
|
||||
RegisterPrivateClass(cls, name, core_lib);
|
||||
pending_classes.Add(cls, Heap::kOld);
|
||||
|
||||
cls = Class::New<Stacktrace>();
|
||||
object_store->set_stacktrace_class(cls);
|
||||
name = Symbols::Stacktrace();
|
||||
@@ -1103,18 +1091,12 @@ void Object::InitFromSnapshot(Isolate* isolate) {
|
||||
cls = Class::New<TwoByteString>();
|
||||
object_store->set_two_byte_string_class(cls);
|
||||
|
||||
cls = Class::New<FourByteString>();
|
||||
object_store->set_four_byte_string_class(cls);
|
||||
|
||||
cls = Class::New<ExternalOneByteString>();
|
||||
object_store->set_external_one_byte_string_class(cls);
|
||||
|
||||
cls = Class::New<ExternalTwoByteString>();
|
||||
object_store->set_external_two_byte_string_class(cls);
|
||||
|
||||
cls = Class::New<ExternalFourByteString>();
|
||||
object_store->set_external_four_byte_string_class(cls);
|
||||
|
||||
cls = Class::New<Bool>();
|
||||
object_store->set_bool_class(cls);
|
||||
|
||||
@@ -1247,10 +1229,8 @@ RawString* Class::UserVisibleName() const {
|
||||
return Symbols::New("double");
|
||||
case kOneByteStringCid:
|
||||
case kTwoByteStringCid:
|
||||
case kFourByteStringCid:
|
||||
case kExternalOneByteStringCid:
|
||||
case kExternalTwoByteStringCid:
|
||||
case kExternalFourByteStringCid:
|
||||
return Symbols::New("String");
|
||||
case kArrayCid:
|
||||
case kImmutableArrayCid:
|
||||
@@ -9823,17 +9803,22 @@ bool String::Equals(const Instance& other) const {
|
||||
|
||||
|
||||
bool String::Equals(const char* str) const {
|
||||
ASSERT(str != NULL);
|
||||
intptr_t len = strlen(str);
|
||||
for (intptr_t i = 0; i < this->Length(); ++i) {
|
||||
if (*str == '\0') {
|
||||
// Lengths don't match.
|
||||
return false;
|
||||
}
|
||||
int32_t ch;
|
||||
intptr_t consumed = Utf8::Decode(str, &ch);
|
||||
intptr_t consumed = Utf8::Decode(reinterpret_cast<const uint8_t*>(str),
|
||||
len,
|
||||
&ch);
|
||||
if (consumed == 0 || this->CharAt(i) != ch) {
|
||||
return false;
|
||||
}
|
||||
str += consumed;
|
||||
len -= consumed;
|
||||
}
|
||||
return *str == '\0';
|
||||
}
|
||||
@@ -9927,76 +9912,70 @@ RawInstance* String::Canonicalize() const {
|
||||
|
||||
|
||||
RawString* String::New(const char* str, Heap::Space space) {
|
||||
intptr_t width = 0;
|
||||
intptr_t len = Utf8::CodePointCount(str, &width);
|
||||
if (width == 1) {
|
||||
const OneByteString& onestr
|
||||
ASSERT(str != NULL);
|
||||
intptr_t array_len = strlen(str);
|
||||
const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
|
||||
return String::New(utf8_array, array_len, space);
|
||||
}
|
||||
|
||||
|
||||
RawString* String::New(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space) {
|
||||
Utf8::Type type;
|
||||
intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type);
|
||||
if (type == Utf8::kAscii) {
|
||||
const OneByteString& strobj
|
||||
= OneByteString::Handle(OneByteString::New(len, space));
|
||||
if (len > 0) {
|
||||
NoGCScope no_gc;
|
||||
Utf8::Decode(str, onestr.CharAddr(0), len);
|
||||
Utf8::DecodeToAscii(utf8_array, array_len, strobj.CharAddr(0), len);
|
||||
}
|
||||
return onestr.raw();
|
||||
} else if (width == 2) {
|
||||
const TwoByteString& twostr =
|
||||
TwoByteString::Handle(TwoByteString::New(len, space));
|
||||
NoGCScope no_gc;
|
||||
Utf8::Decode(str, twostr.CharAddr(0), len);
|
||||
return twostr.raw();
|
||||
return strobj.raw();
|
||||
}
|
||||
ASSERT(width == 4);
|
||||
const FourByteString& fourstr =
|
||||
FourByteString::Handle(FourByteString::New(len, space));
|
||||
ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
|
||||
const TwoByteString& strobj =
|
||||
TwoByteString::Handle(TwoByteString::New(len, space));
|
||||
NoGCScope no_gc;
|
||||
Utf8::Decode(str, fourstr.CharAddr(0), len);
|
||||
return fourstr.raw();
|
||||
Utf8::DecodeToUTF16(utf8_array, array_len, strobj.CharAddr(0), len);
|
||||
return strobj.raw();
|
||||
}
|
||||
|
||||
|
||||
RawString* String::New(const uint8_t* characters,
|
||||
intptr_t len,
|
||||
Heap::Space space) {
|
||||
return OneByteString::New(characters, len, space);
|
||||
}
|
||||
|
||||
|
||||
RawString* String::New(const uint16_t* characters,
|
||||
intptr_t len,
|
||||
RawString* String::New(const uint16_t* utf16_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space) {
|
||||
bool is_one_byte_string = true;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
if (characters[i] > 0xFF) {
|
||||
for (intptr_t i = 0; i < array_len; ++i) {
|
||||
if (utf16_array[i] > 0x7F) {
|
||||
is_one_byte_string = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_one_byte_string) {
|
||||
return OneByteString::New(characters, len, space);
|
||||
return OneByteString::New(utf16_array, array_len, space);
|
||||
}
|
||||
return TwoByteString::New(characters, len, space);
|
||||
return TwoByteString::New(utf16_array, array_len, space);
|
||||
}
|
||||
|
||||
|
||||
RawString* String::New(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
RawString* String::New(const uint32_t* utf32_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space) {
|
||||
bool is_one_byte_string = true;
|
||||
bool is_two_byte_string = true;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
if (characters[i] > 0xFFFF) {
|
||||
is_two_byte_string = false;
|
||||
is_one_byte_string = false;
|
||||
break;
|
||||
} else if (characters[i] > 0xFF) {
|
||||
intptr_t utf16_len = array_len;
|
||||
for (intptr_t i = 0; i < array_len; ++i) {
|
||||
if (utf32_array[i] > 0x7F) {
|
||||
is_one_byte_string = false;
|
||||
}
|
||||
if (utf32_array[i] > 0xFFFF) {
|
||||
utf16_len += 1;
|
||||
}
|
||||
}
|
||||
if (is_one_byte_string) {
|
||||
return OneByteString::New(characters, len, space);
|
||||
} else if (is_two_byte_string) {
|
||||
return TwoByteString::New(characters, len, space);
|
||||
return OneByteString::New(utf32_array, array_len, space);
|
||||
}
|
||||
return FourByteString::New(characters, len, space);
|
||||
return TwoByteString::New(utf16_len, utf32_array, array_len, space);
|
||||
}
|
||||
|
||||
|
||||
@@ -10010,11 +9989,9 @@ RawString* String::New(const String& str, Heap::Space space) {
|
||||
intptr_t char_size = str.CharSize();
|
||||
if (char_size == kOneByteChar) {
|
||||
result ^= OneByteString::New(len, space);
|
||||
} else if (char_size == kTwoByteChar) {
|
||||
result ^= TwoByteString::New(len, space);
|
||||
} else {
|
||||
ASSERT(char_size == kFourByteChar);
|
||||
result ^= FourByteString::New(len, space);
|
||||
ASSERT(char_size == kTwoByteChar);
|
||||
result ^= TwoByteString::New(len, space);
|
||||
}
|
||||
String::Copy(result, 0, str, 0, len);
|
||||
return result.raw();
|
||||
@@ -10039,15 +10016,6 @@ RawString* String::NewExternal(const uint16_t* characters,
|
||||
}
|
||||
|
||||
|
||||
RawString* String::NewExternal(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback,
|
||||
Heap::Space space) {
|
||||
return ExternalFourByteString::New(characters, len, peer, callback, space);
|
||||
}
|
||||
|
||||
|
||||
void String::Copy(const String& dst, intptr_t dst_offset,
|
||||
const uint8_t* characters,
|
||||
intptr_t len) {
|
||||
@@ -10066,73 +10034,29 @@ void String::Copy(const String& dst, intptr_t dst_offset,
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
*twostr.CharAddr(i + dst_offset) = characters[i];
|
||||
}
|
||||
} else {
|
||||
ASSERT(dst.IsFourByteString());
|
||||
const FourByteString& fourstr = FourByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
*fourstr.CharAddr(i + dst_offset) = characters[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void String::Copy(const String& dst, intptr_t dst_offset,
|
||||
const uint16_t* characters,
|
||||
intptr_t len) {
|
||||
const uint16_t* utf16_array,
|
||||
intptr_t array_len) {
|
||||
ASSERT(dst_offset >= 0);
|
||||
ASSERT(len >= 0);
|
||||
ASSERT(len <= (dst.Length() - dst_offset));
|
||||
ASSERT(array_len >= 0);
|
||||
ASSERT(array_len <= (dst.Length() - dst_offset));
|
||||
if (dst.IsOneByteString()) {
|
||||
const OneByteString& onestr = OneByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
ASSERT(characters[i] <= 0xFF);
|
||||
*onestr.CharAddr(i + dst_offset) = characters[i];
|
||||
}
|
||||
} else if (dst.IsTwoByteString()) {
|
||||
const TwoByteString& twostr = TwoByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
if (len > 0) {
|
||||
memmove(twostr.CharAddr(dst_offset), characters, len * 2);
|
||||
for (intptr_t i = 0; i < array_len; ++i) {
|
||||
ASSERT(utf16_array[i] <= 0x7F);
|
||||
*onestr.CharAddr(i + dst_offset) = utf16_array[i];
|
||||
}
|
||||
} else {
|
||||
ASSERT(dst.IsFourByteString());
|
||||
const FourByteString& fourstr = FourByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
*fourstr.CharAddr(i + dst_offset) = characters[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void String::Copy(const String& dst, intptr_t dst_offset,
|
||||
const uint32_t* characters,
|
||||
intptr_t len) {
|
||||
ASSERT(dst_offset >= 0);
|
||||
ASSERT(len >= 0);
|
||||
ASSERT(len <= (dst.Length() - dst_offset));
|
||||
if (dst.IsOneByteString()) {
|
||||
const OneByteString& onestr = OneByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
ASSERT(characters[i] <= 0xFF);
|
||||
*onestr.CharAddr(i + dst_offset) = characters[i];
|
||||
}
|
||||
} else if (dst.IsTwoByteString()) {
|
||||
ASSERT(dst.IsTwoByteString());
|
||||
const TwoByteString& twostr = TwoByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
ASSERT(characters[i] <= 0xFFFF);
|
||||
*twostr.CharAddr(i + dst_offset) = characters[i];
|
||||
}
|
||||
} else {
|
||||
ASSERT(dst.IsFourByteString());
|
||||
const FourByteString& fourstr = FourByteString::Cast(dst);
|
||||
NoGCScope no_gc;
|
||||
if (len > 0) {
|
||||
memmove(fourstr.CharAddr(dst_offset), characters, len * 4);
|
||||
if (array_len > 0) {
|
||||
memmove(twostr.CharAddr(dst_offset), utf16_array, (array_len * 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10159,7 +10083,8 @@ void String::Copy(const String& dst, intptr_t dst_offset,
|
||||
NoGCScope no_gc;
|
||||
String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len);
|
||||
}
|
||||
} else if (char_size == kTwoByteChar) {
|
||||
} else {
|
||||
ASSERT(char_size == kTwoByteChar);
|
||||
if (src.IsTwoByteString()) {
|
||||
const TwoByteString& twostr = TwoByteString::Cast(src);
|
||||
NoGCScope no_gc;
|
||||
@@ -10170,19 +10095,6 @@ void String::Copy(const String& dst, intptr_t dst_offset,
|
||||
NoGCScope no_gc;
|
||||
String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len);
|
||||
}
|
||||
} else {
|
||||
ASSERT(char_size == kFourByteChar);
|
||||
if (src.IsFourByteString()) {
|
||||
const FourByteString& fourstr = FourByteString::Cast(src);
|
||||
NoGCScope no_gc;
|
||||
String::Copy(dst, dst_offset, fourstr.CharAddr(0) + src_offset, len);
|
||||
} else {
|
||||
ASSERT(src.IsExternalFourByteString());
|
||||
const ExternalFourByteString& fourstr =
|
||||
ExternalFourByteString::Cast(src);
|
||||
NoGCScope no_gc;
|
||||
String::Copy(dst, dst_offset, fourstr.CharAddr(0) + src_offset, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10193,13 +10105,9 @@ RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) {
|
||||
const OneByteString& onestr = OneByteString::Cast(str);
|
||||
return onestr.EscapeSpecialCharacters(raw_str);
|
||||
}
|
||||
if (str.IsTwoByteString()) {
|
||||
const TwoByteString& twostr = TwoByteString::Cast(str);
|
||||
return twostr.EscapeSpecialCharacters(raw_str);
|
||||
}
|
||||
ASSERT(str.IsFourByteString());
|
||||
const FourByteString& fourstr = FourByteString::Cast(str);
|
||||
return fourstr.EscapeSpecialCharacters(raw_str);
|
||||
ASSERT(str.IsTwoByteString());
|
||||
const TwoByteString& twostr = TwoByteString::Cast(str);
|
||||
return twostr.EscapeSpecialCharacters(raw_str);
|
||||
}
|
||||
|
||||
|
||||
@@ -10232,9 +10140,6 @@ RawString* String::Concat(const String& str1,
|
||||
Heap::Space space) {
|
||||
ASSERT(!str1.IsNull() && !str2.IsNull());
|
||||
intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize());
|
||||
if (char_size == kFourByteChar) {
|
||||
return FourByteString::Concat(str1, str2, space);
|
||||
}
|
||||
if (char_size == kTwoByteChar) {
|
||||
return TwoByteString::Concat(str1, str2, space);
|
||||
}
|
||||
@@ -10256,11 +10161,9 @@ RawString* String::ConcatAll(const Array& strings,
|
||||
}
|
||||
if (char_size == kOneByteChar) {
|
||||
return OneByteString::ConcatAll(strings, result_len, space);
|
||||
} else if (char_size == kTwoByteChar) {
|
||||
return TwoByteString::ConcatAll(strings, result_len, space);
|
||||
}
|
||||
ASSERT(char_size == kFourByteChar);
|
||||
return FourByteString::ConcatAll(strings, result_len, space);
|
||||
ASSERT(char_size == kTwoByteChar);
|
||||
return TwoByteString::ConcatAll(strings, result_len, space);
|
||||
}
|
||||
|
||||
|
||||
@@ -10290,32 +10193,19 @@ RawString* String::SubString(const String& str,
|
||||
}
|
||||
String& result = String::Handle();
|
||||
bool is_one_byte_string = true;
|
||||
bool is_two_byte_string = true;
|
||||
intptr_t char_size = str.CharSize();
|
||||
if (char_size == kTwoByteChar) {
|
||||
for (intptr_t i = begin_index; i < begin_index + length; ++i) {
|
||||
if (str.CharAt(i) > 0xFF) {
|
||||
if (str.CharAt(i) > 0x7F) {
|
||||
is_one_byte_string = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (char_size == kFourByteChar) {
|
||||
for (intptr_t i = begin_index; i < begin_index + length; ++i) {
|
||||
if (str.CharAt(i) > 0xFFFF) {
|
||||
is_one_byte_string = false;
|
||||
is_two_byte_string = false;
|
||||
break;
|
||||
} else if (str.CharAt(i) > 0xFF) {
|
||||
is_one_byte_string = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_one_byte_string) {
|
||||
result ^= OneByteString::New(length, space);
|
||||
} else if (is_two_byte_string) {
|
||||
result ^= TwoByteString::New(length, space);
|
||||
} else {
|
||||
result ^= FourByteString::New(length, space);
|
||||
result ^= TwoByteString::New(length, space);
|
||||
}
|
||||
String::Copy(result, 0, str, begin_index, length);
|
||||
return result.raw();
|
||||
@@ -10325,10 +10215,24 @@ RawString* String::SubString(const String& str,
|
||||
const char* String::ToCString() const {
|
||||
intptr_t len = Utf8::Length(*this);
|
||||
Zone* zone = Isolate::Current()->current_zone();
|
||||
char* result = zone->Alloc<char>(len + 1);
|
||||
Utf8::Encode(*this, result, len);
|
||||
uint8_t* result = zone->Alloc<uint8_t>(len + 1);
|
||||
ToUTF8(result, len);
|
||||
result[len] = 0;
|
||||
return result;
|
||||
return reinterpret_cast<const char*>(result);
|
||||
}
|
||||
|
||||
|
||||
void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const {
|
||||
if (CharSize() == kOneByteChar) {
|
||||
const OneByteString& obj = OneByteString::Cast(*this);
|
||||
ASSERT(array_len >= obj.Length());
|
||||
if (obj.Length() > 0) {
|
||||
memmove(utf8_array, obj.CharAddr(0), obj.Length());
|
||||
}
|
||||
} else {
|
||||
ASSERT(array_len >= Utf8::Length(*this));
|
||||
Utf8::Encode(*this, reinterpret_cast<char*>(utf8_array), array_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10351,14 +10255,11 @@ RawString* String::Transform(int32_t (*mapping)(int32_t ch),
|
||||
if (!has_mapping) {
|
||||
return str.raw();
|
||||
}
|
||||
if (dst_max <= 0xFF) {
|
||||
if (dst_max <= 0x7F) {
|
||||
return OneByteString::Transform(mapping, str, space);
|
||||
}
|
||||
if (dst_max <= 0xFFFF) {
|
||||
return TwoByteString::Transform(mapping, str, space);
|
||||
}
|
||||
ASSERT(dst_max > 0xFFFF);
|
||||
return FourByteString::Transform(mapping, str, space);
|
||||
ASSERT(dst_max > 0x7F);
|
||||
return TwoByteString::Transform(mapping, str, space);
|
||||
}
|
||||
|
||||
|
||||
@@ -10489,7 +10390,10 @@ RawOneByteString* OneByteString::New(const uint8_t* characters,
|
||||
Heap::Space space) {
|
||||
const OneByteString& result =
|
||||
OneByteString::Handle(OneByteString::New(len, space));
|
||||
String::Copy(result, 0, characters, len);
|
||||
if (len > 0) {
|
||||
NoGCScope no_gc;
|
||||
memmove(result.CharAddr(0), characters, len);
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
@@ -10499,7 +10403,10 @@ RawOneByteString* OneByteString::New(const uint16_t* characters,
|
||||
Heap::Space space) {
|
||||
const OneByteString& result =
|
||||
OneByteString::Handle(OneByteString::New(len, space));
|
||||
String::Copy(result, 0, characters, len);
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
ASSERT(characters[i] <= 0x7F);
|
||||
*result.CharAddr(i) = characters[i];
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
@@ -10509,7 +10416,10 @@ RawOneByteString* OneByteString::New(const uint32_t* characters,
|
||||
Heap::Space space) {
|
||||
const OneByteString& result =
|
||||
OneByteString::Handle(OneByteString::New(len, space));
|
||||
String::Copy(result, 0, characters, len);
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
ASSERT(characters[i] <= 0x7F);
|
||||
*result.CharAddr(i) = characters[i];
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
@@ -10565,7 +10475,7 @@ RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
|
||||
OneByteString::Handle(OneByteString::New(len, space));
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
int32_t ch = mapping(str.CharAt(i));
|
||||
ASSERT(ch >= 0 && ch <= 0xFF);
|
||||
ASSERT(ch >= 0 && ch <= 0x7F);
|
||||
*result.CharAddr(i) = ch;
|
||||
}
|
||||
return result.raw();
|
||||
@@ -10631,22 +10541,42 @@ RawTwoByteString* TwoByteString::New(intptr_t len,
|
||||
}
|
||||
|
||||
|
||||
RawTwoByteString* TwoByteString::New(const uint16_t* characters,
|
||||
intptr_t len,
|
||||
RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space) {
|
||||
ASSERT(array_len > 0);
|
||||
const TwoByteString& result =
|
||||
TwoByteString::Handle(TwoByteString::New(len, space));
|
||||
String::Copy(result, 0, characters, len);
|
||||
TwoByteString::Handle(TwoByteString::New(array_len, space));
|
||||
{
|
||||
NoGCScope no_gc;
|
||||
memmove(result.CharAddr(0), utf16_array, (array_len * 2));
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
RawTwoByteString* TwoByteString::New(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
RawTwoByteString* TwoByteString::New(intptr_t utf16_len,
|
||||
const uint32_t* utf32_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space) {
|
||||
ASSERT((array_len > 0) && (utf16_len >= array_len));
|
||||
const TwoByteString& result =
|
||||
TwoByteString::Handle(TwoByteString::New(len, space));
|
||||
String::Copy(result, 0, characters, len);
|
||||
TwoByteString::Handle(TwoByteString::New(utf16_len, space));
|
||||
{
|
||||
NoGCScope no_gc;
|
||||
intptr_t j = 0;
|
||||
for (intptr_t i = 0; i < array_len; ++i) {
|
||||
if (utf32_array[i] > 0xffff) {
|
||||
ASSERT(j < (utf16_len - 1));
|
||||
Utf8::ConvertUTF32ToUTF16(utf32_array[i], result.CharAddr(j));
|
||||
j += 2;
|
||||
} else {
|
||||
ASSERT(j < utf16_len);
|
||||
*result.CharAddr(j) = utf32_array[i];
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
@@ -10714,132 +10644,6 @@ const char* TwoByteString::ToCString() const {
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::EscapeSpecialCharacters(bool raw_str) const {
|
||||
intptr_t len = Length();
|
||||
if (len > 0) {
|
||||
intptr_t num_escapes = 0;
|
||||
intptr_t index = 0;
|
||||
for (intptr_t i = 0; i < len; i++) {
|
||||
if (IsSpecialCharacter(*CharAddr(i)) ||
|
||||
(!raw_str && (*CharAddr(i) == '\\'))) {
|
||||
num_escapes += 1;
|
||||
}
|
||||
}
|
||||
const FourByteString& dststr = FourByteString::Handle(
|
||||
FourByteString::New(len + num_escapes, Heap::kNew));
|
||||
for (intptr_t i = 0; i < len; i++) {
|
||||
if (IsSpecialCharacter(*CharAddr(i))) {
|
||||
*(dststr.CharAddr(index)) = '\\';
|
||||
*(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i));
|
||||
index += 2;
|
||||
} else if (!raw_str && (*CharAddr(i) == '\\')) {
|
||||
*(dststr.CharAddr(index)) = '\\';
|
||||
*(dststr.CharAddr(index + 1)) = '\\';
|
||||
index += 2;
|
||||
} else {
|
||||
*(dststr.CharAddr(index)) = *CharAddr(i);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
return dststr.raw();
|
||||
}
|
||||
return FourByteString::null();
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::New(intptr_t len,
|
||||
Heap::Space space) {
|
||||
ASSERT(Isolate::Current()->object_store()->four_byte_string_class() !=
|
||||
Class::null());
|
||||
if (len < 0 || len > kMaxElements) {
|
||||
// This should be caught before we reach here.
|
||||
FATAL1("Fatal error in FourByteString::New: invalid len %"Pd"\n", len);
|
||||
}
|
||||
FourByteString& result = FourByteString::Handle();
|
||||
{
|
||||
RawObject* raw = Object::Allocate(FourByteString::kClassId,
|
||||
FourByteString::InstanceSize(len),
|
||||
space);
|
||||
NoGCScope no_gc;
|
||||
result ^= raw;
|
||||
result.SetLength(len);
|
||||
result.SetHash(0);
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::New(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
Heap::Space space) {
|
||||
const FourByteString& result =
|
||||
FourByteString::Handle(FourByteString::New(len, space));
|
||||
String::Copy(result, 0, characters, len);
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::New(const FourByteString& str,
|
||||
Heap::Space space) {
|
||||
return FourByteString::New(str.CharAddr(0), str.Length(), space);
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::Concat(const String& str1,
|
||||
const String& str2,
|
||||
Heap::Space space) {
|
||||
intptr_t len1 = str1.Length();
|
||||
intptr_t len2 = str2.Length();
|
||||
intptr_t len = len1 + len2;
|
||||
const FourByteString& result =
|
||||
FourByteString::Handle(FourByteString::New(len, space));
|
||||
String::Copy(result, 0, str1, 0, len1);
|
||||
String::Copy(result, len1, str2, 0, len2);
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::ConcatAll(const Array& strings,
|
||||
intptr_t len,
|
||||
Heap::Space space) {
|
||||
const FourByteString& result =
|
||||
FourByteString::Handle(FourByteString::New(len, space));
|
||||
String& str = String::Handle();
|
||||
{
|
||||
intptr_t strings_len = strings.Length();
|
||||
intptr_t pos = 0;
|
||||
for (intptr_t i = 0; i < strings_len; i++) {
|
||||
str ^= strings.At(i);
|
||||
intptr_t str_len = str.Length();
|
||||
String::Copy(result, pos, str, 0, str_len);
|
||||
pos += str_len;
|
||||
}
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::Transform(int32_t (*mapping)(int32_t ch),
|
||||
const String& str,
|
||||
Heap::Space space) {
|
||||
ASSERT(!str.IsNull());
|
||||
intptr_t len = str.Length();
|
||||
const FourByteString& result =
|
||||
FourByteString::Handle(FourByteString::New(len, space));
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
int32_t ch = mapping(str.CharAt(i));
|
||||
ASSERT(ch >= 0 && ch <= 0x10FFFF);
|
||||
*result.CharAddr(i) = ch;
|
||||
}
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
const char* FourByteString::ToCString() const {
|
||||
return String::ToCString();
|
||||
}
|
||||
|
||||
|
||||
static void AddFinalizer(const Object& referent,
|
||||
void* peer,
|
||||
Dart_WeakPersistentHandleFinalizer callback) {
|
||||
@@ -10948,48 +10752,6 @@ const char* ExternalTwoByteString::ToCString() const {
|
||||
}
|
||||
|
||||
|
||||
RawExternalFourByteString* ExternalFourByteString::New(
|
||||
const uint32_t* data,
|
||||
intptr_t len,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback,
|
||||
Heap::Space space) {
|
||||
ASSERT(Isolate::Current()->object_store()->
|
||||
external_four_byte_string_class() != Class::null());
|
||||
if (len < 0 || len > kMaxElements) {
|
||||
// This should be caught before we reach here.
|
||||
FATAL1("Fatal error in ExternalFourByteString::New: invalid len %"Pd"\n",
|
||||
len);
|
||||
}
|
||||
ExternalFourByteString& result = ExternalFourByteString::Handle();
|
||||
ExternalStringData<uint32_t>* external_data =
|
||||
new ExternalStringData<uint32_t>(data, peer, callback);
|
||||
{
|
||||
RawObject* raw = Object::Allocate(ExternalFourByteString::kClassId,
|
||||
ExternalFourByteString::InstanceSize(),
|
||||
space);
|
||||
NoGCScope no_gc;
|
||||
result ^= raw;
|
||||
result.SetLength(len);
|
||||
result.SetHash(0);
|
||||
result.SetExternalData(external_data);
|
||||
}
|
||||
AddFinalizer(result, external_data, ExternalFourByteString::Finalize);
|
||||
return result.raw();
|
||||
}
|
||||
|
||||
|
||||
void ExternalFourByteString::Finalize(Dart_Handle handle, void* peer) {
|
||||
delete reinterpret_cast<ExternalStringData<uint32_t>*>(peer);
|
||||
DeleteWeakPersistentHandle(handle);
|
||||
}
|
||||
|
||||
|
||||
const char* ExternalFourByteString::ToCString() const {
|
||||
return String::ToCString();
|
||||
}
|
||||
|
||||
|
||||
RawBool* Bool::True() {
|
||||
return Isolate::Current()->object_store()->true_value();
|
||||
}
|
||||
|
||||
+32
-130
@@ -3626,13 +3626,12 @@ class String : public Instance {
|
||||
|
||||
static const intptr_t kOneByteChar = 1;
|
||||
static const intptr_t kTwoByteChar = 2;
|
||||
static const intptr_t kFourByteChar = 4;
|
||||
|
||||
// All strings share the same maximum element count to keep things
|
||||
// simple. We choose a value that will prevent integer overflow for
|
||||
// 4 byte strings, since it is the worst case.
|
||||
// 2 byte strings, since it is the worst case.
|
||||
static const intptr_t kSizeofRawString = sizeof(RawObject) + (2 * kWordSize);
|
||||
static const intptr_t kMaxElements = kSmiMax / kFourByteChar;
|
||||
static const intptr_t kMaxElements = kSmiMax / kTwoByteChar;
|
||||
|
||||
intptr_t Length() const { return Smi::Value(raw_ptr()->length_); }
|
||||
static intptr_t length_offset() { return OFFSET_OF(RawString, length_); }
|
||||
@@ -3673,30 +3672,42 @@ class String : public Instance {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static RawString* New(const char* str, Heap::Space space = Heap::kNew);
|
||||
static RawString* New(const uint8_t* characters,
|
||||
intptr_t len,
|
||||
void ToUTF8(uint8_t* utf8_array, intptr_t array_len) const;
|
||||
|
||||
// Creates a new String object from a C string that is assumed to contain
|
||||
// UTF-8 encoded characters and '\0' is considered a termination character.
|
||||
static RawString* New(const char* cstr, Heap::Space space = Heap::kNew);
|
||||
|
||||
// Creates a new String object from an array of UTF-8 encoded characters.
|
||||
static RawString* New(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space = Heap::kNew);
|
||||
static RawString* New(const uint16_t* characters,
|
||||
intptr_t len,
|
||||
|
||||
// Creates a new String object from an array of UTF-16 encoded characters.
|
||||
static RawString* New(const uint16_t* utf16_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space = Heap::kNew);
|
||||
static RawString* New(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
|
||||
// Creates a new String object from an array of UTF-32 encoded characters.
|
||||
static RawString* New(const uint32_t* utf32_array,
|
||||
intptr_t array_len,
|
||||
Heap::Space space = Heap::kNew);
|
||||
|
||||
// Create a new String object from another Dart String instance.
|
||||
static RawString* New(const String& str, Heap::Space space = Heap::kNew);
|
||||
|
||||
static RawString* NewExternal(const uint8_t* characters,
|
||||
intptr_t len,
|
||||
// Creates a new External String object using the specified array of
|
||||
// UTF-8 encoded characters as the external reference.
|
||||
static RawString* NewExternal(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback,
|
||||
Heap::Space = Heap::kNew);
|
||||
static RawString* NewExternal(const uint16_t* characters,
|
||||
intptr_t len,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback,
|
||||
Heap::Space = Heap::kNew);
|
||||
static RawString* NewExternal(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
|
||||
// Creates a new External String object using the specified array of
|
||||
// UTF-16 encoded characters as the external reference.
|
||||
static RawString* NewExternal(const uint16_t* utf16_array,
|
||||
intptr_t array_len,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback,
|
||||
Heap::Space = Heap::kNew);
|
||||
@@ -3709,10 +3720,6 @@ class String : public Instance {
|
||||
intptr_t dst_offset,
|
||||
const uint16_t* characters,
|
||||
intptr_t len);
|
||||
static void Copy(const String& dst,
|
||||
intptr_t dst_offset,
|
||||
const uint32_t* characters,
|
||||
intptr_t len);
|
||||
static void Copy(const String& dst,
|
||||
intptr_t dst_offset,
|
||||
const String& src,
|
||||
@@ -3888,7 +3895,8 @@ class TwoByteString : public String {
|
||||
static RawTwoByteString* New(const uint16_t* characters,
|
||||
intptr_t len,
|
||||
Heap::Space space);
|
||||
static RawTwoByteString* New(const uint32_t* characters,
|
||||
static RawTwoByteString* New(intptr_t utf16_len,
|
||||
const uint32_t* characters,
|
||||
intptr_t len,
|
||||
Heap::Space space);
|
||||
static RawTwoByteString* New(const TwoByteString& str,
|
||||
@@ -3917,64 +3925,6 @@ class TwoByteString : public String {
|
||||
};
|
||||
|
||||
|
||||
class FourByteString : public String {
|
||||
public:
|
||||
virtual int32_t CharAt(intptr_t index) const {
|
||||
return *CharAddr(index);
|
||||
}
|
||||
|
||||
virtual intptr_t CharSize() const {
|
||||
return kFourByteChar;
|
||||
}
|
||||
|
||||
RawFourByteString* EscapeSpecialCharacters(bool raw_str) const;
|
||||
|
||||
static const intptr_t kBytesPerElement = 4;
|
||||
static const intptr_t kMaxElements = String::kMaxElements;
|
||||
|
||||
static intptr_t InstanceSize() {
|
||||
ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static intptr_t InstanceSize(intptr_t len) {
|
||||
ASSERT(sizeof(RawTwoByteString) == kSizeofRawString);
|
||||
ASSERT(0 <= len && len <= kMaxElements);
|
||||
return RoundedAllocationSize(
|
||||
sizeof(RawFourByteString) + (len * kBytesPerElement));
|
||||
}
|
||||
|
||||
static RawFourByteString* New(intptr_t len,
|
||||
Heap::Space space);
|
||||
static RawFourByteString* New(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
Heap::Space space);
|
||||
static RawFourByteString* New(const FourByteString& str,
|
||||
Heap::Space space);
|
||||
|
||||
static RawFourByteString* Concat(const String& str1,
|
||||
const String& str2,
|
||||
Heap::Space space);
|
||||
static RawFourByteString* ConcatAll(const Array& strings,
|
||||
intptr_t len,
|
||||
Heap::Space space);
|
||||
|
||||
static RawFourByteString* Transform(int32_t (*mapping)(int32_t ch),
|
||||
const String& str,
|
||||
Heap::Space space);
|
||||
|
||||
private:
|
||||
uint32_t* CharAddr(intptr_t index) const {
|
||||
ASSERT((index >= 0) && (index < Length()));
|
||||
return &raw_ptr()->data_[index];
|
||||
}
|
||||
|
||||
HEAP_OBJECT_IMPLEMENTATION(FourByteString, String);
|
||||
friend class Class;
|
||||
friend class String;
|
||||
};
|
||||
|
||||
|
||||
class ExternalOneByteString : public String {
|
||||
public:
|
||||
virtual int32_t CharAt(intptr_t index) const {
|
||||
@@ -4071,54 +4021,6 @@ class ExternalTwoByteString : public String {
|
||||
};
|
||||
|
||||
|
||||
class ExternalFourByteString : public String {
|
||||
public:
|
||||
virtual int32_t CharAt(intptr_t index) const {
|
||||
return *CharAddr(index);
|
||||
}
|
||||
|
||||
virtual intptr_t CharSize() const {
|
||||
return kFourByteChar;
|
||||
}
|
||||
|
||||
virtual bool IsExternal() const { return true; }
|
||||
virtual void* GetPeer() const {
|
||||
return raw_ptr()->external_data_->peer();
|
||||
}
|
||||
|
||||
// We use the same maximum elements for all strings.
|
||||
static const intptr_t kBytesPerElement = 4;
|
||||
static const intptr_t kMaxElements = String::kMaxElements;
|
||||
|
||||
static intptr_t InstanceSize() {
|
||||
return RoundedAllocationSize(sizeof(RawExternalFourByteString));
|
||||
}
|
||||
|
||||
static RawExternalFourByteString* New(const uint32_t* characters,
|
||||
intptr_t len,
|
||||
void* peer,
|
||||
Dart_PeerFinalizer callback,
|
||||
Heap::Space space = Heap::kNew);
|
||||
|
||||
private:
|
||||
const uint32_t* CharAddr(intptr_t index) const {
|
||||
// TODO(iposva): Determine if we should throw an exception here.
|
||||
ASSERT((index >= 0) && (index < Length()));
|
||||
return &(raw_ptr()->external_data_->data()[index]);
|
||||
}
|
||||
|
||||
void SetExternalData(ExternalStringData<uint32_t>* data) {
|
||||
raw_ptr()->external_data_ = data;
|
||||
}
|
||||
|
||||
static void Finalize(Dart_Handle handle, void* peer);
|
||||
|
||||
HEAP_OBJECT_IMPLEMENTATION(ExternalFourByteString, String);
|
||||
friend class Class;
|
||||
friend class String;
|
||||
};
|
||||
|
||||
|
||||
// Class Bool implements Dart core class bool.
|
||||
class Bool : public Instance {
|
||||
public:
|
||||
|
||||
@@ -30,10 +30,8 @@ ObjectStore::ObjectStore()
|
||||
string_interface_(Type::null()),
|
||||
one_byte_string_class_(Class::null()),
|
||||
two_byte_string_class_(Class::null()),
|
||||
four_byte_string_class_(Class::null()),
|
||||
external_one_byte_string_class_(Class::null()),
|
||||
external_two_byte_string_class_(Class::null()),
|
||||
external_four_byte_string_class_(Class::null()),
|
||||
bool_type_(Type::null()),
|
||||
bool_class_(Class::null()),
|
||||
list_interface_(Type::null()),
|
||||
|
||||
@@ -117,11 +117,6 @@ class ObjectStore {
|
||||
two_byte_string_class_ = value.raw();
|
||||
}
|
||||
|
||||
RawClass* four_byte_string_class() const { return four_byte_string_class_; }
|
||||
void set_four_byte_string_class(const Class& value) {
|
||||
four_byte_string_class_ = value.raw();
|
||||
}
|
||||
|
||||
RawClass* external_one_byte_string_class() const {
|
||||
return external_one_byte_string_class_;
|
||||
}
|
||||
@@ -136,13 +131,6 @@ class ObjectStore {
|
||||
external_two_byte_string_class_ = value.raw();
|
||||
}
|
||||
|
||||
RawClass* external_four_byte_string_class() const {
|
||||
return external_four_byte_string_class_;
|
||||
}
|
||||
void set_external_four_byte_string_class(const Class& value) {
|
||||
external_four_byte_string_class_ = value.raw();
|
||||
}
|
||||
|
||||
RawType* bool_type() const { return bool_type_; }
|
||||
void set_bool_type(const Type& value) { bool_type_ = value.raw(); }
|
||||
|
||||
@@ -494,10 +482,8 @@ class ObjectStore {
|
||||
RawType* string_interface_;
|
||||
RawClass* one_byte_string_class_;
|
||||
RawClass* two_byte_string_class_;
|
||||
RawClass* four_byte_string_class_;
|
||||
RawClass* external_one_byte_string_class_;
|
||||
RawClass* external_two_byte_string_class_;
|
||||
RawClass* external_four_byte_string_class_;
|
||||
RawType* bool_type_;
|
||||
RawClass* bool_class_;
|
||||
RawType* list_interface_;
|
||||
|
||||
+92
-304
@@ -470,7 +470,6 @@ TEST_CASE(String) {
|
||||
EXPECT(str.IsString());
|
||||
EXPECT(str.IsOneByteString());
|
||||
EXPECT(!str.IsTwoByteString());
|
||||
EXPECT(!str.IsFourByteString());
|
||||
EXPECT(!str.IsNumber());
|
||||
EXPECT_EQ(hello_len, str.Length());
|
||||
EXPECT_EQ('H', str.CharAt(0));
|
||||
@@ -515,23 +514,23 @@ TEST_CASE(String) {
|
||||
EXPECT(empty1.Equals(empty2, 0, 0));
|
||||
|
||||
const intptr_t kCharsLen = 8;
|
||||
const uint8_t chars[kCharsLen] = { 1, 2, 127, 128, 192, 0, 255, -1 };
|
||||
const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 };
|
||||
const String& str8 = String::Handle(String::New(chars, kCharsLen));
|
||||
EXPECT_EQ(kCharsLen, str8.Length());
|
||||
EXPECT_EQ(1, str8.CharAt(0));
|
||||
EXPECT_EQ(127, str8.CharAt(2));
|
||||
EXPECT_EQ(128, str8.CharAt(3));
|
||||
EXPECT_EQ(64, str8.CharAt(3));
|
||||
EXPECT_EQ(0, str8.CharAt(5));
|
||||
EXPECT_EQ(255, str8.CharAt(6));
|
||||
EXPECT_EQ(255, str8.CharAt(7));
|
||||
EXPECT_EQ(55, str8.CharAt(6));
|
||||
EXPECT_EQ(55, str8.CharAt(7));
|
||||
const intptr_t kCharsIndex = 3;
|
||||
const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex));
|
||||
EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length());
|
||||
EXPECT_EQ(128, sub1.CharAt(0));
|
||||
EXPECT_EQ(192, sub1.CharAt(1));
|
||||
EXPECT_EQ(64, sub1.CharAt(0));
|
||||
EXPECT_EQ(92, sub1.CharAt(1));
|
||||
EXPECT_EQ(0, sub1.CharAt(2));
|
||||
EXPECT_EQ(255, sub1.CharAt(3));
|
||||
EXPECT_EQ(255, sub1.CharAt(4));
|
||||
EXPECT_EQ(55, sub1.CharAt(3));
|
||||
EXPECT_EQ(55, sub1.CharAt(4));
|
||||
|
||||
const intptr_t kWideCharsLen = 7;
|
||||
uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' };
|
||||
@@ -541,7 +540,6 @@ TEST_CASE(String) {
|
||||
EXPECT(two_str.IsString());
|
||||
EXPECT(two_str.IsTwoByteString());
|
||||
EXPECT(!two_str.IsOneByteString());
|
||||
EXPECT(!two_str.IsFourByteString());
|
||||
EXPECT_EQ(kWideCharsLen, two_str.Length());
|
||||
EXPECT_EQ('H', two_str.CharAt(0));
|
||||
EXPECT_EQ(256, two_str.CharAt(5));
|
||||
@@ -564,40 +562,38 @@ TEST_CASE(String) {
|
||||
const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' };
|
||||
const String& four_str = String::Handle(String::New(four_chars, 7));
|
||||
EXPECT_EQ(four_str.Hash(), four_str.Hash());
|
||||
EXPECT(!four_str.IsTwoByteString());
|
||||
EXPECT(four_str.IsTwoByteString());
|
||||
EXPECT(!four_str.IsOneByteString());
|
||||
EXPECT(four_str.IsFourByteString());
|
||||
EXPECT_EQ(7, four_str.Length());
|
||||
EXPECT_EQ(8, four_str.Length());
|
||||
EXPECT_EQ('C', four_str.CharAt(0));
|
||||
EXPECT_EQ(0xFF, four_str.CharAt(1));
|
||||
EXPECT_EQ('h', four_str.CharAt(2));
|
||||
EXPECT_EQ(0xFFFF, four_str.CharAt(3));
|
||||
EXPECT_EQ('a', four_str.CharAt(4));
|
||||
EXPECT_EQ(0x10FFFF, four_str.CharAt(5));
|
||||
EXPECT_EQ('r', four_str.CharAt(6));
|
||||
EXPECT_EQ(0xDBFF, four_str.CharAt(5));
|
||||
EXPECT_EQ(0xDFFF, four_str.CharAt(6));
|
||||
EXPECT_EQ('r', four_str.CharAt(7));
|
||||
|
||||
// Create a 1-byte string from an array of 2-byte elements.
|
||||
{
|
||||
const uint16_t char16[] = { 0x00, 0x7F, 0xFF };
|
||||
const uint16_t char16[] = { 0x00, 0x1F, 0x7F };
|
||||
const String& str8 = String::Handle(String::New(char16, 3));
|
||||
EXPECT(str8.IsOneByteString());
|
||||
EXPECT(!str8.IsTwoByteString());
|
||||
EXPECT(!str8.IsFourByteString());
|
||||
EXPECT_EQ(0x00, str8.CharAt(0));
|
||||
EXPECT_EQ(0x7F, str8.CharAt(1));
|
||||
EXPECT_EQ(0xFF, str8.CharAt(2));
|
||||
EXPECT_EQ(0x1F, str8.CharAt(1));
|
||||
EXPECT_EQ(0x7F, str8.CharAt(2));
|
||||
}
|
||||
|
||||
// Create a 1-byte string from an array of 4-byte elements.
|
||||
{
|
||||
const uint32_t char32[] = { 0x00, 0x7F, 0xFF };
|
||||
const uint32_t char32[] = { 0x00, 0x1F, 0x7F };
|
||||
const String& str8 = String::Handle(String::New(char32, 3));
|
||||
EXPECT(str8.IsOneByteString());
|
||||
EXPECT(!str8.IsTwoByteString());
|
||||
EXPECT(!str8.IsFourByteString());
|
||||
EXPECT_EQ(0x00, str8.CharAt(0));
|
||||
EXPECT_EQ(0x7F, str8.CharAt(1));
|
||||
EXPECT_EQ(0xFF, str8.CharAt(2));
|
||||
EXPECT_EQ(0x1F, str8.CharAt(1));
|
||||
EXPECT_EQ(0x7F, str8.CharAt(2));
|
||||
}
|
||||
|
||||
// Create a 2-byte string from an array of 4-byte elements.
|
||||
@@ -606,7 +602,6 @@ TEST_CASE(String) {
|
||||
const String& str16 = String::Handle(String::New(char32, 3));
|
||||
EXPECT(!str16.IsOneByteString());
|
||||
EXPECT(str16.IsTwoByteString());
|
||||
EXPECT(!str16.IsFourByteString());
|
||||
EXPECT_EQ(0x0000, str16.CharAt(0));
|
||||
EXPECT_EQ(0x7FFF, str16.CharAt(1));
|
||||
EXPECT_EQ(0xFFFF, str16.CharAt(2));
|
||||
@@ -622,7 +617,6 @@ TEST_CASE(StringFormat) {
|
||||
EXPECT(str.IsString());
|
||||
EXPECT(str.IsOneByteString());
|
||||
EXPECT(!str.IsTwoByteString());
|
||||
EXPECT(!str.IsFourByteString());
|
||||
EXPECT(!str.IsNumber());
|
||||
EXPECT(str.Equals(hello_str));
|
||||
}
|
||||
@@ -943,7 +937,7 @@ TEST_CASE(StringConcat) {
|
||||
EXPECT(str6.Equals(two_one_two, two_one_two_len));
|
||||
}
|
||||
|
||||
// Concatenated emtpy and non-empty 4-byte strings.
|
||||
// Concatenated emtpy and non-empty strings built from 4-byte elements.
|
||||
{
|
||||
const String& str1 = String::Handle(String::New(""));
|
||||
EXPECT(str1.IsOneByteString());
|
||||
@@ -951,19 +945,20 @@ TEST_CASE(StringConcat) {
|
||||
|
||||
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t four_len = sizeof(four) / sizeof(four[0]);
|
||||
intptr_t expected_len = (four_len * 2);
|
||||
const String& str2 = String::Handle(String::New(four, four_len));
|
||||
EXPECT(str2.IsFourByteString());
|
||||
EXPECT_EQ(4, str2.Length());
|
||||
EXPECT(str2.IsTwoByteString());
|
||||
EXPECT_EQ(expected_len, str2.Length());
|
||||
|
||||
// Concat
|
||||
|
||||
const String& str3 = String::Handle(String::Concat(str1, str2));
|
||||
EXPECT_EQ(four_len, str3.Length());
|
||||
EXPECT_EQ(expected_len, str3.Length());
|
||||
EXPECT(str3.Equals(str2));
|
||||
|
||||
const String& str4 = String::Handle(String::Concat(str2, str1));
|
||||
EXPECT(str4.IsFourByteString());
|
||||
EXPECT_EQ(four_len, str4.Length());
|
||||
EXPECT(str4.IsTwoByteString());
|
||||
EXPECT_EQ(expected_len, str4.Length());
|
||||
EXPECT(str4.Equals(str2));
|
||||
|
||||
// ConcatAll
|
||||
@@ -973,8 +968,8 @@ TEST_CASE(StringConcat) {
|
||||
array1.SetAt(0, str1);
|
||||
array1.SetAt(1, str2);
|
||||
const String& str5 = String::Handle(String::ConcatAll(array1));
|
||||
EXPECT(str5.IsFourByteString());
|
||||
EXPECT_EQ(four_len, str5.Length());
|
||||
EXPECT(str5.IsTwoByteString());
|
||||
EXPECT_EQ(expected_len, str5.Length());
|
||||
EXPECT(str5.Equals(str2));
|
||||
|
||||
const Array& array2 = Array::Handle(Array::New(2));
|
||||
@@ -982,8 +977,8 @@ TEST_CASE(StringConcat) {
|
||||
array2.SetAt(0, str1);
|
||||
array2.SetAt(1, str2);
|
||||
const String& str6 = String::Handle(String::ConcatAll(array2));
|
||||
EXPECT(str6.IsFourByteString());
|
||||
EXPECT_EQ(four_len, str6.Length());
|
||||
EXPECT(str6.IsTwoByteString());
|
||||
EXPECT_EQ(expected_len, str6.Length());
|
||||
EXPECT(str6.Equals(str2));
|
||||
|
||||
const Array& array3 = Array::Handle(Array::New(3));
|
||||
@@ -992,45 +987,51 @@ TEST_CASE(StringConcat) {
|
||||
array3.SetAt(1, str1);
|
||||
array3.SetAt(2, str2);
|
||||
const String& str7 = String::Handle(String::ConcatAll(array3));
|
||||
EXPECT(str7.IsFourByteString());
|
||||
EXPECT(str7.IsTwoByteString());
|
||||
uint32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
|
||||
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]);
|
||||
EXPECT_EQ(fourfour_len, str7.Length());
|
||||
EXPECT(str7.Equals(fourfour, fourfour_len));
|
||||
EXPECT_EQ((fourfour_len * 2), str7.Length());
|
||||
const String& fourfour_str =
|
||||
String::Handle(String::New(fourfour, fourfour_len));
|
||||
EXPECT(str7.Equals(fourfour_str));
|
||||
}
|
||||
|
||||
// Concatenate non-empty 4-byte strings.
|
||||
// Concatenate non-empty strings built from 4-byte elements.
|
||||
{
|
||||
const uint32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF };
|
||||
intptr_t one_len = sizeof(one) / sizeof(one[0]);
|
||||
const String& onestr = String::Handle(String::New(one, one_len));
|
||||
EXPECT(onestr.IsFourByteString());
|
||||
EXPECT_EQ(one_len, onestr.Length());
|
||||
EXPECT(onestr.IsTwoByteString());
|
||||
EXPECT_EQ((one_len *2), onestr.Length());
|
||||
|
||||
const uint32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 };
|
||||
intptr_t two_len = sizeof(two) / sizeof(two[0]);
|
||||
const String& twostr = String::Handle(String::New(two, two_len));
|
||||
EXPECT(twostr.IsFourByteString());
|
||||
EXPECT_EQ(two_len, twostr.Length());
|
||||
EXPECT(twostr.IsTwoByteString());
|
||||
EXPECT_EQ((two_len * 2), twostr.Length());
|
||||
|
||||
// Concat
|
||||
|
||||
const String& str1 = String::Handle(String::Concat(onestr, twostr));
|
||||
EXPECT(str1.IsFourByteString());
|
||||
EXPECT(str1.IsTwoByteString());
|
||||
const uint32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF,
|
||||
0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 };
|
||||
intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]);
|
||||
EXPECT_EQ(one_two_len, str1.Length());
|
||||
EXPECT(str1.Equals(one_two, one_two_len));
|
||||
EXPECT_EQ((one_two_len * 2), str1.Length());
|
||||
const String& one_two_str =
|
||||
String::Handle(String::New(one_two, one_two_len));
|
||||
EXPECT(str1.Equals(one_two_str));
|
||||
|
||||
const String& str2 = String::Handle(String::Concat(twostr, onestr));
|
||||
EXPECT(str2.IsFourByteString());
|
||||
EXPECT(str2.IsTwoByteString());
|
||||
const uint32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9,
|
||||
0x105D0, 0x105D9, 0x105D9, 0x105DF };
|
||||
intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]);
|
||||
EXPECT_EQ(two_one_len, str2.Length());
|
||||
EXPECT(str2.Equals(two_one, two_one_len));
|
||||
EXPECT_EQ((two_one_len * 2), str2.Length());
|
||||
const String& two_one_str =
|
||||
String::Handle(String::New(two_one, two_one_len));
|
||||
EXPECT(str2.Equals(two_one_str));
|
||||
|
||||
// ConcatAll
|
||||
|
||||
@@ -1039,18 +1040,18 @@ TEST_CASE(StringConcat) {
|
||||
array1.SetAt(0, onestr);
|
||||
array1.SetAt(1, twostr);
|
||||
const String& str3 = String::Handle(String::ConcatAll(array1));
|
||||
EXPECT(str3.IsFourByteString());
|
||||
EXPECT_EQ(one_two_len, str3.Length());
|
||||
EXPECT(str3.Equals(one_two, one_two_len));
|
||||
EXPECT(str3.IsTwoByteString());
|
||||
EXPECT_EQ((one_two_len * 2), str3.Length());
|
||||
EXPECT(str3.Equals(one_two_str));
|
||||
|
||||
const Array& array2 = Array::Handle(Array::New(2));
|
||||
EXPECT_EQ(2, array2.Length());
|
||||
array2.SetAt(0, twostr);
|
||||
array2.SetAt(1, onestr);
|
||||
const String& str4 = String::Handle(String::ConcatAll(array2));
|
||||
EXPECT(str4.IsFourByteString());
|
||||
EXPECT_EQ(two_one_len, str4.Length());
|
||||
EXPECT(str4.Equals(two_one, two_one_len));
|
||||
EXPECT(str4.IsTwoByteString());
|
||||
EXPECT_EQ((two_one_len * 2), str4.Length());
|
||||
EXPECT(str4.Equals(two_one_str));
|
||||
|
||||
const Array& array3 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array3.Length());
|
||||
@@ -1058,14 +1059,16 @@ TEST_CASE(StringConcat) {
|
||||
array3.SetAt(1, twostr);
|
||||
array3.SetAt(2, onestr);
|
||||
const String& str5 = String::Handle(String::ConcatAll(array3));
|
||||
EXPECT(str5.IsFourByteString());
|
||||
EXPECT(str5.IsTwoByteString());
|
||||
const uint32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF,
|
||||
0x105E6, 0x105D5, 0x105D5, 0x105D9,
|
||||
0x105D9,
|
||||
0x105D0, 0x105D9, 0x105D9, 0x105DF };
|
||||
intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]);
|
||||
EXPECT_EQ(one_two_one_len, str5.Length());
|
||||
EXPECT(str5.Equals(one_two_one, one_two_one_len));
|
||||
EXPECT_EQ((one_two_one_len * 2), str5.Length());
|
||||
const String& one_two_one_str =
|
||||
String::Handle(String::New(one_two_one, one_two_one_len));
|
||||
EXPECT(str5.Equals(one_two_one_str));
|
||||
|
||||
const Array& array4 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array4.Length());
|
||||
@@ -1073,15 +1076,17 @@ TEST_CASE(StringConcat) {
|
||||
array4.SetAt(1, onestr);
|
||||
array4.SetAt(2, twostr);
|
||||
const String& str6 = String::Handle(String::ConcatAll(array4));
|
||||
EXPECT(str6.IsFourByteString());
|
||||
EXPECT(str6.IsTwoByteString());
|
||||
const uint32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9,
|
||||
0x105D9,
|
||||
0x105D0, 0x105D9, 0x105D9, 0x105DF,
|
||||
0x105E6, 0x105D5, 0x105D5, 0x105D9,
|
||||
0x105D9 };
|
||||
intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]);
|
||||
EXPECT_EQ(two_one_two_len, str6.Length());
|
||||
EXPECT(str6.Equals(two_one_two, two_one_two_len));
|
||||
EXPECT_EQ((two_one_two_len * 2), str6.Length());
|
||||
const String& two_one_two_str =
|
||||
String::Handle(String::New(two_one_two, two_one_two_len));
|
||||
EXPECT(str6.Equals(two_one_two_str));
|
||||
}
|
||||
|
||||
// Concatenate 1-byte strings and 2-byte strings.
|
||||
@@ -1148,192 +1153,6 @@ TEST_CASE(StringConcat) {
|
||||
intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]);
|
||||
EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len));
|
||||
}
|
||||
|
||||
// Concatenate 1-byte strings and 4-byte strings.
|
||||
{
|
||||
const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
|
||||
intptr_t one_len = sizeof(one) / sizeof(one[0]);
|
||||
const String& onestr = String::Handle(String::New(one, one_len));
|
||||
EXPECT(onestr.IsOneByteString());
|
||||
EXPECT_EQ(one_len, onestr.Length());
|
||||
EXPECT(onestr.Equals(one, one_len));
|
||||
|
||||
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t four_len = sizeof(four) / sizeof(four[0]);
|
||||
const String& fourstr = String::Handle(String::New(four, four_len));
|
||||
EXPECT(fourstr.IsFourByteString());
|
||||
EXPECT_EQ(four_len, fourstr.Length());
|
||||
EXPECT(fourstr.Equals(four, four_len));
|
||||
|
||||
// Concat
|
||||
|
||||
const String& one_four_str = String::Handle(String::Concat(onestr,
|
||||
fourstr));
|
||||
EXPECT(one_four_str.IsFourByteString());
|
||||
uint32_t one_four[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
|
||||
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t one_four_len = sizeof(one_four) / sizeof(one_four[0]);
|
||||
EXPECT_EQ(one_four_len, one_four_str.Length());
|
||||
EXPECT(one_four_str.Equals(one_four, one_four_len));
|
||||
|
||||
const String& four_one_str = String::Handle(String::Concat(fourstr,
|
||||
onestr));
|
||||
EXPECT(four_one_str.IsFourByteString());
|
||||
uint32_t four_one[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
|
||||
'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
|
||||
intptr_t four_one_len = sizeof(four_one) / sizeof(four_one[0]);
|
||||
EXPECT_EQ(four_one_len, four_one_str.Length());
|
||||
EXPECT(four_one_str.Equals(four_one, four_one_len));
|
||||
|
||||
// ConcatAll
|
||||
|
||||
const Array& array1 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array1.Length());
|
||||
array1.SetAt(0, onestr);
|
||||
array1.SetAt(1, fourstr);
|
||||
array1.SetAt(2, onestr);
|
||||
const String& one_four_one = String::Handle(String::ConcatAll(array1));
|
||||
EXPECT(one_four_one.IsFourByteString());
|
||||
EXPECT_EQ(onestr.Length()*2 + fourstr.Length(), one_four_one.Length());
|
||||
|
||||
const Array& array2 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array2.Length());
|
||||
array2.SetAt(0, fourstr);
|
||||
array2.SetAt(1, onestr);
|
||||
array2.SetAt(2, fourstr);
|
||||
const String& four_one_four = String::Handle(String::ConcatAll(array2));
|
||||
EXPECT(four_one_four.IsFourByteString());
|
||||
EXPECT_EQ(fourstr.Length()*2 + onestr.Length(), four_one_four.Length());
|
||||
}
|
||||
|
||||
// Concatenate 2-byte strings and 4-byte strings.
|
||||
{
|
||||
uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
|
||||
intptr_t two_len = sizeof(two) / sizeof(two[0]);
|
||||
const String& twostr = String::Handle(String::New(two, two_len));
|
||||
EXPECT(twostr.IsTwoByteString());
|
||||
EXPECT_EQ(two_len, twostr.Length());
|
||||
EXPECT(twostr.Equals(two, two_len));
|
||||
|
||||
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t four_len = sizeof(four) / sizeof(four[0]);
|
||||
const String& fourstr = String::Handle(String::New(four, four_len));
|
||||
EXPECT(fourstr.IsFourByteString());
|
||||
EXPECT_EQ(four_len, fourstr.Length());
|
||||
EXPECT(fourstr.Equals(four, four_len));
|
||||
|
||||
// Concat
|
||||
|
||||
const String& two_four_str = String::Handle(String::Concat(twostr,
|
||||
fourstr));
|
||||
EXPECT(two_four_str.IsFourByteString());
|
||||
uint32_t two_four[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
|
||||
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t two_four_len = sizeof(two_four) / sizeof(two_four[0]);
|
||||
EXPECT_EQ(two_four_len, two_four_str.Length());
|
||||
EXPECT(two_four_str.Equals(two_four, two_four_len));
|
||||
|
||||
const String& four_two_str = String::Handle(String::Concat(fourstr,
|
||||
twostr));
|
||||
EXPECT(four_two_str.IsFourByteString());
|
||||
uint32_t four_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
|
||||
0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
|
||||
intptr_t four_two_len = sizeof(four_two) / sizeof(four_two[0]);
|
||||
EXPECT_EQ(four_two_len, four_two_str.Length());
|
||||
EXPECT(four_two_str.Equals(four_two, four_two_len));
|
||||
|
||||
// ConcatAll
|
||||
|
||||
const Array& array1 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array1.Length());
|
||||
array1.SetAt(0, twostr);
|
||||
array1.SetAt(1, fourstr);
|
||||
array1.SetAt(2, twostr);
|
||||
const String& two_four_two_str = String::Handle(String::ConcatAll(array1));
|
||||
EXPECT(two_four_two_str.IsFourByteString());
|
||||
EXPECT_EQ(twostr.Length()*2 + fourstr.Length(), two_four_two_str.Length());
|
||||
|
||||
const Array& array2 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array2.Length());
|
||||
array2.SetAt(0, fourstr);
|
||||
array2.SetAt(1, twostr);
|
||||
array2.SetAt(2, fourstr);
|
||||
const String& four_two_four_str = String::Handle(String::ConcatAll(array2));
|
||||
EXPECT(four_two_four_str.IsFourByteString());
|
||||
EXPECT_EQ(fourstr.Length()*2 + twostr.Length(), four_two_four_str.Length());
|
||||
}
|
||||
|
||||
// Concatenate 1-byte, 2-byte and 4-byte strings.
|
||||
{
|
||||
const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
|
||||
intptr_t one_len = sizeof(one) / sizeof(one[0]);
|
||||
const String& onestr = String::Handle(String::New(one, one_len));
|
||||
EXPECT(onestr.IsOneByteString());
|
||||
EXPECT_EQ(one_len, onestr.Length());
|
||||
EXPECT(onestr.Equals(one, one_len));
|
||||
|
||||
uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
|
||||
intptr_t two_len = sizeof(two) / sizeof(two[0]);
|
||||
const String& twostr = String::Handle(String::New(two, two_len));
|
||||
EXPECT(twostr.IsTwoByteString());
|
||||
EXPECT_EQ(two_len, twostr.Length());
|
||||
EXPECT(twostr.Equals(two, two_len));
|
||||
|
||||
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t four_len = sizeof(four) / sizeof(four[0]);
|
||||
const String& fourstr = String::Handle(String::New(four, four_len));
|
||||
EXPECT(fourstr.IsFourByteString());
|
||||
EXPECT_EQ(four_len, fourstr.Length());
|
||||
EXPECT(fourstr.Equals(four, four_len));
|
||||
|
||||
// Last element is a 4-byte string.
|
||||
const Array& array1 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array1.Length());
|
||||
array1.SetAt(0, onestr);
|
||||
array1.SetAt(1, twostr);
|
||||
array1.SetAt(2, fourstr);
|
||||
const String& one_two_four_str = String::Handle(String::ConcatAll(array1));
|
||||
EXPECT(one_two_four_str.IsFourByteString());
|
||||
EXPECT_EQ(onestr.Length() + twostr.Length() + fourstr.Length(),
|
||||
one_two_four_str.Length());
|
||||
uint32_t one_two_four[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
|
||||
0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
|
||||
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
|
||||
intptr_t one_two_four_len = sizeof(one_two_four) / sizeof(one_two_four[0]);
|
||||
EXPECT(one_two_four_str.Equals(one_two_four, one_two_four_len));
|
||||
|
||||
// Middle element is a 4-byte string.
|
||||
const Array& array2 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array2.Length());
|
||||
array2.SetAt(0, onestr);
|
||||
array2.SetAt(1, fourstr);
|
||||
array2.SetAt(2, twostr);
|
||||
const String& one_four_two_str = String::Handle(String::ConcatAll(array2));
|
||||
EXPECT(one_four_two_str.IsFourByteString());
|
||||
EXPECT_EQ(onestr.Length() + fourstr.Length() + twostr.Length(),
|
||||
one_four_two_str.Length());
|
||||
uint32_t one_four_two[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
|
||||
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
|
||||
0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
|
||||
intptr_t one_four_two_len = sizeof(one_four_two) / sizeof(one_four_two[0]);
|
||||
EXPECT(one_four_two_str.Equals(one_four_two, one_four_two_len));
|
||||
|
||||
// First element is a 4-byte string.
|
||||
const Array& array3 = Array::Handle(Array::New(3));
|
||||
EXPECT_EQ(3, array3.Length());
|
||||
array3.SetAt(0, fourstr);
|
||||
array3.SetAt(1, onestr);
|
||||
array3.SetAt(2, twostr);
|
||||
const String& four_one_two_str = String::Handle(String::ConcatAll(array3));
|
||||
EXPECT(one_four_two_str.IsFourByteString());
|
||||
EXPECT_EQ(onestr.Length() + fourstr.Length() + twostr.Length(),
|
||||
one_four_two_str.Length());
|
||||
uint32_t four_one_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
|
||||
'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
|
||||
0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
|
||||
intptr_t four_one_two_len = sizeof(four_one_two) / sizeof(four_one_two[0]);
|
||||
EXPECT(four_one_two_str.Equals(four_one_two, four_one_two_len));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1344,16 +1163,18 @@ TEST_CASE(StringSubStringDifferentWidth) {
|
||||
|
||||
const String& onestr = String::Handle(String::New(onechars));
|
||||
EXPECT(!onestr.IsNull());
|
||||
EXPECT(onestr.IsOneByteString());
|
||||
EXPECT(!onestr.IsOneByteString());
|
||||
EXPECT(onestr.IsTwoByteString());
|
||||
|
||||
const String& onesub = String::Handle(String::SubString(onestr, 0));
|
||||
EXPECT(!onesub.IsNull());
|
||||
EXPECT(onestr.IsOneByteString());
|
||||
EXPECT(!onestr.IsOneByteString());
|
||||
EXPECT(onestr.IsTwoByteString());
|
||||
EXPECT_EQ(onesub.Length(), 3);
|
||||
|
||||
// Create 1- and 2-byte substrings from a 2-byte source string.
|
||||
const char* twochars =
|
||||
"\xC3\xB6\xC3\xB1\xC3\xA9"
|
||||
"\x1f\x2f\x3f"
|
||||
"\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93";
|
||||
|
||||
const String& twostr = String::Handle(String::New(twochars));
|
||||
@@ -1370,15 +1191,15 @@ TEST_CASE(StringSubStringDifferentWidth) {
|
||||
EXPECT(twosub2.IsTwoByteString());
|
||||
EXPECT_EQ(twosub2.Length(), 3);
|
||||
|
||||
// Create 1-, 2-, and 4-byte substrings from a 4-byte source string.
|
||||
// Create substrings from a string built using 1-, 2- and 4-byte elements.
|
||||
const char* fourchars =
|
||||
"\xC3\xB6\xC3\xB1\xC3\xA9"
|
||||
"\x1f\x2f\x3f"
|
||||
"\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"
|
||||
"\xF0\x9D\x96\xBF\xF0\x9D\x97\x88\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B";
|
||||
|
||||
const String& fourstr = String::Handle(String::New(fourchars));
|
||||
EXPECT(!fourstr.IsNull());
|
||||
EXPECT(fourstr.IsFourByteString());
|
||||
EXPECT(fourstr.IsTwoByteString());
|
||||
|
||||
const String& foursub1 = String::Handle(String::SubString(fourstr, 0, 3));
|
||||
EXPECT(!foursub1.IsNull());
|
||||
@@ -1391,9 +1212,9 @@ TEST_CASE(StringSubStringDifferentWidth) {
|
||||
EXPECT_EQ(foursub2.Length(), 3);
|
||||
|
||||
const String& foursub4 = String::Handle(String::SubString(fourstr, 6));
|
||||
EXPECT_EQ(foursub4.Length(), 4);
|
||||
EXPECT_EQ(foursub4.Length(), 8);
|
||||
EXPECT(!foursub4.IsNull());
|
||||
EXPECT(foursub4.IsFourByteString());
|
||||
EXPECT(foursub4.IsTwoByteString());
|
||||
}
|
||||
|
||||
|
||||
@@ -1440,7 +1261,7 @@ TEST_CASE(StringFromUtf8Literal) {
|
||||
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
|
||||
};
|
||||
const String& str = String::Handle(String::New(src));
|
||||
EXPECT(str.IsOneByteString());
|
||||
EXPECT(str.IsTwoByteString());
|
||||
intptr_t expected_length = sizeof(expected);
|
||||
EXPECT_EQ(expected_length, str.Length());
|
||||
for (int i = 0; i < str.Length(); ++i) {
|
||||
@@ -1466,7 +1287,7 @@ TEST_CASE(StringFromUtf8Literal) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create a 2-byte string from UTF-8 encoded 1- and 2-byte
|
||||
// Create a BMP 2-byte string from UTF-8 encoded 1- and 2-byte
|
||||
// characters.
|
||||
{
|
||||
const char* src =
|
||||
@@ -1491,22 +1312,23 @@ TEST_CASE(StringFromUtf8Literal) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create a 4-byte string from a UTF-8 string literal.
|
||||
// Create a SMP 2-byte string from a UTF-8 string literal.
|
||||
{
|
||||
const char* src =
|
||||
"\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1"
|
||||
"\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3";
|
||||
const intptr_t expected[] = { 0x1D460, 0x1D461, 0x1D462, 0x1D463 };
|
||||
const intptr_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61,
|
||||
0xd835, 0xdc62, 0xd835, 0xdc63 };
|
||||
const String& str = String::Handle(String::New(src));
|
||||
EXPECT(str.IsFourByteString());
|
||||
intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
||||
EXPECT(str.IsTwoByteString());
|
||||
intptr_t expected_size = (sizeof(expected) / sizeof(expected[0]));
|
||||
EXPECT_EQ(expected_size, str.Length());
|
||||
for (int i = 0; i < str.Length(); ++i) {
|
||||
EXPECT_EQ(expected[i], str.CharAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Create a 4-byte string from UTF-8 encoded 2- and 4-byte
|
||||
// Create a 2-byte string from UTF-8 encoded 2- and 4-byte
|
||||
// characters.
|
||||
{
|
||||
const char* src =
|
||||
@@ -1519,10 +1341,11 @@ TEST_CASE(StringFromUtf8Literal) {
|
||||
"\xF0\x9E\x80\x80\xF0\x9F\x80\x80";
|
||||
const intptr_t expected[] = {
|
||||
0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000,
|
||||
0xD000, 0xE000, 0xF000, 0x1A000, 0x1B000, 0x1D000, 0x1E000, 0x1F000
|
||||
0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00,
|
||||
0xD838, 0xDC00, 0xD83c, 0xDC00,
|
||||
};
|
||||
const String& str = String::Handle(String::New(src));
|
||||
EXPECT(str.IsFourByteString());
|
||||
EXPECT(str.IsTwoByteString());
|
||||
intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
||||
EXPECT_EQ(expected_size, str.Length());
|
||||
for (int i = 0; i < str.Length(); ++i) {
|
||||
@@ -1530,7 +1353,7 @@ TEST_CASE(StringFromUtf8Literal) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create a 4-byte string from UTF-8 encoded 1-, 2- and 4-byte
|
||||
// Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte
|
||||
// characters.
|
||||
{
|
||||
const char* src =
|
||||
@@ -1548,10 +1371,11 @@ TEST_CASE(StringFromUtf8Literal) {
|
||||
0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0,
|
||||
0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00,
|
||||
0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000,
|
||||
0x1A000, 0x1B000, 0x1D000, 0x1E000, 0x1F000
|
||||
0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00,
|
||||
0xD83c, 0xDC00,
|
||||
};
|
||||
const String& str = String::Handle(String::New(src));
|
||||
EXPECT(str.IsFourByteString());
|
||||
EXPECT(str.IsTwoByteString());
|
||||
intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
|
||||
EXPECT_EQ(expected_size, str.Length());
|
||||
for (int i = 0; i < str.Length(); ++i) {
|
||||
@@ -1626,42 +1450,6 @@ TEST_CASE(ExternalTwoByteString) {
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(ExternalFourByteString) {
|
||||
uint32_t characters[] = { 0x1D5BF, 0x1D5C8, 0x1D5CE, 0x1D5CB };
|
||||
intptr_t len = ARRAY_SIZE(characters);
|
||||
|
||||
const String& str =
|
||||
String::Handle(
|
||||
ExternalFourByteString::New(characters, len, NULL, NULL, Heap::kNew));
|
||||
EXPECT(!str.IsFourByteString());
|
||||
EXPECT(str.IsExternalFourByteString());
|
||||
EXPECT_EQ(str.Length(), len);
|
||||
EXPECT(str.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
|
||||
"\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
|
||||
|
||||
const String& copy = String::Handle(String::SubString(str, 0, len));
|
||||
EXPECT(!copy.IsExternalFourByteString());
|
||||
EXPECT(copy.IsFourByteString());
|
||||
EXPECT_EQ(len, copy.Length());
|
||||
EXPECT(copy.Equals(str));
|
||||
|
||||
const String& concat = String::Handle(String::Concat(str, str));
|
||||
EXPECT(!concat.IsExternalFourByteString());
|
||||
EXPECT(concat.IsFourByteString());
|
||||
EXPECT_EQ(len * 2, concat.Length());
|
||||
EXPECT(concat.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
|
||||
"\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"
|
||||
"\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
|
||||
"\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
|
||||
|
||||
const String& substr = String::Handle(String::SubString(str, 1, 2));
|
||||
EXPECT(!substr.IsExternalFourByteString());
|
||||
EXPECT(substr.IsFourByteString());
|
||||
EXPECT_EQ(2, substr.Length());
|
||||
EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(Symbol) {
|
||||
const String& one = String::Handle(Symbols::New("Eins"));
|
||||
EXPECT(one.IsSymbol());
|
||||
@@ -2846,7 +2634,7 @@ TEST_CASE(StackTraceFormat) {
|
||||
"}\n";
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
||||
EXPECT_VALID(lib);
|
||||
Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
|
||||
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
||||
EXPECT_ERROR(
|
||||
result,
|
||||
"Unhandled exception:\n"
|
||||
|
||||
@@ -101,13 +101,6 @@ intptr_t RawObject::SizeFromClass() const {
|
||||
instance_size = TwoByteString::InstanceSize(string_length);
|
||||
break;
|
||||
}
|
||||
case kFourByteStringCid: {
|
||||
const RawFourByteString* raw_string =
|
||||
reinterpret_cast<const RawFourByteString*>(this);
|
||||
intptr_t string_length = Smi::Value(raw_string->ptr()->length_);
|
||||
instance_size = FourByteString::InstanceSize(string_length);
|
||||
break;
|
||||
}
|
||||
case kArrayCid:
|
||||
case kImmutableArrayCid: {
|
||||
const RawArray* raw_array = reinterpret_cast<const RawArray*>(this);
|
||||
@@ -688,14 +681,6 @@ intptr_t RawTwoByteString::VisitTwoByteStringPointers(
|
||||
}
|
||||
|
||||
|
||||
intptr_t RawFourByteString::VisitFourByteStringPointers(
|
||||
RawFourByteString* raw_obj, ObjectPointerVisitor* visitor) {
|
||||
intptr_t length = Smi::Value(raw_obj->ptr()->length_);
|
||||
visitor->VisitPointers(raw_obj->from(), raw_obj->to());
|
||||
return FourByteString::InstanceSize(length);
|
||||
}
|
||||
|
||||
|
||||
intptr_t RawExternalOneByteString::VisitExternalOneByteStringPointers(
|
||||
RawExternalOneByteString* raw_obj, ObjectPointerVisitor* visitor) {
|
||||
// Make sure that we got here with the tagged pointer as this.
|
||||
@@ -714,15 +699,6 @@ intptr_t RawExternalTwoByteString::VisitExternalTwoByteStringPointers(
|
||||
}
|
||||
|
||||
|
||||
intptr_t RawExternalFourByteString::VisitExternalFourByteStringPointers(
|
||||
RawExternalFourByteString* raw_obj, ObjectPointerVisitor* visitor) {
|
||||
// Make sure that we got here with the tagged pointer as this.
|
||||
ASSERT(raw_obj->IsHeapObject());
|
||||
visitor->VisitPointers(raw_obj->from(), raw_obj->to());
|
||||
return ExternalFourByteString::InstanceSize();
|
||||
}
|
||||
|
||||
|
||||
intptr_t RawBool::VisitBoolPointers(RawBool* raw_obj,
|
||||
ObjectPointerVisitor* visitor) {
|
||||
// Make sure that we got here with the tagged pointer as this.
|
||||
|
||||
+23
-42
@@ -59,10 +59,8 @@ namespace dart {
|
||||
V(String) \
|
||||
V(OneByteString) \
|
||||
V(TwoByteString) \
|
||||
V(FourByteString) \
|
||||
V(ExternalOneByteString) \
|
||||
V(ExternalTwoByteString) \
|
||||
V(ExternalFourByteString) \
|
||||
V(Bool) \
|
||||
V(Array) \
|
||||
V(ImmutableArray) \
|
||||
@@ -1125,16 +1123,6 @@ class RawTwoByteString : public RawString {
|
||||
};
|
||||
|
||||
|
||||
class RawFourByteString : public RawString {
|
||||
RAW_HEAP_OBJECT_IMPLEMENTATION(FourByteString);
|
||||
|
||||
// Variable length data follows here.
|
||||
uint32_t data_[0];
|
||||
|
||||
friend class SnapshotReader;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
class ExternalStringData {
|
||||
public:
|
||||
@@ -1175,14 +1163,6 @@ class RawExternalTwoByteString : public RawString {
|
||||
};
|
||||
|
||||
|
||||
class RawExternalFourByteString : public RawString {
|
||||
RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalFourByteString);
|
||||
|
||||
ExternalStringData<uint32_t>* external_data_;
|
||||
friend class Api;
|
||||
};
|
||||
|
||||
|
||||
class RawBool : public RawInstance {
|
||||
RAW_HEAP_OBJECT_IMPLEMENTATION(Bool);
|
||||
|
||||
@@ -1473,6 +1453,7 @@ class RawJSRegExp : public RawInstance {
|
||||
uint8_t data_[0];
|
||||
};
|
||||
|
||||
|
||||
class RawWeakProperty : public RawInstance {
|
||||
RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty);
|
||||
|
||||
@@ -1491,6 +1472,7 @@ class RawWeakProperty : public RawInstance {
|
||||
friend class ScavengerVisitor;
|
||||
};
|
||||
|
||||
|
||||
// Class Id predicates.
|
||||
|
||||
inline bool RawObject::IsErrorClassId(intptr_t index) {
|
||||
@@ -1503,6 +1485,7 @@ inline bool RawObject::IsErrorClassId(intptr_t index) {
|
||||
return (index >= kErrorCid && index < kInstanceCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsNumberClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new Number types are added.
|
||||
ASSERT(kIntegerCid == kNumberCid + 1 &&
|
||||
@@ -1514,6 +1497,7 @@ inline bool RawObject::IsNumberClassId(intptr_t index) {
|
||||
return (index >= kNumberCid && index < kStringCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsIntegerClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new Integer types are added.
|
||||
ASSERT(kSmiCid == kIntegerCid + 1 &&
|
||||
@@ -1523,59 +1507,55 @@ inline bool RawObject::IsIntegerClassId(intptr_t index) {
|
||||
return (index >= kIntegerCid && index < kDoubleCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsStringClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new StringCid types are added.
|
||||
ASSERT(kOneByteStringCid == kStringCid + 1 &&
|
||||
kTwoByteStringCid == kStringCid + 2 &&
|
||||
kFourByteStringCid == kStringCid + 3 &&
|
||||
kExternalOneByteStringCid == kStringCid + 4 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 5 &&
|
||||
kExternalFourByteStringCid == kStringCid + 6 &&
|
||||
kBoolCid == kStringCid + 7);
|
||||
kExternalOneByteStringCid == kStringCid + 3 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 4 &&
|
||||
kBoolCid == kStringCid + 5);
|
||||
return (index >= kStringCid && index < kBoolCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsOneByteStringClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new StringCid types are added.
|
||||
ASSERT(kOneByteStringCid == kStringCid + 1 &&
|
||||
kTwoByteStringCid == kStringCid + 2 &&
|
||||
kFourByteStringCid == kStringCid + 3 &&
|
||||
kExternalOneByteStringCid == kStringCid + 4 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 5 &&
|
||||
kExternalFourByteStringCid == kStringCid + 6 &&
|
||||
kBoolCid == kStringCid + 7);
|
||||
kExternalOneByteStringCid == kStringCid + 3 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 4 &&
|
||||
kBoolCid == kStringCid + 5);
|
||||
return (index == kOneByteStringCid || index == kExternalOneByteStringCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsTwoByteStringClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new StringCid types are added.
|
||||
ASSERT(kOneByteStringCid == kStringCid + 1 &&
|
||||
kTwoByteStringCid == kStringCid + 2 &&
|
||||
kFourByteStringCid == kStringCid + 3 &&
|
||||
kExternalOneByteStringCid == kStringCid + 4 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 5 &&
|
||||
kExternalFourByteStringCid == kStringCid + 6 &&
|
||||
kBoolCid == kStringCid + 7);
|
||||
kExternalOneByteStringCid == kStringCid + 3 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 4 &&
|
||||
kBoolCid == kStringCid + 5);
|
||||
return (index == kOneByteStringCid ||
|
||||
index == kTwoByteStringCid ||
|
||||
index == kExternalOneByteStringCid ||
|
||||
index == kExternalTwoByteStringCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsExternalStringClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new StringCid types are added.
|
||||
ASSERT(kOneByteStringCid == kStringCid + 1 &&
|
||||
kTwoByteStringCid == kStringCid + 2 &&
|
||||
kFourByteStringCid == kStringCid + 3 &&
|
||||
kExternalOneByteStringCid == kStringCid + 4 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 5 &&
|
||||
kExternalFourByteStringCid == kStringCid + 6 &&
|
||||
kBoolCid == kStringCid + 7);
|
||||
kExternalOneByteStringCid == kStringCid + 3 &&
|
||||
kExternalTwoByteStringCid == kStringCid + 4 &&
|
||||
kBoolCid == kStringCid + 5);
|
||||
return (index == kExternalOneByteStringCid ||
|
||||
index == kExternalTwoByteStringCid ||
|
||||
index == kExternalFourByteStringCid);
|
||||
index == kExternalTwoByteStringCid);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsBuiltinListClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new builtin List types are added.
|
||||
ASSERT(kImmutableArrayCid == kArrayCid + 1 &&
|
||||
@@ -1585,6 +1565,7 @@ inline bool RawObject::IsBuiltinListClassId(intptr_t index) {
|
||||
IsByteArrayClassId(index);
|
||||
}
|
||||
|
||||
|
||||
inline bool RawObject::IsByteArrayClassId(intptr_t index) {
|
||||
// Make sure this function is updated when new ByteArray types are added.
|
||||
ASSERT(kInt8ArrayCid == kByteArrayCid + 1 &&
|
||||
|
||||
@@ -1715,37 +1715,6 @@ RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader,
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader,
|
||||
intptr_t object_id,
|
||||
intptr_t tags,
|
||||
Snapshot::Kind kind) {
|
||||
// Read the length so that we can determine instance size to allocate.
|
||||
ASSERT(reader != NULL);
|
||||
intptr_t len = reader->ReadSmiValue();
|
||||
intptr_t hash = reader->ReadSmiValue();
|
||||
FourByteString& str_obj = FourByteString::ZoneHandle(reader->isolate(),
|
||||
FourByteString::null());
|
||||
|
||||
if (kind == Snapshot::kFull) {
|
||||
RawFourByteString* obj = reader->NewFourByteString(len);
|
||||
str_obj = obj;
|
||||
str_obj.set_tags(tags);
|
||||
obj->ptr()->hash_ = Smi::New(hash);
|
||||
uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL;
|
||||
for (intptr_t i = 0; i < len; i++) {
|
||||
ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions.
|
||||
*raw_ptr = reader->Read<uint32_t>();
|
||||
raw_ptr += 1;
|
||||
}
|
||||
ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash);
|
||||
} else {
|
||||
ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags, kind);
|
||||
}
|
||||
reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
|
||||
return str_obj.raw();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
static void StringWriteTo(SnapshotWriter* writer,
|
||||
intptr_t object_id,
|
||||
@@ -1812,20 +1781,6 @@ void RawTwoByteString::WriteTo(SnapshotWriter* writer,
|
||||
}
|
||||
|
||||
|
||||
void RawFourByteString::WriteTo(SnapshotWriter* writer,
|
||||
intptr_t object_id,
|
||||
Snapshot::Kind kind) {
|
||||
StringWriteTo(writer,
|
||||
object_id,
|
||||
kind,
|
||||
kFourByteStringCid,
|
||||
writer->GetObjectTags(this),
|
||||
ptr()->length_,
|
||||
ptr()->hash_,
|
||||
ptr()->data_);
|
||||
}
|
||||
|
||||
|
||||
RawExternalOneByteString* ExternalOneByteString::ReadFrom(
|
||||
SnapshotReader* reader,
|
||||
intptr_t object_id,
|
||||
@@ -1846,16 +1801,6 @@ RawExternalTwoByteString* ExternalTwoByteString::ReadFrom(
|
||||
}
|
||||
|
||||
|
||||
RawExternalFourByteString* ExternalFourByteString::ReadFrom(
|
||||
SnapshotReader* reader,
|
||||
intptr_t object_id,
|
||||
intptr_t tags,
|
||||
Snapshot::Kind kind) {
|
||||
UNREACHABLE();
|
||||
return ExternalFourByteString::null();
|
||||
}
|
||||
|
||||
|
||||
void RawExternalOneByteString::WriteTo(SnapshotWriter* writer,
|
||||
intptr_t object_id,
|
||||
Snapshot::Kind kind) {
|
||||
@@ -1886,21 +1831,6 @@ void RawExternalTwoByteString::WriteTo(SnapshotWriter* writer,
|
||||
}
|
||||
|
||||
|
||||
void RawExternalFourByteString::WriteTo(SnapshotWriter* writer,
|
||||
intptr_t object_id,
|
||||
Snapshot::Kind kind) {
|
||||
// Serialize as a non-external four byte string.
|
||||
StringWriteTo(writer,
|
||||
object_id,
|
||||
kind,
|
||||
kFourByteStringCid,
|
||||
writer->GetObjectTags(this),
|
||||
ptr()->length_,
|
||||
ptr()->hash_,
|
||||
ptr()->external_data_->data());
|
||||
}
|
||||
|
||||
|
||||
RawBool* Bool::ReadFrom(SnapshotReader* reader,
|
||||
intptr_t object_id,
|
||||
intptr_t tags,
|
||||
|
||||
@@ -387,13 +387,6 @@ RawTwoByteString* SnapshotReader::NewTwoByteString(intptr_t len) {
|
||||
}
|
||||
|
||||
|
||||
RawFourByteString* SnapshotReader::NewFourByteString(intptr_t len) {
|
||||
ALLOC_NEW_OBJECT_WITH_LEN(FourByteString,
|
||||
object_store()->four_byte_string_class(),
|
||||
len);
|
||||
}
|
||||
|
||||
|
||||
RawTypeArguments* SnapshotReader::NewTypeArguments(intptr_t len) {
|
||||
ALLOC_NEW_OBJECT_WITH_LEN(TypeArguments,
|
||||
Object::type_arguments_class(),
|
||||
|
||||
@@ -36,7 +36,6 @@ class RawClass;
|
||||
class RawContext;
|
||||
class RawDouble;
|
||||
class RawField;
|
||||
class RawFourByteString;
|
||||
class RawClosureData;
|
||||
class RawRedirectionData;
|
||||
class RawFunction;
|
||||
@@ -239,7 +238,6 @@ class SnapshotReader : public BaseReader {
|
||||
RawImmutableArray* NewImmutableArray(intptr_t len);
|
||||
RawOneByteString* NewOneByteString(intptr_t len);
|
||||
RawTwoByteString* NewTwoByteString(intptr_t len);
|
||||
RawFourByteString* NewFourByteString(intptr_t len);
|
||||
RawTypeArguments* NewTypeArguments(intptr_t len);
|
||||
RawTokenStream* NewTokenStream(intptr_t len);
|
||||
RawContext* NewContext(intptr_t num_variables);
|
||||
|
||||
+16
-16
@@ -945,8 +945,8 @@ UNIT_TEST_CASE(FullSnapshot) {
|
||||
|
||||
// Invoke a function which returns an object.
|
||||
Dart_Handle cls =
|
||||
Dart_GetClass(TestCase::lib(), Dart_NewString("FieldsTest"));
|
||||
result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
|
||||
Dart_GetClass(TestCase::lib(), NewString("FieldsTest"));
|
||||
result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
Dart_ExitScope();
|
||||
}
|
||||
@@ -987,8 +987,8 @@ UNIT_TEST_CASE(FullSnapshot1) {
|
||||
writer.WriteFullSnapshot();
|
||||
|
||||
// Invoke a function which returns an object.
|
||||
Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("FieldsTest"));
|
||||
Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
|
||||
Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest"));
|
||||
Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
}
|
||||
|
||||
@@ -1004,8 +1004,8 @@ UNIT_TEST_CASE(FullSnapshot1) {
|
||||
|
||||
// Invoke a function which returns an object.
|
||||
Dart_Handle cls = Dart_GetClass(TestCase::lib(),
|
||||
Dart_NewString("FieldsTest"));
|
||||
Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
|
||||
NewString("FieldsTest"));
|
||||
Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
|
||||
if (Dart_IsError(result)) {
|
||||
// Print the error. It is probably an unhandled exception.
|
||||
fprintf(stderr, "%s\n", Dart_GetError(result));
|
||||
@@ -1085,8 +1085,8 @@ UNIT_TEST_CASE(ScriptSnapshot) {
|
||||
Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
|
||||
|
||||
// Load the library.
|
||||
Dart_Handle import_lib = Dart_LoadLibrary(Dart_NewString("dart:import-lib"),
|
||||
Dart_NewString(kLibScriptChars));
|
||||
Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart:import-lib"),
|
||||
NewString(kLibScriptChars));
|
||||
EXPECT_VALID(import_lib);
|
||||
|
||||
// Create a test library and Load up a test script in it.
|
||||
@@ -1129,8 +1129,8 @@ UNIT_TEST_CASE(ScriptSnapshot) {
|
||||
EXPECT_EQ(expected_num_libs, actual_num_libs);
|
||||
|
||||
// Invoke a function which returns an object.
|
||||
Dart_Handle cls = Dart_GetClass(result, Dart_NewString("FieldsTest"));
|
||||
result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
|
||||
Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest"));
|
||||
result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
Dart_ExitScope();
|
||||
}
|
||||
@@ -1170,7 +1170,7 @@ TEST_CASE(IntArrayMessage) {
|
||||
static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib,
|
||||
const char* dart_function) {
|
||||
Dart_Handle result;
|
||||
result = Dart_Invoke(lib, Dart_NewString(dart_function), 0, NULL);
|
||||
result = Dart_Invoke(lib, NewString(dart_function), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
|
||||
// Serialize the list into a message.
|
||||
@@ -1210,13 +1210,13 @@ UNIT_TEST_CASE(DartGeneratedMessages) {
|
||||
NULL);
|
||||
EXPECT_VALID(lib);
|
||||
Dart_Handle smi_result;
|
||||
smi_result = Dart_Invoke(lib, Dart_NewString("getSmi"), 0, NULL);
|
||||
smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL);
|
||||
EXPECT_VALID(smi_result);
|
||||
Dart_Handle bigint_result;
|
||||
bigint_result = Dart_Invoke(lib, Dart_NewString("getBigint"), 0, NULL);
|
||||
bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL);
|
||||
EXPECT_VALID(bigint_result);
|
||||
Dart_Handle string_result;
|
||||
string_result = Dart_Invoke(lib, Dart_NewString("getString"), 0, NULL);
|
||||
string_result = Dart_Invoke(lib, NewString("getString"), 0, NULL);
|
||||
EXPECT_VALID(string_result);
|
||||
EXPECT(Dart_IsString(string_result));
|
||||
|
||||
@@ -1974,9 +1974,9 @@ UNIT_TEST_CASE(PostCObject) {
|
||||
Dart_EnterScope();
|
||||
|
||||
// xxx
|
||||
Dart_Handle send_port = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
|
||||
Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL);
|
||||
EXPECT_VALID(send_port);
|
||||
Dart_Handle result = Dart_GetField(send_port, Dart_NewString("_id"));
|
||||
Dart_Handle result = Dart_GetField(send_port, NewString("_id"));
|
||||
ASSERT(!Dart_IsError(result));
|
||||
ASSERT(Dart_IsInteger(result));
|
||||
int64_t send_port_id;
|
||||
|
||||
@@ -240,8 +240,8 @@ TEST_CASE(ValidateStackFrameIteration) {
|
||||
Dart_Handle lib = TestCase::LoadTestScript(
|
||||
kScriptChars,
|
||||
reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
|
||||
Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest"));
|
||||
EXPECT_VALID(Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL));
|
||||
Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest"));
|
||||
EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL));
|
||||
}
|
||||
|
||||
|
||||
@@ -283,8 +283,8 @@ TEST_CASE(ValidateNoSuchMethodStackFrameIteration) {
|
||||
Dart_Handle lib = TestCase::LoadTestScript(
|
||||
kScriptChars,
|
||||
reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
|
||||
Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrame2Test"));
|
||||
EXPECT_VALID(Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL));
|
||||
Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrame2Test"));
|
||||
EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL));
|
||||
}
|
||||
#endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64.
|
||||
|
||||
|
||||
+11
-11
@@ -94,23 +94,23 @@ void Symbols::Add(const Array& symbol_table, const String& str) {
|
||||
|
||||
|
||||
RawString* Symbols::New(const char* str) {
|
||||
intptr_t width = 0;
|
||||
intptr_t len = Utf8::CodePointCount(str, &width);
|
||||
ASSERT(str != NULL);
|
||||
Utf8::Type type;
|
||||
intptr_t str_len = strlen(str);
|
||||
const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
|
||||
intptr_t len = Utf8::CodePointCount(utf8_array, str_len, &type);
|
||||
Zone* zone = Isolate::Current()->current_zone();
|
||||
if (len == 0) {
|
||||
return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0);
|
||||
} else if (width == 1) {
|
||||
}
|
||||
if (type == Utf8::kAscii) {
|
||||
uint8_t* characters = zone->Alloc<uint8_t>(len);
|
||||
Utf8::Decode(str, characters, len);
|
||||
return New(characters, len);
|
||||
} else if (width == 2) {
|
||||
uint16_t* characters = zone->Alloc<uint16_t>(len);
|
||||
Utf8::Decode(str, characters, len);
|
||||
Utf8::DecodeToAscii(utf8_array, str_len, characters, len);
|
||||
return New(characters, len);
|
||||
}
|
||||
ASSERT(width == 4);
|
||||
uint32_t* characters = zone->Alloc<uint32_t>(len);
|
||||
Utf8::Decode(str, characters, len);
|
||||
ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
|
||||
uint16_t* characters = zone->Alloc<uint16_t>(len);
|
||||
Utf8::DecodeToUTF16(utf8_array, str_len, characters, len);
|
||||
return New(characters, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,10 +109,8 @@ class ObjectPointerVisitor;
|
||||
V(ImmutableArray, "_ImmutableArray") \
|
||||
V(OneByteString, "_OneByteString") \
|
||||
V(TwoByteString, "_TwoByteString") \
|
||||
V(FourByteString, "_FourByteString") \
|
||||
V(ExternalOneByteString, "_ExternalOneByteString") \
|
||||
V(ExternalTwoByteString, "_ExternalTwoByteString") \
|
||||
V(ExternalFourByteString, "_ExternalFourByteString") \
|
||||
V(Stacktrace, "Stacktrace") \
|
||||
V(JSSyntaxRegExp, "JSSyntaxRegExp") \
|
||||
V(Object, "Object") \
|
||||
|
||||
+99
-49
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace dart {
|
||||
|
||||
static const uint8_t kTrailBytes[256] = {
|
||||
static const int8_t kTrailBytes[256] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
@@ -58,6 +58,18 @@ static bool IsTrailByte(uint8_t code_unit) {
|
||||
}
|
||||
|
||||
|
||||
static bool IsAsciiSequenceStart(uint8_t code_unit) {
|
||||
// Check is codepoint is <= U+007F
|
||||
return (code_unit <= Utf8::kMaxOneByteChar);
|
||||
}
|
||||
|
||||
|
||||
static bool IsSmpSequenceStart(uint8_t code_unit) {
|
||||
// Check is codepoint is >= U+10000.
|
||||
return (code_unit >= 0xF0);
|
||||
}
|
||||
|
||||
|
||||
// Returns true if the code point is a high- or low-surrogate.
|
||||
static bool IsSurrogate(uint32_t code_point) {
|
||||
return (code_point & 0xfffff800) == 0xd800;
|
||||
@@ -66,7 +78,7 @@ static bool IsSurrogate(uint32_t code_point) {
|
||||
|
||||
// Returns true if the code point value is above Plane 17.
|
||||
static bool IsOutOfRange(uint32_t code_point) {
|
||||
return code_point > 0x10FFFF;
|
||||
return (code_point > 0x10FFFF);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,47 +88,51 @@ static bool IsNonShortestForm(uint32_t code_point, size_t num_bytes) {
|
||||
}
|
||||
|
||||
|
||||
void Utf8::ConvertUTF32ToUTF16(int32_t codepoint, uint16_t* dst) {
|
||||
ASSERT(codepoint > kMaxBmpCodepoint);
|
||||
ASSERT(dst != NULL);
|
||||
dst[0] = (Utf8::kLeadOffset + (codepoint >> 10));
|
||||
dst[1] = (0xDC00 + (codepoint & 0x3FF));
|
||||
}
|
||||
|
||||
|
||||
// Returns a count of the number of UTF-8 trail bytes.
|
||||
intptr_t Utf8::CodePointCount(const char* str, intptr_t* width) {
|
||||
bool is_two_byte_string = false;
|
||||
bool is_four_byte_string = false;
|
||||
intptr_t Utf8::CodePointCount(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
Type* type) {
|
||||
intptr_t len = 0;
|
||||
for (; *str != '\0'; ++str) {
|
||||
uint8_t code_unit = *str;
|
||||
Type char_type = kAscii;
|
||||
for (intptr_t i = 0; i < array_len; i++) {
|
||||
uint8_t code_unit = utf8_array[i];
|
||||
if (!IsTrailByte(code_unit)) {
|
||||
++len;
|
||||
}
|
||||
if (code_unit > 0xC3) { // > U+00FF
|
||||
if (code_unit < 0xF0) { // < U+10000
|
||||
is_two_byte_string = true;
|
||||
} else {
|
||||
is_four_byte_string = true;
|
||||
if (!IsAsciiSequenceStart(code_unit)) { // > U+007F
|
||||
if (IsSmpSequenceStart(code_unit)) { // >= U+10000
|
||||
char_type = kSMP;
|
||||
++len;
|
||||
} else if (char_type == kAscii) {
|
||||
char_type = kBMP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_four_byte_string) {
|
||||
*width = 4;
|
||||
} else if (is_two_byte_string) {
|
||||
*width = 2;
|
||||
} else {
|
||||
*width = 1;
|
||||
}
|
||||
*type = char_type;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
// Returns true if str is a valid NUL-terminated UTF-8 string.
|
||||
bool Utf8::IsValid(const char* str) {
|
||||
bool Utf8::IsValid(const uint8_t* utf8_array, intptr_t array_len) {
|
||||
intptr_t i = 0;
|
||||
while (str[i] != '\0') {
|
||||
uint32_t ch = str[i] & 0xFF;
|
||||
while (i < array_len) {
|
||||
uint32_t ch = utf8_array[i] & 0xFF;
|
||||
intptr_t j = 1;
|
||||
if (ch >= 0x80) {
|
||||
uint8_t num_trail_bytes = kTrailBytes[ch];
|
||||
int8_t num_trail_bytes = kTrailBytes[ch];
|
||||
bool is_malformed = false;
|
||||
for (; j < num_trail_bytes; ++j) {
|
||||
if (str[i + j] != '\0') {
|
||||
uint8_t code_unit = str[i + j];
|
||||
if ((i + j) < array_len) {
|
||||
uint8_t code_unit = utf8_array[i + j];
|
||||
is_malformed |= !IsTrailByte(code_unit);
|
||||
ch = (ch << 6) + code_unit;
|
||||
} else {
|
||||
@@ -202,15 +218,17 @@ intptr_t Utf8::Encode(const String& src, char* dst, intptr_t len) {
|
||||
}
|
||||
|
||||
|
||||
intptr_t Utf8::Decode(const char* src, int32_t* dst) {
|
||||
uint32_t ch = src[0] & 0xFF;
|
||||
uint32_t i = 1;
|
||||
intptr_t Utf8::Decode(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
int32_t* dst) {
|
||||
uint32_t ch = utf8_array[0] & 0xFF;
|
||||
intptr_t i = 1;
|
||||
if (ch >= 0x80) {
|
||||
uint32_t num_trail_bytes = kTrailBytes[ch];
|
||||
int32_t num_trail_bytes = kTrailBytes[ch];
|
||||
bool is_malformed = false;
|
||||
for (; i < num_trail_bytes; ++i) {
|
||||
if (src[i] != '\0') {
|
||||
uint8_t code_unit = src[i];
|
||||
if (i < array_len) {
|
||||
uint8_t code_unit = utf8_array[i];
|
||||
is_malformed |= !IsTrailByte(code_unit);
|
||||
ch = (ch << 6) + code_unit;
|
||||
} else {
|
||||
@@ -233,38 +251,70 @@ intptr_t Utf8::Decode(const char* src, int32_t* dst) {
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
static bool DecodeImpl(const char* src, T* dst, intptr_t len) {
|
||||
bool Utf8::DecodeToAscii(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
uint8_t* dst,
|
||||
intptr_t len) {
|
||||
if (len < array_len) {
|
||||
return false; // output overflow
|
||||
}
|
||||
#ifdef DEBUG
|
||||
for (intptr_t i = 0; i < array_len; i++) {
|
||||
ASSERT(IsAsciiSequenceStart(utf8_array[i]));
|
||||
}
|
||||
#endif
|
||||
memmove(dst, utf8_array, array_len);
|
||||
return true; // success
|
||||
}
|
||||
|
||||
|
||||
bool Utf8::DecodeToUTF16(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
uint16_t* dst,
|
||||
intptr_t len) {
|
||||
intptr_t i = 0;
|
||||
intptr_t j = 0;
|
||||
intptr_t num_bytes;
|
||||
for (; src[i] != '\0' && j < len; i += num_bytes, ++j) {
|
||||
for (; (i < array_len) && (j < len); i += num_bytes, ++j) {
|
||||
int32_t ch;
|
||||
num_bytes = Utf8::Decode(&src[i], &ch);
|
||||
bool is_smp = IsSmpSequenceStart(utf8_array[i]);
|
||||
num_bytes = Utf8::Decode(&utf8_array[i], (array_len - i), &ch);
|
||||
if (ch == -1) {
|
||||
return false; // invalid input
|
||||
}
|
||||
dst[j] = ch;
|
||||
if (is_smp) {
|
||||
ConvertUTF32ToUTF16(ch, &(dst[j]));
|
||||
j = j + 1;
|
||||
} else {
|
||||
dst[j] = ch;
|
||||
}
|
||||
}
|
||||
if (src[i] != '\0' && j == len) {
|
||||
if ((i < array_len) && (j == len)) {
|
||||
return false; // output overflow
|
||||
}
|
||||
return true; // success
|
||||
}
|
||||
|
||||
|
||||
bool Utf8::Decode(const char* src, uint8_t* dst, intptr_t len) {
|
||||
return DecodeImpl(src, dst, len);
|
||||
}
|
||||
|
||||
|
||||
bool Utf8::Decode(const char* src, uint16_t* dst, intptr_t len) {
|
||||
return DecodeImpl(src, dst, len);
|
||||
}
|
||||
|
||||
|
||||
bool Utf8::Decode(const char* src, uint32_t* dst, intptr_t len) {
|
||||
return DecodeImpl(src, dst, len);
|
||||
bool Utf8::DecodeToUTF32(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
uint32_t* dst,
|
||||
intptr_t len) {
|
||||
intptr_t i = 0;
|
||||
intptr_t j = 0;
|
||||
intptr_t num_bytes;
|
||||
for (; (i < array_len) && (j < len); i += num_bytes, ++j) {
|
||||
int32_t ch;
|
||||
num_bytes = Utf8::Decode(&utf8_array[i], (array_len - i), &ch);
|
||||
if (ch == -1) {
|
||||
return false; // invalid input
|
||||
}
|
||||
dst[j] = ch;
|
||||
}
|
||||
if ((i < array_len) && (j == len)) {
|
||||
return false; // output overflow
|
||||
}
|
||||
return true; // success
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
+39
-6
@@ -14,14 +14,27 @@ class String;
|
||||
|
||||
class Utf8 : AllStatic {
|
||||
public:
|
||||
enum Type {
|
||||
kAscii = 0, // ASCII character set.
|
||||
kBMP, // Basic Multilingual Plane.
|
||||
kSMP, // Supplementary Multilingual Plane.
|
||||
};
|
||||
|
||||
static const intptr_t kMaxOneByteChar = 0x7F;
|
||||
static const intptr_t kMaxTwoByteChar = 0x7FF;
|
||||
static const intptr_t kMaxThreeByteChar = 0xFFFF;
|
||||
static const intptr_t kMaxFourByteChar = 0x10FFFF;
|
||||
static const intptr_t kMaxBmpCodepoint = 0xffff;
|
||||
static const int32_t kLeadOffset = (0xD800 - (0x10000 >> 10));
|
||||
static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00);
|
||||
|
||||
static intptr_t CodePointCount(const char* str, intptr_t* width);
|
||||
static void ConvertUTF32ToUTF16(int32_t codepoint, uint16_t* dst);
|
||||
static intptr_t CodePointCount(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
Type* type);
|
||||
|
||||
static bool IsValid(const char* src);
|
||||
// Returns true if 'utf8_array' is a valid UTF-8 string.
|
||||
static bool IsValid(const uint8_t* utf8_array, intptr_t array_len);
|
||||
|
||||
static intptr_t Length(int32_t ch);
|
||||
static intptr_t Length(const String& str);
|
||||
@@ -29,10 +42,30 @@ class Utf8 : AllStatic {
|
||||
static intptr_t Encode(int32_t ch, char* dst);
|
||||
static intptr_t Encode(const String& src, char* dst, intptr_t len);
|
||||
|
||||
static intptr_t Decode(const char*, int32_t* ch);
|
||||
static bool Decode(const char* src, uint8_t* dst, intptr_t len);
|
||||
static bool Decode(const char* src, uint16_t* dst, intptr_t len);
|
||||
static bool Decode(const char* src, uint32_t* dst, intptr_t len);
|
||||
static intptr_t Decode(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
int32_t* ch);
|
||||
|
||||
static bool DecodeToAscii(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
uint8_t* dst,
|
||||
intptr_t len);
|
||||
static bool DecodeToUTF16(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
uint16_t* dst,
|
||||
intptr_t len);
|
||||
static bool DecodeToUTF32(const uint8_t* utf8_array,
|
||||
intptr_t array_len,
|
||||
uint32_t* dst,
|
||||
intptr_t len);
|
||||
static bool DecodeCStringToUTF32(const char* str,
|
||||
uint32_t* dst,
|
||||
intptr_t len) {
|
||||
ASSERT(str != NULL);
|
||||
intptr_t array_len = strlen(str);
|
||||
const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
|
||||
return DecodeToUTF32(utf8_array, array_len, dst, len);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
+86
-85
@@ -15,7 +15,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x41, 0xF1, 0x42 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -25,7 +25,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x4D };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -35,7 +35,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x430 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -45,7 +45,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x4E8C };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -55,7 +55,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x10302 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -65,7 +65,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x4D, 0x430, 0x4E8C, 0x10302 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ TEST_CASE(Utf8Decode) {
|
||||
0x5D1, 0x5E8, 0x5DB, 0x5D4 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -93,7 +93,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x3BA, 0x1F79, 0x3C3, 0x3BC, 0x3B5 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -108,7 +108,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -119,7 +119,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -130,7 +130,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x800 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -141,7 +141,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x10000 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -152,7 +152,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x200000 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -163,7 +163,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x400000 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -176,7 +176,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x7F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -187,7 +187,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x7FF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -198,7 +198,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -209,7 +209,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x1FFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -220,7 +220,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x3FFFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -231,7 +231,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x7FFFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -244,7 +244,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xD7FF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -255,7 +255,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xE000 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -266,7 +266,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFFFD };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -277,7 +277,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x10FFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -288,7 +288,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x110000 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -303,7 +303,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -314,7 +314,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xBF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -325,7 +325,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80, 0xBF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -336,7 +336,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80, 0xBF, 0x80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -347,7 +347,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80, 0xBF, 0x80, 0xBF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -358,7 +358,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80, 0xBF, 0x80, 0xBF, 0x80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -369,7 +369,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -380,7 +380,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF, 0x80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -399,7 +399,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
for (size_t i = 0; i < strlen(src); ++i) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i], dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -422,7 +422,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
for (size_t i = 0; i < strlen(src); i += 2) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i], dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -439,7 +439,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
for (size_t i = 0; i < strlen(src); i += 2) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i], dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -454,7 +454,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
for (size_t i = 0; i < strlen(src); i += 2) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i], dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -468,7 +468,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
for (size_t i = 0; i < strlen(src); i += 2) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i], dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -482,7 +482,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
for (size_t i = 0; i < strlen(src); i += 2) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i], dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -496,7 +496,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -507,7 +507,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -518,7 +518,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -529,7 +529,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -541,7 +541,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -552,7 +552,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -563,7 +563,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -574,7 +574,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -586,7 +586,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -598,7 +598,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -615,7 +615,8 @@ TEST_CASE(Utf8Decode) {
|
||||
for (size_t i = 0; i < strlen(src); ++i) {
|
||||
for (size_t j = 1; j < (strlen(src) - i); ++j) {
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(&src[i], dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(&src[i],
|
||||
dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -630,7 +631,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFE };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -641,7 +642,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -652,7 +653,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -667,7 +668,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x2F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -678,7 +679,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x2F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -689,7 +690,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x2F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -700,7 +701,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x2F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -711,7 +712,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x2F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -724,7 +725,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x7F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -735,7 +736,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x7FF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -746,7 +747,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -757,7 +758,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x1FFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -768,7 +769,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x3FFFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -781,7 +782,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -792,7 +793,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -803,7 +804,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -814,7 +815,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -825,7 +826,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0x0 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0xFF, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -838,7 +839,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xD800 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -849,7 +850,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDB7F };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -860,7 +861,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDB80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -871,7 +872,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDBFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -882,7 +883,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDC00 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -893,7 +894,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDF80 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -904,7 +905,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -917,7 +918,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xD800, 0xDC00 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -928,7 +929,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xD800, 0xDFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -939,7 +940,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDB7F, 0xDC00 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -950,7 +951,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDB7F, 0xDFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -961,7 +962,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDB80, 0xDC00 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -972,7 +973,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDB80, 0xDFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -983,7 +984,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDBFF, 0xDC00 };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -994,7 +995,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xDBFF, 0xDFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(!is_valid);
|
||||
EXPECT(memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -1007,7 +1008,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFFFE };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
@@ -1018,7 +1019,7 @@ TEST_CASE(Utf8Decode) {
|
||||
uint32_t expected[] = { 0xFFFF };
|
||||
uint32_t dst[ARRAY_SIZE(expected)];
|
||||
memset(dst, 0, sizeof(dst));
|
||||
bool is_valid = Utf8::Decode(src, dst, ARRAY_SIZE(dst));
|
||||
bool is_valid = Utf8::DecodeCStringToUTF32(src, dst, ARRAY_SIZE(dst));
|
||||
EXPECT(is_valid);
|
||||
EXPECT(!memcmp(expected, dst, sizeof(expected)));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
|
||||
if (!Dart_IsLibrary(library)) {
|
||||
return Dart_Error("not a library");
|
||||
}
|
||||
if (!Dart_IsString8(url)) {
|
||||
if (!Dart_IsString(url)) {
|
||||
return Dart_Error("url is not a string");
|
||||
}
|
||||
const char* url_chars = NULL;
|
||||
@@ -100,8 +100,8 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
|
||||
|
||||
Dart_Handle TestCase::LoadTestScript(const char* script,
|
||||
Dart_NativeEntryResolver resolver) {
|
||||
Dart_Handle url = Dart_NewString(TestCase::url());
|
||||
Dart_Handle source = Dart_NewString(script);
|
||||
Dart_Handle url = NewString(TestCase::url());
|
||||
Dart_Handle source = NewString(script);
|
||||
Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
|
||||
EXPECT_VALID(result);
|
||||
EXPECT_VALID(result);
|
||||
@@ -114,7 +114,7 @@ Dart_Handle TestCase::LoadTestScript(const char* script,
|
||||
|
||||
|
||||
Dart_Handle TestCase::lib() {
|
||||
Dart_Handle url = Dart_NewString(TestCase::url());
|
||||
Dart_Handle url = NewString(TestCase::url());
|
||||
Dart_Handle lib = Dart_LookupLibrary(url);
|
||||
DART_CHECK_VALID(lib);
|
||||
ASSERT(Dart_IsLibrary(lib));
|
||||
|
||||
@@ -132,6 +132,11 @@
|
||||
}
|
||||
|
||||
|
||||
inline Dart_Handle NewString(const char* str) {
|
||||
return Dart_NewStringFromCString(str);
|
||||
}
|
||||
|
||||
|
||||
namespace dart {
|
||||
|
||||
// Forward declarations.
|
||||
|
||||
@@ -443,7 +443,7 @@ LibTest/core/Queue/iterator_hasNext_A01_t01: Slow, Pass
|
||||
[ $compiler == dart2js ]
|
||||
Language/11_Expressions/22_Equality_A01_t01: Fail, OK # Function declaration takes precedence over function expression.
|
||||
Language/11_Expressions/28_Postfix_Expressions_A01_t01: Fail, OK # A map literal cannot start an expression statement.
|
||||
LibTest/core/String/String_class_A02_t01: Fail, OK # compiler cancelled: Unhandled non-BMP character: U+10000
|
||||
LibTest/core/String/String_class_A02_t01: Pass, Fail, OK # issue 6418 compiler cancelled: Unhandled non-BMP character: U+10000
|
||||
LibTest/core/String/charCodeAt_A01_t01: Fail, OK # compiler cancelled: Unhandled non-BMP character: U+10000
|
||||
LibTest/core/String/charCodes_A01_t01: Fail, OK # compiler cancelled: Unhandled non-BMP character: U+10000
|
||||
|
||||
|
||||
@@ -201,6 +201,10 @@ LibTest/math/sin_A01_t01: Fail # TODO(vm-team): Please triage this failure.
|
||||
|
||||
LibTest/isolate/isolate_api/port_A01_t01: Skip # Times out.
|
||||
|
||||
LibTest/core/String/String_class_A02_t01: Fail, OK # co19 issue 284
|
||||
LibTest/core/String/charCodeAt_A01_t01: Fail, OK # co19 issue 284
|
||||
LibTest/core/String/charCodes_A01_t01: Fail, OK # co19 issue 284
|
||||
|
||||
Language/06_Functions/1_Function_Declaration_A02_t03: Fail # issue 6058
|
||||
Language/06_Functions/1_Function_Declaration_A03_t03: Fail # issue 6058
|
||||
Language/06_Functions/2_Formal_Parameters/2_Optional_Formals_A03_t01: Fail # issue 6085
|
||||
|
||||
@@ -366,24 +366,24 @@ class CharEscapeTest {
|
||||
|
||||
var v10000 = "\u{10000}";
|
||||
var v010000 = "\u{010000}";
|
||||
Expect.equals(1, v10000.length);
|
||||
Expect.equals(1, v010000.length);
|
||||
Expect.equals(2, v10000.length);
|
||||
Expect.equals(2, v010000.length);
|
||||
Expect.equals("\u{10000}", new String.fromCharCodes([0x10000]));
|
||||
Expect.equals("\u{010000}", new String.fromCharCodes([0x10000]));
|
||||
|
||||
var v1FFFF = "\u{1FFFF}";
|
||||
var v01FFFF = "\u{01FFFF}";
|
||||
Expect.equals(1, v1FFFF.length);
|
||||
Expect.equals(1, v01FFFF.length);
|
||||
Expect.equals(2, v1FFFF.length);
|
||||
Expect.equals(2, v01FFFF.length);
|
||||
Expect.equals("\u{1FFFF}", new String.fromCharCodes([0x1FFFF]));
|
||||
Expect.equals("\u{01FFFF}", new String.fromCharCodes([0x1FFFF]));
|
||||
|
||||
var v105555 = "\u{105555}";
|
||||
Expect.equals(1, v105555.length);
|
||||
Expect.equals(2, v105555.length);
|
||||
Expect.equals("\u{105555}", new String.fromCharCodes([0x105555]));
|
||||
|
||||
var v10FFFF = "\u{10FFFF}";
|
||||
Expect.equals(1, v10FFFF.length);
|
||||
Expect.equals(2, v10FFFF.length);
|
||||
Expect.equals("\u{10FFFF}", new String.fromCharCodes([0x10FFFF]));
|
||||
|
||||
var bs = "\b";
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
[ $compiler == dart2js ]
|
||||
dummy_compiler_test: Slow, Pass
|
||||
recursive_import_test: Slow, Pass
|
||||
utf8_test: Fail # issue 6418
|
||||
|
||||
[ $compiler == none && $runtime == drt ]
|
||||
dummy_compiler_test: Fail # http://dartbug.com/2264
|
||||
|
||||
Reference in New Issue
Block a user