| 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 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 // function to do the setting. | 1639 // function to do the setting. |
| 1640 EnsureConstructor(this); | 1640 EnsureConstructor(this); |
| 1641 } | 1641 } |
| 1642 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); | 1642 Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
| 1643 } | 1643 } |
| 1644 | 1644 |
| 1645 | 1645 |
| 1646 // --- S c r i p t D a t a --- | 1646 // --- S c r i p t D a t a --- |
| 1647 | 1647 |
| 1648 | 1648 |
| 1649 ScriptData* ScriptData::PreCompile(const char* input, int length) { | 1649 ScriptData* ScriptData::PreCompile(v8::Isolate* isolate, |
| 1650 const char* input, |
| 1651 int length) { |
| 1650 i::Utf8ToUtf16CharacterStream stream( | 1652 i::Utf8ToUtf16CharacterStream stream( |
| 1651 reinterpret_cast<const unsigned char*>(input), length); | 1653 reinterpret_cast<const unsigned char*>(input), length); |
| 1652 return i::PreParserApi::PreParse(i::Isolate::Current(), &stream); | 1654 return i::PreParserApi::PreParse( |
| 1655 reinterpret_cast<i::Isolate*>(isolate), &stream); |
| 1653 } | 1656 } |
| 1654 | 1657 |
| 1655 | 1658 |
| 1656 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { | 1659 ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1657 i::Handle<i::String> str = Utils::OpenHandle(*source); | 1660 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1658 i::Isolate* isolate = str->GetIsolate(); | 1661 i::Isolate* isolate = str->GetIsolate(); |
| 1659 if (str->IsExternalTwoByteString()) { | 1662 if (str->IsExternalTwoByteString()) { |
| 1660 i::ExternalTwoByteStringUtf16CharacterStream stream( | 1663 i::ExternalTwoByteStringUtf16CharacterStream stream( |
| 1661 i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); | 1664 i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
| 1662 return i::PreParserApi::PreParse(isolate, &stream); | 1665 return i::PreParserApi::PreParse(isolate, &stream); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1689 } | 1692 } |
| 1690 | 1693 |
| 1691 | 1694 |
| 1692 // --- S c r i p t --- | 1695 // --- S c r i p t --- |
| 1693 | 1696 |
| 1694 | 1697 |
| 1695 Local<Script> Script::New(v8::Handle<String> source, | 1698 Local<Script> Script::New(v8::Handle<String> source, |
| 1696 v8::ScriptOrigin* origin, | 1699 v8::ScriptOrigin* origin, |
| 1697 v8::ScriptData* pre_data, | 1700 v8::ScriptData* pre_data, |
| 1698 v8::Handle<String> script_data) { | 1701 v8::Handle<String> script_data) { |
| 1699 i::Isolate* isolate = i::Isolate::Current(); | 1702 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1703 i::Isolate* isolate = str->GetIsolate(); |
| 1700 ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); | 1704 ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1701 LOG_API(isolate, "Script::New"); | 1705 LOG_API(isolate, "Script::New"); |
| 1702 ENTER_V8(isolate); | 1706 ENTER_V8(isolate); |
| 1703 i::SharedFunctionInfo* raw_result = NULL; | 1707 i::SharedFunctionInfo* raw_result = NULL; |
| 1704 { i::HandleScope scope(isolate); | 1708 { i::HandleScope scope(isolate); |
| 1705 i::Handle<i::String> str = Utils::OpenHandle(*source); | |
| 1706 i::Handle<i::Object> name_obj; | 1709 i::Handle<i::Object> name_obj; |
| 1707 int line_offset = 0; | 1710 int line_offset = 0; |
| 1708 int column_offset = 0; | 1711 int column_offset = 0; |
| 1709 bool is_shared_cross_origin = false; | 1712 bool is_shared_cross_origin = false; |
| 1710 if (origin != NULL) { | 1713 if (origin != NULL) { |
| 1711 if (!origin->ResourceName().IsEmpty()) { | 1714 if (!origin->ResourceName().IsEmpty()) { |
| 1712 name_obj = Utils::OpenHandle(*origin->ResourceName()); | 1715 name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1713 } | 1716 } |
| 1714 if (!origin->ResourceLineOffset().IsEmpty()) { | 1717 if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1715 line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); | 1718 line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 v8::Handle<Value> file_name) { | 1761 v8::Handle<Value> file_name) { |
| 1759 ScriptOrigin origin(file_name); | 1762 ScriptOrigin origin(file_name); |
| 1760 return New(source, &origin); | 1763 return New(source, &origin); |
| 1761 } | 1764 } |
| 1762 | 1765 |
| 1763 | 1766 |
| 1764 Local<Script> Script::Compile(v8::Handle<String> source, | 1767 Local<Script> Script::Compile(v8::Handle<String> source, |
| 1765 v8::ScriptOrigin* origin, | 1768 v8::ScriptOrigin* origin, |
| 1766 v8::ScriptData* pre_data, | 1769 v8::ScriptData* pre_data, |
| 1767 v8::Handle<String> script_data) { | 1770 v8::Handle<String> script_data) { |
| 1768 i::Isolate* isolate = i::Isolate::Current(); | 1771 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1772 i::Isolate* isolate = str->GetIsolate(); |
| 1769 ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); | 1773 ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1770 LOG_API(isolate, "Script::Compile"); | 1774 LOG_API(isolate, "Script::Compile"); |
| 1771 ENTER_V8(isolate); | 1775 ENTER_V8(isolate); |
| 1772 Local<Script> generic = New(source, origin, pre_data, script_data); | 1776 Local<Script> generic = New(source, origin, pre_data, script_data); |
| 1773 if (generic.IsEmpty()) | 1777 if (generic.IsEmpty()) |
| 1774 return generic; | 1778 return generic; |
| 1775 i::Handle<i::Object> obj = Utils::OpenHandle(*generic); | 1779 i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1776 i::Handle<i::SharedFunctionInfo> function = | 1780 i::Handle<i::SharedFunctionInfo> function = |
| 1777 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); | 1781 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1778 i::Handle<i::JSFunction> result = | 1782 i::Handle<i::JSFunction> result = |
| 1779 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1783 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1780 function, | 1784 function, |
| 1781 isolate->global_context()); | 1785 isolate->global_context()); |
| 1782 return ToApiHandle<Script>(result); | 1786 return ToApiHandle<Script>(result); |
| 1783 } | 1787 } |
| 1784 | 1788 |
| 1785 | 1789 |
| 1786 Local<Script> Script::Compile(v8::Handle<String> source, | 1790 Local<Script> Script::Compile(v8::Handle<String> source, |
| 1787 v8::Handle<Value> file_name, | 1791 v8::Handle<Value> file_name, |
| 1788 v8::Handle<String> script_data) { | 1792 v8::Handle<String> script_data) { |
| 1789 ScriptOrigin origin(file_name); | 1793 ScriptOrigin origin(file_name); |
| 1790 return Compile(source, &origin, 0, script_data); | 1794 return Compile(source, &origin, 0, script_data); |
| 1791 } | 1795 } |
| 1792 | 1796 |
| 1793 | 1797 |
| 1794 Local<Value> Script::Run() { | 1798 Local<Value> Script::Run() { |
| 1795 i::Isolate* isolate = i::Isolate::Current(); | 1799 // If execution is terminating, Compile(script)->Run() requires this check. |
| 1800 if (this == NULL) return Local<Value>(); |
| 1801 i::Handle<i::HeapObject> obj = |
| 1802 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1803 i::Isolate* isolate = obj->GetIsolate(); |
| 1796 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); | 1804 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1797 LOG_API(isolate, "Script::Run"); | 1805 LOG_API(isolate, "Script::Run"); |
| 1798 ENTER_V8(isolate); | 1806 ENTER_V8(isolate); |
| 1799 i::Logger::TimerEventScope timer_scope( | 1807 i::Logger::TimerEventScope timer_scope( |
| 1800 isolate, i::Logger::TimerEventScope::v8_execute); | 1808 isolate, i::Logger::TimerEventScope::v8_execute); |
| 1801 i::Object* raw_result = NULL; | 1809 i::Object* raw_result = NULL; |
| 1802 { | 1810 { |
| 1803 i::HandleScope scope(isolate); | 1811 i::HandleScope scope(isolate); |
| 1804 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
| 1805 i::Handle<i::JSFunction> fun; | 1812 i::Handle<i::JSFunction> fun; |
| 1806 if (obj->IsSharedFunctionInfo()) { | 1813 if (obj->IsSharedFunctionInfo()) { |
| 1807 i::Handle<i::SharedFunctionInfo> | 1814 i::Handle<i::SharedFunctionInfo> |
| 1808 function_info(i::SharedFunctionInfo::cast(*obj), isolate); | 1815 function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
| 1809 fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1816 fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1810 function_info, isolate->global_context()); | 1817 function_info, isolate->global_context()); |
| 1811 } else { | 1818 } else { |
| 1812 fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); | 1819 fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
| 1813 } | 1820 } |
| 1814 EXCEPTION_PREAMBLE(isolate); | 1821 EXCEPTION_PREAMBLE(isolate); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1832 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); | 1839 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1833 } else { | 1840 } else { |
| 1834 result = | 1841 result = |
| 1835 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); | 1842 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1836 } | 1843 } |
| 1837 return result; | 1844 return result; |
| 1838 } | 1845 } |
| 1839 | 1846 |
| 1840 | 1847 |
| 1841 Local<Value> Script::Id() { | 1848 Local<Value> Script::Id() { |
| 1842 i::Isolate* isolate = i::Isolate::Current(); | 1849 i::Handle<i::HeapObject> obj = |
| 1850 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1851 i::Isolate* isolate = obj->GetIsolate(); |
| 1843 ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); | 1852 ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); |
| 1844 LOG_API(isolate, "Script::Id"); | 1853 LOG_API(isolate, "Script::Id"); |
| 1845 i::Object* raw_id = NULL; | 1854 i::Object* raw_id = NULL; |
| 1846 { | 1855 { |
| 1847 i::HandleScope scope(isolate); | 1856 i::HandleScope scope(isolate); |
| 1848 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); | 1857 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1849 i::Handle<i::Script> script(i::Script::cast(function_info->script())); | 1858 i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
| 1850 i::Handle<i::Object> id(script->id(), isolate); | 1859 i::Handle<i::Object> id(script->id(), isolate); |
| 1851 raw_id = *id; | 1860 raw_id = *id; |
| 1852 } | 1861 } |
| 1853 i::Handle<i::Object> id(raw_id, isolate); | 1862 i::Handle<i::Object> id(raw_id, isolate); |
| 1854 return Utils::ToLocal(id); | 1863 return Utils::ToLocal(id); |
| 1855 } | 1864 } |
| 1856 | 1865 |
| 1857 | 1866 |
| 1858 int Script::GetId() { | 1867 int Script::GetId() { |
| 1859 i::Isolate* isolate = i::Isolate::Current(); | 1868 i::Handle<i::HeapObject> obj = |
| 1869 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1870 i::Isolate* isolate = obj->GetIsolate(); |
| 1860 ON_BAILOUT(isolate, "v8::Script::Id()", return -1); | 1871 ON_BAILOUT(isolate, "v8::Script::Id()", return -1); |
| 1861 LOG_API(isolate, "Script::Id"); | 1872 LOG_API(isolate, "Script::Id"); |
| 1862 { | 1873 { |
| 1863 i::HandleScope scope(isolate); | 1874 i::HandleScope scope(isolate); |
| 1864 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); | 1875 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1865 i::Handle<i::Script> script(i::Script::cast(function_info->script())); | 1876 i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
| 1866 return script->id()->value(); | 1877 return script->id()->value(); |
| 1867 } | 1878 } |
| 1868 } | 1879 } |
| 1869 | 1880 |
| 1870 | 1881 |
| 1871 int Script::GetLineNumber(int code_pos) { | 1882 int Script::GetLineNumber(int code_pos) { |
| 1872 i::Isolate* isolate = i::Isolate::Current(); | 1883 i::Handle<i::HeapObject> obj = |
| 1884 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1885 i::Isolate* isolate = obj->GetIsolate(); |
| 1873 ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1); | 1886 ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1); |
| 1874 LOG_API(isolate, "Script::GetLineNumber"); | 1887 LOG_API(isolate, "Script::GetLineNumber"); |
| 1875 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
| 1876 if (obj->IsScript()) { | 1888 if (obj->IsScript()) { |
| 1877 i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj)); | 1889 i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj)); |
| 1878 return i::GetScriptLineNumber(script, code_pos); | 1890 return i::GetScriptLineNumber(script, code_pos); |
| 1879 } else { | 1891 } else { |
| 1880 return -1; | 1892 return -1; |
| 1881 } | 1893 } |
| 1882 } | 1894 } |
| 1883 | 1895 |
| 1884 | 1896 |
| 1885 Handle<Value> Script::GetScriptName() { | 1897 Handle<Value> Script::GetScriptName() { |
| 1886 i::Isolate* isolate = i::Isolate::Current(); | 1898 i::Handle<i::HeapObject> obj = |
| 1899 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1900 i::Isolate* isolate = obj->GetIsolate(); |
| 1887 ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>()); | 1901 ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>()); |
| 1888 LOG_API(isolate, "Script::GetName"); | 1902 LOG_API(isolate, "Script::GetName"); |
| 1889 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
| 1890 if (obj->IsScript()) { | 1903 if (obj->IsScript()) { |
| 1891 i::Object* name = i::Script::cast(*obj)->name(); | 1904 i::Object* name = i::Script::cast(*obj)->name(); |
| 1892 return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); | 1905 return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); |
| 1893 } else { | 1906 } else { |
| 1894 return Handle<String>(); | 1907 return Handle<String>(); |
| 1895 } | 1908 } |
| 1896 } | 1909 } |
| 1897 | 1910 |
| 1898 | 1911 |
| 1899 void Script::SetData(v8::Handle<String> data) { | 1912 void Script::SetData(v8::Handle<String> data) { |
| 1900 i::Isolate* isolate = i::Isolate::Current(); | 1913 i::Handle<i::HeapObject> obj = |
| 1914 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1915 i::Isolate* isolate = obj->GetIsolate(); |
| 1901 ON_BAILOUT(isolate, "v8::Script::SetData()", return); | 1916 ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1902 LOG_API(isolate, "Script::SetData"); | 1917 LOG_API(isolate, "Script::SetData"); |
| 1903 { | 1918 { |
| 1904 i::HandleScope scope(isolate); | 1919 i::HandleScope scope(isolate); |
| 1905 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); | 1920 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1906 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); | 1921 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
| 1907 i::Handle<i::Script> script(i::Script::cast(function_info->script())); | 1922 i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
| 1908 script->set_data(*raw_data); | 1923 script->set_data(*raw_data); |
| 1909 } | 1924 } |
| 1910 } | 1925 } |
| (...skipping 5664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7575 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7590 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7576 Address callback_address = | 7591 Address callback_address = |
| 7577 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7592 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7578 VMState<EXTERNAL> state(isolate); | 7593 VMState<EXTERNAL> state(isolate); |
| 7579 ExternalCallbackScope call_scope(isolate, callback_address); | 7594 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7580 callback(info); | 7595 callback(info); |
| 7581 } | 7596 } |
| 7582 | 7597 |
| 7583 | 7598 |
| 7584 } } // namespace v8::internal | 7599 } } // namespace v8::internal |
| OLD | NEW |