OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 1692 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
1693 return ToApiHandle<UnboundScript>( | 1693 return ToApiHandle<UnboundScript>( |
1694 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); | 1694 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); |
1695 } | 1695 } |
1696 | 1696 |
1697 | 1697 |
1698 Local<UnboundScript> ScriptCompiler::CompileUnbound( | 1698 Local<UnboundScript> ScriptCompiler::CompileUnbound( |
1699 Isolate* v8_isolate, | 1699 Isolate* v8_isolate, |
1700 Source* source, | 1700 Source* source, |
1701 CompileOptions options) { | 1701 CompileOptions options) { |
1702 i::ScriptData* script_data = NULL; | |
1703 i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA; | |
1704 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1702 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1705 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", | 1703 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", |
1706 return Local<UnboundScript>()); | 1704 return Local<UnboundScript>()); |
1707 if (options & kProduceDataToCache) { | 1705 |
1708 cached_data_mode = i::PRODUCE_CACHED_DATA; | 1706 // Support the old API for a transition period: |
1709 CHECK(source->cached_data == NULL); | 1707 // - kProduceToCache -> kProduceParserCache |
1710 } else if (source->cached_data) { | 1708 // - kNoCompileOptions + cached_data != NULL -> kConsumeParserCache |
1711 cached_data_mode = i::CONSUME_CACHED_DATA; | 1709 if (options == kProduceDataToCache) { |
| 1710 options = kProduceParserCache; |
| 1711 } else if (options == kNoCompileOptions && source->cached_data) { |
| 1712 options = kConsumeParserCache; |
| 1713 } |
| 1714 |
| 1715 i::ScriptData* script_data = NULL; |
| 1716 if (options == kConsumeParserCache || options == kConsumeCodeCache) { |
| 1717 ASSERT(source->cached_data); |
1712 // ScriptData takes care of pointer-aligning the data. | 1718 // ScriptData takes care of pointer-aligning the data. |
1713 script_data = new i::ScriptData(source->cached_data->data, | 1719 script_data = new i::ScriptData(source->cached_data->data, |
1714 source->cached_data->length); | 1720 source->cached_data->length); |
1715 } | 1721 } |
1716 | 1722 |
1717 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); | 1723 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); |
1718 LOG_API(isolate, "ScriptCompiler::CompileUnbound"); | 1724 LOG_API(isolate, "ScriptCompiler::CompileUnbound"); |
1719 ENTER_V8(isolate); | 1725 ENTER_V8(isolate); |
1720 i::SharedFunctionInfo* raw_result = NULL; | 1726 i::SharedFunctionInfo* raw_result = NULL; |
1721 { i::HandleScope scope(isolate); | 1727 { i::HandleScope scope(isolate); |
(...skipping 12 matching lines...) Expand all Loading... |
1734 static_cast<int>(source->resource_column_offset->Value()); | 1740 static_cast<int>(source->resource_column_offset->Value()); |
1735 } | 1741 } |
1736 if (!source->resource_is_shared_cross_origin.IsEmpty()) { | 1742 if (!source->resource_is_shared_cross_origin.IsEmpty()) { |
1737 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1743 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
1738 is_shared_cross_origin = | 1744 is_shared_cross_origin = |
1739 source->resource_is_shared_cross_origin == v8::True(v8_isolate); | 1745 source->resource_is_shared_cross_origin == v8::True(v8_isolate); |
1740 } | 1746 } |
1741 EXCEPTION_PREAMBLE(isolate); | 1747 EXCEPTION_PREAMBLE(isolate); |
1742 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( | 1748 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( |
1743 str, name_obj, line_offset, column_offset, is_shared_cross_origin, | 1749 str, name_obj, line_offset, column_offset, is_shared_cross_origin, |
1744 isolate->global_context(), NULL, &script_data, cached_data_mode, | 1750 isolate->global_context(), NULL, &script_data, options, |
1745 i::NOT_NATIVES_CODE); | 1751 i::NOT_NATIVES_CODE); |
1746 has_pending_exception = result.is_null(); | 1752 has_pending_exception = result.is_null(); |
1747 if (has_pending_exception && cached_data_mode == i::CONSUME_CACHED_DATA) { | 1753 if (has_pending_exception && script_data != NULL) { |
1748 // This case won't happen during normal operation; we have compiled | 1754 // This case won't happen during normal operation; we have compiled |
1749 // successfully and produced cached data, and but the second compilation | 1755 // successfully and produced cached data, and but the second compilation |
1750 // of the same source code fails. | 1756 // of the same source code fails. |
1751 delete script_data; | 1757 delete script_data; |
1752 script_data = NULL; | 1758 script_data = NULL; |
1753 } | 1759 } |
1754 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); | 1760 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
1755 raw_result = *result; | 1761 raw_result = *result; |
1756 if ((options & kProduceDataToCache) && script_data != NULL) { | 1762 |
1757 // script_data_impl now contains the data that was generated. source will | 1763 if ((options == kProduceParserCache || options == kProduceCodeCache) && |
| 1764 script_data != NULL) { |
| 1765 // script_data now contains the data that was generated. source will |
1758 // take the ownership. | 1766 // take the ownership. |
1759 source->cached_data = new CachedData( | 1767 source->cached_data = new CachedData( |
1760 script_data->data(), script_data->length(), CachedData::BufferOwned); | 1768 script_data->data(), script_data->length(), CachedData::BufferOwned); |
1761 script_data->ReleaseDataOwnership(); | 1769 script_data->ReleaseDataOwnership(); |
1762 } | 1770 } |
1763 delete script_data; | 1771 delete script_data; |
1764 } | 1772 } |
1765 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | 1773 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
1766 return ToApiHandle<UnboundScript>(result); | 1774 return ToApiHandle<UnboundScript>(result); |
1767 } | 1775 } |
(...skipping 5818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7586 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7594 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7587 Address callback_address = | 7595 Address callback_address = |
7588 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7596 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7589 VMState<EXTERNAL> state(isolate); | 7597 VMState<EXTERNAL> state(isolate); |
7590 ExternalCallbackScope call_scope(isolate, callback_address); | 7598 ExternalCallbackScope call_scope(isolate, callback_address); |
7591 callback(info); | 7599 callback(info); |
7592 } | 7600 } |
7593 | 7601 |
7594 | 7602 |
7595 } } // namespace v8::internal | 7603 } } // namespace v8::internal |
OLD | NEW |