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#ifndef V8_EXECUTION_EXECUTION_H_
61cb0ef41Sopenharmony_ci#define V8_EXECUTION_EXECUTION_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/common/globals.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_cinamespace internal {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciclass MicrotaskQueue;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_citemplate <typename T>
161cb0ef41Sopenharmony_ciclass Handle;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciclass Execution final : public AllStatic {
191cb0ef41Sopenharmony_ci public:
201cb0ef41Sopenharmony_ci  // Whether to report pending messages, or keep them pending on the isolate.
211cb0ef41Sopenharmony_ci  enum class MessageHandling { kReport, kKeepPending };
221cb0ef41Sopenharmony_ci  enum class Target { kCallable, kRunMicrotasks };
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  // Call a function (that is not a script), the caller supplies a receiver and
251cb0ef41Sopenharmony_ci  // an array of arguments.
261cb0ef41Sopenharmony_ci  // When the function called is not in strict mode, receiver is
271cb0ef41Sopenharmony_ci  // converted to an object.
281cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Call(
291cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<Object> callable, Handle<Object> receiver,
301cb0ef41Sopenharmony_ci      int argc, Handle<Object> argv[]);
311cb0ef41Sopenharmony_ci  // Run a script. For JSFunctions that are not scripts, use Execution::Call.
321cb0ef41Sopenharmony_ci  // Depending on the script, the host_defined_options might not be used but the
331cb0ef41Sopenharmony_ci  // caller has to provide it at all times.
341cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object> CallScript(
351cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> callable, Handle<Object> receiver,
361cb0ef41Sopenharmony_ci      Handle<Object> host_defined_options);
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> CallBuiltin(
391cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> builtin, Handle<Object> receiver,
401cb0ef41Sopenharmony_ci      int argc, Handle<Object> argv[]);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  // Construct object from function, the caller supplies an array of
431cb0ef41Sopenharmony_ci  // arguments.
441cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> New(
451cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<Object> constructor, int argc,
461cb0ef41Sopenharmony_ci      Handle<Object> argv[]);
471cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> New(
481cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<Object> constructor, Handle<Object> new_target,
491cb0ef41Sopenharmony_ci      int argc, Handle<Object> argv[]);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  // Call a function, just like Call(), but handle don't report exceptions
521cb0ef41Sopenharmony_ci  // externally.
531cb0ef41Sopenharmony_ci  // The return value is either the result of calling the function (if no
541cb0ef41Sopenharmony_ci  // exception occurred), or an empty handle.
551cb0ef41Sopenharmony_ci  // If message_handling is MessageHandling::kReport, exceptions (except for
561cb0ef41Sopenharmony_ci  // termination exceptions) will be stored in exception_out (if not a
571cb0ef41Sopenharmony_ci  // nullptr).
581cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static MaybeHandle<Object> TryCall(
591cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<Object> callable, Handle<Object> receiver,
601cb0ef41Sopenharmony_ci      int argc, Handle<Object> argv[], MessageHandling message_handling,
611cb0ef41Sopenharmony_ci      MaybeHandle<Object>* exception_out, bool reschedule_terminate = true);
621cb0ef41Sopenharmony_ci  // Same as Execute::TryCall but for scripts which need an explicit
631cb0ef41Sopenharmony_ci  // host-defined options object. See Execution:CallScript
641cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static MaybeHandle<Object> TryCallScript(
651cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> script_function,
661cb0ef41Sopenharmony_ci      Handle<Object> receiver, Handle<FixedArray> host_defined_options,
671cb0ef41Sopenharmony_ci      MessageHandling message_handling, MaybeHandle<Object>* exception_out,
681cb0ef41Sopenharmony_ci      bool reschedule_terminate = true);
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci  // Convenience method for performing RunMicrotasks
711cb0ef41Sopenharmony_ci  static MaybeHandle<Object> TryRunMicrotasks(
721cb0ef41Sopenharmony_ci      Isolate* isolate, MicrotaskQueue* microtask_queue,
731cb0ef41Sopenharmony_ci      MaybeHandle<Object>* exception_out);
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
761cb0ef41Sopenharmony_ci  // Call a Wasm function identified by {wasm_call_target} through the
771cb0ef41Sopenharmony_ci  // provided {wrapper_code}, which must match the function's signature.
781cb0ef41Sopenharmony_ci  // Upon return, either isolate->has_pending_exception() is true, or
791cb0ef41Sopenharmony_ci  // the function's return values are in {packed_args}.
801cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static void CallWasm(Isolate* isolate,
811cb0ef41Sopenharmony_ci                                         Handle<CodeT> wrapper_code,
821cb0ef41Sopenharmony_ci                                         Address wasm_call_target,
831cb0ef41Sopenharmony_ci                                         Handle<Object> object_ref,
841cb0ef41Sopenharmony_ci                                         Address packed_args);
851cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
861cb0ef41Sopenharmony_ci};
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci}  // namespace internal
891cb0ef41Sopenharmony_ci}  // namespace v8
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci#endif  // V8_EXECUTION_EXECUTION_H_
92