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

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

Issue 10824209: - Allow patching of top-level methods and accessors. (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 | « no previous file | 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 5461 matching lines...) Expand 10 before | Expand all | Expand 10 after
5472 result_cstr = ""; 5472 result_cstr = "";
5473 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); 5473 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
5474 EXPECT_STREQ("bar", result_cstr); 5474 EXPECT_STREQ("bar", result_cstr);
5475 } 5475 }
5476 5476
5477 5477
5478 TEST_CASE(ParsePatchLibrary) { 5478 TEST_CASE(ParsePatchLibrary) {
5479 const char* kLibraryChars = 5479 const char* kLibraryChars =
5480 "#library('patched_library');\n" 5480 "#library('patched_library');\n"
5481 "class A {\n" 5481 "class A {\n"
5482 " var _f;\n"
5482 " external method(var value);\n" 5483 " external method(var value);\n"
5483 "}\n" 5484 "}\n"
5484 "external int topLevel(var value);\n"; 5485 "external int unpatched();\n"
5486 "external int topLevel(var value);\n"
5487 "external int get topLevelGetter();\n"
5488 "external void set topLevelSetter(int value);\n";
5485 5489
5486 const char* kPatchChars = 5490 const char* kPatchChars =
5487 "patch int topLevel(var value) => value * value;\n"; 5491 "var _topLevelValue = -1;"
5492 "patch int topLevel(var value) => value * value;\n"
5493 "patch int set topLevelSetter(value) { _topLevelValue = value; }\n"
5494 "patch int get topLevelGetter() => 2 * _topLevelValue;\n"
5495 // Allow top level methods named patch.
5496 "patch(x) => x*3;\n";
5488 5497
5489 const char* kScriptChars = 5498 const char* kScriptChars =
5490 "#import('theLibrary');\n" 5499 "#import('theLibrary');\n"
5491 "main() {\n" 5500 "e1() => unpatched();\n"
5492 // TODO(iposva): Implement patching. 5501 "m1() => topLevel(2);\n"
5493 " return 4 /* topLevel(2) */;\n" 5502 "m2() {\n"
5494 "}\n"; 5503 " topLevelSetter = 20;\n"
5504 " return topLevelGetter;\n"
5505 "}\n"
5506 "m3() => patch(7);\n";
5495 5507
5496 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); 5508 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler);
5497 EXPECT_VALID(result); 5509 EXPECT_VALID(result);
5498 5510
5499 Dart_Handle lib_url = Dart_NewString("theLibrary"); 5511 Dart_Handle lib_url = Dart_NewString("theLibrary");
5500 Dart_Handle source = Dart_NewString(kLibraryChars); 5512 Dart_Handle source = Dart_NewString(kLibraryChars);
5501 result = Dart_LoadLibrary(lib_url, source); 5513 result = Dart_LoadLibrary(lib_url, source);
5502 EXPECT_VALID(result); 5514 EXPECT_VALID(result);
5503 5515
5504 // TODO(iposva): Implement patching. 5516 const String& url = String::Handle(String::New("theLibrary"));
5505 source = Dart_NewString(kPatchChars); 5517 const String& patch_source = String::Handle(String::New(kPatchChars));
5518 const Library& lib = Library::Handle(Library::LookupLibrary(url));
5519 const Error& err = Error::Handle(lib.Patch(url, patch_source));
5520 if (!err.IsNull()) {
5521 OS::Print("Patching error: %s\n", err.ToErrorCString());
5522 EXPECT(false);
5523 }
5506 5524
5507 Dart_Handle script_url = Dart_NewString("theScript"); 5525 Dart_Handle script_url = Dart_NewString("theScript");
5508 source = Dart_NewString(kScriptChars); 5526 source = Dart_NewString(kScriptChars);
5509 result = Dart_LoadScript(script_url, source); 5527 Dart_Handle test_script = Dart_LoadScript(script_url, source);
5510 EXPECT_VALID(result); 5528 EXPECT_VALID(test_script);
5511 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 5529
5530 result = Dart_Invoke(test_script, Dart_NewString("e1"), 0, NULL);
5531 EXPECT_ERROR(result, "External implementation missing");
5532
5533 int64_t value = 0;
5534 result = Dart_Invoke(test_script, Dart_NewString("m1"), 0, NULL);
5512 EXPECT_VALID(result); 5535 EXPECT_VALID(result);
5513 EXPECT(Dart_IsInteger(result)); 5536 EXPECT(Dart_IsInteger(result));
5514 int64_t value = 0;
5515 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 5537 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
5516 EXPECT_EQ(4, value); 5538 EXPECT_EQ(4, value);
5539
5540 value = 0;
5541 result = Dart_Invoke(test_script, Dart_NewString("m2"), 0, NULL);
5542 EXPECT_VALID(result);
5543 EXPECT(Dart_IsInteger(result));
5544 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
5545 EXPECT_EQ(40, value);
5546
5547 value = 0;
5548 result = Dart_Invoke(test_script, Dart_NewString("m3"), 0, NULL);
5549 EXPECT_VALID(result);
5550 EXPECT(Dart_IsInteger(result));
5551 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
5552 EXPECT_EQ(21, value);
5517 } 5553 }
5518 5554
5519 5555
5520 static void MyNativeFunction1(Dart_NativeArguments args) { 5556 static void MyNativeFunction1(Dart_NativeArguments args) {
5521 Dart_EnterScope(); 5557 Dart_EnterScope();
5522 Dart_SetReturnValue(args, Dart_NewInteger(654321)); 5558 Dart_SetReturnValue(args, Dart_NewInteger(654321));
5523 Dart_ExitScope(); 5559 Dart_ExitScope();
5524 } 5560 }
5525 5561
5526 5562
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
6523 EXPECT(Dart_IsString(str)); 6559 EXPECT(Dart_IsString(str));
6524 len = -1; 6560 len = -1;
6525 EXPECT_VALID(Dart_StringLength(str, &len)); 6561 EXPECT_VALID(Dart_StringLength(str, &len));
6526 EXPECT_EQ(0, len); 6562 EXPECT_EQ(0, len);
6527 } 6563 }
6528 6564
6529 6565
6530 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 6566 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
6531 6567
6532 } // namespace dart 6568 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698