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

Side by Side Diff: Source/WebCore/bindings/dart/DartNativeUtilities.cpp

Issue 10660025: Cleanup dart to string conversions. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: . Created 8 years, 6 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 2012, Google Inc. 1 // Copyright 2012, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 Dart_ThrowException(exception); 69 Dart_ThrowException(exception);
70 ASSERT_NOT_REACHED(); 70 ASSERT_NOT_REACHED();
71 } 71 }
72 72
73 static void print(Dart_NativeArguments args) 73 static void print(Dart_NativeArguments args)
74 { 74 {
75 DartApiScope dartApiScope; 75 DartApiScope dartApiScope;
76 Dart_Handle exception = 0; 76 Dart_Handle exception = 0;
77 77
78 { 78 {
79 const ParameterAdapter<String> message(Dart_GetNativeArgument(args, 0)); 79 DartStringAdapter message = DartUtilities::dartToString(Dart_GetNativeAr gument(args, 0), exception);
80 if (!message.conversionSuccessful()) { 80 if (exception)
81 exception = message.exception();
82 goto fail; 81 goto fail;
83 }
84 82
85 printf("[print]: %s\n", String(message).utf8().data()); 83 printf("[print]: %s\n", String(message).utf8().data());
Anton Muhin 2012/06/26 16:52:28 do you still need this conversion?
podivilov 2012/06/26 18:07:38 Sure, DartStringAdapter has no utf8 method.
86 return; 84 return;
87 } 85 }
88 86
89 fail: 87 fail:
90 Dart_ThrowException(exception); 88 Dart_ThrowException(exception);
91 ASSERT_NOT_REACHED(); 89 ASSERT_NOT_REACHED();
92 } 90 }
93 91
94 static void npObjectRetrieve(Dart_NativeArguments args) 92 static void npObjectRetrieve(Dart_NativeArguments args)
95 { 93 {
96 DartApiScope dartApiScope; 94 DartApiScope dartApiScope;
97 Dart_Handle exception = 0; 95 Dart_Handle exception = 0;
98 { 96 {
99 const ParameterAdapter<String> key(Dart_GetNativeArgument(args, 0)); 97 DartStringAdapter key = DartUtilities::dartToString(Dart_GetNativeArgume nt(args, 0), exception);
100 if (!key.conversionSuccessful()) { 98 if (exception)
101 exception = key.exception();
102 goto fail; 99 goto fail;
103 }
104 100
105 DartController* controller = DartController::retrieve(DartUtilities::scr iptExecutionContext()); 101 DartController* controller = DartController::retrieve(DartUtilities::scr iptExecutionContext());
106 NPObject* npObject = controller->npObject(key); 102 NPObject* npObject = controller->npObject(key);
107 if (npObject) { 103 if (npObject) {
108 // FIXME: put NPObjects into a map as well. 104 // FIXME: put NPObjects into a map as well.
109 Dart_SetReturnValue(args, DartDOMWrapper::newWrapper("_NPObject", np Object)); 105 Dart_SetReturnValue(args, DartDOMWrapper::newWrapper("_NPObject", np Object));
110 } 106 }
111 return; 107 return;
112 } 108 }
113 109
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 Dart_Handle exception = 0; 178 Dart_Handle exception = 0;
183 { 179 {
184 // IMPORTANT NOTE: Runtime type of first argument must be checked 180 // IMPORTANT NOTE: Runtime type of first argument must be checked
185 // by Dart code---we're doing read without any additional checks here! 181 // by Dart code---we're doing read without any additional checks here!
186 intptr_t value; 182 intptr_t value;
187 Dart_Handle result = Dart_GetNativeInstanceField(Dart_GetNativeArgument( args, 0), 0, &value); 183 Dart_Handle result = Dart_GetNativeInstanceField(Dart_GetNativeArgument( args, 0), 0, &value);
188 ASSERT(!Dart_IsError(result)); 184 ASSERT(!Dart_IsError(result));
189 UNUSED_PARAM(result); 185 UNUSED_PARAM(result);
190 RefPtr<DOMWindow> targetWindow(reinterpret_cast<DOMWindow*>(value)); 186 RefPtr<DOMWindow> targetWindow(reinterpret_cast<DOMWindow*>(value));
191 187
192 const ParameterAdapter<String> entryPoint(Dart_GetNativeArgument(args, 1 )); 188 DartStringAdapter entryPoint = DartUtilities::dartToString(Dart_GetNativ eArgument(args, 1), exception);
193 if (!entryPoint.conversionSuccessful()) { 189 if (exception)
194 exception = entryPoint.exception();
195 goto fail; 190 goto fail;
196 }
197 191
198 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext( ); 192 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext( );
199 if (!context) { 193 if (!context) {
200 exception = DartUtilities::internalErrorException("[spawnDomIsolate] failed to retrieve ScriptExecutionContext"); 194 exception = DartUtilities::internalErrorException("[spawnDomIsolate] failed to retrieve ScriptExecutionContext");
201 goto fail; 195 goto fail;
202 } 196 }
203 197
204 DartController* controller = DartController::retrieve(context); 198 DartController* controller = DartController::retrieve(context);
205 if (!controller) { 199 if (!controller) {
206 exception = DartUtilities::internalErrorException("[spawnDomIsolate] failed to retrieve DartController"); 200 exception = DartUtilities::internalErrorException("[spawnDomIsolate] failed to retrieve DartController");
(...skipping 26 matching lines...) Expand all
233 extern Dart_NativeFunction snapshotResolver(Dart_Handle name, int argumentCount) ; 227 extern Dart_NativeFunction snapshotResolver(Dart_Handle name, int argumentCount) ;
234 228
235 Dart_NativeFunction domResolver(Dart_Handle name, int argumentCount) 229 Dart_NativeFunction domResolver(Dart_Handle name, int argumentCount)
236 { 230 {
237 // Some utility functions. 231 // Some utility functions.
238 if (Dart_NativeFunction func = snapshotResolver(name, argumentCount)) 232 if (Dart_NativeFunction func = snapshotResolver(name, argumentCount))
239 return func; 233 return func;
240 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun t)) 234 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun t))
241 return func; 235 return func;
242 236
243 String str = DartUtilities::dartStringToString(name); 237 String str = DartUtilities::toString(name);
244 if (argumentCount == 0 && str == "Utils_window") 238 if (argumentCount == 0 && str == "Utils_window")
245 return topLevelWindow; 239 return topLevelWindow;
246 if (argumentCount == 1 && str == "Utils_print") 240 if (argumentCount == 1 && str == "Utils_print")
247 return print; 241 return print;
248 if (argumentCount == 2 && str == "Utils_spawnDomIsolate") 242 if (argumentCount == 2 && str == "Utils_spawnDomIsolate")
249 return spawnDomIsolate; 243 return spawnDomIsolate;
250 if (argumentCount == 1 && str == "NPObject_retrieve") 244 if (argumentCount == 1 && str == "NPObject_retrieve")
251 return npObjectRetrieve; 245 return npObjectRetrieve;
252 if (argumentCount == 2 && str == "NPObject_property") 246 if (argumentCount == 2 && str == "NPObject_property")
253 return npObjectProperty; 247 return npObjectProperty;
254 if (argumentCount == 3 && str == "NPObject_invoke") 248 if (argumentCount == 3 && str == "NPObject_invoke")
255 return npObjectInvoke; 249 return npObjectInvoke;
256 if (argumentCount == 1 && str == "DOMWindow_history_cross_frame_Getter") 250 if (argumentCount == 1 && str == "DOMWindow_history_cross_frame_Getter")
257 return DartDOMWindowInternal::historyCrossFrameGetter; 251 return DartDOMWindowInternal::historyCrossFrameGetter;
258 if (argumentCount == 1 && str == "DOMWindow_location_cross_frame_Getter") 252 if (argumentCount == 1 && str == "DOMWindow_location_cross_frame_Getter")
259 return DartDOMWindowInternal::locationCrossFrameGetter; 253 return DartDOMWindowInternal::locationCrossFrameGetter;
260 return 0; 254 return 0;
261 } 255 }
262 256
263 } 257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698