// Copyright 2021 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/debug/debug-interface.h" #include "src/api/api-inl.h" #include "src/debug/debug-coverage.h" #include "src/debug/debug-evaluate.h" #include "src/debug/debug-property-iterator.h" #include "src/debug/debug-type-profile.h" #include "src/debug/debug.h" #include "src/execution/vm-state-inl.h" #include "src/objects/js-generator-inl.h" #include "src/objects/stack-frame-info-inl.h" #include "src/regexp/regexp-stack.h" #include "src/strings/string-builder-inl.h" #if V8_ENABLE_WEBASSEMBLY #include "src/debug/debug-wasm-objects-inl.h" #include "src/wasm/wasm-engine.h" #endif // V8_ENABLE_WEBASSEMBLY // Has to be the last include (doesn't have include guards): #include "src/api/api-macros.h" namespace v8 { namespace debug { void SetContextId(Local context, int id) { Utils::OpenHandle(*context)->set_debug_context_id(i::Smi::FromInt(id)); } int GetContextId(Local context) { i::Object value = Utils::OpenHandle(*context)->debug_context_id(); return (value.IsSmi()) ? i::Smi::ToInt(value) : 0; } void SetInspector(Isolate* isolate, v8_inspector::V8Inspector* inspector) { i::Isolate* i_isolate = reinterpret_cast(isolate); i_isolate->set_inspector(inspector); } v8_inspector::V8Inspector* GetInspector(Isolate* isolate) { return reinterpret_cast(isolate)->inspector(); } Local GetFunctionDebugName(Local frame) { #if V8_ENABLE_WEBASSEMBLY auto info = Utils::OpenHandle(*frame); if (info->IsWasm()) { auto isolate = info->GetIsolate(); auto instance = handle(info->GetWasmInstance(), isolate); auto func_index = info->GetWasmFunctionIndex(); return Utils::ToLocal( i::GetWasmFunctionDebugName(isolate, instance, func_index)); } #endif // V8_ENABLE_WEBASSEMBLY return frame->GetFunctionName(); } Local GetFunctionDescription(Local function) { auto receiver = Utils::OpenHandle(*function); if (receiver->IsJSBoundFunction()) { return Utils::ToLocal(i::JSBoundFunction::ToString( i::Handle::cast(receiver))); } if (receiver->IsJSFunction()) { auto function = i::Handle::cast(receiver); #if V8_ENABLE_WEBASSEMBLY if (function->shared().HasWasmExportedFunctionData()) { auto isolate = function->GetIsolate(); auto func_index = function->shared().wasm_exported_function_data().function_index(); auto instance = i::handle( function->shared().wasm_exported_function_data().instance(), isolate); if (instance->module()->origin == i::wasm::kWasmOrigin) { // For asm.js functions, we can still print the source // code (hopefully), so don't bother with them here. auto debug_name = i::GetWasmFunctionDebugName(isolate, instance, func_index); i::IncrementalStringBuilder builder(isolate); builder.AppendCString("function "); builder.AppendString(debug_name); builder.AppendCString("() { [native code] }"); return Utils::ToLocal(builder.Finish().ToHandleChecked()); } } #endif // V8_ENABLE_WEBASSEMBLY return Utils::ToLocal(i::JSFunction::ToString(function)); } return Utils::ToLocal( receiver->GetIsolate()->factory()->function_native_code_string()); } void SetBreakOnNextFunctionCall(Isolate* isolate) { reinterpret_cast(isolate)->debug()->SetBreakOnNextFunctionCall(); } void ClearBreakOnNextFunctionCall(Isolate* isolate) { reinterpret_cast(isolate) ->debug() ->ClearBreakOnNextFunctionCall(); } MaybeLocal GetInternalProperties(Isolate* v8_isolate, Local value) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); i::Handle val = Utils::OpenHandle(*value); i::Handle result; if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result)) return MaybeLocal(); return Utils::ToLocal(result); } namespace { void CollectPrivateMethodsAndAccessorsFromContext( i::Isolate* isolate, i::Handle context, i::IsStaticFlag is_static_flag, std::vector>* names_out, std::vector>* values_out) { i::Handle scope_info(context->scope_info(), isolate); int local_count = scope_info->ContextLocalCount(); for (int j = 0; j < local_count; ++j) { i::VariableMode mode = scope_info->ContextLocalMode(j); i::IsStaticFlag flag = scope_info->ContextLocalIsStaticFlag(j); if (!i::IsPrivateMethodOrAccessorVariableMode(mode) || flag != is_static_flag) { continue; } i::Handle name(scope_info->ContextLocalName(j), isolate); int context_index = scope_info->ContextHeaderLength() + j; i::Handle slot_value(context->get(context_index), isolate); DCHECK_IMPLIES(mode == i::VariableMode::kPrivateMethod, slot_value->IsJSFunction()); DCHECK_IMPLIES(mode != i::VariableMode::kPrivateMethod, slot_value->IsAccessorPair()); names_out->push_back(Utils::ToLocal(name)); values_out->push_back(Utils::ToLocal(slot_value)); } } } // namespace bool GetPrivateMembers(Local context, Local value, std::vector>* names_out, std::vector>* values_out) { i::Isolate* isolate = reinterpret_cast(context->GetIsolate()); LOG_API(isolate, debug, GetPrivateMembers); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); i::Handle receiver = Utils::OpenHandle(*value); i::Handle names; i::Handle values; i::PropertyFilter key_filter = static_cast(i::PropertyFilter::PRIVATE_NAMES_ONLY); i::Handle keys; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, keys, i::KeyAccumulator::GetKeys(receiver, i::KeyCollectionMode::kOwnOnly, key_filter, i::GetKeysConversion::kConvertToString), false); // Estimate number of private fields and private instance methods/accessors. int private_entries_count = 0; for (int i = 0; i < keys->length(); ++i) { // Exclude the private brand symbols. i::Handle key(i::Symbol::cast(keys->get(i)), isolate); if (key->is_private_brand()) { i::Handle value; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value, i::Object::GetProperty(isolate, receiver, key), false); i::Handle context(i::Context::cast(*value), isolate); i::Handle scope_info(context->scope_info(), isolate); // At least one slot contains the brand symbol so it does not count. private_entries_count += (scope_info->ContextLocalCount() - 1); } else { private_entries_count++; } } // Estimate number of static private methods/accessors for classes. bool has_static_private_methods_or_accessors = false; if (receiver->IsJSFunction()) { i::Handle func(i::JSFunction::cast(*receiver), isolate); i::Handle shared(func->shared(), isolate); if (shared->is_class_constructor() && shared->has_static_private_methods_or_accessors()) { has_static_private_methods_or_accessors = true; i::Handle context(func->context(), isolate); i::Handle scope_info(context->scope_info(), isolate); int local_count = scope_info->ContextLocalCount(); for (int j = 0; j < local_count; ++j) { i::VariableMode mode = scope_info->ContextLocalMode(j); i::IsStaticFlag is_static_flag = scope_info->ContextLocalIsStaticFlag(j); if (i::IsPrivateMethodOrAccessorVariableMode(mode) && is_static_flag == i::IsStaticFlag::kStatic) { private_entries_count += local_count; break; } } } } DCHECK(names_out->empty()); names_out->reserve(private_entries_count); DCHECK(values_out->empty()); values_out->reserve(private_entries_count); if (has_static_private_methods_or_accessors) { i::Handle context(i::JSFunction::cast(*receiver).context(), isolate); CollectPrivateMethodsAndAccessorsFromContext( isolate, context, i::IsStaticFlag::kStatic, names_out, values_out); } for (int i = 0; i < keys->length(); ++i) { i::Handle obj_key(keys->get(i), isolate); i::Handle key(i::Symbol::cast(*obj_key), isolate); CHECK(key->is_private_name()); i::Handle value; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value, i::Object::GetProperty(isolate, receiver, key), false); if (key->is_private_brand()) { DCHECK(value->IsContext()); i::Handle context(i::Context::cast(*value), isolate); CollectPrivateMethodsAndAccessorsFromContext( isolate, context, i::IsStaticFlag::kNotStatic, names_out, values_out); } else { // Private fields i::Handle name( i::String::cast(i::Symbol::cast(*key).description()), isolate); names_out->push_back(Utils::ToLocal(name)); values_out->push_back(Utils::ToLocal(value)); } } DCHECK_EQ(names_out->size(), values_out->size()); DCHECK_LE(names_out->size(), private_entries_count); return true; } MaybeLocal GetCreationContext(Local value) { i::Handle val = Utils::OpenHandle(*value); if (val->IsJSGlobalProxy()) { return MaybeLocal(); } return value->GetCreationContext(); } void ChangeBreakOnException(Isolate* isolate, ExceptionBreakState type) { i::Isolate* internal_isolate = reinterpret_cast(isolate); internal_isolate->debug()->ChangeBreakOnException( i::BreakException, type == BreakOnAnyException); internal_isolate->debug()->ChangeBreakOnException(i::BreakUncaughtException, type != NoBreakOnException); } void SetBreakPointsActive(Isolate* v8_isolate, bool is_active) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); isolate->debug()->set_break_points_active(is_active); } void PrepareStep(Isolate* v8_isolate, StepAction action) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_DO_NOT_USE(isolate); CHECK(isolate->debug()->CheckExecutionState()); // Clear all current stepping setup. isolate->debug()->ClearStepping(); // Prepare step. isolate->debug()->PrepareStep(static_cast(action)); } void ClearStepping(Isolate* v8_isolate) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); // Clear all current stepping setup. isolate->debug()->ClearStepping(); } void BreakRightNow(Isolate* v8_isolate) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_DO_NOT_USE(isolate); isolate->debug()->HandleDebugBreak(i::kIgnoreIfAllFramesBlackboxed); } void SetTerminateOnResume(Isolate* v8_isolate) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); isolate->debug()->SetTerminateOnResume(); } bool CanBreakProgram(Isolate* v8_isolate) { i::Isolate* isolate = reinterpret_cast(v8_isolate); ENTER_V8_DO_NOT_USE(isolate); // We cannot break a program if we are currently running a regexp. // TODO(yangguo): fix this exception. return !isolate->regexp_stack()->is_in_use() && isolate->debug()->AllFramesOnStackAreBlackboxed(); } Isolate* Script::GetIsolate() const { return reinterpret_cast(Utils::OpenHandle(this)->GetIsolate()); } ScriptOriginOptions Script::OriginOptions() const { return Utils::OpenHandle(this)->origin_options(); } bool Script::WasCompiled() const { return Utils::OpenHandle(this)->compilation_state() == i::Script::COMPILATION_STATE_COMPILED; } bool Script::IsEmbedded() const { i::Handle script = Utils::OpenHandle(this); return script->context_data() == script->GetReadOnlyRoots().uninitialized_symbol(); } int Script::Id() const { return Utils::OpenHandle(this)->id(); } int Script::LineOffset() const { return Utils::OpenHandle(this)->line_offset(); } int Script::ColumnOffset() const { return Utils::OpenHandle(this)->column_offset(); } std::vector Script::LineEnds() const { i::Handle script = Utils::OpenHandle(this); #if V8_ENABLE_WEBASSEMBLY if (script->type() == i::Script::TYPE_WASM) return {}; #endif // V8_ENABLE_WEBASSEMBLY i::Isolate* isolate = script->GetIsolate(); i::HandleScope scope(isolate); i::Script::InitLineEnds(isolate, script); CHECK(script->line_ends().IsFixedArray()); i::Handle line_ends(i::FixedArray::cast(script->line_ends()), isolate); std::vector result(line_ends->length()); for (int i = 0; i < line_ends->length(); ++i) { i::Smi line_end = i::Smi::cast(line_ends->get(i)); result[i] = line_end.value(); } return result; } MaybeLocal Script::Name() const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); i::HandleScope handle_scope(isolate); i::Handle value(script->name(), isolate); if (!value->IsString()) return MaybeLocal(); return Utils::ToLocal( handle_scope.CloseAndEscape(i::Handle::cast(value))); } MaybeLocal Script::SourceURL() const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); i::HandleScope handle_scope(isolate); i::Handle value(script->source_url(), isolate); if (!value->IsString()) return MaybeLocal(); return Utils::ToLocal( handle_scope.CloseAndEscape(i::Handle::cast(value))); } MaybeLocal Script::SourceMappingURL() const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); i::HandleScope handle_scope(isolate); i::Handle value(script->source_mapping_url(), isolate); if (!value->IsString()) return MaybeLocal(); return Utils::ToLocal( handle_scope.CloseAndEscape(i::Handle::cast(value))); } Maybe Script::ContextId() const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); i::HandleScope handle_scope(isolate); i::Object value = script->context_data(); if (value.IsSmi()) return Just(i::Smi::ToInt(value)); return Nothing(); } MaybeLocal Script::Source() const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); i::HandleScope handle_scope(isolate); i::Handle value(script->source(), isolate); if (!value->IsString()) return MaybeLocal(); return Utils::ToLocal( handle_scope.CloseAndEscape(i::Handle::cast(value))); } #if V8_ENABLE_WEBASSEMBLY bool Script::IsWasm() const { return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM; } #endif // V8_ENABLE_WEBASSEMBLY bool Script::IsModule() const { return Utils::OpenHandle(this)->origin_options().IsModule(); } namespace { int GetSmiValue(i::Handle array, int index) { return i::Smi::ToInt(array->get(index)); } bool CompareBreakLocation(const i::BreakLocation& loc1, const i::BreakLocation& loc2) { return loc1.position() < loc2.position(); } } // namespace bool Script::GetPossibleBreakpoints( const Location& start, const Location& end, bool restrict_to_function, std::vector* locations) const { CHECK(!start.IsEmpty()); i::Handle script = Utils::OpenHandle(this); #if V8_ENABLE_WEBASSEMBLY if (script->type() == i::Script::TYPE_WASM) { i::wasm::NativeModule* native_module = script->wasm_native_module(); return i::WasmScript::GetPossibleBreakpoints(native_module, start, end, locations); } #endif // V8_ENABLE_WEBASSEMBLY i::Isolate* isolate = script->GetIsolate(); i::Script::InitLineEnds(isolate, script); CHECK(script->line_ends().IsFixedArray()); i::Handle line_ends = i::Handle::cast(i::handle(script->line_ends(), isolate)); CHECK(line_ends->length()); int start_offset = GetSourceOffset(start); int end_offset = end.IsEmpty() ? GetSmiValue(line_ends, line_ends->length() - 1) + 1 : GetSourceOffset(end); if (start_offset >= end_offset) return true; std::vector v8_locations; if (!isolate->debug()->GetPossibleBreakpoints( script, start_offset, end_offset, restrict_to_function, &v8_locations)) { return false; } std::sort(v8_locations.begin(), v8_locations.end(), CompareBreakLocation); int current_line_end_index = 0; for (const auto& v8_location : v8_locations) { int offset = v8_location.position(); while (offset > GetSmiValue(line_ends, current_line_end_index)) { ++current_line_end_index; CHECK(current_line_end_index < line_ends->length()); } int line_offset = 0; if (current_line_end_index > 0) { line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; } locations->emplace_back( current_line_end_index + script->line_offset(), offset - line_offset + (current_line_end_index == 0 ? script->column_offset() : 0), v8_location.type()); } return true; } int Script::GetSourceOffset(const Location& location) const { i::Handle script = Utils::OpenHandle(this); #if V8_ENABLE_WEBASSEMBLY if (script->type() == i::Script::TYPE_WASM) { DCHECK_EQ(0, location.GetLineNumber()); return location.GetColumnNumber(); } #endif // V8_ENABLE_WEBASSEMBLY int line = std::max(location.GetLineNumber() - script->line_offset(), 0); int column = location.GetColumnNumber(); if (line == 0) { column = std::max(0, column - script->column_offset()); } i::Script::InitLineEnds(script->GetIsolate(), script); CHECK(script->line_ends().IsFixedArray()); i::Handle line_ends = i::Handle::cast( i::handle(script->line_ends(), script->GetIsolate())); CHECK(line_ends->length()); if (line >= line_ends->length()) return GetSmiValue(line_ends, line_ends->length() - 1); int line_offset = GetSmiValue(line_ends, line); if (line == 0) return std::min(column, line_offset); int prev_line_offset = GetSmiValue(line_ends, line - 1); return std::min(prev_line_offset + column + 1, line_offset); } Location Script::GetSourceLocation(int offset) const { i::Handle script = Utils::OpenHandle(this); i::Script::PositionInfo info; i::Script::GetPositionInfo(script, offset, &info, i::Script::WITH_OFFSET); return Location(info.line, info.column); } bool Script::SetScriptSource(Local newSource, bool preview, LiveEditResult* result) const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); return isolate->debug()->SetScriptSource( script, Utils::OpenHandle(*newSource), preview, result); } bool Script::SetBreakpoint(Local condition, Location* location, BreakpointId* id) const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); int offset = GetSourceOffset(*location); if (!isolate->debug()->SetBreakPointForScript( script, Utils::OpenHandle(*condition), &offset, id)) { return false; } *location = GetSourceLocation(offset); return true; } bool Script::SetBreakpointOnScriptEntry(BreakpointId* id) const { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); #if V8_ENABLE_WEBASSEMBLY if (script->type() == i::Script::TYPE_WASM) { int position = i::WasmScript::kOnEntryBreakpointPosition; return isolate->debug()->SetBreakPointForScript( script, isolate->factory()->empty_string(), &position, id); } #endif // V8_ENABLE_WEBASSEMBLY i::SharedFunctionInfo::ScriptIterator it(isolate, *script); for (i::SharedFunctionInfo sfi = it.Next(); !sfi.is_null(); sfi = it.Next()) { if (sfi.is_toplevel()) { return isolate->debug()->SetBreakpointForFunction( handle(sfi, isolate), isolate->factory()->empty_string(), id); } } return false; } #if V8_ENABLE_WEBASSEMBLY void Script::RemoveWasmBreakpoint(BreakpointId id) { i::Handle script = Utils::OpenHandle(this); i::Isolate* isolate = script->GetIsolate(); isolate->debug()->RemoveBreakpointForWasmScript(script, id); } #endif // V8_ENABLE_WEBASSEMBLY void RemoveBreakpoint(Isolate* v8_isolate, BreakpointId id) { i::Isolate* isolate = reinterpret_cast(v8_isolate); i::HandleScope handle_scope(isolate); isolate->debug()->RemoveBreakpoint(id); } Platform* GetCurrentPlatform() { return i::V8::GetCurrentPlatform(); } void ForceGarbageCollection( Isolate* isolate, EmbedderHeapTracer::EmbedderStackState embedder_stack_state) { i::Heap* heap = reinterpret_cast(isolate)->heap(); heap->SetEmbedderStackStateForNextFinalization(embedder_stack_state); isolate->LowMemoryNotification(); } #if V8_ENABLE_WEBASSEMBLY WasmScript* WasmScript::Cast(Script* script) { CHECK(script->IsWasm()); return static_cast(script); } WasmScript::DebugSymbolsType WasmScript::GetDebugSymbolType() const { i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); switch (script->wasm_native_module()->module()->debug_symbols.type) { case i::wasm::WasmDebugSymbols::Type::None: return WasmScript::DebugSymbolsType::None; case i::wasm::WasmDebugSymbols::Type::EmbeddedDWARF: return WasmScript::DebugSymbolsType::EmbeddedDWARF; case i::wasm::WasmDebugSymbols::Type::ExternalDWARF: return WasmScript::DebugSymbolsType::ExternalDWARF; case i::wasm::WasmDebugSymbols::Type::SourceMap: return WasmScript::DebugSymbolsType::SourceMap; } } MemorySpan WasmScript::ExternalSymbolsURL() const { i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); const i::wasm::WasmDebugSymbols& symbols = script->wasm_native_module()->module()->debug_symbols; if (symbols.external_url.is_empty()) return {}; internal::wasm::ModuleWireBytes wire_bytes( script->wasm_native_module()->wire_bytes()); i::wasm::WasmName external_url = wire_bytes.GetNameOrNull(symbols.external_url); return {external_url.data(), external_url.size()}; } int WasmScript::NumFunctions() const { i::DisallowGarbageCollection no_gc; i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); i::wasm::NativeModule* native_module = script->wasm_native_module(); const i::wasm::WasmModule* module = native_module->module(); DCHECK_GE(i::kMaxInt, module->functions.size()); return static_cast(module->functions.size()); } int WasmScript::NumImportedFunctions() const { i::DisallowGarbageCollection no_gc; i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); i::wasm::NativeModule* native_module = script->wasm_native_module(); const i::wasm::WasmModule* module = native_module->module(); DCHECK_GE(i::kMaxInt, module->num_imported_functions); return static_cast(module->num_imported_functions); } MemorySpan WasmScript::Bytecode() const { i::Handle script = Utils::OpenHandle(this); i::Vector wire_bytes = script->wasm_native_module()->wire_bytes(); return {wire_bytes.begin(), wire_bytes.size()}; } std::pair WasmScript::GetFunctionRange(int function_index) const { i::DisallowGarbageCollection no_gc; i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); i::wasm::NativeModule* native_module = script->wasm_native_module(); const i::wasm::WasmModule* module = native_module->module(); DCHECK_LE(0, function_index); DCHECK_GT(module->functions.size(), function_index); const i::wasm::WasmFunction& func = module->functions[function_index]; DCHECK_GE(i::kMaxInt, func.code.offset()); DCHECK_GE(i::kMaxInt, func.code.end_offset()); return std::make_pair(static_cast(func.code.offset()), static_cast(func.code.end_offset())); } int WasmScript::GetContainingFunction(int byte_offset) const { i::DisallowGarbageCollection no_gc; i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); i::wasm::NativeModule* native_module = script->wasm_native_module(); const i::wasm::WasmModule* module = native_module->module(); DCHECK_LE(0, byte_offset); return i::wasm::GetContainingWasmFunction(module, byte_offset); } uint32_t WasmScript::GetFunctionHash(int function_index) { i::DisallowGarbageCollection no_gc; i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); i::wasm::NativeModule* native_module = script->wasm_native_module(); const i::wasm::WasmModule* module = native_module->module(); DCHECK_LE(0, function_index); DCHECK_GT(module->functions.size(), function_index); const i::wasm::WasmFunction& func = module->functions[function_index]; i::wasm::ModuleWireBytes wire_bytes(native_module->wire_bytes()); i::Vector function_bytes = wire_bytes.GetFunctionBytes(&func); // TODO(herhut): Maybe also take module, name and signature into account. return i::StringHasher::HashSequentialString(function_bytes.begin(), function_bytes.length(), 0); } int WasmScript::CodeOffset() const { i::Handle script = Utils::OpenHandle(this); DCHECK_EQ(i::Script::TYPE_WASM, script->type()); i::wasm::NativeModule* native_module = script->wasm_native_module(); const i::wasm::WasmModule* module = native_module->module(); // If the module contains at least one function, the code offset must have // been initialized, and it cannot be zero. DCHECK_IMPLIES(module->num_declared_functions > 0, module->code.offset() != 0); return module->code.offset(); } #endif // V8_ENABLE_WEBASSEMBLY Location::Location(int line_number, int column_number) : line_number_(line_number), column_number_(column_number), is_empty_(false) {} Location::Location() : line_number_(Function::kLineOffsetNotFound), column_number_(Function::kLineOffsetNotFound), is_empty_(true) {} int Location::GetLineNumber() const { DCHECK(!IsEmpty()); return line_number_; } int Location::GetColumnNumber() const { DCHECK(!IsEmpty()); return column_number_; } bool Location::IsEmpty() const { return is_empty_; } void GetLoadedScripts(Isolate* v8_isolate, PersistentValueVector