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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 } | 1560 } |
1561 | 1561 |
1562 | 1562 |
1563 Local<Script> UnboundScript::BindToCurrentContext() { | 1563 Local<Script> UnboundScript::BindToCurrentContext() { |
1564 i::Handle<i::HeapObject> obj = | 1564 i::Handle<i::HeapObject> obj = |
1565 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1565 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
1566 i::Handle<i::SharedFunctionInfo> | 1566 i::Handle<i::SharedFunctionInfo> |
1567 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); | 1567 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); |
1568 i::Handle<i::JSFunction> function = | 1568 i::Handle<i::JSFunction> function = |
1569 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( | 1569 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( |
1570 function_info, obj->GetIsolate()->global_context()); | 1570 function_info, obj->GetIsolate()->native_context()); |
1571 return ToApiHandle<Script>(function); | 1571 return ToApiHandle<Script>(function); |
1572 } | 1572 } |
1573 | 1573 |
1574 | 1574 |
1575 int UnboundScript::GetId() { | 1575 int UnboundScript::GetId() { |
1576 i::Handle<i::HeapObject> obj = | 1576 i::Handle<i::HeapObject> obj = |
1577 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1577 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
1578 i::Isolate* isolate = obj->GetIsolate(); | 1578 i::Isolate* isolate = obj->GetIsolate(); |
1579 ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1); | 1579 ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1); |
1580 LOG_API(isolate, "v8::UnboundScript::GetId"); | 1580 LOG_API(isolate, "v8::UnboundScript::GetId"); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 static_cast<int>(source->resource_column_offset->Value()); | 1725 static_cast<int>(source->resource_column_offset->Value()); |
1726 } | 1726 } |
1727 if (!source->resource_is_shared_cross_origin.IsEmpty()) { | 1727 if (!source->resource_is_shared_cross_origin.IsEmpty()) { |
1728 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1728 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
1729 is_shared_cross_origin = | 1729 is_shared_cross_origin = |
1730 source->resource_is_shared_cross_origin == v8::True(v8_isolate); | 1730 source->resource_is_shared_cross_origin == v8::True(v8_isolate); |
1731 } | 1731 } |
1732 EXCEPTION_PREAMBLE(isolate); | 1732 EXCEPTION_PREAMBLE(isolate); |
1733 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( | 1733 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( |
1734 str, name_obj, line_offset, column_offset, is_shared_cross_origin, | 1734 str, name_obj, line_offset, column_offset, is_shared_cross_origin, |
1735 isolate->global_context(), NULL, &script_data, options, | 1735 isolate->native_context(), NULL, &script_data, options, |
1736 i::NOT_NATIVES_CODE); | 1736 i::NOT_NATIVES_CODE); |
1737 has_pending_exception = result.is_null(); | 1737 has_pending_exception = result.is_null(); |
1738 if (has_pending_exception && script_data != NULL) { | 1738 if (has_pending_exception && script_data != NULL) { |
1739 // This case won't happen during normal operation; we have compiled | 1739 // This case won't happen during normal operation; we have compiled |
1740 // successfully and produced cached data, and but the second compilation | 1740 // successfully and produced cached data, and but the second compilation |
1741 // of the same source code fails. | 1741 // of the same source code fails. |
1742 delete script_data; | 1742 delete script_data; |
1743 script_data = NULL; | 1743 script_data = NULL; |
1744 } | 1744 } |
1745 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); | 1745 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
(...skipping 24 matching lines...) Expand all Loading... |
1770 ENTER_V8(isolate); | 1770 ENTER_V8(isolate); |
1771 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); | 1771 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); |
1772 if (generic.IsEmpty()) return Local<Script>(); | 1772 if (generic.IsEmpty()) return Local<Script>(); |
1773 return generic->BindToCurrentContext(); | 1773 return generic->BindToCurrentContext(); |
1774 } | 1774 } |
1775 | 1775 |
1776 | 1776 |
1777 ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( | 1777 ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( |
1778 Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { | 1778 Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { |
1779 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1779 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1780 if (!isolate->global_context().is_null() && | |
1781 !isolate->global_context()->IsNativeContext()) { | |
1782 // The context chain is non-trivial, and constructing the corresponding | |
1783 // non-trivial Scope chain outside the V8 heap is not implemented. Don't | |
1784 // stream the script. This will only occur if Harmony scoping is enabled and | |
1785 // a previous script has introduced "let" or "const" variables. TODO(marja): | |
1786 // Implement externalizing ScopeInfos and constructing non-trivial Scope | |
1787 // chains independent of the V8 heap so that we can stream also in this | |
1788 // case. | |
1789 return NULL; | |
1790 } | |
1791 return new i::BackgroundParsingTask(source->impl(), options, | 1780 return new i::BackgroundParsingTask(source->impl(), options, |
1792 i::FLAG_stack_size, isolate); | 1781 i::FLAG_stack_size, isolate); |
1793 } | 1782 } |
1794 | 1783 |
1795 | 1784 |
1796 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, | 1785 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, |
1797 StreamedSource* v8_source, | 1786 StreamedSource* v8_source, |
1798 Handle<String> full_source_string, | 1787 Handle<String> full_source_string, |
1799 const ScriptOrigin& origin) { | 1788 const ScriptOrigin& origin) { |
1800 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1789 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
(...skipping 16 matching lines...) Expand all Loading... |
1817 } | 1806 } |
1818 if (!origin.ResourceColumnOffset().IsEmpty()) { | 1807 if (!origin.ResourceColumnOffset().IsEmpty()) { |
1819 script->set_column_offset(i::Smi::FromInt( | 1808 script->set_column_offset(i::Smi::FromInt( |
1820 static_cast<int>(origin.ResourceColumnOffset()->Value()))); | 1809 static_cast<int>(origin.ResourceColumnOffset()->Value()))); |
1821 } | 1810 } |
1822 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { | 1811 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { |
1823 script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() == | 1812 script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() == |
1824 v8::True(v8_isolate)); | 1813 v8::True(v8_isolate)); |
1825 } | 1814 } |
1826 source->info->set_script(script); | 1815 source->info->set_script(script); |
1827 source->info->SetContext(isolate->global_context()); | 1816 source->info->SetContext(isolate->native_context()); |
1828 | 1817 |
1829 EXCEPTION_PREAMBLE(isolate); | 1818 EXCEPTION_PREAMBLE(isolate); |
1830 | 1819 |
1831 // Do the parsing tasks which need to be done on the main thread. This will | 1820 // Do the parsing tasks which need to be done on the main thread. This will |
1832 // also handle parse errors. | 1821 // also handle parse errors. |
1833 source->parser->Internalize(); | 1822 source->parser->Internalize(); |
1834 | 1823 |
1835 i::Handle<i::SharedFunctionInfo> result = | 1824 i::Handle<i::SharedFunctionInfo> result = |
1836 i::Handle<i::SharedFunctionInfo>::null(); | 1825 i::Handle<i::SharedFunctionInfo>::null(); |
1837 if (source->info->function() != NULL) { | 1826 if (source->info->function() != NULL) { |
(...skipping 5949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7787 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7776 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7788 Address callback_address = | 7777 Address callback_address = |
7789 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7778 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7790 VMState<EXTERNAL> state(isolate); | 7779 VMState<EXTERNAL> state(isolate); |
7791 ExternalCallbackScope call_scope(isolate, callback_address); | 7780 ExternalCallbackScope call_scope(isolate, callback_address); |
7792 callback(info); | 7781 callback(info); |
7793 } | 7782 } |
7794 | 7783 |
7795 | 7784 |
7796 } } // namespace v8::internal | 7785 } } // namespace v8::internal |
OLD | NEW |