| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 isolate->stack_guard()->SetStackLimit( | 320 isolate->stack_guard()->SetStackLimit( |
| 321 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 321 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 322 | 322 |
| 323 const char* program = "var x = 'something';\n" | 323 const char* program = "var x = 'something';\n" |
| 324 "escape: function() {}"; | 324 "escape: function() {}"; |
| 325 // Fails parsing expecting an identifier after "function". | 325 // Fails parsing expecting an identifier after "function". |
| 326 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 326 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
| 327 // and then used the invalid currently scanned literal. This always | 327 // and then used the invalid currently scanned literal. This always |
| 328 // failed in debug mode, and sometimes crashed in release mode. | 328 // failed in debug mode, and sometimes crashed in release mode. |
| 329 | 329 |
| 330 i::Utf8ToUtf16CharacterStream stream( | 330 v8::HandleScope handles(CcTest::isolate()); |
| 331 reinterpret_cast<const i::byte*>(program), | 331 i::Handle<i::String> source = isolate->factory()->NewStringFromAscii( |
| 332 static_cast<unsigned>(strlen(program))); | 332 i::Vector<const char>(reinterpret_cast<const char*>(program), |
| 333 i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, &stream); | 333 strlen(program))); |
| 334 i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, source); |
| 334 CHECK(data->HasError()); | 335 CHECK(data->HasError()); |
| 335 delete data; | 336 delete data; |
| 336 } | 337 } |
| 337 | 338 |
| 338 | 339 |
| 339 TEST(Regress928) { | 340 TEST(Regress928) { |
| 340 v8::V8::Initialize(); | 341 v8::V8::Initialize(); |
| 341 i::Isolate* isolate = CcTest::i_isolate(); | 342 i::Isolate* isolate = CcTest::i_isolate(); |
| 342 i::Factory* factory = isolate->factory(); | 343 i::Factory* factory = isolate->factory(); |
| 343 | 344 |
| 344 // Preparsing didn't consider the catch clause of a try statement | 345 // Preparsing didn't consider the catch clause of a try statement |
| 345 // as with-content, which made it assume that a function inside | 346 // as with-content, which made it assume that a function inside |
| 346 // the block could be lazily compiled, and an extra, unexpected, | 347 // the block could be lazily compiled, and an extra, unexpected, |
| 347 // entry was added to the data. | 348 // entry was added to the data. |
| 348 int marker; | 349 int marker; |
| 349 isolate->stack_guard()->SetStackLimit( | 350 isolate->stack_guard()->SetStackLimit( |
| 350 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 351 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 351 | 352 |
| 352 const char* program = | 353 const char* program = |
| 353 "try { } catch (e) { var foo = function () { /* first */ } }" | 354 "try { } catch (e) { var foo = function () { /* first */ } }" |
| 354 "var bar = function () { /* second */ }"; | 355 "var bar = function () { /* second */ }"; |
| 355 | 356 |
| 356 v8::HandleScope handles(CcTest::isolate()); | 357 v8::HandleScope handles(CcTest::isolate()); |
| 357 i::Handle<i::String> source( | 358 i::Handle<i::String> source( |
| 358 factory->NewStringFromAscii(i::CStrVector(program))); | 359 factory->NewStringFromAscii(i::CStrVector(program))); |
| 359 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 360 i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, source); |
| 360 i::ScriptDataImpl* data = i::PreParserApi::PreParse(isolate, &stream); | |
| 361 CHECK(!data->HasError()); | 361 CHECK(!data->HasError()); |
| 362 | 362 |
| 363 data->Initialize(); | 363 data->Initialize(); |
| 364 | 364 |
| 365 int first_function = | 365 int first_function = |
| 366 static_cast<int>(strstr(program, "function") - program); | 366 static_cast<int>(strstr(program, "function") - program); |
| 367 int first_lbrace = first_function + i::StrLength("function () "); | 367 int first_lbrace = first_function + i::StrLength("function () "); |
| 368 CHECK_EQ('{', program[first_lbrace]); | 368 CHECK_EQ('{', program[first_lbrace]); |
| 369 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace); | 369 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace); |
| 370 CHECK(!entry1.is_valid()); | 370 CHECK(!entry1.is_valid()); |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 " b = function() { \n" | 1332 " b = function() { \n" |
| 1333 " 01; \n" | 1333 " 01; \n" |
| 1334 " }; \n" | 1334 " }; \n" |
| 1335 "}; \n"; | 1335 "}; \n"; |
| 1336 v8::Script::Compile(v8::String::New(script)); | 1336 v8::Script::Compile(v8::String::New(script)); |
| 1337 CHECK(try_catch.HasCaught()); | 1337 CHECK(try_catch.HasCaught()); |
| 1338 v8::String::Utf8Value exception(try_catch.Exception()); | 1338 v8::String::Utf8Value exception(try_catch.Exception()); |
| 1339 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1339 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
| 1340 *exception); | 1340 *exception); |
| 1341 } | 1341 } |
| OLD | NEW |