| 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 " final fvalue;\n" |
| 5482 " var _f;\n" | 5483 " var _f;\n" |
| 5483 " callFunc(x, y) => x(y);\n" | 5484 " callFunc(x, y) => x(y);\n" |
| 5484 " external method(var value);\n" | 5485 " external method(var value);\n" |
| 5485 " get field() => _field;\n" | 5486 " get field() => _field;\n" |
| 5486 "}\n" | 5487 "}\n" |
| 5487 "external int unpatched();\n" | 5488 "external int unpatched();\n" |
| 5488 "external int topLevel(var value);\n" | 5489 "external int topLevel(var value);\n" |
| 5489 "external int get topLevelGetter();\n" | 5490 "external int get topLevelGetter();\n" |
| 5490 "external void set topLevelSetter(int value);\n"; | 5491 "external void set topLevelSetter(int value);\n"; |
| 5491 | 5492 |
| 5492 const char* kPatchChars = | 5493 const char* kPatchChars = |
| 5493 "patch class A {\n" | 5494 "patch class A {\n" |
| 5494 " var _g;\n" | 5495 " var _g;\n" |
| 5496 " A() : fvalue = 13;\n" |
| 5495 " get _field() => _g;\n" | 5497 " get _field() => _g;\n" |
| 5496 " patch method(var value) {\n" | 5498 " patch method(var value) {\n" |
| 5497 " int closeYourEyes(var eggs) { return eggs * -1; }\n" | 5499 " int closeYourEyes(var eggs) { return eggs * -1; }\n" |
| 5498 " value = callFunc(closeYourEyes, value);\n" | 5500 " value = callFunc(closeYourEyes, value);\n" |
| 5499 " _g = value * 5;\n" | 5501 " _g = value * 5;\n" |
| 5500 " }\n" | 5502 " }\n" |
| 5501 "}\n" | 5503 "}\n" |
| 5502 "var _topLevelValue = -1;\n" | 5504 "var _topLevelValue = -1;\n" |
| 5503 "patch int topLevel(var value) => value * value;\n" | 5505 "patch int topLevel(var value) => value * value;\n" |
| 5504 "patch int set topLevelSetter(value) { _topLevelValue = value; }\n" | 5506 "patch int set topLevelSetter(value) { _topLevelValue = value; }\n" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5540 if (!err.IsNull()) { | 5542 if (!err.IsNull()) { |
| 5541 OS::Print("Patching error: %s\n", err.ToErrorCString()); | 5543 OS::Print("Patching error: %s\n", err.ToErrorCString()); |
| 5542 EXPECT(false); | 5544 EXPECT(false); |
| 5543 } | 5545 } |
| 5544 | 5546 |
| 5545 Dart_Handle script_url = Dart_NewString("theScript"); | 5547 Dart_Handle script_url = Dart_NewString("theScript"); |
| 5546 source = Dart_NewString(kScriptChars); | 5548 source = Dart_NewString(kScriptChars); |
| 5547 Dart_Handle test_script = Dart_LoadScript(script_url, source); | 5549 Dart_Handle test_script = Dart_LoadScript(script_url, source); |
| 5548 EXPECT_VALID(test_script); | 5550 EXPECT_VALID(test_script); |
| 5549 | 5551 |
| 5552 // Make sure that we can compile all of the patched code. |
| 5553 result = Dart_CompileAll(); |
| 5554 EXPECT_VALID(result); |
| 5555 |
| 5550 result = Dart_Invoke(test_script, Dart_NewString("e1"), 0, NULL); | 5556 result = Dart_Invoke(test_script, Dart_NewString("e1"), 0, NULL); |
| 5551 EXPECT_ERROR(result, "External implementation missing"); | 5557 EXPECT_ERROR(result, "External implementation missing"); |
| 5552 | 5558 |
| 5553 int64_t value = 0; | 5559 int64_t value = 0; |
| 5554 result = Dart_Invoke(test_script, Dart_NewString("m1"), 0, NULL); | 5560 result = Dart_Invoke(test_script, Dart_NewString("m1"), 0, NULL); |
| 5555 EXPECT_VALID(result); | 5561 EXPECT_VALID(result); |
| 5556 EXPECT(Dart_IsInteger(result)); | 5562 EXPECT(Dart_IsInteger(result)); |
| 5557 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5563 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5558 EXPECT_EQ(4, value); | 5564 EXPECT_EQ(4, value); |
| 5559 | 5565 |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6586 EXPECT(Dart_IsString(str)); | 6592 EXPECT(Dart_IsString(str)); |
| 6587 len = -1; | 6593 len = -1; |
| 6588 EXPECT_VALID(Dart_StringLength(str, &len)); | 6594 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6589 EXPECT_EQ(0, len); | 6595 EXPECT_EQ(0, len); |
| 6590 } | 6596 } |
| 6591 | 6597 |
| 6592 | 6598 |
| 6593 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6599 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6594 | 6600 |
| 6595 } // namespace dart | 6601 } // namespace dart |
| OLD | NEW |