| Index: test/cctest/test-api.cc
|
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
|
| index 5fa2a2fb3a0af7e0102c0b5fc980281db03ab6d6..25c5049e45140155574f027fe8a29bf8d2f061d8 100644
|
| --- a/test/cctest/test-api.cc
|
| +++ b/test/cctest/test-api.cc
|
| @@ -23848,15 +23848,31 @@ class TestSourceStream : public v8::ScriptCompiler::ExternalSourceStream {
|
| // too).
|
| static char* FullSourceString(const char** chunks) {
|
| size_t total_len = 0;
|
| + bool has_bom = false;
|
| for (size_t i = 0; chunks[i] != NULL; ++i) {
|
| total_len += strlen(chunks[i]);
|
| +
|
| + // Remove BOM when constructing the full source string; this simluates
|
| + // what the embedder does.
|
| + if (i == 0 && strlen(chunks[i]) >= 3 &&
|
| + chunks[i][0] == static_cast<char>(0xef) &&
|
| + chunks[i][1] == static_cast<char>(0xbb) &&
|
| + chunks[i][2] == static_cast<char>(0xbf)) {
|
| + total_len -= 3;
|
| + has_bom = true;
|
| + }
|
| }
|
| char* full_string = new char[total_len + 1];
|
| size_t offset = 0;
|
| for (size_t i = 0; chunks[i] != NULL; ++i) {
|
| size_t len = strlen(chunks[i]);
|
| - memcpy(full_string + offset, chunks[i], len);
|
| - offset += len;
|
| + if (has_bom) {
|
| + memcpy(full_string + offset, chunks[i] + 3, len - 3);
|
| + offset += len - 3;
|
| + } else {
|
| + memcpy(full_string + offset, chunks[i], len);
|
| + offset += len;
|
| + }
|
| }
|
| full_string[total_len] = 0;
|
| return full_string;
|
| @@ -23900,6 +23916,7 @@ void RunStreamingTest(const char** chunks,
|
| CHECK(!script.IsEmpty());
|
| v8::Handle<Value> result(script->Run());
|
| // All scripts are supposed to return the fixed value 13 when ran.
|
| + CHECK_EQ(false, try_catch.HasCaught());
|
| CHECK_EQ(13, result->Int32Value());
|
| } else {
|
| CHECK(script.IsEmpty());
|
| @@ -24191,3 +24208,24 @@ TEST(StreamingUtf8ScriptWithMultipleMultibyteCharactersSomeSplit2) {
|
| const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
|
| RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
|
| }
|
| +
|
| +
|
| +TEST(StreamingUtf8ScriptWithByteOrderMark) {
|
| + // Some Windows editors add the "UTF-8 BOM". If we don't handle it properly,
|
| + // some scripts might be parsed successfully but but the positions of lazy
|
| + // functions will be off.
|
| + i::FLAG_min_preparse_length = 0;
|
| + i::FLAG_lazy = true;
|
| + // Note that in this case the byte order mark doesn't actually cause a parse
|
| + // error, since it's a UTF-8 character followed by a comment.
|
| + char chunk1[] =
|
| + "XXX// That's the BOM.\n"
|
| + "function this_is_lazy() {\n"
|
| + " return 13;\n"
|
| + "}\n";
|
| + chunk1[0] = static_cast<char>(0xef);
|
| + chunk1[1] = static_cast<char>(0xbb);
|
| + chunk1[2] = static_cast<char>(0xbf);
|
| + const char* chunks[] = {chunk1, "this_is_lazy();", NULL};
|
| + RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
|
| +}
|
|
|