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

Side by Side Diff: runtime/vm/custom_isolate_test.cc

Issue 1130753006: Hide Isolate pointer from embedder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
« no previous file with comments | « runtime/vm/benchmark_test.h ('k') | runtime/vm/dart_api_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "include/dart_native_api.h" 6 #include "include/dart_native_api.h"
7 7
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 // Custom Isolate Test. 10 // Custom Isolate Test.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 StartEvent(Dart_Isolate isolate, const char* main) 159 StartEvent(Dart_Isolate isolate, const char* main)
160 : Event(isolate), main_(main) {} 160 : Event(isolate), main_(main) {}
161 161
162 virtual void Process(); 162 virtual void Process();
163 private: 163 private:
164 const char* main_; 164 const char* main_;
165 }; 165 };
166 166
167 167
168 void StartEvent::Process() { 168 void StartEvent::Process() {
169 OS::Print(">> StartEvent with isolate(%p)--\n", isolate()); 169 OS::Print(">> StartEvent with isolate(%" PRId64 ")--\n", isolate());
170 Dart_EnterIsolate(isolate()); 170 Dart_EnterIsolate(isolate());
171 Dart_EnterScope(); 171 Dart_EnterScope();
172 Dart_Handle result; 172 Dart_Handle result;
173 173
174 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); 174 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url()));
175 EXPECT_VALID(lib); 175 EXPECT_VALID(lib);
176 176
177 result = Dart_Invoke(lib, NewString(main_), 0, NULL); 177 result = Dart_Invoke(lib, NewString(main_), 0, NULL);
178 EXPECT_VALID(result); 178 EXPECT_VALID(result);
179 free(const_cast<char*>(main_)); 179 free(const_cast<char*>(main_));
(...skipping 10 matching lines...) Expand all
190 explicit MessageEvent(Dart_Isolate isolate) : Event(isolate) {} 190 explicit MessageEvent(Dart_Isolate isolate) : Event(isolate) {}
191 191
192 ~MessageEvent() { 192 ~MessageEvent() {
193 } 193 }
194 194
195 virtual void Process(); 195 virtual void Process();
196 }; 196 };
197 197
198 198
199 void MessageEvent::Process() { 199 void MessageEvent::Process() {
200 OS::Print("$$ MessageEvent with isolate(%p)\n", isolate()); 200 OS::Print("$$ MessageEvent with isolate(%" PRId64 ")\n", isolate());
201 Dart_EnterIsolate(isolate()); 201 Dart_EnterIsolate(isolate());
202 Dart_EnterScope(); 202 Dart_EnterScope();
203 203
204 Dart_Handle result = Dart_HandleMessage(); 204 Dart_Handle result = Dart_HandleMessage();
205 EXPECT_VALID(result); 205 EXPECT_VALID(result);
206 206
207 if (!Dart_HasLivePorts()) { 207 if (!Dart_HasLivePorts()) {
208 OS::Print("<< Shutting down isolate(%p)\n", isolate()); 208 OS::Print("<< Shutting down isolate(%" PRId64 ")\n", isolate());
209 event_queue->RemoveEventsForIsolate(isolate()); 209 event_queue->RemoveEventsForIsolate(isolate());
210 Dart_ShutdownIsolate(); 210 Dart_ShutdownIsolate();
211 } else { 211 } else {
212 Dart_ExitScope(); 212 Dart_ExitScope();
213 Dart_ExitIsolate(); 213 Dart_ExitIsolate();
214 } 214 }
215 ASSERT(Dart_CurrentIsolate() == NULL); 215 ASSERT(Dart_CurrentIsolate() == DART_ILLEGAL_ISOLATE);
216 } 216 }
217 217
218 218
219 static void NotifyMessage(Dart_Isolate dest_isolate) { 219 static void NotifyMessage(Dart_Isolate dest_isolate) {
220 OS::Print("-- Notify isolate(%p) of pending message --\n", dest_isolate); 220 OS::Print("-- Notify isolate(%" PRId64 ") of pending message --\n",
221 dest_isolate);
221 OS::Print("-- Adding MessageEvent to queue --\n"); 222 OS::Print("-- Adding MessageEvent to queue --\n");
222 event_queue->Add(new MessageEvent(dest_isolate)); 223 event_queue->Add(new MessageEvent(dest_isolate));
223 } 224 }
224 225
225 226
226 static Dart_NativeFunction NativeLookup(Dart_Handle name, 227 static Dart_NativeFunction NativeLookup(Dart_Handle name,
227 int argc, 228 int argc,
228 bool* auto_setup_scope) { 229 bool* auto_setup_scope) {
229 ASSERT(auto_setup_scope != NULL); 230 ASSERT(auto_setup_scope != NULL);
230 *auto_setup_scope = false; 231 *auto_setup_scope = false;
(...skipping 14 matching lines...) Expand all
245 Dart_EnterScope(); 246 Dart_EnterScope();
246 Dart_Handle arg = Dart_GetNativeArgument(args, 0); 247 Dart_Handle arg = Dart_GetNativeArgument(args, 0);
247 Dart_Handle toString = Dart_ToString(arg); 248 Dart_Handle toString = Dart_ToString(arg);
248 EXPECT_VALID(toString); 249 EXPECT_VALID(toString);
249 const char* c_str = NULL; 250 const char* c_str = NULL;
250 EXPECT_VALID(Dart_StringToCString(toString, &c_str)); 251 EXPECT_VALID(Dart_StringToCString(toString, &c_str));
251 if (saved_echo) { 252 if (saved_echo) {
252 free(const_cast<char*>(saved_echo)); 253 free(const_cast<char*>(saved_echo));
253 } 254 }
254 saved_echo = strdup(c_str); 255 saved_echo = strdup(c_str);
255 OS::Print("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str); 256 OS::Print("-- (isolate=%" PRId64 ") %s\n", Dart_CurrentIsolate(), c_str);
256 Dart_ExitScope(); 257 Dart_ExitScope();
257 } 258 }
258 259
259 260
260 static void CustomIsolateImpl_start(Dart_NativeArguments args) { 261 static void CustomIsolateImpl_start(Dart_NativeArguments args) {
261 OS::Print("-- Enter: CustomIsolateImpl_start --\n"); 262 OS::Print("-- Enter: CustomIsolateImpl_start --\n");
262 263
263 // We would probably want to pass in the this pointer too, so we 264 // We would probably want to pass in the this pointer too, so we
264 // could associate the CustomIsolateImpl instance with the 265 // could associate the CustomIsolateImpl instance with the
265 // Dart_Isolate by storing it in a native field. 266 // Dart_Isolate by storing it in a native field.
266 EXPECT_EQ(1, Dart_GetNativeArgumentCount(args)); 267 EXPECT_EQ(1, Dart_GetNativeArgumentCount(args));
267 Dart_Handle param = Dart_GetNativeArgument(args, 0); 268 Dart_Handle param = Dart_GetNativeArgument(args, 0);
268 EXPECT_VALID(param); 269 EXPECT_VALID(param);
269 EXPECT(Dart_IsString(param)); 270 EXPECT(Dart_IsString(param));
270 const char* isolate_main = NULL; 271 const char* isolate_main = NULL;
271 EXPECT_VALID(Dart_StringToCString(param, &isolate_main)); 272 EXPECT_VALID(Dart_StringToCString(param, &isolate_main));
272 isolate_main = strdup(isolate_main); 273 isolate_main = strdup(isolate_main);
273 274
274 // Save current isolate. 275 // Save current isolate.
275 Dart_Isolate saved_isolate = Dart_CurrentIsolate(); 276 Dart_Isolate saved_isolate = Dart_CurrentIsolate();
276 Dart_ExitIsolate(); 277 Dart_ExitIsolate();
277 278
278 // Create a new Dart_Isolate. 279 // Create a new Dart_Isolate.
279 Dart_Isolate new_isolate = TestCase::CreateTestIsolate(); 280 Dart_Isolate new_isolate = TestCase::CreateTestIsolate();
280 EXPECT(new_isolate != NULL); 281 EXPECT(new_isolate != DART_ILLEGAL_ISOLATE);
281 Dart_SetMessageNotifyCallback(&NotifyMessage); 282 Dart_SetMessageNotifyCallback(&NotifyMessage);
282 Dart_EnterScope(); 283 Dart_EnterScope();
283 // Reload all the test classes here. 284 // Reload all the test classes here.
284 // 285 //
285 // TODO(turnidge): Use the create isolate callback instead? 286 // TODO(turnidge): Use the create isolate callback instead?
286 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, 287 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars,
287 NativeLookup); 288 NativeLookup);
288 EXPECT_VALID(lib); 289 EXPECT_VALID(lib);
289 290
290 Dart_Handle main_send_port = Dart_GetField(lib, NewString("mainSendPort")); 291 Dart_Handle main_send_port = Dart_GetField(lib, NewString("mainSendPort"));
(...skipping 17 matching lines...) Expand all
308 309
309 OS::Print("-- Exit: CustomIsolateImpl_start --\n"); 310 OS::Print("-- Exit: CustomIsolateImpl_start --\n");
310 Dart_ExitScope(); 311 Dart_ExitScope();
311 } 312 }
312 313
313 314
314 UNIT_TEST_CASE(CustomIsolates) { 315 UNIT_TEST_CASE(CustomIsolates) {
315 event_queue = new EventQueue(); 316 event_queue = new EventQueue();
316 317
317 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); 318 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate();
318 EXPECT(dart_isolate != NULL); 319 EXPECT(dart_isolate != DART_ILLEGAL_ISOLATE);
319 Dart_SetMessageNotifyCallback(&NotifyMessage); 320 Dart_SetMessageNotifyCallback(&NotifyMessage);
320 Dart_EnterScope(); 321 Dart_EnterScope();
321 Dart_Handle result; 322 Dart_Handle result;
322 323
323 // Create a test library. 324 // Create a test library.
324 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, 325 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars,
325 NativeLookup); 326 NativeLookup);
326 EXPECT_VALID(lib); 327 EXPECT_VALID(lib);
327 328
328 // Run main. 329 // Run main.
(...skipping 15 matching lines...) Expand all
344 event = event_queue->Get(); 345 event = event_queue->Get();
345 } 346 }
346 OS::Print("-- Finished event loop --\n"); 347 OS::Print("-- Finished event loop --\n");
347 EXPECT_STREQ("Received: 43", saved_echo); 348 EXPECT_STREQ("Received: 43", saved_echo);
348 free(const_cast<char*>(saved_echo)); 349 free(const_cast<char*>(saved_echo));
349 350
350 delete event_queue; 351 delete event_queue;
351 } 352 }
352 353
353 } // namespace dart 354 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/benchmark_test.h ('k') | runtime/vm/dart_api_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698