| 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 553 } |
| 554 | 554 |
| 555 | 555 |
| 556 void V8::MakeWeak(i::Object** object, | 556 void V8::MakeWeak(i::Object** object, |
| 557 void* parameters, | 557 void* parameters, |
| 558 WeakCallback weak_callback) { | 558 WeakCallback weak_callback) { |
| 559 i::GlobalHandles::MakeWeak(object, parameters, weak_callback); | 559 i::GlobalHandles::MakeWeak(object, parameters, weak_callback); |
| 560 } | 560 } |
| 561 | 561 |
| 562 | 562 |
| 563 void V8::ClearWeak(i::Object** obj) { | 563 void* V8::ClearWeak(i::Object** obj) { |
| 564 i::GlobalHandles::ClearWeakness(obj); | 564 return i::GlobalHandles::ClearWeakness(obj); |
| 565 } | 565 } |
| 566 | 566 |
| 567 | 567 |
| 568 void V8::DisposeGlobal(i::Object** obj) { | 568 void V8::DisposeGlobal(i::Object** obj) { |
| 569 i::GlobalHandles::Destroy(obj); | 569 i::GlobalHandles::Destroy(obj); |
| 570 } | 570 } |
| 571 | 571 |
| 572 | 572 |
| 573 void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) { | 573 void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) { |
| 574 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 574 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 // Copy the data to align it. | 1604 // Copy the data to align it. |
| 1605 unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); | 1605 unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
| 1606 i::CopyBytes(reinterpret_cast<char*>(deserialized_data), | 1606 i::CopyBytes(reinterpret_cast<char*>(deserialized_data), |
| 1607 data, static_cast<size_t>(length)); | 1607 data, static_cast<size_t>(length)); |
| 1608 | 1608 |
| 1609 return new i::ScriptDataImpl( | 1609 return new i::ScriptDataImpl( |
| 1610 i::Vector<unsigned>(deserialized_data, deserialized_data_length)); | 1610 i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
| 1611 } | 1611 } |
| 1612 | 1612 |
| 1613 | 1613 |
| 1614 // --- S c r i p t --- | 1614 // --- S c r i p t s --- |
| 1615 | 1615 |
| 1616 | 1616 |
| 1617 Local<Script> Script::New(v8::Handle<String> source, | 1617 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a |
| 1618 v8::ScriptOrigin* origin, | 1618 // JSFunction. |
| 1619 v8::ScriptData* pre_data, | 1619 |
| 1620 v8::Handle<String> script_data) { | 1620 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin, |
| 1621 i::Handle<i::String> str = Utils::OpenHandle(*source); | 1621 const CachedData& data) |
| 1622 i::Isolate* isolate = str->GetIsolate(); | 1622 : source_string(string), |
| 1623 ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); | 1623 resource_name(origin.ResourceName()), |
| 1624 LOG_API(isolate, "Script::New"); | 1624 resource_line_offset(origin.ResourceLineOffset()), |
| 1625 ENTER_V8(isolate); | 1625 resource_column_offset(origin.ResourceColumnOffset()), |
| 1626 i::SharedFunctionInfo* raw_result = NULL; | 1626 resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()), |
| 1627 { i::HandleScope scope(isolate); | 1627 cached_data(data) {} |
| 1628 i::Handle<i::Object> name_obj; | 1628 |
| 1629 int line_offset = 0; | 1629 |
| 1630 int column_offset = 0; | 1630 ScriptCompiler::Source::Source(Local<String> string, |
| 1631 bool is_shared_cross_origin = false; | 1631 const CachedData& data) |
| 1632 if (origin != NULL) { | 1632 : source_string(string), cached_data(data) {} |
| 1633 if (!origin->ResourceName().IsEmpty()) { | 1633 |
| 1634 name_obj = Utils::OpenHandle(*origin->ResourceName()); | 1634 |
| 1635 } | 1635 Local<Script> UnboundScript::BindToCurrentContext() { |
| 1636 if (!origin->ResourceLineOffset().IsEmpty()) { | 1636 i::Handle<i::HeapObject> obj = |
| 1637 line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); | 1637 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1638 } | 1638 i::Handle<i::SharedFunctionInfo> |
| 1639 if (!origin->ResourceColumnOffset().IsEmpty()) { | 1639 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); |
| 1640 column_offset = | 1640 i::Handle<i::JSFunction> function = |
| 1641 static_cast<int>(origin->ResourceColumnOffset()->Value()); | 1641 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( |
| 1642 } | 1642 function_info, obj->GetIsolate()->global_context()); |
| 1643 if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) { | 1643 return ToApiHandle<Script>(function); |
| 1644 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | |
| 1645 is_shared_cross_origin = | |
| 1646 origin->ResourceIsSharedCrossOrigin() == v8::True(v8_isolate); | |
| 1647 } | |
| 1648 } | |
| 1649 EXCEPTION_PREAMBLE(isolate); | |
| 1650 i::ScriptDataImpl* pre_data_impl = | |
| 1651 static_cast<i::ScriptDataImpl*>(pre_data); | |
| 1652 // We assert that the pre-data is sane, even though we can actually | |
| 1653 // handle it if it turns out not to be in release mode. | |
| 1654 ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); | |
| 1655 // If the pre-data isn't sane we simply ignore it | |
| 1656 if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { | |
| 1657 pre_data_impl = NULL; | |
| 1658 } | |
| 1659 i::Handle<i::SharedFunctionInfo> result = | |
| 1660 i::Compiler::CompileScript(str, | |
| 1661 name_obj, | |
| 1662 line_offset, | |
| 1663 column_offset, | |
| 1664 is_shared_cross_origin, | |
| 1665 isolate->global_context(), | |
| 1666 NULL, | |
| 1667 pre_data_impl, | |
| 1668 Utils::OpenHandle(*script_data, true), | |
| 1669 i::NOT_NATIVES_CODE); | |
| 1670 has_pending_exception = result.is_null(); | |
| 1671 EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); | |
| 1672 raw_result = *result; | |
| 1673 } | |
| 1674 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | |
| 1675 return ToApiHandle<Script>(result); | |
| 1676 } | 1644 } |
| 1677 | 1645 |
| 1678 | 1646 |
| 1679 Local<Script> Script::New(v8::Handle<String> source, | 1647 int UnboundScript::GetId() { |
| 1680 v8::Handle<Value> file_name) { | 1648 i::Handle<i::HeapObject> obj = |
| 1681 ScriptOrigin origin(file_name); | 1649 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1682 return New(source, &origin); | 1650 i::Isolate* isolate = obj->GetIsolate(); |
| 1651 ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1); |
| 1652 LOG_API(isolate, "v8::UnboundScript::GetId"); |
| 1653 { |
| 1654 i::HandleScope scope(isolate); |
| 1655 i::Handle<i::SharedFunctionInfo> function_info( |
| 1656 i::SharedFunctionInfo::cast(*obj)); |
| 1657 i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
| 1658 return script->id()->value(); |
| 1659 } |
| 1683 } | 1660 } |
| 1684 | 1661 |
| 1685 | 1662 |
| 1686 Local<Script> Script::Compile(v8::Handle<String> source, | 1663 int UnboundScript::GetLineNumber(int code_pos) { |
| 1687 v8::ScriptOrigin* origin, | 1664 i::Handle<i::HeapObject> obj = |
| 1688 v8::ScriptData* pre_data, | 1665 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1689 v8::Handle<String> script_data) { | 1666 i::Isolate* isolate = obj->GetIsolate(); |
| 1690 i::Handle<i::String> str = Utils::OpenHandle(*source); | 1667 ON_BAILOUT(isolate, "v8::UnboundScript::GetLineNumber()", return -1); |
| 1691 i::Isolate* isolate = str->GetIsolate(); | 1668 LOG_API(isolate, "UnboundScript::GetLineNumber"); |
| 1692 ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); | 1669 if (obj->IsScript()) { |
| 1693 LOG_API(isolate, "Script::Compile"); | 1670 i::Handle<i::Script> script(i::Script::cast(*obj)); |
| 1694 ENTER_V8(isolate); | 1671 return i::GetScriptLineNumber(script, code_pos); |
| 1695 Local<Script> generic = New(source, origin, pre_data, script_data); | 1672 } else { |
| 1696 if (generic.IsEmpty()) | 1673 return -1; |
| 1697 return generic; | 1674 } |
| 1698 i::Handle<i::Object> obj = Utils::OpenHandle(*generic); | |
| 1699 i::Handle<i::SharedFunctionInfo> function = | |
| 1700 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); | |
| 1701 i::Handle<i::JSFunction> result = | |
| 1702 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 1703 function, | |
| 1704 isolate->global_context()); | |
| 1705 return ToApiHandle<Script>(result); | |
| 1706 } | 1675 } |
| 1707 | 1676 |
| 1708 | 1677 |
| 1709 Local<Script> Script::Compile(v8::Handle<String> source, | 1678 Handle<Value> UnboundScript::GetScriptName() { |
| 1710 v8::Handle<Value> file_name, | 1679 i::Handle<i::HeapObject> obj = |
| 1711 v8::Handle<String> script_data) { | 1680 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1712 ScriptOrigin origin(file_name); | 1681 i::Isolate* isolate = obj->GetIsolate(); |
| 1713 return Compile(source, &origin, 0, script_data); | 1682 ON_BAILOUT(isolate, "v8::UnboundScript::GetName()", |
| 1683 return Handle<String>()); |
| 1684 LOG_API(isolate, "UnboundScript::GetName"); |
| 1685 if (obj->IsScript()) { |
| 1686 i::Object* name = i::Script::cast(*obj)->name(); |
| 1687 return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); |
| 1688 } else { |
| 1689 return Handle<String>(); |
| 1690 } |
| 1714 } | 1691 } |
| 1715 | 1692 |
| 1716 | 1693 |
| 1717 Local<Value> Script::Run() { | 1694 Local<Value> Script::Run() { |
| 1718 // If execution is terminating, Compile(script)->Run() requires this check. | 1695 // If execution is terminating, Compile(..)->Run() requires this |
| 1696 // check. |
| 1719 if (this == NULL) return Local<Value>(); | 1697 if (this == NULL) return Local<Value>(); |
| 1720 i::Handle<i::HeapObject> obj = | 1698 i::Handle<i::HeapObject> obj = |
| 1721 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1699 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1722 i::Isolate* isolate = obj->GetIsolate(); | 1700 i::Isolate* isolate = obj->GetIsolate(); |
| 1723 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); | 1701 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1724 LOG_API(isolate, "Script::Run"); | 1702 LOG_API(isolate, "Script::Run"); |
| 1725 ENTER_V8(isolate); | 1703 ENTER_V8(isolate); |
| 1726 i::Logger::TimerEventScope timer_scope( | 1704 i::Logger::TimerEventScope timer_scope( |
| 1727 isolate, i::Logger::TimerEventScope::v8_execute); | 1705 isolate, i::Logger::TimerEventScope::v8_execute); |
| 1728 i::Object* raw_result = NULL; | 1706 i::Object* raw_result = NULL; |
| 1729 { | 1707 { |
| 1730 i::HandleScope scope(isolate); | 1708 i::HandleScope scope(isolate); |
| 1731 i::Handle<i::JSFunction> fun; | 1709 i::Handle<i::JSFunction> fun = |
| 1732 if (obj->IsSharedFunctionInfo()) { | 1710 i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
| 1733 i::Handle<i::SharedFunctionInfo> | |
| 1734 function_info(i::SharedFunctionInfo::cast(*obj), isolate); | |
| 1735 fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 1736 function_info, isolate->global_context()); | |
| 1737 } else { | |
| 1738 fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); | |
| 1739 } | |
| 1740 EXCEPTION_PREAMBLE(isolate); | 1711 EXCEPTION_PREAMBLE(isolate); |
| 1741 i::Handle<i::Object> receiver( | 1712 i::Handle<i::Object> receiver( |
| 1742 isolate->context()->global_proxy(), isolate); | 1713 isolate->context()->global_proxy(), isolate); |
| 1743 i::Handle<i::Object> result = i::Execution::Call( | 1714 i::Handle<i::Object> result = i::Execution::Call( |
| 1744 isolate, fun, receiver, 0, NULL, &has_pending_exception); | 1715 isolate, fun, receiver, 0, NULL, &has_pending_exception); |
| 1745 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); | 1716 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
| 1746 raw_result = *result; | 1717 raw_result = *result; |
| 1747 } | 1718 } |
| 1748 i::Handle<i::Object> result(raw_result, isolate); | 1719 i::Handle<i::Object> result(raw_result, isolate); |
| 1749 return Utils::ToLocal(result); | 1720 return Utils::ToLocal(result); |
| 1750 } | 1721 } |
| 1751 | 1722 |
| 1752 | 1723 |
| 1753 static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { | 1724 Local<UnboundScript> Script::GetUnboundScript() { |
| 1754 i::Handle<i::Object> obj = Utils::OpenHandle(script); | 1725 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1755 i::Handle<i::SharedFunctionInfo> result; | 1726 return ToApiHandle<UnboundScript>( |
| 1756 if (obj->IsSharedFunctionInfo()) { | 1727 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); |
| 1757 result = | |
| 1758 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); | |
| 1759 } else { | |
| 1760 result = | |
| 1761 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); | |
| 1762 } | |
| 1763 return result; | |
| 1764 } | 1728 } |
| 1765 | 1729 |
| 1766 | 1730 |
| 1767 int Script::GetId() { | 1731 Local<UnboundScript> ScriptCompiler::CompileUnbound( |
| 1768 i::Handle<i::HeapObject> obj = | 1732 Isolate* v8_isolate, |
| 1769 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1733 const Source& source, |
| 1770 i::Isolate* isolate = obj->GetIsolate(); | 1734 CompileOptions options) { |
| 1771 ON_BAILOUT(isolate, "v8::Script::Id()", return -1); | 1735 // FIXME(marja): This function cannot yet create cached data (if options | |
| 1772 LOG_API(isolate, "Script::Id"); | 1736 // produce_data_to_cache is true), but the PreCompile function is still there |
| 1773 { | 1737 // for doing it. |
| 1774 i::HandleScope scope(isolate); | 1738 i::Handle<i::String> str = Utils::OpenHandle(*(source.source_string)); |
| 1775 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); | 1739 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 1776 i::Handle<i::Script> script(i::Script::cast(function_info->script())); | 1740 ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", |
| 1777 return script->id()->value(); | 1741 return Local<UnboundScript>()); |
| 1742 LOG_API(isolate, "ScriptCompiler::CompileUnbound"); |
| 1743 ENTER_V8(isolate); |
| 1744 i::SharedFunctionInfo* raw_result = NULL; |
| 1745 { i::HandleScope scope(isolate); |
| 1746 i::Handle<i::Object> name_obj; |
| 1747 int line_offset = 0; |
| 1748 int column_offset = 0; |
| 1749 bool is_shared_cross_origin = false; |
| 1750 if (!source.resource_name.IsEmpty()) { |
| 1751 name_obj = Utils::OpenHandle(*source.resource_name); |
| 1752 } |
| 1753 if (!source.resource_line_offset.IsEmpty()) { |
| 1754 line_offset = static_cast<int>(source.resource_line_offset->Value()); |
| 1755 } |
| 1756 if (!source.resource_column_offset.IsEmpty()) { |
| 1757 column_offset = |
| 1758 static_cast<int>(source.resource_column_offset->Value()); |
| 1759 } |
| 1760 if (!source.resource_is_shared_cross_origin.IsEmpty()) { |
| 1761 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 1762 is_shared_cross_origin = |
| 1763 source.resource_is_shared_cross_origin == v8::True(v8_isolate); |
| 1764 } |
| 1765 EXCEPTION_PREAMBLE(isolate); |
| 1766 i::ScriptDataImpl* pre_data_impl = NULL; |
| 1767 if (source.cached_data.data) { |
| 1768 // FIXME(marja): Make compiler use CachedData directly. |
| 1769 pre_data_impl = static_cast<i::ScriptDataImpl*>(ScriptData::New( |
| 1770 reinterpret_cast<const char*>(source.cached_data.data), |
| 1771 source.cached_data.length)); |
| 1772 } |
| 1773 // We assert that the pre-data is sane, even though we can actually |
| 1774 // handle it if it turns out not to be in release mode. |
| 1775 ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
| 1776 // If the pre-data isn't sane we simply ignore it |
| 1777 if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1778 delete pre_data_impl; |
| 1779 pre_data_impl = NULL; |
| 1780 } |
| 1781 i::Handle<i::SharedFunctionInfo> result = |
| 1782 i::Compiler::CompileScript(str, |
| 1783 name_obj, |
| 1784 line_offset, |
| 1785 column_offset, |
| 1786 is_shared_cross_origin, |
| 1787 isolate->global_context(), |
| 1788 NULL, |
| 1789 pre_data_impl, |
| 1790 i::NOT_NATIVES_CODE); |
| 1791 has_pending_exception = result.is_null(); |
| 1792 EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
| 1793 raw_result = *result; |
| 1794 delete pre_data_impl; |
| 1778 } | 1795 } |
| 1796 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
| 1797 return ToApiHandle<UnboundScript>(result); |
| 1779 } | 1798 } |
| 1780 | 1799 |
| 1781 | 1800 |
| 1782 int Script::GetLineNumber(int code_pos) { | 1801 Local<Script> ScriptCompiler::Compile( |
| 1783 i::Handle<i::HeapObject> obj = | 1802 Isolate* v8_isolate, |
| 1784 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1803 const Source& source, |
| 1785 i::Isolate* isolate = obj->GetIsolate(); | 1804 CompileOptions options) { |
| 1786 ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1); | 1805 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 1787 LOG_API(isolate, "Script::GetLineNumber"); | 1806 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", |
| 1788 if (obj->IsScript()) { | 1807 return Local<Script>()); |
| 1789 i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj)); | 1808 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); |
| 1790 return i::GetScriptLineNumber(script, code_pos); | 1809 ENTER_V8(isolate); |
| 1791 } else { | 1810 Local<UnboundScript> generic = |
| 1792 return -1; | 1811 CompileUnbound(v8_isolate, source, options); |
| 1793 } | 1812 if (generic.IsEmpty()) return Local<Script>(); |
| 1813 return generic->BindToCurrentContext(); |
| 1794 } | 1814 } |
| 1795 | 1815 |
| 1796 | 1816 |
| 1797 Handle<Value> Script::GetScriptName() { | 1817 Local<Script> Script::Compile(v8::Handle<String> source, |
| 1798 i::Handle<i::HeapObject> obj = | 1818 v8::ScriptOrigin* origin, |
| 1799 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1819 ScriptData* script_data) { |
| 1800 i::Isolate* isolate = obj->GetIsolate(); | 1820 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1801 ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>()); | 1821 ScriptCompiler::CachedData cached_data; |
| 1802 LOG_API(isolate, "Script::GetName"); | 1822 if (script_data) { |
| 1803 if (obj->IsScript()) { | 1823 cached_data = ScriptCompiler::CachedData( |
| 1804 i::Object* name = i::Script::cast(*obj)->name(); | 1824 reinterpret_cast<const uint8_t*>(script_data->Data()), |
| 1805 return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); | 1825 script_data->Length()); |
| 1806 } else { | |
| 1807 return Handle<String>(); | |
| 1808 } | 1826 } |
| 1827 if (origin) { |
| 1828 return ScriptCompiler::Compile( |
| 1829 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), |
| 1830 ScriptCompiler::Source(source, *origin, cached_data)); |
| 1831 } |
| 1832 return ScriptCompiler::Compile( |
| 1833 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), |
| 1834 ScriptCompiler::Source(source, cached_data)); |
| 1809 } | 1835 } |
| 1810 | 1836 |
| 1811 | 1837 |
| 1812 void Script::SetData(v8::Handle<String> data) { | 1838 Local<Script> Script::Compile(v8::Handle<String> source, |
| 1813 i::Handle<i::HeapObject> obj = | 1839 v8::Handle<String> file_name) { |
| 1814 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1840 ScriptOrigin origin(file_name); |
| 1815 i::Isolate* isolate = obj->GetIsolate(); | 1841 return Compile(source, &origin); |
| 1816 ON_BAILOUT(isolate, "v8::Script::SetData()", return); | |
| 1817 LOG_API(isolate, "Script::SetData"); | |
| 1818 { | |
| 1819 i::HandleScope scope(isolate); | |
| 1820 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); | |
| 1821 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); | |
| 1822 i::Handle<i::Script> script(i::Script::cast(function_info->script())); | |
| 1823 script->set_data(*raw_data); | |
| 1824 } | |
| 1825 } | 1842 } |
| 1826 | 1843 |
| 1827 | 1844 |
| 1828 // --- E x c e p t i o n s --- | 1845 // --- E x c e p t i o n s --- |
| 1829 | 1846 |
| 1830 | 1847 |
| 1831 v8::TryCatch::TryCatch() | 1848 v8::TryCatch::TryCatch() |
| 1832 : isolate_(i::Isolate::Current()), | 1849 : isolate_(i::Isolate::Current()), |
| 1833 next_(isolate_->try_catch_handler_address()), | 1850 next_(isolate_->try_catch_handler_address()), |
| 1834 is_verbose_(false), | 1851 is_verbose_(false), |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 // Return this.script.name. | 1990 // Return this.script.name. |
| 1974 i::Handle<i::JSValue> script = | 1991 i::Handle<i::JSValue> script = |
| 1975 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), | 1992 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 1976 isolate)); | 1993 isolate)); |
| 1977 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(), | 1994 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(), |
| 1978 isolate); | 1995 isolate); |
| 1979 return scope.Escape(Utils::ToLocal(resource_name)); | 1996 return scope.Escape(Utils::ToLocal(resource_name)); |
| 1980 } | 1997 } |
| 1981 | 1998 |
| 1982 | 1999 |
| 1983 v8::Handle<Value> Message::GetScriptData() const { | |
| 1984 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 1985 ENTER_V8(isolate); | |
| 1986 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | |
| 1987 i::Handle<i::JSMessageObject> message = | |
| 1988 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | |
| 1989 // Return this.script.data. | |
| 1990 i::Handle<i::JSValue> script = | |
| 1991 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), | |
| 1992 isolate)); | |
| 1993 i::Handle<i::Object> data(i::Script::cast(script->value())->data(), isolate); | |
| 1994 return scope.Escape(Utils::ToLocal(data)); | |
| 1995 } | |
| 1996 | |
| 1997 | |
| 1998 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { | 2000 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
| 1999 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2001 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2000 ENTER_V8(isolate); | 2002 ENTER_V8(isolate); |
| 2001 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2003 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2002 i::Handle<i::JSMessageObject> message = | 2004 i::Handle<i::JSMessageObject> message = |
| 2003 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2005 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2004 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); | 2006 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
| 2005 if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); | 2007 if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 2006 i::Handle<i::JSArray> stackTrace = | 2008 i::Handle<i::JSArray> stackTrace = |
| 2007 i::Handle<i::JSArray>::cast(stackFramesObj); | 2009 i::Handle<i::JSArray>::cast(stackFramesObj); |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2679 | 2681 |
| 2680 | 2682 |
| 2681 void v8::Array::CheckCast(Value* that) { | 2683 void v8::Array::CheckCast(Value* that) { |
| 2682 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2684 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2683 Utils::ApiCheck(obj->IsJSArray(), | 2685 Utils::ApiCheck(obj->IsJSArray(), |
| 2684 "v8::Array::Cast()", | 2686 "v8::Array::Cast()", |
| 2685 "Could not convert to array"); | 2687 "Could not convert to array"); |
| 2686 } | 2688 } |
| 2687 | 2689 |
| 2688 | 2690 |
| 2691 void v8::Promise::CheckCast(Value* that) { |
| 2692 Utils::ApiCheck(that->IsPromise(), |
| 2693 "v8::Promise::Cast()", |
| 2694 "Could not convert to promise"); |
| 2695 } |
| 2696 |
| 2697 |
| 2689 void v8::ArrayBuffer::CheckCast(Value* that) { | 2698 void v8::ArrayBuffer::CheckCast(Value* that) { |
| 2690 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2699 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2691 Utils::ApiCheck(obj->IsJSArrayBuffer(), | 2700 Utils::ApiCheck(obj->IsJSArrayBuffer(), |
| 2692 "v8::ArrayBuffer::Cast()", | 2701 "v8::ArrayBuffer::Cast()", |
| 2693 "Could not convert to ArrayBuffer"); | 2702 "Could not convert to ArrayBuffer"); |
| 2694 } | 2703 } |
| 2695 | 2704 |
| 2696 | 2705 |
| 2697 void v8::ArrayBufferView::CheckCast(Value* that) { | 2706 void v8::ArrayBufferView::CheckCast(Value* that) { |
| 2698 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2707 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3016 i::Handle<i::Object> self = Utils::OpenHandle(this); | 3025 i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 3017 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); | 3026 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3018 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); | 3027 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
| 3019 EXCEPTION_PREAMBLE(isolate); | 3028 EXCEPTION_PREAMBLE(isolate); |
| 3020 i::Handle<i::Object> obj = i::Runtime::SetObjectProperty( | 3029 i::Handle<i::Object> obj = i::Runtime::SetObjectProperty( |
| 3021 isolate, | 3030 isolate, |
| 3022 self, | 3031 self, |
| 3023 key_obj, | 3032 key_obj, |
| 3024 value_obj, | 3033 value_obj, |
| 3025 static_cast<PropertyAttributes>(attribs), | 3034 static_cast<PropertyAttributes>(attribs), |
| 3026 i::kNonStrictMode); | 3035 i::SLOPPY); |
| 3027 has_pending_exception = obj.is_null(); | 3036 has_pending_exception = obj.is_null(); |
| 3028 EXCEPTION_BAILOUT_CHECK(isolate, false); | 3037 EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 3029 return true; | 3038 return true; |
| 3030 } | 3039 } |
| 3031 | 3040 |
| 3032 | 3041 |
| 3033 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { | 3042 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
| 3034 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3043 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3035 ON_BAILOUT(isolate, "v8::Object::Set()", return false); | 3044 ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
| 3036 ENTER_V8(isolate); | 3045 ENTER_V8(isolate); |
| 3037 i::HandleScope scope(isolate); | 3046 i::HandleScope scope(isolate); |
| 3038 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3047 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3039 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); | 3048 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
| 3040 EXCEPTION_PREAMBLE(isolate); | 3049 EXCEPTION_PREAMBLE(isolate); |
| 3041 i::Handle<i::Object> obj = i::JSObject::SetElement( | 3050 i::Handle<i::Object> obj = i::JSObject::SetElement( |
| 3042 self, | 3051 self, |
| 3043 index, | 3052 index, |
| 3044 value_obj, | 3053 value_obj, |
| 3045 NONE, | 3054 NONE, |
| 3046 i::kNonStrictMode); | 3055 i::SLOPPY); |
| 3047 has_pending_exception = obj.is_null(); | 3056 has_pending_exception = obj.is_null(); |
| 3048 EXCEPTION_BAILOUT_CHECK(isolate, false); | 3057 EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 3049 return true; | 3058 return true; |
| 3050 } | 3059 } |
| 3051 | 3060 |
| 3052 | 3061 |
| 3053 bool v8::Object::ForceSet(v8::Handle<Value> key, | 3062 bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 3054 v8::Handle<Value> value, | 3063 v8::Handle<Value> value, |
| 3055 v8::PropertyAttribute attribs) { | 3064 v8::PropertyAttribute attribs) { |
| 3056 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3065 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3141 ENTER_V8(isolate); | 3150 ENTER_V8(isolate); |
| 3142 i::HandleScope scope(isolate); | 3151 i::HandleScope scope(isolate); |
| 3143 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3152 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3144 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); | 3153 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3145 if (!key_obj->IsName()) { | 3154 if (!key_obj->IsName()) { |
| 3146 EXCEPTION_PREAMBLE(isolate); | 3155 EXCEPTION_PREAMBLE(isolate); |
| 3147 key_obj = i::Execution::ToString(isolate, key_obj, &has_pending_exception); | 3156 key_obj = i::Execution::ToString(isolate, key_obj, &has_pending_exception); |
| 3148 EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); | 3157 EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 3149 } | 3158 } |
| 3150 i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj); | 3159 i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj); |
| 3151 PropertyAttributes result = self->GetPropertyAttribute(*key_name); | 3160 PropertyAttributes result = |
| 3161 i::JSReceiver::GetPropertyAttribute(self, key_name); |
| 3152 if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); | 3162 if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 3153 return static_cast<PropertyAttribute>(result); | 3163 return static_cast<PropertyAttribute>(result); |
| 3154 } | 3164 } |
| 3155 | 3165 |
| 3156 | 3166 |
| 3157 Local<Value> v8::Object::GetPrototype() { | 3167 Local<Value> v8::Object::GetPrototype() { |
| 3158 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3168 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3159 ON_BAILOUT(isolate, "v8::Object::GetPrototype()", | 3169 ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
| 3160 return Local<v8::Value>()); | 3170 return Local<v8::Value>()); |
| 3161 ENTER_V8(isolate); | 3171 ENTER_V8(isolate); |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4049 | 4059 |
| 4050 | 4060 |
| 4051 bool Function::IsBuiltin() const { | 4061 bool Function::IsBuiltin() const { |
| 4052 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4062 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4053 return func->IsBuiltin(); | 4063 return func->IsBuiltin(); |
| 4054 } | 4064 } |
| 4055 | 4065 |
| 4056 | 4066 |
| 4057 int Function::ScriptId() const { | 4067 int Function::ScriptId() const { |
| 4058 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4068 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4059 if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId; | 4069 if (!func->shared()->script()->IsScript()) { |
| 4070 return v8::UnboundScript::kNoScriptId; |
| 4071 } |
| 4060 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); | 4072 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4061 return script->id()->value(); | 4073 return script->id()->value(); |
| 4062 } | 4074 } |
| 4063 | 4075 |
| 4064 | 4076 |
| 4065 Local<v8::Value> Function::GetBoundFunction() const { | 4077 Local<v8::Value> Function::GetBoundFunction() const { |
| 4066 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4078 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4067 if (!func->shared()->bound()) { | 4079 if (!func->shared()->bound()) { |
| 4068 return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate())); | 4080 return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate())); |
| 4069 } | 4081 } |
| (...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5646 | 5658 |
| 5647 void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { | 5659 void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { |
| 5648 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 5660 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5649 ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()", | 5661 ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
| 5650 return); | 5662 return); |
| 5651 LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification"); | 5663 LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification"); |
| 5652 ENTER_V8(i_isolate); | 5664 ENTER_V8(i_isolate); |
| 5653 | 5665 |
| 5654 i_isolate->date_cache()->ResetDateCache(); | 5666 i_isolate->date_cache()->ResetDateCache(); |
| 5655 | 5667 |
| 5656 i::HandleScope scope(i_isolate); | 5668 if (!i_isolate->eternal_handles()->Exists( |
| 5657 // Get the function ResetDateCache (defined in date.js). | 5669 i::EternalHandles::DATE_CACHE_VERSION)) { |
| 5658 i::Handle<i::String> func_name_str = | |
| 5659 i_isolate->factory()->InternalizeOneByteString( | |
| 5660 STATIC_ASCII_VECTOR("ResetDateCache")); | |
| 5661 i::MaybeObject* result = | |
| 5662 i_isolate->js_builtins_object()->GetProperty(*func_name_str); | |
| 5663 i::Object* object_func; | |
| 5664 if (!result->ToObject(&object_func)) { | |
| 5665 return; | 5670 return; |
| 5666 } | 5671 } |
| 5667 | 5672 i::Handle<i::FixedArray> date_cache_version = |
| 5668 if (object_func->IsJSFunction()) { | 5673 i::Handle<i::FixedArray>::cast(i_isolate->eternal_handles()->GetSingleton( |
| 5669 i::Handle<i::JSFunction> func = | 5674 i::EternalHandles::DATE_CACHE_VERSION)); |
| 5670 i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); | 5675 ASSERT_EQ(1, date_cache_version->length()); |
| 5671 | 5676 CHECK(date_cache_version->get(0)->IsSmi()); |
| 5672 // Call ResetDateCache(0 but expect no exceptions: | 5677 date_cache_version->set( |
| 5673 bool caught_exception = false; | 5678 0, |
| 5674 i::Execution::TryCall(func, | 5679 i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1)); |
| 5675 i_isolate->js_builtins_object(), | |
| 5676 0, | |
| 5677 NULL, | |
| 5678 &caught_exception); | |
| 5679 } | |
| 5680 } | 5680 } |
| 5681 | 5681 |
| 5682 | 5682 |
| 5683 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { | 5683 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
| 5684 i::Isolate* isolate = i::Isolate::Current(); | 5684 i::Isolate* isolate = i::Isolate::Current(); |
| 5685 uint8_t flags_buf[3]; | 5685 uint8_t flags_buf[3]; |
| 5686 int num_flags = 0; | 5686 int num_flags = 0; |
| 5687 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; | 5687 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 5688 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; | 5688 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 5689 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; | 5689 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5771 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); | 5771 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
| 5772 EXCEPTION_PREAMBLE(isolate); | 5772 EXCEPTION_PREAMBLE(isolate); |
| 5773 ENTER_V8(isolate); | 5773 ENTER_V8(isolate); |
| 5774 i::Handle<i::JSObject> result = i::JSObject::Copy(paragon_handle); | 5774 i::Handle<i::JSObject> result = i::JSObject::Copy(paragon_handle); |
| 5775 has_pending_exception = result.is_null(); | 5775 has_pending_exception = result.is_null(); |
| 5776 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); | 5776 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
| 5777 return Utils::ToLocal(result); | 5777 return Utils::ToLocal(result); |
| 5778 } | 5778 } |
| 5779 | 5779 |
| 5780 | 5780 |
| 5781 bool Value::IsPromise() const { |
| 5782 i::Handle<i::Object> val = Utils::OpenHandle(this); |
| 5783 if (!i::FLAG_harmony_promises || !val->IsJSObject()) return false; |
| 5784 i::Handle<i::JSObject> obj = i::Handle<i::JSObject>::cast(val); |
| 5785 i::Isolate* isolate = obj->GetIsolate(); |
| 5786 LOG_API(isolate, "IsPromise"); |
| 5787 ENTER_V8(isolate); |
| 5788 EXCEPTION_PREAMBLE(isolate); |
| 5789 i::Handle<i::Object> argv[] = { obj }; |
| 5790 i::Handle<i::Object> b = i::Execution::Call( |
| 5791 isolate, |
| 5792 handle( |
| 5793 isolate->context()->global_object()->native_context()->is_promise()), |
| 5794 isolate->factory()->undefined_value(), |
| 5795 ARRAY_SIZE(argv), argv, |
| 5796 &has_pending_exception, |
| 5797 false); |
| 5798 EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 5799 return b->BooleanValue(); |
| 5800 } |
| 5801 |
| 5802 |
| 5803 Local<Promise> Promise::New(Isolate* v8_isolate) { |
| 5804 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 5805 LOG_API(isolate, "Promise::New"); |
| 5806 ENTER_V8(isolate); |
| 5807 EXCEPTION_PREAMBLE(isolate); |
| 5808 i::Handle<i::Object> result = i::Execution::Call( |
| 5809 isolate, |
| 5810 handle(isolate->context()->global_object()->native_context()-> |
| 5811 promise_create()), |
| 5812 isolate->factory()->undefined_value(), |
| 5813 0, NULL, |
| 5814 &has_pending_exception, |
| 5815 false); |
| 5816 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); |
| 5817 return Local<Promise>::Cast(Utils::ToLocal(result)); |
| 5818 } |
| 5819 |
| 5820 |
| 5821 void Promise::Resolve(Handle<Value> value) { |
| 5822 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); |
| 5823 i::Isolate* isolate = promise->GetIsolate(); |
| 5824 LOG_API(isolate, "Promise::Resolve"); |
| 5825 ENTER_V8(isolate); |
| 5826 EXCEPTION_PREAMBLE(isolate); |
| 5827 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; |
| 5828 i::Execution::Call( |
| 5829 isolate, |
| 5830 handle(isolate->context()->global_object()->native_context()-> |
| 5831 promise_resolve()), |
| 5832 isolate->factory()->undefined_value(), |
| 5833 ARRAY_SIZE(argv), argv, |
| 5834 &has_pending_exception, |
| 5835 false); |
| 5836 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); |
| 5837 } |
| 5838 |
| 5839 |
| 5840 void Promise::Reject(Handle<Value> value) { |
| 5841 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); |
| 5842 i::Isolate* isolate = promise->GetIsolate(); |
| 5843 LOG_API(isolate, "Promise::Reject"); |
| 5844 ENTER_V8(isolate); |
| 5845 EXCEPTION_PREAMBLE(isolate); |
| 5846 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; |
| 5847 i::Execution::Call( |
| 5848 isolate, |
| 5849 handle(isolate->context()->global_object()->native_context()-> |
| 5850 promise_reject()), |
| 5851 isolate->factory()->undefined_value(), |
| 5852 ARRAY_SIZE(argv), argv, |
| 5853 &has_pending_exception, |
| 5854 false); |
| 5855 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); |
| 5856 } |
| 5857 |
| 5858 |
| 5859 Local<Promise> Promise::Chain(Handle<Function> handler) { |
| 5860 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); |
| 5861 i::Isolate* isolate = promise->GetIsolate(); |
| 5862 LOG_API(isolate, "Promise::Chain"); |
| 5863 ENTER_V8(isolate); |
| 5864 EXCEPTION_PREAMBLE(isolate); |
| 5865 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; |
| 5866 i::Handle<i::Object> result = i::Execution::Call( |
| 5867 isolate, |
| 5868 handle(isolate->context()->global_object()->native_context()-> |
| 5869 promise_chain()), |
| 5870 promise, |
| 5871 ARRAY_SIZE(argv), argv, |
| 5872 &has_pending_exception, |
| 5873 false); |
| 5874 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); |
| 5875 return Local<Promise>::Cast(Utils::ToLocal(result)); |
| 5876 } |
| 5877 |
| 5878 |
| 5879 Local<Promise> Promise::Catch(Handle<Function> handler) { |
| 5880 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); |
| 5881 i::Isolate* isolate = promise->GetIsolate(); |
| 5882 LOG_API(isolate, "Promise::Catch"); |
| 5883 ENTER_V8(isolate); |
| 5884 EXCEPTION_PREAMBLE(isolate); |
| 5885 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; |
| 5886 i::Handle<i::Object> result = i::Execution::Call( |
| 5887 isolate, |
| 5888 handle(isolate->context()->global_object()->native_context()-> |
| 5889 promise_catch()), |
| 5890 promise, |
| 5891 ARRAY_SIZE(argv), argv, |
| 5892 &has_pending_exception, |
| 5893 false); |
| 5894 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); |
| 5895 return Local<Promise>::Cast(Utils::ToLocal(result)); |
| 5896 } |
| 5897 |
| 5898 |
| 5781 bool v8::ArrayBuffer::IsExternal() const { | 5899 bool v8::ArrayBuffer::IsExternal() const { |
| 5782 return Utils::OpenHandle(this)->is_external(); | 5900 return Utils::OpenHandle(this)->is_external(); |
| 5783 } | 5901 } |
| 5784 | 5902 |
| 5785 | 5903 |
| 5786 v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { | 5904 v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { |
| 5787 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); | 5905 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5788 Utils::ApiCheck(!obj->is_external(), | 5906 Utils::ApiCheck(!obj->is_external(), |
| 5789 "v8::ArrayBuffer::Externalize", | 5907 "v8::ArrayBuffer::Externalize", |
| 5790 "ArrayBuffer already externalized"); | 5908 "ArrayBuffer already externalized"); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5977 if (length == -1) length = i::StrLength(data); | 6095 if (length == -1) length = i::StrLength(data); |
| 5978 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8( | 6096 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8( |
| 5979 i::Vector<const char>(data, length)); | 6097 i::Vector<const char>(data, length)); |
| 5980 result->set_name(*name); | 6098 result->set_name(*name); |
| 5981 } | 6099 } |
| 5982 return Utils::ToLocal(result); | 6100 return Utils::ToLocal(result); |
| 5983 } | 6101 } |
| 5984 | 6102 |
| 5985 | 6103 |
| 5986 Local<Private> v8::Private::New( | 6104 Local<Private> v8::Private::New( |
| 5987 Isolate* isolate, const char* data, int length) { | 6105 Isolate* isolate, Local<String> name) { |
| 5988 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6106 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5989 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()"); | 6107 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()"); |
| 5990 LOG_API(i_isolate, "Private::New()"); | 6108 LOG_API(i_isolate, "Private::New()"); |
| 5991 ENTER_V8(i_isolate); | 6109 ENTER_V8(i_isolate); |
| 5992 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); | 6110 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
| 5993 if (data != NULL) { | 6111 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); |
| 5994 if (length == -1) length = i::StrLength(data); | |
| 5995 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8( | |
| 5996 i::Vector<const char>(data, length)); | |
| 5997 symbol->set_name(*name); | |
| 5998 } | |
| 5999 Local<Symbol> result = Utils::ToLocal(symbol); | 6112 Local<Symbol> result = Utils::ToLocal(symbol); |
| 6000 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); | 6113 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); |
| 6001 } | 6114 } |
| 6002 | 6115 |
| 6003 | 6116 |
| 6004 Local<Number> v8::Number::New(Isolate* isolate, double value) { | 6117 Local<Number> v8::Number::New(Isolate* isolate, double value) { |
| 6005 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6118 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6006 ASSERT(internal_isolate->IsInitialized()); | 6119 ASSERT(internal_isolate->IsInitialized()); |
| 6007 if (std::isnan(value)) { | 6120 if (std::isnan(value)) { |
| 6008 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | 6121 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6414 i::Heap* heap = isolate->heap(); | 6527 i::Heap* heap = isolate->heap(); |
| 6415 heap_statistics->total_heap_size_ = heap->CommittedMemory(); | 6528 heap_statistics->total_heap_size_ = heap->CommittedMemory(); |
| 6416 heap_statistics->total_heap_size_executable_ = | 6529 heap_statistics->total_heap_size_executable_ = |
| 6417 heap->CommittedMemoryExecutable(); | 6530 heap->CommittedMemoryExecutable(); |
| 6418 heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory(); | 6531 heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory(); |
| 6419 heap_statistics->used_heap_size_ = heap->SizeOfObjects(); | 6532 heap_statistics->used_heap_size_ = heap->SizeOfObjects(); |
| 6420 heap_statistics->heap_size_limit_ = heap->MaxReserved(); | 6533 heap_statistics->heap_size_limit_ = heap->MaxReserved(); |
| 6421 } | 6534 } |
| 6422 | 6535 |
| 6423 | 6536 |
| 6537 void Isolate::SetEventLogger(LogEventCallback that) { |
| 6538 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6539 isolate->set_event_logger(that); |
| 6540 } |
| 6541 |
| 6424 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) | 6542 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 6425 : str_(NULL), length_(0) { | 6543 : str_(NULL), length_(0) { |
| 6426 i::Isolate* isolate = i::Isolate::Current(); | 6544 i::Isolate* isolate = i::Isolate::Current(); |
| 6427 if (obj.IsEmpty()) return; | 6545 if (obj.IsEmpty()) return; |
| 6428 ENTER_V8(isolate); | 6546 ENTER_V8(isolate); |
| 6429 i::HandleScope scope(isolate); | 6547 i::HandleScope scope(isolate); |
| 6430 TryCatch try_catch; | 6548 TryCatch try_catch; |
| 6431 Handle<String> str = obj->ToString(); | 6549 Handle<String> str = obj->ToString(); |
| 6432 if (str.IsEmpty()) return; | 6550 if (str.IsEmpty()) return; |
| 6433 i::Handle<i::String> i_str = Utils::OpenHandle(*str); | 6551 i::Handle<i::String> i_str = Utils::OpenHandle(*str); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6870 } | 6988 } |
| 6871 | 6989 |
| 6872 | 6990 |
| 6873 void CpuProfiler::SetSamplingInterval(int us) { | 6991 void CpuProfiler::SetSamplingInterval(int us) { |
| 6874 ASSERT(us >= 0); | 6992 ASSERT(us >= 0); |
| 6875 return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( | 6993 return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( |
| 6876 i::TimeDelta::FromMicroseconds(us)); | 6994 i::TimeDelta::FromMicroseconds(us)); |
| 6877 } | 6995 } |
| 6878 | 6996 |
| 6879 | 6997 |
| 6880 void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) { | 6998 void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) { |
| 6881 reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( | 6999 reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( |
| 6882 *Utils::OpenHandle(*title), record_samples); | 7000 *Utils::OpenHandle(*title), record_samples); |
| 6883 } | 7001 } |
| 6884 | 7002 |
| 6885 | 7003 |
| 6886 const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) { | 7004 void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) { |
| 6887 return reinterpret_cast<const CpuProfile*>( | 7005 StartProfiling(title, record_samples); |
| 7006 } |
| 7007 |
| 7008 |
| 7009 CpuProfile* CpuProfiler::StopProfiling(Handle<String> title) { |
| 7010 return reinterpret_cast<CpuProfile*>( |
| 6888 reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling( | 7011 reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling( |
| 6889 *Utils::OpenHandle(*title))); | 7012 *Utils::OpenHandle(*title))); |
| 6890 } | 7013 } |
| 6891 | 7014 |
| 6892 | 7015 |
| 7016 const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) { |
| 7017 return StopProfiling(title); |
| 7018 } |
| 7019 |
| 7020 |
| 6893 void CpuProfiler::SetIdle(bool is_idle) { | 7021 void CpuProfiler::SetIdle(bool is_idle) { |
| 6894 i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate(); | 7022 i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate(); |
| 6895 i::StateTag state = isolate->current_vm_state(); | 7023 i::StateTag state = isolate->current_vm_state(); |
| 6896 ASSERT(state == i::EXTERNAL || state == i::IDLE); | 7024 ASSERT(state == i::EXTERNAL || state == i::IDLE); |
| 6897 if (isolate->js_entry_sp() != NULL) return; | 7025 if (isolate->js_entry_sp() != NULL) return; |
| 6898 if (is_idle) { | 7026 if (is_idle) { |
| 6899 isolate->set_current_vm_state(i::IDLE); | 7027 isolate->set_current_vm_state(i::IDLE); |
| 6900 } else if (state == i::IDLE) { | 7028 } else if (state == i::IDLE) { |
| 6901 isolate->set_current_vm_state(i::EXTERNAL); | 7029 isolate->set_current_vm_state(i::EXTERNAL); |
| 6902 } | 7030 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7377 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7505 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7378 Address callback_address = | 7506 Address callback_address = |
| 7379 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7507 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7380 VMState<EXTERNAL> state(isolate); | 7508 VMState<EXTERNAL> state(isolate); |
| 7381 ExternalCallbackScope call_scope(isolate, callback_address); | 7509 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7382 callback(info); | 7510 callback(info); |
| 7383 } | 7511 } |
| 7384 | 7512 |
| 7385 | 7513 |
| 7386 } } // namespace v8::internal | 7514 } } // namespace v8::internal |
| OLD | NEW |