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

Side by Side Diff: src/api.cc

Issue 225753004: Remove the PreCompile API and ScriptData. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 8 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/compiler.h » ('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 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 if (value > 0) { 1572 if (value > 0) {
1573 // The internal field count is set by the constructor function's 1573 // The internal field count is set by the constructor function's
1574 // construct code, so we ensure that there is a constructor 1574 // construct code, so we ensure that there is a constructor
1575 // function to do the setting. 1575 // function to do the setting.
1576 EnsureConstructor(isolate, this); 1576 EnsureConstructor(isolate, this);
1577 } 1577 }
1578 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); 1578 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
1579 } 1579 }
1580 1580
1581 1581
1582 // --- S c r i p t D a t a ---
1583
1584
1585 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) {
1586 i::Handle<i::String> str = Utils::OpenHandle(*source);
1587 i::Isolate* isolate = str->GetIsolate();
1588 if (str->IsExternalTwoByteString()) {
1589 i::ExternalTwoByteStringUtf16CharacterStream stream(
1590 i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length());
1591 return i::PreParserApi::PreParse(isolate, &stream);
1592 } else {
1593 i::GenericStringUtf16CharacterStream stream(str, 0, str->length());
1594 return i::PreParserApi::PreParse(isolate, &stream);
1595 }
1596 }
1597
1598
1599 ScriptData* ScriptData::New(const char* data, int length) {
1600 // Return an empty ScriptData if the length is obviously invalid.
1601 if (length % sizeof(unsigned) != 0) {
1602 return new i::ScriptDataImpl();
1603 }
1604
1605 // Copy the data to ensure it is properly aligned.
1606 int deserialized_data_length = length / sizeof(unsigned);
1607 // If aligned, don't create a copy of the data.
1608 if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) {
1609 return new i::ScriptDataImpl(data, length);
1610 }
1611 // Copy the data to align it.
1612 unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length);
1613 i::CopyBytes(reinterpret_cast<char*>(deserialized_data),
1614 data, static_cast<size_t>(length));
1615
1616 return new i::ScriptDataImpl(
1617 i::Vector<unsigned>(deserialized_data, deserialized_data_length));
1618 }
1619
1620
1621 // --- S c r i p t s --- 1582 // --- S c r i p t s ---
1622 1583
1623 1584
1624 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a 1585 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a
1625 // JSFunction. 1586 // JSFunction.
1626 1587
1627 ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_, 1588 ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
1628 BufferPolicy buffer_policy_) 1589 BufferPolicy buffer_policy_)
1629 : data(data_), length(length_), buffer_policy(buffer_policy_) {} 1590 : data(data_), length(length_), buffer_policy(buffer_policy_) {}
1630 1591
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1685 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1725 return ToApiHandle<UnboundScript>( 1686 return ToApiHandle<UnboundScript>(
1726 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); 1687 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
1727 } 1688 }
1728 1689
1729 1690
1730 Local<UnboundScript> ScriptCompiler::CompileUnbound( 1691 Local<UnboundScript> ScriptCompiler::CompileUnbound(
1731 Isolate* v8_isolate, 1692 Isolate* v8_isolate,
1732 Source* source, 1693 Source* source,
1733 CompileOptions options) { 1694 CompileOptions options) {
1734 i::ScriptDataImpl* script_data_impl = NULL; 1695 i::ScriptData* script_data_impl = NULL;
1735 i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA; 1696 i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA;
1736 if (options & kProduceDataToCache) { 1697 if (options & kProduceDataToCache) {
1737 cached_data_mode = i::PRODUCE_CACHED_DATA; 1698 cached_data_mode = i::PRODUCE_CACHED_DATA;
1738 ASSERT(source->cached_data == NULL); 1699 ASSERT(source->cached_data == NULL);
1739 if (source->cached_data) { 1700 if (source->cached_data) {
1740 // Asked to produce cached data even though there is some already -> not 1701 // Asked to produce cached data even though there is some already -> not
1741 // good. In release mode, try to do the right thing: Just regenerate the 1702 // good. In release mode, try to do the right thing: Just regenerate the
1742 // data. 1703 // data.
1743 delete source->cached_data; 1704 delete source->cached_data;
1744 source->cached_data = NULL; 1705 source->cached_data = NULL;
1745 } 1706 }
1746 } else if (source->cached_data) { 1707 } else if (source->cached_data) {
1747 // FIXME(marja): Make compiler use CachedData directly. Aligning needs to be 1708 // ScriptData takes care of aligning, in case the data is not aligned
1748 // taken care of. 1709 // correctly.
1749 script_data_impl = static_cast<i::ScriptDataImpl*>(ScriptData::New( 1710 script_data_impl = i::ScriptData::New(
1750 reinterpret_cast<const char*>(source->cached_data->data), 1711 reinterpret_cast<const char*>(source->cached_data->data),
1751 source->cached_data->length)); 1712 source->cached_data->length);
1752 // We assert that the pre-data is sane, even though we can actually 1713 // We assert that the pre-data is sane, even though we can actually
1753 // handle it if it turns out not to be in release mode. 1714 // handle it if it turns out not to be in release mode.
1754 ASSERT(script_data_impl->SanityCheck()); 1715 ASSERT(script_data_impl->SanityCheck());
1755 if (script_data_impl->SanityCheck()) { 1716 if (script_data_impl->SanityCheck()) {
1756 cached_data_mode = i::CONSUME_CACHED_DATA; 1717 cached_data_mode = i::CONSUME_CACHED_DATA;
1757 } else { 1718 } else {
1758 // If the pre-data isn't sane we simply ignore it. 1719 // If the pre-data isn't sane we simply ignore it.
1759 delete script_data_impl; 1720 delete script_data_impl;
1760 script_data_impl = NULL; 1721 script_data_impl = NULL;
1761 delete source->cached_data; 1722 delete source->cached_data;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); 1791 LOG_API(isolate, "ScriptCompiler::CompiletBound()");
1831 ENTER_V8(isolate); 1792 ENTER_V8(isolate);
1832 Local<UnboundScript> generic = 1793 Local<UnboundScript> generic =
1833 CompileUnbound(v8_isolate, source, options); 1794 CompileUnbound(v8_isolate, source, options);
1834 if (generic.IsEmpty()) return Local<Script>(); 1795 if (generic.IsEmpty()) return Local<Script>();
1835 return generic->BindToCurrentContext(); 1796 return generic->BindToCurrentContext();
1836 } 1797 }
1837 1798
1838 1799
1839 Local<Script> Script::Compile(v8::Handle<String> source, 1800 Local<Script> Script::Compile(v8::Handle<String> source,
1840 v8::ScriptOrigin* origin, 1801 v8::ScriptOrigin* origin) {
1841 ScriptData* script_data) {
1842 i::Handle<i::String> str = Utils::OpenHandle(*source); 1802 i::Handle<i::String> str = Utils::OpenHandle(*source);
1843 ScriptCompiler::CachedData* cached_data = NULL;
1844 if (script_data) {
1845 cached_data = new ScriptCompiler::CachedData(
1846 reinterpret_cast<const uint8_t*>(script_data->Data()),
1847 script_data->Length());
1848 }
1849 if (origin) { 1803 if (origin) {
1850 ScriptCompiler::Source script_source(source, *origin, cached_data); 1804 ScriptCompiler::Source script_source(source, *origin);
1851 return ScriptCompiler::Compile( 1805 return ScriptCompiler::Compile(
1852 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), 1806 reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1853 &script_source); 1807 &script_source);
1854 } 1808 }
1855 ScriptCompiler::Source script_source(source, cached_data); 1809 ScriptCompiler::Source script_source(source);
1856 return ScriptCompiler::Compile( 1810 return ScriptCompiler::Compile(
1857 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), 1811 reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1858 &script_source); 1812 &script_source);
1859 } 1813 }
1860 1814
1861 1815
1862 Local<Script> Script::Compile(v8::Handle<String> source, 1816 Local<Script> Script::Compile(v8::Handle<String> source,
1863 v8::Handle<String> file_name) { 1817 v8::Handle<String> file_name) {
1864 ScriptOrigin origin(file_name); 1818 ScriptOrigin origin(file_name);
1865 return Compile(source, &origin); 1819 return Compile(source, &origin);
(...skipping 5828 matching lines...) Expand 10 before | Expand all | Expand 10 after
7694 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7648 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7695 Address callback_address = 7649 Address callback_address =
7696 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7650 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7697 VMState<EXTERNAL> state(isolate); 7651 VMState<EXTERNAL> state(isolate);
7698 ExternalCallbackScope call_scope(isolate, callback_address); 7652 ExternalCallbackScope call_scope(isolate, callback_address);
7699 callback(info); 7653 callback(info);
7700 } 7654 }
7701 7655
7702 7656
7703 } } // namespace v8::internal 7657 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698