OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 } | 1601 } |
1602 { | 1602 { |
1603 HandleScope scope(isolate); | 1603 HandleScope scope(isolate); |
1604 v8::Local<v8::Value> result = CompileRun( | 1604 v8::Local<v8::Value> result = CompileRun( |
1605 "String.fromCharCode(432, 432, 432, 432, 432, " | 1605 "String.fromCharCode(432, 432, 432, 432, 432, " |
1606 "432, 432, 432, 432, 432, 432, 432, 432, 432, " | 1606 "432, 432, 432, 432, 432, 432, 432, 432, 432, " |
1607 "432, 432, 432, 432, 432, 432, 432, 432, 432)"); | 1607 "432, 432, 432, 432, 432, 432, 432, 432, 432)"); |
1608 CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString()); | 1608 CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString()); |
1609 } | 1609 } |
1610 } | 1610 } |
| 1611 |
| 1612 TEST(ExternalStringIndexOf) { |
| 1613 CcTest::InitializeVM(); |
| 1614 LocalContext context; |
| 1615 v8::HandleScope scope(CcTest::isolate()); |
| 1616 |
| 1617 const char* raw_string = "abcdefghijklmnopqrstuvwxyz"; |
| 1618 v8::Local<v8::String> string = |
| 1619 v8::String::NewExternalOneByte(CcTest::isolate(), |
| 1620 new StaticOneByteResource(raw_string)) |
| 1621 .ToLocalChecked(); |
| 1622 v8::Local<v8::Object> global = context->Global(); |
| 1623 global->Set(context.local(), v8_str("external"), string).FromJust(); |
| 1624 |
| 1625 char source[] = "external.indexOf('%')"; |
| 1626 for (size_t i = 0; i < strlen(raw_string); i++) { |
| 1627 source[18] = raw_string[i]; |
| 1628 int result_position = static_cast<int>(i); |
| 1629 CHECK_EQ(result_position, |
| 1630 CompileRun(source)->Int32Value(context.local()).FromJust()); |
| 1631 } |
| 1632 CHECK_EQ(-1, |
| 1633 CompileRun("external.indexOf('abcdefghijklmnopqrstuvwxyz%%%%%%')") |
| 1634 ->Int32Value(context.local()) |
| 1635 .FromJust()); |
| 1636 CHECK_EQ(1, CompileRun("external.indexOf('', 1)") |
| 1637 ->Int32Value(context.local()) |
| 1638 .FromJust()); |
| 1639 CHECK_EQ(-1, CompileRun("external.indexOf('a', 1)") |
| 1640 ->Int32Value(context.local()) |
| 1641 .FromJust()); |
| 1642 CHECK_EQ(-1, CompileRun("external.indexOf('$')") |
| 1643 ->Int32Value(context.local()) |
| 1644 .FromJust()); |
| 1645 } |
OLD | NEW |