| 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 10645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10656 v8::TryCatch try_catch; | 10656 v8::TryCatch try_catch; |
| 10657 | 10657 |
| 10658 Local<String> source = String::New(script); | 10658 Local<String> source = String::New(script); |
| 10659 Local<Script> compiled_script = Script::New(source, NULL, sd); | 10659 Local<Script> compiled_script = Script::New(source, NULL, sd); |
| 10660 CHECK(try_catch.HasCaught()); | 10660 CHECK(try_catch.HasCaught()); |
| 10661 String::AsciiValue exception_value(try_catch.Message()->Get()); | 10661 String::AsciiValue exception_value(try_catch.Message()->Get()); |
| 10662 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | 10662 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", |
| 10663 *exception_value); | 10663 *exception_value); |
| 10664 | 10664 |
| 10665 try_catch.Reset(); | 10665 try_catch.Reset(); |
| 10666 |
| 10666 // Overwrite function bar's start position with 200. The function entry | 10667 // Overwrite function bar's start position with 200. The function entry |
| 10667 // will not be found when searching for it by position. | 10668 // will not be found when searching for it by position and we should fall |
| 10669 // back on eager compilation. |
| 10668 sd = v8::ScriptData::PreCompile(script, i::StrLength(script)); | 10670 sd = v8::ScriptData::PreCompile(script, i::StrLength(script)); |
| 10669 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); | 10671 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); |
| 10670 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = | 10672 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = |
| 10671 200; | 10673 200; |
| 10672 compiled_script = Script::New(source, NULL, sd); | 10674 compiled_script = Script::New(source, NULL, sd); |
| 10673 CHECK(try_catch.HasCaught()); | 10675 CHECK(!try_catch.HasCaught()); |
| 10674 String::AsciiValue second_exception_value(try_catch.Message()->Get()); | |
| 10675 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", | |
| 10676 *second_exception_value); | |
| 10677 | 10676 |
| 10678 delete sd; | 10677 delete sd; |
| 10679 } | 10678 } |
| 10680 | 10679 |
| 10681 | 10680 |
| 10682 // Verifies that the Handle<String> and const char* versions of the API produce | 10681 // Verifies that the Handle<String> and const char* versions of the API produce |
| 10683 // the same results (at least for one trivial case). | 10682 // the same results (at least for one trivial case). |
| 10684 TEST(PreCompileAPIVariationsAreSame) { | 10683 TEST(PreCompileAPIVariationsAreSame) { |
| 10685 v8::V8::Initialize(); | 10684 v8::V8::Initialize(); |
| 10686 v8::HandleScope scope; | 10685 v8::HandleScope scope; |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11657 v8::kExternalPixelArray, | 11656 v8::kExternalPixelArray, |
| 11658 pixel_data)); | 11657 pixel_data)); |
| 11659 // Force GC to trigger verification. | 11658 // Force GC to trigger verification. |
| 11660 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 11659 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 11661 for (int i = 0; i < kElementCount; i++) { | 11660 for (int i = 0; i < kElementCount; i++) { |
| 11662 pixels->set(i, i % 256); | 11661 pixels->set(i, i % 256); |
| 11663 } | 11662 } |
| 11664 // Force GC to trigger verification. | 11663 // Force GC to trigger verification. |
| 11665 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 11664 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 11666 for (int i = 0; i < kElementCount; i++) { | 11665 for (int i = 0; i < kElementCount; i++) { |
| 11667 CHECK_EQ(i % 256, pixels->get(i)); | 11666 CHECK_EQ(i % 256, pixels->get_scalar(i)); |
| 11668 CHECK_EQ(i % 256, pixel_data[i]); | 11667 CHECK_EQ(i % 256, pixel_data[i]); |
| 11669 } | 11668 } |
| 11670 | 11669 |
| 11671 v8::Handle<v8::Object> obj = v8::Object::New(); | 11670 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 11672 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 11671 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 11673 // Set the elements to be the pixels. | 11672 // Set the elements to be the pixels. |
| 11674 // jsobj->set_elements(*pixels); | 11673 // jsobj->set_elements(*pixels); |
| 11675 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 11674 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
| 11676 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 11675 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); |
| 11677 obj->Set(v8_str("field"), v8::Int32::New(1503)); | 11676 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12132 i::Handle<ExternalArrayClass>::cast( | 12131 i::Handle<ExternalArrayClass>::cast( |
| 12133 FACTORY->NewExternalArray(kElementCount, array_type, array_data)); | 12132 FACTORY->NewExternalArray(kElementCount, array_type, array_data)); |
| 12134 // Force GC to trigger verification. | 12133 // Force GC to trigger verification. |
| 12135 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12134 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 12136 for (int i = 0; i < kElementCount; i++) { | 12135 for (int i = 0; i < kElementCount; i++) { |
| 12137 array->set(i, static_cast<ElementType>(i)); | 12136 array->set(i, static_cast<ElementType>(i)); |
| 12138 } | 12137 } |
| 12139 // Force GC to trigger verification. | 12138 // Force GC to trigger verification. |
| 12140 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12139 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 12141 for (int i = 0; i < kElementCount; i++) { | 12140 for (int i = 0; i < kElementCount; i++) { |
| 12142 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array->get(i))); | 12141 CHECK_EQ(static_cast<int64_t>(i), |
| 12142 static_cast<int64_t>(array->get_scalar(i))); |
| 12143 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); | 12143 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); |
| 12144 } | 12144 } |
| 12145 | 12145 |
| 12146 v8::Handle<v8::Object> obj = v8::Object::New(); | 12146 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 12147 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 12147 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 12148 // Set the elements to be the external array. | 12148 // Set the elements to be the external array. |
| 12149 obj->SetIndexedPropertiesToExternalArrayData(array_data, | 12149 obj->SetIndexedPropertiesToExternalArrayData(array_data, |
| 12150 array_type, | 12150 array_type, |
| 12151 kElementCount); | 12151 kElementCount); |
| 12152 CHECK_EQ( | 12152 CHECK_EQ( |
| (...skipping 2682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14835 } | 14835 } |
| 14836 | 14836 |
| 14837 i::Isolate::Current()->heap()->CollectAllGarbage(true); | 14837 i::Isolate::Current()->heap()->CollectAllGarbage(true); |
| 14838 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); | 14838 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); |
| 14839 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { | 14839 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { |
| 14840 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); | 14840 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); |
| 14841 CHECK_GT(elements, map_cache->NumberOfElements()); | 14841 CHECK_GT(elements, map_cache->NumberOfElements()); |
| 14842 } | 14842 } |
| 14843 } | 14843 } |
| 14844 } | 14844 } |
| OLD | NEW |