v8/src/parsing/preparse-data.cc
Adam Klein 9b51273278 Remove "calls eval" bit from ParseInfo and PreParseData
There's no reason to keep track, for a preparsed function itself,
whether that function calls eval. All that matters is that the ancestor
scopes are marked as having an inner scope which calls eval. The function
will have its "calls eval" bit persisted if/when it's fully parsed.

The only "behavioral" change in this patch is the removal of a DCHECK.

Bug: v8:6092
Change-Id: I17e396c8a265030fe0ad941707e4a97972e6650b
Reviewed-on: https://chromium-review.googlesource.com/481223
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44732}
2017-04-19 19:45:45 +00:00

88 lines
2.8 KiB
C++

// Copyright 2010 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/parsing/preparse-data.h"
#include "src/base/hashmap.h"
#include "src/base/logging.h"
#include "src/globals.h"
#include "src/objects-inl.h"
#include "src/parsing/parser.h"
#include "src/parsing/preparse-data-format.h"
namespace v8 {
namespace internal {
void ParserLogger::LogFunction(int start, int end, int num_parameters,
LanguageMode language_mode,
bool uses_super_property,
int num_inner_functions) {
function_store_.Add(start);
function_store_.Add(end);
function_store_.Add(num_parameters);
function_store_.Add(
FunctionEntry::EncodeFlags(language_mode, uses_super_property));
function_store_.Add(num_inner_functions);
}
ParserLogger::ParserLogger() {
preamble_[PreparseDataConstants::kMagicOffset] =
PreparseDataConstants::kMagicNumber;
preamble_[PreparseDataConstants::kVersionOffset] =
PreparseDataConstants::kCurrentVersion;
preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0;
preamble_[PreparseDataConstants::kSizeOffset] = 0;
DCHECK_EQ(4, PreparseDataConstants::kHeaderSize);
#ifdef DEBUG
prev_start_ = -1;
#endif
}
ScriptData* ParserLogger::GetScriptData() {
int function_size = function_store_.size();
int total_size = PreparseDataConstants::kHeaderSize + function_size;
unsigned* data = NewArray<unsigned>(total_size);
preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size;
MemCopy(data, preamble_, sizeof(preamble_));
if (function_size > 0) {
function_store_.WriteTo(Vector<unsigned>(
data + PreparseDataConstants::kHeaderSize, function_size));
}
DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment));
ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data),
total_size * sizeof(unsigned));
result->AcquireDataOwnership();
return result;
}
PreParseData::FunctionData PreParseData::GetFunctionData(int start) const {
auto it = functions_.find(start);
if (it != functions_.end()) {
return it->second;
}
return FunctionData();
}
void PreParseData::AddFunctionData(int start, FunctionData&& data) {
DCHECK(data.is_valid());
functions_[start] = std::move(data);
}
void PreParseData::AddFunctionData(int start, const FunctionData& data) {
DCHECK(data.is_valid());
functions_[start] = data;
}
size_t PreParseData::size() const { return functions_.size(); }
PreParseData::const_iterator PreParseData::begin() const {
return functions_.begin();
}
PreParseData::const_iterator PreParseData::end() const {
return functions_.end();
}
} // namespace internal
} // namespace v8.