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

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

Issue 22632010: Added following dart API changes to enable more efficient access based (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.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 "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 "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 uint8_t latin1[] = { 'o', 'n', 'e', 0xC2, 0xA2 }; 535 uint8_t latin1[] = { 'o', 'n', 'e', 0xC2, 0xA2 };
536 536
537 Dart_Handle latin1str = Dart_NewStringFromUTF8(latin1, ARRAY_SIZE(latin1)); 537 Dart_Handle latin1str = Dart_NewStringFromUTF8(latin1, ARRAY_SIZE(latin1));
538 EXPECT_VALID(latin1str); 538 EXPECT_VALID(latin1str);
539 EXPECT(Dart_IsString(latin1str)); 539 EXPECT(Dart_IsString(latin1str));
540 EXPECT(Dart_IsStringLatin1(latin1str)); 540 EXPECT(Dart_IsStringLatin1(latin1str));
541 EXPECT(!Dart_IsExternalString(latin1str)); 541 EXPECT(!Dart_IsExternalString(latin1str));
542 intptr_t len = -1; 542 intptr_t len = -1;
543 EXPECT_VALID(Dart_StringLength(latin1str, &len)); 543 EXPECT_VALID(Dart_StringLength(latin1str, &len));
544 EXPECT_EQ(4, len); 544 EXPECT_EQ(4, len);
545 intptr_t char_size;
546 intptr_t str_len;
547 void* peer;
548 EXPECT_VALID(Dart_StringGetProperties(latin1str,
549 &char_size,
550 &str_len,
551 &peer));
552 EXPECT_EQ(1, char_size);
553 EXPECT_EQ(4, str_len);
554 EXPECT(!peer);
545 555
546 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; 556 uint8_t data8[] = { 'o', 'n', 'e', 0x7F };
547 557
548 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); 558 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8));
549 EXPECT_VALID(str8); 559 EXPECT_VALID(str8);
550 EXPECT(Dart_IsString(str8)); 560 EXPECT(Dart_IsString(str8));
551 EXPECT(Dart_IsStringLatin1(str8)); 561 EXPECT(Dart_IsStringLatin1(str8));
552 EXPECT(!Dart_IsExternalString(str8)); 562 EXPECT(!Dart_IsExternalString(str8));
553 563
554 uint8_t latin1_array[] = {0, 0, 0, 0, 0}; 564 uint8_t latin1_array[] = {0, 0, 0, 0, 0};
555 len = 5; 565 len = 5;
556 Dart_Handle result = Dart_StringToLatin1(str8, latin1_array, &len); 566 Dart_Handle result = Dart_StringToLatin1(str8, latin1_array, &len);
557 EXPECT_VALID(result); 567 EXPECT_VALID(result);
558 EXPECT_EQ(4, len); 568 EXPECT_EQ(4, len);
559 EXPECT(latin1_array != NULL); 569 EXPECT(latin1_array != NULL);
560 for (intptr_t i = 0; i < len; i++) { 570 for (intptr_t i = 0; i < len; i++) {
561 EXPECT_EQ(data8[i], latin1_array[i]); 571 EXPECT_EQ(data8[i], latin1_array[i]);
562 } 572 }
563 573
564 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), 574 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8),
565 NULL, NULL); 575 data8, NULL);
566 EXPECT_VALID(ext8); 576 EXPECT_VALID(ext8);
567 EXPECT(Dart_IsString(ext8)); 577 EXPECT(Dart_IsString(ext8));
568 EXPECT(Dart_IsExternalString(ext8)); 578 EXPECT(Dart_IsExternalString(ext8));
579 EXPECT_VALID(Dart_StringGetProperties(ext8,
580 &char_size,
581 &str_len,
582 &peer));
583 EXPECT_EQ(1, char_size);
584 EXPECT_EQ(4, str_len);
585 EXPECT_EQ(data8, peer);
569 586
570 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; 587 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF };
571 588
572 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); 589 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16));
573 EXPECT_VALID(str16); 590 EXPECT_VALID(str16);
574 EXPECT(Dart_IsString(str16)); 591 EXPECT(Dart_IsString(str16));
575 EXPECT(!Dart_IsStringLatin1(str16)); 592 EXPECT(!Dart_IsStringLatin1(str16));
576 EXPECT(!Dart_IsExternalString(str16)); 593 EXPECT(!Dart_IsExternalString(str16));
594 EXPECT_VALID(Dart_StringGetProperties(str16,
595 &char_size,
596 &str_len,
597 &peer));
598 EXPECT_EQ(2, char_size);
599 EXPECT_EQ(4, str_len);
600 EXPECT(!peer);
577 601
578 Dart_Handle ext16 = Dart_NewExternalUTF16String(data16, ARRAY_SIZE(data16), 602 Dart_Handle ext16 = Dart_NewExternalUTF16String(data16, ARRAY_SIZE(data16),
579 NULL, NULL); 603 data16, NULL);
580 EXPECT_VALID(ext16); 604 EXPECT_VALID(ext16);
581 EXPECT(Dart_IsString(ext16)); 605 EXPECT(Dart_IsString(ext16));
582 EXPECT(Dart_IsExternalString(ext16)); 606 EXPECT(Dart_IsExternalString(ext16));
607 EXPECT_VALID(Dart_StringGetProperties(ext16,
608 &char_size,
609 &str_len,
610 &peer));
611 EXPECT_EQ(2, char_size);
612 EXPECT_EQ(4, str_len);
613 EXPECT_EQ(data16, peer);
583 614
584 int32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; 615 int32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF };
585 616
586 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); 617 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32));
587 EXPECT_VALID(str32); 618 EXPECT_VALID(str32);
588 EXPECT(Dart_IsString(str32)); 619 EXPECT(Dart_IsString(str32));
589 EXPECT(!Dart_IsExternalString(str32)); 620 EXPECT(!Dart_IsExternalString(str32));
590 } 621 }
591 622
592 623
(...skipping 6505 matching lines...) Expand 10 before | Expand all | Expand 10 after
7098 // Test external strings and optimized code. 7129 // Test external strings and optimized code.
7099 static void ExternalStringDeoptimize_Finalize(void* peer) { 7130 static void ExternalStringDeoptimize_Finalize(void* peer) {
7100 delete[] reinterpret_cast<char*>(peer); 7131 delete[] reinterpret_cast<char*>(peer);
7101 } 7132 }
7102 7133
7103 7134
7104 static void A_change_str_native(Dart_NativeArguments args) { 7135 static void A_change_str_native(Dart_NativeArguments args) {
7105 Dart_EnterScope(); 7136 Dart_EnterScope();
7106 Dart_Handle str = Dart_GetNativeArgument(args, 0); 7137 Dart_Handle str = Dart_GetNativeArgument(args, 0);
7107 EXPECT(Dart_IsString(str)); 7138 EXPECT(Dart_IsString(str));
7139 void* peer;
7140 Dart_Handle str_arg = Dart_GetNativeStringArgument(args, 0, &peer);
7141 EXPECT(Dart_IsString(str_arg));
7142 EXPECT(!peer);
7108 intptr_t size = 0; 7143 intptr_t size = 0;
7109 EXPECT_VALID(Dart_StringStorageSize(str, &size)); 7144 EXPECT_VALID(Dart_StringStorageSize(str, &size));
7145 intptr_t arg_size = 0;
7146 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size));
7147 EXPECT_EQ(size, arg_size);
7110 char* str_data = new char[size]; 7148 char* str_data = new char[size];
7111 Dart_Handle result = 7149 Dart_Handle result =
7112 Dart_MakeExternalString(str, 7150 Dart_MakeExternalString(str,
7113 str_data, 7151 str_data,
7114 size, 7152 size,
7115 str_data, 7153 str_data,
7116 &ExternalStringDeoptimize_Finalize); 7154 &ExternalStringDeoptimize_Finalize);
7117 EXPECT_VALID(result); 7155 EXPECT_VALID(result);
7118 Dart_ExitScope(); 7156 Dart_ExitScope();
7119 } 7157 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
7252 NewString("main"), 7290 NewString("main"),
7253 0, 7291 0,
7254 NULL); 7292 NULL);
7255 int64_t value = 0; 7293 int64_t value = 0;
7256 result = Dart_IntegerToInt64(result, &value); 7294 result = Dart_IntegerToInt64(result, &value);
7257 EXPECT_VALID(result); 7295 EXPECT_VALID(result);
7258 EXPECT_EQ(8, value); 7296 EXPECT_EQ(8, value);
7259 } 7297 }
7260 7298
7261 } // namespace dart 7299 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698