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

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

Issue 11264032: Introduce VM API for the patching mechanism. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Duplicate the code instead to keep error messages. 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
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | 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 5655 matching lines...) Expand 10 before | Expand all | Expand 10 after
5666 recv = Dart_New(cls, Dart_Null(), 0, NULL); 5666 recv = Dart_New(cls, Dart_Null(), 0, NULL);
5667 result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL); 5667 result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL);
5668 EXPECT_VALID(result); 5668 EXPECT_VALID(result);
5669 EXPECT(Dart_IsString(result)); 5669 EXPECT(Dart_IsString(result));
5670 result_cstr = ""; 5670 result_cstr = "";
5671 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); 5671 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
5672 EXPECT_STREQ("bar", result_cstr); 5672 EXPECT_STREQ("bar", result_cstr);
5673 } 5673 }
5674 5674
5675 5675
5676 TEST_CASE(LoadPatch) {
5677 const char* kLibrary1Chars =
5678 "#library('library1_name');";
5679 const char* kSourceChars =
5680 "external int foo();";
5681 const char* kPatchChars =
5682 "patch int foo() => 42;";
5683
5684 // Load up a library.
5685 Dart_Handle url = Dart_NewString("library1_url");
5686 Dart_Handle source = Dart_NewString(kLibrary1Chars);
5687 Dart_Handle lib = Dart_LoadLibrary(url, source);
5688 EXPECT_VALID(lib);
5689 EXPECT(Dart_IsLibrary(lib));
5690
5691 url = Dart_NewString("source_url");
5692 source = Dart_NewString(kSourceChars);
5693
5694 Dart_Handle result = Dart_LoadSource(lib, url, source);
5695 EXPECT_VALID(result);
5696
5697 url = Dart_NewString("patch_url");
5698 source = Dart_NewString(kPatchChars);
5699
5700 result = Dart_LoadPatch(lib, url, source);
5701 EXPECT_VALID(result);
5702
5703 result = Dart_Invoke(lib, Dart_NewString("foo"), 0, NULL);
5704 EXPECT_VALID(result);
5705 EXPECT(Dart_IsInteger(result));
5706 int64_t value = 0;
5707 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
5708 EXPECT_EQ(42, value);
5709 }
5710
5711
5676 static void PatchNativeFunction(Dart_NativeArguments args) { 5712 static void PatchNativeFunction(Dart_NativeArguments args) {
5677 Dart_EnterScope(); 5713 Dart_EnterScope();
5678 Dart_SetReturnValue(args, Dart_Null()); 5714 Dart_SetReturnValue(args, Dart_Null());
5679 Dart_ExitScope(); 5715 Dart_ExitScope();
5680 } 5716 }
5681 5717
5682 5718
5683 static Dart_NativeFunction PatchNativeResolver(Dart_Handle name, 5719 static Dart_NativeFunction PatchNativeResolver(Dart_Handle name,
5684 int arg_count) { 5720 int arg_count) {
5685 return &PatchNativeFunction; 5721 return &PatchNativeFunction;
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
7146 EXPECT(o2 == reinterpret_cast<void*>(&p2)); 7182 EXPECT(o2 == reinterpret_cast<void*>(&p2));
7147 } 7183 }
7148 Dart_ExitScope(); 7184 Dart_ExitScope();
7149 isolate->heap()->CollectGarbage(Heap::kOld); 7185 isolate->heap()->CollectGarbage(Heap::kOld);
7150 EXPECT_EQ(0, isolate->heap()->PeerCount()); 7186 EXPECT_EQ(0, isolate->heap()->PeerCount());
7151 } 7187 }
7152 7188
7153 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7189 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7154 7190
7155 } // namespace dart 7191 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698