OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
6 #include "bin/filter.h" | 6 #include "bin/filter.h" |
7 #include "bin/io_buffer.h" | 7 #include "bin/io_buffer.h" |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 void FUNCTION_NAME(Filter_CreateZLibDeflate)(Dart_NativeArguments args) { | 54 void FUNCTION_NAME(Filter_CreateZLibDeflate)(Dart_NativeArguments args) { |
55 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 55 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
56 Dart_Handle gzip_obj = Dart_GetNativeArgument(args, 1); | 56 Dart_Handle gzip_obj = Dart_GetNativeArgument(args, 1); |
57 Dart_Handle level_obj = Dart_GetNativeArgument(args, 2); | 57 Dart_Handle level_obj = Dart_GetNativeArgument(args, 2); |
58 bool gzip; | 58 bool gzip; |
59 if (Dart_IsError(Dart_BooleanValue(gzip_obj, &gzip))) { | 59 if (Dart_IsError(Dart_BooleanValue(gzip_obj, &gzip))) { |
60 Dart_ThrowException(DartUtils::NewInternalError( | 60 Dart_ThrowException(DartUtils::NewInternalError( |
61 "Failed to get 'gzip' parameter")); | 61 "Failed to get 'gzip' parameter")); |
62 } | 62 } |
63 int64_t level; | 63 int64_t level = 0; |
64 if (Dart_IsError(Dart_IntegerToInt64(level_obj, &level))) { | 64 Dart_Handle result = Dart_IntegerToInt64(level_obj, &level); |
| 65 if (Dart_IsError(result) || (level < kMinInt32) || (level > kMaxInt32)) { |
65 Dart_ThrowException(DartUtils::NewInternalError( | 66 Dart_ThrowException(DartUtils::NewInternalError( |
66 "Failed to get 'level' parameter")); | 67 "Failed to get 'level' parameter")); |
67 } | 68 } |
68 Filter* filter = new ZLibDeflateFilter(gzip, level); | 69 Filter* filter = new ZLibDeflateFilter(gzip, static_cast<int32_t>(level)); |
69 if (filter == NULL || !filter->Init()) { | 70 if (filter == NULL || !filter->Init()) { |
70 delete filter; | 71 delete filter; |
71 Dart_ThrowException(DartUtils::NewInternalError( | 72 Dart_ThrowException(DartUtils::NewInternalError( |
72 "Failed to create ZLibDeflateFilter")); | 73 "Failed to create ZLibDeflateFilter")); |
73 } | 74 } |
74 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter); | 75 result = Filter::SetFilterPointerNativeField(filter_obj, filter); |
75 if (Dart_IsError(result)) { | 76 if (Dart_IsError(result)) { |
76 delete filter; | 77 delete filter; |
77 Dart_PropagateError(result); | 78 Dart_PropagateError(result); |
78 } | 79 } |
79 } | 80 } |
80 | 81 |
81 void FUNCTION_NAME(Filter_Process)(Dart_NativeArguments args) { | 82 void FUNCTION_NAME(Filter_Process)(Dart_NativeArguments args) { |
82 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 83 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
83 Filter* filter = GetFilter(filter_obj); | 84 Filter* filter = GetFilter(filter_obj); |
84 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); | 85 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 case Z_STREAM_ERROR: | 305 case Z_STREAM_ERROR: |
305 // An error occoured. | 306 // An error occoured. |
306 delete[] current_buffer_; | 307 delete[] current_buffer_; |
307 current_buffer_ = NULL; | 308 current_buffer_ = NULL; |
308 return -1; | 309 return -1; |
309 } | 310 } |
310 } | 311 } |
311 | 312 |
312 } // namespace bin | 313 } // namespace bin |
313 } // namespace dart | 314 } // namespace dart |
OLD | NEW |