• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_EXECUTION_EXECUTION_H_
6 #define V8_EXECUTION_EXECUTION_H_
7 
8 #include "src/common/globals.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class MicrotaskQueue;
14 
15 template <typename T>
16 class Handle;
17 
18 class Execution final : public AllStatic {
19  public:
20   // Whether to report pending messages, or keep them pending on the isolate.
21   enum class MessageHandling { kReport, kKeepPending };
22   enum class Target { kCallable, kRunMicrotasks };
23 
24   // Call a function (that is not a script), the caller supplies a receiver and
25   // an array of arguments.
26   // When the function called is not in strict mode, receiver is
27   // converted to an object.
28   V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Call(
29       Isolate* isolate, Handle<Object> callable, Handle<Object> receiver,
30       int argc, Handle<Object> argv[]);
31   // Run a script. For JSFunctions that are not scripts, use Execution::Call.
32   // Depending on the script, the host_defined_options might not be used but the
33   // caller has to provide it at all times.
34   V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object> CallScript(
35       Isolate* isolate, Handle<JSFunction> callable, Handle<Object> receiver,
36       Handle<Object> host_defined_options);
37 
38   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> CallBuiltin(
39       Isolate* isolate, Handle<JSFunction> builtin, Handle<Object> receiver,
40       int argc, Handle<Object> argv[]);
41 
42   // Construct object from function, the caller supplies an array of
43   // arguments.
44   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> New(
45       Isolate* isolate, Handle<Object> constructor, int argc,
46       Handle<Object> argv[]);
47   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> New(
48       Isolate* isolate, Handle<Object> constructor, Handle<Object> new_target,
49       int argc, Handle<Object> argv[]);
50 
51   // Call a function, just like Call(), but handle don't report exceptions
52   // externally.
53   // The return value is either the result of calling the function (if no
54   // exception occurred), or an empty handle.
55   // If message_handling is MessageHandling::kReport, exceptions (except for
56   // termination exceptions) will be stored in exception_out (if not a
57   // nullptr).
58   V8_EXPORT_PRIVATE static MaybeHandle<Object> TryCall(
59       Isolate* isolate, Handle<Object> callable, Handle<Object> receiver,
60       int argc, Handle<Object> argv[], MessageHandling message_handling,
61       MaybeHandle<Object>* exception_out, bool reschedule_terminate = true);
62   // Same as Execute::TryCall but for scripts which need an explicit
63   // host-defined options object. See Execution:CallScript
64   V8_EXPORT_PRIVATE static MaybeHandle<Object> TryCallScript(
65       Isolate* isolate, Handle<JSFunction> script_function,
66       Handle<Object> receiver, Handle<FixedArray> host_defined_options,
67       MessageHandling message_handling, MaybeHandle<Object>* exception_out,
68       bool reschedule_terminate = true);
69 
70   // Convenience method for performing RunMicrotasks
71   static MaybeHandle<Object> TryRunMicrotasks(
72       Isolate* isolate, MicrotaskQueue* microtask_queue,
73       MaybeHandle<Object>* exception_out);
74 
75 #if V8_ENABLE_WEBASSEMBLY
76   // Call a Wasm function identified by {wasm_call_target} through the
77   // provided {wrapper_code}, which must match the function's signature.
78   // Upon return, either isolate->has_pending_exception() is true, or
79   // the function's return values are in {packed_args}.
80   V8_EXPORT_PRIVATE static void CallWasm(Isolate* isolate,
81                                          Handle<CodeT> wrapper_code,
82                                          Address wasm_call_target,
83                                          Handle<Object> object_ref,
84                                          Address packed_args);
85 #endif  // V8_ENABLE_WEBASSEMBLY
86 };
87 
88 }  // namespace internal
89 }  // namespace v8
90 
91 #endif  // V8_EXECUTION_EXECUTION_H_
92