| 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_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 8310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8321 EXPECT(Dart_IsExternalString(utf16_str)); | 8321 EXPECT(Dart_IsExternalString(utf16_str)); |
| 8322 EXPECT_VALID(Dart_StringLength(str, &length)); | 8322 EXPECT_VALID(Dart_StringLength(str, &length)); |
| 8323 EXPECT_EQ(expected_length, length); | 8323 EXPECT_EQ(expected_length, length); |
| 8324 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); | 8324 EXPECT_VALID(Dart_StringLength(utf16_str, &length)); |
| 8325 EXPECT_EQ(expected_length, length); | 8325 EXPECT_EQ(expected_length, length); |
| 8326 EXPECT(Dart_IdentityEquals(str, utf16_str)); | 8326 EXPECT(Dart_IdentityEquals(str, utf16_str)); |
| 8327 for (intptr_t i = 0; i < length; i++) { | 8327 for (intptr_t i = 0; i < length; i++) { |
| 8328 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); | 8328 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); |
| 8329 } | 8329 } |
| 8330 | 8330 |
| 8331 // Test with a symbol (hash value should be preserved on externalization). |
| 8332 const char* symbol_ascii = "string"; |
| 8333 expected_length = strlen(symbol_ascii); |
| 8334 Dart_Handle symbol_str = |
| 8335 Api::NewHandle(isolate, Symbols::New(symbol_ascii, expected_length)); |
| 8336 EXPECT_VALID(symbol_str); |
| 8337 EXPECT(Dart_IsString(symbol_str)); |
| 8338 EXPECT(Dart_IsStringLatin1(symbol_str)); |
| 8339 EXPECT(!Dart_IsExternalString(symbol_str)); |
| 8340 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); |
| 8341 EXPECT_EQ(expected_length, length); |
| 8342 EXPECT(Api::UnwrapStringHandle(isolate, symbol_str).HasHash()); |
| 8343 |
| 8344 uint8_t ext_symbol_ascii[kLength]; |
| 8345 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); |
| 8346 str = Dart_MakeExternalString(symbol_str, |
| 8347 ext_symbol_ascii, |
| 8348 size, |
| 8349 &peer8, |
| 8350 MakeExternalCback); |
| 8351 EXPECT(Api::UnwrapStringHandle(isolate, str).HasHash()); |
| 8352 EXPECT(Api::UnwrapStringHandle(isolate, str).Hash() == |
| 8353 Api::UnwrapStringHandle(isolate, symbol_str).Hash()); |
| 8354 EXPECT(Dart_IsString(str)); |
| 8355 EXPECT(Dart_IsString(symbol_str)); |
| 8356 EXPECT(Dart_IsStringLatin1(str)); |
| 8357 EXPECT(Dart_IsStringLatin1(symbol_str)); |
| 8358 EXPECT(Dart_IsExternalString(str)); |
| 8359 EXPECT(Dart_IsExternalString(symbol_str)); |
| 8360 EXPECT_VALID(Dart_StringLength(str, &length)); |
| 8361 EXPECT_EQ(expected_length, length); |
| 8362 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); |
| 8363 EXPECT_EQ(expected_length, length); |
| 8364 EXPECT(Dart_IdentityEquals(str, symbol_str)); |
| 8365 for (intptr_t i = 0; i < length; i++) { |
| 8366 EXPECT_EQ(symbol_ascii[i], ext_symbol_ascii[i]); |
| 8367 } |
| 8368 |
| 8331 Dart_ExitScope(); | 8369 Dart_ExitScope(); |
| 8332 } | 8370 } |
| 8333 EXPECT_EQ(40, peer8); | 8371 EXPECT_EQ(40, peer8); |
| 8334 EXPECT_EQ(41, peer16); | 8372 EXPECT_EQ(41, peer16); |
| 8335 EXPECT_EQ(42, canonical_str_peer); | 8373 EXPECT_EQ(42, canonical_str_peer); |
| 8336 Isolate::Current()->heap()->CollectAllGarbage(); | 8374 Isolate::Current()->heap()->CollectAllGarbage(); |
| 8337 EXPECT_EQ(80, peer8); | 8375 EXPECT_EQ(80, peer8); |
| 8338 EXPECT_EQ(82, peer16); | 8376 EXPECT_EQ(82, peer16); |
| 8339 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8377 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
| 8340 } | 8378 } |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8606 NewString("main"), | 8644 NewString("main"), |
| 8607 1, | 8645 1, |
| 8608 dart_args); | 8646 dart_args); |
| 8609 int64_t value = 0; | 8647 int64_t value = 0; |
| 8610 result = Dart_IntegerToInt64(result, &value); | 8648 result = Dart_IntegerToInt64(result, &value); |
| 8611 EXPECT_VALID(result); | 8649 EXPECT_VALID(result); |
| 8612 EXPECT_EQ(6, value); | 8650 EXPECT_EQ(6, value); |
| 8613 } | 8651 } |
| 8614 | 8652 |
| 8615 } // namespace dart | 8653 } // namespace dart |
| OLD | NEW |