11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include <vector>
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/codegen/compiler.h"
81cb0ef41Sopenharmony_ci#include "src/common/globals.h"
91cb0ef41Sopenharmony_ci#include "src/debug/debug-coverage.h"
101cb0ef41Sopenharmony_ci#include "src/debug/debug-evaluate.h"
111cb0ef41Sopenharmony_ci#include "src/debug/debug-frames.h"
121cb0ef41Sopenharmony_ci#include "src/debug/debug-scopes.h"
131cb0ef41Sopenharmony_ci#include "src/debug/debug.h"
141cb0ef41Sopenharmony_ci#include "src/debug/liveedit.h"
151cb0ef41Sopenharmony_ci#include "src/deoptimizer/deoptimizer.h"
161cb0ef41Sopenharmony_ci#include "src/execution/arguments-inl.h"
171cb0ef41Sopenharmony_ci#include "src/execution/frames-inl.h"
181cb0ef41Sopenharmony_ci#include "src/execution/isolate-inl.h"
191cb0ef41Sopenharmony_ci#include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
201cb0ef41Sopenharmony_ci#include "src/interpreter/bytecode-array-iterator.h"
211cb0ef41Sopenharmony_ci#include "src/interpreter/bytecodes.h"
221cb0ef41Sopenharmony_ci#include "src/interpreter/interpreter.h"
231cb0ef41Sopenharmony_ci#include "src/logging/counters.h"
241cb0ef41Sopenharmony_ci#include "src/objects/debug-objects-inl.h"
251cb0ef41Sopenharmony_ci#include "src/objects/heap-object-inl.h"
261cb0ef41Sopenharmony_ci#include "src/objects/js-array-buffer-inl.h"
271cb0ef41Sopenharmony_ci#include "src/objects/js-collection-inl.h"
281cb0ef41Sopenharmony_ci#include "src/objects/js-generator-inl.h"
291cb0ef41Sopenharmony_ci#include "src/objects/js-promise-inl.h"
301cb0ef41Sopenharmony_ci#include "src/runtime/runtime-utils.h"
311cb0ef41Sopenharmony_ci#include "src/runtime/runtime.h"
321cb0ef41Sopenharmony_ci#include "src/snapshot/embedded/embedded-data.h"
331cb0ef41Sopenharmony_ci#include "src/snapshot/snapshot.h"
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
361cb0ef41Sopenharmony_ci#include "src/debug/debug-wasm-objects.h"
371cb0ef41Sopenharmony_ci#include "src/wasm/wasm-objects-inl.h"
381cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cinamespace v8 {
411cb0ef41Sopenharmony_cinamespace internal {
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciRUNTIME_FUNCTION_RETURN_PAIR(Runtime_DebugBreakOnBytecode) {
441cb0ef41Sopenharmony_ci  using interpreter::Bytecode;
451cb0ef41Sopenharmony_ci  using interpreter::Bytecodes;
461cb0ef41Sopenharmony_ci  using interpreter::OperandScale;
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
491cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
501cb0ef41Sopenharmony_ci  Handle<Object> value = args.at(0);
511cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  // Return value can be changed by debugger. Last set value will be used as
541cb0ef41Sopenharmony_ci  // return value.
551cb0ef41Sopenharmony_ci  ReturnValueScope result_scope(isolate->debug());
561cb0ef41Sopenharmony_ci  isolate->debug()->set_return_value(*value);
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  // Get the top-most JavaScript frame.
591cb0ef41Sopenharmony_ci  JavaScriptFrameIterator it(isolate);
601cb0ef41Sopenharmony_ci  if (isolate->debug_execution_mode() == DebugInfo::kBreakpoints) {
611cb0ef41Sopenharmony_ci    isolate->debug()->Break(it.frame(),
621cb0ef41Sopenharmony_ci                            handle(it.frame()->function(), isolate));
631cb0ef41Sopenharmony_ci  }
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  // Return the handler from the original bytecode array.
661cb0ef41Sopenharmony_ci  DCHECK(it.frame()->is_interpreted());
671cb0ef41Sopenharmony_ci  InterpretedFrame* interpreted_frame =
681cb0ef41Sopenharmony_ci      reinterpret_cast<InterpretedFrame*>(it.frame());
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci  bool side_effect_check_failed = false;
711cb0ef41Sopenharmony_ci  if (isolate->debug_execution_mode() == DebugInfo::kSideEffects) {
721cb0ef41Sopenharmony_ci    side_effect_check_failed =
731cb0ef41Sopenharmony_ci        !isolate->debug()->PerformSideEffectCheckAtBytecode(interpreted_frame);
741cb0ef41Sopenharmony_ci  }
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci  // Make sure to only access these objects after the side effect check, as the
771cb0ef41Sopenharmony_ci  // check can allocate on failure.
781cb0ef41Sopenharmony_ci  SharedFunctionInfo shared = interpreted_frame->function().shared();
791cb0ef41Sopenharmony_ci  BytecodeArray bytecode_array = shared.GetBytecodeArray(isolate);
801cb0ef41Sopenharmony_ci  int bytecode_offset = interpreted_frame->GetBytecodeOffset();
811cb0ef41Sopenharmony_ci  Bytecode bytecode = Bytecodes::FromByte(bytecode_array.get(bytecode_offset));
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  if (Bytecodes::Returns(bytecode)) {
841cb0ef41Sopenharmony_ci    // If we are returning (or suspending), reset the bytecode array on the
851cb0ef41Sopenharmony_ci    // interpreted stack frame to the non-debug variant so that the interpreter
861cb0ef41Sopenharmony_ci    // entry trampoline sees the return/suspend bytecode rather than the
871cb0ef41Sopenharmony_ci    // DebugBreak.
881cb0ef41Sopenharmony_ci    interpreted_frame->PatchBytecodeArray(bytecode_array);
891cb0ef41Sopenharmony_ci  }
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  // We do not have to deal with operand scale here. If the bytecode at the
921cb0ef41Sopenharmony_ci  // break is prefixed by operand scaling, we would have patched over the
931cb0ef41Sopenharmony_ci  // scaling prefix. We now simply dispatch to the handler for the prefix.
941cb0ef41Sopenharmony_ci  // We need to deserialize now to ensure we don't hit the debug break again
951cb0ef41Sopenharmony_ci  // after deserializing.
961cb0ef41Sopenharmony_ci  OperandScale operand_scale = OperandScale::kSingle;
971cb0ef41Sopenharmony_ci  isolate->interpreter()->GetBytecodeHandler(bytecode, operand_scale);
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci  if (side_effect_check_failed) {
1001cb0ef41Sopenharmony_ci    return MakePair(ReadOnlyRoots(isolate).exception(),
1011cb0ef41Sopenharmony_ci                    Smi::FromInt(static_cast<uint8_t>(bytecode)));
1021cb0ef41Sopenharmony_ci  }
1031cb0ef41Sopenharmony_ci  Object interrupt_object = isolate->stack_guard()->HandleInterrupts();
1041cb0ef41Sopenharmony_ci  if (interrupt_object.IsException(isolate)) {
1051cb0ef41Sopenharmony_ci    return MakePair(interrupt_object,
1061cb0ef41Sopenharmony_ci                    Smi::FromInt(static_cast<uint8_t>(bytecode)));
1071cb0ef41Sopenharmony_ci  }
1081cb0ef41Sopenharmony_ci  return MakePair(isolate->debug()->return_value(),
1091cb0ef41Sopenharmony_ci                  Smi::FromInt(static_cast<uint8_t>(bytecode)));
1101cb0ef41Sopenharmony_ci}
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugBreakAtEntry) {
1131cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
1141cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
1151cb0ef41Sopenharmony_ci  Handle<JSFunction> function = args.at<JSFunction>(0);
1161cb0ef41Sopenharmony_ci  USE(function);
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci  DCHECK(function->shared().HasDebugInfo());
1191cb0ef41Sopenharmony_ci  DCHECK(function->shared().GetDebugInfo().BreakAtEntry());
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci  // Get the top-most JavaScript frame. This is the debug target function.
1221cb0ef41Sopenharmony_ci  JavaScriptFrameIterator it(isolate);
1231cb0ef41Sopenharmony_ci  DCHECK_EQ(*function, it.frame()->function());
1241cb0ef41Sopenharmony_ci  // Check whether the next JS frame is closer than the last API entry.
1251cb0ef41Sopenharmony_ci  // if yes, then the call to the debug target came from JavaScript. Otherwise,
1261cb0ef41Sopenharmony_ci  // the call to the debug target came from API. Do not break for the latter.
1271cb0ef41Sopenharmony_ci  it.Advance();
1281cb0ef41Sopenharmony_ci  if (!it.done() &&
1291cb0ef41Sopenharmony_ci      it.frame()->fp() < isolate->thread_local_top()->last_api_entry_) {
1301cb0ef41Sopenharmony_ci    isolate->debug()->Break(it.frame(), function);
1311cb0ef41Sopenharmony_ci  }
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
1341cb0ef41Sopenharmony_ci}
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_HandleDebuggerStatement) {
1371cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
1381cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
1391cb0ef41Sopenharmony_ci  if (isolate->debug()->break_points_active()) {
1401cb0ef41Sopenharmony_ci    isolate->debug()->HandleDebugBreak(
1411cb0ef41Sopenharmony_ci        kIgnoreIfTopFrameBlackboxed,
1421cb0ef41Sopenharmony_ci        v8::debug::BreakReasons({v8::debug::BreakReason::kDebuggerStatement}));
1431cb0ef41Sopenharmony_ci  }
1441cb0ef41Sopenharmony_ci  return isolate->stack_guard()->HandleInterrupts();
1451cb0ef41Sopenharmony_ci}
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ScheduleBreak) {
1481cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
1491cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
1501cb0ef41Sopenharmony_ci  isolate->RequestInterrupt(
1511cb0ef41Sopenharmony_ci      [](v8::Isolate* isolate, void*) {
1521cb0ef41Sopenharmony_ci        v8::debug::BreakRightNow(
1531cb0ef41Sopenharmony_ci            isolate,
1541cb0ef41Sopenharmony_ci            v8::debug::BreakReasons({v8::debug::BreakReason::kScheduled}));
1551cb0ef41Sopenharmony_ci      },
1561cb0ef41Sopenharmony_ci      nullptr);
1571cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
1581cb0ef41Sopenharmony_ci}
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_cinamespace {
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_citemplate <class IteratorType>
1631cb0ef41Sopenharmony_cistatic Handle<ArrayList> AddIteratorInternalProperties(
1641cb0ef41Sopenharmony_ci    Isolate* isolate, Handle<ArrayList> result, Handle<IteratorType> iterator) {
1651cb0ef41Sopenharmony_ci  const char* kind = nullptr;
1661cb0ef41Sopenharmony_ci  switch (iterator->map().instance_type()) {
1671cb0ef41Sopenharmony_ci    case JS_MAP_KEY_ITERATOR_TYPE:
1681cb0ef41Sopenharmony_ci      kind = "keys";
1691cb0ef41Sopenharmony_ci      break;
1701cb0ef41Sopenharmony_ci    case JS_MAP_KEY_VALUE_ITERATOR_TYPE:
1711cb0ef41Sopenharmony_ci    case JS_SET_KEY_VALUE_ITERATOR_TYPE:
1721cb0ef41Sopenharmony_ci      kind = "entries";
1731cb0ef41Sopenharmony_ci      break;
1741cb0ef41Sopenharmony_ci    case JS_MAP_VALUE_ITERATOR_TYPE:
1751cb0ef41Sopenharmony_ci    case JS_SET_VALUE_ITERATOR_TYPE:
1761cb0ef41Sopenharmony_ci      kind = "values";
1771cb0ef41Sopenharmony_ci      break;
1781cb0ef41Sopenharmony_ci    default:
1791cb0ef41Sopenharmony_ci      UNREACHABLE();
1801cb0ef41Sopenharmony_ci  }
1811cb0ef41Sopenharmony_ci
1821cb0ef41Sopenharmony_ci  result = ArrayList::Add(
1831cb0ef41Sopenharmony_ci      isolate, result,
1841cb0ef41Sopenharmony_ci      isolate->factory()->NewStringFromAsciiChecked("[[IteratorHasMore]]"),
1851cb0ef41Sopenharmony_ci      isolate->factory()->ToBoolean(iterator->HasMore()));
1861cb0ef41Sopenharmony_ci  result = ArrayList::Add(
1871cb0ef41Sopenharmony_ci      isolate, result,
1881cb0ef41Sopenharmony_ci      isolate->factory()->NewStringFromAsciiChecked("[[IteratorIndex]]"),
1891cb0ef41Sopenharmony_ci      handle(iterator->index(), isolate));
1901cb0ef41Sopenharmony_ci  result = ArrayList::Add(
1911cb0ef41Sopenharmony_ci      isolate, result,
1921cb0ef41Sopenharmony_ci      isolate->factory()->NewStringFromAsciiChecked("[[IteratorKind]]"),
1931cb0ef41Sopenharmony_ci      isolate->factory()->NewStringFromAsciiChecked(kind));
1941cb0ef41Sopenharmony_ci  return result;
1951cb0ef41Sopenharmony_ci}
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci}  // namespace
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ciMaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
2001cb0ef41Sopenharmony_ci                                                    Handle<Object> object) {
2011cb0ef41Sopenharmony_ci  auto result = ArrayList::New(isolate, 8 * 2);
2021cb0ef41Sopenharmony_ci  if (object->IsJSObject()) {
2031cb0ef41Sopenharmony_ci    PrototypeIterator iter(isolate, Handle<JSObject>::cast(object),
2041cb0ef41Sopenharmony_ci                           kStartAtReceiver);
2051cb0ef41Sopenharmony_ci    if (iter.HasAccess()) {
2061cb0ef41Sopenharmony_ci      iter.Advance();
2071cb0ef41Sopenharmony_ci      Handle<Object> prototype = PrototypeIterator::GetCurrent(iter);
2081cb0ef41Sopenharmony_ci      if (!prototype->IsNull(isolate)) {
2091cb0ef41Sopenharmony_ci        result = ArrayList::Add(
2101cb0ef41Sopenharmony_ci            isolate, result,
2111cb0ef41Sopenharmony_ci            isolate->factory()->NewStringFromStaticChars("[[Prototype]]"),
2121cb0ef41Sopenharmony_ci            prototype);
2131cb0ef41Sopenharmony_ci      }
2141cb0ef41Sopenharmony_ci    }
2151cb0ef41Sopenharmony_ci  }
2161cb0ef41Sopenharmony_ci  if (object->IsJSBoundFunction()) {
2171cb0ef41Sopenharmony_ci    Handle<JSBoundFunction> function = Handle<JSBoundFunction>::cast(object);
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2201cb0ef41Sopenharmony_ci        isolate, result,
2211cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[TargetFunction]]"),
2221cb0ef41Sopenharmony_ci        handle(function->bound_target_function(), isolate));
2231cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2241cb0ef41Sopenharmony_ci        isolate, result,
2251cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[BoundThis]]"),
2261cb0ef41Sopenharmony_ci        handle(function->bound_this(), isolate));
2271cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2281cb0ef41Sopenharmony_ci        isolate, result,
2291cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[BoundArgs]]"),
2301cb0ef41Sopenharmony_ci        isolate->factory()->NewJSArrayWithElements(
2311cb0ef41Sopenharmony_ci            isolate->factory()->CopyFixedArray(
2321cb0ef41Sopenharmony_ci                handle(function->bound_arguments(), isolate))));
2331cb0ef41Sopenharmony_ci  } else if (object->IsJSMapIterator()) {
2341cb0ef41Sopenharmony_ci    Handle<JSMapIterator> iterator = Handle<JSMapIterator>::cast(object);
2351cb0ef41Sopenharmony_ci    result = AddIteratorInternalProperties(isolate, result, iterator);
2361cb0ef41Sopenharmony_ci  } else if (object->IsJSSetIterator()) {
2371cb0ef41Sopenharmony_ci    Handle<JSSetIterator> iterator = Handle<JSSetIterator>::cast(object);
2381cb0ef41Sopenharmony_ci    result = AddIteratorInternalProperties(isolate, result, iterator);
2391cb0ef41Sopenharmony_ci  } else if (object->IsJSGeneratorObject()) {
2401cb0ef41Sopenharmony_ci    Handle<JSGeneratorObject> generator =
2411cb0ef41Sopenharmony_ci        Handle<JSGeneratorObject>::cast(object);
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ci    const char* status = "suspended";
2441cb0ef41Sopenharmony_ci    if (generator->is_closed()) {
2451cb0ef41Sopenharmony_ci      status = "closed";
2461cb0ef41Sopenharmony_ci    } else if (generator->is_executing()) {
2471cb0ef41Sopenharmony_ci      status = "running";
2481cb0ef41Sopenharmony_ci    } else {
2491cb0ef41Sopenharmony_ci      DCHECK(generator->is_suspended());
2501cb0ef41Sopenharmony_ci    }
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2531cb0ef41Sopenharmony_ci        isolate, result,
2541cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[GeneratorState]]"),
2551cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked(status));
2561cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2571cb0ef41Sopenharmony_ci        isolate, result,
2581cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[GeneratorFunction]]"),
2591cb0ef41Sopenharmony_ci        handle(generator->function(), isolate));
2601cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2611cb0ef41Sopenharmony_ci        isolate, result,
2621cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[GeneratorReceiver]]"),
2631cb0ef41Sopenharmony_ci        handle(generator->receiver(), isolate));
2641cb0ef41Sopenharmony_ci  } else if (object->IsJSPromise()) {
2651cb0ef41Sopenharmony_ci    Handle<JSPromise> promise = Handle<JSPromise>::cast(object);
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2681cb0ef41Sopenharmony_ci        isolate, result,
2691cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[PromiseState]]"),
2701cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked(
2711cb0ef41Sopenharmony_ci            JSPromise::Status(promise->status())));
2721cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2731cb0ef41Sopenharmony_ci        isolate, result,
2741cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[PromiseResult]]"),
2751cb0ef41Sopenharmony_ci        promise->status() == Promise::kPending
2761cb0ef41Sopenharmony_ci            ? isolate->factory()->undefined_value()
2771cb0ef41Sopenharmony_ci            : handle(promise->result(), isolate));
2781cb0ef41Sopenharmony_ci  } else if (object->IsJSProxy()) {
2791cb0ef41Sopenharmony_ci    Handle<JSProxy> js_proxy = Handle<JSProxy>::cast(object);
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2821cb0ef41Sopenharmony_ci        isolate, result,
2831cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[Handler]]"),
2841cb0ef41Sopenharmony_ci        handle(js_proxy->handler(), isolate));
2851cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2861cb0ef41Sopenharmony_ci        isolate, result,
2871cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[Target]]"),
2881cb0ef41Sopenharmony_ci        handle(js_proxy->target(), isolate));
2891cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2901cb0ef41Sopenharmony_ci        isolate, result,
2911cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[IsRevoked]]"),
2921cb0ef41Sopenharmony_ci        isolate->factory()->ToBoolean(js_proxy->IsRevoked()));
2931cb0ef41Sopenharmony_ci  } else if (object->IsJSPrimitiveWrapper()) {
2941cb0ef41Sopenharmony_ci    Handle<JSPrimitiveWrapper> js_value =
2951cb0ef41Sopenharmony_ci        Handle<JSPrimitiveWrapper>::cast(object);
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ci    result = ArrayList::Add(
2981cb0ef41Sopenharmony_ci        isolate, result,
2991cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromAsciiChecked("[[PrimitiveValue]]"),
3001cb0ef41Sopenharmony_ci        handle(js_value->value(), isolate));
3011cb0ef41Sopenharmony_ci  } else if (object->IsJSArrayBuffer()) {
3021cb0ef41Sopenharmony_ci    Handle<JSArrayBuffer> js_array_buffer = Handle<JSArrayBuffer>::cast(object);
3031cb0ef41Sopenharmony_ci    if (js_array_buffer->was_detached()) {
3041cb0ef41Sopenharmony_ci      // Mark a detached JSArrayBuffer and such and don't even try to
3051cb0ef41Sopenharmony_ci      // create views for it, since the TypedArray constructors will
3061cb0ef41Sopenharmony_ci      // throw a TypeError when the underlying buffer is detached.
3071cb0ef41Sopenharmony_ci      result = ArrayList::Add(
3081cb0ef41Sopenharmony_ci          isolate, result,
3091cb0ef41Sopenharmony_ci          isolate->factory()->NewStringFromAsciiChecked("[[IsDetached]]"),
3101cb0ef41Sopenharmony_ci          isolate->factory()->true_value());
3111cb0ef41Sopenharmony_ci    } else {
3121cb0ef41Sopenharmony_ci      const size_t byte_length = js_array_buffer->byte_length();
3131cb0ef41Sopenharmony_ci      static const ExternalArrayType kTypes[] = {
3141cb0ef41Sopenharmony_ci          kExternalInt8Array,
3151cb0ef41Sopenharmony_ci          kExternalUint8Array,
3161cb0ef41Sopenharmony_ci          kExternalInt16Array,
3171cb0ef41Sopenharmony_ci          kExternalInt32Array,
3181cb0ef41Sopenharmony_ci      };
3191cb0ef41Sopenharmony_ci      for (auto type : kTypes) {
3201cb0ef41Sopenharmony_ci        switch (type) {
3211cb0ef41Sopenharmony_ci#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype)                           \
3221cb0ef41Sopenharmony_ci  case kExternal##Type##Array: {                                            \
3231cb0ef41Sopenharmony_ci    if ((byte_length % sizeof(ctype)) != 0) continue;                       \
3241cb0ef41Sopenharmony_ci    result = ArrayList::Add(                                                \
3251cb0ef41Sopenharmony_ci        isolate, result,                                                    \
3261cb0ef41Sopenharmony_ci        isolate->factory()->NewStringFromStaticChars("[[" #Type "Array]]"), \
3271cb0ef41Sopenharmony_ci        isolate->factory()->NewJSTypedArray(kExternal##Type##Array,         \
3281cb0ef41Sopenharmony_ci                                            js_array_buffer, 0,             \
3291cb0ef41Sopenharmony_ci                                            byte_length / sizeof(ctype)));  \
3301cb0ef41Sopenharmony_ci    break;                                                                  \
3311cb0ef41Sopenharmony_ci  }
3321cb0ef41Sopenharmony_ci          TYPED_ARRAYS(TYPED_ARRAY_CASE)
3331cb0ef41Sopenharmony_ci#undef TYPED_ARRAY_CASE
3341cb0ef41Sopenharmony_ci        default:
3351cb0ef41Sopenharmony_ci          UNREACHABLE();
3361cb0ef41Sopenharmony_ci        }
3371cb0ef41Sopenharmony_ci      }
3381cb0ef41Sopenharmony_ci      result =
3391cb0ef41Sopenharmony_ci          ArrayList::Add(isolate, result,
3401cb0ef41Sopenharmony_ci                         isolate->factory()->NewStringFromAsciiChecked(
3411cb0ef41Sopenharmony_ci                             "[[ArrayBufferByteLength]]"),
3421cb0ef41Sopenharmony_ci                         isolate->factory()->NewNumberFromSize(byte_length));
3431cb0ef41Sopenharmony_ci
3441cb0ef41Sopenharmony_ci      auto backing_store = js_array_buffer->GetBackingStore();
3451cb0ef41Sopenharmony_ci      Handle<Object> array_buffer_data =
3461cb0ef41Sopenharmony_ci          backing_store
3471cb0ef41Sopenharmony_ci              ? isolate->factory()->NewNumberFromUint(backing_store->id())
3481cb0ef41Sopenharmony_ci              : isolate->factory()->null_value();
3491cb0ef41Sopenharmony_ci      result = ArrayList::Add(
3501cb0ef41Sopenharmony_ci          isolate, result,
3511cb0ef41Sopenharmony_ci          isolate->factory()->NewStringFromAsciiChecked("[[ArrayBufferData]]"),
3521cb0ef41Sopenharmony_ci          array_buffer_data);
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci      Handle<Symbol> memory_symbol =
3551cb0ef41Sopenharmony_ci          isolate->factory()->array_buffer_wasm_memory_symbol();
3561cb0ef41Sopenharmony_ci      Handle<Object> memory_object =
3571cb0ef41Sopenharmony_ci          JSObject::GetDataProperty(isolate, js_array_buffer, memory_symbol);
3581cb0ef41Sopenharmony_ci      if (!memory_object->IsUndefined(isolate)) {
3591cb0ef41Sopenharmony_ci        result = ArrayList::Add(isolate, result,
3601cb0ef41Sopenharmony_ci                                isolate->factory()->NewStringFromAsciiChecked(
3611cb0ef41Sopenharmony_ci                                    "[[WebAssemblyMemory]]"),
3621cb0ef41Sopenharmony_ci                                memory_object);
3631cb0ef41Sopenharmony_ci      }
3641cb0ef41Sopenharmony_ci    }
3651cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
3661cb0ef41Sopenharmony_ci  } else if (object->IsWasmInstanceObject()) {
3671cb0ef41Sopenharmony_ci    result = AddWasmInstanceObjectInternalProperties(
3681cb0ef41Sopenharmony_ci        isolate, result, Handle<WasmInstanceObject>::cast(object));
3691cb0ef41Sopenharmony_ci  } else if (object->IsWasmModuleObject()) {
3701cb0ef41Sopenharmony_ci    result = AddWasmModuleObjectInternalProperties(
3711cb0ef41Sopenharmony_ci        isolate, result, Handle<WasmModuleObject>::cast(object));
3721cb0ef41Sopenharmony_ci  } else if (object->IsWasmTableObject()) {
3731cb0ef41Sopenharmony_ci    result = AddWasmTableObjectInternalProperties(
3741cb0ef41Sopenharmony_ci        isolate, result, Handle<WasmTableObject>::cast(object));
3751cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
3761cb0ef41Sopenharmony_ci  }
3771cb0ef41Sopenharmony_ci  return isolate->factory()->NewJSArrayWithElements(
3781cb0ef41Sopenharmony_ci      ArrayList::Elements(isolate, result), PACKED_ELEMENTS);
3791cb0ef41Sopenharmony_ci}
3801cb0ef41Sopenharmony_ci
3811cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetGeneratorScopeCount) {
3821cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
3831cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_ci  if (!args[0].IsJSGeneratorObject()) return Smi::zero();
3861cb0ef41Sopenharmony_ci
3871cb0ef41Sopenharmony_ci  // Check arguments.
3881cb0ef41Sopenharmony_ci  Handle<JSGeneratorObject> gen = args.at<JSGeneratorObject>(0);
3891cb0ef41Sopenharmony_ci
3901cb0ef41Sopenharmony_ci  // Only inspect suspended generator scopes.
3911cb0ef41Sopenharmony_ci  if (!gen->is_suspended()) {
3921cb0ef41Sopenharmony_ci    return Smi::zero();
3931cb0ef41Sopenharmony_ci  }
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ci  // Count the visible scopes.
3961cb0ef41Sopenharmony_ci  int n = 0;
3971cb0ef41Sopenharmony_ci  for (ScopeIterator it(isolate, gen); !it.Done(); it.Next()) {
3981cb0ef41Sopenharmony_ci    n++;
3991cb0ef41Sopenharmony_ci  }
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ci  return Smi::FromInt(n);
4021cb0ef41Sopenharmony_ci}
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetGeneratorScopeDetails) {
4051cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
4061cb0ef41Sopenharmony_ci  DCHECK_EQ(2, args.length());
4071cb0ef41Sopenharmony_ci
4081cb0ef41Sopenharmony_ci  if (!args[0].IsJSGeneratorObject()) {
4091cb0ef41Sopenharmony_ci    return ReadOnlyRoots(isolate).undefined_value();
4101cb0ef41Sopenharmony_ci  }
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_ci  // Check arguments.
4131cb0ef41Sopenharmony_ci  Handle<JSGeneratorObject> gen = args.at<JSGeneratorObject>(0);
4141cb0ef41Sopenharmony_ci  int index = NumberToInt32(args[1]);
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_ci  // Only inspect suspended generator scopes.
4171cb0ef41Sopenharmony_ci  if (!gen->is_suspended()) {
4181cb0ef41Sopenharmony_ci    return ReadOnlyRoots(isolate).undefined_value();
4191cb0ef41Sopenharmony_ci  }
4201cb0ef41Sopenharmony_ci
4211cb0ef41Sopenharmony_ci  // Find the requested scope.
4221cb0ef41Sopenharmony_ci  int n = 0;
4231cb0ef41Sopenharmony_ci  ScopeIterator it(isolate, gen);
4241cb0ef41Sopenharmony_ci  for (; !it.Done() && n < index; it.Next()) {
4251cb0ef41Sopenharmony_ci    n++;
4261cb0ef41Sopenharmony_ci  }
4271cb0ef41Sopenharmony_ci  if (it.Done()) {
4281cb0ef41Sopenharmony_ci    return ReadOnlyRoots(isolate).undefined_value();
4291cb0ef41Sopenharmony_ci  }
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci  return *it.MaterializeScopeDetails();
4321cb0ef41Sopenharmony_ci}
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_cistatic bool SetScopeVariableValue(ScopeIterator* it, int index,
4351cb0ef41Sopenharmony_ci                                  Handle<String> variable_name,
4361cb0ef41Sopenharmony_ci                                  Handle<Object> new_value) {
4371cb0ef41Sopenharmony_ci  for (int n = 0; !it->Done() && n < index; it->Next()) {
4381cb0ef41Sopenharmony_ci    n++;
4391cb0ef41Sopenharmony_ci  }
4401cb0ef41Sopenharmony_ci  if (it->Done()) {
4411cb0ef41Sopenharmony_ci    return false;
4421cb0ef41Sopenharmony_ci  }
4431cb0ef41Sopenharmony_ci  return it->SetVariableValue(variable_name, new_value);
4441cb0ef41Sopenharmony_ci}
4451cb0ef41Sopenharmony_ci
4461cb0ef41Sopenharmony_ci// Change variable value in closure or local scope
4471cb0ef41Sopenharmony_ci// args[0]: number or JsFunction: break id or function
4481cb0ef41Sopenharmony_ci// args[1]: number: scope index
4491cb0ef41Sopenharmony_ci// args[2]: string: variable name
4501cb0ef41Sopenharmony_ci// args[3]: object: new value
4511cb0ef41Sopenharmony_ci//
4521cb0ef41Sopenharmony_ci// Return true if success and false otherwise
4531cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SetGeneratorScopeVariableValue) {
4541cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
4551cb0ef41Sopenharmony_ci  DCHECK_EQ(4, args.length());
4561cb0ef41Sopenharmony_ci  Handle<JSGeneratorObject> gen = args.at<JSGeneratorObject>(0);
4571cb0ef41Sopenharmony_ci  int index = NumberToInt32(args[1]);
4581cb0ef41Sopenharmony_ci  Handle<String> variable_name = args.at<String>(2);
4591cb0ef41Sopenharmony_ci  Handle<Object> new_value = args.at(3);
4601cb0ef41Sopenharmony_ci  ScopeIterator it(isolate, gen);
4611cb0ef41Sopenharmony_ci  bool res = SetScopeVariableValue(&it, index, variable_name, new_value);
4621cb0ef41Sopenharmony_ci  return isolate->heap()->ToBoolean(res);
4631cb0ef41Sopenharmony_ci}
4641cb0ef41Sopenharmony_ci
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetBreakLocations) {
4671cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
4681cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
4691cb0ef41Sopenharmony_ci  CHECK(isolate->debug()->is_active());
4701cb0ef41Sopenharmony_ci  Handle<JSFunction> fun = args.at<JSFunction>(0);
4711cb0ef41Sopenharmony_ci
4721cb0ef41Sopenharmony_ci  Handle<SharedFunctionInfo> shared(fun->shared(), isolate);
4731cb0ef41Sopenharmony_ci  // Find the number of break points
4741cb0ef41Sopenharmony_ci  Handle<Object> break_locations =
4751cb0ef41Sopenharmony_ci      Debug::GetSourceBreakLocations(isolate, shared);
4761cb0ef41Sopenharmony_ci  if (break_locations->IsUndefined(isolate)) {
4771cb0ef41Sopenharmony_ci    return ReadOnlyRoots(isolate).undefined_value();
4781cb0ef41Sopenharmony_ci  }
4791cb0ef41Sopenharmony_ci  // Return array as JS array
4801cb0ef41Sopenharmony_ci  return *isolate->factory()->NewJSArrayWithElements(
4811cb0ef41Sopenharmony_ci      Handle<FixedArray>::cast(break_locations));
4821cb0ef41Sopenharmony_ci}
4831cb0ef41Sopenharmony_ci
4841cb0ef41Sopenharmony_ci
4851cb0ef41Sopenharmony_ci// Returns the state of break on exceptions
4861cb0ef41Sopenharmony_ci// args[0]: boolean indicating uncaught exceptions
4871cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_IsBreakOnException) {
4881cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
4891cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
4901cb0ef41Sopenharmony_ci  uint32_t type_arg = NumberToUint32(args[0]);
4911cb0ef41Sopenharmony_ci
4921cb0ef41Sopenharmony_ci  ExceptionBreakType type = static_cast<ExceptionBreakType>(type_arg);
4931cb0ef41Sopenharmony_ci  bool result = isolate->debug()->IsBreakOnException(type);
4941cb0ef41Sopenharmony_ci  return Smi::FromInt(result);
4951cb0ef41Sopenharmony_ci}
4961cb0ef41Sopenharmony_ci
4971cb0ef41Sopenharmony_ci// Clear all stepping set by PrepareStep.
4981cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ClearStepping) {
4991cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
5001cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
5011cb0ef41Sopenharmony_ci  CHECK(isolate->debug()->is_active());
5021cb0ef41Sopenharmony_ci  isolate->debug()->ClearStepping();
5031cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
5041cb0ef41Sopenharmony_ci}
5051cb0ef41Sopenharmony_ci
5061cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugGetLoadedScriptIds) {
5071cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
5081cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
5091cb0ef41Sopenharmony_ci
5101cb0ef41Sopenharmony_ci  Handle<FixedArray> instances;
5111cb0ef41Sopenharmony_ci  {
5121cb0ef41Sopenharmony_ci    DebugScope debug_scope(isolate->debug());
5131cb0ef41Sopenharmony_ci    // Fill the script objects.
5141cb0ef41Sopenharmony_ci    instances = isolate->debug()->GetLoadedScripts();
5151cb0ef41Sopenharmony_ci  }
5161cb0ef41Sopenharmony_ci
5171cb0ef41Sopenharmony_ci  // Convert the script objects to proper JS objects.
5181cb0ef41Sopenharmony_ci  for (int i = 0; i < instances->length(); i++) {
5191cb0ef41Sopenharmony_ci    Handle<Script> script(Script::cast(instances->get(i)), isolate);
5201cb0ef41Sopenharmony_ci    instances->set(i, Smi::FromInt(script->id()));
5211cb0ef41Sopenharmony_ci  }
5221cb0ef41Sopenharmony_ci
5231cb0ef41Sopenharmony_ci  // Return result as a JS array.
5241cb0ef41Sopenharmony_ci  return *isolate->factory()->NewJSArrayWithElements(instances);
5251cb0ef41Sopenharmony_ci}
5261cb0ef41Sopenharmony_ci
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_FunctionGetInferredName) {
5291cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
5301cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
5311cb0ef41Sopenharmony_ci
5321cb0ef41Sopenharmony_ci  Object f = args[0];
5331cb0ef41Sopenharmony_ci  if (f.IsJSFunction()) {
5341cb0ef41Sopenharmony_ci    return JSFunction::cast(f).shared().inferred_name();
5351cb0ef41Sopenharmony_ci  }
5361cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).empty_string();
5371cb0ef41Sopenharmony_ci}
5381cb0ef41Sopenharmony_ci
5391cb0ef41Sopenharmony_ci
5401cb0ef41Sopenharmony_ci// Performs a GC.
5411cb0ef41Sopenharmony_ci// Presently, it only does a full GC.
5421cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CollectGarbage) {
5431cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
5441cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
5451cb0ef41Sopenharmony_ci  isolate->heap()->PreciseCollectAllGarbage(Heap::kNoGCFlags,
5461cb0ef41Sopenharmony_ci                                            GarbageCollectionReason::kRuntime);
5471cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
5481cb0ef41Sopenharmony_ci}
5491cb0ef41Sopenharmony_ci
5501cb0ef41Sopenharmony_cinamespace {
5511cb0ef41Sopenharmony_ci
5521cb0ef41Sopenharmony_ciint ScriptLinePosition(Handle<Script> script, int line) {
5531cb0ef41Sopenharmony_ci  if (line < 0) return -1;
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
5561cb0ef41Sopenharmony_ci  if (script->type() == Script::TYPE_WASM) {
5571cb0ef41Sopenharmony_ci    // Wasm positions are relative to the start of the module.
5581cb0ef41Sopenharmony_ci    return 0;
5591cb0ef41Sopenharmony_ci  }
5601cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
5611cb0ef41Sopenharmony_ci
5621cb0ef41Sopenharmony_ci  Script::InitLineEnds(script->GetIsolate(), script);
5631cb0ef41Sopenharmony_ci
5641cb0ef41Sopenharmony_ci  FixedArray line_ends_array = FixedArray::cast(script->line_ends());
5651cb0ef41Sopenharmony_ci  const int line_count = line_ends_array.length();
5661cb0ef41Sopenharmony_ci  DCHECK_LT(0, line_count);
5671cb0ef41Sopenharmony_ci
5681cb0ef41Sopenharmony_ci  if (line == 0) return 0;
5691cb0ef41Sopenharmony_ci  // If line == line_count, we return the first position beyond the last line.
5701cb0ef41Sopenharmony_ci  if (line > line_count) return -1;
5711cb0ef41Sopenharmony_ci  return Smi::ToInt(line_ends_array.get(line - 1)) + 1;
5721cb0ef41Sopenharmony_ci}
5731cb0ef41Sopenharmony_ci
5741cb0ef41Sopenharmony_ciint ScriptLinePositionWithOffset(Handle<Script> script, int line, int offset) {
5751cb0ef41Sopenharmony_ci  if (line < 0 || offset < 0) return -1;
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_ci  if (line == 0 || offset == 0)
5781cb0ef41Sopenharmony_ci    return ScriptLinePosition(script, line) + offset;
5791cb0ef41Sopenharmony_ci
5801cb0ef41Sopenharmony_ci  Script::PositionInfo info;
5811cb0ef41Sopenharmony_ci  if (!Script::GetPositionInfo(script, offset, &info, Script::NO_OFFSET)) {
5821cb0ef41Sopenharmony_ci    return -1;
5831cb0ef41Sopenharmony_ci  }
5841cb0ef41Sopenharmony_ci
5851cb0ef41Sopenharmony_ci  const int total_line = info.line + line;
5861cb0ef41Sopenharmony_ci  return ScriptLinePosition(script, total_line);
5871cb0ef41Sopenharmony_ci}
5881cb0ef41Sopenharmony_ci
5891cb0ef41Sopenharmony_ciHandle<Object> GetJSPositionInfo(Handle<Script> script, int position,
5901cb0ef41Sopenharmony_ci                                 Script::OffsetFlag offset_flag,
5911cb0ef41Sopenharmony_ci                                 Isolate* isolate) {
5921cb0ef41Sopenharmony_ci  Script::PositionInfo info;
5931cb0ef41Sopenharmony_ci  if (!Script::GetPositionInfo(script, position, &info, offset_flag)) {
5941cb0ef41Sopenharmony_ci    return isolate->factory()->null_value();
5951cb0ef41Sopenharmony_ci  }
5961cb0ef41Sopenharmony_ci
5971cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
5981cb0ef41Sopenharmony_ci  const bool is_wasm_script = script->type() == Script::TYPE_WASM;
5991cb0ef41Sopenharmony_ci#else
6001cb0ef41Sopenharmony_ci  const bool is_wasm_script = false;
6011cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
6021cb0ef41Sopenharmony_ci  Handle<String> sourceText =
6031cb0ef41Sopenharmony_ci      is_wasm_script ? isolate->factory()->empty_string()
6041cb0ef41Sopenharmony_ci                     : isolate->factory()->NewSubString(
6051cb0ef41Sopenharmony_ci                           handle(String::cast(script->source()), isolate),
6061cb0ef41Sopenharmony_ci                           info.line_start, info.line_end);
6071cb0ef41Sopenharmony_ci
6081cb0ef41Sopenharmony_ci  Handle<JSObject> jsinfo =
6091cb0ef41Sopenharmony_ci      isolate->factory()->NewJSObject(isolate->object_function());
6101cb0ef41Sopenharmony_ci
6111cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, jsinfo, isolate->factory()->script_string(),
6121cb0ef41Sopenharmony_ci                        script, NONE);
6131cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, jsinfo, isolate->factory()->position_string(),
6141cb0ef41Sopenharmony_ci                        handle(Smi::FromInt(position), isolate), NONE);
6151cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, jsinfo, isolate->factory()->line_string(),
6161cb0ef41Sopenharmony_ci                        handle(Smi::FromInt(info.line), isolate), NONE);
6171cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, jsinfo, isolate->factory()->column_string(),
6181cb0ef41Sopenharmony_ci                        handle(Smi::FromInt(info.column), isolate), NONE);
6191cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, jsinfo,
6201cb0ef41Sopenharmony_ci                        isolate->factory()->sourceText_string(), sourceText,
6211cb0ef41Sopenharmony_ci                        NONE);
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_ci  return jsinfo;
6241cb0ef41Sopenharmony_ci}
6251cb0ef41Sopenharmony_ci
6261cb0ef41Sopenharmony_ciHandle<Object> ScriptLocationFromLine(Isolate* isolate, Handle<Script> script,
6271cb0ef41Sopenharmony_ci                                      Handle<Object> opt_line,
6281cb0ef41Sopenharmony_ci                                      Handle<Object> opt_column,
6291cb0ef41Sopenharmony_ci                                      int32_t offset) {
6301cb0ef41Sopenharmony_ci  // Line and column are possibly undefined and we need to handle these cases,
6311cb0ef41Sopenharmony_ci  // additionally subtracting corresponding offsets.
6321cb0ef41Sopenharmony_ci
6331cb0ef41Sopenharmony_ci  int32_t line = 0;
6341cb0ef41Sopenharmony_ci  if (!opt_line->IsNullOrUndefined(isolate)) {
6351cb0ef41Sopenharmony_ci    CHECK(opt_line->IsNumber());
6361cb0ef41Sopenharmony_ci    line = NumberToInt32(*opt_line) - script->line_offset();
6371cb0ef41Sopenharmony_ci  }
6381cb0ef41Sopenharmony_ci
6391cb0ef41Sopenharmony_ci  int32_t column = 0;
6401cb0ef41Sopenharmony_ci  if (!opt_column->IsNullOrUndefined(isolate)) {
6411cb0ef41Sopenharmony_ci    CHECK(opt_column->IsNumber());
6421cb0ef41Sopenharmony_ci    column = NumberToInt32(*opt_column);
6431cb0ef41Sopenharmony_ci    if (line == 0) column -= script->column_offset();
6441cb0ef41Sopenharmony_ci  }
6451cb0ef41Sopenharmony_ci
6461cb0ef41Sopenharmony_ci  int line_position = ScriptLinePositionWithOffset(script, line, offset);
6471cb0ef41Sopenharmony_ci  if (line_position < 0 || column < 0) return isolate->factory()->null_value();
6481cb0ef41Sopenharmony_ci
6491cb0ef41Sopenharmony_ci  return GetJSPositionInfo(script, line_position + column, Script::NO_OFFSET,
6501cb0ef41Sopenharmony_ci                           isolate);
6511cb0ef41Sopenharmony_ci}
6521cb0ef41Sopenharmony_ci
6531cb0ef41Sopenharmony_ci// Slow traversal over all scripts on the heap.
6541cb0ef41Sopenharmony_cibool GetScriptById(Isolate* isolate, int needle, Handle<Script>* result) {
6551cb0ef41Sopenharmony_ci  Script::Iterator iterator(isolate);
6561cb0ef41Sopenharmony_ci  for (Script script = iterator.Next(); !script.is_null();
6571cb0ef41Sopenharmony_ci       script = iterator.Next()) {
6581cb0ef41Sopenharmony_ci    if (script.id() == needle) {
6591cb0ef41Sopenharmony_ci      *result = handle(script, isolate);
6601cb0ef41Sopenharmony_ci      return true;
6611cb0ef41Sopenharmony_ci    }
6621cb0ef41Sopenharmony_ci  }
6631cb0ef41Sopenharmony_ci
6641cb0ef41Sopenharmony_ci  return false;
6651cb0ef41Sopenharmony_ci}
6661cb0ef41Sopenharmony_ci
6671cb0ef41Sopenharmony_ci}  // namespace
6681cb0ef41Sopenharmony_ci
6691cb0ef41Sopenharmony_ci// TODO(5530): Rename once conflicting function has been deleted.
6701cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ScriptLocationFromLine2) {
6711cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
6721cb0ef41Sopenharmony_ci  DCHECK_EQ(4, args.length());
6731cb0ef41Sopenharmony_ci  int32_t scriptid = NumberToInt32(args[0]);
6741cb0ef41Sopenharmony_ci  Handle<Object> opt_line = args.at(1);
6751cb0ef41Sopenharmony_ci  Handle<Object> opt_column = args.at(2);
6761cb0ef41Sopenharmony_ci  int32_t offset = NumberToInt32(args[3]);
6771cb0ef41Sopenharmony_ci
6781cb0ef41Sopenharmony_ci  Handle<Script> script;
6791cb0ef41Sopenharmony_ci  CHECK(GetScriptById(isolate, scriptid, &script));
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_ci  return *ScriptLocationFromLine(isolate, script, opt_line, opt_column, offset);
6821cb0ef41Sopenharmony_ci}
6831cb0ef41Sopenharmony_ci
6841cb0ef41Sopenharmony_ci// On function call, depending on circumstances, prepare for stepping in,
6851cb0ef41Sopenharmony_ci// or perform a side effect check.
6861cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugOnFunctionCall) {
6871cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
6881cb0ef41Sopenharmony_ci  DCHECK_EQ(2, args.length());
6891cb0ef41Sopenharmony_ci  Handle<JSFunction> fun = args.at<JSFunction>(0);
6901cb0ef41Sopenharmony_ci  Handle<Object> receiver = args.at(1);
6911cb0ef41Sopenharmony_ci  if (isolate->debug()->needs_check_on_function_call()) {
6921cb0ef41Sopenharmony_ci    // Ensure that the callee will perform debug check on function call too.
6931cb0ef41Sopenharmony_ci    Handle<SharedFunctionInfo> shared(fun->shared(), isolate);
6941cb0ef41Sopenharmony_ci    isolate->debug()->DeoptimizeFunction(shared);
6951cb0ef41Sopenharmony_ci    if (isolate->debug()->last_step_action() >= StepInto ||
6961cb0ef41Sopenharmony_ci        isolate->debug()->break_on_next_function_call()) {
6971cb0ef41Sopenharmony_ci      DCHECK_EQ(isolate->debug_execution_mode(), DebugInfo::kBreakpoints);
6981cb0ef41Sopenharmony_ci      isolate->debug()->PrepareStepIn(fun);
6991cb0ef41Sopenharmony_ci    }
7001cb0ef41Sopenharmony_ci    if (isolate->debug_execution_mode() == DebugInfo::kSideEffects &&
7011cb0ef41Sopenharmony_ci        !isolate->debug()->PerformSideEffectCheck(fun, receiver)) {
7021cb0ef41Sopenharmony_ci      return ReadOnlyRoots(isolate).exception();
7031cb0ef41Sopenharmony_ci    }
7041cb0ef41Sopenharmony_ci  }
7051cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
7061cb0ef41Sopenharmony_ci}
7071cb0ef41Sopenharmony_ci
7081cb0ef41Sopenharmony_ci// Set one shot breakpoints for the suspended generator object.
7091cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugPrepareStepInSuspendedGenerator) {
7101cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
7111cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
7121cb0ef41Sopenharmony_ci  isolate->debug()->PrepareStepInSuspendedGenerator();
7131cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
7141cb0ef41Sopenharmony_ci}
7151cb0ef41Sopenharmony_ci
7161cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugPushPromise) {
7171cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
7181cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
7191cb0ef41Sopenharmony_ci  Handle<JSObject> promise = args.at<JSObject>(0);
7201cb0ef41Sopenharmony_ci  isolate->PushPromise(promise);
7211cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
7221cb0ef41Sopenharmony_ci}
7231cb0ef41Sopenharmony_ci
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugPopPromise) {
7261cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
7271cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
7281cb0ef41Sopenharmony_ci  isolate->PopPromise();
7291cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
7301cb0ef41Sopenharmony_ci}
7311cb0ef41Sopenharmony_ci
7321cb0ef41Sopenharmony_cinamespace {
7331cb0ef41Sopenharmony_ciHandle<JSObject> MakeRangeObject(Isolate* isolate, const CoverageBlock& range) {
7341cb0ef41Sopenharmony_ci  Factory* factory = isolate->factory();
7351cb0ef41Sopenharmony_ci
7361cb0ef41Sopenharmony_ci  Handle<String> start_string = factory->InternalizeUtf8String("start");
7371cb0ef41Sopenharmony_ci  Handle<String> end_string = factory->InternalizeUtf8String("end");
7381cb0ef41Sopenharmony_ci  Handle<String> count_string = factory->InternalizeUtf8String("count");
7391cb0ef41Sopenharmony_ci
7401cb0ef41Sopenharmony_ci  Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto();
7411cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, range_obj, start_string,
7421cb0ef41Sopenharmony_ci                        factory->NewNumberFromInt(range.start), NONE);
7431cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, range_obj, end_string,
7441cb0ef41Sopenharmony_ci                        factory->NewNumberFromInt(range.end), NONE);
7451cb0ef41Sopenharmony_ci  JSObject::AddProperty(isolate, range_obj, count_string,
7461cb0ef41Sopenharmony_ci                        factory->NewNumberFromUint(range.count), NONE);
7471cb0ef41Sopenharmony_ci
7481cb0ef41Sopenharmony_ci  return range_obj;
7491cb0ef41Sopenharmony_ci}
7501cb0ef41Sopenharmony_ci}  // namespace
7511cb0ef41Sopenharmony_ci
7521cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugCollectCoverage) {
7531cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
7541cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
7551cb0ef41Sopenharmony_ci  // Collect coverage data.
7561cb0ef41Sopenharmony_ci  std::unique_ptr<Coverage> coverage;
7571cb0ef41Sopenharmony_ci  if (isolate->is_best_effort_code_coverage()) {
7581cb0ef41Sopenharmony_ci    coverage = Coverage::CollectBestEffort(isolate);
7591cb0ef41Sopenharmony_ci  } else {
7601cb0ef41Sopenharmony_ci    coverage = Coverage::CollectPrecise(isolate);
7611cb0ef41Sopenharmony_ci  }
7621cb0ef41Sopenharmony_ci  Factory* factory = isolate->factory();
7631cb0ef41Sopenharmony_ci  // Turn the returned data structure into JavaScript.
7641cb0ef41Sopenharmony_ci  // Create an array of scripts.
7651cb0ef41Sopenharmony_ci  int num_scripts = static_cast<int>(coverage->size());
7661cb0ef41Sopenharmony_ci  // Prepare property keys.
7671cb0ef41Sopenharmony_ci  Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts);
7681cb0ef41Sopenharmony_ci  Handle<String> script_string = factory->script_string();
7691cb0ef41Sopenharmony_ci  for (int i = 0; i < num_scripts; i++) {
7701cb0ef41Sopenharmony_ci    const auto& script_data = coverage->at(i);
7711cb0ef41Sopenharmony_ci    HandleScope inner_scope(isolate);
7721cb0ef41Sopenharmony_ci
7731cb0ef41Sopenharmony_ci    std::vector<CoverageBlock> ranges;
7741cb0ef41Sopenharmony_ci    int num_functions = static_cast<int>(script_data.functions.size());
7751cb0ef41Sopenharmony_ci    for (int j = 0; j < num_functions; j++) {
7761cb0ef41Sopenharmony_ci      const auto& function_data = script_data.functions[j];
7771cb0ef41Sopenharmony_ci      ranges.emplace_back(function_data.start, function_data.end,
7781cb0ef41Sopenharmony_ci                          function_data.count);
7791cb0ef41Sopenharmony_ci      for (size_t k = 0; k < function_data.blocks.size(); k++) {
7801cb0ef41Sopenharmony_ci        const auto& block_data = function_data.blocks[k];
7811cb0ef41Sopenharmony_ci        ranges.emplace_back(block_data.start, block_data.end, block_data.count);
7821cb0ef41Sopenharmony_ci      }
7831cb0ef41Sopenharmony_ci    }
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ci    int num_ranges = static_cast<int>(ranges.size());
7861cb0ef41Sopenharmony_ci    Handle<FixedArray> ranges_array = factory->NewFixedArray(num_ranges);
7871cb0ef41Sopenharmony_ci    for (int j = 0; j < num_ranges; j++) {
7881cb0ef41Sopenharmony_ci      Handle<JSObject> range_object = MakeRangeObject(isolate, ranges[j]);
7891cb0ef41Sopenharmony_ci      ranges_array->set(j, *range_object);
7901cb0ef41Sopenharmony_ci    }
7911cb0ef41Sopenharmony_ci
7921cb0ef41Sopenharmony_ci    Handle<JSArray> script_obj =
7931cb0ef41Sopenharmony_ci        factory->NewJSArrayWithElements(ranges_array, PACKED_ELEMENTS);
7941cb0ef41Sopenharmony_ci    JSObject::AddProperty(isolate, script_obj, script_string,
7951cb0ef41Sopenharmony_ci                          handle(script_data.script->source(), isolate), NONE);
7961cb0ef41Sopenharmony_ci    scripts_array->set(i, *script_obj);
7971cb0ef41Sopenharmony_ci  }
7981cb0ef41Sopenharmony_ci  return *factory->NewJSArrayWithElements(scripts_array, PACKED_ELEMENTS);
7991cb0ef41Sopenharmony_ci}
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) {
8021cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
8031cb0ef41Sopenharmony_ci  bool enable = Oddball::cast(args[0]).ToBool(isolate);
8041cb0ef41Sopenharmony_ci  Coverage::SelectMode(isolate, enable ? debug::CoverageMode::kPreciseCount
8051cb0ef41Sopenharmony_ci                                       : debug::CoverageMode::kBestEffort);
8061cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
8071cb0ef41Sopenharmony_ci}
8081cb0ef41Sopenharmony_ci
8091cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugToggleBlockCoverage) {
8101cb0ef41Sopenharmony_ci  SealHandleScope shs(isolate);
8111cb0ef41Sopenharmony_ci  bool enable = Oddball::cast(args[0]).ToBool(isolate);
8121cb0ef41Sopenharmony_ci  Coverage::SelectMode(isolate, enable ? debug::CoverageMode::kBlockCount
8131cb0ef41Sopenharmony_ci                                       : debug::CoverageMode::kBestEffort);
8141cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
8151cb0ef41Sopenharmony_ci}
8161cb0ef41Sopenharmony_ci
8171cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_IncBlockCounter) {
8181cb0ef41Sopenharmony_ci  UNREACHABLE();  // Never called. See the IncBlockCounter builtin instead.
8191cb0ef41Sopenharmony_ci}
8201cb0ef41Sopenharmony_ci
8211cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugAsyncFunctionSuspended) {
8221cb0ef41Sopenharmony_ci  DCHECK_EQ(5, args.length());
8231cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
8241cb0ef41Sopenharmony_ci  Handle<JSPromise> promise = args.at<JSPromise>(0);
8251cb0ef41Sopenharmony_ci  Handle<JSPromise> outer_promise = args.at<JSPromise>(1);
8261cb0ef41Sopenharmony_ci  Handle<JSFunction> reject_handler = args.at<JSFunction>(2);
8271cb0ef41Sopenharmony_ci  Handle<JSGeneratorObject> generator = args.at<JSGeneratorObject>(3);
8281cb0ef41Sopenharmony_ci  bool is_predicted_as_caught = Oddball::cast(args[4]).ToBool(isolate);
8291cb0ef41Sopenharmony_ci
8301cb0ef41Sopenharmony_ci  // Allocate the throwaway promise and fire the appropriate init
8311cb0ef41Sopenharmony_ci  // hook for the throwaway promise (passing the {promise} as its
8321cb0ef41Sopenharmony_ci  // parent).
8331cb0ef41Sopenharmony_ci  Handle<JSPromise> throwaway = isolate->factory()->NewJSPromiseWithoutHook();
8341cb0ef41Sopenharmony_ci  isolate->OnAsyncFunctionSuspended(throwaway, promise);
8351cb0ef41Sopenharmony_ci
8361cb0ef41Sopenharmony_ci  // The Promise will be thrown away and not handled, but it
8371cb0ef41Sopenharmony_ci  // shouldn't trigger unhandled reject events as its work is done
8381cb0ef41Sopenharmony_ci  throwaway->set_has_handler(true);
8391cb0ef41Sopenharmony_ci
8401cb0ef41Sopenharmony_ci  // Enable proper debug support for promises.
8411cb0ef41Sopenharmony_ci  if (isolate->debug()->is_active()) {
8421cb0ef41Sopenharmony_ci    Object::SetProperty(isolate, reject_handler,
8431cb0ef41Sopenharmony_ci                        isolate->factory()->promise_forwarding_handler_symbol(),
8441cb0ef41Sopenharmony_ci                        isolate->factory()->true_value(),
8451cb0ef41Sopenharmony_ci                        StoreOrigin::kMaybeKeyed,
8461cb0ef41Sopenharmony_ci                        Just(ShouldThrow::kThrowOnError))
8471cb0ef41Sopenharmony_ci        .Check();
8481cb0ef41Sopenharmony_ci    promise->set_handled_hint(is_predicted_as_caught);
8491cb0ef41Sopenharmony_ci
8501cb0ef41Sopenharmony_ci    // Mark the dependency to {outer_promise} in case the {throwaway}
8511cb0ef41Sopenharmony_ci    // Promise is found on the Promise stack
8521cb0ef41Sopenharmony_ci    Object::SetProperty(isolate, throwaway,
8531cb0ef41Sopenharmony_ci                        isolate->factory()->promise_handled_by_symbol(),
8541cb0ef41Sopenharmony_ci                        outer_promise, StoreOrigin::kMaybeKeyed,
8551cb0ef41Sopenharmony_ci                        Just(ShouldThrow::kThrowOnError))
8561cb0ef41Sopenharmony_ci        .Check();
8571cb0ef41Sopenharmony_ci
8581cb0ef41Sopenharmony_ci    Object::SetProperty(
8591cb0ef41Sopenharmony_ci        isolate, promise, isolate->factory()->promise_awaited_by_symbol(),
8601cb0ef41Sopenharmony_ci        generator, StoreOrigin::kMaybeKeyed, Just(ShouldThrow::kThrowOnError))
8611cb0ef41Sopenharmony_ci        .Check();
8621cb0ef41Sopenharmony_ci  }
8631cb0ef41Sopenharmony_ci
8641cb0ef41Sopenharmony_ci  return *throwaway;
8651cb0ef41Sopenharmony_ci}
8661cb0ef41Sopenharmony_ci
8671cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DebugPromiseThen) {
8681cb0ef41Sopenharmony_ci  DCHECK_EQ(1, args.length());
8691cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
8701cb0ef41Sopenharmony_ci  Handle<JSReceiver> promise = args.at<JSReceiver>(0);
8711cb0ef41Sopenharmony_ci  if (promise->IsJSPromise()) {
8721cb0ef41Sopenharmony_ci    isolate->OnPromiseThen(Handle<JSPromise>::cast(promise));
8731cb0ef41Sopenharmony_ci  }
8741cb0ef41Sopenharmony_ci  return *promise;
8751cb0ef41Sopenharmony_ci}
8761cb0ef41Sopenharmony_ci
8771cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_LiveEditPatchScript) {
8781cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
8791cb0ef41Sopenharmony_ci  DCHECK_EQ(2, args.length());
8801cb0ef41Sopenharmony_ci  Handle<JSFunction> script_function = args.at<JSFunction>(0);
8811cb0ef41Sopenharmony_ci  Handle<String> new_source = args.at<String>(1);
8821cb0ef41Sopenharmony_ci
8831cb0ef41Sopenharmony_ci  Handle<Script> script(Script::cast(script_function->shared().script()),
8841cb0ef41Sopenharmony_ci                        isolate);
8851cb0ef41Sopenharmony_ci  v8::debug::LiveEditResult result;
8861cb0ef41Sopenharmony_ci  LiveEdit::PatchScript(isolate, script, new_source, false, &result);
8871cb0ef41Sopenharmony_ci  switch (result.status) {
8881cb0ef41Sopenharmony_ci    case v8::debug::LiveEditResult::COMPILE_ERROR:
8891cb0ef41Sopenharmony_ci      return isolate->Throw(*isolate->factory()->NewStringFromAsciiChecked(
8901cb0ef41Sopenharmony_ci          "LiveEdit failed: COMPILE_ERROR"));
8911cb0ef41Sopenharmony_ci    case v8::debug::LiveEditResult::BLOCKED_BY_RUNNING_GENERATOR:
8921cb0ef41Sopenharmony_ci      return isolate->Throw(*isolate->factory()->NewStringFromAsciiChecked(
8931cb0ef41Sopenharmony_ci          "LiveEdit failed: BLOCKED_BY_RUNNING_GENERATOR"));
8941cb0ef41Sopenharmony_ci    case v8::debug::LiveEditResult::BLOCKED_BY_ACTIVE_FUNCTION:
8951cb0ef41Sopenharmony_ci      return isolate->Throw(*isolate->factory()->NewStringFromAsciiChecked(
8961cb0ef41Sopenharmony_ci          "LiveEdit failed: BLOCKED_BY_ACTIVE_FUNCTION"));
8971cb0ef41Sopenharmony_ci    case v8::debug::LiveEditResult::OK:
8981cb0ef41Sopenharmony_ci      return ReadOnlyRoots(isolate).undefined_value();
8991cb0ef41Sopenharmony_ci  }
9001cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
9011cb0ef41Sopenharmony_ci}
9021cb0ef41Sopenharmony_ci
9031cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ProfileCreateSnapshotDataBlob) {
9041cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
9051cb0ef41Sopenharmony_ci  DCHECK_EQ(0, args.length());
9061cb0ef41Sopenharmony_ci
9071cb0ef41Sopenharmony_ci  // Used only by the test/memory/Memory.json benchmark. This creates a snapshot
9081cb0ef41Sopenharmony_ci  // blob and outputs various statistics around it.
9091cb0ef41Sopenharmony_ci
9101cb0ef41Sopenharmony_ci  DCHECK(FLAG_profile_deserialization && FLAG_serialization_statistics);
9111cb0ef41Sopenharmony_ci
9121cb0ef41Sopenharmony_ci  DisableEmbeddedBlobRefcounting();
9131cb0ef41Sopenharmony_ci
9141cb0ef41Sopenharmony_ci  v8::StartupData blob = CreateSnapshotDataBlobInternal(
9151cb0ef41Sopenharmony_ci      v8::SnapshotCreator::FunctionCodeHandling::kClear, nullptr);
9161cb0ef41Sopenharmony_ci  delete[] blob.data;
9171cb0ef41Sopenharmony_ci
9181cb0ef41Sopenharmony_ci  // Track the embedded blob size as well.
9191cb0ef41Sopenharmony_ci  {
9201cb0ef41Sopenharmony_ci    i::EmbeddedData d = i::EmbeddedData::FromBlob(isolate);
9211cb0ef41Sopenharmony_ci    PrintF("Embedded blob is %d bytes\n",
9221cb0ef41Sopenharmony_ci           static_cast<int>(d.code_size() + d.data_size()));
9231cb0ef41Sopenharmony_ci  }
9241cb0ef41Sopenharmony_ci
9251cb0ef41Sopenharmony_ci  FreeCurrentEmbeddedBlob();
9261cb0ef41Sopenharmony_ci
9271cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
9281cb0ef41Sopenharmony_ci}
9291cb0ef41Sopenharmony_ci
9301cb0ef41Sopenharmony_ci}  // namespace internal
9311cb0ef41Sopenharmony_ci}  // namespace v8
932