Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: src/api.cc

Issue 203353002: New compilation API, part 2. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 i::Vector<unsigned>(deserialized_data, deserialized_data_length)); 1610 i::Vector<unsigned>(deserialized_data, deserialized_data_length));
1611 } 1611 }
1612 1612
1613 1613
1614 // --- S c r i p t s --- 1614 // --- S c r i p t s ---
1615 1615
1616 1616
1617 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a 1617 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a
1618 // JSFunction. 1618 // JSFunction.
1619 1619
1620 ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
1621 BufferPolicy buffer_policy_)
1622 : data(data_), length(length_), buffer_policy(buffer_policy_) {}
1623
1624
1625 ScriptCompiler::CachedData::~CachedData() {
1626 if (buffer_policy == BufferOwned) {
1627 delete[] data;
1628 }
1629 }
1630
1631
1620 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin, 1632 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
1621 const CachedData& data) 1633 CachedData* data)
1622 : source_string(string), 1634 : source_string(string),
1623 resource_name(origin.ResourceName()), 1635 resource_name(origin.ResourceName()),
1624 resource_line_offset(origin.ResourceLineOffset()), 1636 resource_line_offset(origin.ResourceLineOffset()),
1625 resource_column_offset(origin.ResourceColumnOffset()), 1637 resource_column_offset(origin.ResourceColumnOffset()),
1626 resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()), 1638 resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()),
1627 cached_data(data) {} 1639 cached_data(data) {}
1628 1640
1629 1641
1630 ScriptCompiler::Source::Source(Local<String> string, 1642 ScriptCompiler::Source::Source(Local<String> string,
1631 const CachedData& data) 1643 CachedData* data)
1632 : source_string(string), cached_data(data) {} 1644 : source_string(string), cached_data(data) {}
1633 1645
1634 1646
1647 ScriptCompiler::Source::~Source() {
1648 delete cached_data;
1649 }
1650
1651
1652 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
1653 const {
1654 return cached_data;
1655 }
1656
1657
1635 Local<Script> UnboundScript::BindToCurrentContext() { 1658 Local<Script> UnboundScript::BindToCurrentContext() {
1636 i::Handle<i::HeapObject> obj = 1659 i::Handle<i::HeapObject> obj =
1637 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); 1660 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
1638 i::Handle<i::SharedFunctionInfo> 1661 i::Handle<i::SharedFunctionInfo>
1639 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); 1662 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
1640 i::Handle<i::JSFunction> function = 1663 i::Handle<i::JSFunction> function =
1641 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( 1664 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
1642 function_info, obj->GetIsolate()->global_context()); 1665 function_info, obj->GetIsolate()->global_context());
1643 return ToApiHandle<Script>(function); 1666 return ToApiHandle<Script>(function);
1644 } 1667 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 1746
1724 Local<UnboundScript> Script::GetUnboundScript() { 1747 Local<UnboundScript> Script::GetUnboundScript() {
1725 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1748 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1726 return ToApiHandle<UnboundScript>( 1749 return ToApiHandle<UnboundScript>(
1727 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); 1750 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
1728 } 1751 }
1729 1752
1730 1753
1731 Local<UnboundScript> ScriptCompiler::CompileUnbound( 1754 Local<UnboundScript> ScriptCompiler::CompileUnbound(
1732 Isolate* v8_isolate, 1755 Isolate* v8_isolate,
1733 const Source& source, 1756 Source* source,
1734 CompileOptions options) { 1757 CompileOptions options) {
1735 // FIXME(marja): This function cannot yet create cached data (if options | 1758 i::ScriptDataImpl* script_data_impl = NULL;
1736 // produce_data_to_cache is true), but the PreCompile function is still there 1759 i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA;
1737 // for doing it. 1760 if (options & kProduceDataToCache) {
1738 i::Handle<i::String> str = Utils::OpenHandle(*(source.source_string)); 1761 cached_data_mode = i::PRODUCE_CACHED_DATA;
1762 ASSERT(source->cached_data == NULL);
1763 if (source->cached_data) {
1764 // Asked to produce cached data even though there is some already -> not
1765 // good. In release mode, try to do the right thing: Just regenerate the
1766 // data.
1767 delete source->cached_data;
1768 source->cached_data = NULL;
1769 }
1770 } else if (source->cached_data) {
1771 // FIXME(marja): Make compiler use CachedData directly. Aligning needs to be
1772 // taken care of.
1773 script_data_impl = static_cast<i::ScriptDataImpl*>(ScriptData::New(
1774 reinterpret_cast<const char*>(source->cached_data->data),
1775 source->cached_data->length));
1776 // We assert that the pre-data is sane, even though we can actually
1777 // handle it if it turns out not to be in release mode.
1778 ASSERT(script_data_impl->SanityCheck());
1779 if (script_data_impl->SanityCheck()) {
1780 cached_data_mode = i::CONSUME_CACHED_DATA;
1781 } else {
1782 // If the pre-data isn't sane we simply ignore it.
1783 delete script_data_impl;
1784 script_data_impl = NULL;
1785 delete source->cached_data;
1786 source->cached_data = NULL;
1787 }
1788 }
1789
1790 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string));
1739 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 1791 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1740 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", 1792 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()",
1741 return Local<UnboundScript>()); 1793 return Local<UnboundScript>());
1742 LOG_API(isolate, "ScriptCompiler::CompileUnbound"); 1794 LOG_API(isolate, "ScriptCompiler::CompileUnbound");
1743 ENTER_V8(isolate); 1795 ENTER_V8(isolate);
1744 i::SharedFunctionInfo* raw_result = NULL; 1796 i::SharedFunctionInfo* raw_result = NULL;
1745 { i::HandleScope scope(isolate); 1797 { i::HandleScope scope(isolate);
1746 i::Handle<i::Object> name_obj; 1798 i::Handle<i::Object> name_obj;
1747 int line_offset = 0; 1799 int line_offset = 0;
1748 int column_offset = 0; 1800 int column_offset = 0;
1749 bool is_shared_cross_origin = false; 1801 bool is_shared_cross_origin = false;
1750 if (!source.resource_name.IsEmpty()) { 1802 if (!source->resource_name.IsEmpty()) {
1751 name_obj = Utils::OpenHandle(*source.resource_name); 1803 name_obj = Utils::OpenHandle(*(source->resource_name));
1752 } 1804 }
1753 if (!source.resource_line_offset.IsEmpty()) { 1805 if (!source->resource_line_offset.IsEmpty()) {
1754 line_offset = static_cast<int>(source.resource_line_offset->Value()); 1806 line_offset = static_cast<int>(source->resource_line_offset->Value());
1755 } 1807 }
1756 if (!source.resource_column_offset.IsEmpty()) { 1808 if (!source->resource_column_offset.IsEmpty()) {
1757 column_offset = 1809 column_offset =
1758 static_cast<int>(source.resource_column_offset->Value()); 1810 static_cast<int>(source->resource_column_offset->Value());
1759 } 1811 }
1760 if (!source.resource_is_shared_cross_origin.IsEmpty()) { 1812 if (!source->resource_is_shared_cross_origin.IsEmpty()) {
1761 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 1813 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
1762 is_shared_cross_origin = 1814 is_shared_cross_origin =
1763 source.resource_is_shared_cross_origin == v8::True(v8_isolate); 1815 source->resource_is_shared_cross_origin == v8::True(v8_isolate);
1764 } 1816 }
1765 EXCEPTION_PREAMBLE(isolate); 1817 EXCEPTION_PREAMBLE(isolate);
1766 i::ScriptDataImpl* pre_data_impl = NULL;
1767 if (source.cached_data.data) {
1768 // FIXME(marja): Make compiler use CachedData directly.
1769 pre_data_impl = static_cast<i::ScriptDataImpl*>(ScriptData::New(
1770 reinterpret_cast<const char*>(source.cached_data.data),
1771 source.cached_data.length));
1772 }
1773 // We assert that the pre-data is sane, even though we can actually
1774 // handle it if it turns out not to be in release mode.
1775 ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck());
1776 // If the pre-data isn't sane we simply ignore it
1777 if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) {
1778 delete pre_data_impl;
1779 pre_data_impl = NULL;
1780 }
1781 i::Handle<i::SharedFunctionInfo> result = 1818 i::Handle<i::SharedFunctionInfo> result =
1782 i::Compiler::CompileScript(str, 1819 i::Compiler::CompileScript(str,
1783 name_obj, 1820 name_obj,
1784 line_offset, 1821 line_offset,
1785 column_offset, 1822 column_offset,
1786 is_shared_cross_origin, 1823 is_shared_cross_origin,
1787 isolate->global_context(), 1824 isolate->global_context(),
1788 NULL, 1825 NULL,
1789 pre_data_impl, 1826 &script_data_impl,
1827 cached_data_mode,
1790 i::NOT_NATIVES_CODE); 1828 i::NOT_NATIVES_CODE);
1791 has_pending_exception = result.is_null(); 1829 has_pending_exception = result.is_null();
1792 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); 1830 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>());
1793 raw_result = *result; 1831 raw_result = *result;
1794 delete pre_data_impl; 1832 if ((options & kProduceDataToCache) && script_data_impl != NULL) {
1833 // script_data_impl now contains the data that was generated. source will
1834 // take the ownership.
1835 source->cached_data = new CachedData(
1836 reinterpret_cast<const uint8_t*>(script_data_impl->Data()),
1837 script_data_impl->Length(), CachedData::BufferOwned);
1838 script_data_impl->owns_store_ = false;
1839 }
1840 delete script_data_impl;
1795 } 1841 }
1796 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); 1842 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1797 return ToApiHandle<UnboundScript>(result); 1843 return ToApiHandle<UnboundScript>(result);
1798 } 1844 }
1799 1845
1800 1846
1801 Local<Script> ScriptCompiler::Compile( 1847 Local<Script> ScriptCompiler::Compile(
1802 Isolate* v8_isolate, 1848 Isolate* v8_isolate,
1803 const Source& source, 1849 Source* source,
1804 CompileOptions options) { 1850 CompileOptions options) {
1805 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 1851 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1806 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", 1852 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()",
1807 return Local<Script>()); 1853 return Local<Script>());
1808 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); 1854 LOG_API(isolate, "ScriptCompiler::CompiletBound()");
1809 ENTER_V8(isolate); 1855 ENTER_V8(isolate);
1810 Local<UnboundScript> generic = 1856 Local<UnboundScript> generic =
1811 CompileUnbound(v8_isolate, source, options); 1857 CompileUnbound(v8_isolate, source, options);
1812 if (generic.IsEmpty()) return Local<Script>(); 1858 if (generic.IsEmpty()) return Local<Script>();
1813 return generic->BindToCurrentContext(); 1859 return generic->BindToCurrentContext();
1814 } 1860 }
1815 1861
1816 1862
1817 Local<Script> Script::Compile(v8::Handle<String> source, 1863 Local<Script> Script::Compile(v8::Handle<String> source,
1818 v8::ScriptOrigin* origin, 1864 v8::ScriptOrigin* origin,
1819 ScriptData* script_data) { 1865 ScriptData* script_data) {
1820 i::Handle<i::String> str = Utils::OpenHandle(*source); 1866 i::Handle<i::String> str = Utils::OpenHandle(*source);
1821 ScriptCompiler::CachedData cached_data; 1867 ScriptCompiler::CachedData* cached_data = NULL;
1822 if (script_data) { 1868 if (script_data) {
1823 cached_data = ScriptCompiler::CachedData( 1869 cached_data = new ScriptCompiler::CachedData(
1824 reinterpret_cast<const uint8_t*>(script_data->Data()), 1870 reinterpret_cast<const uint8_t*>(script_data->Data()),
1825 script_data->Length()); 1871 script_data->Length());
1826 } 1872 }
1827 if (origin) { 1873 if (origin) {
1874 ScriptCompiler::Source script_source(source, *origin, cached_data);
1828 return ScriptCompiler::Compile( 1875 return ScriptCompiler::Compile(
1829 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), 1876 reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1830 ScriptCompiler::Source(source, *origin, cached_data)); 1877 &script_source);
1831 } 1878 }
1879 ScriptCompiler::Source script_source(source, cached_data);
1832 return ScriptCompiler::Compile( 1880 return ScriptCompiler::Compile(
1833 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), 1881 reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1834 ScriptCompiler::Source(source, cached_data)); 1882 &script_source);
1835 } 1883 }
1836 1884
1837 1885
1838 Local<Script> Script::Compile(v8::Handle<String> source, 1886 Local<Script> Script::Compile(v8::Handle<String> source,
1839 v8::Handle<String> file_name) { 1887 v8::Handle<String> file_name) {
1840 ScriptOrigin origin(file_name); 1888 ScriptOrigin origin(file_name);
1841 return Compile(source, &origin); 1889 return Compile(source, &origin);
1842 } 1890 }
1843 1891
1844 1892
(...skipping 5698 matching lines...) Expand 10 before | Expand all | Expand 10 after
7543 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7591 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7544 Address callback_address = 7592 Address callback_address =
7545 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7593 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7546 VMState<EXTERNAL> state(isolate); 7594 VMState<EXTERNAL> state(isolate);
7547 ExternalCallbackScope call_scope(isolate, callback_address); 7595 ExternalCallbackScope call_scope(isolate, callback_address);
7548 callback(info); 7596 callback(info);
7549 } 7597 }
7550 7598
7551 7599
7552 } } // namespace v8::internal 7600 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698