| Index: test/cctest/test-strings.cc
|
| diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
|
| index 80c8f92ac431ef8d0a714a3565db57a94d97dbd2..80cbd7a62e9b2d660b72ae1432d7133a4191ed08 100644
|
| --- a/test/cctest/test-strings.cc
|
| +++ b/test/cctest/test-strings.cc
|
| @@ -1608,3 +1608,38 @@ TEST(Regress609831) {
|
| CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString());
|
| }
|
| }
|
| +
|
| +TEST(ExternalStringIndexOf) {
|
| + CcTest::InitializeVM();
|
| + LocalContext context;
|
| + v8::HandleScope scope(CcTest::isolate());
|
| +
|
| + const char* raw_string = "abcdefghijklmnopqrstuvwxyz";
|
| + v8::Local<v8::String> string =
|
| + v8::String::NewExternalOneByte(CcTest::isolate(),
|
| + new StaticOneByteResource(raw_string))
|
| + .ToLocalChecked();
|
| + v8::Local<v8::Object> global = context->Global();
|
| + global->Set(context.local(), v8_str("external"), string).FromJust();
|
| +
|
| + char source[] = "external.indexOf('%')";
|
| + for (size_t i = 0; i < strlen(raw_string); i++) {
|
| + source[18] = raw_string[i];
|
| + int result_position = static_cast<int>(i);
|
| + CHECK_EQ(result_position,
|
| + CompileRun(source)->Int32Value(context.local()).FromJust());
|
| + }
|
| + CHECK_EQ(-1,
|
| + CompileRun("external.indexOf('abcdefghijklmnopqrstuvwxyz%%%%%%')")
|
| + ->Int32Value(context.local())
|
| + .FromJust());
|
| + CHECK_EQ(1, CompileRun("external.indexOf('', 1)")
|
| + ->Int32Value(context.local())
|
| + .FromJust());
|
| + CHECK_EQ(-1, CompileRun("external.indexOf('a', 1)")
|
| + ->Int32Value(context.local())
|
| + .FromJust());
|
| + CHECK_EQ(-1, CompileRun("external.indexOf('$')")
|
| + ->Int32Value(context.local())
|
| + .FromJust());
|
| +}
|
|
|