Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1381)

Side by Side Diff: src/api.cc

Issue 181543003: Proof of concept: API for doing only one parsing pass instead of first preparsing and then parsing. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased -- this applies to r19832 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/compiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ---
1615 1615
1616 1616
1617 Local<Script> Script::New(v8::Handle<String> source, 1617 Local<Script> Script::New(v8::Handle<String> source,
1618 v8::ScriptOrigin* origin, 1618 v8::ScriptOrigin* origin,
1619 v8::ScriptData* pre_data) { 1619 v8::ScriptData* pre_data) {
1620 if (pre_data) {
1621 return NewAndGenerateScriptDataIfNeeded(source, origin, &pre_data);
1622 }
1623 // Don't generate ScriptData; we're not going to pass it to the caller.
1624 return NewAndGenerateScriptDataIfNeeded(source, origin, NULL);
1625 }
1626
1627
1628 Local<Script> Script::NewAndGenerateScriptDataIfNeeded(
1629 v8::Handle<String> source, v8::ScriptOrigin* origin,
1630 v8::ScriptData** pre_data) {
1631 // pre_data == NULL: we don't have ScriptData and we don't want to.
1632 // pre_data != NULL and *pre_data == NULL: we don't have ScriptData yet, but
1633 // we want it to be produced
1634 // pre_data != NULL and *pre_data != NULL; we already have ScriptData and it
1635 // should be used when parsing.
1620 i::Handle<i::String> str = Utils::OpenHandle(*source); 1636 i::Handle<i::String> str = Utils::OpenHandle(*source);
1621 i::Isolate* isolate = str->GetIsolate(); 1637 i::Isolate* isolate = str->GetIsolate();
1622 ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); 1638 ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>());
1623 LOG_API(isolate, "Script::New"); 1639 LOG_API(isolate, "Script::New");
1624 ENTER_V8(isolate); 1640 ENTER_V8(isolate);
1625 i::SharedFunctionInfo* raw_result = NULL; 1641 i::SharedFunctionInfo* raw_result = NULL;
1626 { i::HandleScope scope(isolate); 1642 { i::HandleScope scope(isolate);
1627 i::Handle<i::Object> name_obj; 1643 i::Handle<i::Object> name_obj;
1628 int line_offset = 0; 1644 int line_offset = 0;
1629 int column_offset = 0; 1645 int column_offset = 0;
1630 bool is_shared_cross_origin = false; 1646 bool is_shared_cross_origin = false;
1631 if (origin != NULL) { 1647 if (origin != NULL) {
1632 if (!origin->ResourceName().IsEmpty()) { 1648 if (!origin->ResourceName().IsEmpty()) {
1633 name_obj = Utils::OpenHandle(*origin->ResourceName()); 1649 name_obj = Utils::OpenHandle(*origin->ResourceName());
1634 } 1650 }
1635 if (!origin->ResourceLineOffset().IsEmpty()) { 1651 if (!origin->ResourceLineOffset().IsEmpty()) {
1636 line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); 1652 line_offset = static_cast<int>(origin->ResourceLineOffset()->Value());
1637 } 1653 }
1638 if (!origin->ResourceColumnOffset().IsEmpty()) { 1654 if (!origin->ResourceColumnOffset().IsEmpty()) {
1639 column_offset = 1655 column_offset =
1640 static_cast<int>(origin->ResourceColumnOffset()->Value()); 1656 static_cast<int>(origin->ResourceColumnOffset()->Value());
1641 } 1657 }
1642 if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) { 1658 if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) {
1643 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 1659 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
1644 is_shared_cross_origin = 1660 is_shared_cross_origin =
1645 origin->ResourceIsSharedCrossOrigin() == v8::True(v8_isolate); 1661 origin->ResourceIsSharedCrossOrigin() == v8::True(v8_isolate);
1646 } 1662 }
1647 } 1663 }
1648 EXCEPTION_PREAMBLE(isolate); 1664 EXCEPTION_PREAMBLE(isolate);
1649 i::ScriptDataImpl* pre_data_impl = 1665 i::ScriptDataImpl* pre_data_impl = pre_data ?
1650 static_cast<i::ScriptDataImpl*>(pre_data); 1666 static_cast<i::ScriptDataImpl*>(*pre_data) : NULL;
1651 // We assert that the pre-data is sane, even though we can actually 1667 // We assert that the pre-data is sane, even though we can actually
1652 // handle it if it turns out not to be in release mode. 1668 // handle it if it turns out not to be in release mode.
1653 ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); 1669 ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck());
1654 // If the pre-data isn't sane we simply ignore it 1670 // If the pre-data isn't sane we simply ignore it. Careful: don't nullify
1671 // the caller's pointer, since the caller owns the invalid ScriptData.
1655 if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { 1672 if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) {
1656 pre_data_impl = NULL; 1673 pre_data_impl = NULL;
1657 } 1674 }
1658 i::Handle<i::SharedFunctionInfo> result = 1675 i::Handle<i::SharedFunctionInfo> result =
1659 i::Compiler::CompileScript(str, 1676 i::Compiler::CompileScript(str,
1660 name_obj, 1677 name_obj,
1661 line_offset, 1678 line_offset,
1662 column_offset, 1679 column_offset,
1663 is_shared_cross_origin, 1680 is_shared_cross_origin,
1664 isolate->global_context(), 1681 isolate->global_context(),
1665 NULL, 1682 NULL,
1666 pre_data_impl, 1683 pre_data ? &pre_data_impl : NULL,
1667 i::NOT_NATIVES_CODE); 1684 i::NOT_NATIVES_CODE);
1668 has_pending_exception = result.is_null(); 1685 has_pending_exception = result.is_null();
1669 EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); 1686 EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
1670 raw_result = *result; 1687 raw_result = *result;
1688 if (pre_data != NULL && *pre_data == NULL) {
1689 // Caller wanted us to generate ScriptData.
1690 *pre_data = pre_data_impl;
1691 }
1671 } 1692 }
1672 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); 1693 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1673 return ToApiHandle<Script>(result); 1694 return ToApiHandle<Script>(result);
1674 } 1695 }
1675 1696
1676 1697
1677 Local<Script> Script::New(v8::Handle<String> source, 1698 Local<Script> Script::New(v8::Handle<String> source,
1678 v8::Handle<Value> file_name) { 1699 v8::Handle<Value> file_name) {
1679 ScriptOrigin origin(file_name); 1700 ScriptOrigin origin(file_name);
1680 return New(source, &origin); 1701 return New(source, &origin);
(...skipping 15 matching lines...) Expand all
1696 i::Handle<i::SharedFunctionInfo> function = 1717 i::Handle<i::SharedFunctionInfo> function =
1697 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); 1718 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
1698 i::Handle<i::JSFunction> result = 1719 i::Handle<i::JSFunction> result =
1699 isolate->factory()->NewFunctionFromSharedFunctionInfo( 1720 isolate->factory()->NewFunctionFromSharedFunctionInfo(
1700 function, 1721 function,
1701 isolate->global_context()); 1722 isolate->global_context());
1702 return ToApiHandle<Script>(result); 1723 return ToApiHandle<Script>(result);
1703 } 1724 }
1704 1725
1705 1726
1727 Local<Script> Script::CompileAndGenerateScriptDataIfNeeded(
1728 v8::Handle<String> source, v8::ScriptOrigin* origin,
1729 v8::ScriptData** cached_data) {
1730 i::Handle<i::String> str = Utils::OpenHandle(*source);
1731 i::Isolate* isolate = str->GetIsolate();
1732 ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>());
1733 LOG_API(isolate, "Script::Compile");
1734 ENTER_V8(isolate);
1735 Local<Script> generic =
1736 NewAndGenerateScriptDataIfNeeded(source, origin, cached_data);
1737 if (generic.IsEmpty()) return generic;
1738 i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
1739 i::Handle<i::SharedFunctionInfo> function =
1740 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
1741 i::Handle<i::JSFunction> result =
1742 isolate->factory()->NewFunctionFromSharedFunctionInfo(
1743 function,
1744 isolate->global_context());
1745 return ToApiHandle<Script>(result);
1746 }
1747
1748
1706 Local<Script> Script::Compile(v8::Handle<String> source, 1749 Local<Script> Script::Compile(v8::Handle<String> source,
1707 v8::Handle<Value> file_name) { 1750 v8::Handle<Value> file_name) {
1708 ScriptOrigin origin(file_name); 1751 ScriptOrigin origin(file_name);
1709 return Compile(source, &origin); 1752 return Compile(source, &origin);
1710 } 1753 }
1711 1754
1712 1755
1713 Local<Value> Script::Run() { 1756 Local<Value> Script::Run() {
1714 // If execution is terminating, Compile(script)->Run() requires this check. 1757 // If execution is terminating, Compile(script)->Run() requires this check.
1715 if (this == NULL) return Local<Value>(); 1758 if (this == NULL) return Local<Value>();
(...skipping 5739 matching lines...) Expand 10 before | Expand all | Expand 10 after
7455 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7498 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7456 Address callback_address = 7499 Address callback_address =
7457 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7500 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7458 VMState<EXTERNAL> state(isolate); 7501 VMState<EXTERNAL> state(isolate);
7459 ExternalCallbackScope call_scope(isolate, callback_address); 7502 ExternalCallbackScope call_scope(isolate, callback_address);
7460 callback(info); 7503 callback(info);
7461 } 7504 }
7462 7505
7463 7506
7464 } } // namespace v8::internal 7507 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698