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

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

Issue 10821076: - Allow parsing of external methods. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/object.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 5353 matching lines...) Expand 10 before | Expand all | Expand 10 after
5364 EXPECT_VALID(cls); 5364 EXPECT_VALID(cls);
5365 recv = Dart_New(cls, Dart_Null(), 0, NULL); 5365 recv = Dart_New(cls, Dart_Null(), 0, NULL);
5366 result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL); 5366 result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL);
5367 EXPECT_VALID(result); 5367 EXPECT_VALID(result);
5368 EXPECT(Dart_IsString(result)); 5368 EXPECT(Dart_IsString(result));
5369 result_cstr = ""; 5369 result_cstr = "";
5370 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); 5370 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
5371 EXPECT_STREQ("bar", result_cstr); 5371 EXPECT_STREQ("bar", result_cstr);
5372 } 5372 }
5373 5373
5374
5375 TEST_CASE(ParsePatchLibrary) {
5376 const char* kLibraryChars =
5377 "#library('patched_library');\n"
5378 "class A {\n"
5379 " external method(var value);\n"
5380 "}\n"
5381 "external int topLevel(var value);\n";
5382
5383 const char* kPatchChars =
5384 "patch int topLevel(var value) => value * value;\n";
5385
5386 const char* kScriptChars =
5387 "#import('theLibrary');\n"
5388 "main() {\n"
5389 // TODO(iposva): Implement patching.
5390 " return 4 /* topLevel(2) */;\n"
5391 "}\n";
5392
5393 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler);
5394 EXPECT_VALID(result);
5395
5396 Dart_Handle lib_url = Dart_NewString("theLibrary");
5397 Dart_Handle source = Dart_NewString(kLibraryChars);
5398 result = Dart_LoadLibrary(lib_url, source);
5399 EXPECT_VALID(result);
5400
5401 // TODO(iposva): Implement patching.
5402 source = Dart_NewString(kPatchChars);
5403
5404 Dart_Handle script_url = Dart_NewString("theScript");
5405 source = Dart_NewString(kScriptChars);
5406 result = Dart_LoadScript(script_url, source);
5407 EXPECT_VALID(result);
5408 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
5409 EXPECT_VALID(result);
5410 EXPECT(Dart_IsInteger(result));
5411 int64_t value = 0;
5412 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
5413 EXPECT_EQ(4, value);
5414 }
5415
5416
5374 static void MyNativeFunction1(Dart_NativeArguments args) { 5417 static void MyNativeFunction1(Dart_NativeArguments args) {
5375 Dart_EnterScope(); 5418 Dart_EnterScope();
5376 Dart_SetReturnValue(args, Dart_NewInteger(654321)); 5419 Dart_SetReturnValue(args, Dart_NewInteger(654321));
5377 Dart_ExitScope(); 5420 Dart_ExitScope();
5378 } 5421 }
5379 5422
5380 5423
5381 static void MyNativeFunction2(Dart_NativeArguments args) { 5424 static void MyNativeFunction2(Dart_NativeArguments args) {
5382 Dart_EnterScope(); 5425 Dart_EnterScope();
5383 Dart_SetReturnValue(args, Dart_NewInteger(123456)); 5426 Dart_SetReturnValue(args, Dart_NewInteger(123456));
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
6332 EXPECT_VALID(result); 6375 EXPECT_VALID(result);
6333 EXPECT(Dart_IsInteger(result)); 6376 EXPECT(Dart_IsInteger(result));
6334 int64_t value = 0; 6377 int64_t value = 0;
6335 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 6378 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
6336 EXPECT_EQ(0, value); 6379 EXPECT_EQ(0, value);
6337 } 6380 }
6338 6381
6339 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 6382 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
6340 6383
6341 } // namespace dart 6384 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698