wasm-debug.cc 1.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2016 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/assert-scope.h"
#include "src/debug/debug.h"
#include "src/factory.h"
#include "src/isolate.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-module.h"
11
#include "src/wasm/wasm-objects.h"
12 13 14 15

using namespace v8::internal;
using namespace v8::internal::wasm;

16 17
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
  Isolate *isolate = instance->GetIsolate();
18
  Factory *factory = isolate->factory();
19 20
  Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED);
  arr->set(kInstance, *instance);
21 22 23 24 25 26 27

  return Handle<WasmDebugInfo>::cast(arr);
}

bool WasmDebugInfo::IsDebugInfo(Object *object) {
  if (!object->IsFixedArray()) return false;
  FixedArray *arr = FixedArray::cast(object);
28
  return arr->length() == kFieldCount && IsWasmInstance(arr->get(kInstance));
29 30 31 32 33 34 35
}

WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
  DCHECK(IsDebugInfo(object));
  return reinterpret_cast<WasmDebugInfo *>(object);
}

36
WasmInstanceObject *WasmDebugInfo::wasm_instance() {
37
  return WasmInstanceObject::cast(get(kInstance));
38
}