Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Unified Diff: mojo/dart/embedder/mojo_io_natives.cc

Issue 1786473004: Rolls Dart runtime forward. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: whitespace Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/dart/embedder/io/filter_patch.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/dart/embedder/mojo_io_natives.cc
diff --git a/mojo/dart/embedder/mojo_io_natives.cc b/mojo/dart/embedder/mojo_io_natives.cc
index 80f283a8875aed4052cdeec5005325151195215c..dee0dbe577413a4cc3634314685694a633c21f2a 100644
--- a/mojo/dart/embedder/mojo_io_natives.cc
+++ b/mojo/dart/embedder/mojo_io_natives.cc
@@ -20,7 +20,6 @@ namespace dart {
#define MOJO_IO_NATIVE_LIST(V) \
V(Filter_CreateZLibDeflate, 8) \
V(Filter_CreateZLibInflate, 4) \
- V(Filter_End, 1) \
V(Filter_Process, 4) \
V(Filter_Processed, 3) \
V(InternetAddress_Parse, 1) \
@@ -115,128 +114,148 @@ class IOBuffer {
DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer);
};
-static Filter* GetFilter(Dart_Handle filter_obj) {
- Filter* filter;
- Dart_Handle result = Filter::GetFilterPointerNativeField(filter_obj, &filter);
- if (Dart_IsError(result)) {
- Dart_PropagateError(result);
+static Dart_Handle GetFilter(Dart_Handle filter_obj, Filter** filter) {
+ CHECK(filter != NULL);
+ Filter* result;
+ Dart_Handle err = Filter::GetFilterNativeField(filter_obj, &result);
+ if (Dart_IsError(err)) {
+ return err;
}
- if (filter == NULL) {
- Dart_ThrowException(DartEmbedder::NewInternalError("Filter destroyed"));
+ if (result == NULL) {
+ return Dart_NewApiError("Filter was destroyed");
}
- return filter;
-}
-static void EndFilter(Dart_Handle filter_obj, Filter* filter) {
- Filter::SetFilterPointerNativeField(filter_obj, NULL);
- delete filter;
+ *filter = result;
+ return Dart_Null();
}
-static uint8_t* copyDictionary(Dart_Handle dictionary_obj) {
+static Dart_Handle CopyDictionary(Dart_Handle dictionary_obj,
+ uint8_t** dictionary) {
+ CHECK(dictionary != NULL);
uint8_t* src = NULL;
intptr_t size;
Dart_TypedData_Type type;
- if (Dart_IsError(Dart_ListLength(dictionary_obj, &size))) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get the zlib dictionary length"));
+ Dart_Handle err = Dart_ListLength(dictionary_obj, &size);
+ if (Dart_IsError(err)) {
+ return err;
}
- uint8_t* dictionary = new uint8_t[size];
-
- if (dictionary == NULL) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to allocate buffer for the zlib dictionary"));
+ uint8_t* result = new uint8_t[size];
+ if (result == NULL) {
+ return Dart_NewApiError("Could not allocate new dictionary");
}
- Dart_Handle result = Dart_TypedDataAcquireData(
+ err = Dart_TypedDataAcquireData(
dictionary_obj, &type, reinterpret_cast<void**>(&src), &size);
- if (!Dart_IsError(result)) {
- memmove(dictionary, src, size);
+ if (!Dart_IsError(err)) {
+ memmove(result, src, size);
Dart_TypedDataReleaseData(dictionary_obj);
} else {
- if (Dart_IsError(Dart_ListGetAsBytes(dictionary_obj, 0, dictionary,
- size))) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get the zlib dictionary"));
+ err = Dart_ListGetAsBytes(dictionary_obj, 0, result, size);
+ if (Dart_IsError(err)) {
+ delete[] result;
+ return err;
}
}
- return dictionary;
+ *dictionary = result;
+ return Dart_Null();
}
void Filter_CreateZLibInflate(Dart_NativeArguments args) {
Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
- Dart_Handle window_bits_obj = Dart_GetNativeArgument(args, 1);
- int64_t window_bits = DartEmbedder::GetIntegerValue(window_bits_obj);
+ int64_t window_bits = DartEmbedder::GetIntegerArgument(args, 1);
Dart_Handle dict_obj = Dart_GetNativeArgument(args, 2);
+ bool raw = DartEmbedder::GetBooleanArgument(args, 3);
+
+ Dart_Handle err;
uint8_t* dictionary = NULL;
intptr_t dictionary_length = 0;
if (!Dart_IsNull(dict_obj)) {
- dictionary = copyDictionary(dict_obj);
- if (dictionary != NULL) {
- dictionary_length = 0;
- Dart_ListLength(dict_obj, &dictionary_length);
+ err = CopyDictionary(dict_obj, &dictionary);
+ if (Dart_IsError(err)) {
+ Dart_PropagateError(err);
+ }
+ CHECK(dictionary != NULL);
+ dictionary_length = 0;
+ err = Dart_ListLength(dict_obj, &dictionary_length);
+ if (Dart_IsError(err)) {
+ delete[] dictionary;
+ Dart_PropagateError(err);
}
}
- Dart_Handle raw_obj = Dart_GetNativeArgument(args, 3);
- bool raw;
- if (Dart_IsError(Dart_BooleanValue(raw_obj, &raw))) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get 'raw' parameter"));
+
+ ZLibInflateFilter* filter = new ZLibInflateFilter(
+ static_cast<int32_t>(window_bits), dictionary, dictionary_length, raw);
+ if (filter == NULL) {
+ delete[] dictionary;
+ Dart_PropagateError(Dart_NewApiError(
+ "Could not allocate ZLibInflateFilter"));
}
- Filter* filter = new ZLibInflateFilter(static_cast<int32_t>(window_bits),
- dictionary, dictionary_length, raw);
if (!filter->Init()) {
delete filter;
Dart_ThrowException(DartEmbedder::NewInternalError(
"Failed to create ZLibInflateFilter"));
}
- Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter);
- if (Dart_IsError(result)) {
+ err = Filter::SetFilterAndCreateFinalizer(
+ filter_obj, filter, sizeof(*filter) + dictionary_length);
+ if (Dart_IsError(err)) {
delete filter;
- Dart_PropagateError(result);
+ Dart_PropagateError(err);
}
}
void Filter_CreateZLibDeflate(Dart_NativeArguments args) {
Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
- Dart_Handle gzip_obj = Dart_GetNativeArgument(args, 1);
- bool gzip = DartEmbedder::GetBooleanValue(gzip_obj);
+ bool gzip = DartEmbedder::GetBooleanArgument(args, 1);
Dart_Handle level_obj = Dart_GetNativeArgument(args, 2);
int64_t level = DartEmbedder::GetInt64ValueCheckRange(
level_obj,
std::numeric_limits<int32_t>::min(),
std::numeric_limits<int32_t>::max());
- Dart_Handle window_bits_obj = Dart_GetNativeArgument(args, 3);
- int64_t window_bits = DartEmbedder::GetIntegerValue(window_bits_obj);
- Dart_Handle mLevel_obj = Dart_GetNativeArgument(args, 4);
- int64_t mem_level = DartEmbedder::GetIntegerValue(mLevel_obj);
- Dart_Handle strategy_obj = Dart_GetNativeArgument(args, 5);
- int64_t strategy = DartEmbedder::GetIntegerValue(strategy_obj);
+ int64_t window_bits = DartEmbedder::GetIntegerArgument(args, 3);
+ int64_t mem_level = DartEmbedder::GetIntegerArgument(args, 4);
+ int64_t strategy = DartEmbedder::GetIntegerArgument(args, 5);
Dart_Handle dict_obj = Dart_GetNativeArgument(args, 6);
+ bool raw = DartEmbedder::GetBooleanArgument(args, 7);
+
+ Dart_Handle err;
uint8_t* dictionary = NULL;
intptr_t dictionary_length = 0;
if (!Dart_IsNull(dict_obj)) {
- dictionary = copyDictionary(dict_obj);
- if (dictionary != NULL) {
- dictionary_length = 0;
- Dart_ListLength(dict_obj, &dictionary_length);
+ err = CopyDictionary(dict_obj, &dictionary);
+ if (Dart_IsError(err)) {
+ Dart_PropagateError(err);
+ }
+ CHECK(dictionary != NULL);
+ dictionary_length = 0;
+ err = Dart_ListLength(dict_obj, &dictionary_length);
+ if (Dart_IsError(err)) {
+ delete[] dictionary;
+ Dart_PropagateError(err);
}
}
- Dart_Handle raw_obj = Dart_GetNativeArgument(args, 7);
- bool raw = DartEmbedder::GetBooleanValue(raw_obj);
- Filter* filter = new ZLibDeflateFilter(gzip, static_cast<int32_t>(level),
- static_cast<int32_t>(window_bits),
- static_cast<int32_t>(mem_level),
- static_cast<int32_t>(strategy),
- dictionary, dictionary_length, raw);
+
+ ZLibDeflateFilter* filter = new ZLibDeflateFilter(
+ gzip,
+ static_cast<int32_t>(level),
+ static_cast<int32_t>(window_bits),
+ static_cast<int32_t>(mem_level),
+ static_cast<int32_t>(strategy),
+ dictionary, dictionary_length, raw);
+ if (filter == NULL) {
+ delete[] dictionary;
+ Dart_PropagateError(Dart_NewApiError(
+ "Could not allocate ZLibDeflateFilter"));
+ }
if (!filter->Init()) {
delete filter;
Dart_ThrowException(DartEmbedder::NewInternalError(
"Failed to create ZLibDeflateFilter"));
}
- Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter);
+ Dart_Handle result = Filter::SetFilterAndCreateFinalizer(
+ filter_obj, filter, sizeof(*filter) + dictionary_length);
if (Dart_IsError(result)) {
delete filter;
Dart_PropagateError(result);
@@ -245,20 +264,24 @@ void Filter_CreateZLibDeflate(Dart_NativeArguments args) {
void Filter_Process(Dart_NativeArguments args) {
Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
- Filter* filter = GetFilter(filter_obj);
Dart_Handle data_obj = Dart_GetNativeArgument(args, 1);
- intptr_t start =
- DartEmbedder::GetIntptrValue(Dart_GetNativeArgument(args, 2));
- intptr_t end = DartEmbedder::GetIntptrValue(Dart_GetNativeArgument(args, 3));
+ intptr_t start = DartEmbedder::GetIntptrArgument(args, 2);
+ intptr_t end = DartEmbedder::GetIntptrArgument(args, 3);
intptr_t chunk_length = end - start;
intptr_t length;
Dart_TypedData_Type type;
uint8_t* buffer = NULL;
+
+ Filter* filter = NULL;
+ Dart_Handle err = GetFilter(filter_obj, &filter);
+ if (Dart_IsError(err)) {
+ Dart_PropagateError(err);
+ }
+
Dart_Handle result = Dart_TypedDataAcquireData(
data_obj, &type, reinterpret_cast<void**>(&buffer), &length);
-
if (!Dart_IsError(result)) {
- DCHECK(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8);
+ CHECK(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8);
if (type != Dart_TypedData_kUint8 && type != Dart_TypedData_kInt8) {
Dart_TypedDataReleaseData(data_obj);
Dart_ThrowException(DartEmbedder::NewInternalError(
@@ -267,29 +290,30 @@ void Filter_Process(Dart_NativeArguments args) {
uint8_t* zlib_buffer = new uint8_t[chunk_length];
if (zlib_buffer == NULL) {
Dart_TypedDataReleaseData(data_obj);
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to allocate buffer for zlib"));
+ Dart_PropagateError(Dart_NewApiError("Could not allocate zlib buffer"));
}
+
memmove(zlib_buffer, buffer + start, chunk_length);
Dart_TypedDataReleaseData(data_obj);
buffer = zlib_buffer;
} else {
- if (Dart_IsError(Dart_ListLength(data_obj, &length))) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get list length"));
+ err = Dart_ListLength(data_obj, &length);
+ if (Dart_IsError(err)) {
+ Dart_PropagateError(err);
}
buffer = new uint8_t[chunk_length];
- if (Dart_IsError(Dart_ListGetAsBytes(
- data_obj, start, buffer, chunk_length))) {
+ if (buffer == NULL) {
+ Dart_PropagateError(Dart_NewApiError("Could not allocate buffer"));
+ }
+ err = Dart_ListGetAsBytes(data_obj, start, buffer, chunk_length);
+ if (Dart_IsError(err)) {
delete[] buffer;
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get list bytes"));
+ Dart_PropagateError(err);
}
}
// Process will take ownership of buffer, if successful.
if (!filter->Process(buffer, chunk_length)) {
delete[] buffer;
- EndFilter(filter_obj, filter);
Dart_ThrowException(DartEmbedder::NewInternalError(
"Call to Process while still processing data"));
}
@@ -297,26 +321,20 @@ void Filter_Process(Dart_NativeArguments args) {
void Filter_Processed(Dart_NativeArguments args) {
Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
- Filter* filter = GetFilter(filter_obj);
- Dart_Handle flush_obj = Dart_GetNativeArgument(args, 1);
- bool flush;
- if (Dart_IsError(Dart_BooleanValue(flush_obj, &flush))) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get 'flush' parameter"));
- }
- Dart_Handle end_obj = Dart_GetNativeArgument(args, 2);
- bool end;
- if (Dart_IsError(Dart_BooleanValue(end_obj, &end))) {
- Dart_ThrowException(DartEmbedder::NewInternalError(
- "Failed to get 'end' parameter"));
+ bool flush = DartEmbedder::GetBooleanArgument(args, 1);
+ bool end = DartEmbedder::GetBooleanArgument(args, 2);
+
+ Filter* filter = NULL;
+ Dart_Handle err = GetFilter(filter_obj, &filter);
+ if (Dart_IsError(err)) {
+ Dart_PropagateError(err);
}
+
intptr_t read = filter->Processed(filter->processed_buffer(),
filter->processed_buffer_size(),
flush,
end);
if (read < 0) {
- // Error, end filter.
- EndFilter(filter_obj, filter);
Dart_ThrowException(DartEmbedder::NewInternalError(
"Filter error, bad data"));
} else if (read == 0) {
@@ -329,12 +347,6 @@ void Filter_Processed(Dart_NativeArguments args) {
}
}
-void Filter_End(Dart_NativeArguments args) {
- Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
- Filter* filter = GetFilter(filter_obj);
- EndFilter(filter_obj, filter);
-}
-
void InternetAddress_Parse(Dart_NativeArguments arguments) {
const char* address = DartEmbedder::GetStringArgument(arguments, 0);
CHECK(address != nullptr);
« no previous file with comments | « mojo/dart/embedder/io/filter_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698