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

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

Issue 13813018: Changelist to land https://codereview.chromium.org/13452007/ for Siva. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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/dart_api_impl.cc ('k') | runtime/vm/isolate.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 6260 matching lines...) Expand 10 before | Expand all | Expand 10 after
6271 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); 6271 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result));
6272 6272
6273 Dart_ExitScope(); 6273 Dart_ExitScope();
6274 6274
6275 // Delete the native ports. 6275 // Delete the native ports.
6276 EXPECT(Dart_CloseNativePort(port_id1)); 6276 EXPECT(Dart_CloseNativePort(port_id1));
6277 EXPECT(Dart_CloseNativePort(port_id2)); 6277 EXPECT(Dart_CloseNativePort(port_id2));
6278 } 6278 }
6279 6279
6280 6280
6281 static bool RunLoopTestCallback(const char* script_name, 6281 static Dart_Isolate RunLoopTestCallback(const char* script_name,
6282 const char* main, 6282 const char* main,
6283 void* data, 6283 void* data,
6284 char** error) { 6284 char** error) {
6285 const char* kScriptChars = 6285 const char* kScriptChars =
6286 "import 'builtin';\n" 6286 "import 'builtin';\n"
6287 "import 'dart:isolate';\n" 6287 "import 'dart:isolate';\n"
6288 "void entry() {\n" 6288 "void entry() {\n"
6289 " port.receive((message, replyTo) {\n" 6289 " port.receive((message, replyTo) {\n"
6290 " if (message) {\n" 6290 " if (message) {\n"
6291 " throw new Exception('MakeChildExit');\n" 6291 " throw new Exception('MakeChildExit');\n"
6292 " } else {\n" 6292 " } else {\n"
6293 " replyTo.call('hello');\n" 6293 " replyTo.call('hello');\n"
6294 " port.close();\n" 6294 " port.close();\n"
(...skipping 15 matching lines...) Expand all
6310 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 6310 Dart_Isolate isolate = TestCase::CreateTestIsolate();
6311 ASSERT(isolate != NULL); 6311 ASSERT(isolate != NULL);
6312 Dart_EnterScope(); 6312 Dart_EnterScope();
6313 Dart_Handle url = NewString(TestCase::url()); 6313 Dart_Handle url = NewString(TestCase::url());
6314 Dart_Handle source = NewString(kScriptChars); 6314 Dart_Handle source = NewString(kScriptChars);
6315 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 6315 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
6316 EXPECT_VALID(result); 6316 EXPECT_VALID(result);
6317 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); 6317 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0);
6318 EXPECT_VALID(lib); 6318 EXPECT_VALID(lib);
6319 Dart_ExitScope(); 6319 Dart_ExitScope();
6320 return true; 6320 Dart_ExitIsolate();
6321 bool retval = Dart_IsolateMakeRunnable(isolate);
6322 EXPECT(retval);
6323 return isolate;
6321 } 6324 }
6322 6325
6323 6326
6324 // The error string from the last unhandled exception. This value is only 6327 // The error string from the last unhandled exception. This value is only
6325 // valid until the next Dart_ExitScope(). 6328 // valid until the next Dart_ExitScope().
6326 static char* last_exception = NULL; 6329 static char* last_exception = NULL;
6327 6330
6328 6331
6329 static void RunLoopUnhandledExceptionCallback(Dart_Handle exception) { 6332 static void RunLoopUnhandledExceptionCallback(Dart_Handle exception) {
6330 Dart_Handle error_string = Dart_ToString(exception); 6333 Dart_Handle error_string = Dart_ToString(exception);
6331 EXPECT_VALID(error_string); 6334 EXPECT_VALID(error_string);
6332 const char* error_text; 6335 const char* error_text;
6333 Dart_Handle result = Dart_StringToCString(error_string, &error_text); 6336 Dart_Handle result = Dart_StringToCString(error_string, &error_text);
6334 // Duplicate the string since error text is freed when callback is finished. 6337 // Duplicate the string since error text is freed when callback is finished.
6335 last_exception = strdup(error_text); 6338 last_exception = strdup(error_text);
6336 EXPECT_VALID(result); 6339 EXPECT_VALID(result);
6337 } 6340 }
6338 6341
6339 6342
6340 // Common code for RunLoop_Success/RunLoop_Failure. 6343 // Common code for RunLoop_Success/RunLoop_Failure.
6341 static void RunLoopTest(bool throw_exception_child, 6344 static void RunLoopTest(bool throw_exception_child,
6342 bool throw_exception_parent) { 6345 bool throw_exception_parent) {
6343 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); 6346 Dart_IsolateCreateCallback saved = Isolate::CreateCallback();
6344 Isolate::SetCreateCallback(RunLoopTestCallback); 6347 Isolate::SetCreateCallback(RunLoopTestCallback);
6345 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback); 6348 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback);
6346 RunLoopTestCallback(NULL, NULL, NULL, NULL); 6349 Dart_Isolate isolate = RunLoopTestCallback(NULL, NULL, NULL, NULL);
6347 6350
6351 Dart_EnterIsolate(isolate);
6348 Dart_EnterScope(); 6352 Dart_EnterScope();
6349 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); 6353 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url()));
6350 EXPECT_VALID(lib); 6354 EXPECT_VALID(lib);
6351 6355
6352 Dart_Handle result; 6356 Dart_Handle result;
6353 Dart_Handle args[2]; 6357 Dart_Handle args[2];
6354 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); 6358 args[0] = (throw_exception_child ? Dart_True() : Dart_False());
6355 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); 6359 args[1] = (throw_exception_parent ? Dart_True() : Dart_False());
6356 result = Dart_Invoke(lib, NewString("main"), 2, args); 6360 result = Dart_Invoke(lib, NewString("main"), 2, args);
6357 EXPECT_VALID(result); 6361 EXPECT_VALID(result);
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
7588 NULL); 7592 NULL);
7589 int64_t value = 0; 7593 int64_t value = 0;
7590 result = Dart_IntegerToInt64(result, &value); 7594 result = Dart_IntegerToInt64(result, &value);
7591 EXPECT_VALID(result); 7595 EXPECT_VALID(result);
7592 EXPECT_EQ(260, value); 7596 EXPECT_EQ(260, value);
7593 } 7597 }
7594 7598
7595 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7599 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7596 7600
7597 } // namespace dart 7601 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698