| OLD | NEW |
| 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 Loading... |
| 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"; |
| 5488 | 5495 |
| 5489 const char* kScriptChars = | 5496 const char* kScriptChars = |
| 5490 "#import('theLibrary');\n" | 5497 "#import('theLibrary');\n" |
| 5491 "main() {\n" | 5498 "e1() => unpatched();\n" |
| 5492 // TODO(iposva): Implement patching. | 5499 "m1() => topLevel(2);\n" |
| 5493 " return 4 /* topLevel(2) */;\n" | 5500 "m2() {\n" |
| 5501 " topLevelSetter = 20;\n" |
| 5502 " return topLevelGetter;\n" |
| 5494 "}\n"; | 5503 "}\n"; |
| 5495 | 5504 |
| 5496 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); | 5505 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); |
| 5497 EXPECT_VALID(result); | 5506 EXPECT_VALID(result); |
| 5498 | 5507 |
| 5499 Dart_Handle lib_url = Dart_NewString("theLibrary"); | 5508 Dart_Handle lib_url = Dart_NewString("theLibrary"); |
| 5500 Dart_Handle source = Dart_NewString(kLibraryChars); | 5509 Dart_Handle source = Dart_NewString(kLibraryChars); |
| 5501 result = Dart_LoadLibrary(lib_url, source); | 5510 result = Dart_LoadLibrary(lib_url, source); |
| 5502 EXPECT_VALID(result); | 5511 EXPECT_VALID(result); |
| 5503 | 5512 |
| 5504 // TODO(iposva): Implement patching. | 5513 const String& url = String::Handle(String::New("theLibrary")); |
| 5505 source = Dart_NewString(kPatchChars); | 5514 const String& patch_source = String::Handle(String::New(kPatchChars)); |
| 5515 const Library& lib = Library::Handle(Library::LookupLibrary(url)); |
| 5516 const Error& err = Error::Handle(lib.Patch(url, patch_source)); |
| 5517 if (!err.IsNull()) { |
| 5518 OS::Print("Patching error: %s\n", err.ToErrorCString()); |
| 5519 EXPECT(false); |
| 5520 } |
| 5506 | 5521 |
| 5507 Dart_Handle script_url = Dart_NewString("theScript"); | 5522 Dart_Handle script_url = Dart_NewString("theScript"); |
| 5508 source = Dart_NewString(kScriptChars); | 5523 source = Dart_NewString(kScriptChars); |
| 5509 result = Dart_LoadScript(script_url, source); | 5524 Dart_Handle test_script = Dart_LoadScript(script_url, source); |
| 5510 EXPECT_VALID(result); | 5525 EXPECT_VALID(test_script); |
| 5511 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 5526 |
| 5527 result = Dart_Invoke(test_script, Dart_NewString("e1"), 0, NULL); |
| 5528 EXPECT_ERROR(result, "External implementation missing"); |
| 5529 |
| 5530 int64_t value = 0; |
| 5531 result = Dart_Invoke(test_script, Dart_NewString("m1"), 0, NULL); |
| 5512 EXPECT_VALID(result); | 5532 EXPECT_VALID(result); |
| 5513 EXPECT(Dart_IsInteger(result)); | 5533 EXPECT(Dart_IsInteger(result)); |
| 5514 int64_t value = 0; | |
| 5515 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5534 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5516 EXPECT_EQ(4, value); | 5535 EXPECT_EQ(4, value); |
| 5536 |
| 5537 value = 0; |
| 5538 result = Dart_Invoke(test_script, Dart_NewString("m2"), 0, NULL); |
| 5539 EXPECT_VALID(result); |
| 5540 EXPECT(Dart_IsInteger(result)); |
| 5541 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5542 EXPECT_EQ(40, value); |
| 5517 } | 5543 } |
| 5518 | 5544 |
| 5519 | 5545 |
| 5520 static void MyNativeFunction1(Dart_NativeArguments args) { | 5546 static void MyNativeFunction1(Dart_NativeArguments args) { |
| 5521 Dart_EnterScope(); | 5547 Dart_EnterScope(); |
| 5522 Dart_SetReturnValue(args, Dart_NewInteger(654321)); | 5548 Dart_SetReturnValue(args, Dart_NewInteger(654321)); |
| 5523 Dart_ExitScope(); | 5549 Dart_ExitScope(); |
| 5524 } | 5550 } |
| 5525 | 5551 |
| 5526 | 5552 |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6523 EXPECT(Dart_IsString(str)); | 6549 EXPECT(Dart_IsString(str)); |
| 6524 len = -1; | 6550 len = -1; |
| 6525 EXPECT_VALID(Dart_StringLength(str, &len)); | 6551 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6526 EXPECT_EQ(0, len); | 6552 EXPECT_EQ(0, len); |
| 6527 } | 6553 } |
| 6528 | 6554 |
| 6529 | 6555 |
| 6530 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6556 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6531 | 6557 |
| 6532 } // namespace dart | 6558 } // namespace dart |
| OLD | NEW |