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

Side by Side Diff: vm/custom_isolate_test.cc

Issue 11275008: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 1 month 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 // Custom Isolate Test. 9 // Custom Isolate Test.
10 // 10 //
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Reload all the test classes here. 172 // Reload all the test classes here.
173 // 173 //
174 // TODO(turnidge): Use the create isolate callback instead? 174 // TODO(turnidge): Use the create isolate callback instead?
175 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, 175 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars,
176 NativeLookup); 176 NativeLookup);
177 EXPECT_VALID(lib); 177 EXPECT_VALID(lib);
178 EXPECT_VALID(Dart_CompileAll()); 178 EXPECT_VALID(Dart_CompileAll());
179 179
180 Dart_Handle recv_port = Dart_GetReceivePort(Dart_GetMainPortId()); 180 Dart_Handle recv_port = Dart_GetReceivePort(Dart_GetMainPortId());
181 EXPECT_VALID(recv_port); 181 EXPECT_VALID(recv_port);
182 result = Dart_SetField(lib, Dart_NewString("mainPort"), recv_port); 182 result = Dart_SetField(lib, NewString("mainPort"), recv_port);
183 EXPECT_VALID(result); 183 EXPECT_VALID(result);
184 184
185 result = Dart_Invoke(lib, Dart_NewString(main_), 0, NULL); 185 result = Dart_Invoke(lib, NewString(main_), 0, NULL);
186 EXPECT_VALID(result); 186 EXPECT_VALID(result);
187 free(const_cast<char*>(main_)); 187 free(const_cast<char*>(main_));
188 main_ = NULL; 188 main_ = NULL;
189 189
190 Dart_ExitScope(); 190 Dart_ExitScope();
191 Dart_ExitIsolate(); 191 Dart_ExitIsolate();
192 } 192 }
193 193
194 194
195 // Notify an isolate of a pending message. 195 // Notify an isolate of a pending message.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 static void NotifyMessage(Dart_Isolate dest_isolate) { 227 static void NotifyMessage(Dart_Isolate dest_isolate) {
228 OS::Print("-- Notify isolate(%p) of pending message --\n", dest_isolate); 228 OS::Print("-- Notify isolate(%p) of pending message --\n", dest_isolate);
229 OS::Print("-- Adding MessageEvent to queue --\n"); 229 OS::Print("-- Adding MessageEvent to queue --\n");
230 event_queue->Add(new MessageEvent(dest_isolate)); 230 event_queue->Add(new MessageEvent(dest_isolate));
231 } 231 }
232 232
233 233
234 static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc) { 234 static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc) {
235 const char* name_str = NULL; 235 const char* name_str = NULL;
236 EXPECT(Dart_IsString(name)); 236 EXPECT(Dart_IsString(name));
237 EXPECT_VALID(Dart_StringToCString(name, &name_str)); 237 EXPECT_VALID(Dart_StringAsCString(name, &name_str));
238 if (strcmp(name_str, "native_echo") == 0) { 238 if (strcmp(name_str, "native_echo") == 0) {
239 return &native_echo; 239 return &native_echo;
240 } else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) { 240 } else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) {
241 return &CustomIsolateImpl_start; 241 return &CustomIsolateImpl_start;
242 } 242 }
243 return NULL; 243 return NULL;
244 } 244 }
245 245
246 246
247 const char* saved_echo = NULL; 247 const char* saved_echo = NULL;
248 static void native_echo(Dart_NativeArguments args) { 248 static void native_echo(Dart_NativeArguments args) {
249 Dart_EnterScope(); 249 Dart_EnterScope();
250 Dart_Handle arg = Dart_GetNativeArgument(args, 0); 250 Dart_Handle arg = Dart_GetNativeArgument(args, 0);
251 Dart_Handle toString = Dart_ToString(arg); 251 Dart_Handle toString = Dart_ToString(arg);
252 EXPECT_VALID(toString); 252 EXPECT_VALID(toString);
253 const char* c_str = NULL; 253 const char* c_str = NULL;
254 EXPECT_VALID(Dart_StringToCString(toString, &c_str)); 254 EXPECT_VALID(Dart_StringAsCString(toString, &c_str));
255 if (saved_echo) { 255 if (saved_echo) {
256 free(const_cast<char*>(saved_echo)); 256 free(const_cast<char*>(saved_echo));
257 } 257 }
258 saved_echo = strdup(c_str); 258 saved_echo = strdup(c_str);
259 OS::Print("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str); 259 OS::Print("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str);
260 Dart_ExitScope(); 260 Dart_ExitScope();
261 } 261 }
262 262
263 263
264 static void CustomIsolateImpl_start(Dart_NativeArguments args) { 264 static void CustomIsolateImpl_start(Dart_NativeArguments args) {
265 OS::Print("-- Enter: CustomIsolateImpl_start --\n"); 265 OS::Print("-- Enter: CustomIsolateImpl_start --\n");
266 266
267 // We would probably want to pass in the this pointer too, so we 267 // We would probably want to pass in the this pointer too, so we
268 // could associate the CustomIsolateImpl instance with the 268 // could associate the CustomIsolateImpl instance with the
269 // Dart_Isolate by storing it in a native field. 269 // Dart_Isolate by storing it in a native field.
270 EXPECT_EQ(1, Dart_GetNativeArgumentCount(args)); 270 EXPECT_EQ(1, Dart_GetNativeArgumentCount(args));
271 Dart_Handle param = Dart_GetNativeArgument(args, 0); 271 Dart_Handle param = Dart_GetNativeArgument(args, 0);
272 EXPECT_VALID(param); 272 EXPECT_VALID(param);
273 EXPECT(Dart_IsString(param)); 273 EXPECT(Dart_IsString(param));
274 const char* isolate_main = NULL; 274 const char* isolate_main = NULL;
275 EXPECT_VALID(Dart_StringToCString(param, &isolate_main)); 275 EXPECT_VALID(Dart_StringAsCString(param, &isolate_main));
276 isolate_main = strdup(isolate_main); 276 isolate_main = strdup(isolate_main);
277 277
278 // Save current isolate. 278 // Save current isolate.
279 Dart_Isolate saved_isolate = Dart_CurrentIsolate(); 279 Dart_Isolate saved_isolate = Dart_CurrentIsolate();
280 Dart_ExitIsolate(); 280 Dart_ExitIsolate();
281 281
282 // Create a new Dart_Isolate. 282 // Create a new Dart_Isolate.
283 Dart_Isolate new_isolate = TestCase::CreateTestIsolate(); 283 Dart_Isolate new_isolate = TestCase::CreateTestIsolate();
284 EXPECT(new_isolate != NULL); 284 EXPECT(new_isolate != NULL);
285 Dart_SetMessageNotifyCallback(&NotifyMessage); 285 Dart_SetMessageNotifyCallback(&NotifyMessage);
(...skipping 24 matching lines...) Expand all
310 Dart_SetMessageNotifyCallback(&NotifyMessage); 310 Dart_SetMessageNotifyCallback(&NotifyMessage);
311 Dart_EnterScope(); 311 Dart_EnterScope();
312 Dart_Handle result; 312 Dart_Handle result;
313 313
314 // Create a test library. 314 // Create a test library.
315 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, 315 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars,
316 NativeLookup); 316 NativeLookup);
317 EXPECT_VALID(lib); 317 EXPECT_VALID(lib);
318 318
319 // Run main. 319 // Run main.
320 result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); 320 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
321 EXPECT_VALID(result); 321 EXPECT_VALID(result);
322 EXPECT(Dart_IsString(result)); 322 EXPECT(Dart_IsString(result));
323 const char* result_str = NULL; 323 const char* result_str = NULL;
324 EXPECT_VALID(Dart_StringToCString(result, &result_str)); 324 EXPECT_VALID(Dart_StringAsCString(result, &result_str));
325 EXPECT_STREQ("success", result_str); 325 EXPECT_STREQ("success", result_str);
326 326
327 Dart_ExitScope(); 327 Dart_ExitScope();
328 Dart_ExitIsolate(); 328 Dart_ExitIsolate();
329 329
330 OS::Print("-- Starting event loop --\n"); 330 OS::Print("-- Starting event loop --\n");
331 Event* event = event_queue->Get(); 331 Event* event = event_queue->Get();
332 while (event) { 332 while (event) {
333 event->Process(); 333 event->Process();
334 delete event; 334 delete event;
335 event = event_queue->Get(); 335 event = event_queue->Get();
336 } 336 }
337 OS::Print("-- Finished event loop --\n"); 337 OS::Print("-- Finished event loop --\n");
338 EXPECT_STREQ("Received: 43", saved_echo); 338 EXPECT_STREQ("Received: 43", saved_echo);
339 free(const_cast<char*>(saved_echo)); 339 free(const_cast<char*>(saved_echo));
340 340
341 delete event_queue; 341 delete event_queue;
342 } 342 }
343 343
344 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 344 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
345 345
346 } // namespace dart 346 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698