| 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 7244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7255 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size)); | 7255 EXPECT_VALID(Dart_StringStorageSize(str_arg, &arg_size)); |
| 7256 EXPECT_EQ(size, arg_size); | 7256 EXPECT_EQ(size, arg_size); |
| 7257 char* str_data = new char[size]; | 7257 char* str_data = new char[size]; |
| 7258 Dart_Handle result = | 7258 Dart_Handle result = |
| 7259 Dart_MakeExternalString(str, | 7259 Dart_MakeExternalString(str, |
| 7260 str_data, | 7260 str_data, |
| 7261 size, | 7261 size, |
| 7262 str_data, | 7262 str_data, |
| 7263 &ExternalStringDeoptimize_Finalize); | 7263 &ExternalStringDeoptimize_Finalize); |
| 7264 EXPECT_VALID(result); | 7264 EXPECT_VALID(result); |
| 7265 EXPECT(Dart_IsExternalString(result)); |
| 7265 Dart_ExitScope(); | 7266 Dart_ExitScope(); |
| 7266 } | 7267 } |
| 7267 | 7268 |
| 7268 | 7269 |
| 7269 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( | 7270 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( |
| 7270 Dart_Handle name, int argument_count) { | 7271 Dart_Handle name, int argument_count) { |
| 7271 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); | 7272 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); |
| 7272 } | 7273 } |
| 7273 | 7274 |
| 7274 | 7275 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7398 Dart_Handle result = Dart_Invoke(lib, | 7399 Dart_Handle result = Dart_Invoke(lib, |
| 7399 NewString("main"), | 7400 NewString("main"), |
| 7400 0, | 7401 0, |
| 7401 NULL); | 7402 NULL); |
| 7402 int64_t value = 0; | 7403 int64_t value = 0; |
| 7403 result = Dart_IntegerToInt64(result, &value); | 7404 result = Dart_IntegerToInt64(result, &value); |
| 7404 EXPECT_VALID(result); | 7405 EXPECT_VALID(result); |
| 7405 EXPECT_EQ(8, value); | 7406 EXPECT_EQ(8, value); |
| 7406 } | 7407 } |
| 7407 | 7408 |
| 7409 |
| 7410 TEST_CASE(ExternalStringIndexOf) { |
| 7411 const char* kScriptChars = |
| 7412 "main(String pattern) {\n" |
| 7413 " var str = 'Hello World';\n" |
| 7414 " return str.indexOf(pattern);\n" |
| 7415 "}\n"; |
| 7416 Dart_Handle lib = |
| 7417 TestCase::LoadTestScript(kScriptChars, NULL); |
| 7418 |
| 7419 uint8_t data8[] = { 'W' }; |
| 7420 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), |
| 7421 data8, NULL); |
| 7422 EXPECT_VALID(ext8); |
| 7423 EXPECT(Dart_IsString(ext8)); |
| 7424 EXPECT(Dart_IsExternalString(ext8)); |
| 7425 |
| 7426 Dart_Handle dart_args[1]; |
| 7427 dart_args[0] = ext8; |
| 7428 Dart_Handle result = Dart_Invoke(lib, |
| 7429 NewString("main"), |
| 7430 1, |
| 7431 dart_args); |
| 7432 int64_t value = 0; |
| 7433 result = Dart_IntegerToInt64(result, &value); |
| 7434 EXPECT_VALID(result); |
| 7435 EXPECT_EQ(6, value); |
| 7436 } |
| 7437 |
| 7408 } // namespace dart | 7438 } // namespace dart |
| OLD | NEW |