| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 10602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10613 v8::TryCatch try_catch; | 10613 v8::TryCatch try_catch; |
| 10614 | 10614 |
| 10615 Local<String> source = String::New(script); | 10615 Local<String> source = String::New(script); |
| 10616 Local<Script> compiled_script = Script::New(source, NULL, sd); | 10616 Local<Script> compiled_script = Script::New(source, NULL, sd); |
| 10617 CHECK(try_catch.HasCaught()); | 10617 CHECK(try_catch.HasCaught()); |
| 10618 String::AsciiValue exception_value(try_catch.Message()->Get()); | 10618 String::AsciiValue exception_value(try_catch.Message()->Get()); |
| 10619 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | 10619 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", |
| 10620 *exception_value); | 10620 *exception_value); |
| 10621 | 10621 |
| 10622 try_catch.Reset(); | 10622 try_catch.Reset(); |
| 10623 |
| 10623 // Overwrite function bar's start position with 200. The function entry | 10624 // Overwrite function bar's start position with 200. The function entry |
| 10624 // will not be found when searching for it by position. | 10625 // will not be found when searching for it by position and we should fall |
| 10626 // back on eager compilation. |
| 10625 sd = v8::ScriptData::PreCompile(script, i::StrLength(script)); | 10627 sd = v8::ScriptData::PreCompile(script, i::StrLength(script)); |
| 10626 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 10628 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
| 10627 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = | 10629 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = |
| 10628 200; | 10630 200; |
| 10629 compiled_script = Script::New(source, NULL, sd); | 10631 compiled_script = Script::New(source, NULL, sd); |
| 10630 CHECK(try_catch.HasCaught()); | 10632 CHECK(!try_catch.HasCaught()); |
| 10631 String::AsciiValue second_exception_value(try_catch.Message()->Get()); | |
| 10632 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | |
| 10633 *second_exception_value); | |
| 10634 | 10633 |
| 10635 delete sd; | 10634 delete sd; |
| 10636 } | 10635 } |
| 10637 | 10636 |
| 10638 | 10637 |
| 10639 // Verifies that the Handle<String> and const char* versions of the API produce | 10638 // Verifies that the Handle<String> and const char* versions of the API produce |
| 10640 // the same results (at least for one trivial case). | 10639 // the same results (at least for one trivial case). |
| 10641 TEST(PreCompileAPIVariationsAreSame) { | 10640 TEST(PreCompileAPIVariationsAreSame) { |
| 10642 v8::V8::Initialize(); | 10641 v8::V8::Initialize(); |
| 10643 v8::HandleScope scope; | 10642 v8::HandleScope scope; |
| (...skipping 4143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14787 } | 14786 } |
| 14788 | 14787 |
| 14789 i::Isolate::Current()->heap()->CollectAllGarbage(true); | 14788 i::Isolate::Current()->heap()->CollectAllGarbage(true); |
| 14790 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); | 14789 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); |
| 14791 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { | 14790 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { |
| 14792 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); | 14791 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); |
| 14793 CHECK_GT(elements, map_cache->NumberOfElements()); | 14792 CHECK_GT(elements, map_cache->NumberOfElements()); |
| 14794 } | 14793 } |
| 14795 } | 14794 } |
| 14796 } | 14795 } |
| OLD | NEW |