| 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 TEST_CASE(InstanceValues) { | 700 TEST_CASE(InstanceValues) { |
| 701 EXPECT(Dart_IsInstance(NewString("test"))); | 701 EXPECT(Dart_IsInstance(NewString("test"))); |
| 702 EXPECT(Dart_IsInstance(Dart_True())); | 702 EXPECT(Dart_IsInstance(Dart_True())); |
| 703 | 703 |
| 704 // By convention, our Is*() functions exclude null. | 704 // By convention, our Is*() functions exclude null. |
| 705 EXPECT(!Dart_IsInstance(Dart_Null())); | 705 EXPECT(!Dart_IsInstance(Dart_Null())); |
| 706 } | 706 } |
| 707 | 707 |
| 708 | 708 |
| 709 TEST_CASE(InstanceGetType) { | 709 TEST_CASE(InstanceGetType) { |
| 710 Isolate* isolate = Isolate::Current(); | 710 Zone* zone = thread->zone(); |
| 711 // Get the handle from a valid instance handle. | 711 // Get the handle from a valid instance handle. |
| 712 Dart_Handle type = Dart_InstanceGetType(Dart_Null()); | 712 Dart_Handle type = Dart_InstanceGetType(Dart_Null()); |
| 713 EXPECT_VALID(type); | 713 EXPECT_VALID(type); |
| 714 EXPECT(Dart_IsType(type)); | 714 EXPECT(Dart_IsType(type)); |
| 715 const Type& null_type_obj = Api::UnwrapTypeHandle(isolate, type); | 715 const Type& null_type_obj = Api::UnwrapTypeHandle(zone, type); |
| 716 EXPECT(null_type_obj.raw() == Type::NullType()); | 716 EXPECT(null_type_obj.raw() == Type::NullType()); |
| 717 | 717 |
| 718 Dart_Handle instance = Dart_True(); | 718 Dart_Handle instance = Dart_True(); |
| 719 type = Dart_InstanceGetType(instance); | 719 type = Dart_InstanceGetType(instance); |
| 720 EXPECT_VALID(type); | 720 EXPECT_VALID(type); |
| 721 EXPECT(Dart_IsType(type)); | 721 EXPECT(Dart_IsType(type)); |
| 722 const Type& bool_type_obj = Api::UnwrapTypeHandle(isolate, type); | 722 const Type& bool_type_obj = Api::UnwrapTypeHandle(zone, type); |
| 723 EXPECT(bool_type_obj.raw() == Type::BoolType()); | 723 EXPECT(bool_type_obj.raw() == Type::BoolType()); |
| 724 | 724 |
| 725 Dart_Handle cls_name = Dart_TypeName(type); | 725 Dart_Handle cls_name = Dart_TypeName(type); |
| 726 EXPECT_VALID(cls_name); | 726 EXPECT_VALID(cls_name); |
| 727 const char* cls_name_cstr = ""; | 727 const char* cls_name_cstr = ""; |
| 728 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); | 728 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| 729 EXPECT_STREQ("bool", cls_name_cstr); | 729 EXPECT_STREQ("bool", cls_name_cstr); |
| 730 | 730 |
| 731 Dart_Handle qual_cls_name = Dart_QualifiedTypeName(type); | 731 Dart_Handle qual_cls_name = Dart_QualifiedTypeName(type); |
| 732 EXPECT_VALID(qual_cls_name); | 732 EXPECT_VALID(qual_cls_name); |
| (...skipping 4593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5326 Dart_Handle args[kNumArgs]; | 5326 Dart_Handle args[kNumArgs]; |
| 5327 args[0] = Dart_NewInteger(1); | 5327 args[0] = Dart_NewInteger(1); |
| 5328 Dart_Handle list_obj = Dart_New(list_type, Dart_Null(), kNumArgs, args); | 5328 Dart_Handle list_obj = Dart_New(list_type, Dart_Null(), kNumArgs, args); |
| 5329 EXPECT_VALID(list_obj); | 5329 EXPECT_VALID(list_obj); |
| 5330 EXPECT(Dart_IsList(list_obj)); | 5330 EXPECT(Dart_IsList(list_obj)); |
| 5331 } | 5331 } |
| 5332 | 5332 |
| 5333 | 5333 |
| 5334 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { | 5334 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { |
| 5335 EXPECT(Dart_IsLibrary(lib)); | 5335 EXPECT(Dart_IsLibrary(lib)); |
| 5336 Isolate* isolate = Isolate::Current(); | 5336 Thread* thread = Thread::Current(); |
| 5337 const Library& library_obj = Api::UnwrapLibraryHandle(isolate, lib); | 5337 const Library& library_obj = Api::UnwrapLibraryHandle(thread->zone(), lib); |
| 5338 const String& name = String::Handle(String::New(str)); | 5338 const String& name = String::Handle(String::New(str)); |
| 5339 return Api::NewHandle(isolate, library_obj.PrivateName(name)); | 5339 return Api::NewHandle(thread->isolate(), library_obj.PrivateName(name)); |
| 5340 } | 5340 } |
| 5341 | 5341 |
| 5342 | 5342 |
| 5343 TEST_CASE(Invoke) { | 5343 TEST_CASE(Invoke) { |
| 5344 const char* kScriptChars = | 5344 const char* kScriptChars = |
| 5345 "class BaseMethods {\n" | 5345 "class BaseMethods {\n" |
| 5346 " inheritedMethod(arg) => 'inherited $arg';\n" | 5346 " inheritedMethod(arg) => 'inherited $arg';\n" |
| 5347 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" | 5347 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" |
| 5348 "}\n" | 5348 "}\n" |
| 5349 "\n" | 5349 "\n" |
| (...skipping 3517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8867 EXPECT(Dart_IsExternalString(utf16_str)); | 8867 EXPECT(Dart_IsExternalString(utf16_str)); |
| 8868 EXPECT_VALID(Dart_StringLength(str, &length)); | 8868 EXPECT_VALID(Dart_StringLength(str, &length)); |
| 8869 EXPECT_EQ(expected_length, length); | 8869 EXPECT_EQ(expected_length, length); |
| 8870 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); | 8870 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); |
| 8871 EXPECT_EQ(expected_length, length); | 8871 EXPECT_EQ(expected_length, length); |
| 8872 EXPECT(Dart_IdentityEquals(str, utf16_str)); | 8872 EXPECT(Dart_IdentityEquals(str, utf16_str)); |
| 8873 for (intptr_t i = 0; i < length; i++) { | 8873 for (intptr_t i = 0; i < length; i++) { |
| 8874 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); | 8874 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); |
| 8875 } | 8875 } |
| 8876 | 8876 |
| 8877 Zone* zone = thread->zone(); |
| 8877 // Test with a symbol (hash value should be preserved on externalization). | 8878 // Test with a symbol (hash value should be preserved on externalization). |
| 8878 const char* symbol_ascii = "?unseen"; | 8879 const char* symbol_ascii = "?unseen"; |
| 8879 expected_length = strlen(symbol_ascii); | 8880 expected_length = strlen(symbol_ascii); |
| 8880 Dart_Handle symbol_str = | 8881 Dart_Handle symbol_str = |
| 8881 Api::NewHandle(isolate, Symbols::New(symbol_ascii, expected_length)); | 8882 Api::NewHandle(isolate, Symbols::New(symbol_ascii, expected_length)); |
| 8882 EXPECT_VALID(symbol_str); | 8883 EXPECT_VALID(symbol_str); |
| 8883 EXPECT(Dart_IsString(symbol_str)); | 8884 EXPECT(Dart_IsString(symbol_str)); |
| 8884 EXPECT(Dart_IsStringLatin1(symbol_str)); | 8885 EXPECT(Dart_IsStringLatin1(symbol_str)); |
| 8885 EXPECT(!Dart_IsExternalString(symbol_str)); | 8886 EXPECT(!Dart_IsExternalString(symbol_str)); |
| 8886 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); | 8887 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); |
| 8887 EXPECT_EQ(expected_length, length); | 8888 EXPECT_EQ(expected_length, length); |
| 8888 EXPECT(Api::UnwrapStringHandle(isolate, symbol_str).HasHash()); | 8889 EXPECT(Api::UnwrapStringHandle(zone, symbol_str).HasHash()); |
| 8889 | 8890 |
| 8890 uint8_t ext_symbol_ascii[kLength]; | 8891 uint8_t ext_symbol_ascii[kLength]; |
| 8891 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); | 8892 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); |
| 8892 str = Dart_MakeExternalString(symbol_str, | 8893 str = Dart_MakeExternalString(symbol_str, |
| 8893 ext_symbol_ascii, | 8894 ext_symbol_ascii, |
| 8894 size, | 8895 size, |
| 8895 &peer8, | 8896 &peer8, |
| 8896 MakeExternalCback); | 8897 MakeExternalCback); |
| 8897 EXPECT(Api::UnwrapStringHandle(isolate, str).HasHash()); | 8898 EXPECT(Api::UnwrapStringHandle(zone, str).HasHash()); |
| 8898 EXPECT(Api::UnwrapStringHandle(isolate, str).Hash() == | 8899 EXPECT(Api::UnwrapStringHandle(zone, str).Hash() == |
| 8899 Api::UnwrapStringHandle(isolate, symbol_str).Hash()); | 8900 Api::UnwrapStringHandle(zone, symbol_str).Hash()); |
| 8900 EXPECT(Dart_IsString(str)); | 8901 EXPECT(Dart_IsString(str)); |
| 8901 EXPECT(Dart_IsString(symbol_str)); | 8902 EXPECT(Dart_IsString(symbol_str)); |
| 8902 EXPECT(Dart_IsStringLatin1(str)); | 8903 EXPECT(Dart_IsStringLatin1(str)); |
| 8903 EXPECT(Dart_IsStringLatin1(symbol_str)); | 8904 EXPECT(Dart_IsStringLatin1(symbol_str)); |
| 8904 EXPECT(Dart_IsExternalString(str)); | 8905 EXPECT(Dart_IsExternalString(str)); |
| 8905 EXPECT(Dart_IsExternalString(symbol_str)); | 8906 EXPECT(Dart_IsExternalString(symbol_str)); |
| 8906 EXPECT_VALID(Dart_StringLength(str, &length)); | 8907 EXPECT_VALID(Dart_StringLength(str, &length)); |
| 8907 EXPECT_EQ(expected_length, length); | 8908 EXPECT_EQ(expected_length, length); |
| 8908 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); | 8909 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); |
| 8909 EXPECT_EQ(expected_length, length); | 8910 EXPECT_EQ(expected_length, length); |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9779 | 9780 |
| 9780 // Heartbeat test for new events. | 9781 // Heartbeat test for new events. |
| 9781 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9782 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
| 9782 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9783 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9783 | 9784 |
| 9784 // Free buffer allocated by AppendStreamConsumer | 9785 // Free buffer allocated by AppendStreamConsumer |
| 9785 free(data.buffer); | 9786 free(data.buffer); |
| 9786 } | 9787 } |
| 9787 | 9788 |
| 9788 } // namespace dart | 9789 } // namespace dart |
| OLD | NEW |