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

Side by Side Diff: runtime/bin/filter.cc

Issue 22303002: Auto create ApiLocalScope before calling native functions, this ensures that (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 } 30 }
31 return filter; 31 return filter;
32 } 32 }
33 33
34 void EndFilter(Dart_Handle filter_obj, Filter* filter) { 34 void EndFilter(Dart_Handle filter_obj, Filter* filter) {
35 Filter::SetFilterPointerNativeField(filter_obj, NULL); 35 Filter::SetFilterPointerNativeField(filter_obj, NULL);
36 delete filter; 36 delete filter;
37 } 37 }
38 38
39 void FUNCTION_NAME(Filter_CreateZLibInflate)(Dart_NativeArguments args) { 39 void FUNCTION_NAME(Filter_CreateZLibInflate)(Dart_NativeArguments args) {
40 Dart_EnterScope();
41 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); 40 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
42 Filter* filter = new ZLibInflateFilter(); 41 Filter* filter = new ZLibInflateFilter();
43 if (filter == NULL || !filter->Init()) { 42 if (filter == NULL || !filter->Init()) {
44 delete filter; 43 delete filter;
45 Dart_ThrowException(DartUtils::NewInternalError( 44 Dart_ThrowException(DartUtils::NewInternalError(
46 "Failed to create ZLibInflateFilter")); 45 "Failed to create ZLibInflateFilter"));
47 } 46 }
48 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter); 47 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter);
49 if (Dart_IsError(result)) { 48 if (Dart_IsError(result)) {
50 delete filter; 49 delete filter;
51 Dart_PropagateError(result); 50 Dart_PropagateError(result);
52 } 51 }
53 Dart_ExitScope();
54 } 52 }
55 53
56 void FUNCTION_NAME(Filter_CreateZLibDeflate)(Dart_NativeArguments args) { 54 void FUNCTION_NAME(Filter_CreateZLibDeflate)(Dart_NativeArguments args) {
57 Dart_EnterScope();
58 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); 55 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
59 Dart_Handle gzip_obj = Dart_GetNativeArgument(args, 1); 56 Dart_Handle gzip_obj = Dart_GetNativeArgument(args, 1);
60 Dart_Handle level_obj = Dart_GetNativeArgument(args, 2); 57 Dart_Handle level_obj = Dart_GetNativeArgument(args, 2);
61 bool gzip; 58 bool gzip;
62 if (Dart_IsError(Dart_BooleanValue(gzip_obj, &gzip))) { 59 if (Dart_IsError(Dart_BooleanValue(gzip_obj, &gzip))) {
63 Dart_ThrowException(DartUtils::NewInternalError( 60 Dart_ThrowException(DartUtils::NewInternalError(
64 "Failed to get 'gzip' parameter")); 61 "Failed to get 'gzip' parameter"));
65 } 62 }
66 int64_t level; 63 int64_t level;
67 if (Dart_IsError(Dart_IntegerToInt64(level_obj, &level))) { 64 if (Dart_IsError(Dart_IntegerToInt64(level_obj, &level))) {
68 Dart_ThrowException(DartUtils::NewInternalError( 65 Dart_ThrowException(DartUtils::NewInternalError(
69 "Failed to get 'level' parameter")); 66 "Failed to get 'level' parameter"));
70 } 67 }
71 Filter* filter = new ZLibDeflateFilter(gzip, level); 68 Filter* filter = new ZLibDeflateFilter(gzip, level);
72 if (filter == NULL || !filter->Init()) { 69 if (filter == NULL || !filter->Init()) {
73 delete filter; 70 delete filter;
74 Dart_ThrowException(DartUtils::NewInternalError( 71 Dart_ThrowException(DartUtils::NewInternalError(
75 "Failed to create ZLibDeflateFilter")); 72 "Failed to create ZLibDeflateFilter"));
76 } 73 }
77 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter); 74 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter);
78 if (Dart_IsError(result)) { 75 if (Dart_IsError(result)) {
79 delete filter; 76 delete filter;
80 Dart_PropagateError(result); 77 Dart_PropagateError(result);
81 } 78 }
82 Dart_ExitScope();
83 } 79 }
84 80
85 void FUNCTION_NAME(Filter_Process)(Dart_NativeArguments args) { 81 void FUNCTION_NAME(Filter_Process)(Dart_NativeArguments args) {
86 Dart_EnterScope();
87 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); 82 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
88 Filter* filter = GetFilter(filter_obj); 83 Filter* filter = GetFilter(filter_obj);
89 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); 84 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1);
90 intptr_t length; 85 intptr_t length;
91 Dart_TypedData_Type type; 86 Dart_TypedData_Type type;
92 uint8_t* buffer = NULL; 87 uint8_t* buffer = NULL;
93 Dart_Handle result = Dart_TypedDataAcquireData( 88 Dart_Handle result = Dart_TypedDataAcquireData(
94 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); 89 data_obj, &type, reinterpret_cast<void**>(&buffer), &length);
95 if (!Dart_IsError(result)) { 90 if (!Dart_IsError(result)) {
96 uint8_t* zlib_buffer = new uint8_t[length]; 91 uint8_t* zlib_buffer = new uint8_t[length];
(...skipping 17 matching lines...) Expand all
114 "Failed to get list bytes")); 109 "Failed to get list bytes"));
115 } 110 }
116 } 111 }
117 // Process will take ownership of buffer, if successful. 112 // Process will take ownership of buffer, if successful.
118 if (!filter->Process(buffer, length)) { 113 if (!filter->Process(buffer, length)) {
119 delete[] buffer; 114 delete[] buffer;
120 EndFilter(filter_obj, filter); 115 EndFilter(filter_obj, filter);
121 Dart_ThrowException(DartUtils::NewInternalError( 116 Dart_ThrowException(DartUtils::NewInternalError(
122 "Call to Process while still processing data")); 117 "Call to Process while still processing data"));
123 } 118 }
124 Dart_ExitScope();
125 } 119 }
126 120
127 121
128 void FUNCTION_NAME(Filter_Processed)(Dart_NativeArguments args) { 122 void FUNCTION_NAME(Filter_Processed)(Dart_NativeArguments args) {
129 Dart_EnterScope();
130 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); 123 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
131 Filter* filter = GetFilter(filter_obj); 124 Filter* filter = GetFilter(filter_obj);
132 Dart_Handle flush_obj = Dart_GetNativeArgument(args, 1); 125 Dart_Handle flush_obj = Dart_GetNativeArgument(args, 1);
133 bool flush; 126 bool flush;
134 if (Dart_IsError(Dart_BooleanValue(flush_obj, &flush))) { 127 if (Dart_IsError(Dart_BooleanValue(flush_obj, &flush))) {
135 Dart_ThrowException(DartUtils::NewInternalError( 128 Dart_ThrowException(DartUtils::NewInternalError(
136 "Failed to get 'flush' parameter")); 129 "Failed to get 'flush' parameter"));
137 } 130 }
138 Dart_Handle end_obj = Dart_GetNativeArgument(args, 2); 131 Dart_Handle end_obj = Dart_GetNativeArgument(args, 2);
139 bool end; 132 bool end;
(...skipping 11 matching lines...) Expand all
151 Dart_ThrowException(DartUtils::NewInternalError( 144 Dart_ThrowException(DartUtils::NewInternalError(
152 "Filter error, bad data")); 145 "Filter error, bad data"));
153 } else if (read == 0) { 146 } else if (read == 0) {
154 Dart_SetReturnValue(args, Dart_Null()); 147 Dart_SetReturnValue(args, Dart_Null());
155 } else { 148 } else {
156 uint8_t* io_buffer; 149 uint8_t* io_buffer;
157 Dart_Handle result = IOBuffer::Allocate(read, &io_buffer); 150 Dart_Handle result = IOBuffer::Allocate(read, &io_buffer);
158 memmove(io_buffer, filter->processed_buffer(), read); 151 memmove(io_buffer, filter->processed_buffer(), read);
159 Dart_SetReturnValue(args, result); 152 Dart_SetReturnValue(args, result);
160 } 153 }
161 Dart_ExitScope();
162 } 154 }
163 155
164 156
165 void FUNCTION_NAME(Filter_End)(Dart_NativeArguments args) { 157 void FUNCTION_NAME(Filter_End)(Dart_NativeArguments args) {
166 Dart_EnterScope();
167 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); 158 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0);
168 Filter* filter = GetFilter(filter_obj); 159 Filter* filter = GetFilter(filter_obj);
169 EndFilter(filter_obj, filter); 160 EndFilter(filter_obj, filter);
170 Dart_ExitScope();
171 } 161 }
172 162
173 163
174 Dart_Handle Filter::SetFilterPointerNativeField(Dart_Handle filter, 164 Dart_Handle Filter::SetFilterPointerNativeField(Dart_Handle filter,
175 Filter* filter_pointer) { 165 Filter* filter_pointer) {
176 return Dart_SetNativeInstanceField( 166 return Dart_SetNativeInstanceField(
177 filter, 167 filter,
178 kFilterPointerNativeField, 168 kFilterPointerNativeField,
179 reinterpret_cast<intptr_t>(filter_pointer)); 169 reinterpret_cast<intptr_t>(filter_pointer));
180 } 170 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 case Z_STREAM_ERROR: 300 case Z_STREAM_ERROR:
311 // An error occoured. 301 // An error occoured.
312 delete[] current_buffer_; 302 delete[] current_buffer_;
313 current_buffer_ = NULL; 303 current_buffer_ = NULL;
314 return -1; 304 return -1;
315 } 305 }
316 } 306 }
317 307
318 } // namespace bin 308 } // namespace bin
319 } // namespace dart 309 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/filter_unsupported.cc » ('j') | runtime/vm/ast.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698