2011-05-03 08:23:58 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2011-05-06 11:41:15 +00:00
|
|
|
#ifndef V8_PREPARSE_DATA_H_
|
|
|
|
#define V8_PREPARSE_DATA_H_
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/hashmap.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/preparse-data-format.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/utils-inl.h"
|
2010-11-23 11:46:36 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
class ScriptData;
|
|
|
|
|
2010-11-23 11:46:36 +00:00
|
|
|
|
|
|
|
// Abstract interface for preparse data recorder.
|
|
|
|
class ParserRecorder {
|
|
|
|
public:
|
2014-04-14 08:49:23 +00:00
|
|
|
ParserRecorder() { }
|
2010-11-23 11:46:36 +00:00
|
|
|
virtual ~ParserRecorder() { }
|
|
|
|
|
|
|
|
// Logs the scope and some details of a function literal in the source.
|
|
|
|
virtual void LogFunction(int start,
|
|
|
|
int end,
|
|
|
|
int literals,
|
2011-06-09 09:05:15 +00:00
|
|
|
int properties,
|
2014-03-11 14:41:22 +00:00
|
|
|
StrictMode strict_mode) = 0;
|
2010-11-23 11:46:36 +00:00
|
|
|
|
|
|
|
// Logs an error message and marks the log as containing an error.
|
|
|
|
// Further logging will be ignored, and ExtractData will return a vector
|
|
|
|
// representing the error only.
|
|
|
|
virtual void LogMessage(int start,
|
|
|
|
int end,
|
|
|
|
const char* message,
|
2014-04-01 14:17:43 +00:00
|
|
|
const char* argument_opt,
|
|
|
|
bool is_reference_error) = 0;
|
2014-03-13 11:56:13 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
|
|
|
|
};
|
2010-11-23 11:46:36 +00:00
|
|
|
|
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
class SingletonLogger : public ParserRecorder {
|
|
|
|
public:
|
2014-04-01 14:17:43 +00:00
|
|
|
SingletonLogger()
|
|
|
|
: has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {}
|
|
|
|
virtual ~SingletonLogger() {}
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
void Reset() { has_error_ = false; }
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
virtual void LogFunction(int start,
|
|
|
|
int end,
|
|
|
|
int literals,
|
|
|
|
int properties,
|
|
|
|
StrictMode strict_mode) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!has_error_);
|
2014-03-13 11:56:13 +00:00
|
|
|
start_ = start;
|
|
|
|
end_ = end;
|
|
|
|
literals_ = literals;
|
|
|
|
properties_ = properties;
|
|
|
|
strict_mode_ = strict_mode;
|
2014-05-09 12:59:24 +00:00
|
|
|
}
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
// Logs an error message and marks the log as containing an error.
|
|
|
|
// Further logging will be ignored, and ExtractData will return a vector
|
|
|
|
// representing the error only.
|
|
|
|
virtual void LogMessage(int start,
|
|
|
|
int end,
|
|
|
|
const char* message,
|
2014-04-01 14:17:43 +00:00
|
|
|
const char* argument_opt,
|
|
|
|
bool is_reference_error) {
|
2014-03-13 11:56:13 +00:00
|
|
|
if (has_error_) return;
|
|
|
|
has_error_ = true;
|
|
|
|
start_ = start;
|
|
|
|
end_ = end;
|
|
|
|
message_ = message;
|
|
|
|
argument_opt_ = argument_opt;
|
2014-04-01 14:17:43 +00:00
|
|
|
is_reference_error_ = is_reference_error;
|
2014-03-13 11:56:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 14:17:43 +00:00
|
|
|
bool has_error() const { return has_error_; }
|
2014-03-13 11:56:13 +00:00
|
|
|
|
2014-04-01 14:17:43 +00:00
|
|
|
int start() const { return start_; }
|
|
|
|
int end() const { return end_; }
|
|
|
|
int literals() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!has_error_);
|
2014-03-13 11:56:13 +00:00
|
|
|
return literals_;
|
|
|
|
}
|
2014-04-01 14:17:43 +00:00
|
|
|
int properties() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!has_error_);
|
2014-03-13 11:56:13 +00:00
|
|
|
return properties_;
|
|
|
|
}
|
2014-04-01 14:17:43 +00:00
|
|
|
StrictMode strict_mode() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!has_error_);
|
2014-03-13 11:56:13 +00:00
|
|
|
return strict_mode_;
|
|
|
|
}
|
2014-04-01 14:17:43 +00:00
|
|
|
int is_reference_error() const { return is_reference_error_; }
|
2014-03-13 11:56:13 +00:00
|
|
|
const char* message() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(has_error_);
|
2014-03-13 11:56:13 +00:00
|
|
|
return message_;
|
|
|
|
}
|
2014-04-01 14:17:43 +00:00
|
|
|
const char* argument_opt() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(has_error_);
|
2014-03-13 11:56:13 +00:00
|
|
|
return argument_opt_;
|
|
|
|
}
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
private:
|
|
|
|
bool has_error_;
|
|
|
|
int start_;
|
|
|
|
int end_;
|
|
|
|
// For function entries.
|
|
|
|
int literals_;
|
|
|
|
int properties_;
|
|
|
|
StrictMode strict_mode_;
|
|
|
|
// For error messages.
|
|
|
|
const char* message_;
|
|
|
|
const char* argument_opt_;
|
2014-04-01 14:17:43 +00:00
|
|
|
bool is_reference_error_;
|
2014-03-13 11:56:13 +00:00
|
|
|
};
|
2010-11-23 11:46:36 +00:00
|
|
|
|
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
class CompleteParserRecorder : public ParserRecorder {
|
2010-11-23 11:46:36 +00:00
|
|
|
public:
|
2014-03-13 11:56:13 +00:00
|
|
|
struct Key {
|
|
|
|
bool is_one_byte;
|
|
|
|
Vector<const byte> literal_bytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
CompleteParserRecorder();
|
|
|
|
virtual ~CompleteParserRecorder() {}
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2011-06-09 09:05:15 +00:00
|
|
|
virtual void LogFunction(int start,
|
|
|
|
int end,
|
|
|
|
int literals,
|
|
|
|
int properties,
|
2014-03-11 14:41:22 +00:00
|
|
|
StrictMode strict_mode) {
|
2010-11-23 11:46:36 +00:00
|
|
|
function_store_.Add(start);
|
|
|
|
function_store_.Add(end);
|
|
|
|
function_store_.Add(literals);
|
|
|
|
function_store_.Add(properties);
|
2014-03-11 14:41:22 +00:00
|
|
|
function_store_.Add(strict_mode);
|
2010-11-23 11:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Logs an error message and marks the log as containing an error.
|
|
|
|
// Further logging will be ignored, and ExtractData will return a vector
|
|
|
|
// representing the error only.
|
|
|
|
virtual void LogMessage(int start,
|
|
|
|
int end,
|
|
|
|
const char* message,
|
2014-04-01 14:17:43 +00:00
|
|
|
const char* argument_opt,
|
|
|
|
bool is_reference_error_);
|
2014-07-10 10:28:05 +00:00
|
|
|
ScriptData* GetScriptData();
|
2014-03-13 11:56:13 +00:00
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
bool HasError() {
|
2010-11-23 11:46:36 +00:00
|
|
|
return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
|
|
|
|
}
|
2014-07-10 10:28:05 +00:00
|
|
|
Vector<unsigned> ErrorMessageData() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(HasError());
|
2014-07-10 10:28:05 +00:00
|
|
|
return function_store_.ToVector();
|
|
|
|
}
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
private:
|
2010-11-23 11:46:36 +00:00
|
|
|
void WriteString(Vector<const char> str);
|
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
// Write a non-negative number to the symbol store.
|
|
|
|
void WriteNumber(int number);
|
|
|
|
|
2010-11-23 11:46:36 +00:00
|
|
|
Collector<unsigned> function_store_;
|
|
|
|
unsigned preamble_[PreparseDataConstants::kHeaderSize];
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
int prev_start_;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal.
|
|
|
|
|
2011-05-06 11:41:15 +00:00
|
|
|
#endif // V8_PREPARSE_DATA_H_
|