[ubsan] Port Struct subclasses, part 8: Script

Bug: v8:3770
Change-Id: Id7a05e5687d36c9347f35f6f3276af2a4b6115fd
Reviewed-on: https://chromium-review.googlesource.com/c/1377770
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58279}
This commit is contained in:
Jakob Kummerow 2018-12-17 04:49:34 -08:00 committed by Commit Bot
parent 01b0afd527
commit 8dc9e26eda
44 changed files with 105 additions and 94 deletions

View File

@ -9520,8 +9520,8 @@ void debug::GetLoadedScripts(v8::Isolate* v8_isolate,
{
i::DisallowHeapAllocation no_gc;
i::Script::Iterator iterator(isolate);
i::Script* script;
while ((script = iterator.Next()) != nullptr) {
for (i::Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
if (!script->IsUserJavaScript()) continue;
if (script->HasValidSource()) {
i::HandleScope handle_scope(isolate);

View File

@ -530,7 +530,8 @@ std::unique_ptr<Coverage> Coverage::Collect(
// between source ranges and invocation counts.
std::unique_ptr<Coverage> result(new Coverage());
Script::Iterator scripts(isolate);
while (Script* script = scripts.Next()) {
for (Script script = scripts.Next(); !script.is_null();
script = scripts.Next()) {
if (!script->IsUserJavaScript()) continue;
// Create and add new script data.

View File

@ -24,7 +24,8 @@ std::unique_ptr<TypeProfile> TypeProfile::Collect(Isolate* isolate) {
Script::Iterator scripts(isolate);
while (Script* script = scripts.Next()) {
for (Script script = scripts.Next(); !script.is_null();
script = scripts.Next()) {
if (!script->IsUserJavaScript()) {
continue;
}

View File

@ -1648,8 +1648,8 @@ Handle<FixedArray> Debug::GetLoadedScripts() {
int length = 0;
{
Script::Iterator iterator(isolate_);
Script* script;
while ((script = iterator.Next()) != nullptr) {
for (Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
if (script->HasValidSource()) results->set(length++, script);
}
}

View File

@ -813,7 +813,7 @@ class FunctionDataMap : public ThreadVisitor {
if (!sfi->script()->IsScript() || start_position == -1) {
return false;
}
Script* script = Script::cast(sfi->script());
Script script = Script::cast(sfi->script());
return Lookup(GetFuncId(script->id(), sfi), data);
}

View File

@ -783,10 +783,10 @@ Address InterpretedFrame::GetExpressionAddress(int n) const {
return fp() + offset - n * kPointerSize;
}
Script* StandardFrame::script() const {
Script StandardFrame::script() const {
// This should only be called on frames which override this method.
DCHECK(false);
return nullptr;
UNREACHABLE();
return Script();
}
Object* StandardFrame::receiver() const {
@ -1109,7 +1109,7 @@ Object* JavaScriptFrame::context() const {
return maybe_result;
}
Script* JavaScriptFrame::script() const {
Script JavaScriptFrame::script() const {
return Script::cast(function()->shared()->script());
}
@ -1132,7 +1132,7 @@ void JavaScriptFrame::PrintFunctionAndOffset(JSFunction function,
int source_pos = code->SourcePosition(code_offset);
Object* maybe_script = shared->script();
if (maybe_script->IsScript()) {
Script* script = Script::cast(maybe_script);
Script script = Script::cast(maybe_script);
int line = script->GetLineNumber(source_pos) + 1;
Object* script_name_raw = script->name();
if (script_name_raw->IsString()) {
@ -1201,7 +1201,7 @@ void JavaScriptFrame::CollectFunctionAndOffsetForICStats(JSFunction function,
int source_pos = code->SourcePosition(code_offset);
Object* maybe_script = shared->script();
if (maybe_script->IsScript()) {
Script* script = Script::cast(maybe_script);
Script script = Script::cast(maybe_script);
ic_info.line_num = script->GetLineNumber(source_pos) + 1;
ic_info.script_name = ic_stats->GetOrCacheScriptName(script);
}
@ -1831,7 +1831,7 @@ uint32_t WasmCompiledFrame::function_index() const {
return FrameSummary::GetSingle(this).AsWasmCompiled().function_index();
}
Script* WasmCompiledFrame::script() const { return module_object()->script(); }
Script WasmCompiledFrame::script() const { return module_object()->script(); }
int WasmCompiledFrame::position() const {
return FrameSummary::GetSingle(this).SourcePosition();
@ -1884,7 +1884,7 @@ void WasmInterpreterEntryFrame::Print(StringStream* accumulator, PrintMode mode,
int index) const {
PrintIndex(accumulator, mode, index);
accumulator->Add("WASM INTERPRETER ENTRY [");
Script* script = this->script();
Script script = this->script();
accumulator->PrintName(script->name());
accumulator->Add("]");
if (mode != OVERVIEW) accumulator->Add("\n");
@ -1919,7 +1919,7 @@ WasmModuleObject WasmInterpreterEntryFrame::module_object() const {
return wasm_instance()->module_object();
}
Script* WasmInterpreterEntryFrame::script() const {
Script WasmInterpreterEntryFrame::script() const {
return module_object()->script();
}
@ -1997,7 +1997,7 @@ void JavaScriptFrame::Print(StringStream* accumulator,
ScopeInfo scope_info = shared->scope_info();
Object* script_obj = shared->script();
if (script_obj->IsScript()) {
Script* script = Script::cast(script_obj);
Script script = Script::cast(script_obj);
accumulator->Add(" [");
accumulator->PrintName(script->name());

View File

@ -605,7 +605,7 @@ class StandardFrame : public StackFrame {
// Accessors.
virtual Object* receiver() const;
virtual Script* script() const;
virtual Script script() const;
virtual Object* context() const;
virtual int position() const;
@ -682,7 +682,7 @@ class JavaScriptFrame : public StandardFrame {
Object* unchecked_function() const;
Object* receiver() const override;
Object* context() const override;
Script* script() const override;
Script script() const override;
inline void set_receiver(Object* value);
@ -949,7 +949,7 @@ class WasmCompiledFrame final : public StandardFrame {
WasmInstanceObject wasm_instance() const;
wasm::WasmCode* wasm_code() const;
uint32_t function_index() const;
Script* script() const override;
Script script() const override;
int position() const override;
bool at_to_number_conversion() const;
@ -990,7 +990,7 @@ class WasmInterpreterEntryFrame final : public StandardFrame {
WasmDebugInfo debug_info() const;
WasmInstanceObject wasm_instance() const;
Script* script() const override;
Script script() const override;
int position() const override;
Object* context() const override;

View File

@ -991,7 +991,7 @@ class CodeDescription {
return !shared_info_.is_null() && shared_info_->script()->IsScript();
}
Script* script() { return Script::cast(shared_info_->script()); }
Script script() { return Script::cast(shared_info_->script()); }
bool IsLineInfoAvailable() { return lineinfo_ != nullptr; }

View File

@ -15,7 +15,7 @@ namespace internal {
void CodeStatistics::RecordCodeAndMetadataStatistics(HeapObject* object,
Isolate* isolate) {
if (object->IsScript()) {
Script* script = Script::cast(object);
Script script = Script::cast(object);
// Log the size of external source code.
Object* source = script->source();
if (source->IsExternalString()) {

View File

@ -394,7 +394,7 @@ class ObjectStatsCollectorImpl {
void RecordVirtualJSCollectionDetails(JSObject object);
void RecordVirtualJSObjectDetails(JSObject object);
void RecordVirtualMapDetails(Map map);
void RecordVirtualScriptDetails(Script* script);
void RecordVirtualScriptDetails(Script script);
void RecordVirtualExternalStringDetails(ExternalString script);
void RecordVirtualSharedFunctionInfoDetails(SharedFunctionInfo info);
void RecordVirtualJSFunctionDetails(JSFunction function);
@ -797,7 +797,7 @@ void ObjectStatsCollectorImpl::RecordVirtualMapDetails(Map map) {
}
}
void ObjectStatsCollectorImpl::RecordVirtualScriptDetails(Script* script) {
void ObjectStatsCollectorImpl::RecordVirtualScriptDetails(Script script) {
RecordSimpleVirtualObjectStats(
script, script->shared_function_infos(),
ObjectStats::SCRIPT_SHARED_FUNCTION_INFOS_TYPE);

View File

@ -54,9 +54,10 @@ void ICStats::Dump() {
Reset();
}
const char* ICStats::GetOrCacheScriptName(Script* script) {
if (script_name_map_.find(script) != script_name_map_.end()) {
return script_name_map_[script].get();
const char* ICStats::GetOrCacheScriptName(Script script) {
Address script_ptr = script.ptr();
if (script_name_map_.find(script_ptr) != script_name_map_.end()) {
return script_name_map_[script_ptr].get();
}
Object* script_name_raw = script->name();
if (script_name_raw->IsString()) {
@ -65,11 +66,11 @@ const char* ICStats::GetOrCacheScriptName(Script* script) {
script_name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)
.release();
script_name_map_.insert(
std::make_pair(script, std::unique_ptr<char[]>(c_script_name)));
std::make_pair(script_ptr, std::unique_ptr<char[]>(c_script_name)));
return c_script_name;
} else {
script_name_map_.insert(
std::make_pair(script, std::unique_ptr<char[]>(nullptr)));
std::make_pair(script_ptr, std::unique_ptr<char[]>(nullptr)));
return nullptr;
}
return nullptr;

View File

@ -59,7 +59,7 @@ class ICStats {
DCHECK(pos_ >= 0 && pos_ < MAX_IC_INFO);
return ic_infos_[pos_];
}
const char* GetOrCacheScriptName(Script* script);
const char* GetOrCacheScriptName(Script script);
const char* GetOrCacheFunctionName(JSFunction function);
V8_INLINE static ICStats* instance() { return instance_.Pointer(); }
@ -67,7 +67,8 @@ class ICStats {
static base::LazyInstance<ICStats>::type instance_;
base::Atomic32 enabled_;
std::vector<ICInfo> ic_infos_;
std::unordered_map<Script*, std::unique_ptr<char[]>> script_name_map_;
// Keys are Script pointers; uses raw Address to keep includes light.
std::unordered_map<Address, std::unique_ptr<char[]>> script_name_map_;
// Keys are JSFunction pointers; uses raw Address to keep includes light.
std::unordered_map<Address, std::unique_ptr<char[]>> function_name_map_;
int pos_;

View File

@ -14,7 +14,7 @@ namespace v8 {
namespace internal {
CodeEventListener::LogEventsAndTags Logger::ToNativeByScript(
CodeEventListener::LogEventsAndTags tag, Script* script) {
CodeEventListener::LogEventsAndTags tag, Script script) {
if (script->type() != Script::TYPE_NATIVE) return tag;
switch (tag) {
case CodeEventListener::FUNCTION_TAG:

View File

@ -1293,7 +1293,7 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
if (!FLAG_log_source_code) return;
Object* script_object = shared->script();
if (!script_object->IsScript()) return;
Script* script = Script::cast(script_object);
Script script = Script::cast(script_object);
if (!EnsureLogScriptSource(script)) return;
// We log source code information in the form:
@ -1562,7 +1562,7 @@ void Logger::ScriptEvent(ScriptEventType type, int script_id) {
msg.WriteToLogFile();
}
void Logger::ScriptDetails(Script* script) {
void Logger::ScriptDetails(Script script) {
if (!log_->IsEnabled() || !FLAG_log_function_events) return;
{
Log::MessageBuilder msg(log_);
@ -1580,7 +1580,7 @@ void Logger::ScriptDetails(Script* script) {
EnsureLogScriptSource(script);
}
bool Logger::EnsureLogScriptSource(Script* script) {
bool Logger::EnsureLogScriptSource(Script script) {
if (!log_->IsEnabled()) return false;
Log::MessageBuilder msg(log_);
// Make sure the script is written to the log file.

View File

@ -175,7 +175,7 @@ class Logger : public CodeEventListener {
void CompilationCacheEvent(const char* action, const char* cache_type,
SharedFunctionInfo sfi);
void ScriptEvent(ScriptEventType type, int script_id);
void ScriptDetails(Script* script);
void ScriptDetails(Script script);
// ==== Events logged by --log-api. ====
void ApiSecurityCheck();
@ -278,7 +278,7 @@ class Logger : public CodeEventListener {
// Converts tag to a corresponding NATIVE_... if the script is native.
V8_INLINE static CodeEventListener::LogEventsAndTags ToNativeByScript(
CodeEventListener::LogEventsAndTags, Script*);
CodeEventListener::LogEventsAndTags, Script);
// Callback from Log, stops profiling in case of insufficient resources.
void LogFailure();
@ -316,7 +316,7 @@ class Logger : public CodeEventListener {
// Logs a scripts sources. Keeps track of all logged scripts to ensure that
// each script is logged only once.
bool EnsureLogScriptSource(Script* script);
bool EnsureLogScriptSource(Script script);
Isolate* isolate_;

View File

@ -786,7 +786,7 @@ void JSGeneratorObject::JSGeneratorObjectPrint(std::ostream& os) { // NOLINT
DisallowHeapAllocation no_gc;
SharedFunctionInfo fun_info = function()->shared();
if (fun_info->HasSourceCode()) {
Script* script = Script::cast(fun_info->script());
Script script = Script::cast(fun_info->script());
int lin = script->GetLineNumber(source_position()) + 1;
int col = script->GetColumnNumber(source_position()) + 1;
String script_name = script->name()->IsString()
@ -2003,7 +2003,7 @@ void AllocationMemento::AllocationMementoPrint(std::ostream& os) { // NOLINT
void Script::ScriptPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "Script");
PrintHeader(os, "Script");
os << "\n - source: " << Brief(source());
os << "\n - name: " << Brief(name());
os << "\n - line_offset: " << line_offset();

View File

@ -13739,7 +13739,7 @@ bool Script::IsUserJavaScript() { return type() == Script::TYPE_NORMAL; }
bool Script::ContainsAsmModule() {
DisallowHeapAllocation no_gc;
SharedFunctionInfo::ScriptIterator iter(this->GetIsolate(), this);
SharedFunctionInfo::ScriptIterator iter(this->GetIsolate(), *this);
for (SharedFunctionInfo info = iter.Next(); !info.is_null();
info = iter.Next()) {
if (info->HasAsmWasmData()) return true;
@ -13748,7 +13748,7 @@ bool Script::ContainsAsmModule() {
}
namespace {
bool GetPositionInfoSlow(const Script* script, int position,
bool GetPositionInfoSlow(const Script script, int position,
Script::PositionInfo* info) {
if (!script->source()->IsString()) return false;
if (position < 0) position = 0;
@ -13789,7 +13789,7 @@ bool Script::GetPositionInfo(int position, PositionInfo* info,
if (line_ends()->IsUndefined()) {
// Slow mode: we do not have line_ends. We have to iterate through source.
if (!GetPositionInfoSlow(this, position, info)) return false;
if (!GetPositionInfoSlow(*this, position, info)) return false;
} else {
DCHECK(line_ends()->IsFixedArray());
FixedArray ends = FixedArray::cast(line_ends());
@ -13906,12 +13906,12 @@ MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo(
Script::Iterator::Iterator(Isolate* isolate)
: iterator_(isolate->heap()->script_list()) {}
Script* Script::Iterator::Next() {
Script Script::Iterator::Next() {
Object* o = iterator_.Next();
if (o != nullptr) {
return Script::cast(o);
}
return nullptr;
return Script();
}
Code SharedFunctionInfo::GetCode() const {
@ -13962,7 +13962,7 @@ WasmExportedFunctionData SharedFunctionInfo::wasm_exported_function_data()
}
SharedFunctionInfo::ScriptIterator::ScriptIterator(Isolate* isolate,
Script* script)
Script script)
: ScriptIterator(isolate,
handle(script->shared_function_infos(), isolate)) {}
@ -13985,7 +13985,7 @@ SharedFunctionInfo SharedFunctionInfo::ScriptIterator::Next() {
return SharedFunctionInfo();
}
void SharedFunctionInfo::ScriptIterator::Reset(Script* script) {
void SharedFunctionInfo::ScriptIterator::Reset(Script script) {
shared_function_infos_ = handle(script->shared_function_infos(), isolate_);
index_ = 0;
}
@ -14001,8 +14001,8 @@ SharedFunctionInfo SharedFunctionInfo::GlobalIterator::Next() {
for (;;) {
next = sfi_iterator_.Next();
if (next != nullptr) return SharedFunctionInfo::cast(next);
Script* next_script = script_iterator_.Next();
if (next_script == nullptr) return SharedFunctionInfo();
Script next_script = script_iterator_.Next();
if (next_script.is_null()) return SharedFunctionInfo();
sfi_iterator_.Reset(next_script);
}
}
@ -14063,7 +14063,7 @@ void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list);
// Remove shared function info from old script's list.
Script* old_script = Script::cast(shared->script());
Script old_script = Script::cast(shared->script());
// Due to liveedit, it might happen that the old_script doesn't know
// about the SharedFunctionInfo, so we have to guard against that.
@ -14126,7 +14126,7 @@ bool SharedFunctionInfo::PassesFilter(const char* raw_filter) {
bool SharedFunctionInfo::HasSourceCode() const {
Isolate* isolate = GetIsolate();
return !script()->IsUndefined(isolate) &&
!reinterpret_cast<Script*>(script())->source()->IsUndefined(isolate);
!Script::cast(script())->source()->IsUndefined(isolate);
}
void SharedFunctionInfo::DiscardCompiledMetadata(

View File

@ -42,7 +42,7 @@ uint32_t CompilationCacheShape::StringSharedHash(String source,
// script source code and the start position of the calling scope.
// We do this to ensure that the cache entries can survive garbage
// collection.
Script* script(Script::cast(shared->script()));
Script script(Script::cast(shared->script()));
hash ^= String::cast(script->source())->Hash();
STATIC_ASSERT(LanguageModeSize == 2);
if (is_strict(language_mode)) hash ^= 0x8000;

View File

@ -693,7 +693,7 @@ void JSMessageObject::set_type(MessageTemplate value) {
WRITE_FIELD(this, kTypeOffset, Smi::FromInt(static_cast<int>(value)));
}
ACCESSORS(JSMessageObject, argument, Object, kArgumentsOffset)
ACCESSORS(JSMessageObject, script, Script, kScriptOffset)
ACCESSORS2(JSMessageObject, script, Script, kScriptOffset)
ACCESSORS(JSMessageObject, stack_frames, Object, kStackFramesOffset)
SMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset)
SMI_ACCESSORS(JSMessageObject, end_position, kEndPositionOffset)

View File

@ -1373,7 +1373,7 @@ class JSMessageObject : public JSObject {
DECL_ACCESSORS(argument, Object)
// [script]: the script from which the error message originated.
DECL_ACCESSORS(script, Script)
DECL_ACCESSORS2(script, Script)
// [stack_frames]: an array of stack frames for this error object.
DECL_ACCESSORS(stack_frames, Object)

View File

@ -25,7 +25,7 @@ ACCESSORS2(Module, regular_exports, FixedArray, kRegularExportsOffset)
ACCESSORS2(Module, regular_imports, FixedArray, kRegularImportsOffset)
ACCESSORS(Module, module_namespace, HeapObject, kModuleNamespaceOffset)
ACCESSORS2(Module, requested_modules, FixedArray, kRequestedModulesOffset)
ACCESSORS(Module, script, Script, kScriptOffset)
ACCESSORS2(Module, script, Script, kScriptOffset)
ACCESSORS(Module, exception, Object, kExceptionOffset)
ACCESSORS(Module, import_meta, Object, kImportMetaOffset)
SMI_ACCESSORS(Module, status, kStatusOffset)

View File

@ -82,7 +82,7 @@ class Module : public Struct, public NeverReadOnlySpaceObject {
DECL_ACCESSORS2(requested_modules, FixedArray)
// [script]: Script from which the module originates.
DECL_ACCESSORS(script, Script)
DECL_ACCESSORS2(script, Script)
// The value of import.meta inside of this module.
// Lazily initialized on first access. It's the hole before first access and

View File

@ -17,7 +17,11 @@
namespace v8 {
namespace internal {
CAST_ACCESSOR(Script)
OBJECT_CONSTRUCTORS_IMPL(Script, StructPtr)
NEVER_READ_ONLY_SPACE_IMPL(Script)
CAST_ACCESSOR2(Script)
ACCESSORS(Script, source, Object, kSourceOffset)
ACCESSORS(Script, name, Object, kNameOffset)

View File

@ -16,8 +16,9 @@ namespace v8 {
namespace internal {
// Script describes a script which has been added to the VM.
class Script : public Struct, public NeverReadOnlySpaceObject {
class Script : public StructPtr {
public:
NEVER_READ_ONLY_SPACE
// Script types.
enum Type {
TYPE_NATIVE = 0,
@ -118,7 +119,7 @@ class Script : public Struct, public NeverReadOnlySpaceObject {
inline v8::ScriptOriginOptions origin_options();
inline void set_origin_options(ScriptOriginOptions origin_options);
DECL_CAST(Script)
DECL_CAST2(Script)
// If script source is an external string, check that the underlying
// resource is accessible. Otherwise, always return true.
@ -177,7 +178,7 @@ class Script : public Struct, public NeverReadOnlySpaceObject {
class Iterator {
public:
explicit Iterator(Isolate* isolate);
Script* Next();
Script Next();
private:
WeakArrayList::Iterator iterator_;
@ -220,7 +221,7 @@ class Script : public Struct, public NeverReadOnlySpaceObject {
static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1)
<< kOriginOptionsShift;
DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
OBJECT_CONSTRUCTORS(Script, StructPtr);
};
} // namespace internal

View File

@ -710,7 +710,7 @@ String SharedFunctionInfo::inferred_name() {
bool SharedFunctionInfo::IsUserJavaScript() {
Object* script_obj = script();
if (script_obj->IsUndefined()) return false;
Script* script = Script::cast(script_obj);
Script script = Script::cast(script_obj);
return script->IsUserJavaScript();
}

View File

@ -580,14 +580,14 @@ class SharedFunctionInfo : public HeapObjectPtr {
// Iterate over all shared function infos in a given script.
class ScriptIterator {
public:
ScriptIterator(Isolate* isolate, Script* script);
ScriptIterator(Isolate* isolate, Script script);
ScriptIterator(Isolate* isolate,
Handle<WeakFixedArray> shared_function_infos);
SharedFunctionInfo Next();
int CurrentIndex() const { return index_ - 1; }
// Reset the iterator to run on |script|.
void Reset(Script* script);
void Reset(Script script);
private:
Isolate* isolate_;

View File

@ -489,7 +489,7 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
if (V8_UNLIKELY(FLAG_log_function_events) && result != nullptr) {
double ms = timer.Elapsed().InMillisecondsF();
const char* event_name = "parse-eval";
Script* script = *info->script();
Script script = *info->script();
int start = -1;
int end = -1;
if (!info->is_eval()) {

View File

@ -246,7 +246,7 @@ unsigned AllocationTracker::AddFunctionInfo(SharedFunctionInfo shared,
info->name = names_->GetName(shared->DebugName());
info->function_id = id;
if (shared->script()->IsScript()) {
Script* script = Script::cast(shared->script());
Script script = Script::cast(shared->script());
if (script->name()->IsName()) {
Name name = Name::cast(script->name());
info->script_name = names_->GetName(name);
@ -275,17 +275,15 @@ unsigned AllocationTracker::functionInfoIndexForVMState(StateTag state) {
return info_index_for_other_state_;
}
AllocationTracker::UnresolvedLocation::UnresolvedLocation(
Script* script, int start, FunctionInfo* info)
: start_position_(start),
info_(info) {
AllocationTracker::UnresolvedLocation::UnresolvedLocation(Script script,
int start,
FunctionInfo* info)
: start_position_(start), info_(info) {
script_ = script->GetIsolate()->global_handles()->Create(script);
GlobalHandles::MakeWeak(script_.location(), this, &HandleWeakScript,
v8::WeakCallbackType::kParameter);
}
AllocationTracker::UnresolvedLocation::~UnresolvedLocation() {
if (!script_.is_null()) {
GlobalHandles::Destroy(script_.location());

View File

@ -125,7 +125,7 @@ class AllocationTracker {
class UnresolvedLocation {
public:
UnresolvedLocation(Script* script, int start, FunctionInfo* info);
UnresolvedLocation(Script script, int start, FunctionInfo* info);
~UnresolvedLocation();
void Resolve();

View File

@ -540,7 +540,7 @@ void V8HeapExplorer::ExtractLocation(HeapEntry* entry, HeapObject* object) {
void V8HeapExplorer::ExtractLocationForJSFunction(HeapEntry* entry,
JSFunction func) {
if (!func->shared()->script()->IsScript()) return;
Script* script = Script::cast(func->shared()->script());
Script script = Script::cast(func->shared()->script());
int scriptId = script->id();
int start = func->shared()->StartPosition();
int line = script->GetLineNumber(start);
@ -1093,7 +1093,7 @@ void V8HeapExplorer::ExtractSharedFunctionInfoReferences(
SharedFunctionInfo::kOuterScopeInfoOrFeedbackMetadataOffset);
}
void V8HeapExplorer::ExtractScriptReferences(HeapEntry* entry, Script* script) {
void V8HeapExplorer::ExtractScriptReferences(HeapEntry* entry, Script script) {
SetInternalReference(entry, "source", script->source(),
Script::kSourceOffset);
SetInternalReference(entry, "name", script->name(), Script::kNameOffset);

View File

@ -358,7 +358,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
void ExtractMapReferences(HeapEntry* entry, Map map);
void ExtractSharedFunctionInfoReferences(HeapEntry* entry,
SharedFunctionInfo shared);
void ExtractScriptReferences(HeapEntry* entry, Script* script);
void ExtractScriptReferences(HeapEntry* entry, Script script);
void ExtractAccessorInfoReferences(HeapEntry* entry,
AccessorInfo accessor_info);
void ExtractAccessorPairReferences(HeapEntry* entry, AccessorPair accessors);

View File

@ -144,7 +144,7 @@ void CodeEntry::set_deopt_info(
void CodeEntry::FillFunctionInfo(SharedFunctionInfo shared) {
if (!shared->script()->IsScript()) return;
Script* script = Script::cast(shared->script());
Script script = Script::cast(shared->script());
set_script_id(script->id());
set_position(shared->StartPosition());
if (shared->optimization_disabled()) {

View File

@ -85,7 +85,7 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
rec->instruction_start = abstract_code->InstructionStart();
std::unique_ptr<SourcePositionTable> line_table;
if (shared->script()->IsScript()) {
Script* script = Script::cast(shared->script());
Script script = Script::cast(shared->script());
line_table.reset(new SourcePositionTable());
for (SourcePositionTableIterator it(abstract_code->source_position_table());
!it.done(); it.Advance()) {

View File

@ -208,7 +208,7 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() {
const char* name = this->names()->GetName(shared->DebugName());
int script_id = v8::UnboundScript::kNoScriptId;
if (shared->script()->IsScript()) {
Script* script = Script::cast(shared->script());
Script script = Script::cast(shared->script());
script_id = script->id();
}
node = FindOrAddChildNode(node, name, script_id, shared->StartPosition());
@ -282,7 +282,8 @@ v8::AllocationProfile* SamplingHeapProfiler::GetAllocationProfile() {
std::map<int, Handle<Script>> scripts;
{
Script::Iterator iterator(isolate_);
while (Script* script = iterator.Next()) {
for (Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
scripts[script->id()] = handle(script, isolate_);
}
}

View File

@ -231,7 +231,7 @@ class RootVisitor;
V(Map, external_map, ExternalMap) \
V(Map, message_object_map, JSMessageObjectMap) \
/* Canonical empty values */ \
V(Script*, empty_script, EmptyScript) \
V(Script, empty_script, EmptyScript) \
V(FeedbackCell, many_closures_cell, ManyClosuresCell) \
V(FeedbackCell, no_feedback_cell, NoFeedbackCell) \
V(Cell*, invalid_prototype_validity_cell, InvalidPrototypeValidityCell) \

View File

@ -575,8 +575,8 @@ Handle<Object> ScriptLocationFromLine(Isolate* isolate, Handle<Script> script,
// Slow traversal over all scripts on the heap.
bool GetScriptById(Isolate* isolate, int needle, Handle<Script>* result) {
Script::Iterator iterator(isolate);
Script* script = nullptr;
while ((script = iterator.Next()) != nullptr) {
for (Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
if (script->id() == needle) {
*result = handle(script, isolate);
return true;

View File

@ -155,7 +155,7 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
}
if (obj->IsScript()) {
Script* script_obj = Script::cast(obj);
Script script_obj = Script::cast(obj);
DCHECK_NE(script_obj->compilation_type(), Script::COMPILATION_TYPE_EVAL);
// We want to differentiate between undefined and uninitialized_symbol for
// context_data for now. It is hack to allow debugging for scripts that are
@ -280,7 +280,7 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
if (log_code_creation || FLAG_log_function_events) {
String name = ReadOnlyRoots(isolate).empty_string();
if (result->script()->IsScript()) {
Script* script = Script::cast(result->script());
Script script = Script::cast(result->script());
if (script->name()->IsString()) name = String::cast(script->name());
if (FLAG_log_function_events) {
LOG(isolate, FunctionEvent("deserialize", script->id(),

View File

@ -177,7 +177,7 @@ void Deserializer::LogNewMapEvents() {
}
}
void Deserializer::LogScriptEvents(Script* script) {
void Deserializer::LogScriptEvents(Script script) {
DisallowHeapAllocation no_gc;
LOG(isolate_,
ScriptEvent(Logger::ScriptEventType::kDeserialize, script->id()));

View File

@ -63,7 +63,7 @@ class Deserializer : public SerializerDeserializer {
// Create Log events for newly deserialized objects.
void LogNewObjectEvents();
void LogScriptEvents(Script* script);
void LogScriptEvents(Script script);
void LogNewMapEvents();
// This returns the address of an object that has been described in the

View File

@ -80,7 +80,7 @@ void SourcePosition::Print(std::ostream& out,
Script::PositionInfo pos;
Object* source_name = nullptr;
if (function->script()->IsScript()) {
Script* script = Script::cast(function->script());
Script script = Script::cast(function->script());
source_name = script->name();
script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET);
}

View File

@ -76,7 +76,7 @@ CAST_ACCESSOR2(AsmWasmData)
ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
kNativeModuleOffset)
ACCESSORS2(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
ACCESSORS(WasmModuleObject, script, Script, kScriptOffset)
ACCESSORS2(WasmModuleObject, script, Script, kScriptOffset)
ACCESSORS2(WasmModuleObject, weak_instance_list, WeakArrayList,
kWeakInstanceListOffset)
OPTIONAL_ACCESSORS2(WasmModuleObject, asm_js_offset_table, ByteArray,

View File

@ -112,7 +112,7 @@ class WasmModuleObject : public JSObject {
DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
DECL_ACCESSORS2(export_wrappers, FixedArray)
DECL_ACCESSORS(script, Script)
DECL_ACCESSORS2(script, Script)
DECL_ACCESSORS2(weak_instance_list, WeakArrayList)
DECL_OPTIONAL_ACCESSORS2(asm_js_offset_table, ByteArray)
DECL_OPTIONAL_ACCESSORS2(breakpoint_infos, FixedArray)

View File

@ -5212,7 +5212,10 @@ TEST(ScriptIterator) {
{
Script::Iterator iterator(isolate);
while (iterator.Next()) script_count--;
for (Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
script_count--;
}
}
CHECK_EQ(0, script_count);

View File

@ -4279,8 +4279,8 @@ UNINITIALIZED_TEST(LoadedAtStartupScripts) {
{
i::DisallowHeapAllocation no_gc;
i::Script::Iterator iterator(i_isolate);
i::Script* script;
while ((script = iterator.Next()) != nullptr) {
for (i::Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
if (script->type() == i::Script::TYPE_NATIVE &&
script->name()->IsUndefined(i_isolate)) {
continue;