diff --git a/runtime/bin/builtin.cc b/runtime/bin/builtin.cc index 0148a781c58..f6d297e9c84 100644 --- a/runtime/bin/builtin.cc +++ b/runtime/bin/builtin.cc @@ -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)); } } diff --git a/runtime/bin/builtin_natives.cc b/runtime/bin/builtin_natives.cc index 2a53c30c6df..be9b99b2b12 100644 --- a/runtime/bin/builtin_natives.cc +++ b/runtime/bin/builtin_natives.cc @@ -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(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); } diff --git a/runtime/bin/builtin_nolib.cc b/runtime/bin/builtin_nolib.cc index e870d7b30bd..77428c7f085 100644 --- a/runtime/bin/builtin_nolib.cc +++ b/runtime/bin/builtin_nolib.cc @@ -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); diff --git a/runtime/bin/common.cc b/runtime/bin/common.cc index 3887e6205a1..261557d7f7c 100644 --- a/runtime/bin/common.cc +++ b/runtime/bin/common.cc @@ -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 = diff --git a/runtime/bin/crypto.cc b/runtime/bin/crypto.cc index 97984a202a7..e4db17cb78b 100644 --- a/runtime/bin/crypto.cc +++ b/runtime/bin/crypto.cc @@ -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(); } - diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc index 57dfbc59d08..3740b7ed8a0 100644 --- a/runtime/bin/dartutils.cc +++ b/runtime/bin/dartutils.cc @@ -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(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(malloc(len + 1)); + uint8_t* text_buffer = reinterpret_cast(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]; diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h index e660da33c72..93f700194e8 100644 --- a/runtime/bin/dartutils.h +++ b/runtime/bin/dartutils.h @@ -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(str), + strlen(str)); + } + static void SetOriginalWorkingDirectory(); // Global state that stores the original working directory.. diff --git a/runtime/bin/dbg_message.cc b/runtime/bin/dbg_message.cc index ae7edf543d5..43fa850b295 100644 --- a/runtime/bin/dbg_message.cc +++ b/runtime/bin/dbg_message.cc @@ -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(malloc(str_len * sizeof(uint32_t))); + uint16_t* codepoints = + reinterpret_cast(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; diff --git a/runtime/bin/directory.cc b/runtime/bin/directory.cc index 9f8252741db..cc37c28da65 100644 --- a/runtime/bin/directory.cc +++ b/runtime/bin/directory.cc @@ -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(); diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc index 3bd7256e524..88d0ef428b4 100644 --- a/runtime/bin/file.cc +++ b/runtime/bin/file.cc @@ -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(); diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc index 6e2e6c71de0..b3513e48407 100644 --- a/runtime/bin/gen_snapshot.cc +++ b/runtime/bin/gen_snapshot.cc @@ -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); } diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc index 3c4a8c8c46b..7cc8f0c46e5 100644 --- a/runtime/bin/main.cc +++ b/runtime/bin/main.cc @@ -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)); } diff --git a/runtime/bin/platform.cc b/runtime/bin/platform.cc index 34c29100272..80ed2775717 100644 --- a/runtime/bin/platform.cc +++ b/runtime/bin/platform.cc @@ -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); } diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc index 394c4385126..3cde519941a 100644 --- a/runtime/bin/socket.cc +++ b/runtime/bin/socket.cc @@ -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 { diff --git a/runtime/bin/test_extension.cc b/runtime/bin/test_extension.cc index 623e151fc9e..000728fc817 100644 --- a/runtime/bin/test_extension.cc +++ b/runtime/bin/test_extension.cc @@ -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; diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h index be97d76bc6b..c2ac3716843 100755 --- a/runtime/include/dart_api.h +++ b/runtime/include/dart_api.h @@ -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 --- /** diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc index 179264b73b9..c7990b4e23a 100644 --- a/runtime/lib/mirrors.cc +++ b/runtime/lib/mirrors.cc @@ -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); diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc index 2d5bd9168d6..f10337a861a 100644 --- a/runtime/lib/string.cc +++ b/runtime/lib/string.cc @@ -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(len); + intptr_t utf16_len = array_len; + uint32_t* utf32_array = zone->Alloc(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 args; @@ -33,21 +33,20 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { if (value < 0) { GrowableArray 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); } diff --git a/runtime/vm/benchmark_test.cc b/runtime/vm/benchmark_test.cc index c23c54ecca2..ccc840caa48 100644 --- a/runtime/vm/benchmark_test.cc +++ b/runtime/vm/benchmark_test.cc @@ -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(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); diff --git a/runtime/vm/benchmark_test.h b/runtime/vm/benchmark_test.h index 91043b7835d..ce7f2d052e1 100644 --- a/runtime/vm/benchmark_test.h +++ b/runtime/vm/benchmark_test.h @@ -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); diff --git a/runtime/vm/class_finalizer.cc b/runtime/vm/class_finalizer.cc index ce87b6ba7d2..dec72beee60 100644 --- a/runtime/vm/class_finalizer.cc +++ b/runtime/vm/class_finalizer.cc @@ -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: diff --git a/runtime/vm/custom_isolate_test.cc b/runtime/vm/custom_isolate_test.cc index d767b3084cd..2090a7dbc8b 100644 --- a/runtime/vm/custom_isolate_test.cc +++ b/runtime/vm/custom_isolate_test.cc @@ -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(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; diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index f1acf1c5561..95827a0aac2 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -273,13 +273,6 @@ bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) { *peer = data->peer(); return true; } - case kExternalFourByteStringCid: { - RawExternalFourByteString* raw_string = - reinterpret_cast(raw_obj)->ptr(); - ExternalStringData* 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(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(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(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(*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(str_obj.CharAt(i)); } - memmove(result, cstring, *length); - *bytes = result; + *length = copy_len; return Api::Success(isolate); } diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index fe8c40029f5..215b21a3e8c 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -31,7 +31,7 @@ TEST_CASE(ErrorHandleBasics) { Dart_Handle instance = Dart_True(); Dart_Handle error = Api::NewError("myerror"); Dart_Handle exception = Dart_Invoke(lib, - Dart_NewString("testMain"), + NewString("testMain"), 0, NULL); @@ -66,10 +66,10 @@ TEST_CASE(ErrorHandleTypes) { const String& compile_message = String::Handle(String::New("CompileError")); const String& fatal_message = String::Handle(String::New("FatalError")); - Dart_Handle not_error = Dart_NewString("NotError"); + Dart_Handle not_error = NewString("NotError"); Dart_Handle api_error = Dart_NewApiError("Api%s", "Error"); Dart_Handle exception_error = - Dart_NewUnhandledExceptionError(Dart_NewString("ExceptionError")); + Dart_NewUnhandledExceptionError(NewString("ExceptionError")); Dart_Handle compile_error = Api::NewHandle(isolate, LanguageError::New(compile_message)); Dart_Handle fatal_error = @@ -155,12 +155,12 @@ TEST_CASE(Dart_PropagateError) { kScriptChars, &PropagateError_native_lookup); Dart_Handle result; - result = Dart_Invoke(lib, Dart_NewString("Func1"), 0, NULL); + result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); EXPECT(Dart_IsError(result)); EXPECT(!Dart_ErrorHasException(result)); EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); - result = Dart_Invoke(lib, Dart_NewString("Func2"), 0, NULL); + result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); EXPECT(Dart_IsError(result)); EXPECT(Dart_ErrorHasException(result)); EXPECT_SUBSTRING("myException", Dart_GetError(result)); @@ -181,16 +181,16 @@ TEST_CASE(Null) { EXPECT_VALID(null); EXPECT(Dart_IsNull(null)); - Dart_Handle str = Dart_NewString("test"); + Dart_Handle str = NewString("test"); EXPECT_VALID(str); EXPECT(!Dart_IsNull(str)); } TEST_CASE(IdentityEquals) { - Dart_Handle five = Dart_NewString("5"); - Dart_Handle five_again = Dart_NewString("5"); - Dart_Handle seven = Dart_NewString("7"); + Dart_Handle five = NewString("5"); + Dart_Handle five_again = NewString("5"); + Dart_Handle seven = NewString("7"); // Same objects. EXPECT(Dart_IdentityEquals(five, five)); @@ -220,9 +220,9 @@ TEST_CASE(IdentityEquals) { TEST_CASE(ObjectEquals) { bool equal = false; - Dart_Handle five = Dart_NewString("5"); - Dart_Handle five_again = Dart_NewString("5"); - Dart_Handle seven = Dart_NewString("7"); + Dart_Handle five = NewString("5"); + Dart_Handle five_again = NewString("5"); + Dart_Handle seven = NewString("7"); // Same objects. EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); @@ -241,7 +241,7 @@ TEST_CASE(ObjectEquals) { TEST_CASE(InstanceValues) { - EXPECT(Dart_IsInstance(Dart_NewString("test"))); + EXPECT(Dart_IsInstance(NewString("test"))); EXPECT(Dart_IsInstance(Dart_True())); // By convention, our Is*() functions exclude null. @@ -276,7 +276,7 @@ TEST_CASE(InstanceGetClass) { TEST_CASE(BooleanValues) { - Dart_Handle str = Dart_NewString("test"); + Dart_Handle str = NewString("test"); EXPECT(!Dart_IsBoolean(str)); bool value = false; @@ -351,22 +351,22 @@ TEST_CASE(NumberValues) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Check int case. - result = Dart_Invoke(lib, Dart_NewString("getInt"), 0, NULL); + result = Dart_Invoke(lib, NewString("getInt"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsNumber(result)); // Check double case. - result = Dart_Invoke(lib, Dart_NewString("getDouble"), 0, NULL); + result = Dart_Invoke(lib, NewString("getDouble"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsNumber(result)); // Check bool case. - result = Dart_Invoke(lib, Dart_NewString("getBool"), 0, NULL); + result = Dart_Invoke(lib, NewString("getBool"), 0, NULL); EXPECT_VALID(result); EXPECT(!Dart_IsNumber(result)); // Check null case. - result = Dart_Invoke(lib, Dart_NewString("getNull"), 0, NULL); + result = Dart_Invoke(lib, NewString("getNull"), 0, NULL); EXPECT_VALID(result); EXPECT(!Dart_IsNumber(result)); } @@ -478,7 +478,7 @@ TEST_CASE(IntegerFitsIntoUint64) { TEST_CASE(ArrayValues) { const int kArrayLength = 10; - Dart_Handle str = Dart_NewString("test"); + Dart_Handle str = NewString("test"); EXPECT(!Dart_IsList(str)); Dart_Handle val = Dart_NewList(kArrayLength); EXPECT(Dart_IsList(val)); @@ -513,76 +513,61 @@ TEST_CASE(ArrayValues) { TEST_CASE(IsString) { - uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; + uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; - Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); + Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); EXPECT_VALID(str8); EXPECT(Dart_IsString(str8)); - EXPECT(Dart_IsString8(str8)); - EXPECT(Dart_IsString16(str8)); + EXPECT(Dart_IsAsciiString(str8)); EXPECT(!Dart_IsExternalString(str8)); - Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), - NULL, NULL); + Dart_Handle ext8 = Dart_NewExternalUTF8String(data8, ARRAY_SIZE(data8), + NULL, NULL); EXPECT_VALID(ext8); EXPECT(Dart_IsString(ext8)); - EXPECT(Dart_IsString8(ext8)); - EXPECT(Dart_IsString16(ext8)); EXPECT(Dart_IsExternalString(ext8)); uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; - Dart_Handle str16 = Dart_NewString16(data16, ARRAY_SIZE(data16)); + Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); EXPECT_VALID(str16); EXPECT(Dart_IsString(str16)); - EXPECT(!Dart_IsString8(str16)); - EXPECT(Dart_IsString16(str16)); + EXPECT(!Dart_IsAsciiString(str16)); EXPECT(!Dart_IsExternalString(str16)); - Dart_Handle ext16 = Dart_NewExternalString16(data16, ARRAY_SIZE(data16), - NULL, NULL); + Dart_Handle ext16 = Dart_NewExternalUTF16String(data16, ARRAY_SIZE(data16), + NULL, NULL); EXPECT_VALID(ext16); EXPECT(Dart_IsString(ext16)); - EXPECT(!Dart_IsString8(ext16)); - EXPECT(Dart_IsString16(ext16)); EXPECT(Dart_IsExternalString(ext16)); uint32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; - Dart_Handle str32 = Dart_NewString32(data32, ARRAY_SIZE(data32)); + Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); EXPECT_VALID(str32); EXPECT(Dart_IsString(str32)); - EXPECT(!Dart_IsString8(str32)); - EXPECT(!Dart_IsString16(str32)); EXPECT(!Dart_IsExternalString(str32)); - - Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32), - NULL, NULL); - EXPECT_VALID(ext32); - EXPECT(Dart_IsString(ext32)); - EXPECT(!Dart_IsString8(ext32)); - EXPECT(!Dart_IsString16(ext32)); - EXPECT(Dart_IsExternalString(ext32)); } TEST_CASE(NewString) { const char* ascii = "string"; - Dart_Handle ascii_str = Dart_NewString(ascii); + Dart_Handle ascii_str = NewString(ascii); EXPECT_VALID(ascii_str); EXPECT(Dart_IsString(ascii_str)); const char* null = NULL; - Dart_Handle null_str = Dart_NewString(null); + Dart_Handle null_str = NewString(null); EXPECT(Dart_IsError(null_str)); - const char* utf8 = "\xE4\xBA\x8C"; // U+4E8C - Dart_Handle utf8_str = Dart_NewString(utf8); + uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. + Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); EXPECT_VALID(utf8_str); EXPECT(Dart_IsString(utf8_str)); - const char* invalid = "\xE4\xBA"; // underflow - Dart_Handle invalid_str = Dart_NewString(invalid); + uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. + Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, + ARRAY_SIZE(invalid)); EXPECT(Dart_IsError(invalid_str)); } @@ -590,13 +575,13 @@ TEST_CASE(NewString) { TEST_CASE(ExternalStringGetPeer) { Dart_Handle result; - uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; + uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; int peer_data = 123; void* peer = NULL; // Success. - Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), - &peer_data, NULL); + Dart_Handle ext8 = Dart_NewExternalUTF8String(data8, ARRAY_SIZE(data8), + &peer_data, NULL); EXPECT_VALID(ext8); result = Dart_ExternalStringGetPeer(ext8, &peer); @@ -611,7 +596,7 @@ TEST_CASE(ExternalStringGetPeer) { // String is not external. peer = NULL; - Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); + Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); EXPECT_VALID(str8); result = Dart_ExternalStringGetPeer(str8, &peer); EXPECT(Dart_IsError(result)); @@ -640,13 +625,12 @@ static void ExternalStringCallbackFinalizer(void* peer) { TEST_CASE(ExternalStringCallback) { int peer8 = 40; int peer16 = 41; - int peer32 = 42; { Dart_EnterScope(); uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; - Dart_Handle obj8 = Dart_NewExternalString8( + Dart_Handle obj8 = Dart_NewExternalUTF8String( data8, ARRAY_SIZE(data8), &peer8, @@ -657,7 +641,7 @@ TEST_CASE(ExternalStringCallback) { EXPECT_EQ(api_peer8, &peer8); uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' }; - Dart_Handle obj16 = Dart_NewExternalString16( + Dart_Handle obj16 = Dart_NewExternalUTF16String( data16, ARRAY_SIZE(data16), &peer16, @@ -667,31 +651,17 @@ TEST_CASE(ExternalStringCallback) { EXPECT_VALID(Dart_ExternalStringGetPeer(obj16, &api_peer16)); EXPECT_EQ(api_peer16, &peer16); - uint32_t data32[] = { 'h', 'e', 'l', 'l', 'o' }; - Dart_Handle obj32 = Dart_NewExternalString32( - data32, - ARRAY_SIZE(data32), - &peer32, - ExternalStringCallbackFinalizer); - EXPECT_VALID(obj32); - void* api_peer32 = NULL; - EXPECT_VALID(Dart_ExternalStringGetPeer(obj32, &api_peer32)); - EXPECT_EQ(api_peer32, &peer32); - Dart_ExitScope(); } EXPECT_EQ(40, peer8); EXPECT_EQ(41, peer16); - EXPECT_EQ(42, peer32); Isolate::Current()->heap()->CollectGarbage(Heap::kOld); EXPECT_EQ(40, peer8); EXPECT_EQ(41, peer16); - EXPECT_EQ(42, peer32); Isolate::Current()->heap()->CollectGarbage(Heap::kNew); EXPECT_EQ(80, peer8); EXPECT_EQ(82, peer16); - EXPECT_EQ(84, peer32); } @@ -710,7 +680,7 @@ TEST_CASE(ListAccess) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Invoke a function which returns an object of type List. - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); // First ensure that the returned object is an array. @@ -1327,7 +1297,7 @@ TEST_CASE(WeakPersistentHandle) { Dart_EnterScope(); // Create an object in new space. - Dart_Handle new_ref = Dart_NewString("new string"); + Dart_Handle new_ref = NewString("new string"); EXPECT_VALID(new_ref); // Create an object in old space. @@ -1425,7 +1395,7 @@ TEST_CASE(WeakPersistentHandleCallback) { int peer = 0; { Dart_EnterScope(); - Dart_Handle obj = Dart_NewString("new string"); + Dart_Handle obj = NewString("new string"); EXPECT_VALID(obj); weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, WeakPersistentHandlePeerFinalizer); @@ -1447,7 +1417,7 @@ TEST_CASE(WeakPersistentHandleNoCallback) { int peer = 0; { Dart_EnterScope(); - Dart_Handle obj = Dart_NewString("new string"); + Dart_Handle obj = NewString("new string"); EXPECT_VALID(obj); weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, WeakPersistentHandlePeerFinalizer); @@ -2364,8 +2334,8 @@ TEST_CASE(ClassBasics) { "interface MyInterface default MyDefault {\n" "}\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); - Dart_Handle interface = Dart_GetClass(lib, Dart_NewString("MyInterface")); + Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); + Dart_Handle interface = Dart_GetClass(lib, NewString("MyInterface")); // Test Dart_IsClass and Dart_IsInterface. EXPECT(Dart_IsClass(cls)); @@ -2434,9 +2404,9 @@ TEST_CASE(ClassTypedefsEtc) { "typedef void SomeHandler(String a);\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); EXPECT_VALID(lib); - Dart_Handle normal_cls = Dart_GetClass(lib, Dart_NewString("SomeClass")); + Dart_Handle normal_cls = Dart_GetClass(lib, NewString("SomeClass")); EXPECT_VALID(normal_cls); - Dart_Handle typedef_cls = Dart_GetClass(lib, Dart_NewString("SomeHandler")); + Dart_Handle typedef_cls = Dart_GetClass(lib, NewString("SomeHandler")); EXPECT_VALID(typedef_cls); EXPECT(Dart_IsClass(normal_cls)); @@ -2506,11 +2476,11 @@ TEST_CASE(ClassGetInterfaces) { "}\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls0 = Dart_GetClass(lib, Dart_NewString("MyClass0")); - Dart_Handle cls1 = Dart_GetClass(lib, Dart_NewString("MyClass1")); - Dart_Handle cls2 = Dart_GetClass(lib, Dart_NewString("MyClass2")); - Dart_Handle intf0 = Dart_GetClass(lib, Dart_NewString("MyInterface0")); - Dart_Handle intf1 = Dart_GetClass(lib, Dart_NewString("MyInterface1")); + Dart_Handle cls0 = Dart_GetClass(lib, NewString("MyClass0")); + Dart_Handle cls1 = Dart_GetClass(lib, NewString("MyClass1")); + Dart_Handle cls2 = Dart_GetClass(lib, NewString("MyClass2")); + Dart_Handle intf0 = Dart_GetClass(lib, NewString("MyInterface0")); + Dart_Handle intf1 = Dart_GetClass(lib, NewString("MyInterface1")); intptr_t len = -1; EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len)); @@ -2574,7 +2544,7 @@ static void TestFieldOk(Dart_Handle container, OS::SNPrint(buffer, 256, "Expected%d", ++counter); // Try to change the field value. - result = Dart_SetField(container, name, Dart_NewString(buffer)); + result = Dart_SetField(container, name, NewString(buffer)); if (final) { EXPECT(Dart_IsError(result)); } else { @@ -2687,163 +2657,163 @@ TEST_CASE(FieldAccess) { // Shared setup. Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); + Dart_Handle cls = Dart_GetClass(lib, NewString("Fields")); EXPECT_VALID(cls); - Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); + Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); EXPECT_VALID(instance); Dart_Handle name; // Load imported lib. - Dart_Handle url = Dart_NewString("library_url"); - Dart_Handle source = Dart_NewString(kImportedScriptChars); + Dart_Handle url = NewString("library_url"); + Dart_Handle source = NewString(kImportedScriptChars); Dart_Handle imported_lib = Dart_LoadLibrary(url, source); - Dart_Handle prefix = Dart_NewString(""); + Dart_Handle prefix = NewString(""); EXPECT_VALID(imported_lib); Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); EXPECT_VALID(result); - result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); + result = Dart_Invoke(imported_lib, NewString("test2"), 0, NULL); EXPECT_VALID(result); // Instance field. - name = Dart_NewString("instance_fld"); + name = NewString("instance_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, false, "instance"); // Hidden instance field. - name = Dart_NewString("_instance_fld"); + name = NewString("_instance_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, false, "hidden instance"); // Final instance field. - name = Dart_NewString("final_instance_fld"); + name = NewString("final_instance_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, true, "final instance"); // Hidden final instance field. - name = Dart_NewString("_final_instance_fld"); + name = NewString("_final_instance_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, true, "hidden final instance"); // Inherited field. - name = Dart_NewString("inherited_fld"); + name = NewString("inherited_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, false, "inherited"); // Instance get/set field. - name = Dart_NewString("instance_getset_fld"); + name = NewString("instance_getset_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, false, "instance getset"); // Hidden instance get/set field. - name = Dart_NewString("_instance_getset_fld"); + name = NewString("_instance_getset_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(cls, name); TestFieldOk(instance, name, false, "hidden instance getset"); // Static field. - name = Dart_NewString("static_fld"); + name = NewString("static_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldOk(cls, name, false, "static"); // Hidden static field. - name = Dart_NewString("_static_fld"); + name = NewString("_static_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldOk(cls, name, false, "hidden static"); // Static final field. - name = Dart_NewString("const_static_fld"); + name = NewString("const_static_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldOk(cls, name, true, "const static"); // Hidden static const field. - name = Dart_NewString("_const_static_fld"); + name = NewString("_const_static_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldOk(cls, name, true, "hidden const static"); // Static non-inherited field. Not found at any level. - name = Dart_NewString("non_inherited_fld"); + name = NewString("non_inherited_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldNotFound(cls, name); // Static get/set field. - name = Dart_NewString("static_getset_fld"); + name = NewString("static_getset_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldOk(cls, name, false, "static getset"); // Hidden static get/set field. - name = Dart_NewString("_static_getset_fld"); + name = NewString("_static_getset_fld"); TestFieldNotFound(lib, name); TestFieldNotFound(instance, name); TestFieldOk(cls, name, false, "hidden static getset"); // Top-Level field. - name = Dart_NewString("top_fld"); + name = NewString("top_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, false, "top"); // Hidden top-level field. - name = Dart_NewString("_top_fld"); + name = NewString("_top_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, false, "hidden top"); // Top-Level final field. - name = Dart_NewString("const_top_fld"); + name = NewString("const_top_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, true, "const top"); // Hidden top-level final field. - name = Dart_NewString("_const_top_fld"); + name = NewString("_const_top_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, true, "hidden const top"); // Top-Level get/set field. - name = Dart_NewString("top_getset_fld"); + name = NewString("top_getset_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, false, "top getset"); // Hidden top-level get/set field. - name = Dart_NewString("_top_getset_fld"); + name = NewString("_top_getset_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, false, "hidden top getset"); // Imported top-Level field. - name = Dart_NewString("imported_fld"); + name = NewString("imported_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, false, "imported"); // Hidden imported top-level field. Not found at any level. - name = Dart_NewString("_imported_fld"); + name = NewString("_imported_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldNotFound(lib, name); // Imported top-Level get/set field. - name = Dart_NewString("imported_getset_fld"); + name = NewString("imported_getset_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldOk(lib, name, false, "imported getset"); // Hidden imported top-level get/set field. Not found at any level. - name = Dart_NewString("_imported_getset_fld"); + name = NewString("_imported_getset_fld"); TestFieldNotFound(cls, name); TestFieldNotFound(instance, name); TestFieldNotFound(lib, name); @@ -2855,7 +2825,7 @@ TEST_CASE(SetField_FunnyValue) { "var top;\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle name = Dart_NewString("top"); + Dart_Handle name = NewString("top"); bool value; // Test that you can set the field to a good value. @@ -2920,13 +2890,13 @@ TEST_CASE(InjectNativeFields1) { // Create a native wrapper class with native fields. result = Dart_CreateNativeWrapperClass( lib, - Dart_NewString("NativeFieldsWrapper"), + NewString("NativeFieldsWrapper"), kNumNativeFields); // Load up a test script in the test library. // Invoke a function which returns an object of type NativeFields. - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); DARTSCOPE_NOCHECKS(Isolate::Current()); Instance& obj = Instance::Handle(); @@ -2963,7 +2933,7 @@ TEST_CASE(InjectNativeFields2) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Invoke a function which returns an object of type NativeFields. - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); // We expect this to fail as class "NativeFields" extends // "NativeFieldsWrapper" and there is no definition of it either @@ -2994,7 +2964,7 @@ TEST_CASE(InjectNativeFields3) { native_field_lookup); // Invoke a function which returns an object of type NativeFields. - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); DARTSCOPE_NOCHECKS(Isolate::Current()); Instance& obj = Instance::Handle(); @@ -3032,7 +3002,7 @@ TEST_CASE(InjectNativeFields4) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Invoke a function which returns an object of type NativeFields. - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); // We expect the test script to fail finalization with the error below: EXPECT(Dart_IsError(result)); @@ -3064,7 +3034,7 @@ TEST_CASE(InjectNativeFieldsSuperClass) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_field_lookup); // Invoke a function which returns an object of type NativeFields. - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); @@ -3077,29 +3047,29 @@ TEST_CASE(InjectNativeFieldsSuperClass) { static void TestNativeFields(Dart_Handle retobj) { // Access and set various instance fields of the object. - Dart_Handle result = Dart_GetField(retobj, Dart_NewString("fld3")); + Dart_Handle result = Dart_GetField(retobj, NewString("fld3")); EXPECT(Dart_IsError(result)); - result = Dart_GetField(retobj, Dart_NewString("fld0")); + result = Dart_GetField(retobj, NewString("fld0")); EXPECT_VALID(result); EXPECT(Dart_IsNull(result)); - result = Dart_GetField(retobj, Dart_NewString("fld1")); + result = Dart_GetField(retobj, NewString("fld1")); EXPECT_VALID(result); int64_t value = 0; result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(10, value); - result = Dart_GetField(retobj, Dart_NewString("fld2")); + result = Dart_GetField(retobj, NewString("fld2")); EXPECT_VALID(result); result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(20, value); result = Dart_SetField(retobj, - Dart_NewString("fld2"), + NewString("fld2"), Dart_NewInteger(40)); EXPECT(Dart_IsError(result)); result = Dart_SetField(retobj, - Dart_NewString("fld1"), + NewString("fld1"), Dart_NewInteger(40)); EXPECT_VALID(result); - result = Dart_GetField(retobj, Dart_NewString("fld1")); + result = Dart_GetField(retobj, NewString("fld1")); EXPECT_VALID(result); result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(40, value); @@ -3144,11 +3114,11 @@ static void TestNativeFields(Dart_Handle retobj) { // Now re-access various dart instance fields of the returned object // to ensure that there was no corruption while setting native fields. - result = Dart_GetField(retobj, Dart_NewString("fld1")); + result = Dart_GetField(retobj, NewString("fld1")); EXPECT_VALID(result); result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(40, value); - result = Dart_GetField(retobj, Dart_NewString("fld2")); + result = Dart_GetField(retobj, NewString("fld2")); EXPECT_VALID(result); result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(20, value); @@ -3178,14 +3148,14 @@ TEST_CASE(NativeFieldAccess) { // Create a native wrapper class with native fields. Dart_Handle result = Dart_CreateNativeWrapperClass( lib, - Dart_NewString("NativeFieldsWrapper"), + NewString("NativeFieldsWrapper"), kNumNativeFields); EXPECT_VALID(result); // Load up a test script in it. // Invoke a function which returns an object of type NativeFields. - Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(retobj); // Now access and set various instance fields of the returned object. @@ -3225,7 +3195,7 @@ TEST_CASE(ImplicitNativeFieldAccess) { native_field_lookup); // Invoke a function which returns an object of type NativeFields. - Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(retobj); // Now access and set various instance fields of the returned object. @@ -3256,7 +3226,7 @@ TEST_CASE(NegativeNativeFieldAccess) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Invoke a function which returns an object of type NativeFields. - Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain1"), 0, NULL); + Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); EXPECT_VALID(retobj); // Now access and set various native instance fields of the returned object. @@ -3284,7 +3254,7 @@ TEST_CASE(NegativeNativeFieldAccess) { EXPECT(Dart_IsError(result)); // Invoke a function which returns a closure object. - retobj = Dart_Invoke(lib, Dart_NewString("testMain2"), 0, NULL); + retobj = Dart_Invoke(lib, NewString("testMain2"), 0, NULL); EXPECT_VALID(retobj); result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); @@ -3315,33 +3285,33 @@ TEST_CASE(GetStaticField_RunsInitializer) { Dart_Handle result; // Create a test library and Load up a test script in it. Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass")); EXPECT_VALID(cls); // Invoke a function which returns an object. - result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); EXPECT_VALID(result); // For uninitialized fields, the getter is returned - result = Dart_GetField(cls, Dart_NewString("fld1")); + result = Dart_GetField(cls, NewString("fld1")); EXPECT_VALID(result); int64_t value = 0; result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(7, value); - result = Dart_GetField(cls, Dart_NewString("fld2")); + result = Dart_GetField(cls, NewString("fld2")); EXPECT_VALID(result); result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(11, value); // Overwrite fld2 result = Dart_SetField(cls, - Dart_NewString("fld2"), + NewString("fld2"), Dart_NewInteger(13)); EXPECT_VALID(result); // We now get the new value for fld2, not the initializer - result = Dart_GetField(cls, Dart_NewString("fld2")); + result = Dart_GetField(cls, NewString("fld2")); EXPECT_VALID(result); result = Dart_IntegerToInt64(result, &value); EXPECT_EQ(13, value); @@ -3392,13 +3362,13 @@ TEST_CASE(New) { "}\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); EXPECT_VALID(cls); - Dart_Handle cls2 = Dart_GetClass(lib, Dart_NewString("MyClass2")); + Dart_Handle cls2 = Dart_GetClass(lib, NewString("MyClass2")); EXPECT_VALID(cls2); - Dart_Handle intf = Dart_GetClass(lib, Dart_NewString("MyInterface")); + Dart_Handle intf = Dart_GetClass(lib, NewString("MyInterface")); EXPECT_VALID(intf); - Dart_Handle intf2 = Dart_GetClass(lib, Dart_NewString("MyInterface2")); + Dart_Handle intf2 = Dart_GetClass(lib, NewString("MyInterface2")); EXPECT_VALID(intf2); Dart_Handle args[1]; args[0] = Dart_NewInteger(11); @@ -3412,79 +3382,79 @@ TEST_CASE(New) { EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int64_t int_value = 0; - Dart_Handle foo = Dart_GetField(result, Dart_NewString("foo")); + Dart_Handle foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(7, int_value); // Invoke the unnamed constructor with an empty string. - result = Dart_New(cls, Dart_NewString(""), 0, NULL); + result = Dart_New(cls, NewString(""), 0, NULL); EXPECT_VALID(result); instanceof = false; EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int_value = 0; - foo = Dart_GetField(result, Dart_NewString("foo")); + foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(7, int_value); // Invoke a named constructor. - result = Dart_New(cls, Dart_NewString("named"), 1, args); + result = Dart_New(cls, NewString("named"), 1, args); EXPECT_VALID(result); EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int_value = 0; - foo = Dart_GetField(result, Dart_NewString("foo")); + foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(11, int_value); // Invoke a hidden named constructor. - result = Dart_New(cls, Dart_NewString("_hidden"), 1, args); + result = Dart_New(cls, NewString("_hidden"), 1, args); EXPECT_VALID(result); EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int_value = 0; - foo = Dart_GetField(result, Dart_NewString("foo")); + foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(-11, int_value); // Invoke a factory constructor. - result = Dart_New(cls, Dart_NewString("multiply"), 1, args); + result = Dart_New(cls, NewString("multiply"), 1, args); EXPECT_VALID(result); EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int_value = 0; - foo = Dart_GetField(result, Dart_NewString("foo")); + foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(1100, int_value); // Invoke a factory constructor which returns null. - result = Dart_New(cls, Dart_NewString("nullo"), 0, NULL); + result = Dart_New(cls, NewString("nullo"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsNull(result)); // Pass an error class object. Error is passed through. - result = Dart_New(Dart_Error("myerror"), Dart_NewString("named"), 1, args); + result = Dart_New(Dart_Error("myerror"), NewString("named"), 1, args); EXPECT_ERROR(result, "myerror"); // Pass a bad class object. - result = Dart_New(Dart_Null(), Dart_NewString("named"), 1, args); + result = Dart_New(Dart_Null(), NewString("named"), 1, args); EXPECT_ERROR(result, "Dart_New expects argument 'clazz' to be non-null."); // Pass a negative arg count. - result = Dart_New(cls, Dart_NewString("named"), -1, args); + result = Dart_New(cls, NewString("named"), -1, args); EXPECT_ERROR( result, "Dart_New expects argument 'number_of_arguments' to be non-negative."); // Pass the wrong arg count. - result = Dart_New(cls, Dart_NewString("named"), 0, NULL); + result = Dart_New(cls, NewString("named"), 0, NULL); EXPECT_ERROR( result, "Dart_New: wrong argument count for constructor 'MyClass.named': " "0 passed, 1 expected."); // Pass a bad argument. Error is passed through. - result = Dart_New(cls, Dart_NewString("named"), 1, bad_args); + result = Dart_New(cls, NewString("named"), 1, bad_args); EXPECT_ERROR(result, "myerror"); // Pass a bad constructor name. @@ -3494,12 +3464,12 @@ TEST_CASE(New) { "Dart_New expects argument 'constructor_name' to be of type String."); // Invoke a missing constructor. - result = Dart_New(cls, Dart_NewString("missing"), 1, args); + result = Dart_New(cls, NewString("missing"), 1, args); EXPECT_ERROR(result, "Dart_New: could not find constructor 'MyClass.missing'."); // Invoke a constructor which throws an exception. - result = Dart_New(cls, Dart_NewString("exception"), 1, args); + result = Dart_New(cls, NewString("exception"), 1, args); EXPECT_ERROR(result, "ConstructorDeath"); // MyInterface has default class MyClass. @@ -3515,23 +3485,23 @@ TEST_CASE(New) { // MyClass.foo() from the class MyClass. // Invoke an interface constructor. - result = Dart_New(intf, Dart_NewString("named"), 1, args); + result = Dart_New(intf, NewString("named"), 1, args); EXPECT_VALID(result); EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int_value = 0; - foo = Dart_GetField(result, Dart_NewString("foo")); + foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(11, int_value); // Invoke an interface constructor which in turn calls a factory // constructor. - result = Dart_New(intf, Dart_NewString("multiply"), 1, args); + result = Dart_New(intf, NewString("multiply"), 1, args); EXPECT_VALID(result); EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); EXPECT(instanceof); int_value = 0; - foo = Dart_GetField(result, Dart_NewString("foo")); + foo = Dart_GetField(result, NewString("foo")); EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); EXPECT_EQ(1100, int_value); @@ -3543,7 +3513,7 @@ TEST_CASE(New) { // Invoke a constructor that is present in the interface but missing // in the default class. - result = Dart_New(intf, Dart_NewString("notfound"), 1, args); + result = Dart_New(intf, NewString("notfound"), 1, args); EXPECT_ERROR(result, "Dart_New: could not find constructor 'MyClass.notfound'."); @@ -3561,24 +3531,24 @@ TEST_CASE(New) { // Invoke an interface constructor which in turn calls a factory // constructor. - result = Dart_New(intf2, Dart_NewString("multiply"), 1, args); + result = Dart_New(intf2, NewString("multiply"), 1, args); EXPECT_VALID(result); EXPECT_VALID(Dart_ObjectIsType(result, cls2, &instanceof)); EXPECT(instanceof); int_value = 0; - Dart_Handle bar = Dart_GetField(result, Dart_NewString("bar")); + Dart_Handle bar = Dart_GetField(result, NewString("bar")); EXPECT_VALID(Dart_IntegerToInt64(bar, &int_value)); EXPECT_EQ(110000, int_value); // Invoke a constructor that is missing in the interface but present // in the default class. - result = Dart_New(intf2, Dart_NewString("unused"), 1, args); + result = Dart_New(intf2, NewString("unused"), 1, args); EXPECT_ERROR(result, "Dart_New: could not find constructor 'MyInterface2.unused'."); // Invoke a constructor that is present in the interface but missing // in the default class. - result = Dart_New(intf2, Dart_NewString("notfound"), 1, args); + result = Dart_New(intf2, NewString("notfound"), 1, args); EXPECT_ERROR(result, "Dart_New: could not find factory 'MyInterface2.notfound' " "in class 'MyClass'."); @@ -3589,9 +3559,9 @@ TEST_CASE(New_Issue2971) { // Issue 2971: We were unable to use Dart_New to construct an // instance of List, due to problems implementing interface // factories. - Dart_Handle core_lib = Dart_LookupLibrary(Dart_NewString("dart:core")); + Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); EXPECT_VALID(core_lib); - Dart_Handle list_class = Dart_GetClass(core_lib, Dart_NewString("List")); + Dart_Handle list_class = Dart_GetClass(core_lib, NewString("List")); EXPECT_VALID(list_class); const int kNumArgs = 1; @@ -3626,21 +3596,21 @@ TEST_CASE(Invoke) { // Shared setup. Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Methods")); + Dart_Handle cls = Dart_GetClass(lib, NewString("Methods")); EXPECT_VALID(cls); - Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); + Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); EXPECT_VALID(instance); Dart_Handle args[1]; - args[0] = Dart_NewString("!!!"); + args[0] = NewString("!!!"); Dart_Handle bad_args[2]; - bad_args[0] = Dart_NewString("bad1"); - bad_args[1] = Dart_NewString("bad2"); + bad_args[0] = NewString("bad1"); + bad_args[1] = NewString("bad2"); Dart_Handle result; Dart_Handle name; const char* str; // Instance method. - name = Dart_NewString("instanceMethod"); + name = NewString("instanceMethod"); EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); result = Dart_Invoke(instance, name, 1, args); @@ -3653,7 +3623,7 @@ TEST_CASE(Invoke) { "did not find instance method 'Methods.instanceMethod'"); // Hidden instance method. - name = Dart_NewString("_instanceMethod"); + name = NewString("_instanceMethod"); EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); result = Dart_Invoke(instance, name, 1, args); @@ -3662,7 +3632,7 @@ TEST_CASE(Invoke) { EXPECT_STREQ("hidden instance !!!", str); // Inherited method. - name = Dart_NewString("inheritedMethod"); + name = NewString("inheritedMethod"); EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); result = Dart_Invoke(instance, name, 1, args); @@ -3671,7 +3641,7 @@ TEST_CASE(Invoke) { EXPECT_STREQ("inherited !!!", str); // Static method. - name = Dart_NewString("staticMethod"); + name = NewString("staticMethod"); EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); result = Dart_Invoke(cls, name, 1, args); @@ -3684,7 +3654,7 @@ TEST_CASE(Invoke) { "did not find static method 'Methods.staticMethod'"); // Hidden static method. - name = Dart_NewString("_staticMethod"); + name = NewString("_staticMethod"); EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); result = Dart_Invoke(cls, name, 1, args); @@ -3693,13 +3663,13 @@ TEST_CASE(Invoke) { EXPECT_STREQ("hidden static !!!", str); // Static non-inherited method. Not found at any level. - name = Dart_NewString("non_inheritedMethod"); + name = NewString("non_inheritedMethod"); EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); // Top-Level method. - name = Dart_NewString("topMethod"); + name = NewString("topMethod"); EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); result = Dart_Invoke(lib, name, 1, args); @@ -3713,7 +3683,7 @@ TEST_CASE(Invoke) { "2 passed, 1 expected."); // Hidden top-level method. - name = Dart_NewString("_topMethod"); + name = NewString("_topMethod"); EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); result = Dart_Invoke(lib, name, 1, args); @@ -3728,12 +3698,12 @@ TEST_CASE(Invoke_FunnyArgs) { "test(arg) => 'hello $arg';\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle func_name = Dart_NewString("test"); + Dart_Handle func_name = NewString("test"); Dart_Handle args[1]; const char* str; // Make sure that valid args yield valid results. - args[0] = Dart_NewString("!!!"); + args[0] = NewString("!!!"); Dart_Handle result = Dart_Invoke(lib, func_name, 1, args); EXPECT_VALID(result); result = Dart_StringToCString(result, &str); @@ -3774,7 +3744,7 @@ TEST_CASE(Invoke_FunnyArgs) { TEST_CASE(Invoke_Null) { Dart_Handle result = Dart_Invoke(Dart_Null(), - Dart_NewString("toString"), + NewString("toString"), 0, NULL); EXPECT_VALID(result); @@ -3786,7 +3756,7 @@ TEST_CASE(Invoke_Null) { // Should throw a NullPointerException. Disabled due to bug 5415268. /* - Dart_Handle function_name2 = Dart_NewString("NoNoNo"); + Dart_Handle function_name2 = NewString("NoNoNo"); result = Dart_Invoke(null_receiver, function_name2, number_of_arguments, @@ -3807,14 +3777,14 @@ TEST_CASE(Invoke_CrossLibrary) { "void _imported() {}\n"; // Load lib1 - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib1 = Dart_LoadLibrary(url, source); EXPECT_VALID(lib1); // Load lib2 - url = Dart_NewString("library2_url"); - source = Dart_NewString(kLibrary2Chars); + url = NewString("library2_url"); + source = NewString(kLibrary2Chars); Dart_Handle lib2 = Dart_LoadLibrary(url, source); EXPECT_VALID(lib2); @@ -3823,12 +3793,12 @@ TEST_CASE(Invoke_CrossLibrary) { EXPECT_VALID(result); // We can invoke both private and non-private local functions. - EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); - EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); + EXPECT_VALID(Dart_Invoke(lib1, NewString("local"), 0, NULL)); + EXPECT_VALID(Dart_Invoke(lib1, NewString("_local"), 0, NULL)); // We can only invoke non-private imported functions. - EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("imported"), 0, NULL)); - EXPECT_ERROR(Dart_Invoke(lib1, Dart_NewString("_imported"), 0, NULL), + EXPECT_VALID(Dart_Invoke(lib1, NewString("imported"), 0, NULL)); + EXPECT_ERROR(Dart_Invoke(lib1, NewString("_imported"), 0, NULL), "did not find top-level function '_imported'"); } @@ -3871,11 +3841,11 @@ TEST_CASE(ClosureFunction) { // Create a test library and Load up a test script in it. Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); EXPECT_VALID(lib); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Foo")); + Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); EXPECT_VALID(cls); // Invoke a function which returns a closure. - Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("getClosure"), 0, NULL); + Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); EXPECT_VALID(retobj); EXPECT(Dart_IsClosure(retobj)); @@ -3887,7 +3857,7 @@ TEST_CASE(ClosureFunction) { EXPECT(Dart_IsFunction(result)); owner = Dart_FunctionOwner(result); EXPECT_VALID(owner); - defining_function = Dart_LookupFunction(lib, Dart_NewString("getClosure")); + defining_function = Dart_LookupFunction(lib, NewString("getClosure")); EXPECT(Dart_IdentityEquals(owner, defining_function)); int64_t fixed_param_count = -999; int64_t opt_param_count = -999; @@ -3903,7 +3873,7 @@ TEST_CASE(ClosureFunction) { EXPECT(Dart_IsError(result)); // Invoke a function which returns an "instance" closure. - retobj = Dart_Invoke(lib, Dart_NewString("getInstanceClosure"), 0, NULL); + retobj = Dart_Invoke(lib, NewString("getInstanceClosure"), 0, NULL); EXPECT_VALID(retobj); EXPECT(Dart_IsClosure(retobj)); @@ -3914,7 +3884,7 @@ TEST_CASE(ClosureFunction) { owner = Dart_FunctionOwner(result); EXPECT_VALID(owner); defining_function = Dart_LookupFunction(cls, - Dart_NewString("getInstanceClosure")); + NewString("getInstanceClosure")); EXPECT(Dart_IdentityEquals(owner, defining_function)); // -999: We want to distinguish between a non-answer and a wrong answer, and // -1 has been a previous wrong answer @@ -3929,7 +3899,7 @@ TEST_CASE(ClosureFunction) { // Invoke a function which returns an "instance" closure with arguments. retobj = Dart_Invoke(lib, - Dart_NewString("getInstanceClosureWithArgs"), + NewString("getInstanceClosureWithArgs"), 0, NULL); EXPECT_VALID(retobj); @@ -3942,7 +3912,7 @@ TEST_CASE(ClosureFunction) { owner = Dart_FunctionOwner(result); EXPECT_VALID(owner); defining_function = - Dart_LookupFunction(cls, Dart_NewString("getInstanceClosureWithArgs")); + Dart_LookupFunction(cls, NewString("getInstanceClosureWithArgs")); EXPECT(Dart_IdentityEquals(owner, defining_function)); // -999: We want to distinguish between a non-answer and a wrong answer, and // -1 has been a previous wrong answer @@ -3956,7 +3926,7 @@ TEST_CASE(ClosureFunction) { EXPECT_EQ(1, opt_param_count); // Invoke a function which returns a "static" closure. - retobj = Dart_Invoke(lib, Dart_NewString("getStaticClosure"), 0, NULL); + retobj = Dart_Invoke(lib, NewString("getStaticClosure"), 0, NULL); EXPECT_VALID(retobj); EXPECT(Dart_IsClosure(retobj)); @@ -3967,7 +3937,7 @@ TEST_CASE(ClosureFunction) { owner = Dart_FunctionOwner(result); EXPECT_VALID(owner); defining_function = Dart_LookupFunction(cls, - Dart_NewString("getStaticClosure")); + NewString("getStaticClosure")); EXPECT(Dart_IdentityEquals(owner, defining_function)); // -999: We want to distinguish between a non-answer and a wrong answer, and // -1 has been a previous wrong answer @@ -3983,7 +3953,7 @@ TEST_CASE(ClosureFunction) { // Invoke a function which returns a "static" closure with arguments. retobj = Dart_Invoke(lib, - Dart_NewString("getStaticClosureWithArgs"), + NewString("getStaticClosureWithArgs"), 0, NULL); EXPECT_VALID(retobj); @@ -3996,7 +3966,7 @@ TEST_CASE(ClosureFunction) { owner = Dart_FunctionOwner(result); EXPECT_VALID(owner); defining_function = - Dart_LookupFunction(cls, Dart_NewString("getStaticClosureWithArgs")); + Dart_LookupFunction(cls, NewString("getStaticClosureWithArgs")); EXPECT(Dart_IdentityEquals(owner, defining_function)); // -999: We want to distinguish between a non-answer and a wrong answer, and // -1 has been a previous wrong answer @@ -4040,7 +4010,7 @@ TEST_CASE(InvokeClosure) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Invoke a function which returns a closure. - Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain1"), 0, NULL); + Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); EXPECT_VALID(retobj); EXPECT(Dart_IsClosure(retobj)); @@ -4062,11 +4032,11 @@ TEST_CASE(InvokeClosure) { EXPECT(Dart_ErrorHasException(result)); // Invoke a function which returns a closure. - retobj = Dart_Invoke(lib, Dart_NewString("testMain2"), 0, NULL); + retobj = Dart_Invoke(lib, NewString("testMain2"), 0, NULL); EXPECT_VALID(retobj); EXPECT(Dart_IsClosure(retobj)); - EXPECT(!Dart_IsClosure(Dart_NewString("abcdef"))); + EXPECT(!Dart_IsClosure(NewString("abcdef"))); // Now invoke the closure and check the result (should be an exception). dart_arguments[0] = Dart_NewInteger(1); @@ -4078,7 +4048,7 @@ TEST_CASE(InvokeClosure) { void ExceptionNative(Dart_NativeArguments args) { Dart_EnterScope(); - Dart_ThrowException(Dart_NewString("Hello from ExceptionNative!")); + Dart_ThrowException(NewString("Hello from ExceptionNative!")); UNREACHABLE(); } @@ -4105,12 +4075,12 @@ TEST_CASE(ThrowException) { reinterpret_cast(native_lookup)); // Throwing an exception here should result in an error. - result = Dart_ThrowException(Dart_NewString("This doesn't work")); + result = Dart_ThrowException(NewString("This doesn't work")); EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); EXPECT(!Dart_ErrorHasException(result)); // Invoke 'test' and check for an uncaught exception. - result = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); + result = Dart_Invoke(lib, NewString("test"), 0, NULL); EXPECT_ERROR(result, "Hello from ExceptionNative!"); EXPECT(Dart_ErrorHasException(result)); @@ -4146,7 +4116,7 @@ TEST_CASE(GetNativeArgumentCount) { kScriptChars, reinterpret_cast(gnac_lookup)); - Dart_Handle result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); @@ -4170,31 +4140,31 @@ TEST_CASE(GetClass) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Lookup a class. - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Class")); + Dart_Handle cls = Dart_GetClass(lib, NewString("Class")); EXPECT_VALID(cls); - Dart_Handle name = Dart_GetField(cls, Dart_NewString("name")); + Dart_Handle name = Dart_GetField(cls, NewString("name")); EXPECT_VALID(name); const char* name_cstr = ""; EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); EXPECT_STREQ("Class", name_cstr); // Lookup a private class. - cls = Dart_GetClass(lib, Dart_NewString("_Class")); + cls = Dart_GetClass(lib, NewString("_Class")); EXPECT_VALID(cls); - name = Dart_GetField(cls, Dart_NewString("name")); + name = Dart_GetField(cls, NewString("name")); EXPECT_VALID(name); name_cstr = ""; EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); EXPECT_STREQ("_Class", name_cstr); // Lookup a class that does not exist. - cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist")); + cls = Dart_GetClass(lib, NewString("DoesNotExist")); EXPECT(Dart_IsError(cls)); EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.", Dart_GetError(cls)); // Lookup a class from an error library. The error propagates. - cls = Dart_GetClass(Api::NewError("myerror"), Dart_NewString("Class")); + cls = Dart_GetClass(Api::NewError("myerror"), NewString("Class")); EXPECT(Dart_IsError(cls)); EXPECT_STREQ("myerror", Dart_GetError(cls)); @@ -4292,14 +4262,14 @@ TEST_CASE(FunctionReflection) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); EXPECT_VALID(lib); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); EXPECT_VALID(cls); - Dart_Handle private_cls = Dart_GetClass(lib, Dart_NewString("_PrivateClass")); + Dart_Handle private_cls = Dart_GetClass(lib, NewString("_PrivateClass")); EXPECT_VALID(private_cls); TextBuffer buffer(128); // Lookup a top-level function. - Dart_Handle func = Dart_LookupFunction(lib, Dart_NewString("a")); + Dart_Handle func = Dart_LookupFunction(lib, NewString("a")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4310,7 +4280,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, lib)); // Lookup a private top-level function. - func = Dart_LookupFunction(lib, Dart_NewString("_b")); + func = Dart_LookupFunction(lib, NewString("_b")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4320,7 +4290,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, lib)); // Lookup a top-level getter. - func = Dart_LookupFunction(lib, Dart_NewString("c")); + func = Dart_LookupFunction(lib, NewString("c")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4330,7 +4300,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, lib)); // Lookup a top-level setter. - func = Dart_LookupFunction(lib, Dart_NewString("d=")); + func = Dart_LookupFunction(lib, NewString("d=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4340,7 +4310,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, lib)); // Lookup a private top-level getter. - func = Dart_LookupFunction(lib, Dart_NewString("_e")); + func = Dart_LookupFunction(lib, NewString("_e")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4350,7 +4320,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, lib)); // Lookup a private top-level setter. - func = Dart_LookupFunction(lib, Dart_NewString("_f=")); + func = Dart_LookupFunction(lib, NewString("_f=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4360,7 +4330,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, lib)); // Lookup an unnamed constructor - func = Dart_LookupFunction(cls, Dart_NewString("MyClass")); + func = Dart_LookupFunction(cls, NewString("MyClass")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4370,7 +4340,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a named constructor - func = Dart_LookupFunction(cls, Dart_NewString("MyClass.named")); + func = Dart_LookupFunction(cls, NewString("MyClass.named")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4380,7 +4350,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup an private unnamed constructor - func = Dart_LookupFunction(private_cls, Dart_NewString("_PrivateClass")); + func = Dart_LookupFunction(private_cls, NewString("_PrivateClass")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4391,7 +4361,7 @@ TEST_CASE(FunctionReflection) { // Lookup a private named constructor func = Dart_LookupFunction(private_cls, - Dart_NewString("_PrivateClass.named")); + NewString("_PrivateClass.named")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4401,7 +4371,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, private_cls)); // Lookup a method. - func = Dart_LookupFunction(cls, Dart_NewString("a")); + func = Dart_LookupFunction(cls, NewString("a")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4411,7 +4381,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private method. - func = Dart_LookupFunction(cls, Dart_NewString("_b")); + func = Dart_LookupFunction(cls, NewString("_b")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4421,7 +4391,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a instance getter. - func = Dart_LookupFunction(cls, Dart_NewString("c")); + func = Dart_LookupFunction(cls, NewString("c")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4431,7 +4401,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a instance setter. - func = Dart_LookupFunction(cls, Dart_NewString("d=")); + func = Dart_LookupFunction(cls, NewString("d=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4441,7 +4411,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private instance getter. - func = Dart_LookupFunction(cls, Dart_NewString("_e")); + func = Dart_LookupFunction(cls, NewString("_e")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4451,7 +4421,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private instance setter. - func = Dart_LookupFunction(cls, Dart_NewString("_f=")); + func = Dart_LookupFunction(cls, NewString("_f=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4461,7 +4431,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a static method. - func = Dart_LookupFunction(cls, Dart_NewString("g")); + func = Dart_LookupFunction(cls, NewString("g")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4471,7 +4441,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private static method. - func = Dart_LookupFunction(cls, Dart_NewString("_h")); + func = Dart_LookupFunction(cls, NewString("_h")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4481,7 +4451,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a static getter. - func = Dart_LookupFunction(cls, Dart_NewString("i")); + func = Dart_LookupFunction(cls, NewString("i")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4491,7 +4461,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a static setter. - func = Dart_LookupFunction(cls, Dart_NewString("j=")); + func = Dart_LookupFunction(cls, NewString("j=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4501,7 +4471,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private static getter. - func = Dart_LookupFunction(cls, Dart_NewString("_k")); + func = Dart_LookupFunction(cls, NewString("_k")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4511,7 +4481,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private static setter. - func = Dart_LookupFunction(cls, Dart_NewString("_l=")); + func = Dart_LookupFunction(cls, NewString("_l=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4521,7 +4491,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup an abstract method. - func = Dart_LookupFunction(cls, Dart_NewString("m")); + func = Dart_LookupFunction(cls, NewString("m")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4531,7 +4501,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private abstract method. - func = Dart_LookupFunction(cls, Dart_NewString("_n")); + func = Dart_LookupFunction(cls, NewString("_n")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4541,7 +4511,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a abstract getter. - func = Dart_LookupFunction(cls, Dart_NewString("o")); + func = Dart_LookupFunction(cls, NewString("o")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4551,7 +4521,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a abstract setter. - func = Dart_LookupFunction(cls, Dart_NewString("p=")); + func = Dart_LookupFunction(cls, NewString("p=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4561,7 +4531,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private abstract getter. - func = Dart_LookupFunction(cls, Dart_NewString("_q")); + func = Dart_LookupFunction(cls, NewString("_q")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4571,7 +4541,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a private abstract setter. - func = Dart_LookupFunction(cls, Dart_NewString("_r=")); + func = Dart_LookupFunction(cls, NewString("_r=")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4581,7 +4551,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a method with fixed and optional parameters. - func = Dart_LookupFunction(cls, Dart_NewString("s")); + func = Dart_LookupFunction(cls, NewString("s")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4591,7 +4561,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a method with only optional parameters. - func = Dart_LookupFunction(cls, Dart_NewString("t")); + func = Dart_LookupFunction(cls, NewString("t")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4601,7 +4571,7 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup an operator - func = Dart_LookupFunction(cls, Dart_NewString("==")); + func = Dart_LookupFunction(cls, NewString("==")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); BuildFunctionDescription(&buffer, func); @@ -4611,11 +4581,11 @@ TEST_CASE(FunctionReflection) { EXPECT(Dart_IdentityEquals(owner, cls)); // Lookup a function that does not exist from a library. - func = Dart_LookupFunction(lib, Dart_NewString("DoesNotExist")); + func = Dart_LookupFunction(lib, NewString("DoesNotExist")); EXPECT(Dart_IsNull(func)); // Lookup a function that does not exist from a class. - func = Dart_LookupFunction(cls, Dart_NewString("DoesNotExist")); + func = Dart_LookupFunction(cls, NewString("DoesNotExist")); EXPECT(Dart_IsNull(func)); // Lookup a class using an error class name. The error propagates. @@ -4623,7 +4593,7 @@ TEST_CASE(FunctionReflection) { EXPECT_ERROR(func, "myerror"); // Lookup a class from an error library. The error propagates. - func = Dart_LookupFunction(Api::NewError("myerror"), Dart_NewString("foo")); + func = Dart_LookupFunction(Api::NewError("myerror"), NewString("foo")); EXPECT_ERROR(func, "myerror"); } @@ -4635,7 +4605,7 @@ TEST_CASE(TypeReflection) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); EXPECT_VALID(lib); - Dart_Handle func = Dart_LookupFunction(lib, Dart_NewString("func")); + Dart_Handle func = Dart_LookupFunction(lib, NewString("func")); EXPECT_VALID(func); EXPECT(Dart_IsFunction(func)); @@ -4664,7 +4634,7 @@ TEST_CASE(TypeReflection) { EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); EXPECT_STREQ("String", cls_name_cstr); - Dart_Handle var = Dart_LookupVariable(lib, Dart_NewString("variable")); + Dart_Handle var = Dart_LookupVariable(lib, NewString("variable")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); @@ -4722,104 +4692,104 @@ TEST_CASE(VariableReflection) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); EXPECT_VALID(lib); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); EXPECT_VALID(cls); TextBuffer buffer(128); // Lookup a top-level variable. - Dart_Handle var = Dart_LookupVariable(lib, Dart_NewString("a")); + Dart_Handle var = Dart_LookupVariable(lib, NewString("a")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("a static", buffer.buf()); // Lookup a private top-level variable. - var = Dart_LookupVariable(lib, Dart_NewString("_b")); + var = Dart_LookupVariable(lib, NewString("_b")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("_b static", buffer.buf()); // Lookup a const top-level variable. - var = Dart_LookupVariable(lib, Dart_NewString("c")); + var = Dart_LookupVariable(lib, NewString("c")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("c static final", buffer.buf()); // Lookup a private const top-level variable. - var = Dart_LookupVariable(lib, Dart_NewString("_d")); + var = Dart_LookupVariable(lib, NewString("_d")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("_d static final", buffer.buf()); // Lookup a instance variable. - var = Dart_LookupVariable(cls, Dart_NewString("a")); + var = Dart_LookupVariable(cls, NewString("a")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("a", buffer.buf()); // Lookup a private instance variable. - var = Dart_LookupVariable(cls, Dart_NewString("_b")); + var = Dart_LookupVariable(cls, NewString("_b")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("_b", buffer.buf()); // Lookup a final instance variable. - var = Dart_LookupVariable(cls, Dart_NewString("c")); + var = Dart_LookupVariable(cls, NewString("c")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("c final", buffer.buf()); // Lookup a private final instance variable. - var = Dart_LookupVariable(cls, Dart_NewString("_d")); + var = Dart_LookupVariable(cls, NewString("_d")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("_d final", buffer.buf()); // Lookup a static variable. - var = Dart_LookupVariable(cls, Dart_NewString("e")); + var = Dart_LookupVariable(cls, NewString("e")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("e static", buffer.buf()); // Lookup a private static variable. - var = Dart_LookupVariable(cls, Dart_NewString("_f")); + var = Dart_LookupVariable(cls, NewString("_f")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("_f static", buffer.buf()); // Lookup a const static variable. - var = Dart_LookupVariable(cls, Dart_NewString("g")); + var = Dart_LookupVariable(cls, NewString("g")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("g static final", buffer.buf()); // Lookup a private const static variable. - var = Dart_LookupVariable(cls, Dart_NewString("_h")); + var = Dart_LookupVariable(cls, NewString("_h")); EXPECT_VALID(var); EXPECT(Dart_IsVariable(var)); BuildVariableDescription(&buffer, var); EXPECT_STREQ("_h static final", buffer.buf()); // Lookup a variable that does not exist from a library. - var = Dart_LookupVariable(lib, Dart_NewString("DoesNotExist")); + var = Dart_LookupVariable(lib, NewString("DoesNotExist")); EXPECT(Dart_IsNull(var)); // Lookup a variable that does not exist from a class. - var = Dart_LookupVariable(cls, Dart_NewString("DoesNotExist")); + var = Dart_LookupVariable(cls, NewString("DoesNotExist")); EXPECT(Dart_IsNull(var)); // Lookup a class from an error library. The error propagates. - var = Dart_LookupVariable(Api::NewError("myerror"), Dart_NewString("foo")); + var = Dart_LookupVariable(Api::NewError("myerror"), NewString("foo")); EXPECT_ERROR(var, "myerror"); // Lookup a class using an error class name. The error propagates. @@ -4837,7 +4807,7 @@ TEST_CASE(TypeVariableReflection) { "}\n"; Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("GenericClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("GenericClass")); EXPECT_VALID(cls); // Test Dart_GetTypeVariableNames. @@ -4850,7 +4820,7 @@ TEST_CASE(TypeVariableReflection) { EXPECT_STREQ("[U, T]", cstr); // Test variable U. - Dart_Handle type_var = Dart_LookupTypeVariable(cls, Dart_NewString("U")); + Dart_Handle type_var = Dart_LookupTypeVariable(cls, NewString("U")); EXPECT_VALID(type_var); EXPECT(Dart_IsTypeVariable(type_var)); Dart_Handle type_var_name = Dart_TypeVariableName(type_var); @@ -4866,7 +4836,7 @@ TEST_CASE(TypeVariableReflection) { EXPECT_STREQ("Object", cstr); // Test variable T. - type_var = Dart_LookupTypeVariable(cls, Dart_NewString("T")); + type_var = Dart_LookupTypeVariable(cls, NewString("T")); EXPECT_VALID(type_var); EXPECT(Dart_IsTypeVariable(type_var)); type_var_name = Dart_TypeVariableName(type_var); @@ -4899,12 +4869,12 @@ TEST_CASE(InstanceOf) { Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); // Fetch InstanceOfTest class. - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest")); + Dart_Handle cls = Dart_GetClass(lib, NewString("InstanceOfTest")); EXPECT_VALID(cls); // Invoke a function which returns an object of type InstanceOf.. Dart_Handle instanceOfTestObj = - Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); + Dart_Invoke(cls, NewString("testMain"), 0, NULL); EXPECT_VALID(instanceOfTestObj); // Now check instanceOfTestObj reported as an instance of @@ -4915,7 +4885,7 @@ TEST_CASE(InstanceOf) { EXPECT(is_instance); // Fetch OtherClass and check if instanceOfTestObj is instance of it. - Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass")); + Dart_Handle otherClass = Dart_GetClass(lib, NewString("OtherClass")); EXPECT_VALID(otherClass); result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); @@ -4923,7 +4893,7 @@ TEST_CASE(InstanceOf) { EXPECT(!is_instance); // Check that primitives are not instances of InstanceOfTest class. - result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass, + result = Dart_ObjectIsType(NewString("a string"), otherClass, &is_instance); EXPECT_VALID(result); EXPECT(!is_instance); @@ -4938,7 +4908,7 @@ TEST_CASE(InstanceOf) { // Check that null is not an instance of InstanceOfTest class. Dart_Handle null = Dart_Invoke(otherClass, - Dart_NewString("returnNull"), + NewString("returnNull"), 0, NULL); EXPECT_VALID(null); @@ -4968,8 +4938,8 @@ TEST_CASE(LoadScript) { "main() {" " return 12345;" "}"; - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); Dart_Handle error = Dart_Error("incoming error"); Dart_Handle result; @@ -5009,7 +4979,7 @@ TEST_CASE(LoadScript) { result = Dart_LoadScript(url, source); EXPECT_VALID(result); - result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); + result = Dart_Invoke(result, NewString("main"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); int64_t value = 0; @@ -5036,8 +5006,8 @@ TEST_CASE(RootLibrary) { EXPECT(Dart_IsNull(root_lib)); // 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)); root_lib = Dart_RootLibrary(); @@ -5090,8 +5060,8 @@ static Dart_Handle import_library_handler(Dart_LibraryTag tag, TEST_CASE(LoadScript_CompileError) { const char* kScriptChars = ")"; - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); EXPECT_VALID(result); result = Dart_LoadScript(url, source); @@ -5109,15 +5079,15 @@ TEST_CASE(LookupLibrary) { "#import('library2.dart');"; // Create a test library and Load up a test script in it. - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); result = Dart_LoadScript(url, source); EXPECT_VALID(result); - url = Dart_NewString("library1.dart"); - source = Dart_NewString(kLibrary1Chars); + url = NewString("library1.dart"); + source = NewString(kLibrary1Chars); result = Dart_LoadLibrary(url, source); EXPECT_VALID(result); @@ -5139,7 +5109,7 @@ TEST_CASE(LookupLibrary) { EXPECT(Dart_IsError(result)); EXPECT_STREQ("incoming error", Dart_GetError(result)); - url = Dart_NewString("noodles.dart"); + url = NewString("noodles.dart"); result = Dart_LookupLibrary(url); EXPECT(Dart_IsError(result)); EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", @@ -5150,8 +5120,8 @@ TEST_CASE(LookupLibrary) { TEST_CASE(LibraryName) { const char* kLibrary1Chars = "#library('library1_name');"; - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib = Dart_LoadLibrary(url, source); Dart_Handle error = Dart_Error("incoming error"); EXPECT_VALID(lib); @@ -5183,8 +5153,8 @@ TEST_CASE(LibraryName) { TEST_CASE(LibraryUrl) { const char* kLibrary1Chars = "#library('library1_name');"; - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib = Dart_LoadLibrary(url, source); Dart_Handle error = Dart_Error("incoming error"); EXPECT_VALID(lib); @@ -5227,8 +5197,8 @@ TEST_CASE(LibraryGetClassNames) { "_compare(String a, String b) => a.compareTo(b);\n" "sort(list) => list.sort(_compare);\n"; - Dart_Handle url = Dart_NewString("library_url"); - Dart_Handle source = Dart_NewString(kLibraryChars); + Dart_Handle url = NewString("library_url"); + Dart_Handle source = NewString(kLibraryChars); Dart_Handle lib = Dart_LoadLibrary(url, source); EXPECT_VALID(lib); @@ -5240,7 +5210,7 @@ TEST_CASE(LibraryGetClassNames) { const int kNumArgs = 1; Dart_Handle args[1]; args[0] = list; - EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); + EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); Dart_Handle list_string = Dart_ToString(list); EXPECT_VALID(list_string); @@ -5278,8 +5248,8 @@ TEST_CASE(GetFunctionNames) { "sort(list) => list.sort(_compare);\n"; // Get the functions from a library. - Dart_Handle url = Dart_NewString("library_url"); - Dart_Handle source = Dart_NewString(kLibraryChars); + Dart_Handle url = NewString("library_url"); + Dart_Handle source = NewString(kLibraryChars); Dart_Handle lib = Dart_LoadLibrary(url, source); EXPECT_VALID(lib); @@ -5291,7 +5261,7 @@ TEST_CASE(GetFunctionNames) { const int kNumArgs = 1; Dart_Handle args[1]; args[0] = list; - EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); + EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); Dart_Handle list_string = Dart_ToString(list); EXPECT_VALID(list_string); @@ -5300,7 +5270,7 @@ TEST_CASE(GetFunctionNames) { EXPECT_STREQ("[A, B, C=, _A, _B, _C=, _compare, sort]", list_cstr); // Get the functions from a class. - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); EXPECT_VALID(cls); list = Dart_GetFunctionNames(cls); @@ -5309,7 +5279,7 @@ TEST_CASE(GetFunctionNames) { // Sort the list. args[0] = list; - EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); + EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); // Check list contents. list_string = Dart_ToString(list); @@ -5342,8 +5312,8 @@ TEST_CASE(GetVariableNames) { "sort(list) => list.sort(_compare);\n"; // Get the variables from a library. - Dart_Handle url = Dart_NewString("library_url"); - Dart_Handle source = Dart_NewString(kLibraryChars); + Dart_Handle url = NewString("library_url"); + Dart_Handle source = NewString(kLibraryChars); Dart_Handle lib = Dart_LoadLibrary(url, source); EXPECT_VALID(lib); @@ -5355,7 +5325,7 @@ TEST_CASE(GetVariableNames) { const int kNumArgs = 1; Dart_Handle args[1]; args[0] = list; - EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); + EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); // Check list contents. Dart_Handle list_string = Dart_ToString(list); @@ -5365,7 +5335,7 @@ TEST_CASE(GetVariableNames) { EXPECT_STREQ("[A, _A]", list_cstr); // Get the variables from a class. - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); EXPECT_VALID(cls); list = Dart_GetVariableNames(cls); @@ -5374,7 +5344,7 @@ TEST_CASE(GetVariableNames) { // Sort the list. args[0] = list; - EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); + EXPECT_VALID(Dart_Invoke(lib, NewString("sort"), kNumArgs, args)); // Check list contents. list_string = Dart_ToString(list); @@ -5393,13 +5363,13 @@ TEST_CASE(LibraryImportLibrary) { Dart_Handle error = Dart_Error("incoming error"); Dart_Handle result; - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib1 = Dart_LoadLibrary(url, source); EXPECT_VALID(lib1); - url = Dart_NewString("library2_url"); - source = Dart_NewString(kLibrary2Chars); + url = NewString("library2_url"); + source = NewString(kLibrary2Chars); Dart_Handle lib2 = Dart_LoadLibrary(url, source); EXPECT_VALID(lib2); @@ -5444,8 +5414,8 @@ TEST_CASE(ImportLibraryWithPrefix) { const char* kLibrary1Chars = "#library('library1_name');" "int bar() => 42;"; - Dart_Handle url1 = Dart_NewString("library1_url"); - Dart_Handle source1 = Dart_NewString(kLibrary1Chars); + Dart_Handle url1 = NewString("library1_url"); + Dart_Handle source1 = NewString(kLibrary1Chars); Dart_Handle lib1 = Dart_LoadLibrary(url1, source1); EXPECT_VALID(lib1); EXPECT(Dart_IsLibrary(lib1)); @@ -5453,24 +5423,24 @@ TEST_CASE(ImportLibraryWithPrefix) { const char* kLibrary2Chars = "#library('library2_name');" "int foobar() => foo.bar();"; - Dart_Handle url2 = Dart_NewString("library2_url"); - Dart_Handle source2 = Dart_NewString(kLibrary2Chars); + Dart_Handle url2 = NewString("library2_url"); + Dart_Handle source2 = NewString(kLibrary2Chars); Dart_Handle lib2 = Dart_LoadLibrary(url2, source2); EXPECT_VALID(lib2); EXPECT(Dart_IsLibrary(lib2)); - Dart_Handle prefix = Dart_NewString("foo"); + Dart_Handle prefix = NewString("foo"); Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); EXPECT_VALID(result); // Lib1 is imported under a library prefix and therefore 'foo' should // not be found directly in lib2. - Dart_Handle method_name = Dart_NewString("foo"); + Dart_Handle method_name = NewString("foo"); result = Dart_Invoke(lib2, method_name, 0, NULL); EXPECT_ERROR(result, "Dart_Invoke: did not find top-level function 'foo'"); // Check that lib1 is available under the prefix in lib2. - method_name = Dart_NewString("foobar"); + method_name = NewString("foobar"); result = Dart_Invoke(lib2, method_name, 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); @@ -5487,8 +5457,8 @@ TEST_CASE(LoadLibrary) { Dart_Handle error = Dart_Error("incoming error"); Dart_Handle result; - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); result = Dart_LoadLibrary(Dart_Null(), source); EXPECT(Dart_IsError(result)); @@ -5537,8 +5507,8 @@ TEST_CASE(LoadLibrary_CompileError) { const char* kLibrary1Chars = "#library('library1_name');" ")"; - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle result = Dart_LoadLibrary(url, source); EXPECT(Dart_IsError(result)); EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); @@ -5556,14 +5526,14 @@ TEST_CASE(LoadSource) { Dart_Handle result; // Load up a library. - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib = Dart_LoadLibrary(url, source); EXPECT_VALID(lib); EXPECT(Dart_IsLibrary(lib)); - url = Dart_NewString("source_url"); - source = Dart_NewString(kSourceChars); + url = NewString("source_url"); + source = NewString(kSourceChars); result = Dart_LoadSource(Dart_Null(), url, source); EXPECT(Dart_IsError(result)); @@ -5622,7 +5592,7 @@ TEST_CASE(LoadSource) { EXPECT(Dart_IdentityEquals(lib, result)); // Language errors are detected. - source = Dart_NewString(kBadSourceChars); + source = NewString(kBadSourceChars); result = Dart_LoadSource(lib, url, source); EXPECT(Dart_IsError(result)); } @@ -5638,17 +5608,17 @@ TEST_CASE(LoadSource_LateLoad) { "class NewClass extends OldClass{\n" " bar() => 'bar';\n" "}\n"; - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib = Dart_LoadLibrary(url, source); EXPECT_VALID(lib); EXPECT(Dart_IsLibrary(lib)); // Call a dynamic function on OldClass. - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("OldClass")); + Dart_Handle cls = Dart_GetClass(lib, NewString("OldClass")); EXPECT_VALID(cls); Dart_Handle recv = Dart_New(cls, Dart_Null(), 0, NULL); - Dart_Handle result = Dart_Invoke(recv, Dart_NewString("foo"), 0, NULL); + Dart_Handle result = Dart_Invoke(recv, NewString("foo"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsString(result)); const char* result_cstr = ""; @@ -5656,15 +5626,15 @@ TEST_CASE(LoadSource_LateLoad) { EXPECT_STREQ("foo", result_cstr); // Load a source file late. - url = Dart_NewString("source_url"); - source = Dart_NewString(kSourceChars); + url = NewString("source_url"); + source = NewString(kSourceChars); EXPECT_VALID(Dart_LoadSource(lib, url, source)); // Call a dynamic function on NewClass in the updated library. - cls = Dart_GetClass(lib, Dart_NewString("NewClass")); + cls = Dart_GetClass(lib, NewString("NewClass")); EXPECT_VALID(cls); recv = Dart_New(cls, Dart_Null(), 0, NULL); - result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL); + result = Dart_Invoke(recv, NewString("bar"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsString(result)); result_cstr = ""; @@ -5682,25 +5652,25 @@ TEST_CASE(LoadPatch) { "patch int foo() => 42;"; // Load up a library. - Dart_Handle url = Dart_NewString("library1_url"); - Dart_Handle source = Dart_NewString(kLibrary1Chars); + Dart_Handle url = NewString("library1_url"); + Dart_Handle source = NewString(kLibrary1Chars); Dart_Handle lib = Dart_LoadLibrary(url, source); EXPECT_VALID(lib); EXPECT(Dart_IsLibrary(lib)); - url = Dart_NewString("source_url"); - source = Dart_NewString(kSourceChars); + url = NewString("source_url"); + source = NewString(kSourceChars); Dart_Handle result = Dart_LoadSource(lib, url, source); EXPECT_VALID(result); - url = Dart_NewString("patch_url"); - source = Dart_NewString(kPatchChars); + url = NewString("patch_url"); + source = NewString(kPatchChars); result = Dart_LoadPatch(lib, url, source); EXPECT_VALID(result); - result = Dart_Invoke(lib, Dart_NewString("foo"), 0, NULL); + result = Dart_Invoke(lib, NewString("foo"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); int64_t value = 0; @@ -5789,8 +5759,8 @@ TEST_CASE(ParsePatchLibrary) { Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); - Dart_Handle url = Dart_NewString("theLibrary"); - Dart_Handle source = Dart_NewString(kLibraryChars); + Dart_Handle url = NewString("theLibrary"); + Dart_Handle source = NewString(kLibraryChars); result = Dart_LoadLibrary(url, source); EXPECT_VALID(result); @@ -5809,8 +5779,8 @@ TEST_CASE(ParsePatchLibrary) { result = Dart_SetNativeResolver(result, &PatchNativeResolver); EXPECT_VALID(result); - Dart_Handle script_url = Dart_NewString("theScript"); - source = Dart_NewString(kScriptChars); + Dart_Handle script_url = NewString("theScript"); + source = NewString(kScriptChars); Dart_Handle test_script = Dart_LoadScript(script_url, source); EXPECT_VALID(test_script); @@ -5818,43 +5788,43 @@ TEST_CASE(ParsePatchLibrary) { result = Dart_CompileAll(); EXPECT_VALID(result); - result = Dart_Invoke(test_script, Dart_NewString("e1"), 0, NULL); + result = Dart_Invoke(test_script, NewString("e1"), 0, NULL); EXPECT_ERROR(result, "No such method: 'unpatched'"); int64_t value = 0; - result = Dart_Invoke(test_script, Dart_NewString("m1"), 0, NULL); + result = Dart_Invoke(test_script, NewString("m1"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); EXPECT_VALID(Dart_IntegerToInt64(result, &value)); EXPECT_EQ(4, value); value = 0; - result = Dart_Invoke(test_script, Dart_NewString("m2"), 0, NULL); + result = Dart_Invoke(test_script, NewString("m2"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); EXPECT_VALID(Dart_IntegerToInt64(result, &value)); EXPECT_EQ(40, value); value = 0; - result = Dart_Invoke(test_script, Dart_NewString("m3"), 0, NULL); + result = Dart_Invoke(test_script, NewString("m3"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); EXPECT_VALID(Dart_IntegerToInt64(result, &value)); EXPECT_EQ(21, value); value = 0; - result = Dart_Invoke(test_script, Dart_NewString("m4"), 0, NULL); + result = Dart_Invoke(test_script, NewString("m4"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); EXPECT_VALID(Dart_IntegerToInt64(result, &value)); EXPECT_EQ(-25, value); - result = Dart_Invoke(test_script, Dart_NewString("m5"), 0, NULL); + result = Dart_Invoke(test_script, NewString("m5"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsNull(result)); value = 0; - result = Dart_Invoke(test_script, Dart_NewString("m6"), 0, NULL); + result = Dart_Invoke(test_script, NewString("m6"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); EXPECT_VALID(Dart_IntegerToInt64(result, &value)); @@ -5899,14 +5869,14 @@ TEST_CASE(SetNativeResolver) { Dart_Handle result; // Load a test 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); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); Dart_Handle lib = Dart_LoadScript(url, source); EXPECT_VALID(lib); EXPECT(Dart_IsLibrary(lib)); - Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Test")); + Dart_Handle cls = Dart_GetClass(lib, NewString("Test")); EXPECT_VALID(cls); result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); @@ -5929,7 +5899,7 @@ TEST_CASE(SetNativeResolver) { EXPECT_VALID(result); // Call a function and make sure native resolution works. - result = Dart_Invoke(cls, Dart_NewString("foo"), 0, NULL); + result = Dart_Invoke(cls, NewString("foo"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); int64_t value = 0; @@ -5941,7 +5911,7 @@ TEST_CASE(SetNativeResolver) { EXPECT_VALID(result); // 'foo' has already been resolved so gets the old value. - result = Dart_Invoke(cls, Dart_NewString("foo"), 0, NULL); + result = Dart_Invoke(cls, NewString("foo"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); value = 0; @@ -5949,7 +5919,7 @@ TEST_CASE(SetNativeResolver) { EXPECT_EQ(654321, value); // 'bar' has not yet been resolved so gets the new value. - result = Dart_Invoke(cls, Dart_NewString("bar"), 0, NULL); + result = Dart_Invoke(cls, NewString("bar"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); value = 0; @@ -5960,7 +5930,7 @@ TEST_CASE(SetNativeResolver) { result = Dart_SetNativeResolver(lib, NULL); EXPECT_VALID(result); - EXPECT_ERROR(Dart_Invoke(cls, Dart_NewString("baz"), 0, NULL), + EXPECT_ERROR(Dart_Invoke(cls, NewString("baz"), 0, NULL), "native function 'SomeNativeFunction3' cannot be found"); } @@ -5982,21 +5952,21 @@ TEST_CASE(ImportLibrary2) { "var foo;\n"; Dart_Handle result; // Create a test library and Load up a test script in it. - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); result = Dart_LoadScript(url, source); - url = Dart_NewString("library1.dart"); - source = Dart_NewString(kLibrary1Chars); + url = NewString("library1.dart"); + source = NewString(kLibrary1Chars); Dart_LoadLibrary(url, source); - url = Dart_NewString("library2.dart"); - source = Dart_NewString(kLibrary2Chars); + url = NewString("library2.dart"); + source = NewString(kLibrary2Chars); Dart_LoadLibrary(url, source); - result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); + result = Dart_Invoke(result, NewString("main"), 0, NULL); EXPECT_VALID(result); } @@ -6018,22 +5988,22 @@ TEST_CASE(ImportLibrary3) { Dart_Handle result; // Create a test library and Load up a test script in it. - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); result = Dart_LoadScript(url, source); EXPECT_VALID(result); - url = Dart_NewString("library2.dart"); - source = Dart_NewString(kLibrary2Chars); + url = NewString("library2.dart"); + source = NewString(kLibrary2Chars); Dart_LoadLibrary(url, source); - url = Dart_NewString("library1.dart"); - source = Dart_NewString(kLibrary1Chars); + url = NewString("library1.dart"); + source = NewString(kLibrary1Chars); Dart_LoadLibrary(url, source); - result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); + result = Dart_Invoke(result, NewString("main"), 0, NULL); EXPECT(Dart_IsError(result)); EXPECT_SUBSTRING("ambiguous reference: 'foo'", Dart_GetError(result)); } @@ -6055,22 +6025,22 @@ TEST_CASE(ImportLibrary4) { Dart_Handle result; // Create a test library and Load up a test script in it. - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); result = Dart_LoadScript(url, source); EXPECT_VALID(result); - url = Dart_NewString("library2.dart"); - source = Dart_NewString(kLibrary2Chars); + url = NewString("library2.dart"); + source = NewString(kLibrary2Chars); Dart_LoadLibrary(url, source); - url = Dart_NewString("library1.dart"); - source = Dart_NewString(kLibrary1Chars); + url = NewString("library1.dart"); + source = NewString(kLibrary1Chars); Dart_LoadLibrary(url, source); - result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); + result = Dart_Invoke(result, NewString("main"), 0, NULL); EXPECT_VALID(result); } @@ -6090,17 +6060,17 @@ TEST_CASE(ImportLibrary5) { Dart_Handle result; // Create a test library and Load up a test script in it. - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); result = Dart_LoadScript(url, source); - url = Dart_NewString("lib.dart"); - source = Dart_NewString(kLibraryChars); + url = NewString("lib.dart"); + source = NewString(kLibraryChars); Dart_LoadLibrary(url, source); - result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); + result = Dart_Invoke(result, NewString("main"), 0, NULL); EXPECT_VALID(result); } @@ -6170,7 +6140,7 @@ UNIT_TEST_CASE(NewNativePort) { Dart_Handle dart_args[1]; dart_args[0] = send_port1; Dart_Handle result = - Dart_Invoke(lib, Dart_NewString("callPort"), 1, dart_args); + Dart_Invoke(lib, NewString("callPort"), 1, dart_args); EXPECT_VALID(result); result = Dart_RunLoop(); EXPECT(Dart_IsError(result)); @@ -6179,7 +6149,7 @@ UNIT_TEST_CASE(NewNativePort) { // result second port. dart_args[0] = send_port2; - result = Dart_Invoke(lib, Dart_NewString("callPort"), 1, dart_args); + result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); EXPECT_VALID(result); result = Dart_RunLoop(); EXPECT(Dart_IsError(result)); @@ -6226,8 +6196,8 @@ static bool RunLoopTestCallback(const char* script_name, Dart_Isolate isolate = TestCase::CreateTestIsolate(); ASSERT(isolate != NULL); Dart_EnterScope(); - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); EXPECT_VALID(result); Dart_Handle lib = Dart_LoadScript(url, source); @@ -6245,14 +6215,14 @@ static void RunLoopTest(bool throw_exception_child, RunLoopTestCallback(NULL, NULL, NULL, NULL); Dart_EnterScope(); - Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); + Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); EXPECT_VALID(lib); Dart_Handle result; Dart_Handle args[2]; args[0] = (throw_exception_child ? Dart_True() : Dart_False()); args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); - result = Dart_Invoke(lib, Dart_NewString("main"), 2, args); + result = Dart_Invoke(lib, NewString("main"), 2, args); EXPECT_VALID(result); result = Dart_RunLoop(); if (throw_exception_parent) { @@ -6329,8 +6299,8 @@ void BusyLoop_start(uword unused) { shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); EXPECT(shared_isolate != NULL); Dart_EnterScope(); - Dart_Handle url = Dart_NewString(TestCase::url()); - Dart_Handle source = Dart_NewString(kScriptChars); + Dart_Handle url = NewString(TestCase::url()); + Dart_Handle source = NewString(kScriptChars); Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); EXPECT_VALID(result); lib = Dart_LoadScript(url, source); @@ -6342,7 +6312,7 @@ void BusyLoop_start(uword unused) { sync->Exit(); } - Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); + Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); EXPECT(Dart_IsError(result)); EXPECT(Dart_ErrorHasException(result)); EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", @@ -6374,9 +6344,9 @@ static bool IsolateInterruptTestCallback() { } if (interrupt_count == kInterruptCount) { Dart_EnterScope(); - Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); + Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); EXPECT_VALID(lib); - Dart_Handle exc = Dart_NewString("foo"); + Dart_Handle exc = NewString("foo"); EXPECT_VALID(exc); Dart_Handle result = Dart_ThrowException(exc); EXPECT_VALID(result); @@ -6597,8 +6567,8 @@ TEST_CASE(NativeFunctionClosure) { Dart_Handle result; // Load a test 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); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); Dart_Handle lib = Dart_LoadScript(url, source); @@ -6607,7 +6577,7 @@ TEST_CASE(NativeFunctionClosure) { result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver); EXPECT_VALID(result); - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); int64_t value = 0; @@ -6735,8 +6705,8 @@ TEST_CASE(NativeStaticFunctionClosure) { Dart_Handle result; // Load a test 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); result = Dart_SetLibraryTagHandler(library_handler); EXPECT_VALID(result); Dart_Handle lib = Dart_LoadScript(url, source); @@ -6745,7 +6715,7 @@ TEST_CASE(NativeStaticFunctionClosure) { result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver); EXPECT_VALID(result); - result = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); + result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); EXPECT_VALID(result); EXPECT(Dart_IsInteger(result)); int64_t value = 0; @@ -6763,37 +6733,37 @@ TEST_CASE(RangeLimits) { "expects argument 'length' to be in the range"); EXPECT_ERROR(Dart_NewList(Array::kMaxElements+1), "expects argument 'length' to be in the range"); - EXPECT_ERROR(Dart_NewString8(chars8, -1), + EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, -1), "expects argument 'length' to be in the range"); - EXPECT_ERROR(Dart_NewString8(chars8, OneByteString::kMaxElements+1), + EXPECT_ERROR(Dart_NewStringFromUTF8(chars8, OneByteString::kMaxElements+1), "expects argument 'length' to be in the range"); - EXPECT_ERROR(Dart_NewString16(chars16, -1), + EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, -1), "expects argument 'length' to be in the range"); - EXPECT_ERROR(Dart_NewString16(chars16, TwoByteString::kMaxElements+1), + EXPECT_ERROR(Dart_NewStringFromUTF16(chars16, TwoByteString::kMaxElements+1), "expects argument 'length' to be in the range"); - EXPECT_ERROR(Dart_NewString32(chars32, -1), + EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, -1), "expects argument 'length' to be in the range"); - EXPECT_ERROR(Dart_NewString32(chars32, FourByteString::kMaxElements+1), + EXPECT_ERROR(Dart_NewStringFromUTF32(chars32, TwoByteString::kMaxElements+1), "expects argument 'length' to be in the range"); } TEST_CASE(NewString_Null) { - Dart_Handle str = Dart_NewString8(NULL, 0); + Dart_Handle str = Dart_NewStringFromUTF8(NULL, 0); EXPECT_VALID(str); EXPECT(Dart_IsString(str)); intptr_t len = -1; EXPECT_VALID(Dart_StringLength(str, &len)); EXPECT_EQ(0, len); - str = Dart_NewString16(NULL, 0); + str = Dart_NewStringFromUTF16(NULL, 0); EXPECT_VALID(str); EXPECT(Dart_IsString(str)); len = -1; EXPECT_VALID(Dart_StringLength(str, &len)); EXPECT_EQ(0, len); - str = Dart_NewString32(NULL, 0); + str = Dart_NewStringFromUTF32(NULL, 0); EXPECT_VALID(str); EXPECT(Dart_IsString(str)); len = -1; @@ -6839,7 +6809,7 @@ TEST_CASE(InvalidGetSetPeer) { // by one. TEST_CASE(OneNewSpacePeer) { Isolate* isolate = Isolate::Current(); - Dart_Handle str = Dart_NewString("a string"); + Dart_Handle str = NewString("a string"); EXPECT_VALID(str); EXPECT(Dart_IsString(str)); EXPECT_EQ(0, isolate->heap()->PeerCount()); @@ -6868,7 +6838,7 @@ TEST_CASE(CollectOneNewSpacePeer) { Dart_EnterScope(); { DARTSCOPE_NOCHECKS(isolate); - Dart_Handle str = Dart_NewString("a string"); + Dart_Handle str = NewString("a string"); EXPECT_VALID(str); EXPECT(Dart_IsString(str)); EXPECT_EQ(0, isolate->heap()->PeerCount()); @@ -6898,7 +6868,7 @@ TEST_CASE(CollectOneNewSpacePeer) { // by two. TEST_CASE(TwoNewSpacePeers) { Isolate* isolate = Isolate::Current(); - Dart_Handle s1 = Dart_NewString("s1"); + Dart_Handle s1 = NewString("s1"); EXPECT_VALID(s1); EXPECT(Dart_IsString(s1)); void* o1 = &o1; @@ -6910,7 +6880,7 @@ TEST_CASE(TwoNewSpacePeers) { EXPECT_EQ(1, isolate->heap()->PeerCount()); EXPECT_VALID(Dart_GetPeer(s1, &o1)); EXPECT(o1 == reinterpret_cast(&p1)); - Dart_Handle s2 = Dart_NewString("a string"); + Dart_Handle s2 = NewString("a string"); EXPECT_VALID(s2); EXPECT(Dart_IsString(s2)); EXPECT_EQ(1, isolate->heap()->PeerCount()); @@ -6941,7 +6911,7 @@ TEST_CASE(CollectTwoNewSpacePeers) { Dart_EnterScope(); { DARTSCOPE_NOCHECKS(isolate); - Dart_Handle s1 = Dart_NewString("s1"); + Dart_Handle s1 = NewString("s1"); EXPECT_VALID(s1); EXPECT(Dart_IsString(s1)); EXPECT_EQ(0, isolate->heap()->PeerCount()); @@ -6953,7 +6923,7 @@ TEST_CASE(CollectTwoNewSpacePeers) { EXPECT_EQ(1, isolate->heap()->PeerCount()); EXPECT_VALID(Dart_GetPeer(s1, &o1)); EXPECT(o1 == reinterpret_cast(&p1)); - Dart_Handle s2 = Dart_NewString("s2"); + Dart_Handle s2 = NewString("s2"); EXPECT_VALID(s2); EXPECT(Dart_IsString(s2)); EXPECT_EQ(1, isolate->heap()->PeerCount()); @@ -6979,7 +6949,7 @@ TEST_CASE(CopyNewSpacePeers) { Isolate* isolate = Isolate::Current(); Dart_Handle s[kPeerCount]; for (int i = 0; i < kPeerCount; ++i) { - s[i] = Dart_NewString("a string"); + s[i] = NewString("a string"); EXPECT_VALID(s[i]); EXPECT(Dart_IsString(s[i])); void* o = &o; @@ -7008,7 +6978,7 @@ TEST_CASE(CopyNewSpacePeers) { // of peer objects is decremented by one. TEST_CASE(OnePromotedPeer) { Isolate* isolate = Isolate::Current(); - Dart_Handle str = Dart_NewString("a string"); + Dart_Handle str = NewString("a string"); EXPECT_VALID(str); EXPECT(Dart_IsString(str)); EXPECT_EQ(0, isolate->heap()->PeerCount()); diff --git a/runtime/vm/dart_api_message.cc b/runtime/vm/dart_api_message.cc index 9c12280fd69..7541536cdf6 100644 --- a/runtime/vm/dart_api_message.cc +++ b/runtime/vm/dart_api_message.cc @@ -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); diff --git a/runtime/vm/debugger_api_impl_test.cc b/runtime/vm/debugger_api_impl_test.cc index 3a3a3668eb9..4bf3e9c44fc 100644 --- a/runtime/vm/debugger_api_impl_test.cc +++ b/runtime/vm/debugger_api_impl_test.cc @@ -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(); diff --git a/runtime/vm/exceptions_test.cc b/runtime/vm/exceptions_test.cc index 9111615ce34..ef319de9a34 100644 --- a/runtime/vm/exceptions_test.cc +++ b/runtime/vm/exceptions_test.cc @@ -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(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). diff --git a/runtime/vm/flow_graph_compiler.cc b/runtime/vm/flow_graph_compiler.cc index d4ad720b865..812d968a3c3 100644 --- a/runtime/vm/flow_graph_compiler.cc +++ b/runtime/vm/flow_graph_compiler.cc @@ -539,10 +539,8 @@ void FlowGraphCompiler::GenerateStringTypeCheck(Register kClassIdReg, GrowableArray 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); } diff --git a/runtime/vm/heap_profiler.cc b/runtime/vm/heap_profiler.cc index e5950675a76..f218a816f0e 100644 --- a/runtime/vm/heap_profiler.cc +++ b/runtime/vm/heap_profiler.cc @@ -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(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(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(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)); diff --git a/runtime/vm/heap_test.cc b/runtime/vm/heap_test.cc index 440cddaab57..0a487e5b724 100644 --- a/runtime/vm/heap_test.cc +++ b/runtime/vm/heap_test.cc @@ -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)); diff --git a/runtime/vm/isolate_test.cc b/runtime/vm/isolate_test.cc index 3d626f70c78..2aadf6d24e3 100644 --- a/runtime/vm/isolate_test.cc +++ b/runtime/vm/isolate_test.cc @@ -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); diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 67e756dfe94..342bbcac101 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -612,12 +612,6 @@ RawError* Object::Init(Isolate* isolate) { RegisterPrivateClass(cls, name, core_lib); pending_classes.Add(cls, Heap::kOld); - cls = Class::New(); - 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(); 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(); - 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(); object_store->set_stacktrace_class(cls); name = Symbols::Stacktrace(); @@ -1103,18 +1091,12 @@ void Object::InitFromSnapshot(Isolate* isolate) { cls = Class::New(); object_store->set_two_byte_string_class(cls); - cls = Class::New(); - object_store->set_four_byte_string_class(cls); - cls = Class::New(); object_store->set_external_one_byte_string_class(cls); cls = Class::New(); object_store->set_external_two_byte_string_class(cls); - cls = Class::New(); - object_store->set_external_four_byte_string_class(cls); - cls = Class::New(); 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(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(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(len + 1); - Utf8::Encode(*this, result, len); + uint8_t* result = zone->Alloc(len + 1); + ToUTF8(result, len); result[len] = 0; - return result; + return reinterpret_cast(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(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* external_data = - new ExternalStringData(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*>(peer); - DeleteWeakPersistentHandle(handle); -} - - -const char* ExternalFourByteString::ToCString() const { - return String::ToCString(); -} - - RawBool* Bool::True() { return Isolate::Current()->object_store()->true_value(); } diff --git a/runtime/vm/object.h b/runtime/vm/object.h index d79c2868596..4052ba4c41c 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -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* 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: diff --git a/runtime/vm/object_store.cc b/runtime/vm/object_store.cc index 63ea281c133..970ad17ba8a 100644 --- a/runtime/vm/object_store.cc +++ b/runtime/vm/object_store.cc @@ -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()), diff --git a/runtime/vm/object_store.h b/runtime/vm/object_store.h index 75ae4162631..f59d78c191b 100644 --- a/runtime/vm/object_store.h +++ b/runtime/vm/object_store.h @@ -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_; diff --git a/runtime/vm/object_test.cc b/runtime/vm/object_test.cc index 6bcf17c5deb..9347a569772 100644 --- a/runtime/vm/object_test.cc +++ b/runtime/vm/object_test.cc @@ -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" diff --git a/runtime/vm/raw_object.cc b/runtime/vm/raw_object.cc index 2d41d746d61..582c6494b5f 100644 --- a/runtime/vm/raw_object.cc +++ b/runtime/vm/raw_object.cc @@ -101,13 +101,6 @@ intptr_t RawObject::SizeFromClass() const { instance_size = TwoByteString::InstanceSize(string_length); break; } - case kFourByteStringCid: { - const RawFourByteString* raw_string = - reinterpret_cast(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(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. diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h index 1fc850f69e7..af0143860ae 100644 --- a/runtime/vm/raw_object.h +++ b/runtime/vm/raw_object.h @@ -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 class ExternalStringData { public: @@ -1175,14 +1163,6 @@ class RawExternalTwoByteString : public RawString { }; -class RawExternalFourByteString : public RawString { - RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalFourByteString); - - ExternalStringData* 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 && diff --git a/runtime/vm/raw_object_snapshot.cc b/runtime/vm/raw_object_snapshot.cc index 036bec19c52..fd671491c3d 100644 --- a/runtime/vm/raw_object_snapshot.cc +++ b/runtime/vm/raw_object_snapshot.cc @@ -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(); - raw_ptr += 1; - } - ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); - } else { - ReadFromImpl(reader, &str_obj, len, tags, kind); - } - reader->AddBackRef(object_id, &str_obj, kIsDeserialized); - return str_obj.raw(); -} - - template 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, diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc index 12aad9e2a29..77204f33ba6 100644 --- a/runtime/vm/snapshot.cc +++ b/runtime/vm/snapshot.cc @@ -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(), diff --git a/runtime/vm/snapshot.h b/runtime/vm/snapshot.h index 44c19fe84be..fba122a811d 100644 --- a/runtime/vm/snapshot.h +++ b/runtime/vm/snapshot.h @@ -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); diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc index 9d8514a42bb..3e84b599c12 100644 --- a/runtime/vm/snapshot_test.cc +++ b/runtime/vm/snapshot_test.cc @@ -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; diff --git a/runtime/vm/stack_frame_test.cc b/runtime/vm/stack_frame_test.cc index f011e6c759d..4348fc6dd11 100644 --- a/runtime/vm/stack_frame_test.cc +++ b/runtime/vm/stack_frame_test.cc @@ -240,8 +240,8 @@ TEST_CASE(ValidateStackFrameIteration) { Dart_Handle lib = TestCase::LoadTestScript( kScriptChars, reinterpret_cast(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(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. diff --git a/runtime/vm/symbols.cc b/runtime/vm/symbols.cc index bfb2bea7543..3547f87c600 100644 --- a/runtime/vm/symbols.cc +++ b/runtime/vm/symbols.cc @@ -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(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(NULL), 0); - } else if (width == 1) { + } + if (type == Utf8::kAscii) { uint8_t* characters = zone->Alloc(len); - Utf8::Decode(str, characters, len); - return New(characters, len); - } else if (width == 2) { - uint16_t* characters = zone->Alloc(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(len); - Utf8::Decode(str, characters, len); + ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); + uint16_t* characters = zone->Alloc(len); + Utf8::DecodeToUTF16(utf8_array, str_len, characters, len); return New(characters, len); } diff --git a/runtime/vm/symbols.h b/runtime/vm/symbols.h index 3dd49252d6e..36c4b906bda 100644 --- a/runtime/vm/symbols.h +++ b/runtime/vm/symbols.h @@ -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") \ diff --git a/runtime/vm/unicode.cc b/runtime/vm/unicode.cc index d9dca3e45cf..42cd42607c2 100644 --- a/runtime/vm/unicode.cc +++ b/runtime/vm/unicode.cc @@ -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 -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 diff --git a/runtime/vm/unicode.h b/runtime/vm/unicode.h index ef6b1e354f2..ce572dc633e 100644 --- a/runtime/vm/unicode.h +++ b/runtime/vm/unicode.h @@ -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(str); + return DecodeToUTF32(utf8_array, array_len, dst, len); + } }; diff --git a/runtime/vm/unicode_test.cc b/runtime/vm/unicode_test.cc index 92c09f7c39d..967e9caaccb 100644 --- a/runtime/vm/unicode_test.cc +++ b/runtime/vm/unicode_test.cc @@ -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))); } diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc index 4f10eae995e..6b0594f1312 100644 --- a/runtime/vm/unit_test.cc +++ b/runtime/vm/unit_test.cc @@ -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)); diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h index 1a21e38fcd6..713c2729fdd 100644 --- a/runtime/vm/unit_test.h +++ b/runtime/vm/unit_test.h @@ -132,6 +132,11 @@ } +inline Dart_Handle NewString(const char* str) { + return Dart_NewStringFromCString(str); +} + + namespace dart { // Forward declarations. diff --git a/tests/co19/co19-dart2js.status b/tests/co19/co19-dart2js.status index 7e2f8bd08f9..e16ed9ce9ed 100644 --- a/tests/co19/co19-dart2js.status +++ b/tests/co19/co19-dart2js.status @@ -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 diff --git a/tests/co19/co19-runtime.status b/tests/co19/co19-runtime.status index c971c1c534a..2d6e5702348 100644 --- a/tests/co19/co19-runtime.status +++ b/tests/co19/co19-runtime.status @@ -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 diff --git a/tests/language/char_escape_test.dart b/tests/language/char_escape_test.dart index 18a0f471a47..a890e4d7c25 100644 --- a/tests/language/char_escape_test.dart +++ b/tests/language/char_escape_test.dart @@ -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"; diff --git a/tests/utils/utils.status b/tests/utils/utils.status index 65640cc2d62..d06160be5d2 100644 --- a/tests/utils/utils.status +++ b/tests/utils/utils.status @@ -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