diff options
Diffstat (limited to 'deps/v8/test/cctest/test-parsing.cc')
-rw-r--r--[-rwxr-xr-x] | deps/v8/test/cctest/test-parsing.cc | 100 |
1 files changed, 61 insertions, 39 deletions
diff --git a/deps/v8/test/cctest/test-parsing.cc b/deps/v8/test/cctest/test-parsing.cc index 717c66519..c8956c9eb 100755..100644 --- a/deps/v8/test/cctest/test-parsing.cc +++ b/deps/v8/test/cctest/test-parsing.cc @@ -173,7 +173,7 @@ class ScriptResource : public v8::String::ExternalAsciiStringResource { TEST(Preparsing) { - v8::HandleScope handles; + v8::HandleScope handles(v8::Isolate::GetCurrent()); v8::Persistent<v8::Context> context = v8::Context::New(); v8::Context::Scope context_scope(context); int marker; @@ -351,7 +351,7 @@ TEST(Regress928) { "try { } catch (e) { var foo = function () { /* first */ } }" "var bar = function () { /* second */ }"; - v8::HandleScope handles; + v8::HandleScope handles(v8::Isolate::GetCurrent()); i::Handle<i::String> source( FACTORY->NewStringFromAscii(i::CStrVector(program))); i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); @@ -439,7 +439,7 @@ void TestCharacterStream(const char* ascii_source, unsigned end = 0) { if (end == 0) end = length; unsigned sub_length = end - start; - i::HandleScope test_scope; + i::HandleScope test_scope(i::Isolate::Current()); i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); for (unsigned i = 0; i < length; i++) { uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); @@ -544,7 +544,7 @@ void TestCharacterStream(const char* ascii_source, TEST(CharacterStreams) { - v8::HandleScope handles; + v8::HandleScope handles(v8::Isolate::GetCurrent()); v8::Persistent<v8::Context> context = v8::Context::New(); v8::Context::Scope context_scope(context); @@ -988,7 +988,7 @@ TEST(ScopePositions) { { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } }; - v8::HandleScope handles; + v8::HandleScope handles(v8::Isolate::GetCurrent()); v8::Persistent<v8::Context> context = v8::Context::New(); v8::Context::Scope context_scope(context); @@ -1041,6 +1041,31 @@ TEST(ScopePositions) { } +i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { + i::Handle<i::String> format = v8::Utils::OpenHandle( + *v8::String::New(data->BuildMessage())); + i::Vector<const char*> args = data->BuildArgs(); + i::Handle<i::JSArray> args_array = FACTORY->NewJSArray(args.length()); + for (int i = 0; i < args.length(); i++) { + i::JSArray::SetElement(args_array, + i, + v8::Utils::OpenHandle(*v8::String::New(args[i])), + NONE, + i::kNonStrictMode); + } + i::Handle<i::JSObject> builtins(i::Isolate::Current()->js_builtins_object()); + i::Handle<i::Object> format_fun = + i::GetProperty(builtins, "FormatMessage"); + i::Handle<i::Object> arg_handles[] = { format, args_array }; + bool has_exception = false; + i::Handle<i::Object> result = + i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); + CHECK(!has_exception); + CHECK(result->IsString()); + return i::Handle<i::String>::cast(result); +} + + void TestParserSync(i::Handle<i::String> source, int flags) { uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); bool harmony_scoping = ((i::kLanguageModeMask & flags) == i::EXTENDED_MODE); @@ -1067,53 +1092,50 @@ void TestParserSync(i::Handle<i::String> source, int flags) { i::FunctionLiteral* function = parser.ParseProgram(); i::FLAG_harmony_scoping = save_harmony_scoping; - i::String* type_string = NULL; + // Check that preparsing fails iff parsing fails. if (function == NULL) { // Extract exception from the parser. - i::Handle<i::String> type_symbol = FACTORY->LookupAsciiSymbol("type"); CHECK(i::Isolate::Current()->has_pending_exception()); i::MaybeObject* maybe_object = i::Isolate::Current()->pending_exception(); i::JSObject* exception = NULL; CHECK(maybe_object->To(&exception)); + i::Handle<i::JSObject> exception_handle(exception); + i::Handle<i::String> message_string = + i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); - // Get the type string. - maybe_object = exception->GetProperty(*type_symbol); - CHECK(maybe_object->To(&type_string)); - } - - // Check that preparsing fails iff parsing fails. - if (data.has_error() && function != NULL) { - i::OS::Print( - "Preparser failed on:\n" - "\t%s\n" - "with error:\n" - "\t%s\n" - "However, the parser succeeded", - *source->ToCString(), data.BuildMessage()); - CHECK(false); - } else if (!data.has_error() && function == NULL) { - i::OS::Print( - "Parser failed on:\n" - "\t%s\n" - "with error:\n" - "\t%s\n" - "However, the preparser succeeded", - *source->ToCString(), *type_string->ToCString()); - CHECK(false); - } - - // Check that preparser and parser produce the same error. - if (function == NULL) { - if (!type_string->IsEqualTo(i::CStrVector(data.BuildMessage()))) { + if (!data.has_error()) { + i::OS::Print( + "Parser failed on:\n" + "\t%s\n" + "with error:\n" + "\t%s\n" + "However, the preparser succeeded", + *source->ToCString(), *message_string->ToCString()); + CHECK(false); + } + // Check that preparser and parser produce the same error. + i::Handle<i::String> preparser_message = FormatMessage(&data); + if (!message_string->Equals(*preparser_message)) { i::OS::Print( "Expected parser and preparser to produce the same error on:\n" "\t%s\n" "However, found the following error messages\n" "\tparser: %s\n" "\tpreparser: %s\n", - *source->ToCString(), *type_string->ToCString(), data.BuildMessage()); + *source->ToCString(), + *message_string->ToCString(), + *preparser_message->ToCString()); CHECK(false); } + } else if (data.has_error()) { + i::OS::Print( + "Preparser failed on:\n" + "\t%s\n" + "with error:\n" + "\t%s\n" + "However, the parser succeeded", + *source->ToCString(), *FormatMessage(&data)->ToCString()); + CHECK(false); } } @@ -1204,7 +1226,7 @@ TEST(ParserSync) { NULL }; - v8::HandleScope handles; + v8::HandleScope handles(v8::Isolate::GetCurrent()); v8::Persistent<v8::Context> context = v8::Context::New(); v8::Context::Scope context_scope(context); @@ -1245,7 +1267,7 @@ TEST(PreparserStrictOctal) { // such (issue 2220). v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. v8::V8::Initialize(); - v8::HandleScope scope; + v8::HandleScope scope(v8::Isolate::GetCurrent()); v8::Context::Scope context_scope(v8::Context::New()); v8::TryCatch try_catch; const char* script = |