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 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 } | 1556 } |
1557 | 1557 |
1558 | 1558 |
1559 Local<UnboundScript> Script::GetUnboundScript() { | 1559 Local<UnboundScript> Script::GetUnboundScript() { |
1560 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 1560 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
1561 return ToApiHandle<UnboundScript>( | 1561 return ToApiHandle<UnboundScript>( |
1562 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); | 1562 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); |
1563 } | 1563 } |
1564 | 1564 |
1565 | 1565 |
1566 Local<UnboundScript> ScriptCompiler::CompileUnbound( | 1566 Local<UnboundScript> ScriptCompiler::CompileUnboundInternal( |
1567 Isolate* v8_isolate, | 1567 Isolate* v8_isolate, Source* source, CompileOptions options, |
1568 Source* source, | 1568 bool is_module) { |
1569 CompileOptions options) { | |
1570 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1569 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1571 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", | 1570 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", |
1572 return Local<UnboundScript>()); | 1571 return Local<UnboundScript>()); |
1573 | 1572 |
1574 // Support the old API for a transition period: | 1573 // Support the old API for a transition period: |
1575 // - kProduceToCache -> kProduceParserCache | 1574 // - kProduceToCache -> kProduceParserCache |
1576 // - kNoCompileOptions + cached_data != NULL -> kConsumeParserCache | 1575 // - kNoCompileOptions + cached_data != NULL -> kConsumeParserCache |
1577 if (options == kProduceDataToCache) { | 1576 if (options == kProduceDataToCache) { |
1578 options = kProduceParserCache; | 1577 options = kProduceParserCache; |
1579 } else if (options == kNoCompileOptions && source->cached_data) { | 1578 } else if (options == kNoCompileOptions && source->cached_data) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 source->resource_is_shared_cross_origin->IsTrue(); | 1619 source->resource_is_shared_cross_origin->IsTrue(); |
1621 } | 1620 } |
1622 if (!source->resource_is_embedder_debug_script.IsEmpty()) { | 1621 if (!source->resource_is_embedder_debug_script.IsEmpty()) { |
1623 is_embedder_debug_script = | 1622 is_embedder_debug_script = |
1624 source->resource_is_embedder_debug_script->IsTrue(); | 1623 source->resource_is_embedder_debug_script->IsTrue(); |
1625 } | 1624 } |
1626 EXCEPTION_PREAMBLE(isolate); | 1625 EXCEPTION_PREAMBLE(isolate); |
1627 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( | 1626 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( |
1628 str, name_obj, line_offset, column_offset, is_embedder_debug_script, | 1627 str, name_obj, line_offset, column_offset, is_embedder_debug_script, |
1629 is_shared_cross_origin, isolate->native_context(), NULL, &script_data, | 1628 is_shared_cross_origin, isolate->native_context(), NULL, &script_data, |
1630 options, i::NOT_NATIVES_CODE); | 1629 options, i::NOT_NATIVES_CODE, is_module); |
1631 has_pending_exception = result.is_null(); | 1630 has_pending_exception = result.is_null(); |
1632 if (has_pending_exception && script_data != NULL) { | 1631 if (has_pending_exception && script_data != NULL) { |
1633 // This case won't happen during normal operation; we have compiled | 1632 // This case won't happen during normal operation; we have compiled |
1634 // successfully and produced cached data, and but the second compilation | 1633 // successfully and produced cached data, and but the second compilation |
1635 // of the same source code fails. | 1634 // of the same source code fails. |
1636 delete script_data; | 1635 delete script_data; |
1637 script_data = NULL; | 1636 script_data = NULL; |
1638 } | 1637 } |
1639 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); | 1638 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
1640 raw_result = *result; | 1639 raw_result = *result; |
1641 | 1640 |
1642 if ((options == kProduceParserCache || options == kProduceCodeCache) && | 1641 if ((options == kProduceParserCache || options == kProduceCodeCache) && |
1643 script_data != NULL) { | 1642 script_data != NULL) { |
1644 // script_data now contains the data that was generated. source will | 1643 // script_data now contains the data that was generated. source will |
1645 // take the ownership. | 1644 // take the ownership. |
1646 source->cached_data = new CachedData( | 1645 source->cached_data = new CachedData( |
1647 script_data->data(), script_data->length(), CachedData::BufferOwned); | 1646 script_data->data(), script_data->length(), CachedData::BufferOwned); |
1648 script_data->ReleaseDataOwnership(); | 1647 script_data->ReleaseDataOwnership(); |
1649 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) { | 1648 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) { |
1650 source->cached_data->rejected = script_data->rejected(); | 1649 source->cached_data->rejected = script_data->rejected(); |
1651 } | 1650 } |
1652 delete script_data; | 1651 delete script_data; |
1653 } | 1652 } |
1654 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | 1653 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
1655 return ToApiHandle<UnboundScript>(result); | 1654 return ToApiHandle<UnboundScript>(result); |
1656 } | 1655 } |
1657 | 1656 |
1658 | 1657 |
| 1658 Local<UnboundScript> ScriptCompiler::CompileUnbound(Isolate* v8_isolate, |
| 1659 Source* source, |
| 1660 CompileOptions options) { |
| 1661 return CompileUnboundInternal(v8_isolate, source, options, false); |
| 1662 } |
| 1663 |
| 1664 |
1659 Local<Script> ScriptCompiler::Compile( | 1665 Local<Script> ScriptCompiler::Compile( |
1660 Isolate* v8_isolate, | 1666 Isolate* v8_isolate, |
1661 Source* source, | 1667 Source* source, |
1662 CompileOptions options) { | 1668 CompileOptions options) { |
1663 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1669 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1664 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); | 1670 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); |
1665 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); | 1671 LOG_API(isolate, "ScriptCompiler::CompileBound()"); |
1666 ENTER_V8(isolate); | 1672 ENTER_V8(isolate); |
1667 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); | 1673 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); |
1668 if (generic.IsEmpty()) return Local<Script>(); | 1674 if (generic.IsEmpty()) return Local<Script>(); |
1669 return generic->BindToCurrentContext(); | 1675 return generic->BindToCurrentContext(); |
1670 } | 1676 } |
1671 | 1677 |
1672 | 1678 |
| 1679 Local<Script> ScriptCompiler::CompileModule(Isolate* v8_isolate, Source* source, |
| 1680 CompileOptions options) { |
| 1681 CHECK(i::FLAG_harmony_modules); |
| 1682 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 1683 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileModule()", |
| 1684 return Local<Script>()); |
| 1685 LOG_API(isolate, "ScriptCompiler::CompileModule()"); |
| 1686 ENTER_V8(isolate); |
| 1687 Local<UnboundScript> generic = |
| 1688 CompileUnboundInternal(v8_isolate, source, options, true); |
| 1689 if (generic.IsEmpty()) return Local<Script>(); |
| 1690 return generic->BindToCurrentContext(); |
| 1691 } |
| 1692 |
| 1693 |
1673 ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( | 1694 ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( |
1674 Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { | 1695 Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { |
1675 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1696 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1676 return new i::BackgroundParsingTask(source->impl(), options, | 1697 return new i::BackgroundParsingTask(source->impl(), options, |
1677 i::FLAG_stack_size, isolate); | 1698 i::FLAG_stack_size, isolate); |
1678 } | 1699 } |
1679 | 1700 |
1680 | 1701 |
1681 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, | 1702 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, |
1682 StreamedSource* v8_source, | 1703 StreamedSource* v8_source, |
(...skipping 6049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7732 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7753 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7733 Address callback_address = | 7754 Address callback_address = |
7734 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7755 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7735 VMState<EXTERNAL> state(isolate); | 7756 VMState<EXTERNAL> state(isolate); |
7736 ExternalCallbackScope call_scope(isolate, callback_address); | 7757 ExternalCallbackScope call_scope(isolate, callback_address); |
7737 callback(info); | 7758 callback(info); |
7738 } | 7759 } |
7739 | 7760 |
7740 | 7761 |
7741 } } // namespace v8::internal | 7762 } } // namespace v8::internal |
OLD | NEW |