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_impl = NULL; | 1702 i::ScriptData* script_data = NULL; |
1703 i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA; | 1703 i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA; |
1704 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1704 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1705 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", | 1705 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", |
1706 return Local<UnboundScript>()); | 1706 return Local<UnboundScript>()); |
1707 if (options & kProduceDataToCache) { | 1707 if (options & kProduceDataToCache) { |
1708 cached_data_mode = i::PRODUCE_CACHED_DATA; | 1708 cached_data_mode = i::PRODUCE_CACHED_DATA; |
1709 ASSERT(source->cached_data == NULL); | 1709 CHECK(source->cached_data == NULL); |
1710 if (source->cached_data) { | |
1711 // Asked to produce cached data even though there is some already -> not | |
1712 // good. Fail the compilation. | |
1713 EXCEPTION_PREAMBLE(isolate); | |
1714 i::Handle<i::Object> result = isolate->factory()->NewSyntaxError( | |
1715 "invalid_cached_data", isolate->factory()->NewJSArray(0)); | |
1716 isolate->Throw(*result); | |
1717 isolate->ReportPendingMessages(); | |
1718 has_pending_exception = true; | |
1719 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); | |
1720 } | |
1721 } else if (source->cached_data) { | 1710 } else if (source->cached_data) { |
1722 cached_data_mode = i::CONSUME_CACHED_DATA; | 1711 cached_data_mode = i::CONSUME_CACHED_DATA; |
1723 // ScriptData takes care of aligning, in case the data is not aligned | 1712 // ScriptData takes care of pointer-aligning the data. |
1724 // correctly. | 1713 script_data = new i::ScriptData(source->cached_data->data, |
1725 script_data_impl = i::ScriptData::New( | 1714 source->cached_data->length); |
1726 reinterpret_cast<const char*>(source->cached_data->data), | |
1727 source->cached_data->length); | |
1728 // If the cached data is not valid, fail the compilation. | |
1729 if (script_data_impl == NULL || !script_data_impl->SanityCheck()) { | |
1730 EXCEPTION_PREAMBLE(isolate); | |
1731 i::Handle<i::Object> result = isolate->factory()->NewSyntaxError( | |
1732 "invalid_cached_data", isolate->factory()->NewJSArray(0)); | |
1733 isolate->Throw(*result); | |
1734 isolate->ReportPendingMessages(); | |
1735 delete script_data_impl; | |
1736 has_pending_exception = true; | |
1737 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); | |
1738 } | |
1739 } | 1715 } |
1740 | 1716 |
1741 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); | 1717 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); |
1742 LOG_API(isolate, "ScriptCompiler::CompileUnbound"); | 1718 LOG_API(isolate, "ScriptCompiler::CompileUnbound"); |
1743 ENTER_V8(isolate); | 1719 ENTER_V8(isolate); |
1744 i::SharedFunctionInfo* raw_result = NULL; | 1720 i::SharedFunctionInfo* raw_result = NULL; |
1745 { i::HandleScope scope(isolate); | 1721 { i::HandleScope scope(isolate); |
1746 i::Handle<i::Object> name_obj; | 1722 i::Handle<i::Object> name_obj; |
1747 int line_offset = 0; | 1723 int line_offset = 0; |
1748 int column_offset = 0; | 1724 int column_offset = 0; |
1749 bool is_shared_cross_origin = false; | 1725 bool is_shared_cross_origin = false; |
1750 if (!source->resource_name.IsEmpty()) { | 1726 if (!source->resource_name.IsEmpty()) { |
1751 name_obj = Utils::OpenHandle(*(source->resource_name)); | 1727 name_obj = Utils::OpenHandle(*(source->resource_name)); |
1752 } | 1728 } |
1753 if (!source->resource_line_offset.IsEmpty()) { | 1729 if (!source->resource_line_offset.IsEmpty()) { |
1754 line_offset = static_cast<int>(source->resource_line_offset->Value()); | 1730 line_offset = static_cast<int>(source->resource_line_offset->Value()); |
1755 } | 1731 } |
1756 if (!source->resource_column_offset.IsEmpty()) { | 1732 if (!source->resource_column_offset.IsEmpty()) { |
1757 column_offset = | 1733 column_offset = |
1758 static_cast<int>(source->resource_column_offset->Value()); | 1734 static_cast<int>(source->resource_column_offset->Value()); |
1759 } | 1735 } |
1760 if (!source->resource_is_shared_cross_origin.IsEmpty()) { | 1736 if (!source->resource_is_shared_cross_origin.IsEmpty()) { |
1761 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1737 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
1762 is_shared_cross_origin = | 1738 is_shared_cross_origin = |
1763 source->resource_is_shared_cross_origin == v8::True(v8_isolate); | 1739 source->resource_is_shared_cross_origin == v8::True(v8_isolate); |
1764 } | 1740 } |
1765 EXCEPTION_PREAMBLE(isolate); | 1741 EXCEPTION_PREAMBLE(isolate); |
1766 i::Handle<i::SharedFunctionInfo> result = | 1742 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( |
1767 i::Compiler::CompileScript(str, | 1743 str, name_obj, line_offset, column_offset, is_shared_cross_origin, |
1768 name_obj, | 1744 isolate->global_context(), NULL, &script_data, cached_data_mode, |
1769 line_offset, | 1745 i::NOT_NATIVES_CODE); |
1770 column_offset, | |
1771 is_shared_cross_origin, | |
1772 isolate->global_context(), | |
1773 NULL, | |
1774 &script_data_impl, | |
1775 cached_data_mode, | |
1776 i::NOT_NATIVES_CODE); | |
1777 has_pending_exception = result.is_null(); | 1746 has_pending_exception = result.is_null(); |
1778 if (has_pending_exception && cached_data_mode == i::CONSUME_CACHED_DATA) { | 1747 if (has_pending_exception && cached_data_mode == i::CONSUME_CACHED_DATA) { |
1779 // This case won't happen during normal operation; we have compiled | 1748 // This case won't happen during normal operation; we have compiled |
1780 // successfully and produced cached data, and but the second compilation | 1749 // successfully and produced cached data, and but the second compilation |
1781 // of the same source code fails. | 1750 // of the same source code fails. |
1782 delete script_data_impl; | 1751 delete script_data; |
1783 script_data_impl = NULL; | 1752 script_data = NULL; |
1784 } | 1753 } |
1785 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); | 1754 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
1786 raw_result = *result; | 1755 raw_result = *result; |
1787 if ((options & kProduceDataToCache) && script_data_impl != NULL) { | 1756 if ((options & kProduceDataToCache) && script_data != NULL) { |
1788 // script_data_impl now contains the data that was generated. source will | 1757 // script_data_impl now contains the data that was generated. source will |
1789 // take the ownership. | 1758 // take the ownership. |
1790 source->cached_data = new CachedData( | 1759 source->cached_data = new CachedData( |
1791 reinterpret_cast<const uint8_t*>(script_data_impl->Data()), | 1760 script_data->data(), script_data->length(), CachedData::BufferOwned); |
1792 script_data_impl->Length(), CachedData::BufferOwned); | 1761 script_data->ReleaseDataOwnership(); |
1793 script_data_impl->owns_store_ = false; | |
1794 } | 1762 } |
1795 delete script_data_impl; | 1763 delete script_data; |
1796 } | 1764 } |
1797 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | 1765 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
1798 return ToApiHandle<UnboundScript>(result); | 1766 return ToApiHandle<UnboundScript>(result); |
1799 } | 1767 } |
1800 | 1768 |
1801 | 1769 |
1802 Local<Script> ScriptCompiler::Compile( | 1770 Local<Script> ScriptCompiler::Compile( |
1803 Isolate* v8_isolate, | 1771 Isolate* v8_isolate, |
1804 Source* source, | 1772 Source* source, |
1805 CompileOptions options) { | 1773 CompileOptions options) { |
(...skipping 5881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7687 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7655 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7688 Address callback_address = | 7656 Address callback_address = |
7689 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7657 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7690 VMState<EXTERNAL> state(isolate); | 7658 VMState<EXTERNAL> state(isolate); |
7691 ExternalCallbackScope call_scope(isolate, callback_address); | 7659 ExternalCallbackScope call_scope(isolate, callback_address); |
7692 callback(info); | 7660 callback(info); |
7693 } | 7661 } |
7694 | 7662 |
7695 | 7663 |
7696 } } // namespace v8::internal | 7664 } } // namespace v8::internal |
OLD | NEW |