| OLD | NEW |
| 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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 if (value > 0) { | 1560 if (value > 0) { |
| 1561 // The internal field count is set by the constructor function's | 1561 // The internal field count is set by the constructor function's |
| 1562 // construct code, so we ensure that there is a constructor | 1562 // construct code, so we ensure that there is a constructor |
| 1563 // function to do the setting. | 1563 // function to do the setting. |
| 1564 EnsureConstructor(isolate, this); | 1564 EnsureConstructor(isolate, this); |
| 1565 } | 1565 } |
| 1566 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); | 1566 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
| 1567 } | 1567 } |
| 1568 | 1568 |
| 1569 | 1569 |
| 1570 // --- S c r i p t D a t a --- | |
| 1571 | |
| 1572 | |
| 1573 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { | |
| 1574 i::Handle<i::String> str = Utils::OpenHandle(*source); | |
| 1575 i::Isolate* isolate = str->GetIsolate(); | |
| 1576 if (str->IsExternalTwoByteString()) { | |
| 1577 i::ExternalTwoByteStringUtf16CharacterStream stream( | |
| 1578 i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); | |
| 1579 return i::PreParserApi::PreParse(isolate, &stream); | |
| 1580 } else { | |
| 1581 i::GenericStringUtf16CharacterStream stream(str, 0, str->length()); | |
| 1582 return i::PreParserApi::PreParse(isolate, &stream); | |
| 1583 } | |
| 1584 } | |
| 1585 | |
| 1586 | |
| 1587 ScriptData* ScriptData::New(const char* data, int length) { | |
| 1588 // Return an empty ScriptData if the length is obviously invalid. | |
| 1589 if (length % sizeof(unsigned) != 0) { | |
| 1590 return new i::ScriptDataImpl(); | |
| 1591 } | |
| 1592 | |
| 1593 // Copy the data to ensure it is properly aligned. | |
| 1594 int deserialized_data_length = length / sizeof(unsigned); | |
| 1595 // If aligned, don't create a copy of the data. | |
| 1596 if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { | |
| 1597 return new i::ScriptDataImpl(data, length); | |
| 1598 } | |
| 1599 // Copy the data to align it. | |
| 1600 unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); | |
| 1601 i::CopyBytes(reinterpret_cast<char*>(deserialized_data), | |
| 1602 data, static_cast<size_t>(length)); | |
| 1603 | |
| 1604 return new i::ScriptDataImpl( | |
| 1605 i::Vector<unsigned>(deserialized_data, deserialized_data_length)); | |
| 1606 } | |
| 1607 | |
| 1608 | |
| 1609 // --- S c r i p t s --- | 1570 // --- S c r i p t s --- |
| 1610 | 1571 |
| 1611 | 1572 |
| 1612 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a | 1573 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a |
| 1613 // JSFunction. | 1574 // JSFunction. |
| 1614 | 1575 |
| 1615 ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_, | 1576 ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_, |
| 1616 BufferPolicy buffer_policy_) | 1577 BufferPolicy buffer_policy_) |
| 1617 : data(data_), length(length_), buffer_policy(buffer_policy_) {} | 1578 : data(data_), length(length_), buffer_policy(buffer_policy_) {} |
| 1618 | 1579 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 cached_data_mode = i::PRODUCE_CACHED_DATA; | 1691 cached_data_mode = i::PRODUCE_CACHED_DATA; |
| 1731 ASSERT(source->cached_data == NULL); | 1692 ASSERT(source->cached_data == NULL); |
| 1732 if (source->cached_data) { | 1693 if (source->cached_data) { |
| 1733 // Asked to produce cached data even though there is some already -> not | 1694 // Asked to produce cached data even though there is some already -> not |
| 1734 // good. In release mode, try to do the right thing: Just regenerate the | 1695 // good. In release mode, try to do the right thing: Just regenerate the |
| 1735 // data. | 1696 // data. |
| 1736 delete source->cached_data; | 1697 delete source->cached_data; |
| 1737 source->cached_data = NULL; | 1698 source->cached_data = NULL; |
| 1738 } | 1699 } |
| 1739 } else if (source->cached_data) { | 1700 } else if (source->cached_data) { |
| 1740 // FIXME(marja): Make compiler use CachedData directly. Aligning needs to be | 1701 // ScriptDataImpl takes care of aligning, in case the data is not aligned |
| 1741 // taken care of. | 1702 // correctly. |
| 1742 script_data_impl = static_cast<i::ScriptDataImpl*>(ScriptData::New( | 1703 script_data_impl = new i::ScriptDataImpl( |
| 1743 reinterpret_cast<const char*>(source->cached_data->data), | 1704 reinterpret_cast<const char*>(source->cached_data->data), |
| 1744 source->cached_data->length)); | 1705 source->cached_data->length); |
| 1745 // We assert that the pre-data is sane, even though we can actually | 1706 // We assert that the pre-data is sane, even though we can actually |
| 1746 // handle it if it turns out not to be in release mode. | 1707 // handle it if it turns out not to be in release mode. |
| 1747 ASSERT(script_data_impl->SanityCheck()); | 1708 ASSERT(script_data_impl->SanityCheck()); |
| 1748 if (script_data_impl->SanityCheck()) { | 1709 if (script_data_impl->SanityCheck()) { |
| 1749 cached_data_mode = i::CONSUME_CACHED_DATA; | 1710 cached_data_mode = i::CONSUME_CACHED_DATA; |
| 1750 } else { | 1711 } else { |
| 1751 // If the pre-data isn't sane we simply ignore it. | 1712 // If the pre-data isn't sane we simply ignore it. |
| 1752 delete script_data_impl; | 1713 delete script_data_impl; |
| 1753 script_data_impl = NULL; | 1714 script_data_impl = NULL; |
| 1754 delete source->cached_data; | 1715 delete source->cached_data; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); | 1784 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); |
| 1824 ENTER_V8(isolate); | 1785 ENTER_V8(isolate); |
| 1825 Local<UnboundScript> generic = | 1786 Local<UnboundScript> generic = |
| 1826 CompileUnbound(v8_isolate, source, options); | 1787 CompileUnbound(v8_isolate, source, options); |
| 1827 if (generic.IsEmpty()) return Local<Script>(); | 1788 if (generic.IsEmpty()) return Local<Script>(); |
| 1828 return generic->BindToCurrentContext(); | 1789 return generic->BindToCurrentContext(); |
| 1829 } | 1790 } |
| 1830 | 1791 |
| 1831 | 1792 |
| 1832 Local<Script> Script::Compile(v8::Handle<String> source, | 1793 Local<Script> Script::Compile(v8::Handle<String> source, |
| 1833 v8::ScriptOrigin* origin, | 1794 v8::ScriptOrigin* origin) { |
| 1834 ScriptData* script_data) { | |
| 1835 i::Handle<i::String> str = Utils::OpenHandle(*source); | 1795 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1836 ScriptCompiler::CachedData* cached_data = NULL; | |
| 1837 if (script_data) { | |
| 1838 cached_data = new ScriptCompiler::CachedData( | |
| 1839 reinterpret_cast<const uint8_t*>(script_data->Data()), | |
| 1840 script_data->Length()); | |
| 1841 } | |
| 1842 if (origin) { | 1796 if (origin) { |
| 1843 ScriptCompiler::Source script_source(source, *origin, cached_data); | 1797 ScriptCompiler::Source script_source(source, *origin); |
| 1844 return ScriptCompiler::Compile( | 1798 return ScriptCompiler::Compile( |
| 1845 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), | 1799 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), |
| 1846 &script_source); | 1800 &script_source); |
| 1847 } | 1801 } |
| 1848 ScriptCompiler::Source script_source(source, cached_data); | 1802 ScriptCompiler::Source script_source(source); |
| 1849 return ScriptCompiler::Compile( | 1803 return ScriptCompiler::Compile( |
| 1850 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), | 1804 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), |
| 1851 &script_source); | 1805 &script_source); |
| 1852 } | 1806 } |
| 1853 | 1807 |
| 1854 | 1808 |
| 1855 Local<Script> Script::Compile(v8::Handle<String> source, | 1809 Local<Script> Script::Compile(v8::Handle<String> source, |
| 1856 v8::Handle<String> file_name) { | 1810 v8::Handle<String> file_name) { |
| 1857 ScriptOrigin origin(file_name); | 1811 ScriptOrigin origin(file_name); |
| 1858 return Compile(source, &origin); | 1812 return Compile(source, &origin); |
| (...skipping 5803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7662 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7616 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7663 Address callback_address = | 7617 Address callback_address = |
| 7664 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7618 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7665 VMState<EXTERNAL> state(isolate); | 7619 VMState<EXTERNAL> state(isolate); |
| 7666 ExternalCallbackScope call_scope(isolate, callback_address); | 7620 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7667 callback(info); | 7621 callback(info); |
| 7668 } | 7622 } |
| 7669 | 7623 |
| 7670 | 7624 |
| 7671 } } // namespace v8::internal | 7625 } } // namespace v8::internal |
| OLD | NEW |